Update.
[glibc.git] / linuxthreads / wrapsyscall.c
blob4659692d563d5bf0c49f2984e3ada2c9abd9a3a3
1 /* Wrapper arpund system calls to provide cancelation points.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <fcntl.h>
22 #include <pthread.h>
23 #include <unistd.h>
24 #include <stdarg.h>
25 #include <stddef.h>
26 #include <sys/resource.h>
27 #include <sys/wait.h>
28 #include <sys/socket.h>
31 #ifndef PIC
32 /* We need a hook to force this file to be linked in when static
33 libpthread is used. */
34 const int __pthread_provide_wrappers = 0;
35 #endif
38 #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
39 res_type __libc_##name param_list; \
40 res_type \
41 name param_list \
42 { \
43 res_type result; \
44 int oldtype; \
45 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
46 result = __libc_##name params; \
47 pthread_setcanceltype (oldtype, NULL); \
48 return result; \
51 #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
52 res_type __libc_##name param_list; \
53 res_type \
54 name param_list \
55 { \
56 res_type result; \
57 int oldtype; \
58 va_list ap; \
59 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
60 va_start (ap, last_arg); \
61 result = __libc_##name params; \
62 va_end (ap); \
63 pthread_setcanceltype (oldtype, NULL); \
64 return result; \
68 /* close(2). */
69 CANCELABLE_SYSCALL (int, close, (int fd), (fd))
70 strong_alias (close, __close)
73 /* fcntl(2). */
74 CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
75 (fd, cmd, va_arg (ap, long int)), cmd)
76 strong_alias (fcntl, __fcntl)
79 /* fsync(2). */
80 CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
83 /* lseek(2). */
84 CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
85 (fd, offset, whence))
86 strong_alias (lseek, __lseek)
89 /* msync(2). */
90 CANCELABLE_SYSCALL (int, msync, (const void *start, size_t length, int flags),
91 (start, length, flags))
94 /* nanosleep(2). */
95 CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
96 struct timespec *remaining),
97 (requested_time, remaining))
100 /* open(2). */
101 CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
102 (pathname, flags, va_arg (ap, mode_t)), flags)
103 strong_alias (open, __open)
106 /* pause(2). */
107 CANCELABLE_SYSCALL (int, pause, (void), ())
110 /* read(2). */
111 CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
112 (fd, buf, count))
113 strong_alias (read, __read)
116 /* system(3). */
117 CANCELABLE_SYSCALL (int, system, (const char *line), (line))
120 /* tcdrain(2). */
121 CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
124 /* wait(2). */
125 CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
126 strong_alias (wait, __wait)
129 /* waitpid(2). */
130 CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
131 int options),
132 (pid, stat_loc, options))
135 /* write(2). */
136 CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
137 (fd, buf, n))
138 strong_alias (write, __write)
141 /* The following system calls are thread cancellation points specified
142 in XNS. */
144 /* accept(2). */
145 CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
146 socklen_t *addr_len),
147 (fd, addr, addr_len))
149 /* connect(2). */
150 CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
151 socklen_t len),
152 (fd, addr, len))
153 strong_alias (connect, __connect)
155 /* recv(2). */
156 CANCELABLE_SYSCALL (int, recv, (int fd, __ptr_t buf, size_t n, int flags),
157 (fd, buf, n, flags))
159 /* recvfrom(2). */
160 CANCELABLE_SYSCALL (int, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
161 __SOCKADDR_ARG addr, socklen_t *addr_len),
162 (fd, buf, n, flags, addr, addr_len))
164 /* recvmsg(2). */
165 CANCELABLE_SYSCALL (int, recvmsg, (int fd, struct msghdr *message, int flags),
166 (fd, message, flags))
168 /* send(2). */
169 CANCELABLE_SYSCALL (int, send, (int fd, const __ptr_t buf, size_t n,
170 int flags),
171 (fd, buf, n, flags))
172 strong_alias (send, __send)
174 /* sendmsg(2). */
175 CANCELABLE_SYSCALL (int, sendmsg, (int fd, const struct msghdr *message,
176 int flags),
177 (fd, message, flags))
179 /* sendto(2). */
180 CANCELABLE_SYSCALL (int, sendto, (int fd, const __ptr_t buf, size_t n,
181 int flags, __CONST_SOCKADDR_ARG addr,
182 socklen_t addr_len),
183 (fd, buf, n, flags, addr, addr_len))