4
* LinuxThreads specific stuff.
10
#include <limits.h> /* PTHREAD_THREADS_MAX */
17
#include "linuxthreads.h"
19
#define AT_INT(intval) *((int32_t*)(intval))
22
* Internal LinuxThreads variables.
23
* Official interface exposed to GDB.
26
extern volatile int __pthread_threads_debug;
27
extern volatile char __pthread_handles;
28
extern char __pthread_initial_thread;
29
/*extern volatile Elf32_Sym* __pthread_manager_thread;*/
30
extern const int __pthread_sizeof_handle;
31
extern const int __pthread_offsetof_descr;
32
extern const int __pthread_offsetof_pid;
33
extern volatile int __pthread_handles_num;
40
linuxthreads_notify_others( const int signotify)
42
const pid_t mypid = getpid();
43
//const pthread_t mytid = pthread_self();
46
int threads[PTHREAD_THREADS_MAX];
49
TRACE_FPRINTF((stderr, "theadcount:%d\n", __pthread_handles_num));
50
if (__pthread_handles_num==2) {
51
/* no threads beside the initial thread */
54
/*assert(maxthreads>=3);
55
assert(maxthreads>=__pthread_handles_num+2);*/
57
// take the initial thread with us
58
pid = AT_INT(&__pthread_initial_thread + __pthread_offsetof_pid);
59
if (pid!=mypid && pid!=0)
60
threads[threadcount++] = pid;
61
// don't know why, but always handles[0]==handles[1]
62
for (i=1; i<__pthread_handles_num; ++i) {
63
const int descr = AT_INT(&__pthread_handles+i*__pthread_sizeof_handle+__pthread_offsetof_descr);
65
pid = AT_INT(descr+__pthread_offsetof_pid);
66
if (pid!=mypid && pid!=0)
67
threads[threadcount++] = pid;
69
/* TRACE_FPRINTF((stderr, "Stopping threads...")); */
70
//for (i=0; i<threadcount; ++i) {
71
// /* TRACE_FPRINTF((stderr, "%d ", threads[i])); */
73
// kill(threads[i], SIGSTOP); /* Tell thread to stop */
75
/* TRACE_FPRINTF((stderr, " done!\n")); */
76
for (i=0; i<threadcount; ++i) {
77
TRACE_FPRINTF((stderr, "--- NOTIFYING %d\n", threads[i]));
78
kill(threads[i], signotify); /* Tell to print stack trace */
79
/* TRACE_FPRINTF((stderr, "--- WAITING FOR %d\n", threads[i])); */
80
/*pause(); Wait for confirmation. */
82
for (i=0; i<threadcount; ++i)
84
for (i=0; i<threadcount; ++i) {
85
TRACE_FPRINTF((stderr, "--- KILLING %d\n", threads[i]));
86
kill(threads[i], SIGKILL); /* Tell thread die :) */
88
return __pthread_handles_num;