root/syscallwrappers.h
/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- FOREACH_DMTCP_WRAPPER
- FOREACH_LIBPTHREAD_WRAPPERS
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 DMTCP. *
6 * *
7 * DMTCP 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 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 SYSCALLWRAPPERS_H
23 #define SYSCALLWRAPPERS_H
24
25 #include <features.h>
26 #include <pthread.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <signal.h>
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <poll.h>
34 #include <stdarg.h>
35 #include <sys/shm.h>
36 #include <sys/sem.h>
37 #include <sys/msg.h>
38 #ifdef __cplusplus
39 # include <sys/stat.h>
40 #else
41 # ifndef __USE_LARGEFILE64
42 # define __USE_LARGEFILE64_not_defined
43 # define __USE_LARGEFILE64
44 # include <sys/stat.h>
45 # ifdef __USE_LARGEFILE64_not_defined
46 # undef __USE_LARGEFILE64_not_defined
47 # undef __USE_LARGEFILE64
48 # endif
49 # endif
50 #endif
51 #include <sys/mman.h>
52 #include <dirent.h>
53 #include <unistd.h>
54 #include <mqueue.h>
55 #ifdef HAVE_SYS_INOTIFY_H
56 # include <sys/inotify.h>
57 #endif
58
59 #include "constants.h"
60 #include "dmtcp.h"
61 #include "mtcp/ldt.h"
62 #include "config.h"
63
64 #ifdef HAVE_SYS_EPOLL_H
65 # include <sys/epoll.h>
66 #else
67 /* KEEP THIS IN SYNC WITH connection.h */
68 # ifndef _SYS_EPOLL_H
69 # define _SYS_EPOLL_H 1
70 struct epoll_event {int dummy;};
71 /* Valid opcodes ("op" parameter) to issue to epoll_ctl(). */
72 # define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface. */
73 # define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface. */
74 # define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure. */
75 # endif
76 #endif
77
78 void _dmtcp_setup_trampolines();
79
80 #ifdef __cplusplus
81 extern "C"
82 {
83 #endif
84
85 #if defined(__arm__) || defined(__aarch64__)
86 # define DISABLE_PTHREAD_GETSPECIFIC_TRICK
87 #endif
88
89 LIB_PRIVATE pid_t dmtcp_gettid();
90 LIB_PRIVATE int dmtcp_tkill(int tid, int sig);
91 LIB_PRIVATE int dmtcp_tgkill(int tgid, int tid, int sig);
92
93 extern int dmtcp_wrappers_initializing;
94
95 LIB_PRIVATE extern __thread int thread_performing_dlopen_dlsym;
96
97 #define FOREACH_GLIBC_MALLOC_FAMILY_WRAPPERS(MACRO)\
98 MACRO(calloc) \
99 MACRO(malloc) \
100 MACRO(free) \
101 MACRO(__libc_memalign) \
102 MACRO(realloc) \
103 MACRO(mmap) \
104 MACRO(mmap64) \
105 MACRO(mremap) \
106 MACRO(munmap)
107
108 #define FOREACH_GLIBC_WRAPPERS(MACRO) \
109 MACRO(dlopen) \
110 MACRO(dlclose) \
111 MACRO(getpid) \
112 MACRO(getppid) \
113 MACRO(kill) \
114 \
115 MACRO(tcgetpgrp) \
116 MACRO(tcsetpgrp) \
117 MACRO(getpgrp) \
118 MACRO(setpgrp) \
119 \
120 MACRO(getpgid) \
121 MACRO(setpgid) \
122 MACRO(getsid) \
123 MACRO(setsid) \
124 MACRO(setgid) \
125 MACRO(setuid) \
126 \
127 MACRO(wait) \
128 MACRO(waitpid) \
129 MACRO(waitid) \
130 MACRO(wait3) \
131 MACRO(wait4) \
132 MACRO(ioctl) \
133 MACRO(fcntl) \
134 \
135 MACRO(socket) \
136 MACRO(connect) \
137 MACRO(bind) \
138 MACRO(listen) \
139 MACRO(accept) \
140 MACRO(accept4) \
141 MACRO(setsockopt) \
142 MACRO(getsockopt) \
143 MACRO(socketpair) \
144 \
145 MACRO(fexecve) \
146 MACRO(execve) \
147 MACRO(execv) \
148 MACRO(execvp) \
149 MACRO(execvpe) \
150 MACRO(execl) \
151 MACRO(execlp) \
152 MACRO(execle) \
153 MACRO(system) \
154 MACRO(popen) \
155 MACRO(pclose) \
156 \
157 MACRO(signal) \
158 MACRO(sigaction) \
159 MACRO(sigvec) \
160 \
161 MACRO(sigset) \
162 MACRO(sigblock) \
163 MACRO(sigsetmask) \
164 MACRO(siggetmask) \
165 MACRO(sigprocmask) \
166 \
167 MACRO(sigsuspend) \
168 MACRO(sighold) \
169 MACRO(sigignore) \
170 MACRO(__sigpause) \
171 MACRO(sigpause) \
172 MACRO(sigrelse) \
173 \
174 MACRO(sigwait) \
175 MACRO(sigwaitinfo) \
176 MACRO(sigtimedwait) \
177 \
178 MACRO(fork) \
179 MACRO(__clone) \
180 MACRO(open) \
181 MACRO(open64) \
182 MACRO(fopen) \
183 MACRO(fopen64) \
184 MACRO(openat) \
185 MACRO(openat64) \
186 MACRO(opendir) \
187 MACRO(mkstemp) \
188 MACRO(close) \
189 MACRO(fclose) \
190 MACRO(closedir) \
191 MACRO(dup) \
192 MACRO(dup2) \
193 MACRO(dup3) \
194 MACRO(__xstat) \
195 MACRO(__xstat64) \
196 MACRO(__lxstat) \
197 MACRO(__lxstat64) \
198 MACRO(readlink) \
199 MACRO(exit) \
200 MACRO(syscall) \
201 MACRO(unsetenv) \
202 MACRO(ptsname_r) \
203 MACRO(ttyname_r) \
204 MACRO(getpt) \
205 MACRO(posix_openpt) \
206 MACRO(openlog) \
207 MACRO(closelog) \
208 \
209 MACRO(shmget) \
210 MACRO(shmat) \
211 MACRO(shmdt) \
212 MACRO(shmctl) \
213 \
214 MACRO(semget) \
215 MACRO(semctl) \
216 MACRO(semop) \
217 MACRO(semtimedop) \
218 \
219 MACRO(msgget) \
220 MACRO(msgctl) \
221 MACRO(msgsnd) \
222 MACRO(msgrcv) \
223 \
224 MACRO(mq_open) \
225 MACRO(mq_close) \
226 MACRO(mq_timedsend) \
227 MACRO(mq_timedreceive) \
228 MACRO(mq_notify) \
229 \
230 MACRO(read) \
231 MACRO(write) \
232 \
233 MACRO(select) \
234 MACRO(poll) \
235 \
236 MACRO(pthread_create) \
237 MACRO(pthread_exit) \
238 MACRO(pthread_tryjoin_np) \
239 MACRO(pthread_timedjoin_np) \
240 MACRO(pthread_sigmask) \
241 MACRO(pthread_getspecific) \
242 MACRO(pthread_mutex_lock) \
243 MACRO(pthread_mutex_trylock) \
244 MACRO(pthread_mutex_unlock) \
245 MACRO(pthread_rwlock_unlock) \
246 MACRO(pthread_rwlock_rdlock) \
247 MACRO(pthread_rwlock_tryrdlock) \
248 MACRO(pthread_rwlock_wrlock) \
249 MACRO(pthread_rwlock_trywrlock)
250
251 #define FOREACH_LIBPTHREAD_WRAPPERS(MACRO) \
252 MACRO(pthread_cond_broadcast) \
253 MACRO(pthread_cond_destroy) \
254 MACRO(pthread_cond_init) \
255 MACRO(pthread_cond_signal) \
256 MACRO(pthread_cond_timedwait) \
257 MACRO(pthread_cond_wait)
258
259 #define FOREACH_DMTCP_WRAPPER(MACRO) \
260 FOREACH_GLIBC_WRAPPERS(MACRO) \
261 FOREACH_GLIBC_MALLOC_FAMILY_WRAPPERS(MACRO)
262
263 # define ENUM(x) enum_ ## x
264 # define GEN_ENUM(x) ENUM(x),
265 typedef enum {
266 FOREACH_DMTCP_WRAPPER(GEN_ENUM)
267 FOREACH_LIBPTHREAD_WRAPPERS(GEN_ENUM)
268 numLibcWrappers
269 } LibcWrapperOffset;
270
271 union semun {
272 int val; /* Value for SETVAL */
273 struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
274 unsigned short *array; /* Array for GETALL, SETALL */
275 struct seminfo *__buf; /* Buffer for IPC_INFO (Linux-specific) */
276 };
277
278 void _dmtcp_lock();
279 void _dmtcp_unlock();
280
281 void _dmtcp_remutex_on_fork();
282 LIB_PRIVATE void dmtcpResetTid(pid_t tid);
283 LIB_PRIVATE void dmtcpResetPidPpid();
284
285 int _dmtcp_unsetenv(const char *name);
286 void initialize_libc_wrappers();
287 void initialize_libpthread_wrappers();
288
289 int _real_socket (int domain, int type, int protocol);
290 int _real_connect (int sockfd, const struct sockaddr *serv_addr,
291 socklen_t addrlen);
292 int _real_bind (int sockfd, const struct sockaddr *my_addr,
293 socklen_t addrlen);
294 int _real_listen (int sockfd, int backlog);
295 int _real_accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen);
296 int _real_accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
297 int flags);
298 int _real_setsockopt (int s, int level, int optname, const void *optval,
299 socklen_t optlen);
300 int _real_getsockopt (int s, int level, int optname, void *optval,
301 socklen_t *optlen);
302
303 int _real_fexecve (int fd, char *const argv[], char *const envp[]);
304 int _real_execve (const char *filename, char *const argv[], char *const envp[]);
305 int _real_execv (const char *path, char *const argv[]);
306 int _real_execvp (const char *file, char *const argv[]);
307 int _real_execvpe(const char *file, char *const argv[], char *const envp[]);
308 // int _real_execl(const char *path, const char *arg, ...);
309 // int _real_execlp(const char *file, const char *arg, ...);
310 // int _real_execle(const char *path, const char *arg, ..., char * const envp[]);
311 int _real_system (const char * cmd);
312 FILE *_real_popen(const char *command, const char *mode);
313 int _real_pclose(FILE *fp);
314
315 pid_t _real_fork();
316 int _real_clone (int (*fn) (void *arg), void *child_stack, int flags, void *arg, int *parent_tidptr, struct user_desc *newtls, int *child_tidptr);
317
318 int _real_open(const char *pathname, int flags, ...);
319 int _real_open64(const char *pathname, int flags, ...);
320 FILE* _real_fopen(const char *path, const char *mode);
321 FILE* _real_fopen64(const char *path, const char *mode);
322 int _real_openat(int dirfd, const char *pathname, int flags, mode_t mode);
323 int _real_openat64(int dirfd, const char *pathname, int flags, mode_t mode);
324 DIR* _real_opendir(const char *name);
325 int _real_mkstemp(char *ttemplate);
326 int _real_close (int fd);
327 int _real_fclose (FILE *fp);
328 int _real_closedir (DIR *dir);
329 void _real_exit (int status);
330 int _real_dup (int oldfd);
331 int _real_dup2 (int oldfd, int newfd);
332 int _real_dup3 (int oldfd, int newfd, int flags);
333 int _real_fcntl(int fd, int cmd, void *arg);
334
335 int _real_ttyname_r (int fd, char *buf, size_t buflen);
336 int _real_ptsname_r (int fd, char * buf, size_t buflen);
337 int _real_getpt (void);
338 int _real_posix_openpt (int flags);
339
340 int _real_socketpair (int d, int type, int protocol, int sv[2]);
341
342 void _real_openlog (const char *ident, int option, int facility);
343 void _real_closelog (void);
344
345 // Despite what 'man signal' says, signal.h already defines sighandler_t
346 // But signal.h defines this only because we define GNU_SOURCE (or __USE_GNU_
347 typedef void (*sighandler_t)(int); /* POSIX has user define this type */
348
349 //set the handler
350 sighandler_t _real_signal(int signum, sighandler_t handler);
351 int _real_sigaction(int signum, const struct sigaction *act,
352 struct sigaction *oldact);
353 int _real_rt_sigaction(int signum, const struct sigaction *act,
354 struct sigaction *oldact);
355 #if !__GLIBC_PREREQ(2,21)
356 int _real_sigvec(int sig, const struct sigvec *vec, struct sigvec *ovec);
357 #endif
358
359 //set the mask
360 int _real_sigblock(int mask);
361 int _real_sigsetmask(int mask);
362 int _real_siggetmask(void);
363 int _real_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
364 int _real_rt_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
365 int _real_pthread_sigmask(int how, const sigset_t *newmask,
366 sigset_t *oldmask);
367 void *_real_pthread_getspecific(pthread_key_t key);
368
369 int _real_sigsuspend(const sigset_t *mask);
370 int _real_sighold(int sig);
371 int _real_sigignore(int sig);
372 int _real__sigpause(int __sig_or_mask, int __is_sig);
373 int _real_sigpause(int sig);
374 int _real_sigrelse(int sig);
375 sighandler_t _real_sigset(int sig, sighandler_t disp);
376
377 int _real_sigwait(const sigset_t *set, int *sig);
378 int _real_sigwaitinfo(const sigset_t *set, siginfo_t *info);
379 int _real_sigtimedwait(const sigset_t *set, siginfo_t *info,
380 const struct timespec *timeout);
381
382 long _real_syscall(long sys_num, ...);
383
384 int _real_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
385 void *(*start_routine)(void*), void *arg);
386 void _real_pthread_exit(void *retval) __attribute__ ((__noreturn__));
387 int _real_pthread_tryjoin_np(pthread_t thread, void **retval);
388 int _real_pthread_timedjoin_np(pthread_t thread, void **retval,
389 const struct timespec *abstime);
390
391 int _real_xstat(int vers, const char *path, struct stat *buf);
392 int _real_xstat64(int vers, const char *path, struct stat64 *buf);
393 int _real_lxstat(int vers, const char *path, struct stat *buf);
394 int _real_lxstat64(int vers, const char *path, struct stat64 *buf);
395 ssize_t _real_readlink(const char *path, char *buf, size_t bufsiz);
396 void * _real_dlsym (void *handle, const char *symbol);
397
398 void *_real_dlopen(const char *filename, int flag);
399 int _real_dlclose(void *handle);
400
401 void *_real_calloc(size_t nmemb, size_t size);
402 void *_real_malloc(size_t size);
403 void _real_free(void *ptr);
404 void *_real_realloc(void *ptr, size_t size);
405 void *_real_libc_memalign(size_t boundary, size_t size);
406 void *_real_mmap(void *addr, size_t length, int prot, int flags,
407 int fd, off_t offset);
408 void *_real_mmap64(void *addr, size_t length, int prot, int flags,
409 int fd, __off64_t offset);
410 #if __GLIBC_PREREQ (2,4)
411 void *_real_mremap(void *old_address, size_t old_size, size_t new_size,
412 int flags, ... /* void *new_address */);
413 #else
414 void *_real_mremap(void *old_address, size_t old_size, size_t new_size,
415 int flags);
416 #endif
417 int _real_munmap(void *addr, size_t length);
418
419 ssize_t _real_read(int fd, void *buf, size_t count);
420 ssize_t _real_write(int fd, const void *buf, size_t count);
421 int _real_select(int nfds, fd_set *readfds, fd_set *writefds,
422 fd_set *exceptfds, struct timeval *timeout);
423 off_t _real_lseek(int fd, off_t offset, int whence);
424 int _real_unlink(const char *pathname);
425
426 int _real_pthread_mutex_lock(pthread_mutex_t *mutex);
427 int _real_pthread_mutex_trylock(pthread_mutex_t *mutex);
428 int _real_pthread_mutex_unlock(pthread_mutex_t *mutex);
429 int _real_pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
430 int _real_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
431 int _real_pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
432 int _real_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
433 int _real_pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
434 int _real_pthread_cond_broadcast(pthread_cond_t *cond);
435 int _real_pthread_cond_destroy(pthread_cond_t *cond);
436 int _real_pthread_cond_init(pthread_cond_t *cond,
437 const pthread_condattr_t *attr);
438 int _real_pthread_cond_signal(pthread_cond_t *cond);
439 int _real_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
440 const struct timespec *abstime);
441 int _real_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
442
443 int _real_poll(struct pollfd *fds, nfds_t nfds, int timeout);
444
445 int _real_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
446 pid_t _real_wait4(pid_t pid, __WAIT_STATUS status, int options,
447 struct rusage *rusage);
448
449 int _real_shmget (int key, size_t size, int shmflg);
450 void* _real_shmat (int shmid, const void *shmaddr, int shmflg);
451 int _real_shmdt (const void *shmaddr);
452 int _real_shmctl (int shmid, int cmd, struct shmid_ds *buf);
453 int _real_semget(key_t key, int nsems, int semflg);
454 int _real_semop(int semid, struct sembuf *sops, size_t nsops);
455 int _real_semtimedop(int semid, struct sembuf *sops, size_t nsops,
456 const struct timespec *timeout);
457 int _real_semctl(int semid, int semnum, int cmd, ...);
458
459 int _real_msgget(key_t key, int msgflg);
460 int _real_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
461 ssize_t _real_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,
462 int msgflg);
463 int _real_msgctl(int msqid, int cmd, struct msqid_ds *buf);
464
465
466 mqd_t _real_mq_open(const char *name, int oflag, mode_t mode,
467 struct mq_attr *attr);
468 int _real_mq_close(mqd_t mqdes);
469 int _real_mq_notify(mqd_t mqdes, const struct sigevent *sevp);
470 ssize_t _real_mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
471 unsigned int *msg_prio,
472 const struct timespec *abs_timeout);
473 int _real_mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
474 unsigned int msg_prio,
475 const struct timespec *abs_timeout);
476
477 #ifdef __cplusplus
478 }
479 #endif
480
481 #endif
482