]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl_db/td_thr_event_getmsg.c
nptl: Move pthread_attr_setinheritsched implementation into libc.
[thirdparty/glibc.git] / nptl_db / td_thr_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 19
76a50749 20#include "thread_dbP.h"
7f08f55a 21#include <assert.h>
76a50749
UD
22
23
24td_err_e
25td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
26{
7f08f55a
RM
27 td_err_e err;
28 psaddr_t eventbuf, eventnum, eventdata;
29 psaddr_t thp, prevp;
30 void *copy;
76a50749
UD
31
32 LOG ("td_thr_event_getmsg");
33
7f08f55a
RM
34 /* Copy the event message buffer in from the inferior. */
35 err = DB_GET_FIELD_ADDRESS (eventbuf, th->th_ta_p, th->th_unique, pthread,
36 eventbuf, 0);
37 if (err == TD_OK)
38 err = DB_GET_STRUCT (copy, th->th_ta_p, eventbuf, td_eventbuf_t);
39 if (err != TD_OK)
40 return err;
76a50749
UD
41
42 /* Check whether an event occurred. */
7f08f55a
RM
43 err = DB_GET_FIELD_LOCAL (eventnum, th->th_ta_p, copy,
44 td_eventbuf_t, eventnum, 0);
45 if (err != TD_OK)
46 return err;
47 if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
76a50749
UD
48 /* Nothing. */
49 return TD_NOMSG;
50
51 /* Fill the user's data structure. */
7f08f55a
RM
52 err = DB_GET_FIELD_LOCAL (eventdata, th->th_ta_p, copy,
53 td_eventbuf_t, eventdata, 0);
54 if (err != TD_OK)
55 return err;
56
57 msg->msg.data = (uintptr_t) eventdata;
58 msg->event = (uintptr_t) eventnum;
76a50749 59 msg->th_p = th;
76a50749
UD
60
61 /* And clear the event message in the target. */
7f08f55a
RM
62 memset (copy, 0, th->th_ta_p->ta_sizeof_td_eventbuf_t);
63 err = DB_PUT_STRUCT (th->th_ta_p, eventbuf, td_eventbuf_t, copy);
64 if (err != TD_OK)
65 return err;
76a50749 66
90758db4
RM
67 /* Get the pointer to the thread descriptor with the last event.
68 If it doesn't match TH, then walk down the list until we find it.
69 We must splice it out of the list so that there is no dangling
70 pointer to it later when it dies. */
7f08f55a
RM
71 err = DB_GET_SYMBOL (prevp, th->th_ta_p, __nptl_last_event);
72 if (err != TD_OK)
73 return err;
74 err = DB_GET_VALUE (thp, th->th_ta_p, __nptl_last_event, 0);
75 if (err != TD_OK)
76 return err;
90758db4 77
90758db4
RM
78 while (thp != 0)
79 {
7f08f55a
RM
80 psaddr_t next;
81 err = DB_GET_FIELD (next, th->th_ta_p, th->th_unique, pthread,
82 nextevent, 0);
83 if (err != TD_OK)
84 return err;
90758db4
RM
85
86 if (next == thp)
87 return TD_DBERR;
88
89 if (thp == th->th_unique)
90 {
91 /* PREVP points at this thread, splice it out. */
7f08f55a
RM
92 psaddr_t next_nextp;
93 err = DB_GET_FIELD_ADDRESS (next_nextp, th->th_ta_p, next, pthread,
94 nextevent, 0);
95 assert (err == TD_OK); /* We used this field before. */
96 if (prevp == next_nextp)
90758db4
RM
97 return TD_DBERR;
98
7f08f55a
RM
99 err = _td_store_value (th->th_ta_p,
100 th->th_ta_p->ta_var___nptl_last_event, -1,
101 0, prevp, next);
102 if (err != TD_OK)
103 return err;
90758db4
RM
104
105 /* Now clear this thread's own next pointer so it's not dangling
106 when the thread resumes and then chains on for its next event. */
7f08f55a 107 return DB_PUT_FIELD (th->th_ta_p, thp, pthread, nextevent, 0, 0);
90758db4
RM
108 }
109
7f08f55a
RM
110 err = DB_GET_FIELD_ADDRESS (prevp, th->th_ta_p, thp, pthread,
111 nextevent, 0);
112 assert (err == TD_OK); /* We used this field before. */
90758db4
RM
113 thp = next;
114 }
115
116 /* Ack! This should not happen. */
117 return TD_DBERR;
76a50749 118}