td_thr_validate.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Validate a thread handle.
  2. Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include "thread_dbP.h"
  18. #include <stdbool.h>
  19. static td_err_e
  20. check_thread_list (const td_thrhandle_t *th, psaddr_t head, bool *uninit)
  21. {
  22. td_err_e err;
  23. psaddr_t next, ofs;
  24. err = DB_GET_FIELD (next, th->th_ta_p, head, list_t, next, 0);
  25. if (err == TD_OK)
  26. {
  27. if (next == 0)
  28. {
  29. *uninit = true;
  30. return TD_NOTHR;
  31. }
  32. err = DB_GET_FIELD_ADDRESS (ofs, th->th_ta_p, 0, pthread, list, 0);
  33. }
  34. while (err == TD_OK)
  35. {
  36. if (next == head)
  37. return TD_NOTHR;
  38. if (next - (ofs - (psaddr_t) 0) == th->th_unique)
  39. return TD_OK;
  40. err = DB_GET_FIELD (next, th->th_ta_p, next, list_t, next, 0);
  41. }
  42. return err;
  43. }
  44. td_err_e
  45. td_thr_validate (const td_thrhandle_t *th)
  46. {
  47. td_err_e err;
  48. psaddr_t list = NULL;
  49. LOG ("td_thr_validate");
  50. /* First check the list with threads using user allocated stacks. */
  51. bool uninit = false;
  52. err = DB_GET_SYMBOL (list, th->th_ta_p, __stack_user);
  53. if (err == TD_OK)
  54. err = check_thread_list (th, list, &uninit);
  55. /* If our thread is not on this list search the list with stack
  56. using implementation allocated stacks. */
  57. if (err == TD_NOTHR)
  58. {
  59. err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
  60. if (err == TD_OK)
  61. err = check_thread_list (th, list, &uninit);
  62. if (err == TD_NOTHR && uninit)
  63. {
  64. /* __pthread_initialize_minimal has not run yet.
  65. But the main thread still has a valid ID. */
  66. td_thrhandle_t main_th;
  67. err = td_ta_map_lwp2thr (th->th_ta_p,
  68. ps_getpid (th->th_ta_p->ph), &main_th);
  69. if (err == TD_OK && th->th_unique != main_th.th_unique)
  70. err = TD_NOTHR;
  71. }
  72. }
  73. return err;
  74. }