/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- FOREACH_PIDVIRT_WRAPPER
- FOREACH_SYSVIPC_CTL_WRAPPER
- FOREACH_FOPEN_WRAPPER
1 /****************************************************************************
2 * Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
3 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu *
4 * *
5 * This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src). *
6 * *
7 * DMTCP:dmtcp/src is free software: you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * DMTCP:dmtcp/src is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with DMTCP:dmtcp/src. If not, see *
19 * <http://www.gnu.org/licenses/>. *
20 ****************************************************************************/
21
22 #ifndef PIDWRAPPERS_H
23 #define PIDWRAPPERS_H
24
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif
28
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <signal.h>
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 #include <sys/ptrace.h>
36 // This was needed for 64-bit SUSE LINUX Enterprise Server 9 (Linux 2.6.5):
37 #ifndef PTRACE_GETEVENTMSG
38 # include <sys/ptrace.h>
39 #endif
40 #include <stdarg.h>
41 #if defined(__arm__) || defined(__aarch64__)
42 struct user_desc {int dummy;}; /* <asm/ldt.h> is missing in Ubuntu 14.04 */
43 #else
44 # include <asm/ldt.h> // Needed for 'struct user_desc' (arg 6 of __clone)
45 #endif
46 #include <stdio.h>
47 #include <thread_db.h>
48 #include <sys/procfs.h>
49 #include <syslog.h>
50 #include <sys/ipc.h>
51 #include <sys/shm.h>
52 #include <sys/sem.h>
53 #include <sys/msg.h>
54 #include <sys/stat.h>
55 #include <sys/mman.h>
56 #include <sys/epoll.h>
57 #include <dirent.h>
58 #include <unistd.h>
59 #include <pwd.h>
60 #include <grp.h>
61 #include <netdb.h>
62 #include <mqueue.h>
63
64 #include "dmtcp.h"
65
66 // Keep in sync with dmtcp/src/constants.h
67 #define ENV_VAR_VIRTUAL_PID "DMTCP_VIRTUAL_PID"
68
69 #ifdef __cplusplus
70 extern "C"
71 {
72 #endif
73
74 union semun {
75 int val; /* Value for SETVAL */
76 struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
77 unsigned short *array; /* Array for GETALL, SETALL */
78 struct seminfo *__buf; /* Buffer for IPC_INFO (Linux-specific) */
79 };
80
81 void dmtcpResetPidPpid();
82 void dmtcpResetTid(pid_t tid);
83
84 LIB_PRIVATE void *_real_dlsym(void *handle, const char *symbol);
85
86 /* The following function are defined in pidwrappers.cpp */
87 LIB_PRIVATE pid_t dmtcp_gettid();
88 LIB_PRIVATE int dmtcp_tkill(int tid, int sig);
89 LIB_PRIVATE int dmtcp_tgkill(int tgid, int tid, int sig);
90
91 #define FOREACH_PIDVIRT_WRAPPER(MACRO)\
92 MACRO(fork) \
93 MACRO(__clone) \
94 MACRO(gettid) \
95 MACRO(tkill) \
96 MACRO(tgkill) \
97 MACRO(syscall) \
98 MACRO(shmget) \
99 MACRO(shmat) \
100 MACRO(shmdt) \
101 MACRO(mq_notify) \
102 MACRO(clock_getcpuclockid)\
103 MACRO(timer_create) \
104 MACRO(getppid) \
105 MACRO(tcgetsid) \
106 MACRO(tcgetpgrp) \
107 MACRO(tcsetpgrp) \
108 MACRO(getpgrp) \
109 MACRO(setpgrp) \
110 MACRO(getpgid) \
111 MACRO(setpgid) \
112 MACRO(getsid) \
113 MACRO(setsid) \
114 MACRO(kill) \
115 MACRO(wait) \
116 MACRO(waitpid) \
117 MACRO(waitid) \
118 MACRO(wait3) \
119 MACRO(wait4) \
120 MACRO(ioctl) \
121 MACRO(setgid) \
122 MACRO(setuid) \
123 MACRO(ptrace ) \
124 MACRO(pthread_exit ) \
125 MACRO(fcntl) \
126 MACRO(open) \
127 MACRO(open64) \
128 MACRO(fopen64) \
129 MACRO(__xstat) \
130 MACRO(__xstat64) \
131 MACRO(__lxstat) \
132 MACRO(__lxstat64) \
133 MACRO(readlink)
134
135 #define FOREACH_SYSVIPC_CTL_WRAPPER(MACRO)\
136 MACRO(shmctl) \
137 MACRO(semctl) \
138 MACRO(msgctl)
139
140 #define FOREACH_FOPEN_WRAPPER(MACRO)\
141 MACRO(fopen) \
142 MACRO(fclose)
143
144 # define PIDVIRT_ENUM(x) pid_enum_ ## x
145 # define PIDVIRT_GEN_ENUM(x) PIDVIRT_ENUM(x),
146 typedef enum {
147 FOREACH_PIDVIRT_WRAPPER(PIDVIRT_GEN_ENUM)
148 FOREACH_SYSVIPC_CTL_WRAPPER(PIDVIRT_GEN_ENUM)
149 FOREACH_FOPEN_WRAPPER(PIDVIRT_GEN_ENUM)
150 numPidVirtWrappers
151 } PidVirtWrapperOffset;
152
153 pid_t _real_fork();
154 int _real_clone ( int ( *fn ) ( void *arg ), void *child_stack, int flags,
155 void *arg, int *parent_tidptr, struct user_desc *newtls,
156 int *child_tidptr );
157
158 pid_t _real_gettid(void);
159 int _real_tkill(int tid, int sig);
160 int _real_tgkill(int tgid, int tid, int sig);
161
162 long int _real_syscall(long int sys_num, ... );
163
164 /* System V shared memory */
165 int _real_shmget(key_t key, size_t size, int shmflg);
166 void* _real_shmat(int shmid, const void *shmaddr, int shmflg);
167 int _real_shmdt(const void *shmaddr);
168 int _real_shmctl(int shmid, int cmd, struct shmid_ds *buf);
169 int _real_semctl(int semid, int semnum, int cmd, ...);
170 int _real_msgctl(int msqid, int cmd, struct msqid_ds *buf);
171 int _real_mq_notify(mqd_t mqdes, const struct sigevent *sevp);
172 int _real_clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
173 int _real_timer_create(clockid_t clockid,
174 struct sigevent *sevp,
175 timer_t *timerid);
176
177 pid_t _real_getpid(void);
178 pid_t _real_getppid(void);
179
180 pid_t _real_tcgetsid(int fd);
181 pid_t _real_tcgetpgrp(int fd);
182 int _real_tcsetpgrp(int fd, pid_t pgrp);
183
184 pid_t _real_getpgrp(void);
185 pid_t _real_setpgrp(void);
186
187 pid_t _real_getpgid(pid_t pid);
188 int _real_setpgid(pid_t pid, pid_t pgid);
189
190 pid_t _real_getsid(pid_t pid);
191 pid_t _real_setsid(void);
192
193 int _real_kill(pid_t pid, int sig);
194
195 pid_t _real_wait(__WAIT_STATUS stat_loc);
196 pid_t _real_waitpid(pid_t pid, int *stat_loc, int options);
197 int _real_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
198
199 pid_t _real_wait3(__WAIT_STATUS status, int options, struct rusage *rusage);
200 pid_t _real_wait4(pid_t pid, __WAIT_STATUS status, int options,
201 struct rusage *rusage);
202 LIB_PRIVATE extern int send_sigwinch;
203 int _real_ioctl(int d, unsigned long int request, ...) __THROW;
204
205 int _real_setgid(gid_t gid);
206 int _real_setuid(uid_t uid);
207
208 long _real_ptrace ( enum __ptrace_request request, pid_t pid, void *addr,
209 void *data);
210
211 void _real_pthread_exit (void *retval);
212 int _real_fcntl(int fd, int cmd, void *arg);
213
214 int _real_open(const char *pathname, int flags, ...);
215 int _real_open64(const char *pathname, int flags, ...);
216 FILE* _real_fopen(const char *path, const char *mode);
217 FILE* _real_fopen64(const char *path, const char *mode);
218 int _real_fclose(FILE *fp);
219 int _real_xstat(int vers, const char *path, struct stat *buf);
220 int _real_xstat64(int vers, const char *path, struct stat64 *buf);
221 int _real_lxstat(int vers, const char *path, struct stat *buf);
222 int _real_lxstat64(int vers, const char *path, struct stat64 *buf);
223 ssize_t _real_readlink(const char *path, char *buf, size_t bufsiz);
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif
230