]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl_db/td_ta_event_getmsg.c
nptl: Move pthread_attr_setinheritsched implementation into libc.
[thirdparty/glibc.git] / nptl_db / td_ta_event_getmsg.c
CommitLineData
76a50749 1/* Retrieve event.
04277e02 2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
76a50749
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
76a50749
UD
19
20#include <stddef.h>
21#include <string.h>
22
23#include "thread_dbP.h"
24
25
26td_err_e
7f08f55a 27td_ta_event_getmsg (const td_thragent_t *ta_arg, td_event_msg_t *msg)
76a50749 28{
7f08f55a
RM
29 td_thragent_t *const ta = (td_thragent_t *) ta_arg;
30 td_err_e err;
31 psaddr_t eventbuf, eventnum, eventdata;
32 psaddr_t thp, next;
33 void *copy;
34
76a50749
UD
35 /* XXX I cannot think of another way but using a static variable. */
36 /* XXX Use at least __thread once it is possible. */
37 static td_thrhandle_t th;
38
7f08f55a 39 LOG ("td_thr_event_getmsg");
76a50749
UD
40
41 /* Test whether the TA parameter is ok. */
42 if (! ta_ok (ta))
43 return TD_BADTA;
44
45 /* Get the pointer to the thread descriptor with the last event. */
7f08f55a
RM
46 err = DB_GET_VALUE (thp, ta, __nptl_last_event, 0);
47 if (err != TD_OK)
48 return err;
76a50749 49
7f08f55a 50 if (thp == 0)
58a851f1 51 /* Nothing waiting. */
76a50749
UD
52 return TD_NOMSG;
53
7f08f55a
RM
54 /* Copy the event message buffer in from the inferior. */
55 err = DB_GET_FIELD_ADDRESS (eventbuf, ta, thp, pthread, eventbuf, 0);
56 if (err == TD_OK)
57 err = DB_GET_STRUCT (copy, ta, eventbuf, td_eventbuf_t);
58 if (err != TD_OK)
59 return err;
60
61 /* Read the event details from the target thread. */
62 err = DB_GET_FIELD_LOCAL (eventnum, ta, copy, td_eventbuf_t, eventnum, 0);
63 if (err != TD_OK)
64 return err;
76a50749 65 /* If the structure is on the list there better be an event recorded. */
7f08f55a 66 if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
8cfb7315 67 return TD_DBERR;
76a50749 68
7f08f55a
RM
69 /* Fill the user's data structure. */
70 err = DB_GET_FIELD_LOCAL (eventdata, ta, copy, td_eventbuf_t, eventdata, 0);
71 if (err != TD_OK)
72 return err;
73
76a50749
UD
74 /* Generate the thread descriptor. */
75 th.th_ta_p = (td_thragent_t *) ta;
7f08f55a 76 th.th_unique = thp;
76a50749
UD
77
78 /* Fill the user's data structure. */
7f08f55a
RM
79 msg->msg.data = (uintptr_t) eventdata;
80 msg->event = (uintptr_t) eventnum;
76a50749 81 msg->th_p = &th;
76a50749 82
8cfb7315 83 /* And clear the event message in the target. */
7f08f55a
RM
84 memset (copy, 0, ta->ta_sizeof_td_eventbuf_t);
85 err = DB_PUT_STRUCT (ta, eventbuf, td_eventbuf_t, copy);
86 if (err != TD_OK)
87 return err;
8cfb7315 88
76a50749 89 /* Get the pointer to the next descriptor with an event. */
7f08f55a
RM
90 err = DB_GET_FIELD (next, ta, thp, pthread, nextevent, 0);
91 if (err != TD_OK)
92 return err;
8cfb7315 93
76a50749 94 /* Store the pointer in the list head variable. */
7f08f55a
RM
95 err = DB_PUT_VALUE (ta, __nptl_last_event, 0, next);
96 if (err != TD_OK)
97 return err;
98
99 if (next != 0)
100 /* Clear the next pointer in the current descriptor. */
101 err = DB_PUT_FIELD (ta, thp, pthread, nextevent, 0, 0);
102
103 return err;
76a50749 104}