td_thr_validate.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Validate a thread handle.
  2. Copyright (C) 1999,2001,2002,2003,2004,2007 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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "thread_dbP.h"
  17. #include <stdbool.h>
  18. static td_err_e
  19. check_thread_list (const td_thrhandle_t *th, psaddr_t head, bool *uninit)
  20. {
  21. td_err_e err;
  22. psaddr_t next, ofs;
  23. err = DB_GET_FIELD (next, th->th_ta_p, head, list_t, next, 0);
  24. if (err == TD_OK)
  25. {
  26. if (next == 0)
  27. {
  28. *uninit = true;
  29. return TD_NOTHR;
  30. }
  31. err = DB_GET_FIELD_ADDRESS (ofs, th->th_ta_p, 0, pthread, list, 0);
  32. }
  33. while (err == TD_OK)
  34. {
  35. if (next == head)
  36. return TD_NOTHR;
  37. if (next - (ofs - (psaddr_t) 0) == th->th_unique)
  38. return TD_OK;
  39. err = DB_GET_FIELD (next, th->th_ta_p, next, list_t, next, 0);
  40. }
  41. return err;
  42. }
  43. td_err_e
  44. td_thr_validate (const td_thrhandle_t *th)
  45. {
  46. td_err_e err;
  47. psaddr_t list = NULL;
  48. LOG ("td_thr_validate");
  49. /* First check the list with threads using user allocated stacks. */
  50. bool uninit = false;
  51. err = DB_GET_SYMBOL (list, th->th_ta_p, __stack_user);
  52. if (err == TD_OK)
  53. err = check_thread_list (th, list, &uninit);
  54. /* If our thread is not on this list search the list with stack
  55. using implementation allocated stacks. */
  56. if (err == TD_NOTHR)
  57. {
  58. err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
  59. if (err == TD_OK)
  60. err = check_thread_list (th, list, &uninit);
  61. if (err == TD_NOTHR && uninit && th->th_unique == 0)
  62. /* __pthread_initialize_minimal has not run yet.
  63. There is only the special case thread handle. */
  64. err = TD_OK;
  65. }
  66. return err;
  67. }