diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-05-07 19:05:25 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-05-07 19:05:25 +0000 |
commit | be4e94637d7117375492627b79c41629c7da9bc3 (patch) | |
tree | 61a9fabcc07d38d2720bbb937e83103928286550 /lib/libc/sys | |
parent | 33d8693716b4a6d503e0ba97f94a783905b87f28 (diff) |
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread
and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable!
Make libpthread dlopen'able by moving the cancelation wrappers into libc
and doing locking and fork/errno handling via callbacks that libpthread
registers when it first initializes. 'errno' *must* be declared via
<errno.h> now!
Clean up libpthread's symbol exports like libc.
On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec.
Testing by various, particularly sthen@ and patrick@
ok kettenis@
Diffstat (limited to 'lib/libc/sys')
39 files changed, 1176 insertions, 55 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 8d85a113bf7..aca044f5b22 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.141 2016/03/30 07:55:36 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.142 2016/05/07 19:05:22 guenther Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -6,16 +6,15 @@ .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/sys ${LIBCSRCDIR}/sys # modules with non-default implementations on at least one architecture: -SRCS+= Ovfork.S brk.S cerror.S fork.S \ +SRCS+= Ovfork.S brk.S ${CERROR} \ sbrk.S sigpending.S sigprocmask.S sigreturn.S \ sigsuspend.S syscall.S tfork_thread.S # glue to offer userland wrappers for some syscalls SRCS+= posix_madvise.c pthread_sigmask.c \ - w_fork.c w_sigaction.c w_sigprocmask.c + w_fork.c w_sigaction.c w_sigprocmask.c w_sigsuspend.c w_vfork.c -# glue to provide compatibility between GCC 1.X and 2.X and for compat -# with old syscall interfaces. +# glue for compat with old syscall interfaces. SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \ timer_create.c timer_delete.c timer_getoverrun.c timer_gettime.c \ timer_settime.c pread.c preadv.c pwrite.c pwritev.c @@ -23,18 +22,37 @@ SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \ # stack protector helper functions SRCS+= stack_protector.c +# cancelation details +SRCS+= canceled.c + +# syscalls that would be normal...except for cancellation or SIGTHR +CANCEL= accept accept4 \ + close closefrom connect \ + fcntl fsync \ + msgrcv msgsnd msync \ + nanosleep \ + open openat \ + poll ppoll pselect \ + read readv recvfrom recvmsg \ + select sendmsg sendto \ + wait4 write writev +SRCS+= ${CANCEL:%=w_%.c} w_pread.c w_preadv.c w_pwrite.c w_pwritev.c + # modules with default implementations on all architectures, unless overridden # below: ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \ __threxit.o __thrsigdivert.o __thrsleep.o \ - __thrwakeup.o accept.o accept4.o access.o acct.o adjfreq.o adjtime.o \ + __thrwakeup.o \ + access.o acct.o adjfreq.o adjtime.o \ bind.o chdir.o chflags.o chflagsat.o chmod.o chown.o chroot.o \ - clock_getres.o clock_gettime.o clock_settime.o close.o \ - closefrom.o connect.o dup.o dup2.o dup3.o execve.o faccessat.o \ - fchdir.o fchflags.o fchmod.o fchmodat.o fchown.o \ - fchownat.o fcntl.o fhopen.o fhstat.o fhstatfs.o \ + clock_getres.o clock_gettime.o clock_settime.o \ + dup.o dup2.o dup3.o \ + execve.o \ + faccessat.o fchdir.o fchflags.o fchmod.o fchmodat.o fchown.o \ + fchownat.o fhopen.o fhstat.o fhstatfs.o \ flock.o fpathconf.o fstat.o fstatat.o fstatfs.o \ - fsync.o futimens.o futimes.o getentropy.o getdents.o getdtablecount.o \ + futimens.o futimes.o \ + getentropy.o getdents.o getdtablecount.o \ getegid.o geteuid.o getfh.o getfsstat.o getgid.o \ getgroups.o getitimer.o getpeername.o getpgid.o getpgrp.o \ getpid.o getppid.o getpriority.o getresgid.o getresuid.o \ @@ -44,14 +62,13 @@ ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \ link.o linkat.o listen.o lstat.o madvise.o mincore.o \ minherit.o mkdir.o mkdirat.o mkfifo.o mkfifoat.o \ mknod.o mknodat.o mlock.o mlockall.o mount.o mprotect.o \ - msgctl.o msgget.o msgrcv.o msgsnd.o msync.o munlock.o \ - munlockall.o munmap.o nanosleep.o nfssvc.o \ - open.o openat.o pathconf.o pipe.o pipe2.o pledge.o \ - poll.o ppoll.o profil.o pselect.o \ - quotactl.o read.o readlink.o readlinkat.o readv.o reboot.o \ - recvfrom.o recvmsg.o rename.o renameat.o revoke.o rmdir.o \ - sched_yield.o select.o semget.o semop.o sendmsg.o sendsyslog.o \ - sendto.o \ + msgctl.o msgget.o munlock.o munlockall.o munmap.o \ + nfssvc.o \ + pathconf.o pipe.o pipe2.o pledge.o profil.o \ + quotactl.o \ + readlink.o readlinkat.o reboot.o \ + rename.o renameat.o revoke.o rmdir.o \ + sched_yield.o semget.o semop.o sendsyslog.o \ setegid.o seteuid.o setgid.o setgroups.o setitimer.o setlogin.o \ setpgid.o setpriority.o setregid.o setresgid.o setresuid.o \ setreuid.o setrlimit.o setrtable.o setsid.o setsockopt.o \ @@ -59,7 +76,7 @@ ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \ shmget.o shutdown.o sigaltstack.o socket.o \ socketpair.o stat.o statfs.o swapctl.o symlink.o symlinkat.o \ sync.o sysarch.o sysctl.o thrkill.o umask.o unlink.o unlinkat.o \ - unmount.o utimensat.o utimes.o utrace.o wait4.o write.o writev.o + unmount.o utimensat.o utimes.o utrace.o SRCS+= ${SRCS_${MACHINE_CPU}} .for i in ${SRCS_${MACHINE_CPU}} @@ -83,7 +100,7 @@ PPSEUDO_NOERR=${PSEUDO_NOERR:.o=.po} SPSEUDO_NOERR=${PSEUDO_NOERR:.o=.so} DPSEUDO_NOERR=${PSEUDO_NOERR:.o=.do} -HIDDEN= sigaction.o _ptrace.o +HIDDEN= fork.o sigaction.o _ptrace.o ${CANCEL:=.o} GHIDDEN=${HIDDEN:.o=.go} PHIDDEN=${HIDDEN:.o=.po} SHIDDEN=${HIDDEN:.o=.so} diff --git a/lib/libc/sys/canceled.c b/lib/libc/sys/canceled.c new file mode 100644 index 00000000000..7bf02c93552 --- /dev/null +++ b/lib/libc/sys/canceled.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> +#include "cancel.h" + +void +_thread_canceled(void) +{ + if (_thread_cb.tc_canceled != NULL) + _thread_cb.tc_canceled(); + exit(0); +} + diff --git a/lib/libc/sys/pread.c b/lib/libc/sys/pread.c index 4c522399217..54f6134ae5f 100644 --- a/lib/libc/sys/pread.c +++ b/lib/libc/sys/pread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pread.c,v 1.10 2015/09/11 13:26:20 guenther Exp $ */ +/* $OpenBSD: pread.c,v 1.11 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 1992, 1993 @@ -31,24 +31,20 @@ #include <sys/syscall.h> #include <unistd.h> -#include "thread_private.h" ssize_t __syscall(quad_t, ...); PROTO_NORMAL(__syscall); -DEF_SYS(ftruncate); +DEF_SYS(pread); -STUB_PROTOTYPE(pread); - -STUB_ALIAS(pread); /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -STUB_NAME(pread)(int fd, void *buf, size_t nbyte, off_t offset) +HIDDEN(pread)(int fd, void *buf, size_t nbyte, off_t offset) { return (__syscall(SYS_pread, fd, buf, nbyte, 0, offset)); } diff --git a/lib/libc/sys/preadv.c b/lib/libc/sys/preadv.c index 5e008f47ce1..3b53ffafd76 100644 --- a/lib/libc/sys/preadv.c +++ b/lib/libc/sys/preadv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: preadv.c,v 1.10 2015/09/11 13:26:20 guenther Exp $ */ +/* $OpenBSD: preadv.c,v 1.11 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 1992, 1993 @@ -29,25 +29,22 @@ * SUCH DAMAGE. */ +#include <sys/types.h> #include <sys/syscall.h> #include <sys/uio.h> -#include <unistd.h> -#include "thread_private.h" ssize_t __syscall(quad_t, ...); PROTO_NORMAL(__syscall); -STUB_PROTOTYPE(preadv); - -STUB_ALIAS(preadv); +DEF_SYS(preadv); /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -STUB_NAME(preadv)(int fd, const struct iovec *iovp, int iovcnt, off_t offset) +HIDDEN(preadv)(int fd, const struct iovec *iovp, int iovcnt, off_t offset) { return (__syscall(SYS_preadv, fd, iovp, iovcnt, 0, offset)); } diff --git a/lib/libc/sys/pwrite.c b/lib/libc/sys/pwrite.c index 445b12ab430..2c99f4912a5 100644 --- a/lib/libc/sys/pwrite.c +++ b/lib/libc/sys/pwrite.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwrite.c,v 1.10 2015/09/11 13:26:20 guenther Exp $ */ +/* $OpenBSD: pwrite.c,v 1.11 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 1992, 1993 @@ -31,22 +31,19 @@ #include <sys/syscall.h> #include <unistd.h> -#include "thread_private.h" ssize_t __syscall(quad_t, ...); PROTO_NORMAL(__syscall); -STUB_PROTOTYPE(pwrite); - -STUB_ALIAS(pwrite); +DEF_SYS(pwrite); /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -STUB_NAME(pwrite)(int fd, const void *buf, size_t nbyte, off_t offset) +HIDDEN(pwrite)(int fd, const void *buf, size_t nbyte, off_t offset) { return (__syscall(SYS_pwrite, fd, buf, nbyte, 0, offset)); } diff --git a/lib/libc/sys/pwritev.c b/lib/libc/sys/pwritev.c index a6008ef2c19..92b47c4e714 100644 --- a/lib/libc/sys/pwritev.c +++ b/lib/libc/sys/pwritev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwritev.c,v 1.10 2015/09/11 13:26:20 guenther Exp $ */ +/* $OpenBSD: pwritev.c,v 1.11 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 1992, 1993 @@ -29,25 +29,22 @@ * SUCH DAMAGE. */ +#include <sys/types.h> #include <sys/syscall.h> #include <sys/uio.h> -#include <unistd.h> -#include "thread_private.h" ssize_t __syscall(quad_t, ...); PROTO_NORMAL(__syscall); -STUB_PROTOTYPE(pwritev); - -STUB_ALIAS(pwritev); +DEF_SYS(pwritev); /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -STUB_NAME(pwritev)(int fd, const struct iovec *iovp, int iovcnt, off_t offset) +HIDDEN(pwritev)(int fd, const struct iovec *iovp, int iovcnt, off_t offset) { return (__syscall(SYS_pwritev, fd, iovp, iovcnt, 0, offset)); diff --git a/lib/libc/sys/w_accept.c b/lib/libc/sys/w_accept.c new file mode 100644 index 00000000000..1d75c5bc5d4 --- /dev/null +++ b/lib/libc/sys/w_accept.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_accept.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +int +accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(accept)(s, addr, addrlen); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(accept); diff --git a/lib/libc/sys/w_accept4.c b/lib/libc/sys/w_accept4.c new file mode 100644 index 00000000000..a32019e637e --- /dev/null +++ b/lib/libc/sys/w_accept4.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_accept4.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +int +accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(accept4)(s, addr, addrlen, flags); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(accept4); diff --git a/lib/libc/sys/w_close.c b/lib/libc/sys/w_close.c new file mode 100644 index 00000000000..e481c1e11c6 --- /dev/null +++ b/lib/libc/sys/w_close.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_close.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +int +close(int fd) +{ + int ret; + + ENTER_CANCEL_POINT(0); + ret = HIDDEN(close)(fd); + LEAVE_CANCEL_POINT(1); + return (ret); +} +DEF_CANCEL(close); diff --git a/lib/libc/sys/w_closefrom.c b/lib/libc/sys/w_closefrom.c new file mode 100644 index 00000000000..1c9e5a0152f --- /dev/null +++ b/lib/libc/sys/w_closefrom.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_closefrom.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +int +closefrom(int fd) +{ + int ret; + + ENTER_CANCEL_POINT(0); + ret = HIDDEN(closefrom)(fd); + LEAVE_CANCEL_POINT(1); + return (ret); +} +DEF_CANCEL(closefrom); diff --git a/lib/libc/sys/w_connect.c b/lib/libc/sys/w_connect.c new file mode 100644 index 00000000000..4b6ab8aa8ea --- /dev/null +++ b/lib/libc/sys/w_connect.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_connect.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +int +connect(int s, const struct sockaddr *name, socklen_t namelen) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(connect)(s, name, namelen); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(connect); diff --git a/lib/libc/sys/w_fcntl.c b/lib/libc/sys/w_fcntl.c new file mode 100644 index 00000000000..c30367ad32c --- /dev/null +++ b/lib/libc/sys/w_fcntl.c @@ -0,0 +1,59 @@ +/* $OpenBSD: w_fcntl.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <fcntl.h> +#include <stdarg.h> +#include "cancel.h" + +int +fcntl(int fd, int cmd, ...) +{ + va_list ap; + int ret; + + va_start(ap, cmd); + switch (cmd) { + case F_DUPFD: + case F_DUPFD_CLOEXEC: + case F_SETFD: + case F_SETFL: + case F_SETOWN: + ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, int)); + break; + case F_GETFD: + case F_GETFL: + case F_GETOWN: + case F_ISATTY: + ret = HIDDEN(fcntl)(fd, cmd); + break; + case F_GETLK: + case F_SETLK: + ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, struct flock *)); + break; + case F_SETLKW: + ENTER_CANCEL_POINT(1); + ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, struct flock *)); + LEAVE_CANCEL_POINT(ret == -1); + break; + default: /* should never happen? */ + ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, void *)); + break; + } + va_end(ap); + return (ret); +} +DEF_CANCEL(fcntl); diff --git a/lib/libc/sys/w_fork.c b/lib/libc/sys/w_fork.c index 89415491f82..668731fdf67 100644 --- a/lib/libc/sys/w_fork.c +++ b/lib/libc/sys/w_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: w_fork.c,v 1.2 2015/10/25 18:03:17 guenther Exp $ */ +/* $OpenBSD: w_fork.c,v 1.3 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2008 Kurt Miller <kurt@openbsd.org> @@ -30,14 +30,13 @@ * $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $ */ +#include <tib.h> #include <unistd.h> #include "thread_private.h" #include "atfork.h" -pid_t _thread_fork(void); - pid_t -fork(void) +WRAP(fork)(void) { struct atfork_fn *p; pid_t newid; @@ -46,15 +45,27 @@ fork(void) * In the common case the list is empty; remain async-signal-safe * then by skipping the locking and just forking */ - if (TAILQ_FIRST(&_atfork_list) == NULL) - return (_thread_fork()); + if (TAILQ_FIRST(&_atfork_list) == NULL) { + if (_thread_cb.tc_fork != NULL) + return _thread_cb.tc_fork(); + newid = fork(); + if (newid == 0) + TIB_GET()->tib_tid = getthrid(); + return newid; + } _ATFORK_LOCK(); TAILQ_FOREACH_REVERSE(p, &_atfork_list, atfork_listhead, fn_next) if (p->fn_prepare) p->fn_prepare(); - newid = _thread_fork(); + if (_thread_cb.tc_fork != NULL) + newid = _thread_cb.tc_fork(); + else { + newid = fork(); + if (newid == 0) + TIB_GET()->tib_tid = getthrid(); + } if (newid == 0) { TAILQ_FOREACH(p, &_atfork_list, fn_next) @@ -69,3 +80,4 @@ fork(void) return (newid); } +DEF_WRAP(fork); diff --git a/lib/libc/sys/w_fsync.c b/lib/libc/sys/w_fsync.c new file mode 100644 index 00000000000..095c3806935 --- /dev/null +++ b/lib/libc/sys/w_fsync.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_fsync.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +int +fsync(int fd) +{ + int ret; + + ENTER_CANCEL_POINT(0); + ret = HIDDEN(fsync)(fd); + LEAVE_CANCEL_POINT(1); + return (ret); +} +DEF_CANCEL(fsync); diff --git a/lib/libc/sys/w_msgrcv.c b/lib/libc/sys/w_msgrcv.c new file mode 100644 index 00000000000..605af2056f4 --- /dev/null +++ b/lib/libc/sys/w_msgrcv.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_msgrcv.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/msg.h> +#include "cancel.h" + +int +msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(msgrcv)(msqid, msgp, msgsz, msgtyp, msgflg); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(msgrcv); diff --git a/lib/libc/sys/w_msgsnd.c b/lib/libc/sys/w_msgsnd.c new file mode 100644 index 00000000000..b958331b0e5 --- /dev/null +++ b/lib/libc/sys/w_msgsnd.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_msgsnd.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/msg.h> +#include "cancel.h" + +int +msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(msgsnd)(msqid, msgp, msgsz, msgflg); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(msgsnd); diff --git a/lib/libc/sys/w_msync.c b/lib/libc/sys/w_msync.c new file mode 100644 index 00000000000..ae64b54480d --- /dev/null +++ b/lib/libc/sys/w_msync.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_msync.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/mman.h> +#include "cancel.h" + +int +msync(void *addr, size_t len, int flags) +{ + int ret; + + ENTER_CANCEL_POINT(0); + ret = HIDDEN(msync)(addr, len, flags); + LEAVE_CANCEL_POINT(1); + return (ret); +} +DEF_CANCEL(msync); diff --git a/lib/libc/sys/w_nanosleep.c b/lib/libc/sys/w_nanosleep.c new file mode 100644 index 00000000000..94f095cd6ca --- /dev/null +++ b/lib/libc/sys/w_nanosleep.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_nanosleep.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <time.h> +#include "cancel.h" + +int +nanosleep(const struct timespec *timeout, struct timespec *remainder) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(nanosleep)(timeout, remainder); + LEAVE_CANCEL_POINT(1); + return (ret); +} +DEF_CANCEL(nanosleep); diff --git a/lib/libc/sys/w_open.c b/lib/libc/sys/w_open.c new file mode 100644 index 00000000000..09f62542049 --- /dev/null +++ b/lib/libc/sys/w_open.c @@ -0,0 +1,41 @@ +/* $OpenBSD: w_open.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <fcntl.h> +#include <stdarg.h> +#include "cancel.h" + +int +open(const char *path, int flags, ...) +{ + va_list ap; + mode_t mode = 0; + int ret; + + if (flags & O_CREAT) { + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(open)(path, flags, mode); + LEAVE_CANCEL_POINT(ret == -1); + + return (ret); +} +DEF_CANCEL(open); diff --git a/lib/libc/sys/w_openat.c b/lib/libc/sys/w_openat.c new file mode 100644 index 00000000000..c797cf7bc61 --- /dev/null +++ b/lib/libc/sys/w_openat.c @@ -0,0 +1,41 @@ +/* $OpenBSD: w_openat.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <fcntl.h> +#include <stdarg.h> +#include "cancel.h" + +int +openat(int fd, const char *path, int flags, ...) +{ + va_list ap; + mode_t mode = 0; + int ret; + + if (flags & O_CREAT) { + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(openat)(fd, path, flags, mode); + LEAVE_CANCEL_POINT(ret == -1); + + return (ret); +} +DEF_CANCEL(openat); diff --git a/lib/libc/sys/w_poll.c b/lib/libc/sys/w_poll.c new file mode 100644 index 00000000000..8ffc6b2865c --- /dev/null +++ b/lib/libc/sys/w_poll.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_poll.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <poll.h> +#include "cancel.h" + +int +poll(struct pollfd *fds, nfds_t nfds, int timeout) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(poll)(fds, nfds, timeout); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(poll); diff --git a/lib/libc/sys/w_ppoll.c b/lib/libc/sys/w_ppoll.c new file mode 100644 index 00000000000..2e6f93c015b --- /dev/null +++ b/lib/libc/sys/w_ppoll.c @@ -0,0 +1,41 @@ +/* $OpenBSD: w_ppoll.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <poll.h> +#include <signal.h> +#include "cancel.h" + +int +ppoll(struct pollfd *fds, nfds_t nfds, + const struct timespec *timeout, const sigset_t *sigmask) +{ + sigset_t set; + int ret; + + if (sigmask != NULL && sigismember(sigmask, SIGTHR)) { + set = *sigmask; + sigdelset(&set, SIGTHR); + sigmask = &set; + } + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(ppoll)(fds, nfds, timeout, sigmask); + LEAVE_CANCEL_POINT(ret == -1); + + return (ret); +} +DEF_CANCEL(ppoll); diff --git a/lib/libc/sys/w_pread.c b/lib/libc/sys/w_pread.c new file mode 100644 index 00000000000..4651f8bea34 --- /dev/null +++ b/lib/libc/sys/w_pread.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_pread.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +ssize_t +pread(int fd, void *buf, size_t nbyte, off_t offset) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(pread)(fd, buf, nbyte, offset); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(pread); diff --git a/lib/libc/sys/w_preadv.c b/lib/libc/sys/w_preadv.c new file mode 100644 index 00000000000..39750066b3c --- /dev/null +++ b/lib/libc/sys/w_preadv.c @@ -0,0 +1,32 @@ +/* $OpenBSD: w_preadv.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/uio.h> +#include <unistd.h> +#include "cancel.h" + +ssize_t +preadv(int fd, const struct iovec *iovp, int iovcnt, off_t offset) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(preadv)(fd, iovp, iovcnt, offset); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(preadv); diff --git a/lib/libc/sys/w_pselect.c b/lib/libc/sys/w_pselect.c new file mode 100644 index 00000000000..40f76e6dbd1 --- /dev/null +++ b/lib/libc/sys/w_pselect.c @@ -0,0 +1,42 @@ +/* $OpenBSD: w_pselect.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/select.h> +#include <signal.h> +#include "cancel.h" + +int +pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask) +{ + sigset_t set; + int ret; + + if (sigmask != NULL && sigismember(sigmask, SIGTHR)) { + set = *sigmask; + sigdelset(&set, SIGTHR); + sigmask = &set; + } + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(pselect)(nfds, readfds, writefds, exceptfds, timeout, + sigmask); + LEAVE_CANCEL_POINT(ret == -1); + + return (ret); +} +DEF_CANCEL(pselect); diff --git a/lib/libc/sys/w_pwrite.c b/lib/libc/sys/w_pwrite.c new file mode 100644 index 00000000000..fc2d524f0e7 --- /dev/null +++ b/lib/libc/sys/w_pwrite.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_pwrite.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +ssize_t +pwrite(int fd, const void *buf, size_t nbyte, off_t offset) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(pwrite)(fd, buf, nbyte, offset); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(pwrite); diff --git a/lib/libc/sys/w_pwritev.c b/lib/libc/sys/w_pwritev.c new file mode 100644 index 00000000000..89efcb40627 --- /dev/null +++ b/lib/libc/sys/w_pwritev.c @@ -0,0 +1,32 @@ +/* $OpenBSD: w_pwritev.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/uio.h> +#include <unistd.h> +#include "cancel.h" + +ssize_t +pwritev(int fd, const struct iovec *iovp, int iovcnt, off_t offset) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(pwritev)(fd, iovp, iovcnt, offset); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(pwritev); diff --git a/lib/libc/sys/w_read.c b/lib/libc/sys/w_read.c new file mode 100644 index 00000000000..9a255e76e32 --- /dev/null +++ b/lib/libc/sys/w_read.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_read.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +ssize_t +read(int fd, void *buf, size_t nbytes) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(read)(fd, buf, nbytes); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(read); diff --git a/lib/libc/sys/w_readv.c b/lib/libc/sys/w_readv.c new file mode 100644 index 00000000000..7034f121e70 --- /dev/null +++ b/lib/libc/sys/w_readv.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_readv.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/uio.h> +#include "cancel.h" + +ssize_t +readv(int fd, const struct iovec *iov, int iovcnt) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(readv)(fd, iov, iovcnt); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(readv); diff --git a/lib/libc/sys/w_recvfrom.c b/lib/libc/sys/w_recvfrom.c new file mode 100644 index 00000000000..f89cfc4ccae --- /dev/null +++ b/lib/libc/sys/w_recvfrom.c @@ -0,0 +1,32 @@ +/* $OpenBSD: w_recvfrom.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +ssize_t +recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, + socklen_t *addrlen) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(recvfrom)(fd, buf, len, flags, addr, addrlen); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(recvfrom); diff --git a/lib/libc/sys/w_recvmsg.c b/lib/libc/sys/w_recvmsg.c new file mode 100644 index 00000000000..c2474d33fcb --- /dev/null +++ b/lib/libc/sys/w_recvmsg.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_recvmsg.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +ssize_t +recvmsg(int fd, struct msghdr *msg, int flags) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(recvmsg)(fd, msg, flags); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(recvmsg); diff --git a/lib/libc/sys/w_select.c b/lib/libc/sys/w_select.c new file mode 100644 index 00000000000..a25e8222ca8 --- /dev/null +++ b/lib/libc/sys/w_select.c @@ -0,0 +1,32 @@ +/* $OpenBSD: w_select.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/select.h> +#include "cancel.h" + +int +select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(select)(nfds, readfds, writefds, exceptfds, timeout); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(select); diff --git a/lib/libc/sys/w_sendmsg.c b/lib/libc/sys/w_sendmsg.c new file mode 100644 index 00000000000..d184a212e59 --- /dev/null +++ b/lib/libc/sys/w_sendmsg.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_sendmsg.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +ssize_t +sendmsg(int s, const struct msghdr *msg, int flags) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(sendmsg)(s, msg, flags); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(sendmsg); diff --git a/lib/libc/sys/w_sendto.c b/lib/libc/sys/w_sendto.c new file mode 100644 index 00000000000..5047181badd --- /dev/null +++ b/lib/libc/sys/w_sendto.c @@ -0,0 +1,32 @@ +/* $OpenBSD: w_sendto.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +ssize_t +sendto(int fd, const void *msg, size_t len, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(sendto)(fd, msg, len, flags, to, tolen); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(sendto); diff --git a/lib/libc/sys/w_sigsuspend.c b/lib/libc/sys/w_sigsuspend.c new file mode 100644 index 00000000000..80f91e0529d --- /dev/null +++ b/lib/libc/sys/w_sigsuspend.c @@ -0,0 +1,40 @@ +/* $OpenBSD: w_sigsuspend.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <signal.h> +#include <errno.h> +#include "cancel.h" + +int +sigsuspend(const sigset_t *set) +{ + sigset_t s; + int ret; + + if (sigismember(set, SIGTHR)) { + s = *set; + sigdelset(&s, SIGTHR); + set = &s; + } + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(sigsuspend)(set); + LEAVE_CANCEL_POINT(1); + + return (ret); +} +DEF_CANCEL(sigsuspend); diff --git a/lib/libc/sys/w_vfork.c b/lib/libc/sys/w_vfork.c new file mode 100644 index 00000000000..9716f57ec6b --- /dev/null +++ b/lib/libc/sys/w_vfork.c @@ -0,0 +1,34 @@ +/* $OpenBSD: w_vfork.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <tib.h> +#include <unistd.h> +#include "thread_private.h" + +pid_t +WRAP(vfork)(void) +{ + pid_t newid; + + if (_thread_cb.tc_vfork != NULL) + return (_thread_cb.tc_vfork()); + newid = vfork(); + if (newid == 0) + TIB_GET()->tib_tid = getthrid(); + return newid; +} +DEF_WRAP(vfork); diff --git a/lib/libc/sys/w_wait4.c b/lib/libc/sys/w_wait4.c new file mode 100644 index 00000000000..ba84445f7d9 --- /dev/null +++ b/lib/libc/sys/w_wait4.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_wait4.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/wait.h> +#include "cancel.h" + +int +wait4(pid_t wpid, int *status, int options, struct rusage *rusage) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(wait4)(wpid, status, options, rusage); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(wait4); diff --git a/lib/libc/sys/w_write.c b/lib/libc/sys/w_write.c new file mode 100644 index 00000000000..cb3fa1eff9e --- /dev/null +++ b/lib/libc/sys/w_write.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_write.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <unistd.h> +#include "cancel.h" + +ssize_t +write(int fd, const void *buf, size_t nbytes) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(write)(fd, buf, nbytes); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(write); diff --git a/lib/libc/sys/w_writev.c b/lib/libc/sys/w_writev.c new file mode 100644 index 00000000000..c845238c0b2 --- /dev/null +++ b/lib/libc/sys/w_writev.c @@ -0,0 +1,31 @@ +/* $OpenBSD: w_writev.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/uio.h> +#include "cancel.h" + +ssize_t +writev(int fd, const struct iovec *iov, int iovcnt) +{ + ssize_t ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(writev)(fd, iov, iovcnt); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(writev); |