td_ta_event_getmsg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Retrieve event.
  2. Copyright (C) 1999-2026 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. <https://www.gnu.org/licenses/>. */
  15. #include <stddef.h>
  16. #include <string.h>
  17. #include "thread_dbP.h"
  18. td_err_e
  19. td_ta_event_getmsg (const td_thragent_t *ta_arg, td_event_msg_t *msg)
  20. {
  21. td_thragent_t *const ta = (td_thragent_t *) ta_arg;
  22. td_err_e err;
  23. psaddr_t eventbuf, eventnum, eventdata;
  24. psaddr_t thp, next;
  25. void *copy;
  26. /* XXX I cannot think of another way but using a static variable. */
  27. /* XXX Use at least __thread once it is possible. */
  28. static td_thrhandle_t th;
  29. LOG ("td_thr_event_getmsg");
  30. /* Test whether the TA parameter is ok. */
  31. if (! ta_ok (ta))
  32. return TD_BADTA;
  33. /* Get the pointer to the thread descriptor with the last event. */
  34. err = DB_GET_VALUE (thp, ta, __nptl_last_event, 0);
  35. if (err != TD_OK)
  36. return err;
  37. if (thp == NULL)
  38. /* Nothing waiting. */
  39. return TD_NOMSG;
  40. /* Copy the event message buffer in from the inferior. */
  41. err = DB_GET_FIELD_ADDRESS (eventbuf, ta, thp, pthread, eventbuf, 0);
  42. if (err == TD_OK)
  43. err = DB_GET_STRUCT (copy, ta, eventbuf, td_eventbuf_t);
  44. if (err != TD_OK)
  45. return err;
  46. /* Read the event details from the target thread. */
  47. err = DB_GET_FIELD_LOCAL (eventnum, ta, copy, td_eventbuf_t, eventnum, 0);
  48. if (err != TD_OK)
  49. return err;
  50. /* If the structure is on the list there better be an event recorded. */
  51. if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
  52. return TD_DBERR;
  53. /* Fill the user's data structure. */
  54. err = DB_GET_FIELD_LOCAL (eventdata, ta, copy, td_eventbuf_t, eventdata, 0);
  55. if (err != TD_OK)
  56. return err;
  57. /* Generate the thread descriptor. */
  58. th.th_ta_p = (td_thragent_t *) ta;
  59. th.th_unique = thp;
  60. /* Fill the user's data structure. */
  61. msg->msg.data = (uintptr_t) eventdata;
  62. msg->event = (uintptr_t) eventnum;
  63. msg->th_p = &th;
  64. /* And clear the event message in the target. */
  65. memset (copy, 0, ta->ta_sizeof_td_eventbuf_t);
  66. err = DB_PUT_STRUCT (ta, eventbuf, td_eventbuf_t, copy);
  67. if (err != TD_OK)
  68. return err;
  69. /* Get the pointer to the next descriptor with an event. */
  70. err = DB_GET_FIELD (next, ta, thp, pthread, nextevent, 0);
  71. if (err != TD_OK)
  72. return err;
  73. /* Store the pointer in the list head variable. */
  74. err = DB_PUT_VALUE (ta, __nptl_last_event, 0, next);
  75. if (err != TD_OK)
  76. return err;
  77. if (next != NULL)
  78. /* Clear the next pointer in the current descriptor. */
  79. err = DB_PUT_FIELD (ta, thp, pthread, nextevent, 0, NULL);
  80. return err;
  81. }