td_thr_get_info.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Get thread information.
  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 <stddef.h>
  18. #include <string.h>
  19. #include "thread_dbP.h"
  20. td_err_e
  21. td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
  22. {
  23. td_err_e err;
  24. void *copy;
  25. psaddr_t tls, schedpolicy, schedprio, cancelhandling, tid, report_events;
  26. LOG ("td_thr_get_info");
  27. /* Copy the whole descriptor in once so we can access the several
  28. fields locally. Excess copying in one go is much better than
  29. multiple ps_pdread calls. */
  30. err = DB_GET_STRUCT (copy, th->th_ta_p, th->th_unique, pthread);
  31. if (err != TD_OK)
  32. return err;
  33. err = DB_GET_FIELD_ADDRESS (tls, th->th_ta_p, th->th_unique,
  34. pthread, specific, 0);
  35. if (err != TD_OK)
  36. return err;
  37. err = DB_GET_FIELD_LOCAL (schedpolicy, th->th_ta_p, copy, pthread,
  38. schedpolicy, 0);
  39. if (err != TD_OK)
  40. return err;
  41. err = DB_GET_FIELD_LOCAL (schedprio, th->th_ta_p, copy, pthread,
  42. schedparam_sched_priority, 0);
  43. if (err != TD_OK)
  44. return err;
  45. err = DB_GET_FIELD_LOCAL (tid, th->th_ta_p, copy, pthread, tid, 0);
  46. if (err != TD_OK)
  47. return err;
  48. err = DB_GET_FIELD_LOCAL (cancelhandling, th->th_ta_p, copy, pthread,
  49. cancelhandling, 0);
  50. if (err != TD_OK)
  51. return err;
  52. err = DB_GET_FIELD_LOCAL (report_events, th->th_ta_p, copy, pthread,
  53. report_events, 0);
  54. if (err != TD_OK)
  55. return err;
  56. /* Fill in information. Clear first to provide reproducable
  57. results for the fields we do not fill in. */
  58. memset (infop, '\0', sizeof (td_thrinfo_t));
  59. infop->ti_tid = (thread_t) th->th_unique;
  60. infop->ti_tls = (char *) tls;
  61. infop->ti_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
  62. ? 0 : (uintptr_t) schedprio);
  63. infop->ti_type = TD_THR_USER;
  64. if ((((int) (uintptr_t) cancelhandling) & EXITING_BITMASK) == 0)
  65. /* XXX For now there is no way to get more information. */
  66. infop->ti_state = TD_THR_ACTIVE;
  67. else if ((((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK) == 0)
  68. infop->ti_state = TD_THR_ZOMBIE;
  69. else
  70. infop->ti_state = TD_THR_UNKNOWN;
  71. /* Initialization which are the same in both cases. */
  72. infop->ti_ta_p = th->th_ta_p;
  73. infop->ti_lid = tid == 0 ? ps_getpid (th->th_ta_p->ph) : (uintptr_t) tid;
  74. infop->ti_traceme = report_events != 0;
  75. err = DB_GET_FIELD_LOCAL (infop->ti_startfunc, th->th_ta_p, copy, pthread,
  76. start_routine, 0);
  77. if (err == TD_OK)
  78. {
  79. uint32_t idx;
  80. for (idx = 0; idx < TD_EVENTSIZE; ++idx)
  81. {
  82. psaddr_t word;
  83. err = DB_GET_FIELD_LOCAL (word, th->th_ta_p, copy, pthread,
  84. eventbuf_eventmask_event_bits, idx);
  85. if (err != TD_OK)
  86. break;
  87. infop->ti_events.event_bits[idx] = (uintptr_t) word;
  88. }
  89. if (err == TD_NOAPLIC)
  90. memset (&infop->ti_events.event_bits[idx], 0,
  91. (TD_EVENTSIZE - idx) * sizeof infop->ti_events.event_bits[0]);
  92. }
  93. return err;
  94. }