Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
glibc
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security
Insights
Files
d11dc9e
abilist
aout
argp
assert
bits
catgets
conf
conform
crypt
csu
ctype
debug
dirent
dlfcn
elf
gmon
gnulib
grp
hesiod
hurd
iconv
iconvdata
include
inet
intl
io
libidn
libio
locale
localedata
login
mach
malloc
manual
math
misc
nis
nptl
nptl_db
ChangeLog
Makefile
Versions
db_info.c
fetch-value.c
proc_service.h
shlib-versions
structs.def
td_init.c
td_log.c
td_symbol_list.c
td_ta_clear_event.c
td_ta_delete.c
td_ta_enable_stats.c
td_ta_event_addr.c
td_ta_event_getmsg.c
td_ta_get_nthreads.c
td_ta_get_ph.c
td_ta_get_stats.c
td_ta_map_id2thr.c
td_ta_map_lwp2thr.c
td_ta_new.c
td_ta_reset_stats.c
td_ta_set_event.c
td_ta_setconcurrency.c
td_ta_thr_iter.c
td_ta_tsd_iter.c
td_thr_clear_event.c
td_thr_dbresume.c
td_thr_dbsuspend.c
td_thr_event_enable.c
td_thr_event_getmsg.c
td_thr_get_info.c
td_thr_getfpregs.c
td_thr_getgregs.c
td_thr_getxregs.c
td_thr_getxregsize.c
td_thr_set_event.c
td_thr_setfpregs.c
td_thr_setgregs.c
td_thr_setprio.c
td_thr_setsigpending.c
td_thr_setxregs.c
td_thr_sigsetmask.c
td_thr_tls_get_addr.c
td_thr_tlsbase.c
td_thr_tsd.c
td_thr_validate.c
thread_db.h
thread_dbP.h
nscd
nss
po
posix
pwd
resolv
resource
rt
scripts
setjmp
shadow
signal
socket
soft-fp
stdio-common
stdlib
streams
string
sunrpc
sysdeps
sysvipc
termios
time
timezone
wcsmbs
wctype
.cvsignore
BUGS
CANCEL-FCT-WAIVE
CANCEL-FILE-WAIVE
CONFORMANCE
COPYING
COPYING.LIB
ChangeLog
ChangeLog.1
ChangeLog.10
ChangeLog.11
ChangeLog.12
ChangeLog.13
ChangeLog.14
ChangeLog.15
ChangeLog.16
ChangeLog.2
ChangeLog.3
ChangeLog.4
ChangeLog.5
ChangeLog.6
ChangeLog.7
ChangeLog.8
ChangeLog.9
FAQ
FAQ.in
INSTALL
LICENSES
Makeconfig
Makefile
Makefile.in
Makerules
NAMESPACE
NEWS
NOTES
PROJECTS
README
README.libm
README.template
Rules
Versions.def
WUR-REPORT
abi-tags
aclocal.m4
config-name.in
config.h.in
config.make.in
configure
configure.in
cppflags-iterator.mk
extra-lib.mk
extra-modules.mk
o-iterator.mk
shlib-versions
test-skeleton.c
tls.make.c
version.h
Breadcrumbs
glibc
/
nptl_db
/
td_ta_thr_iter.c
Blame
Blame
Latest commit
History
History
172 lines (144 loc) · 5.58 KB
Breadcrumbs
glibc
/
nptl_db
/
td_ta_thr_iter.c
Top
File metadata and controls
Code
Blame
172 lines (144 loc) · 5.58 KB
Raw
/* Iterate over a process's threads. Copyright (C) 1999,2000,2001,2002,2003,2004,2007,2008 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 1999. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "thread_dbP.h" static td_err_e iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback, void *cbdata_p, td_thr_state_e state, int ti_pri, psaddr_t head, bool fake_empty, pid_t match_pid) { td_err_e err; psaddr_t next, ofs; void *copy; /* Test the state. XXX This is incomplete. Normally this test should be in the loop. */ if (state != TD_THR_ANY_STATE) return TD_OK; err = DB_GET_FIELD (next, ta, head, list_t, next, 0); if (err != TD_OK) return err; if (next == 0 && fake_empty) { /* __pthread_initialize_minimal has not run. There is just the main thread to return. We cannot rely on its thread register. They sometimes contain garbage that would confuse us, left by the kernel at exec. So if it looks like initialization is incomplete, we only fake a special descriptor for the initial thread. */ td_thrhandle_t th = { ta, 0 }; return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK; } /* Cache the offset from struct pthread to its list_t member. */ err = DB_GET_FIELD_ADDRESS (ofs, ta, 0, pthread, list, 0); if (err != TD_OK) return err; if (ta->ta_sizeof_pthread == 0) { err = _td_check_sizeof (ta, &ta->ta_sizeof_pthread, SYM_SIZEOF_pthread); if (err != TD_OK) return err; } copy = __alloca (ta->ta_sizeof_pthread); while (next != head) { psaddr_t addr, schedpolicy, schedprio; addr = next - (ofs - (psaddr_t) 0); if (next == 0 || addr == 0) /* Sanity check. */ return TD_DBERR; /* Copy the whole descriptor in once so we can access the several fields locally. Excess copying in one go is much better than multiple ps_pdread calls. */ if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK) return TD_ERR; /* Verify that this thread's pid field matches the child PID. If its pid field is negative, it's about to do a fork or it is the sole thread in a fork child. */ psaddr_t pid; err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, pid, 0); if (err == TD_OK && (pid_t) (uintptr_t) pid < 0) { if (-(pid_t) (uintptr_t) pid == match_pid) /* It is about to do a fork, but is really still the parent PID. */ pid = (psaddr_t) (uintptr_t) match_pid; else /* It must be a fork child, whose new PID is in the tid field. */ err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, tid, 0); } if (err != TD_OK) break; if ((pid_t) (uintptr_t) pid == match_pid) { err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread, schedpolicy, 0); if (err != TD_OK) break; err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread, schedparam_sched_priority, 0); if (err != TD_OK) break; /* Now test whether this thread matches the specified conditions. */ /* Only if the priority level is as high or higher. */ int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER ? 0 : (uintptr_t) schedprio); if (descr_pri >= ti_pri) { /* Yep, it matches. Call the callback function. */ td_thrhandle_t th; th.th_ta_p = (td_thragent_t *) ta; th.th_unique = addr; if (callback (&th, cbdata_p) != 0) return TD_DBERR; } } /* Get the pointer to the next element. */ err = DB_GET_FIELD_LOCAL (next, ta, copy + (ofs - (psaddr_t) 0), list_t, next, 0); if (err != TD_OK) break; } return err; } td_err_e td_ta_thr_iter (const td_thragent_t *ta_arg, td_thr_iter_f *callback, void *cbdata_p, td_thr_state_e state, int ti_pri, sigset_t *ti_sigmask_p, unsigned int ti_user_flags) { td_thragent_t *const ta = (td_thragent_t *) ta_arg; td_err_e err; psaddr_t list = 0; LOG ("td_ta_thr_iter"); /* Test whether the TA parameter is ok. */ if (! ta_ok (ta)) return TD_BADTA; /* The thread library keeps two lists for the running threads. One list contains the thread which are using user-provided stacks (this includes the main thread) and the other includes the threads for which the thread library allocated the stacks. We have to iterate over both lists separately. We start with the list of threads with user-defined stacks. */ pid_t pid = ps_getpid (ta->ph); err = DB_GET_SYMBOL (list, ta, __stack_user); if (err == TD_OK) err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri, list, true, pid); /* And the threads with stacks allocated by the implementation. */ if (err == TD_OK) err = DB_GET_SYMBOL (list, ta, stack_used); if (err == TD_OK) err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri, list, false, pid); return err; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
You can’t perform that action at this time.