1999-10-08 09:03:03 +02:00
|
|
|
/* Iterate over a process's threads.
|
2003-03-02 12:45:12 +01:00
|
|
|
Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
|
1999-10-08 09:03:03 +02:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 08:58:28 +02:00
|
|
|
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.
|
1999-10-08 09:03:03 +02:00
|
|
|
|
|
|
|
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
|
2001-07-06 08:58:28 +02:00
|
|
|
Lesser General Public License for more details.
|
1999-10-08 09:03:03 +02:00
|
|
|
|
2001-07-06 08:58:28 +02:00
|
|
|
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. */
|
1999-10-08 09:03:03 +02:00
|
|
|
|
|
|
|
#include "thread_dbP.h"
|
2002-02-05 01:57:29 +01:00
|
|
|
#include <linuxthreads/internals.h>
|
Update.
2000-02-27 Ulrich Drepper <drepper@redhat.com>
* conform/conformtest.pl (@headers): Add wordexp.h, wctype.h, wchar.h,
varargs.h, utmpx.h, utime.h, unistd.h, ulimit.h, ucontext.h, time.h,
termios.h, tar.h, sys/wait.h, sys/uio.h, sys/types.h, sys/times.h,
sys/timeb.h, sys/time.h, sys/statvfs.h, sys/stat.h, sys/shm.h,
sys/sem.h, and sys/resource.h.
Implement handling of allow-header.
* conform/data/fcntl.h-data: Correct various bugs.
* conform/data/fnmatch.h-data: Likewise.
* conform/data/math.h-data: Likewise.
* conform/data/ndbm.h-data: Likewise.
* conform/data/nl_types.h-data: Likewise.
* conform/data/poll.h-data: Likewise.
* conform/data/pthread.h-data: Likewise.
* conform/data/semaphore.h-data: Likewise.
* conform/data/setjmp.h-data: Likewise.
* conform/data/signal.h-data: Likewise.
* conform/data/stdarg.h-data: Likewise.
* conform/data/stddef.h-data: Likewise.
* conform/data/stdio.h-data: Likewise.
* conform/data/stdlib.h-data: Likewise.
* conform/data/string.h-data: Likewise.
* conform/data/strings.h-data: Likewise.
* conform/data/stropts.h-data: Likewise.
* conform/data/syslog.h-data: Likewise.
* conform/data/sys/ipc.h-data: Likewise.
* conform/data/sys/mman.h-data: Likewise.
* conform/data/sys/msg.h-data: Likewise.
* conform/data/tar.h-data: New file.
* conform/data/termios.h-data: New file.
* conform/data/time.h-data: New file.
* conform/data/ucontext.h-data: New file.
* conform/data/ulimit.h-data: New file.
* conform/data/unistd.h-data: New file.
* conform/data/utime.h-data: New file.
* conform/data/utmpx.h-data: New file.
* conform/data/varargs.h-data: New file.
* conform/data/wchar.h-data: New file.
* conform/data/wctype.h-data: New file.
* conform/data/wordexp.h-data: New file.
* conform/data/sys/resource.h-data: New file.
* conform/data/sys/sem.h-data: New file.
* conform/data/sys/shm.h-data: New file.
* conform/data/sys/stat.h-data: New file.
* conform/data/sys/statvfs.h-data: New file.
* conform/data/sys/time.h-data: New file.
* conform/data/sys/timeb.h-data: New file.
* conform/data/sys/times.h-data: New file.
* conform/data/sys/types.h-data: New file.
* conform/data/sys/uio.h-data: New file.
* conform/data/sys/wait.h-data: New file.
* grp/grp.h (getgrent_r): Declare only if __USE_GNU.
* include/sys/time.h (__itimes): Fix type of second parameter.
* io/sys/stat.h (S_IFLNK): Define also if __USE_XOPEN.
(S_ISVTX): Likewise.
* io/sys/statvfs.h: Define fsblkcnt_t and fsfilcnt_t.
* locale/langindo.h: Make ERA_YEAR, INT_CURR_SYMBOL, CURRENCY_SYMBOL,
MON_DECIMAL_POINT, MON_THOUSANDS_SEP, MON_GROUPING, POSITIVE_SIGN,
NEGATIVE_SIGN, INT_FRAC_DIGITS, FRAC_DIGITS, P_CS_PRECEDES,
P_SEP_BY_SPACE, N_CS_PRECEDES, N_SEP_BY_SPACE, P_SIGN_POSN,
N_SIGN_POSN, DECIMAL_POINT, THOUSANDS_SEP, GROUPING, YESEXPR,
NOEXPR, YESSTR, and NOSTR only available if __USE_GNU.
* math/bits/mathcalls.h: Don't declare tgamma and scalbn if only
__USE_XOPEN.
* posix/unistd.h: Don't define ptrdiff_t.
(sbrk): Correct type of parameter.
* sysdeps/generic/sbrk.c: Likewise.
* sysdeps/mach/hurd/sbrk.c: Likewise.
* posix/sys/types.h: Allow id_t, suseconds_t, fsblkcnt_t, and
fsfilcnt_t being defined elsewhere.
* resource/sys/resource.h: Define id_t.
If __USE_XOPEN use int for type of first parameter if getrlimit,
getrlimit64, setrlimit, setrlimit64, getrusage, getpriority, and
setpriority.
* sysdeps/generic/getpriority.c: Fix type of second parameter.
* sysdeps/generic/setpriority.c: Likewise.
* sysdeps/mach/hurd/getpriority.c: Likewise.
* sysdeps/mach/hurd/setpriority.c: Likewise.
* sysdeps/unix/sysv/irix4/getpriority.c: Likewise.
* sysdeps/unix/sysv/irix4/setpriority.c: Likewise.
* sysdeps/unix/sysv/linux/getpriority.c: Likewise.
* sysdeps/generic/utimes.c: Fix parameter of third parameter.
* sysdeps/mach/hurd/utimes.c: Likewise.
* sysdeps/posix/utimes.c: Likewise.
* sysdeps/generic/bits/shm.h: Define shmatt_t type and use it in
struct shmid_ds definition.
* sysdeps/gnu/bits/shm.h: Likewise.
* sysdeps/unix/sysv/linux/alpha/bits/shm.h: Likewise.
* sysdeps/unix/sysv/linux/bits/shm.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/bits/shm.h: Likewise.
* sysvipc/sys/shm.h: Define time_t.
* sysvipc/sys/sem.h (struct sembuf): Make sem_num field unsigned.
* sysdeps/gnu/bits/sem.h: Rename anonymous type struct sem_queue and
struct sem_undo to struct __sem_queue and struct __sem_undo resp.
* time/time.h: Define suseconds_t if not already done.
* sysdeps/unix/sysv/linux/bits/statvfs.h: Rename f_spare to __f_spare.
* sysdeps/unix/sysv/linux/fstatvfs64.c: Likewise.
* sysdeps/unix/sysv/linux/statvfs64.c: Likewise.
* sysdeps/unix/sysv/linux/internal_statvfs.c: Likewise.
* intl/bindtextdom.c: Use rwlock to avoid surprising results in
multithreaded applications.
* intl/dcigettext.c: Likewise.
* intl/textdomain.c: Likewise.
* intl/*.c: Update copyright.
* sysdeps/generic/bits/libc-lock.h: Define __libc_rwlock_* stubs.
2000-02-27 Andreas Jaeger <aj@suse.de>
* sysdeps/unix/sysv/linux/configure.in: Treat also "/usr/" as
prefix especially.
2000-02-27 Ulrich Drepper <drepper@redhat.com>
* po/de.po: Update from translation team.
* po/ko.po: Likewise.
2000-02-28 06:08:01 +01:00
|
|
|
#include <alloca.h>
|
1999-10-08 09:03:03 +02:00
|
|
|
|
1999-11-12 22:27:41 +01:00
|
|
|
static int
|
|
|
|
handle_descr (const td_thragent_t *ta, td_thr_iter_f *callback,
|
|
|
|
void *cbdata_p, td_thr_state_e state, int ti_pri,
|
|
|
|
size_t cnt, pthread_descr descr)
|
|
|
|
{
|
|
|
|
struct _pthread_descr_struct pds;
|
|
|
|
size_t sizeof_descr = ta->sizeof_descr;
|
|
|
|
td_thrhandle_t th;
|
|
|
|
|
2002-07-16 01:37:22 +02:00
|
|
|
if (descr == NULL)
|
|
|
|
{
|
|
|
|
/* No descriptor (yet). */
|
|
|
|
if (cnt == 0)
|
|
|
|
{
|
|
|
|
/* This is the main thread. Create a fake descriptor. */
|
|
|
|
memset (&pds, '\0', sizeof (pds));
|
|
|
|
|
|
|
|
/* Empty thread descriptor the thread library would create. */
|
2003-03-02 12:45:12 +01:00
|
|
|
#if !defined USE_TLS || !TLS_DTV_AT_TP
|
2002-07-16 01:37:22 +02:00
|
|
|
pds.p_header.data.self = &pds;
|
2003-03-02 12:45:12 +01:00
|
|
|
#endif
|
2002-07-16 01:37:22 +02:00
|
|
|
pds.p_nextlive = pds.p_prevlive = &pds;
|
|
|
|
pds.p_tid = PTHREAD_THREADS_MAX;
|
|
|
|
/* The init code also sets up p_lock, p_errnop, p_herrnop, and
|
|
|
|
p_userstack but this should not be necessary here. */
|
|
|
|
|
|
|
|
th.th_ta_p = (td_thragent_t *) ta;
|
2002-07-16 06:56:00 +02:00
|
|
|
th.th_unique = NULL;
|
2002-07-16 01:37:22 +02:00
|
|
|
if (callback (&th, cbdata_p) != 0)
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
/* All done successfully. */
|
|
|
|
return TD_OK;
|
|
|
|
}
|
|
|
|
else if (cnt == 1)
|
|
|
|
/* The manager is not yet started. No big deal. */
|
|
|
|
return TD_OK;
|
|
|
|
else
|
|
|
|
/* For every other thread this should not happen. */
|
|
|
|
return TD_ERR;
|
|
|
|
}
|
|
|
|
|
1999-11-12 22:27:41 +01:00
|
|
|
if (ps_pdread (ta->ph, descr, &pds, sizeof_descr) != PS_OK)
|
|
|
|
return TD_ERR; /* XXX Other error value? */
|
|
|
|
|
|
|
|
/* The manager thread must be handled special. The descriptor
|
|
|
|
exists but the thread only gets created when the first
|
|
|
|
`pthread_create' call is issued. A clear indication that this
|
|
|
|
happened is when the p_pid field is non-zero. */
|
|
|
|
if (cnt == 1 && pds.p_pid == 0)
|
|
|
|
return TD_OK;
|
|
|
|
|
|
|
|
/* Now test whether this thread matches the specified
|
|
|
|
conditions. */
|
|
|
|
|
|
|
|
/* Only if the priority level is as high or higher. */
|
|
|
|
if (pds.p_priority < ti_pri)
|
|
|
|
return TD_OK;
|
|
|
|
|
|
|
|
/* Test the state.
|
|
|
|
XXX This is incomplete. */
|
|
|
|
if (state != TD_THR_ANY_STATE)
|
|
|
|
return TD_OK;
|
|
|
|
|
|
|
|
/* XXX For now we ignore threads which are not running anymore.
|
|
|
|
The reason is that gdb tries to get the registers and fails.
|
|
|
|
In future we should have a special mode of the thread library
|
|
|
|
in which we keep the process around until the actual join
|
|
|
|
operation happened. */
|
|
|
|
if (pds.p_exited != 0)
|
|
|
|
return TD_OK;
|
|
|
|
|
|
|
|
/* Yep, it matches. Call the callback function. */
|
|
|
|
th.th_ta_p = (td_thragent_t *) ta;
|
|
|
|
th.th_unique = descr;
|
|
|
|
if (callback (&th, cbdata_p) != 0)
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
/* All done successfully. */
|
|
|
|
return TD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-08 09:03:03 +02:00
|
|
|
td_err_e
|
|
|
|
td_ta_thr_iter (const td_thragent_t *ta, 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)
|
|
|
|
{
|
1999-11-05 03:26:16 +01:00
|
|
|
int pthread_threads_max;
|
|
|
|
struct pthread_handle_struct *phc;
|
1999-11-12 22:27:41 +01:00
|
|
|
td_err_e result = TD_OK;
|
1999-10-08 09:03:03 +02:00
|
|
|
int cnt;
|
1999-11-05 03:26:16 +01:00
|
|
|
#ifdef ALL_THREADS_STOPPED
|
|
|
|
int num;
|
|
|
|
#else
|
|
|
|
# define num 1
|
|
|
|
#endif
|
1999-10-08 09:03:03 +02:00
|
|
|
|
2001-12-28 17:41:29 +01:00
|
|
|
LOG ("td_ta_thr_iter");
|
1999-10-08 09:03:03 +02:00
|
|
|
|
1999-11-05 03:26:16 +01:00
|
|
|
/* Test whether the TA parameter is ok. */
|
|
|
|
if (! ta_ok (ta))
|
|
|
|
return TD_BADTA;
|
|
|
|
|
|
|
|
pthread_threads_max = ta->pthread_threads_max;
|
|
|
|
phc = (struct pthread_handle_struct *) alloca (sizeof (phc[0])
|
|
|
|
* pthread_threads_max);
|
|
|
|
|
1999-11-12 22:27:41 +01:00
|
|
|
/* First read only the main thread and manager thread information. */
|
1999-11-03 07:13:09 +01:00
|
|
|
if (ps_pdread (ta->ph, ta->handles, phc,
|
1999-11-12 22:27:41 +01:00
|
|
|
sizeof (struct pthread_handle_struct) * 2) != PS_OK)
|
|
|
|
return TD_ERR; /* XXX Other error value? */
|
|
|
|
|
|
|
|
/* Now handle these descriptors. */
|
|
|
|
result = handle_descr (ta, callback, cbdata_p, state, ti_pri, 0,
|
|
|
|
phc[0].h_descr);
|
|
|
|
if (result != TD_OK)
|
|
|
|
return result;
|
|
|
|
result = handle_descr (ta, callback, cbdata_p, state, ti_pri, 1,
|
|
|
|
phc[1].h_descr);
|
|
|
|
if (result != TD_OK)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* Read all the descriptors. */
|
1999-11-13 00:31:39 +01:00
|
|
|
if (ps_pdread (ta->ph, ta->handles + 2, &phc[2],
|
1999-11-12 22:27:41 +01:00
|
|
|
(sizeof (struct pthread_handle_struct)
|
|
|
|
* (pthread_threads_max - 2))) != PS_OK)
|
1999-11-03 07:13:09 +01:00
|
|
|
return TD_ERR; /* XXX Other error value? */
|
|
|
|
|
1999-11-05 03:26:16 +01:00
|
|
|
#ifdef ALL_THREADS_STOPPED
|
1999-11-03 07:13:09 +01:00
|
|
|
/* Read the number of currently active threads. */
|
1999-11-05 03:26:16 +01:00
|
|
|
if (ps_pdread (ta->ph, ta->pthread_handles_num, &num, sizeof (int)) != PS_OK)
|
1999-11-03 07:13:09 +01:00
|
|
|
return TD_ERR; /* XXX Other error value? */
|
1999-11-05 03:26:16 +01:00
|
|
|
#endif
|
1999-11-03 07:13:09 +01:00
|
|
|
|
1999-10-08 09:03:03 +02:00
|
|
|
/* Now get all descriptors, one after the other. */
|
1999-11-13 00:11:22 +01:00
|
|
|
for (cnt = 2; cnt < pthread_threads_max && num > 0; ++cnt)
|
1999-11-03 07:13:09 +01:00
|
|
|
if (phc[cnt].h_descr != NULL)
|
|
|
|
{
|
1999-11-13 00:11:22 +01:00
|
|
|
#ifdef ALL_THREADS_STOPPED
|
|
|
|
/* First count this active thread. */
|
|
|
|
--num;
|
|
|
|
#endif
|
|
|
|
|
1999-11-12 22:27:41 +01:00
|
|
|
result = handle_descr (ta, callback, cbdata_p, state, ti_pri, cnt,
|
|
|
|
phc[cnt].h_descr);
|
|
|
|
if (result != TD_OK)
|
|
|
|
break;
|
1999-11-03 07:13:09 +01:00
|
|
|
}
|
1999-10-08 09:03:03 +02:00
|
|
|
|
1999-11-12 22:27:41 +01:00
|
|
|
return result;
|
1999-10-08 09:03:03 +02:00
|
|
|
}
|