td_ta_tsd_iter.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Iterate over a process's thread-specific data.
  2. Copyright (C) 1999,2000,2001,2002,2003 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 <alloca.h>
  19. td_err_e
  20. td_ta_tsd_iter (const td_thragent_t *ta_arg, td_key_iter_f *callback,
  21. void *cbdata_p)
  22. {
  23. td_thragent_t *const ta = (td_thragent_t *) ta_arg;
  24. td_err_e err;
  25. void *keys;
  26. size_t keys_nb, keys_elemsize;
  27. psaddr_t addr;
  28. uint32_t idx;
  29. LOG ("td_ta_tsd_iter");
  30. /* Test whether the TA parameter is ok. */
  31. if (! ta_ok (ta))
  32. return TD_BADTA;
  33. /* This makes sure we have the size information on hand. */
  34. addr = 0;
  35. err = _td_locate_field (ta,
  36. ta->ta_var___pthread_keys, SYM_DESC___pthread_keys,
  37. (psaddr_t) 0 + 1, &addr);
  38. if (err != TD_OK)
  39. return err;
  40. /* Now copy in the entire array of key descriptors. */
  41. keys_elemsize = (addr - (psaddr_t) 0) / 8;
  42. keys_nb = keys_elemsize * DB_DESC_NELEM (ta->ta_var___pthread_keys);
  43. keys = __alloca (keys_nb);
  44. err = DB_GET_SYMBOL (addr, ta, __pthread_keys);
  45. if (err != TD_OK)
  46. return err;
  47. if (ps_pdread (ta->ph, addr, keys, keys_nb) != PS_OK)
  48. return TD_ERR;
  49. /* Now get all descriptors, one after the other. */
  50. for (idx = 0; idx < DB_DESC_NELEM (ta->ta_var___pthread_keys); ++idx)
  51. {
  52. psaddr_t seq, destr;
  53. err = DB_GET_FIELD_LOCAL (seq, ta, keys, pthread_key_struct, seq, 0);
  54. if (err != TD_OK)
  55. return err;
  56. if (((uintptr_t) seq) & 1)
  57. {
  58. err = DB_GET_FIELD_LOCAL (destr, ta, keys, pthread_key_struct,
  59. destr, 0);
  60. if (err != TD_OK)
  61. return err;
  62. /* Return with an error if the callback returns a nonzero value. */
  63. if (callback ((thread_key_t) idx, destr, cbdata_p) != 0)
  64. return TD_DBERR;
  65. }
  66. /* Advance to the next element in the copied array. */
  67. keys += keys_elemsize;
  68. }
  69. return TD_OK;
  70. }