xref: /dflybsd-src/lib/libthread_xu/thread/thr_syscalls.c (revision 74fa2560ac77f9db4a34b2a7c72450126fec4ed6)
171b3fa15SDavid Xu /*
271b3fa15SDavid Xu  * Copyright (C) 2005 David Xu <davidxu@freebsd.org>.
371b3fa15SDavid Xu  * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>.
471b3fa15SDavid Xu  * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
571b3fa15SDavid Xu  * All rights reserved.
671b3fa15SDavid Xu  *
771b3fa15SDavid Xu  * Redistribution and use in source and binary forms, with or without
871b3fa15SDavid Xu  * modification, are permitted provided that the following conditions
971b3fa15SDavid Xu  * are met:
1071b3fa15SDavid Xu  * 1. Redistributions of source code must retain the above copyright
1171b3fa15SDavid Xu  *    notice(s), this list of conditions and the following disclaimer as
1271b3fa15SDavid Xu  *    the first lines of this file unmodified other than the possible
1371b3fa15SDavid Xu  *    addition of one or more copyright notices.
1471b3fa15SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
1571b3fa15SDavid Xu  *    notice(s), this list of conditions and the following disclaimer in
1671b3fa15SDavid Xu  *    the documentation and/or other materials provided with the
1771b3fa15SDavid Xu  *    distribution.
1871b3fa15SDavid Xu  *
1971b3fa15SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
2071b3fa15SDavid Xu  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171b3fa15SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2271b3fa15SDavid Xu  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
2371b3fa15SDavid Xu  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471b3fa15SDavid Xu  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571b3fa15SDavid Xu  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2671b3fa15SDavid Xu  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2771b3fa15SDavid Xu  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2871b3fa15SDavid Xu  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2971b3fa15SDavid Xu  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3071b3fa15SDavid Xu  */
3171b3fa15SDavid Xu 
3271b3fa15SDavid Xu /*
3371b3fa15SDavid Xu  * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
3471b3fa15SDavid Xu  * All rights reserved.
3571b3fa15SDavid Xu  *
3671b3fa15SDavid Xu  * Redistribution and use in source and binary forms, with or without
3771b3fa15SDavid Xu  * modification, are permitted provided that the following conditions
3871b3fa15SDavid Xu  * are met:
3971b3fa15SDavid Xu  * 1. Redistributions of source code must retain the above copyright
4071b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer.
4171b3fa15SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
4271b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
4371b3fa15SDavid Xu  *    documentation and/or other materials provided with the distribution.
44d3b15642Szrj  * 3. Neither the name of the author nor the names of any co-contributors
4571b3fa15SDavid Xu  *    may be used to endorse or promote products derived from this software
4671b3fa15SDavid Xu  *    without specific prior written permission.
4771b3fa15SDavid Xu  *
4871b3fa15SDavid Xu  * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
4971b3fa15SDavid Xu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5071b3fa15SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5171b3fa15SDavid Xu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
5271b3fa15SDavid Xu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5371b3fa15SDavid Xu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5471b3fa15SDavid Xu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5571b3fa15SDavid Xu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5671b3fa15SDavid Xu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5771b3fa15SDavid Xu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5871b3fa15SDavid Xu  * SUCH DAMAGE.
5971b3fa15SDavid Xu  *
6071b3fa15SDavid Xu  */
6171b3fa15SDavid Xu 
626be5672cSzrj 
636be5672cSzrj #include "namespace.h"
6471b3fa15SDavid Xu #include <sys/types.h>
6571b3fa15SDavid Xu #include <sys/mman.h>
6671b3fa15SDavid Xu #include <sys/param.h>
6771b3fa15SDavid Xu #include <sys/select.h>
6871b3fa15SDavid Xu #include <sys/signalvar.h>
6971b3fa15SDavid Xu #include <sys/socket.h>
7071b3fa15SDavid Xu #include <sys/stat.h>
7171b3fa15SDavid Xu #include <sys/time.h>
7271b3fa15SDavid Xu #include <sys/uio.h>
7371b3fa15SDavid Xu #include <sys/wait.h>
749e2ee207SJoerg Sonnenberger #include <machine/tls.h>
7571b3fa15SDavid Xu #include <aio.h>
7671b3fa15SDavid Xu #include <dirent.h>
7771b3fa15SDavid Xu #include <errno.h>
7871b3fa15SDavid Xu #include <fcntl.h>
7971b3fa15SDavid Xu #include <poll.h>
8071b3fa15SDavid Xu #include <signal.h>
8171b3fa15SDavid Xu #include <stdarg.h>
8271b3fa15SDavid Xu #include <stdio.h>
8371b3fa15SDavid Xu #include <stdlib.h>
8471b3fa15SDavid Xu #include <string.h>
8571b3fa15SDavid Xu #include <termios.h>
8671b3fa15SDavid Xu #include <unistd.h>
8771b3fa15SDavid Xu #include <pthread.h>
886be5672cSzrj #include "un-namespace.h"
8971b3fa15SDavid Xu 
9071b3fa15SDavid Xu #include "thr_private.h"
9171b3fa15SDavid Xu 
9271b3fa15SDavid Xu extern int	__creat(const char *, mode_t);
9371b3fa15SDavid Xu extern int	__pause(void);
94ae7cb1b5SNicolas Thery extern int	__sys_pselect(int, fd_set *, fd_set *, fd_set *,
95fc71f871SDavid Xu 			const struct timespec *, const sigset_t *);
96fc71f871SDavid Xu extern unsigned	__sleep(unsigned int);
9771b3fa15SDavid Xu extern int	__system(const char *);
9871b3fa15SDavid Xu extern int	__tcdrain(int);
999e4cdec7SSascha Wildner extern int	__usleep(useconds_t);
10071b3fa15SDavid Xu extern pid_t	__wait(int *);
10171b3fa15SDavid Xu extern pid_t	__waitpid(pid_t, int *, int);
102fc71f871SDavid Xu extern int	__sys_aio_suspend(const struct aiocb * const[], int,
103fc71f871SDavid Xu 			const struct timespec *);
104fc71f871SDavid Xu extern int	__sys_accept(int, struct sockaddr *, socklen_t *);
105fc71f871SDavid Xu extern int	__sys_connect(int, const struct sockaddr *, socklen_t);
106fc71f871SDavid Xu extern int	__sys_fsync(int);
107*74fa2560STomohiro Kusumi extern int	__sys_fdatasync(int);
108fc71f871SDavid Xu extern int	__sys_msync(void *, size_t, int);
109fc71f871SDavid Xu extern int	__sys_poll(struct pollfd *, unsigned, int);
1106d2444c4SImre Vadasz extern int	__sys_ppoll(struct pollfd *, unsigned, const struct timespec *,
1116d2444c4SImre Vadasz 			const sigset_t *);
112fc71f871SDavid Xu extern ssize_t	__sys_recv(int, void *, size_t, int);
113fc71f871SDavid Xu extern ssize_t	__sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
114fc71f871SDavid Xu extern ssize_t	__sys_recvmsg(int, struct msghdr *, int);
115fc71f871SDavid Xu extern int	__sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
116fc71f871SDavid Xu extern int	__sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *,
117fc71f871SDavid Xu 			off_t *, int);
118fc71f871SDavid Xu extern ssize_t	__sys_sendmsg(int, const struct msghdr *, int);
119fc71f871SDavid Xu extern ssize_t	__sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t);
120fc71f871SDavid Xu extern ssize_t	__sys_readv(int, const struct iovec *, int);
121fc71f871SDavid Xu extern pid_t	__sys_wait4(pid_t, int *, int, struct rusage *);
122fc71f871SDavid Xu extern ssize_t	__sys_writev(int, const struct iovec *, int);
123fc71f871SDavid Xu 
124fc71f871SDavid Xu int	___creat(const char *, mode_t);
1259e4cdec7SSascha Wildner int	___usleep(useconds_t);
126fc71f871SDavid Xu int	__accept(int, struct sockaddr *, socklen_t *);
127fc71f871SDavid Xu int	__close(int);
128fc71f871SDavid Xu int	__connect(int, const struct sockaddr *, socklen_t);
129fc71f871SDavid Xu int	__fcntl(int, int,...);
130fc71f871SDavid Xu int	__fsync(int);
131*74fa2560STomohiro Kusumi int	__fdatasync(int);
132fc71f871SDavid Xu int	__msync(void *, size_t, int);
133fc71f871SDavid Xu int	__nanosleep(const struct timespec *, struct timespec *);
13486ccdacbSAaron LI int	__clock_nanosleep(clock_t, int, const struct timespec *,
13586ccdacbSAaron LI 		struct timespec *);
136fc71f871SDavid Xu int	__open(const char *, int,...);
13783a11774SNicolas Thery int	__openat(int fd, const char *, int,...);
138fc71f871SDavid Xu int	__poll(struct pollfd *, unsigned int, int);
1396d2444c4SImre Vadasz int	__ppoll(struct pollfd *, unsigned int, const struct timespec *,
1406d2444c4SImre Vadasz 		const sigset_t *);
141fc71f871SDavid Xu ssize_t	__read(int, void *buf, size_t);
142fc71f871SDavid Xu ssize_t	__readv(int, const struct iovec *, int);
143fc71f871SDavid Xu ssize_t	__recvfrom(int, void *, size_t, int f, struct sockaddr *, socklen_t *);
144fc71f871SDavid Xu ssize_t	__recvmsg(int, struct msghdr *, int);
145fc71f871SDavid Xu int	__select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
146fc71f871SDavid Xu ssize_t	__sendmsg(int, const struct msghdr *, int);
147fc71f871SDavid Xu ssize_t	__sendto(int, const void *, size_t, int,
148fc71f871SDavid Xu 		const struct sockaddr *, socklen_t);
149fc71f871SDavid Xu pid_t	__wait4(pid_t, int *, int, struct rusage *);
150fc71f871SDavid Xu ssize_t	__write(int, const void *, size_t);
151fc71f871SDavid Xu ssize_t	__writev(int, const struct iovec *, int);
152fc71f871SDavid Xu int	_aio_suspend(const struct aiocb * const iocbs[], int,
153fc71f871SDavid Xu 		const struct timespec *);
154fc71f871SDavid Xu int	_pause(void);
155d1cf13b9SSascha Wildner int	__pselect(int, fd_set *, fd_set *, fd_set *,
156fc71f871SDavid Xu 		const struct timespec *, const sigset_t *);
157fc71f871SDavid Xu int	_raise(int);
158fc71f871SDavid Xu unsigned	_sleep(unsigned);
159fc71f871SDavid Xu int	_system(const char *);
160fc71f871SDavid Xu int	_tcdrain(int);
161f7511078SMatthew Dillon #if 0
162fc71f871SDavid Xu int	_vfork(void);
163f7511078SMatthew Dillon #endif
164fc71f871SDavid Xu pid_t	_wait(int *);
16571b3fa15SDavid Xu 
16671b3fa15SDavid Xu int
__accept(int s,struct sockaddr * addr,socklen_t * addrlen)16771b3fa15SDavid Xu __accept(int s, struct sockaddr *addr, socklen_t *addrlen)
16871b3fa15SDavid Xu {
169940be950Szrj 	pthread_t curthread;
17071b3fa15SDavid Xu 	int oldcancel;
17171b3fa15SDavid Xu 	int ret;
17271b3fa15SDavid Xu 
1739e2ee207SJoerg Sonnenberger 	curthread = tls_get_curthread();
17471b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
17571b3fa15SDavid Xu 	ret = __sys_accept(s, addr, addrlen);
17671b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
17771b3fa15SDavid Xu 
17871b3fa15SDavid Xu 	return (ret);
17971b3fa15SDavid Xu }
18071b3fa15SDavid Xu 
1815a1048c8SDavid Xu __strong_reference(__accept, accept);
18271b3fa15SDavid Xu 
18371b3fa15SDavid Xu int
_aio_suspend(const struct aiocb * const iocbs[],int niocb,const struct timespec * timeout)18471b3fa15SDavid Xu _aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
18571b3fa15SDavid Xu     timespec *timeout)
18671b3fa15SDavid Xu {
187940be950Szrj 	pthread_t curthread = tls_get_curthread();
18871b3fa15SDavid Xu 	int oldcancel;
18971b3fa15SDavid Xu 	int ret;
19071b3fa15SDavid Xu 
19171b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
19271b3fa15SDavid Xu 	ret = __sys_aio_suspend(iocbs, niocb, timeout);
19371b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
19471b3fa15SDavid Xu 
19571b3fa15SDavid Xu 	return (ret);
19671b3fa15SDavid Xu }
19771b3fa15SDavid Xu 
1985a1048c8SDavid Xu __strong_reference(_aio_suspend, aio_suspend);
19971b3fa15SDavid Xu 
20071b3fa15SDavid Xu int
__close(int fd)20171b3fa15SDavid Xu __close(int fd)
20271b3fa15SDavid Xu {
203940be950Szrj 	pthread_t curthread = tls_get_curthread();
20471b3fa15SDavid Xu 	int	oldcancel;
20571b3fa15SDavid Xu 	int	ret;
20671b3fa15SDavid Xu 
20771b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
20871b3fa15SDavid Xu 	ret = __sys_close(fd);
20971b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
21071b3fa15SDavid Xu 
21171b3fa15SDavid Xu 	return (ret);
21271b3fa15SDavid Xu }
21371b3fa15SDavid Xu 
2145a1048c8SDavid Xu __strong_reference(__close, close);
21571b3fa15SDavid Xu 
21671b3fa15SDavid Xu int
__connect(int fd,const struct sockaddr * name,socklen_t namelen)21771b3fa15SDavid Xu __connect(int fd, const struct sockaddr *name, socklen_t namelen)
21871b3fa15SDavid Xu {
219940be950Szrj 	pthread_t curthread = tls_get_curthread();
22071b3fa15SDavid Xu 	int oldcancel;
22171b3fa15SDavid Xu 	int ret;
22271b3fa15SDavid Xu 
22371b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
22471b3fa15SDavid Xu 	ret = __sys_connect(fd, name, namelen);
22571b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
22671b3fa15SDavid Xu 
22771b3fa15SDavid Xu 	return (ret);
22871b3fa15SDavid Xu }
22971b3fa15SDavid Xu 
2305a1048c8SDavid Xu __strong_reference(__connect, connect);
23171b3fa15SDavid Xu 
23271b3fa15SDavid Xu int
___creat(const char * path,mode_t mode)23371b3fa15SDavid Xu ___creat(const char *path, mode_t mode)
23471b3fa15SDavid Xu {
235940be950Szrj 	pthread_t curthread = tls_get_curthread();
23671b3fa15SDavid Xu 	int oldcancel;
23771b3fa15SDavid Xu 	int ret;
23871b3fa15SDavid Xu 
23971b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
24071b3fa15SDavid Xu 	ret = __creat(path, mode);
24171b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
24271b3fa15SDavid Xu 
24371b3fa15SDavid Xu 	return ret;
24471b3fa15SDavid Xu }
24571b3fa15SDavid Xu 
2465a1048c8SDavid Xu __strong_reference(___creat, creat);
24771b3fa15SDavid Xu 
24871b3fa15SDavid Xu int
__fcntl(int fd,int cmd,...)24971b3fa15SDavid Xu __fcntl(int fd, int cmd,...)
25071b3fa15SDavid Xu {
251940be950Szrj 	pthread_t curthread = tls_get_curthread();
25271b3fa15SDavid Xu 	int	oldcancel;
25371b3fa15SDavid Xu 	int	ret;
25471b3fa15SDavid Xu 	va_list	ap;
25571b3fa15SDavid Xu 
25671b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
25771b3fa15SDavid Xu 
25871b3fa15SDavid Xu 	va_start(ap, cmd);
25971b3fa15SDavid Xu 	switch (cmd) {
26071b3fa15SDavid Xu 	case F_DUPFD:
26171b3fa15SDavid Xu 		ret = __sys_fcntl(fd, cmd, va_arg(ap, int));
26271b3fa15SDavid Xu 		break;
26371b3fa15SDavid Xu 	case F_SETFD:
26471b3fa15SDavid Xu 	case F_SETFL:
26571b3fa15SDavid Xu 		ret = __sys_fcntl(fd, cmd, va_arg(ap, int));
26671b3fa15SDavid Xu 		break;
26771b3fa15SDavid Xu 	case F_GETFD:
26871b3fa15SDavid Xu 	case F_GETFL:
26971b3fa15SDavid Xu 		ret = __sys_fcntl(fd, cmd);
27071b3fa15SDavid Xu 		break;
27171b3fa15SDavid Xu 	default:
27271b3fa15SDavid Xu 		ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
27371b3fa15SDavid Xu 	}
27471b3fa15SDavid Xu 	va_end(ap);
27571b3fa15SDavid Xu 
27671b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
27771b3fa15SDavid Xu 
27871b3fa15SDavid Xu 	return (ret);
27971b3fa15SDavid Xu }
28071b3fa15SDavid Xu 
2815a1048c8SDavid Xu __strong_reference(__fcntl, fcntl);
28271b3fa15SDavid Xu 
28371b3fa15SDavid Xu int
__fsync(int fd)28471b3fa15SDavid Xu __fsync(int fd)
28571b3fa15SDavid Xu {
286940be950Szrj 	pthread_t curthread = tls_get_curthread();
28771b3fa15SDavid Xu 	int	oldcancel;
28871b3fa15SDavid Xu 	int	ret;
28971b3fa15SDavid Xu 
29071b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
29171b3fa15SDavid Xu 	ret = __sys_fsync(fd);
29271b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
29371b3fa15SDavid Xu 
29471b3fa15SDavid Xu 	return (ret);
29571b3fa15SDavid Xu }
29671b3fa15SDavid Xu 
2975a1048c8SDavid Xu __strong_reference(__fsync, fsync);
29871b3fa15SDavid Xu 
29971b3fa15SDavid Xu int
__fdatasync(int fd)300*74fa2560STomohiro Kusumi __fdatasync(int fd)
301*74fa2560STomohiro Kusumi {
302*74fa2560STomohiro Kusumi 	pthread_t curthread = tls_get_curthread();
303*74fa2560STomohiro Kusumi 	int	oldcancel;
304*74fa2560STomohiro Kusumi 	int	ret;
305*74fa2560STomohiro Kusumi 
306*74fa2560STomohiro Kusumi 	oldcancel = _thr_cancel_enter(curthread);
307*74fa2560STomohiro Kusumi 	ret = __sys_fdatasync(fd);
308*74fa2560STomohiro Kusumi 	_thr_cancel_leave(curthread, oldcancel);
309*74fa2560STomohiro Kusumi 
310*74fa2560STomohiro Kusumi 	return (ret);
311*74fa2560STomohiro Kusumi }
312*74fa2560STomohiro Kusumi 
313*74fa2560STomohiro Kusumi __strong_reference(__fdatasync, fdatasync);
314*74fa2560STomohiro Kusumi 
315*74fa2560STomohiro Kusumi int
__msync(void * addr,size_t len,int flags)31671b3fa15SDavid Xu __msync(void *addr, size_t len, int flags)
31771b3fa15SDavid Xu {
318940be950Szrj 	pthread_t curthread = tls_get_curthread();
31971b3fa15SDavid Xu 	int	oldcancel;
32071b3fa15SDavid Xu 	int	ret;
32171b3fa15SDavid Xu 
32271b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
32371b3fa15SDavid Xu 	ret = __sys_msync(addr, len, flags);
32471b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
32571b3fa15SDavid Xu 
32671b3fa15SDavid Xu 	return ret;
32771b3fa15SDavid Xu }
32871b3fa15SDavid Xu 
3295a1048c8SDavid Xu __strong_reference(__msync, msync);
33071b3fa15SDavid Xu 
33171b3fa15SDavid Xu int
__nanosleep(const struct timespec * time_to_sleep,struct timespec * time_remaining)33271b3fa15SDavid Xu __nanosleep(const struct timespec *time_to_sleep,
33371b3fa15SDavid Xu     struct timespec *time_remaining)
33471b3fa15SDavid Xu {
335940be950Szrj 	pthread_t curthread = tls_get_curthread();
33671b3fa15SDavid Xu 	int		oldcancel;
33771b3fa15SDavid Xu 	int		ret;
33871b3fa15SDavid Xu 
33971b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
34071b3fa15SDavid Xu 	ret = __sys_nanosleep(time_to_sleep, time_remaining);
34171b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
34271b3fa15SDavid Xu 
34371b3fa15SDavid Xu 	return (ret);
34471b3fa15SDavid Xu }
34571b3fa15SDavid Xu 
3465a1048c8SDavid Xu __strong_reference(__nanosleep, nanosleep);
34771b3fa15SDavid Xu 
34871b3fa15SDavid Xu int
__clock_nanosleep(clock_t clock_id,int flags,const struct timespec * time_to_sleep,struct timespec * time_remaining)34986ccdacbSAaron LI __clock_nanosleep(clock_t clock_id, int flags,
35086ccdacbSAaron LI     const struct timespec *time_to_sleep, struct timespec *time_remaining)
35186ccdacbSAaron LI {
35286ccdacbSAaron LI 	pthread_t curthread = tls_get_curthread();
35386ccdacbSAaron LI 	int		oldcancel;
35486ccdacbSAaron LI 	int		ret;
35586ccdacbSAaron LI 
35686ccdacbSAaron LI 	oldcancel = _thr_cancel_enter(curthread);
35786ccdacbSAaron LI 	ret = __sys_clock_nanosleep(clock_id, flags, time_to_sleep,
35886ccdacbSAaron LI 			time_remaining);
35986ccdacbSAaron LI 	_thr_cancel_leave(curthread, oldcancel);
36086ccdacbSAaron LI 
36186ccdacbSAaron LI 	return (ret);
36286ccdacbSAaron LI }
36386ccdacbSAaron LI 
36486ccdacbSAaron LI __strong_reference(__clock_nanosleep, clock_nanosleep);
36586ccdacbSAaron LI 
36686ccdacbSAaron LI int
__open(const char * path,int flags,...)367fc71f871SDavid Xu __open(const char *path, int flags,...)
36871b3fa15SDavid Xu {
369940be950Szrj 	pthread_t curthread = tls_get_curthread();
37071b3fa15SDavid Xu 	int	oldcancel;
37171b3fa15SDavid Xu 	int	ret;
37271b3fa15SDavid Xu 	int	mode = 0;
37371b3fa15SDavid Xu 	va_list	ap;
37471b3fa15SDavid Xu 
37571b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
37671b3fa15SDavid Xu 
37771b3fa15SDavid Xu 	/* Check if the file is being created: */
37871b3fa15SDavid Xu 	if (flags & O_CREAT) {
37971b3fa15SDavid Xu 		/* Get the creation mode: */
38071b3fa15SDavid Xu 		va_start(ap, flags);
38171b3fa15SDavid Xu 		mode = va_arg(ap, int);
38271b3fa15SDavid Xu 		va_end(ap);
38371b3fa15SDavid Xu 	}
38471b3fa15SDavid Xu 
38571b3fa15SDavid Xu 	ret = __sys_open(path, flags, mode);
38671b3fa15SDavid Xu 
38771b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
38871b3fa15SDavid Xu 
38971b3fa15SDavid Xu 	return ret;
39071b3fa15SDavid Xu }
39171b3fa15SDavid Xu 
392fc71f871SDavid Xu __strong_reference(__open, open);
39371b3fa15SDavid Xu 
39471b3fa15SDavid Xu int
__openat(int fd,const char * path,int flags,...)39583a11774SNicolas Thery __openat(int fd, const char *path, int flags,...)
39683a11774SNicolas Thery {
397940be950Szrj 	pthread_t curthread = tls_get_curthread();
39883a11774SNicolas Thery 	int	oldcancel;
39983a11774SNicolas Thery 	int	ret;
40083a11774SNicolas Thery 	int	mode = 0;
40183a11774SNicolas Thery 	va_list	ap;
40283a11774SNicolas Thery 
40383a11774SNicolas Thery 	oldcancel = _thr_cancel_enter(curthread);
40483a11774SNicolas Thery 
40583a11774SNicolas Thery 	/* Check if the file is being created: */
40683a11774SNicolas Thery 	if (flags & O_CREAT) {
40783a11774SNicolas Thery 		/* Get the creation mode: */
40883a11774SNicolas Thery 		va_start(ap, flags);
40983a11774SNicolas Thery 		mode = va_arg(ap, int);
41083a11774SNicolas Thery 		va_end(ap);
41183a11774SNicolas Thery 	}
41283a11774SNicolas Thery 
41383a11774SNicolas Thery 	ret = __sys_openat(fd, path, flags, mode);
41483a11774SNicolas Thery 
41583a11774SNicolas Thery 	_thr_cancel_leave(curthread, oldcancel);
41683a11774SNicolas Thery 
41783a11774SNicolas Thery 	return ret;
41883a11774SNicolas Thery }
41983a11774SNicolas Thery 
42083a11774SNicolas Thery __strong_reference(__openat, openat);
42183a11774SNicolas Thery 
42283a11774SNicolas Thery int
_pause(void)42371b3fa15SDavid Xu _pause(void)
42471b3fa15SDavid Xu {
425940be950Szrj 	pthread_t curthread = tls_get_curthread();
42671b3fa15SDavid Xu 	int	oldcancel;
42771b3fa15SDavid Xu 	int	ret;
42871b3fa15SDavid Xu 
42971b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
43071b3fa15SDavid Xu 	ret = __pause();
43171b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
43271b3fa15SDavid Xu 
43371b3fa15SDavid Xu 	return ret;
43471b3fa15SDavid Xu }
43571b3fa15SDavid Xu 
4365a1048c8SDavid Xu __strong_reference(_pause, pause);
43771b3fa15SDavid Xu 
43871b3fa15SDavid Xu int
__poll(struct pollfd * fds,unsigned int nfds,int timeout)43971b3fa15SDavid Xu __poll(struct pollfd *fds, unsigned int nfds, int timeout)
44071b3fa15SDavid Xu {
441940be950Szrj 	pthread_t curthread = tls_get_curthread();
44271b3fa15SDavid Xu 	int oldcancel;
44371b3fa15SDavid Xu 	int ret;
44471b3fa15SDavid Xu 
44571b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
44671b3fa15SDavid Xu 	ret = __sys_poll(fds, nfds, timeout);
44771b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
44871b3fa15SDavid Xu 
44971b3fa15SDavid Xu 	return ret;
45071b3fa15SDavid Xu }
45171b3fa15SDavid Xu 
4525a1048c8SDavid Xu __strong_reference(__poll, poll);
45371b3fa15SDavid Xu 
45471b3fa15SDavid Xu int
__ppoll(struct pollfd * fds,unsigned int nfds,const struct timespec * ts,const sigset_t * mask)4556d2444c4SImre Vadasz __ppoll(struct pollfd *fds, unsigned int nfds, const struct timespec *ts,
4566d2444c4SImre Vadasz 	const sigset_t *mask)
4576d2444c4SImre Vadasz {
458940be950Szrj 	pthread_t curthread = tls_get_curthread();
4596d2444c4SImre Vadasz 	int oldcancel;
4606d2444c4SImre Vadasz 	int ret;
4616d2444c4SImre Vadasz 
4626d2444c4SImre Vadasz 	oldcancel = _thr_cancel_enter(curthread);
4636d2444c4SImre Vadasz 	ret = __sys_ppoll(fds, nfds, ts, mask);
4646d2444c4SImre Vadasz 	_thr_cancel_leave(curthread, oldcancel);
4656d2444c4SImre Vadasz 
4666d2444c4SImre Vadasz 	return ret;
4676d2444c4SImre Vadasz }
4686d2444c4SImre Vadasz 
4696d2444c4SImre Vadasz __strong_reference(__ppoll, ppoll);
4706d2444c4SImre Vadasz 
4716d2444c4SImre Vadasz int
__pselect(int count,fd_set * rfds,fd_set * wfds,fd_set * efds,const struct timespec * timo,const sigset_t * mask)472ae7cb1b5SNicolas Thery __pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
47371b3fa15SDavid Xu 	const struct timespec *timo, const sigset_t *mask)
47471b3fa15SDavid Xu {
475940be950Szrj 	pthread_t curthread = tls_get_curthread();
47671b3fa15SDavid Xu 	int oldcancel;
47771b3fa15SDavid Xu 	int ret;
47871b3fa15SDavid Xu 
47971b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
480ae7cb1b5SNicolas Thery 	ret = __sys_pselect(count, rfds, wfds, efds, timo, mask);
48171b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
48271b3fa15SDavid Xu 
48371b3fa15SDavid Xu 	return (ret);
48471b3fa15SDavid Xu }
485ae7cb1b5SNicolas Thery __strong_reference(__pselect, pselect);
48671b3fa15SDavid Xu 
48771b3fa15SDavid Xu 
48871b3fa15SDavid Xu int
_raise(int sig)48971b3fa15SDavid Xu _raise(int sig)
49071b3fa15SDavid Xu {
49171b3fa15SDavid Xu 	int ret;
49271b3fa15SDavid Xu 
49371b3fa15SDavid Xu 	if (!_thr_isthreaded())
49471b3fa15SDavid Xu 		ret = kill(getpid(), sig);
495a9df9cc6SDavid Xu 	else
496a9df9cc6SDavid Xu 		ret = _thr_send_sig(tls_get_curthread(), sig);
49771b3fa15SDavid Xu 	return (ret);
49871b3fa15SDavid Xu }
49971b3fa15SDavid Xu 
5005a1048c8SDavid Xu __strong_reference(_raise, raise);
50171b3fa15SDavid Xu 
50271b3fa15SDavid Xu ssize_t
__read(int fd,void * buf,size_t nbytes)50371b3fa15SDavid Xu __read(int fd, void *buf, size_t nbytes)
50471b3fa15SDavid Xu {
505940be950Szrj 	pthread_t curthread = tls_get_curthread();
50671b3fa15SDavid Xu 	int oldcancel;
50771b3fa15SDavid Xu 	ssize_t	ret;
50871b3fa15SDavid Xu 
50971b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
51071b3fa15SDavid Xu 	ret = __sys_read(fd, buf, nbytes);
51171b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
51271b3fa15SDavid Xu 	return ret;
51371b3fa15SDavid Xu }
51471b3fa15SDavid Xu 
5155a1048c8SDavid Xu __strong_reference(__read, read);
51671b3fa15SDavid Xu 
51771b3fa15SDavid Xu ssize_t
__readv(int fd,const struct iovec * iov,int iovcnt)51871b3fa15SDavid Xu __readv(int fd, const struct iovec *iov, int iovcnt)
51971b3fa15SDavid Xu {
520940be950Szrj 	pthread_t curthread = tls_get_curthread();
52171b3fa15SDavid Xu 	int oldcancel;
52271b3fa15SDavid Xu 	ssize_t ret;
52371b3fa15SDavid Xu 
52471b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
52571b3fa15SDavid Xu 	ret = __sys_readv(fd, iov, iovcnt);
52671b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
52771b3fa15SDavid Xu 	return ret;
52871b3fa15SDavid Xu }
52971b3fa15SDavid Xu 
5305a1048c8SDavid Xu __strong_reference(__readv, readv);
53171b3fa15SDavid Xu 
53271b3fa15SDavid Xu ssize_t
__recvfrom(int s,void * b,size_t l,int f,struct sockaddr * from,socklen_t * fl)53371b3fa15SDavid Xu __recvfrom(int s, void *b, size_t l, int f, struct sockaddr *from,
53471b3fa15SDavid Xu     socklen_t *fl)
53571b3fa15SDavid Xu {
536940be950Szrj 	pthread_t curthread = tls_get_curthread();
53771b3fa15SDavid Xu 	int oldcancel;
53871b3fa15SDavid Xu 	ssize_t ret;
53971b3fa15SDavid Xu 
54071b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
54171b3fa15SDavid Xu 	ret = __sys_recvfrom(s, b, l, f, from, fl);
54271b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
54371b3fa15SDavid Xu 	return (ret);
54471b3fa15SDavid Xu }
54571b3fa15SDavid Xu 
5465a1048c8SDavid Xu __strong_reference(__recvfrom, recvfrom);
54771b3fa15SDavid Xu 
54871b3fa15SDavid Xu ssize_t
__recvmsg(int s,struct msghdr * m,int f)54971b3fa15SDavid Xu __recvmsg(int s, struct msghdr *m, int f)
55071b3fa15SDavid Xu {
551940be950Szrj 	pthread_t curthread = tls_get_curthread();
55271b3fa15SDavid Xu 	ssize_t ret;
55371b3fa15SDavid Xu 	int oldcancel;
55471b3fa15SDavid Xu 
55571b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
55671b3fa15SDavid Xu 	ret = __sys_recvmsg(s, m, f);
55771b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
55871b3fa15SDavid Xu 	return (ret);
55971b3fa15SDavid Xu }
56071b3fa15SDavid Xu 
5615a1048c8SDavid Xu __strong_reference(__recvmsg, recvmsg);
56271b3fa15SDavid Xu 
56371b3fa15SDavid Xu int
__select(int numfds,fd_set * readfds,fd_set * writefds,fd_set * exceptfds,struct timeval * timeout)56471b3fa15SDavid Xu __select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
56571b3fa15SDavid Xu 	struct timeval *timeout)
56671b3fa15SDavid Xu {
567940be950Szrj 	pthread_t curthread = tls_get_curthread();
56871b3fa15SDavid Xu 	int oldcancel;
56971b3fa15SDavid Xu 	int ret;
57071b3fa15SDavid Xu 
57171b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
57271b3fa15SDavid Xu 	ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);
57371b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
57471b3fa15SDavid Xu 	return ret;
57571b3fa15SDavid Xu }
57671b3fa15SDavid Xu 
5775a1048c8SDavid Xu __strong_reference(__select, select);
57871b3fa15SDavid Xu 
57971b3fa15SDavid Xu ssize_t
__sendmsg(int s,const struct msghdr * m,int f)58071b3fa15SDavid Xu __sendmsg(int s, const struct msghdr *m, int f)
58171b3fa15SDavid Xu {
582940be950Szrj 	pthread_t curthread = tls_get_curthread();
58371b3fa15SDavid Xu 	ssize_t ret;
58471b3fa15SDavid Xu 	int oldcancel;
58571b3fa15SDavid Xu 
58671b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
58771b3fa15SDavid Xu 	ret = __sys_sendmsg(s, m, f);
58871b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
58971b3fa15SDavid Xu 	return (ret);
59071b3fa15SDavid Xu }
59171b3fa15SDavid Xu 
5925a1048c8SDavid Xu __strong_reference(__sendmsg, sendmsg);
59371b3fa15SDavid Xu 
59471b3fa15SDavid Xu ssize_t
__sendto(int s,const void * m,size_t l,int f,const struct sockaddr * t,socklen_t tl)59571b3fa15SDavid Xu __sendto(int s, const void *m, size_t l, int f, const struct sockaddr *t,
59671b3fa15SDavid Xu     socklen_t tl)
59771b3fa15SDavid Xu {
598940be950Szrj 	pthread_t curthread = tls_get_curthread();
59971b3fa15SDavid Xu 	ssize_t ret;
60071b3fa15SDavid Xu 	int oldcancel;
60171b3fa15SDavid Xu 
60271b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
60371b3fa15SDavid Xu 	ret = __sys_sendto(s, m, l, f, t, tl);
60471b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
60571b3fa15SDavid Xu 	return (ret);
60671b3fa15SDavid Xu }
60771b3fa15SDavid Xu 
6085a1048c8SDavid Xu __strong_reference(__sendto, sendto);
6095a1048c8SDavid Xu 
61071b3fa15SDavid Xu unsigned int
_sleep(unsigned int seconds)61171b3fa15SDavid Xu _sleep(unsigned int seconds)
61271b3fa15SDavid Xu {
613940be950Szrj 	pthread_t	curthread = tls_get_curthread();
61471b3fa15SDavid Xu 	int		oldcancel;
61571b3fa15SDavid Xu 	unsigned int	ret;
61671b3fa15SDavid Xu 
61771b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
61871b3fa15SDavid Xu 	ret = __sleep(seconds);
61971b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
62071b3fa15SDavid Xu 	return (ret);
62171b3fa15SDavid Xu }
62271b3fa15SDavid Xu 
623811de3b6SMatthew Dillon __strong_reference(_sleep, sleep);
624811de3b6SMatthew Dillon 
62571b3fa15SDavid Xu int
_system(const char * string)62671b3fa15SDavid Xu _system(const char *string)
62771b3fa15SDavid Xu {
628940be950Szrj 	pthread_t curthread = tls_get_curthread();
62971b3fa15SDavid Xu 	int	oldcancel;
63071b3fa15SDavid Xu 	int	ret;
63171b3fa15SDavid Xu 
63271b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
63371b3fa15SDavid Xu 	ret = __system(string);
63471b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
63571b3fa15SDavid Xu 	return ret;
63671b3fa15SDavid Xu }
63771b3fa15SDavid Xu 
6385a1048c8SDavid Xu __strong_reference(_system, system);
63971b3fa15SDavid Xu 
64071b3fa15SDavid Xu int
_tcdrain(int fd)64171b3fa15SDavid Xu _tcdrain(int fd)
64271b3fa15SDavid Xu {
643940be950Szrj 	pthread_t curthread = tls_get_curthread();
64471b3fa15SDavid Xu 	int	oldcancel;
64571b3fa15SDavid Xu 	int	ret;
64671b3fa15SDavid Xu 
64771b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
64871b3fa15SDavid Xu 	ret = __tcdrain(fd);
64971b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
65071b3fa15SDavid Xu 	return (ret);
65171b3fa15SDavid Xu }
65271b3fa15SDavid Xu 
6535a1048c8SDavid Xu __strong_reference(_tcdrain, tcdrain);
654807d43a0SDavid Xu 
655807d43a0SDavid Xu int
___usleep(useconds_t useconds)6569e4cdec7SSascha Wildner ___usleep(useconds_t useconds)
657807d43a0SDavid Xu {
658940be950Szrj 	pthread_t	curthread = tls_get_curthread();
659807d43a0SDavid Xu 	int		oldcancel;
660807d43a0SDavid Xu 	int		ret;
661807d43a0SDavid Xu 
662807d43a0SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
663807d43a0SDavid Xu 	ret = __usleep(useconds);
664807d43a0SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
665807d43a0SDavid Xu 	return (ret);
666807d43a0SDavid Xu }
667807d43a0SDavid Xu 
6685a1048c8SDavid Xu __strong_reference(___usleep, usleep);
66971b3fa15SDavid Xu 
670f7511078SMatthew Dillon #if 0
671f7511078SMatthew Dillon /*
672f7511078SMatthew Dillon  * REMOVED - vfork() works as per normal.  In a threaded environment vfork()
673f7511078SMatthew Dillon  *	     blocks the calling thread only and not other threads.
674f7511078SMatthew Dillon  */
67571b3fa15SDavid Xu int
67671b3fa15SDavid Xu _vfork(void)
67771b3fa15SDavid Xu {
67871b3fa15SDavid Xu 	return (fork());
67971b3fa15SDavid Xu }
68071b3fa15SDavid Xu 
6815a1048c8SDavid Xu __strong_reference(_vfork, vfork);
682f7511078SMatthew Dillon #endif
68371b3fa15SDavid Xu 
68471b3fa15SDavid Xu pid_t
_wait(int * istat)68571b3fa15SDavid Xu _wait(int *istat)
68671b3fa15SDavid Xu {
687940be950Szrj 	pthread_t curthread = tls_get_curthread();
68871b3fa15SDavid Xu 	int	oldcancel;
68971b3fa15SDavid Xu 	pid_t	ret;
69071b3fa15SDavid Xu 
69171b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
69271b3fa15SDavid Xu 	ret = __wait(istat);
69371b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
69471b3fa15SDavid Xu 	return ret;
69571b3fa15SDavid Xu }
69671b3fa15SDavid Xu 
6975a1048c8SDavid Xu __strong_reference(_wait, wait);
69871b3fa15SDavid Xu 
69971b3fa15SDavid Xu pid_t
__wait4(pid_t pid,int * istat,int options,struct rusage * rusage)70071b3fa15SDavid Xu __wait4(pid_t pid, int *istat, int options, struct rusage *rusage)
70171b3fa15SDavid Xu {
702940be950Szrj 	pthread_t curthread = tls_get_curthread();
70371b3fa15SDavid Xu 	int oldcancel;
70471b3fa15SDavid Xu 	pid_t ret;
70571b3fa15SDavid Xu 
70671b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
70771b3fa15SDavid Xu 	ret = __sys_wait4(pid, istat, options, rusage);
70871b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
70971b3fa15SDavid Xu 	return ret;
71071b3fa15SDavid Xu }
71171b3fa15SDavid Xu 
7125a1048c8SDavid Xu __strong_reference(__wait4, wait4);
71371b3fa15SDavid Xu 
71471b3fa15SDavid Xu pid_t
_waitpid(pid_t wpid,int * status,int options)71571b3fa15SDavid Xu _waitpid(pid_t wpid, int *status, int options)
71671b3fa15SDavid Xu {
717940be950Szrj 	pthread_t curthread = tls_get_curthread();
71871b3fa15SDavid Xu 	int	oldcancel;
71971b3fa15SDavid Xu 	pid_t	ret;
72071b3fa15SDavid Xu 
72171b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
72271b3fa15SDavid Xu 	ret = __waitpid(wpid, status, options);
72371b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
72471b3fa15SDavid Xu 	return ret;
72571b3fa15SDavid Xu }
72671b3fa15SDavid Xu 
7275a1048c8SDavid Xu __strong_reference(_waitpid, waitpid);
72871b3fa15SDavid Xu 
72971b3fa15SDavid Xu ssize_t
__write(int fd,const void * buf,size_t nbytes)73071b3fa15SDavid Xu __write(int fd, const void *buf, size_t nbytes)
73171b3fa15SDavid Xu {
732940be950Szrj 	pthread_t curthread = tls_get_curthread();
73371b3fa15SDavid Xu 	int	oldcancel;
73471b3fa15SDavid Xu 	ssize_t	ret;
73571b3fa15SDavid Xu 
73671b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
73771b3fa15SDavid Xu 	ret = __sys_write(fd, buf, nbytes);
73871b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
73971b3fa15SDavid Xu 	return ret;
74071b3fa15SDavid Xu }
74171b3fa15SDavid Xu 
7425a1048c8SDavid Xu __strong_reference(__write, write);
74371b3fa15SDavid Xu 
74471b3fa15SDavid Xu ssize_t
__writev(int fd,const struct iovec * iov,int iovcnt)74571b3fa15SDavid Xu __writev(int fd, const struct iovec *iov, int iovcnt)
74671b3fa15SDavid Xu {
747940be950Szrj 	pthread_t curthread = tls_get_curthread();
74871b3fa15SDavid Xu 	int	oldcancel;
74971b3fa15SDavid Xu 	ssize_t ret;
75071b3fa15SDavid Xu 
75171b3fa15SDavid Xu 	oldcancel = _thr_cancel_enter(curthread);
75271b3fa15SDavid Xu 	ret = __sys_writev(fd, iov, iovcnt);
75371b3fa15SDavid Xu 	_thr_cancel_leave(curthread, oldcancel);
75471b3fa15SDavid Xu 	return ret;
75571b3fa15SDavid Xu }
7565a1048c8SDavid Xu 
7575a1048c8SDavid Xu __strong_reference(__writev, writev);
758