td_thr_tlsbase.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Locate TLS data for a thread.
  2. Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "thread_dbP.h"
  16. td_err_e
  17. td_thr_tlsbase (const td_thrhandle_t *th,
  18. unsigned long int modid,
  19. psaddr_t *base)
  20. {
  21. td_err_e err;
  22. psaddr_t dtv, dtvslot, dtvptr;
  23. if (modid < 1)
  24. return TD_NOTLS;
  25. /* Get the DTV pointer from the thread descriptor. */
  26. err = DB_GET_FIELD (dtv, th->th_ta_p, th->th_unique, pthread, dtvp, 0);
  27. if (err != TD_OK)
  28. return err;
  29. /* Find the corresponding entry in the DTV. */
  30. err = DB_GET_FIELD_ADDRESS (dtvslot, th->th_ta_p, dtv, dtv, dtv, modid);
  31. if (err != TD_OK)
  32. return err;
  33. /* Extract the TLS block address from that DTV slot. */
  34. err = DB_GET_FIELD (dtvptr, th->th_ta_p, dtvslot, dtv_t, pointer_val, 0);
  35. if (err != TD_OK)
  36. return err;
  37. /* It could be that the memory for this module is not allocated for
  38. the given thread. */
  39. if ((uintptr_t) dtvptr & 1)
  40. return TD_TLSDEFER;
  41. *base = dtvptr;
  42. return TD_OK;
  43. }