root/threadinfo.h
/* [<][>][^][v][top][bottom][index][help] */
1 #ifndef THREADINFO_H
2 #define THREADINFO_H
3
4 #include <ucontext.h>
5 #include <signal.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/syscall.h>
10 #include <linux/version.h>
11 #include "syscallwrappers.h" /* for _real_syscall */
12 #include "protectedfds.h"
13 #include "mtcp/restore_libc.h"
14
15 // For i386 and x86_64, SETJMP currently has bugs. Don't turn this
16 // on for them until they are debugged.
17 // Default is to use setcontext/getcontext.
18 #if defined(__arm__) || defined(__aarch64__)
19 # define SETJMP /* setcontext/getcontext not defined for ARM glibc */
20 #endif
21
22 #ifdef SETJMP
23 # include <setjmp.h>
24 #else
25 # include <ucontext.h>
26 #endif
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32
33 #define GETTID() (pid_t)_real_syscall(SYS_gettid)
34 #define TGKILL(pid,tid,sig) _real_syscall(SYS_tgkill, pid, tid, sig)
35
36 pid_t dmtcp_get_real_tid() __attribute((weak));
37 pid_t dmtcp_get_real_pid() __attribute((weak));
38 int dmtcp_real_tgkill(pid_t pid, pid_t tid, int sig) __attribute((weak));
39
40 #define THREAD_REAL_PID() \
41 (dmtcp_get_real_pid != NULL ? dmtcp_get_real_pid() : getpid())
42
43 #define THREAD_REAL_TID() \
44 (dmtcp_get_real_tid != NULL ? dmtcp_get_real_tid() : GETTID())
45
46 #define THREAD_TGKILL(pid, tid, sig) \
47 (dmtcp_real_tgkill != NULL ? dmtcp_real_tgkill(pid,tid,sig) \
48 : TGKILL(pid, tid, sig))
49
50 typedef int (*fptr)(void*);
51
52 typedef enum ThreadState {
53 ST_RUNNING,
54 ST_SIGNALED,
55 ST_SUSPINPROG,
56 ST_SUSPENDED,
57 ST_ZOMBIE,
58 ST_CKPNTHREAD
59 } ThreadState;
60
61 typedef struct Thread Thread;
62
63 struct Thread {
64 pid_t tid;
65 Thread *next;
66 Thread *prev;
67 int state;
68
69 int (*fn)(void *);
70 void *arg;
71 int flags;
72 pid_t *ptid;
73 pid_t *ctid;
74
75 pid_t virtual_tid;
76 sigset_t sigblockmask; // blocked signals
77 sigset_t sigpending; // pending signals
78
79 void *saved_sp; // at restart, we use a temporary stack just
80 // beyond original stack (red zone)
81
82 ThreadTLSInfo tlsInfo;
83
84 ///JA: new code ported from v54b
85 #ifdef SETJMP
86 sigjmp_buf jmpbuf; // sigjmp_buf saved by sigsetjmp on ckpt
87 #else
88 ucontext_t savctx; // context saved on suspend
89 #endif
90
91 };
92
93 #ifdef __cplusplus
94 }
95 #endif
96
97 #endif