summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/Makefile.inc4
-rw-r--r--lib/libc/Symbols.list22
-rw-r--r--lib/libc/arch/alpha/Makefile.inc4
-rw-r--r--lib/libc/arch/alpha/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/alpha/sys/cerror.S25
-rw-r--r--lib/libc/arch/alpha/sys/fork.S34
-rw-r--r--lib/libc/arch/alpha/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/amd64/SYS.h64
-rw-r--r--lib/libc/arch/amd64/sys/Ovfork.S14
-rw-r--r--lib/libc/arch/amd64/sys/brk.S22
-rw-r--r--lib/libc/arch/amd64/sys/cerror.S55
-rw-r--r--lib/libc/arch/amd64/sys/fork.S43
-rw-r--r--lib/libc/arch/amd64/sys/sbrk.S21
-rw-r--r--lib/libc/arch/amd64/sys/sigprocmask.S14
-rw-r--r--lib/libc/arch/amd64/sys/sigsuspend.S16
-rw-r--r--lib/libc/arch/amd64/sys/syscall.S17
-rw-r--r--lib/libc/arch/amd64/sys/tfork_thread.S10
-rw-r--r--lib/libc/arch/arm/Makefile.inc4
-rw-r--r--lib/libc/arch/arm/SYS.h3
-rw-r--r--lib/libc/arch/arm/sys/Ovfork.S6
-rw-r--r--lib/libc/arch/arm/sys/cerror.S35
-rw-r--r--lib/libc/arch/arm/sys/fork.S38
-rw-r--r--lib/libc/arch/arm/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/hppa/SYS.h17
-rw-r--r--lib/libc/arch/hppa/sys/Ovfork.S17
-rw-r--r--lib/libc/arch/hppa/sys/cerror.S48
-rw-r--r--lib/libc/arch/hppa/sys/fork.S32
-rw-r--r--lib/libc/arch/hppa/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/hppa64/SYS.h18
-rw-r--r--lib/libc/arch/hppa64/sys/Ovfork.S15
-rw-r--r--lib/libc/arch/hppa64/sys/cerror.S48
-rw-r--r--lib/libc/arch/hppa64/sys/fork.S32
-rw-r--r--lib/libc/arch/hppa64/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/i386/SYS.h51
-rw-r--r--lib/libc/arch/i386/sys/Ovfork.S19
-rw-r--r--lib/libc/arch/i386/sys/brk.S13
-rw-r--r--lib/libc/arch/i386/sys/cerror.S52
-rw-r--r--lib/libc/arch/i386/sys/fork.S37
-rw-r--r--lib/libc/arch/i386/sys/sbrk.S13
-rw-r--r--lib/libc/arch/i386/sys/sigprocmask.S13
-rw-r--r--lib/libc/arch/i386/sys/sigsuspend.S18
-rw-r--r--lib/libc/arch/i386/sys/syscall.S13
-rw-r--r--lib/libc/arch/i386/sys/tfork_thread.S12
-rw-r--r--lib/libc/arch/m88k/Makefile.inc3
-rw-r--r--lib/libc/arch/m88k/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/m88k/sys/cerror.S48
-rw-r--r--lib/libc/arch/m88k/sys/fork.S39
-rw-r--r--lib/libc/arch/m88k/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/mips64/Makefile.inc3
-rw-r--r--lib/libc/arch/mips64/SYS.h6
-rw-r--r--lib/libc/arch/mips64/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/mips64/sys/cerror.S38
-rw-r--r--lib/libc/arch/mips64/sys/fork.S37
-rw-r--r--lib/libc/arch/mips64/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/powerpc/Makefile.inc3
-rw-r--r--lib/libc/arch/powerpc/SYS.h6
-rw-r--r--lib/libc/arch/powerpc/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/powerpc/sys/brk.S4
-rw-r--r--lib/libc/arch/powerpc/sys/cerror.S13
-rw-r--r--lib/libc/arch/powerpc/sys/fork.S33
-rw-r--r--lib/libc/arch/powerpc/sys/sbrk.S4
-rw-r--r--lib/libc/arch/powerpc/sys/sigprocmask.S4
-rw-r--r--lib/libc/arch/powerpc/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/powerpc/sys/tfork_thread.S4
-rw-r--r--lib/libc/arch/sh/Makefile.inc3
-rw-r--r--lib/libc/arch/sh/SYS.h3
-rw-r--r--lib/libc/arch/sh/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/sh/sys/cerror.S41
-rw-r--r--lib/libc/arch/sh/sys/fork.S41
-rw-r--r--lib/libc/arch/sh/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/sparc/SYS.h33
-rw-r--r--lib/libc/arch/sparc/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/sparc/sys/cerror.S59
-rw-r--r--lib/libc/arch/sparc/sys/fork.S38
-rw-r--r--lib/libc/arch/sparc/sys/sigsuspend.S6
-rw-r--r--lib/libc/arch/sparc64/SYS.h28
-rw-r--r--lib/libc/arch/sparc64/sys/Ovfork.S4
-rw-r--r--lib/libc/arch/sparc64/sys/cerror.S57
-rw-r--r--lib/libc/arch/sparc64/sys/fork.S41
-rw-r--r--lib/libc/arch/sparc64/sys/sigsuspend.S6
-rw-r--r--lib/libc/dlfcn/Makefile.inc4
-rw-r--r--lib/libc/dlfcn/init.c108
-rw-r--r--lib/libc/dlfcn/tib.c86
-rw-r--r--lib/libc/gen/errno.c67
-rw-r--r--lib/libc/gen/getcwd.c3
-rw-r--r--lib/libc/hidden/errno.h4
-rw-r--r--lib/libc/hidden/fcntl.h8
-rw-r--r--lib/libc/hidden/poll.h27
-rw-r--r--lib/libc/hidden/signal.h7
-rw-r--r--lib/libc/hidden/stdio.h8
-rw-r--r--lib/libc/hidden/sys/mman.h4
-rw-r--r--lib/libc/hidden/sys/msg.h28
-rw-r--r--lib/libc/hidden/sys/select.h27
-rw-r--r--lib/libc/hidden/sys/socket.h9
-rw-r--r--lib/libc/hidden/sys/uio.h28
-rw-r--r--lib/libc/hidden/sys/wait.h4
-rw-r--r--lib/libc/hidden/tib.h46
-rw-r--r--lib/libc/hidden/time.h4
-rw-r--r--lib/libc/hidden/unistd.h24
-rw-r--r--lib/libc/include/cancel.h75
-rw-r--r--lib/libc/include/namespace.h6
-rw-r--r--lib/libc/include/thread_private.h306
-rw-r--r--lib/libc/shlib_version2
-rw-r--r--lib/libc/stdio/flockfile.c36
-rw-r--r--lib/libc/stdio/local.h15
-rw-r--r--lib/libc/sys/Makefile.inc59
-rw-r--r--lib/libc/sys/canceled.c27
-rw-r--r--lib/libc/sys/pread.c10
-rw-r--r--lib/libc/sys/preadv.c11
-rw-r--r--lib/libc/sys/pwrite.c9
-rw-r--r--lib/libc/sys/pwritev.c11
-rw-r--r--lib/libc/sys/w_accept.c31
-rw-r--r--lib/libc/sys/w_accept4.c31
-rw-r--r--lib/libc/sys/w_close.c31
-rw-r--r--lib/libc/sys/w_closefrom.c31
-rw-r--r--lib/libc/sys/w_connect.c31
-rw-r--r--lib/libc/sys/w_fcntl.c59
-rw-r--r--lib/libc/sys/w_fork.c26
-rw-r--r--lib/libc/sys/w_fsync.c31
-rw-r--r--lib/libc/sys/w_msgrcv.c31
-rw-r--r--lib/libc/sys/w_msgsnd.c31
-rw-r--r--lib/libc/sys/w_msync.c31
-rw-r--r--lib/libc/sys/w_nanosleep.c31
-rw-r--r--lib/libc/sys/w_open.c41
-rw-r--r--lib/libc/sys/w_openat.c41
-rw-r--r--lib/libc/sys/w_poll.c31
-rw-r--r--lib/libc/sys/w_ppoll.c41
-rw-r--r--lib/libc/sys/w_pread.c31
-rw-r--r--lib/libc/sys/w_preadv.c32
-rw-r--r--lib/libc/sys/w_pselect.c42
-rw-r--r--lib/libc/sys/w_pwrite.c31
-rw-r--r--lib/libc/sys/w_pwritev.c32
-rw-r--r--lib/libc/sys/w_read.c31
-rw-r--r--lib/libc/sys/w_readv.c31
-rw-r--r--lib/libc/sys/w_recvfrom.c32
-rw-r--r--lib/libc/sys/w_recvmsg.c31
-rw-r--r--lib/libc/sys/w_select.c32
-rw-r--r--lib/libc/sys/w_sendmsg.c31
-rw-r--r--lib/libc/sys/w_sendto.c32
-rw-r--r--lib/libc/sys/w_sigsuspend.c40
-rw-r--r--lib/libc/sys/w_vfork.c (renamed from lib/libc/thread/unithread_mutex.c)43
-rw-r--r--lib/libc/sys/w_wait4.c31
-rw-r--r--lib/libc/sys/w_write.c31
-rw-r--r--lib/libc/sys/w_writev.c31
-rw-r--r--lib/libc/termios/tcdrain.c11
-rw-r--r--lib/libc/thread/Makefile.inc4
-rw-r--r--lib/libc/thread/callbacks.c42
-rw-r--r--lib/libc/thread/unithread_malloc_lock.c76
-rw-r--r--lib/libc/thread/unithread_tag.c32
149 files changed, 2279 insertions, 1658 deletions
diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc
index 614afd4c0c5..539936a0476 100644
--- a/lib/libc/Makefile.inc
+++ b/lib/libc/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.28 2016/03/09 16:28:46 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.29 2016/05/07 19:05:21 guenther Exp $
#
# This file contains make rules used to build libc
#
@@ -8,7 +8,7 @@ all:
@echo "need to define LIBCSRCDIR" >&2; exit 1
.endif
-CFLAGS+=-I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/hidden \
+CFLAGS+=-I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/hidden -D__LIBC__ \
-Werror-implicit-function-declaration -include namespace.h
.if ${COMPILER_VERSION:L} != "gcc3"
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list
index 76c43e586be..58e05df793b 100644
--- a/lib/libc/Symbols.list
+++ b/lib/libc/Symbols.list
@@ -22,8 +22,6 @@ __plt_start
__plt_end
/* sys */
-___cerror
-__cerror
__get_tcb
__semctl
__set_tcb
@@ -35,7 +33,6 @@ __thrsigdivert
__thrsleep
__thrwakeup
_exit
-_thread_fork
_thread_sys___get_tcb
_thread_sys___getcwd
_thread_sys___semctl
@@ -469,6 +466,8 @@ store
/* dlfcn */
__progname
_csu_finish
+_dl_allocate_tib
+_dl_free_tib
dl_iterate_phdr
dladdr
dlclose
@@ -492,7 +491,6 @@ sigsetmask
sigvec
/* gen */
-___errno
__assert
__assert2
__errno
@@ -592,7 +590,6 @@ endpwent
endttyent
endusershell
err
-errno
errx
execl
execle
@@ -1622,21 +1619,8 @@ tcsetattr
tcsetpgrp
/* thread */
-_thread_arc4_lock
-_thread_arc4_unlock
-_thread_atexit_lock
-_thread_atexit_unlock
_thread_atfork
-_thread_atfork_lock
-_thread_atfork_unlock
-_thread_malloc_lock
-_thread_malloc_unlock
-_thread_mutex_destroy
-_thread_mutex_lock
-_thread_mutex_unlock
-_thread_tag_lock
-_thread_tag_storage
-_thread_tag_unlock
+_thread_set_callbacks
pthread_atfork
/* time */
diff --git a/lib/libc/arch/alpha/Makefile.inc b/lib/libc/arch/alpha/Makefile.inc
index 5bfc478e8ef..050910e7bcd 100644
--- a/lib/libc/arch/alpha/Makefile.inc
+++ b/lib/libc/arch/alpha/Makefile.inc
@@ -1,6 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.6 2014/06/09 20:47:10 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.7 2016/05/07 19:05:21 guenther Exp $
# $NetBSD: Makefile.inc,v 1.4 1996/10/17 02:58:18 cgd Exp $
+CERROR= cerror.S
+
# `source' files built from m4 source
SRCS+= __divqu.S __divq.S __divlu.S __divl.S
SRCS+= __remqu.S __remq.S __remlu.S __reml.S
diff --git a/lib/libc/arch/alpha/sys/Ovfork.S b/lib/libc/arch/alpha/sys/Ovfork.S
index 5da581bcc6f..d5df4e99f08 100644
--- a/lib/libc/arch/alpha/sys/Ovfork.S
+++ b/lib/libc/arch/alpha/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.6 2015/03/31 04:32:01 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.7 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: Ovfork.S,v 1.1 1995/02/10 17:50:29 cgd Exp $ */
/*
@@ -30,4 +30,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/alpha/sys/cerror.S b/lib/libc/arch/alpha/sys/cerror.S
index c85de3282e9..6bee6c9e106 100644
--- a/lib/libc/arch/alpha/sys/cerror.S
+++ b/lib/libc/arch/alpha/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.6 2011/04/04 12:42:39 guenther Exp $ */
+/* $OpenBSD: cerror.S,v 1.7 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: cerror.S,v 1.3 1996/10/17 03:08:17 cgd Exp $ */
/*
@@ -30,14 +30,25 @@
#include "SYS.h"
-IMPORT(errno, 4)
+#define FRAME_SIZE 16
+#define FRAME_RA_OFFSET 0
+#define FRAME_V0_OFFSET 8
-WEAK_ALIAS(__cerror, ___cerror)
-
-LEAF(___cerror, 0)
+NESTED(__cerror, 0, FRAME_SIZE, ra, IM_RA|IM_V0, 0)
+LEAF_NOPROFILE(__cerror, 0)
br t0, L1
L1: LDGP(t0)
- stl v0, errno
+
+ lda sp, -FRAME_SIZE(sp)
+ stq ra, FRAME_RA_OFFSET(sp)
+ stq v0, FRAME_V0_OFFSET(sp)
+
+ CALL(__errno)
+
+ ldq t0, FRAME_V0_OFFSET(sp)
+ stl t0, 0(v0)
ldiq v0, -1
+ ldq ra, FRAME_RA_OFFSET(sp)
+ lda sp, FRAME_SIZE(sp)
RET
-END(___cerror)
+END(__cerror)
diff --git a/lib/libc/arch/alpha/sys/fork.S b/lib/libc/arch/alpha/sys/fork.S
deleted file mode 100644
index 59b96139585..00000000000
--- a/lib/libc/arch/alpha/sys/fork.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $OpenBSD: fork.S,v 1.7 2015/04/07 01:27:06 guenther Exp $ */
-/* $NetBSD: fork.S,v 1.1 1995/02/10 17:50:34 cgd Exp $ */
-
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/alpha/sys/sigsuspend.S b/lib/libc/arch/alpha/sys/sigsuspend.S
index f5201db29f6..f5f05ec3098 100644
--- a/lib/libc/arch/alpha/sys/sigsuspend.S
+++ b/lib/libc/arch/alpha/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.7 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: sigsuspend.S,v 1.2 1996/10/17 03:08:22 cgd Exp $ */
/*
@@ -30,9 +30,9 @@
#include "SYS.h"
-SYSLEAF(sigsuspend, 1)
+SYSLEAF_HIDDEN(sigsuspend, 1)
ldl a0, 0(a0) /* pass *mask instead of mask */
CALLSYS_ERROR(sigsuspend)
mov zero, v0 /* shouldn't need; just in case... */
RET
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/amd64/SYS.h b/lib/libc/arch/amd64/SYS.h
index 3168fa60ab2..3479377f801 100644
--- a/lib/libc/arch/amd64/SYS.h
+++ b/lib/libc/arch/amd64/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.18 2015/11/14 21:53:03 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.19 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,6 +38,8 @@
#include "DEFS.h"
#include <sys/syscall.h>
+/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
+#define TCB_OFFSET_ERRNO 32
#define SYSTRAP(x) movl $(SYS_ ## x),%eax; movq %rcx, %r10; syscall
@@ -53,8 +55,14 @@
END(_HIDDEN(x))
#define SYSCALL_END(x) SYSCALL_END_HIDDEN(x); END(x)
-#define CERROR _C_LABEL(__cerror)
-#define _CERROR _C_LABEL(___cerror)
+
+#define SET_ERRNO \
+ movl %eax,%fs:(TCB_OFFSET_ERRNO); \
+ movq $-1, %rax
+#define HANDLE_ERRNO \
+ jnc,pt 99f; \
+ SET_ERRNO; \
+ 99:
#define _SYSCALL_NOERROR(x,y) \
SYSENTRY(x); \
@@ -63,39 +71,23 @@
SYSENTRY_HIDDEN(x); \
SYSTRAP(y)
-#ifdef __PIC__
-#define _SYSCALL(x,y) \
- .text; _ALIGN_TEXT; \
- 2: mov PIC_GOT(CERROR), %rcx; \
- jmp *%rcx; \
- _SYSCALL_NOERROR(x,y); \
- jc 2b
-#define _SYSCALL_HIDDEN(x,y) \
- .text; _ALIGN_TEXT; \
- 2: mov PIC_GOT(CERROR), %rcx; \
- jmp *%rcx; \
- _SYSCALL_HIDDEN_NOERROR(x,y); \
- jc 2b
-#else
-#define _SYSCALL(x,y) \
- .text; _ALIGN_TEXT; \
- 2: jmp CERROR; \
- _SYSCALL_NOERROR(x,y); \
- jc 2b
-#define _SYSCALL_HIDDEN(x,y) \
- .text; _ALIGN_TEXT; \
- 2: jmp CERROR; \
- _SYSCALL_HIDDEN_NOERROR(x,y); \
- jc 2b
-#endif
-
#define SYSCALL_NOERROR(x) \
_SYSCALL_NOERROR(x,x)
#define SYSCALL_HIDDEN(x) \
- _SYSCALL_HIDDEN(x,x)
+ _SYSCALL_HIDDEN_NOERROR(x,x); \
+ HANDLE_ERRNO
#define SYSCALL(x) \
- _SYSCALL(x,x)
+ _SYSCALL_NOERROR(x,x); \
+ HANDLE_ERRNO
+
+
+/* return, handling errno for failed calls */
+#define _RSYSCALL_RET \
+ jc,pn 99f; \
+ ret; \
+ 99: SET_ERRNO; \
+ ret
#define PSEUDO_NOERROR(x,y) \
_SYSCALL_NOERROR(x,y); \
@@ -103,12 +95,12 @@
SYSCALL_END(x)
#define PSEUDO(x,y) \
- _SYSCALL(x,y); \
- ret; \
+ _SYSCALL_NOERROR(x,y); \
+ _RSYSCALL_RET; \
SYSCALL_END(x)
#define PSEUDO_HIDDEN(x,y) \
- _SYSCALL_HIDDEN(x,y); \
- ret; \
+ _SYSCALL_HIDDEN_NOERROR(x,y); \
+ _RSYSCALL_RET; \
SYSCALL_END_HIDDEN(x)
#define RSYSCALL_NOERROR(x) \
@@ -118,5 +110,3 @@
PSEUDO(x,x)
#define RSYSCALL_HIDDEN(x) \
PSEUDO_HIDDEN(x,x)
-
- .globl CERROR
diff --git a/lib/libc/arch/amd64/sys/Ovfork.S b/lib/libc/arch/amd64/sys/Ovfork.S
index 6e70f7231a8..e42649e28ce 100644
--- a/lib/libc/arch/amd64/sys/Ovfork.S
+++ b/lib/libc/arch/amd64/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.7 2015/10/17 22:40:54 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: Ovfork.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */
/*-
@@ -39,17 +39,13 @@
#include "SYS.h"
-SYSENTRY(vfork)
+SYSENTRY_HIDDEN(vfork)
popq %r9 /* my rta into r9 */
SYSTRAP(vfork)
jc 1f
jmp *%r9
1:
pushq %r9
-#ifdef __PIC__
- movq PIC_GOT(CERROR), %rcx
- jmp *%rcx
-#else
- jmp CERROR
-#endif
-SYSCALL_END(vfork)
+ SET_ERRNO
+ ret
+SYSCALL_END_HIDDEN(vfork)
diff --git a/lib/libc/arch/amd64/sys/brk.S b/lib/libc/arch/amd64/sys/brk.S
index c59f0036eb0..26fb2893b58 100644
--- a/lib/libc/arch/amd64/sys/brk.S
+++ b/lib/libc/arch/amd64/sys/brk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: brk.S,v 1.7 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: brk.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: brk.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */
/*-
@@ -51,22 +51,6 @@ __minbrk:
.weak brk
ENTRY(brk)
-#ifdef __PIC__
- movq PIC_GOT(__minbrk),%rdx
- cmpq %rdi,(%rdx)
- jb 1f
- movq (%rdx),%rdi
-1:
- SYSTRAP(break)
- jc 1f
- movq PIC_GOT(__curbrk),%rdx # set up GOT addressing
- movq %rdi,(%rdx)
- xorl %eax,%eax
- ret
-1:
- movq PIC_GOT(CERROR),%rdx
- jmp *%rdx
-#else
cmpq %rdi,__minbrk(%rip)
jb 1f
movq __minbrk(%rip),%rdi
@@ -77,6 +61,6 @@ ENTRY(brk)
xorl %eax,%eax
ret
1:
- jmp CERROR
-#endif
+ SET_ERRNO
+ ret
END(brk)
diff --git a/lib/libc/arch/amd64/sys/cerror.S b/lib/libc/arch/amd64/sys/cerror.S
deleted file mode 100644
index 89bf7f69aa4..00000000000
--- a/lib/libc/arch/amd64/sys/cerror.S
+++ /dev/null
@@ -1,55 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.7 2015/06/01 09:31:40 uebayasi Exp $ */
-/* $NetBSD: cerror.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)cerror.s 5.1 (Berkeley) 4/23/90
- */
-
-#include <machine/asm.h>
-
-#include "SYS.h"
-
- .globl _C_LABEL(errno)
-
-WEAK_ALIAS(CERROR, _CERROR)
-
-_ENTRY(_CERROR)
-#ifdef __PIC__
- movq PIC_GOT(_C_LABEL(errno)), %rcx
- movl %eax, (%rcx)
-#else
- movl %eax, _C_LABEL(errno)(%rip)
-#endif /* PIC */
- movq $-1,%rax
- ret
-END(_CERROR)
diff --git a/lib/libc/arch/amd64/sys/fork.S b/lib/libc/arch/amd64/sys/fork.S
deleted file mode 100644
index 6582d8a9a32..00000000000
--- a/lib/libc/arch/amd64/sys/fork.S
+++ /dev/null
@@ -1,43 +0,0 @@
-/* $OpenBSD: fork.S,v 1.4 2015/04/07 01:27:06 guenther Exp $ */
-/* $NetBSD: fork.S,v 1.2 2003/02/13 02:50:51 nathanw Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fork.s 5.1 (Berkeley) 4/23/90
- */
-
-#include <machine/asm.h>
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/amd64/sys/sbrk.S b/lib/libc/arch/amd64/sys/sbrk.S
index 06ed6ba7cca..05d289b03b9 100644
--- a/lib/libc/arch/amd64/sys/sbrk.S
+++ b/lib/libc/arch/amd64/sys/sbrk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sbrk.S,v 1.7 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: sbrk.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: sbrk.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */
/*-
@@ -55,21 +55,6 @@ __curbrk: .quad _end
.weak sbrk
ENTRY(sbrk)
-#ifdef __PIC__
- movq PIC_GOT(__curbrk),%rdx
- movslq %edi, %rax
- movq (%rdx),%rdi
- addq %rax,%rdi
- SYSTRAP(break)
- jc 1f
- movq PIC_GOT(__curbrk),%rdx
- movq (%rdx),%rax
- movq %rdi,(%rdx)
- ret
-1:
- mov PIC_GOT(CERROR),%rdx
- jmp *%rdx
-#else
movq __curbrk(%rip),%rax
movslq %edi,%rsi
movq %rsi,%rdi
@@ -80,6 +65,6 @@ ENTRY(sbrk)
addq %rsi,__curbrk(%rip)
ret
1:
- jmp CERROR
-#endif
+ SET_ERRNO
+ ret
END(sbrk)
diff --git a/lib/libc/arch/amd64/sys/sigprocmask.S b/lib/libc/arch/amd64/sys/sigprocmask.S
index 065088d6548..308c5800b50 100644
--- a/lib/libc/arch/amd64/sys/sigprocmask.S
+++ b/lib/libc/arch/amd64/sys/sigprocmask.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigprocmask.S,v 1.8 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: sigprocmask.S,v 1.9 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: sigprocmask.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */
/*-
@@ -48,16 +48,12 @@ SYSENTRY_HIDDEN(sigprocmask)
2: SYSTRAP(sigprocmask)
jc 1f
testq %rdx,%rdx # test if old mask requested
- jz out
+ jz 3f
movl %eax,(%rdx) # store old mask
-out:
+3:
xorl %eax,%eax
ret
1:
-#ifdef __PIC__
- movq PIC_GOT(CERROR), %rcx
- jmp *%rcx
-#else
- jmp CERROR
-#endif
+ SET_ERRNO
+ ret
SYSCALL_END_HIDDEN(sigprocmask)
diff --git a/lib/libc/arch/amd64/sys/sigsuspend.S b/lib/libc/arch/amd64/sys/sigsuspend.S
index 43e6ac3be3c..9abb04e1079 100644
--- a/lib/libc/arch/amd64/sys/sigsuspend.S
+++ b/lib/libc/arch/amd64/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.6 2015/10/17 22:40:54 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.7 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: sigsuspend.S,v 1.1 2001/06/19 00:25:07 fvdl Exp $ */
/*-
@@ -39,17 +39,9 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
movl (%rdi),%edi # indirect to mask arg
SYSTRAP(sigsuspend)
- jc 1f
- xorl %eax,%eax # shouldn t happen
+ SET_ERRNO
ret
-1:
-#ifdef __PIC__
- movq PIC_GOT(CERROR), %rcx
- jmp *%rcx
-#else
- jmp CERROR
-#endif
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/amd64/sys/syscall.S b/lib/libc/arch/amd64/sys/syscall.S
index 0bf3ccfec47..6568ecc55af 100644
--- a/lib/libc/arch/amd64/sys/syscall.S
+++ b/lib/libc/arch/amd64/sys/syscall.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.S,v 1.7 2015/10/17 22:40:54 guenther Exp $ */
+/* $OpenBSD: syscall.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: syscall.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */
/*-
@@ -39,17 +39,4 @@
#include "SYS.h"
-SYSENTRY(syscall)
- movq $0,%rax
- movq %rcx,%r10
- syscall
- jc 1f
- ret
-1:
-#ifdef __PIC__
- movq PIC_GOT(CERROR), %rcx
- jmp *%rcx
-#else
- jmp CERROR
-#endif
-SYSCALL_END(syscall)
+RSYSCALL(syscall)
diff --git a/lib/libc/arch/amd64/sys/tfork_thread.S b/lib/libc/arch/amd64/sys/tfork_thread.S
index 0f67225830e..3477228a40b 100644
--- a/lib/libc/arch/amd64/sys/tfork_thread.S
+++ b/lib/libc/arch/amd64/sys/tfork_thread.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: tfork_thread.S,v 1.5 2015/06/01 09:27:53 uebayasi Exp $ */
+/* $OpenBSD: tfork_thread.S,v 1.6 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
* Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>
@@ -85,10 +85,6 @@ ENTRY(__tfork_thread)
* Branch here if the thread creation fails:
*/
2:
-#ifdef __PIC__
- movq PIC_GOT(CERROR), %rcx
- jmp *%rcx
-#else
- jmp CERROR
-#endif
+ SET_ERRNO
+ ret
END(__tfork_thread)
diff --git a/lib/libc/arch/arm/Makefile.inc b/lib/libc/arch/arm/Makefile.inc
index 429d29db9ee..3347bcd9a54 100644
--- a/lib/libc/arch/arm/Makefile.inc
+++ b/lib/libc/arch/arm/Makefile.inc
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.5 2014/06/09 20:47:10 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2016/05/07 19:05:21 guenther Exp $
# $NetBSD: Makefile.inc,v 1.5 2002/07/10 04:29:06 thorpej Exp $
.include <bsd.own.mk>
-#SRCS+= __sigaction14_sigtramp.c __sigtramp1.S
+CERROR= cerror.S
CPPFLAGS += -DSOFTFLOAT
diff --git a/lib/libc/arch/arm/SYS.h b/lib/libc/arch/arm/SYS.h
index 9812bb3ebc6..baa5f1aefbc 100644
--- a/lib/libc/arch/arm/SYS.h
+++ b/lib/libc/arch/arm/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.14 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.15 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: SYS.h,v 1.8 2003/08/07 16:42:02 agc Exp $ */
/*-
@@ -80,7 +80,6 @@
swi 0
#define CERROR _C_LABEL(__cerror)
-#define _CERROR _C_LABEL(___cerror)
#define _SYSCALL_NOERROR(x,y) \
SYSENTRY(x); \
diff --git a/lib/libc/arch/arm/sys/Ovfork.S b/lib/libc/arch/arm/sys/Ovfork.S
index 10d3ef3ec51..560949a3237 100644
--- a/lib/libc/arch/arm/sys/Ovfork.S
+++ b/lib/libc/arch/arm/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.5 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.6 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: Ovfork.S,v 1.6 2003/08/07 16:42:03 agc Exp $ */
/*-
@@ -37,9 +37,9 @@
.text
.align 0
-SYSENTRY(vfork)
+SYSENTRY_HIDDEN(vfork)
mov r2, r14
SYSTRAP(vfork)
bcs PIC_SYM(CERROR, PLT)
mov r15, r2
-SYSCALL_END(vfork)
+SYSCALL_END_HIDDEN(vfork)
diff --git a/lib/libc/arch/arm/sys/cerror.S b/lib/libc/arch/arm/sys/cerror.S
index d595caa8f36..05ac31af3c0 100644
--- a/lib/libc/arch/arm/sys/cerror.S
+++ b/lib/libc/arch/arm/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.7 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: cerror.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: cerror.S,v 1.5 2003/08/07 16:42:04 agc Exp $ */
/*-
@@ -34,32 +34,11 @@
#include "SYS.h"
-WEAK_ALIAS(CERROR, _CERROR)
-
-ASENTRY(_CERROR)
-#ifdef __PIC__
- /* Setup the GOT */
- ldr r3, .Lgot
- ldr r1, .Lerrno
-.L1:
- add r3, pc, r3
- ldr r1, [r3, r1]
-#else
- ldr r1, .Lerrno
-#endif /* PIC */
- str r0, [r1]
+_ENTRY(CERROR)
+ stmfd sp!, {r4, lr}
+ mov r4, r0
+ bl PIC_SYM(_C_LABEL(__errno), PLT)
+ str r4, [r0]
mvn r0, #0x00000000
mvn r1, #0x00000000
- mov pc, lr
-
-#ifdef __PIC__
- .align 0
-.Lgot:
- .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (.L1+8)
-#endif /* PIC */
-
- .globl _C_LABEL(errno)
-
-.Lerrno:
- .word PIC_SYM(_C_LABEL(errno), GOT)
-END(_CERROR)
+ ldmfd sp!, {r4, pc}
diff --git a/lib/libc/arch/arm/sys/fork.S b/lib/libc/arch/arm/sys/fork.S
deleted file mode 100644
index 8d92b286369..00000000000
--- a/lib/libc/arch/arm/sys/fork.S
+++ /dev/null
@@ -1,38 +0,0 @@
-/* $OpenBSD: fork.S,v 1.4 2015/04/07 01:27:06 guenther Exp $ */
-/* $NetBSD: fork.S,v 1.5 2003/08/07 16:42:04 agc Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fork.s 5.1 (Berkeley) 4/23/90
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/arm/sys/sigsuspend.S b/lib/libc/arch/arm/sys/sigsuspend.S
index b1d695e2f20..3360eab7021 100644
--- a/lib/libc/arch/arm/sys/sigsuspend.S
+++ b/lib/libc/arch/arm/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.4 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.5 2016/05/07 19:05:21 guenther Exp $ */
/* $NetBSD: sigsuspend.S,v 1.6 2003/08/07 16:42:05 agc Exp $ */
/*-
@@ -34,10 +34,10 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ldr r0, [r0]
SYSTRAP(sigsuspend)
bcs PIC_SYM(CERROR, PLT)
mov r0, #0x00000000
mov r15, r14
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/hppa/SYS.h b/lib/libc/arch/hppa/SYS.h
index 7f891b4f899..79cfa517c2c 100644
--- a/lib/libc/arch/hppa/SYS.h
+++ b/lib/libc/arch/hppa/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.21 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.22 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1998-2002 Michael Shalayeff
@@ -33,6 +33,9 @@
#include <machine/vmparam.h>
#undef _LOCORE
+/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
+#define TCB_OFFSET_ERRNO -8
+
/*
* We define a hidden alias with the prefix "_libc_" for each global symbol
* that may be used internally. By referencing _libc_x instead of x, other
@@ -83,9 +86,15 @@ LEAF_ENTRY(__CONCAT(_thread_sys_,x))
ldil L%SYSCALLGATE, r1 !\
ble 4(sr7, r1) !\
ldi __CONCAT(SYS_,x), t1 !\
- .import __cerror, code !\
- comb,<> r0, t1, __cerror !\
- ldw HPPA_FRAME_ERP(sr0,sp), rp
+ comb,= 0, t1, 1f !\
+ ldw HPPA_FRAME_ERP(sr0,sp), rp !\
+ /* set errno */ \
+ mfctl cr27, r1 !\
+ stw t1, TCB_OFFSET_ERRNO(r1) !\
+ ldi -1, ret0 !\
+ bv r0(rp) !\
+ ldi -1, ret1 !\
+1:
#define PSEUDO(x,y) !\
SYSENTRY(x) !\
diff --git a/lib/libc/arch/hppa/sys/Ovfork.S b/lib/libc/arch/hppa/sys/Ovfork.S
index 880c92ad961..8be9141b338 100644
--- a/lib/libc/arch/hppa/sys/Ovfork.S
+++ b/lib/libc/arch/hppa/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.14 2015/03/31 04:32:01 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.15 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1999,2002 Michael Shalayeff
@@ -28,17 +28,20 @@
#include "SYS.h"
-SYSENTRY(vfork)
+SYSENTRY_HIDDEN(vfork)
.import errno, data
copy rp, t4
ldil L%SYSCALLGATE, r1
ble 4(sr7, r1)
ldi __CONCAT(SYS_,vfork), t1
- .import __cerror, code
- comb,<> r0, t1, __cerror
+ comb,= r0, t1, 1f
copy t4, rp
- bv r0(rp)
- nop
-SYSEXIT(vfork)
+ /* set errno */
+ mfctl cr27, r1
+ stw t1, TCB_OFFSET_ERRNO(r1)
+ ldi -1, ret0
+1: bv r0(rp)
+ nop
+SYSEXIT_HIDDEN(vfork)
.end
diff --git a/lib/libc/arch/hppa/sys/cerror.S b/lib/libc/arch/hppa/sys/cerror.S
deleted file mode 100644
index fbec5adfd92..00000000000
--- a/lib/libc/arch/hppa/sys/cerror.S
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.6 2012/08/22 17:19:34 pascal Exp $ */
-
-/*
- * Copyright (c) 2004 Michael Shalayeff
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-WEAK_ALIAS(__cerror, ___cerror)
-
- .import errno, data
-ENTRY(___cerror,0)
-#ifdef __PIC__
- addil LT%errno, r19
- ldw RT%errno(r1), r1
- stw t1, 0(r1)
-#else
- ldil L%errno, r1
- stw t1, R%errno(r1)
-#endif
- ldi -1, ret0
- bv r0(rp)
- ldi -1, ret1
-EXIT(___cerror)
-
- .end
diff --git a/lib/libc/arch/hppa/sys/fork.S b/lib/libc/arch/hppa/sys/fork.S
deleted file mode 100644
index 8bb3bc545b9..00000000000
--- a/lib/libc/arch/hppa/sys/fork.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* $OpenBSD: fork.S,v 1.13 2015/04/07 01:27:06 guenther Exp $ */
-
-/*
- * Copyright (c) 1999 Michael Shalayeff
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/hppa/sys/sigsuspend.S b/lib/libc/arch/hppa/sys/sigsuspend.S
index 4cf34ec6b32..9853ccbb196 100644
--- a/lib/libc/arch/hppa/sys/sigsuspend.S
+++ b/lib/libc/arch/hppa/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.10 2006/01/05 22:13:55 kettenis Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.11 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -28,11 +28,11 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ldw 0(arg0), arg0
stw arg0, HPPA_FRAME_ARG(0)(sp)
SYSCALL(sigsuspend)
-SYSEXIT(sigsuspend)
+SYSEXIT_HIDDEN(sigsuspend)
.end
diff --git a/lib/libc/arch/hppa64/SYS.h b/lib/libc/arch/hppa64/SYS.h
index f8afd9b22b8..fd1a5f1af43 100644
--- a/lib/libc/arch/hppa64/SYS.h
+++ b/lib/libc/arch/hppa64/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.10 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.11 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1998-2002 Michael Shalayeff
@@ -33,6 +33,9 @@
#include <machine/vmparam.h>
#undef _LOCORE
+/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
+#define TCB_OFFSET_ERRNO -12
+
/*
* We define a hidden alias with the prefix "_libc_" for each global symbol
* that may be used internally. By referencing _libc_x instead of x, other
@@ -84,10 +87,15 @@ LEAF_ENTRY(__CONCAT(_thread_sys_,x))
depd %r0, 31, 32, %r1 !\
ble 4(%sr7, %r1) !\
ldi __CONCAT(SYS_,x), %r1 !\
- .import __cerror, code !\
- sub,*= %r0, %r1, %r0 !\
- b,l __cerror, %rp !\
- ldd HPPA_FRAME_RP(%sr0,%sp), %rp
+ comb,==,tr %r0, %ret0, 1f !\
+ ldd HPPA_FRAME_RP(%sr0,%sp), %rp !\
+ /* set errno */ \
+ mfctl %cr27, %r1 !\
+ stw %t1, TCB_OFFSET_ERRNO(%r1) !\
+ bv %r0(%rp) !\
+ ldi -1, %ret0 !\
+1:
+
#define PSEUDO(x,y) !\
SYSENTRY(x) !\
diff --git a/lib/libc/arch/hppa64/sys/Ovfork.S b/lib/libc/arch/hppa64/sys/Ovfork.S
index de7cd713ad1..ca40cfef79b 100644
--- a/lib/libc/arch/hppa64/sys/Ovfork.S
+++ b/lib/libc/arch/hppa64/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.5 2015/03/31 04:32:01 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.6 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1999,2002 Michael Shalayeff
@@ -28,17 +28,20 @@
#include "SYS.h"
-SYSENTRY(vfork)
+SYSENTRY_HIDDEN(vfork)
.import errno, data
copy %rp, arg7
ldil L%SYSCALLGATE, %r1
ble 4(%sr7, %r1)
ldi __CONCAT(SYS_,vfork), arg4
- .import __cerror, code
- comb,<> %r0, arg4, __cerror
+ comb,==,tr %r0, arg4, 1f
copy arg7, %rp
- bv %r0(%rp)
+ /* set errno */
+ mfctl %cr27, %r1
+ stw %t1, TCB_OFFSET_ERRNO(%r1)
+ ldi -1, %ret0
+1: bv %r0(%rp)
nop
-SYSEXIT(vfork)
+SYSEXIT_HIDDEN(vfork)
.end
diff --git a/lib/libc/arch/hppa64/sys/cerror.S b/lib/libc/arch/hppa64/sys/cerror.S
deleted file mode 100644
index ab81d5ecffa..00000000000
--- a/lib/libc/arch/hppa64/sys/cerror.S
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.5 2012/08/22 17:19:34 pascal Exp $ */
-
-/*
- * Copyright (c) 2004 Michael Shalayeff
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-WEAK_ALIAS(__cerror, ___cerror)
-
- .import errno, data
-ENTRY(___cerror,0)
-#ifdef __PIC__
- addil LT%errno, %dp
- ldd RT%errno(%r1), %r1
- stw %ret0, 0(%r1)
-#else
- ldil L%errno, %r1
- stw %ret0, R%errno(%r1)
-#endif
- ldi -1, %ret0
- bv %r0(%rp)
- ldi -1, %ret1
-EXIT(___cerror)
-
- .end
diff --git a/lib/libc/arch/hppa64/sys/fork.S b/lib/libc/arch/hppa64/sys/fork.S
deleted file mode 100644
index 7602c801601..00000000000
--- a/lib/libc/arch/hppa64/sys/fork.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* $OpenBSD: fork.S,v 1.6 2015/04/07 01:27:06 guenther Exp $ */
-
-/*
- * Copyright (c) 1999 Michael Shalayeff
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/hppa64/sys/sigsuspend.S b/lib/libc/arch/hppa64/sys/sigsuspend.S
index a9c2aa19b50..468f49b6e58 100644
--- a/lib/libc/arch/hppa64/sys/sigsuspend.S
+++ b/lib/libc/arch/hppa64/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.5 2011/08/16 18:58:45 kettenis Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.6 2016/05/07 19:05:21 guenther Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -28,10 +28,10 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ldw 0(%arg0), %arg0
SYSCALL(sigsuspend)
-SYSEXIT(sigsuspend)
+SYSEXIT_HIDDEN(sigsuspend)
.end
diff --git a/lib/libc/arch/i386/SYS.h b/lib/libc/arch/i386/SYS.h
index 7373a9796a9..59852a449a7 100644
--- a/lib/libc/arch/i386/SYS.h
+++ b/lib/libc/arch/i386/SYS.h
@@ -29,12 +29,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: SYS.h,v 1.24 2015/10/23 04:39:24 guenther Exp $
+ * $OpenBSD: SYS.h,v 1.25 2016/05/07 19:05:21 guenther Exp $
*/
#include <machine/asm.h>
#include <sys/syscall.h>
+#define TCB_OFFSET_ERRNO 16
/*
* We define a hidden alias with the prefix "_libc_" for each global symbol
@@ -70,9 +71,8 @@
/* Use both _thread_sys_{syscall} and [weak] {syscall}. */
#define SYSENTRY(x) \
- ENTRY(_thread_sys_ ## x); \
- .weak _C_LABEL(x); \
- _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x)
+ ENTRY(_thread_sys_##x); \
+ WEAK_ALIAS(x, _thread_sys_##x)
#define SYSENTRY_HIDDEN(x) \
ENTRY(_thread_sys_ ## x)
#define __END_HIDDEN(x) END(_thread_sys_ ## x); \
@@ -84,8 +84,14 @@
movl $(SYS_ ## x),%eax; \
int $0x80
-#define CERROR _C_LABEL(__cerror)
-#define _CERROR _C_LABEL(___cerror)
+#define SET_ERRNO() \
+ movl %eax,%gs:(TCB_OFFSET_ERRNO); \
+ movl $-1, %eax; \
+ movl $-1, %edx /* for lseek */
+#define HANDLE_ERRNO() \
+ jnc,pt 99f; \
+ SET_ERRNO(); \
+ 99:
/* perform a syscall */
#define _SYSCALL_NOERROR(x,y) \
@@ -99,44 +105,21 @@
_SYSCALL_NOERROR(x,x)
/* perform a syscall, set errno */
-#ifdef __PIC__
#define _SYSCALL(x,y) \
.text; \
.align 2; \
- 2: PIC_PROLOGUE; \
- movl PIC_GOT(CERROR), %ecx; \
- PIC_EPILOGUE; \
- jmp *%ecx; \
_SYSCALL_NOERROR(x,y) \
- jc 2b
+ HANDLE_ERRNO()
#define _SYSCALL_HIDDEN(x,y) \
.text; \
.align 2; \
- 2: PIC_PROLOGUE; \
- movl PIC_GOT(CERROR), %ecx; \
- PIC_EPILOGUE; \
- jmp *%ecx; \
_SYSCALL_HIDDEN_NOERROR(x,y) \
- jc 2b
-#else
-#define _SYSCALL(x,y) \
- .text; \
- .align 2; \
- 2: \
- jmp PIC_PLT(CERROR); \
- _SYSCALL_NOERROR(x,y) \
- jc 2b
-#define _SYSCALL_HIDDEN(x,y) \
- .text; \
- .align 2; \
- 2: \
- jmp PIC_PLT(CERROR); \
- _SYSCALL_HIDDEN_NOERROR(x,y) \
- jc 2b
-#endif
+ HANDLE_ERRNO()
#define SYSCALL(x) \
_SYSCALL(x,x)
+#define SYSCALL_HIDDEN(x) \
+ _SYSCALL_HIDDEN(x,y)
/* perform a syscall, return */
#define PSEUDO_NOERROR(x,y) \
@@ -162,5 +145,3 @@
#define SYSCALL_END(x) __END(x)
#define SYSCALL_END_HIDDEN(x) \
__END_HIDDEN(x)
-
- .globl CERROR
diff --git a/lib/libc/arch/i386/sys/Ovfork.S b/lib/libc/arch/i386/sys/Ovfork.S
index 7068e0bd144..2c276186606 100644
--- a/lib/libc/arch/i386/sys/Ovfork.S
+++ b/lib/libc/arch/i386/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.9 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.10 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -33,21 +33,10 @@
#include "SYS.h"
-SYSENTRY(vfork)
+SYSENTRY_HIDDEN(vfork)
popl %ecx /* my rta into ecx */
movl $(SYS_vfork),%eax
int $0x80
- jc 1f
+ HANDLE_ERRNO()
jmp *%ecx
-1:
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(_C_LABEL(errno)),%edx
- PIC_EPILOGUE
- movl %eax,(%edx)
-#else
- movl %eax,_C_LABEL(errno)
-#endif
- movl $-1,%eax
- jmp *%ecx
-SYSCALL_END(vfork)
+SYSCALL_END_HIDDEN(vfork)
diff --git a/lib/libc/arch/i386/sys/brk.S b/lib/libc/arch/i386/sys/brk.S
index f918b4379e7..05afec06b11 100644
--- a/lib/libc/arch/i386/sys/brk.S
+++ b/lib/libc/arch/i386/sys/brk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: brk.S,v 1.11 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: brk.S,v 1.12 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -64,12 +64,6 @@ ENTRY(brk)
PIC_EPILOGUE
xorl %eax,%eax
movl %ecx,(%edx)
- ret
-2:
- PIC_PROLOGUE
- movl PIC_GOT(CERROR),%ecx # set up GOT addressing
- PIC_EPILOGUE
- jmp *%ecx
#else
@@ -84,8 +78,9 @@ ENTRY(brk)
jc 2f
xorl %eax,%eax
movl %ecx,__curbrk
+#endif
ret
2:
- jmp CERROR
-#endif
+ SET_ERRNO()
+ ret
END(brk)
diff --git a/lib/libc/arch/i386/sys/cerror.S b/lib/libc/arch/i386/sys/cerror.S
deleted file mode 100644
index e30a46e1aa6..00000000000
--- a/lib/libc/arch/i386/sys/cerror.S
+++ /dev/null
@@ -1,52 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.10 2015/09/05 06:22:47 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
- .globl _C_LABEL(errno)
-
-WEAK_ALIAS(CERROR, _CERROR)
-
-_ENTRY(_CERROR)
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(_C_LABEL(errno)),%ecx
- PIC_EPILOGUE
- movl %eax,(%ecx)
-#else
- movl %eax,_C_LABEL(errno)
-#endif
- movl $-1,%eax
- movl $-1,%edx
- ret
-END(_CERROR)
diff --git a/lib/libc/arch/i386/sys/fork.S b/lib/libc/arch/i386/sys/fork.S
deleted file mode 100644
index 1e750d3f0d6..00000000000
--- a/lib/libc/arch/i386/sys/fork.S
+++ /dev/null
@@ -1,37 +0,0 @@
-/* $OpenBSD: fork.S,v 1.6 2015/04/07 01:27:06 guenther Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/i386/sys/sbrk.S b/lib/libc/arch/i386/sys/sbrk.S
index 6c0da58b8a2..a22cb1f895d 100644
--- a/lib/libc/arch/i386/sys/sbrk.S
+++ b/lib/libc/arch/i386/sys/sbrk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sbrk.S,v 1.11 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: sbrk.S,v 1.12 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -61,12 +61,6 @@ ENTRY(sbrk)
PIC_EPILOGUE
movl (%edx),%eax
addl %ecx,(%edx)
- ret
-2:
- PIC_PROLOGUE
- movl PIC_GOT(CERROR), %ecx
- PIC_EPILOGUE
- jmp *%ecx
#else
@@ -78,8 +72,9 @@ ENTRY(sbrk)
jc 2f
movl __curbrk,%eax
addl %ecx,__curbrk
+#endif
ret
2:
- jmp CERROR
-#endif
+ SET_ERRNO()
+ ret
END(sbrk)
diff --git a/lib/libc/arch/i386/sys/sigprocmask.S b/lib/libc/arch/i386/sys/sigprocmask.S
index 2f7b31e2de9..489eabcbf11 100644
--- a/lib/libc/arch/i386/sys/sigprocmask.S
+++ b/lib/libc/arch/i386/sys/sigprocmask.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigprocmask.S,v 1.11 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: sigprocmask.S,v 1.12 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -53,13 +53,6 @@ out:
xorl %eax,%eax
ret
1:
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(CERROR), %ecx
- PIC_EPILOGUE
- jmp *%ecx
-
-#else
- jmp CERROR
-#endif
+ SET_ERRNO()
+ ret
SYSCALL_END_HIDDEN(sigprocmask)
diff --git a/lib/libc/arch/i386/sys/sigsuspend.S b/lib/libc/arch/i386/sys/sigsuspend.S
index cc9b1dda885..88a08c7a1c4 100644
--- a/lib/libc/arch/i386/sys/sigsuspend.S
+++ b/lib/libc/arch/i386/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.9 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.10 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -33,22 +33,12 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
movl 4(%esp),%eax # fetch mask arg
movl (%eax),%eax # indirect to mask arg
movl %eax,4(%esp)
movl $(SYS_sigsuspend),%eax
int $0x80
- jc 1f
- xorl %eax,%eax # shouldn t happen
+ SET_ERRNO()
ret
-1:
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(CERROR), %ecx
- PIC_EPILOGUE
- jmp *%ecx
-#else
- jmp CERROR
-#endif
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/i386/sys/syscall.S b/lib/libc/arch/i386/sys/syscall.S
index 315c1624536..fa2dd652c52 100644
--- a/lib/libc/arch/i386/sys/syscall.S
+++ b/lib/libc/arch/i386/sys/syscall.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.S,v 1.10 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: syscall.S,v 1.11 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -39,15 +39,6 @@ SYSENTRY(syscall)
push %ecx
int $0x80
push %ecx /* Keep stack frame consistent */
- jc 1f
+ HANDLE_ERRNO()
ret
-1:
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(CERROR), %ecx
- PIC_EPILOGUE
- jmp *%ecx
-#else
- jmp CERROR
-#endif
SYSCALL_END(syscall)
diff --git a/lib/libc/arch/i386/sys/tfork_thread.S b/lib/libc/arch/i386/sys/tfork_thread.S
index 2f07845ea68..97a515f0ae8 100644
--- a/lib/libc/arch/i386/sys/tfork_thread.S
+++ b/lib/libc/arch/i386/sys/tfork_thread.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: tfork_thread.S,v 1.7 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: tfork_thread.S,v 1.8 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
* All rights reserved.
@@ -112,12 +112,6 @@ ENTRY(__tfork_thread)
popl %esi
movl %ebp, %esp
popl %ebp
-#ifdef __PIC__
- PIC_PROLOGUE
- movl PIC_GOT(CERROR), %ecx
- PIC_EPILOGUE
- jmp *%ecx
-#else
- jmp CERROR
-#endif
+ HANDLE_ERRNO()
+ ret
END(__tfork_thread)
diff --git a/lib/libc/arch/m88k/Makefile.inc b/lib/libc/arch/m88k/Makefile.inc
index 60b23aad174..ed176e74648 100644
--- a/lib/libc/arch/m88k/Makefile.inc
+++ b/lib/libc/arch/m88k/Makefile.inc
@@ -1 +1,2 @@
-# $OpenBSD: Makefile.inc,v 1.3 2014/06/09 20:47:11 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.4 2016/05/07 19:05:21 guenther Exp $
+CERROR= cerror.S
diff --git a/lib/libc/arch/m88k/sys/Ovfork.S b/lib/libc/arch/m88k/sys/Ovfork.S
index 916f563de92..65de6ed8b52 100644
--- a/lib/libc/arch/m88k/sys/Ovfork.S
+++ b/lib/libc/arch/m88k/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.10 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.11 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -35,4 +35,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/m88k/sys/cerror.S b/lib/libc/arch/m88k/sys/cerror.S
index 933f2400067..5fa6765c740 100644
--- a/lib/libc/arch/m88k/sys/cerror.S
+++ b/lib/libc/arch/m88k/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.12 2013/01/11 21:23:24 miod Exp $ */
+/* $OpenBSD: cerror.S,v 1.13 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -33,28 +33,40 @@
* SUCH DAMAGE.
*/
-#include "SYS.h"
+#include "DEFS.h"
-WEAK_ALIAS(__cerror,___cerror)
+ .globl _C_LABEL(__errno)
- .globl _C_LABEL(errno)
-ENTRY(___cerror)
-#ifdef __PIC__
- PIC_SAVE(%r9)
- PIC_SETUP
-#endif
+/*
+ * long long __cerror(register_t errcode)
+ * stores `errcode' into the current thread's errno variable, and returns
+ * -1LL.
+ */
+
+ASENTRY(__cerror)
+ /* if %r26 has been initialized, don't bother setting up a frame */
+ bcnd ne0, %r26, has_r26
+
+ subu %r31,%r31,16
+ st %r25,%r0,%r31
+ st %r1,%r31,4
#ifdef __PIC__
- PIC_STORE(%r2,_C_LABEL(errno))
+ bsr.n _C_LABEL(__errno)#plt
#else
- or.u %r4,%r0,%hi16(_C_LABEL(errno))
- st %r2,%r4,%lo16(_C_LABEL(errno))
+ bsr.n _C_LABEL(__errno)
#endif
+ or %r25,%r0,%r2
+ or %r26,%r0,%r2 /* save errno ptr */
+ or %r2,%r0,%r25 /* and restore errno value */
-#ifdef __PIC__
- PIC_RESTORE(%r9)
-#endif
- sub %r2,%r0,0x1
+ ld %r1,%r31,4
+ ld %r25,%r0,%r31
+ addu %r31,%r31,16
+
+has_r26:
+ st %r2,%r0,%r26
+ subu %r2,%r0,1
jmp.n %r1
- sub %r3,%r0,0x1
-END(___cerror)
+ or %r3, %r0, %r2
+END(__cerror)
diff --git a/lib/libc/arch/m88k/sys/fork.S b/lib/libc/arch/m88k/sys/fork.S
deleted file mode 100644
index 2c664f74fd2..00000000000
--- a/lib/libc/arch/m88k/sys/fork.S
+++ /dev/null
@@ -1,39 +0,0 @@
-/* $OpenBSD: fork.S,v 1.9 2015/04/07 01:27:06 guenther Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/m88k/sys/sigsuspend.S b/lib/libc/arch/m88k/sys/sigsuspend.S
index 7ba0e873353..847179c0845 100644
--- a/lib/libc/arch/m88k/sys/sigsuspend.S
+++ b/lib/libc/arch/m88k/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.12 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.13 2016/05/07 19:05:21 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -42,11 +42,11 @@
* sigset_t != sizeof int.
*/
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ld %r2,%r2,0 /* dereference the pointer mask */
or %r13,%r0,SYS_sigsuspend
tb0 0,%r0,450
br CERROR
jmp.n %r1
or %r2,%r0,0
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/mips64/Makefile.inc b/lib/libc/arch/mips64/Makefile.inc
index d8c4bff9a3e..e41f5ca03d1 100644
--- a/lib/libc/arch/mips64/Makefile.inc
+++ b/lib/libc/arch/mips64/Makefile.inc
@@ -1 +1,2 @@
-# $OpenBSD: Makefile.inc,v 1.2 2014/06/09 20:47:11 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.3 2016/05/07 19:05:22 guenther Exp $
+CERROR= cerror.S
diff --git a/lib/libc/arch/mips64/SYS.h b/lib/libc/arch/mips64/SYS.h
index bc4bcfa9f45..0eae2a001cc 100644
--- a/lib/libc/arch/mips64/SYS.h
+++ b/lib/libc/arch/mips64/SYS.h
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: SYS.h,v 1.11 2015/10/23 04:39:24 guenther Exp $
+ * $OpenBSD: SYS.h,v 1.12 2016/05/07 19:05:22 guenther Exp $
*/
#include <sys/syscall.h>
@@ -60,8 +60,8 @@
#define END_WEAK(x) END_STRONG(x); .weak x
-#define CERROR _C_LABEL(__cerror)
-#define _CERROR _C_LABEL(___cerror)
+#define CERROR __cerror
+ .hidden CERROR
# define __ENTRY(p,x) ENTRY(p ## x)
diff --git a/lib/libc/arch/mips64/sys/Ovfork.S b/lib/libc/arch/mips64/sys/Ovfork.S
index 6c1896bb8e6..85962be2c7f 100644
--- a/lib/libc/arch/mips64/sys/Ovfork.S
+++ b/lib/libc/arch/mips64/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.6 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.7 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -33,4 +33,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/mips64/sys/cerror.S b/lib/libc/arch/mips64/sys/cerror.S
index c6c5819fabd..b521bf8bc0f 100644
--- a/lib/libc/arch/mips64/sys/cerror.S
+++ b/lib/libc/arch/mips64/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.6 2011/07/08 19:31:41 miod Exp $ */
+/* $OpenBSD: cerror.S,v 1.7 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -33,20 +33,36 @@
#include "SYS.h"
-FRAMESZ= MKFSIZ(1,1)
+FRAMESZ= 4*REGSZ
+S0OFF= FRAMESZ-3*REGSZ
GPOFF= FRAMESZ-2*REGSZ
+RAOFF= FRAMESZ-1*REGSZ
-WEAK_ALIAS(CERROR, _CERROR)
+ .hidden _thread_cb
+ .hidden CERROR
- .globl _C_LABEL(errno)
-LEAF(_CERROR, FRAMESZ)
+NON_LEAF(CERROR, FRAMESZ, ra)
PTR_SUBU sp, FRAMESZ
- SETUP_GP64(GPOFF, _CERROR)
- .set noreorder
- sw v0, _C_LABEL(errno)
- li v0, -1
+#if !__PIC__ || !notyet
+ SETUP_GP64(GPOFF, CERROR)
+#endif
+ .set reorder
+ REG_S ra, RAOFF(sp)
+ REG_S s0, S0OFF(sp)
+
+ move s0, v0
+ dla v0, _thread_cb
+ ld t9, 0(v0)
+ jal t9
+
+ sw s0, 0(v0)
+
+ LI v0, -1
+ REG_L s0, S0OFF(sp)
+ REG_L ra, RAOFF(sp)
+#if !__PIC__ || !notyet
RESTORE_GP64
+#endif
PTR_ADDU sp, FRAMESZ
j ra
- li v1, -1
-END(_CERROR)
+END(CERROR)
diff --git a/lib/libc/arch/mips64/sys/fork.S b/lib/libc/arch/mips64/sys/fork.S
deleted file mode 100644
index be3b2851414..00000000000
--- a/lib/libc/arch/mips64/sys/fork.S
+++ /dev/null
@@ -1,37 +0,0 @@
-/* $OpenBSD: fork.S,v 1.7 2015/04/07 01:27:06 guenther Exp $ */
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/mips64/sys/sigsuspend.S b/lib/libc/arch/mips64/sys/sigsuspend.S
index 8fec33adb6e..6c445f61037 100644
--- a/lib/libc/arch/mips64/sys/sigsuspend.S
+++ b/lib/libc/arch/mips64/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.6 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.7 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,7 +36,7 @@
FRAMESZ= MKFSIZ(1,1)
GPOFF= FRAMESZ-2*REGSZ
-SYSLEAF(sigsuspend, FRAMESZ)
+SYSLEAF_HIDDEN(sigsuspend, FRAMESZ)
PTR_SUBU sp, FRAMESZ
SETUP_GP64(GPOFF, _HIDDEN(sigsuspend))
.set reorder
@@ -53,4 +53,4 @@ SYSLEAF(sigsuspend, FRAMESZ)
RESTORE_GP64
PTR_ADDU sp, FRAMESZ
jr t9
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/powerpc/Makefile.inc b/lib/libc/arch/powerpc/Makefile.inc
index 7e94acff690..74ee41bf416 100644
--- a/lib/libc/arch/powerpc/Makefile.inc
+++ b/lib/libc/arch/powerpc/Makefile.inc
@@ -1 +1,2 @@
-# $OpenBSD: Makefile.inc,v 1.4 2014/06/09 20:47:11 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2016/05/07 19:05:22 guenther Exp $
+CERROR= cerror.S
diff --git a/lib/libc/arch/powerpc/SYS.h b/lib/libc/arch/powerpc/SYS.h
index 61036697b71..05fe72401fa 100644
--- a/lib/libc/arch/powerpc/SYS.h
+++ b/lib/libc/arch/powerpc/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.20 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.21 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1994
* Andrew Cagney. All rights reserved.
@@ -68,13 +68,13 @@
#define _CONCAT(x,y) x##y
-#define PSEUDO_PREFIX(p,x,y) .extern _ASM_LABEL(___cerror) ; \
+#define PSEUDO_PREFIX(p,x,y) .extern _ASM_LABEL(__cerror) ; \
ENTRY(p##x) \
li 0, SYS_##y ; \
/* sc */
#define PSEUDO_SUFFIX cmpwi 0, 0 ; \
beqlr+ ; \
- b _ASM_LABEL(___cerror)
+ b _ASM_LABEL(__cerror)
#define PSEUDO_NOERROR_SUFFIX blr
diff --git a/lib/libc/arch/powerpc/sys/Ovfork.S b/lib/libc/arch/powerpc/sys/Ovfork.S
index 09edfc32c9d..daaa26cff52 100644
--- a/lib/libc/arch/powerpc/sys/Ovfork.S
+++ b/lib/libc/arch/powerpc/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.3 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -27,4 +27,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/powerpc/sys/brk.S b/lib/libc/arch/powerpc/sys/brk.S
index 91753f5afc1..77ea58769a0 100644
--- a/lib/libc/arch/powerpc/sys/brk.S
+++ b/lib/libc/arch/powerpc/sys/brk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: brk.S,v 1.11 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: brk.S,v 1.12 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -66,7 +66,7 @@ PSEUDO_PREFIX(,brk,break)
/* check for error */
cmpwi 0, 0
beq+ .L_brk_ok /* OK so this is stupid but I haven't read b */
- b _ASM_LABEL(___cerror)
+ b _ASM_LABEL(__cerror)
/* update, __curbrk and return */
.L_brk_ok:
diff --git a/lib/libc/arch/powerpc/sys/cerror.S b/lib/libc/arch/powerpc/sys/cerror.S
index 5dad24e0962..bd5b6a0edf5 100644
--- a/lib/libc/arch/powerpc/sys/cerror.S
+++ b/lib/libc/arch/powerpc/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.12 2015/09/09 08:24:12 kettenis Exp $ */
+/* $OpenBSD: cerror.S,v 1.13 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -30,11 +30,10 @@
#define ERRNOPTR_OFFSET 16
-WEAK_ALIAS(__cerror, ___cerror)
-
.text
- .protected _ASM_LABEL(___cerror)
-ASENTRY(___cerror)
+ .hidden _ASM_LABEL(__cerror)
+ .hidden _ASM_LABEL(_HIDDEN(__errno))
+ASENTRY(__cerror)
stwu 1, -16(1) /* follow the SVR4 ABI */
mflr 3 /* error value is in r0, use r3 */
stw 3, 20(1)
@@ -47,7 +46,7 @@ ASENTRY(___cerror)
addi 30, 30, _GLOBAL_OFFSET_TABLE_-1b@l
#endif
mr 31, 0
- bl PIC_PLT(__errno)
+ bl _ASM_LABEL(_HIDDEN(__errno))
stw 31, 0(3)
#ifdef __PIC__
lwz 30, 8(1)
@@ -59,4 +58,4 @@ ASENTRY(___cerror)
li 3, -1
li 4, -1
blr
-END(___cerror)
+END(__cerror)
diff --git a/lib/libc/arch/powerpc/sys/fork.S b/lib/libc/arch/powerpc/sys/fork.S
deleted file mode 100644
index ace55a4a4d1..00000000000
--- a/lib/libc/arch/powerpc/sys/fork.S
+++ /dev/null
@@ -1,33 +0,0 @@
-/* $OpenBSD: fork.S,v 1.3 2015/04/07 01:27:06 guenther Exp $ */
-
-/*
- * Copyright (c) 1996 Dale Rahn
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* pid = fork() */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/powerpc/sys/sbrk.S b/lib/libc/arch/powerpc/sys/sbrk.S
index 7303bc58fbf..36016f63055 100644
--- a/lib/libc/arch/powerpc/sys/sbrk.S
+++ b/lib/libc/arch/powerpc/sys/sbrk.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sbrk.S,v 1.10 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: sbrk.S,v 1.11 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -63,7 +63,7 @@ PSEUDO_PREFIX(,sbrk,break)
/* check for error */
cmpwi 0, 0
beq+ .L_sbrk_ok
- b _ASM_LABEL(___cerror)
+ b _ASM_LABEL(__cerror)
/* update, __curbrk and return */
.L_sbrk_ok:
diff --git a/lib/libc/arch/powerpc/sys/sigprocmask.S b/lib/libc/arch/powerpc/sys/sigprocmask.S
index 2d43827bb82..373685891f4 100644
--- a/lib/libc/arch/powerpc/sys/sigprocmask.S
+++ b/lib/libc/arch/powerpc/sys/sigprocmask.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigprocmask.S,v 1.10 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: sigprocmask.S,v 1.11 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -49,7 +49,7 @@ PREFIX_HIDDEN(sigprocmask)
/* didnt work? */
cmpwi 0, 0
beq+ .L_sigprocmask_ok
- b _ASM_LABEL(___cerror)
+ b _ASM_LABEL(__cerror)
.L_sigprocmask_ok:
lwz 5, 12(1)
diff --git a/lib/libc/arch/powerpc/sys/sigsuspend.S b/lib/libc/arch/powerpc/sys/sigsuspend.S
index cab1d4efe32..cbdd4ca971e 100644
--- a/lib/libc/arch/powerpc/sys/sigsuspend.S
+++ b/lib/libc/arch/powerpc/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.4 2015/09/05 20:06:04 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.5 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1996 Dale Rahn
@@ -30,8 +30,8 @@
#include "SYS.h"
.text
-PREFIX(sigsuspend)
+PREFIX_HIDDEN(sigsuspend)
lwz 3, 0(3) /* load the mask */
sc
PSEUDO_SUFFIX
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/powerpc/sys/tfork_thread.S b/lib/libc/arch/powerpc/sys/tfork_thread.S
index 6c154b8a22b..a59d22051c8 100644
--- a/lib/libc/arch/powerpc/sys/tfork_thread.S
+++ b/lib/libc/arch/powerpc/sys/tfork_thread.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: tfork_thread.S,v 1.5 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: tfork_thread.S,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2005 Tim Wiess <tim@nop.cx>
@@ -46,5 +46,5 @@ ENTRY(__tfork_thread)
1:
li %r3, -1
2:
- b _C_LABEL(___cerror)
+ b _C_LABEL(__cerror)
END(__tfork_thread)
diff --git a/lib/libc/arch/sh/Makefile.inc b/lib/libc/arch/sh/Makefile.inc
index 69a13eed486..74ee41bf416 100644
--- a/lib/libc/arch/sh/Makefile.inc
+++ b/lib/libc/arch/sh/Makefile.inc
@@ -1 +1,2 @@
-# $OpenBSD: Makefile.inc,v 1.4 2007/03/02 06:11:54 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2016/05/07 19:05:22 guenther Exp $
+CERROR= cerror.S
diff --git a/lib/libc/arch/sh/SYS.h b/lib/libc/arch/sh/SYS.h
index c3b95350399..5458eee62d8 100644
--- a/lib/libc/arch/sh/SYS.h
+++ b/lib/libc/arch/sh/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.9 2015/10/23 04:39:24 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.10 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -85,7 +85,6 @@
904:
#define CERROR _C_LABEL(__cerror)
-#define _CERROR _C_LABEL(___cerror)
#define _SYSCALL_NOERROR(x,y) \
SYSENTRY(x); \
diff --git a/lib/libc/arch/sh/sys/Ovfork.S b/lib/libc/arch/sh/sys/Ovfork.S
index a8d7d5e442e..ce21487d807 100644
--- a/lib/libc/arch/sh/sys/Ovfork.S
+++ b/lib/libc/arch/sh/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.2 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.3 2016/05/07 19:05:22 guenther Exp $ */
/* $NetBSD: Ovfork.S,v 1.5 2003/08/07 16:42:20 agc Exp $ */
/*-
@@ -37,4 +37,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/sh/sys/cerror.S b/lib/libc/arch/sh/sys/cerror.S
index 0740e7bb558..92e365571ff 100644
--- a/lib/libc/arch/sh/sys/cerror.S
+++ b/lib/libc/arch/sh/sys/cerror.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: cerror.S,v 1.5 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: cerror.S,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/* $NetBSD: cerror.S,v 1.10 2006/01/06 05:14:39 uwe Exp $ */
/*-
@@ -37,29 +37,22 @@
#include "SYS.h"
-WEAK_ALIAS(CERROR, _CERROR)
-
-ASENTRY(_CERROR)
-#ifdef __PIC__
- mova L_GOT, r0
- mov.l L_GOT, r1
- add r0, r1
- mov.l L_errno, r0
- mov.l @(r0, r1), r1
- mov.l r4, @r1
-#else
- mov.l L_errno, r1
- mov.l r4, @r1
-#endif
- mov #-1, r0
+ASENTRY(CERROR)
+ mov.l .L___errno, r1
+ PIC_PROLOGUE(.L_got)
+ sts.l pr, @-sp
+1: CALL r1
+ mov.l r4, @-sp ! save error code
+ mov.l @sp+, r4
+ lds.l @sp+, pr
+ PIC_EPILOGUE
+ mov.l r4, @r0
+ mov #-1, r1
rts
- mov #-1, r1
+ mov #-1, r0
.align 2
-#ifdef __PIC__
-L_GOT: .long _GLOBAL_OFFSET_TABLE_
-L_errno: .long _C_LABEL(errno)@GOT
-#else
-L_errno: .long _C_LABEL(errno)
-#endif
- SET_ENTRY_SIZE(_CERROR)
+.L_got: PIC_GOT_DATUM
+.L___errno: CALL_DATUM(_C_LABEL(__errno), 1b)
+ SET_ASENTRY_SIZE(CERROR)
+
diff --git a/lib/libc/arch/sh/sys/fork.S b/lib/libc/arch/sh/sys/fork.S
deleted file mode 100644
index 4ee5a0442df..00000000000
--- a/lib/libc/arch/sh/sys/fork.S
+++ /dev/null
@@ -1,41 +0,0 @@
-/* $OpenBSD: fork.S,v 1.4 2015/04/07 01:27:07 guenther Exp $ */
-/* $NetBSD: fork.S,v 1.10 2006/01/06 05:11:29 uwe Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)fork.s 5.1 (Berkeley) 4/23/90
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/sh/sys/sigsuspend.S b/lib/libc/arch/sh/sys/sigsuspend.S
index 2b1401bbcb2..f8aca89650d 100644
--- a/lib/libc/arch/sh/sys/sigsuspend.S
+++ b/lib/libc/arch/sh/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.2 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.3 2016/05/07 19:05:22 guenther Exp $ */
/* $NetBSD: sigsuspend.S,v 1.5 2003/08/07 16:42:21 agc Exp $ */
/*-
@@ -37,7 +37,7 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
mov r4, r0 /* fetch mask arg */
mov.l @r0, r0 /* indirect to mask arg */
mov r0, r4
@@ -53,4 +53,4 @@ SYSENTRY(sigsuspend)
.align 2
LSYS_sigsuspend:
.long SYS_sigsuspend
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/sparc/SYS.h b/lib/libc/arch/sparc/SYS.h
index 1e22754c186..b507659224a 100644
--- a/lib/libc/arch/sparc/SYS.h
+++ b/lib/libc/arch/sparc/SYS.h
@@ -30,13 +30,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: SYS.h,v 1.20 2015/10/23 04:39:25 guenther Exp $
+ * $OpenBSD: SYS.h,v 1.21 2016/05/07 19:05:22 guenther Exp $
*/
#include "DEFS.h"
#include <sys/syscall.h>
#include <machine/trap.h>
+/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
+#define TCB_OFFSET_ERRNO 12
+
#define _CAT(x,y) x##y
#define __ENTRY(p,x) ENTRY(_CAT(p,x)) ; .weak x ; x = _CAT(p,x)
@@ -48,27 +51,13 @@
#define __END(p,x) __END_HIDDEN(p,x); END(x)
/*
- * ERROR branches to cerror.
+ * ERROR sets the thread's errno and returns
*/
-#ifdef __PIC__
-#if __PIC__ == 1
-#define ERROR() \
- PIC_PROLOGUE(%g1,%g2); \
- ld [%g1+_C_LABEL(__cerror)],%g2; jmp %g2; nop
-#else /* __PIC__ == 2 */
-#define ERROR() \
- PIC_PROLOGUE(%g1,%g2); \
- sethi %hi(_C_LABEL(__cerror)),%g2; \
- or %g2,%lo(_C_LABEL(__cerror)),%g2; \
- ld [%g1+%g2],%g2; jmp %g2; nop
-#endif
-#else
-#define ERROR() \
- sethi %hi(_C_LABEL(__cerror)),%g1; \
- or %lo(_C_LABEL(__cerror)),%g1,%g1; \
- jmp %g1; \
- nop
-#endif
+#define ERROR() \
+ st %o0, [%g7 + TCB_OFFSET_ERRNO]; \
+ mov -1, %o0; \
+ retl; \
+ mov -1, %o1
/*
* SYSCALL is used when further action must be taken before returning.
@@ -112,5 +101,3 @@
# define SYSENTRY_HIDDEN(x) __ENTRY_HIDDEN(_thread_sys_,x)
# define SYSCALL_END(x) __END(_thread_sys_,x)
# define SYSCALL_END_HIDDEN(x) __END_HIDDEN(_thread_sys_,x)
-
- .globl _C_LABEL(__cerror)
diff --git a/lib/libc/arch/sparc/sys/Ovfork.S b/lib/libc/arch/sparc/sys/Ovfork.S
index a0a9ce8d3d8..fd37aecda0b 100644
--- a/lib/libc/arch/sparc/sys/Ovfork.S
+++ b/lib/libc/arch/sparc/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.5 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,4 +34,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/sparc/sys/cerror.S b/lib/libc/arch/sparc/sys/cerror.S
deleted file mode 100644
index 5b565a70ebd..00000000000
--- a/lib/libc/arch/sparc/sys/cerror.S
+++ /dev/null
@@ -1,59 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.8 2012/09/04 19:08:15 deraadt Exp $ */
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "DEFS.h"
-#include "SYS.h"
-
- .globl _C_LABEL(errno)
-
-WEAK_ALIAS(__cerror, ___cerror)
-
-FUNC(_C_LABEL(___cerror))
-#ifdef __PIC__
-#if __PIC__ == 1
- ld [%g1 + _C_LABEL(errno)], %g1
- st %o0, [%g1]
-#else /* __PIC__ == 2 */
- sethi %hi(_C_LABEL(errno)), %g2
- or %g2, %lo(_C_LABEL(errno)), %g2
- ld [%g1 + %g2], %g1
- st %o0, [%g1]
-#endif
-#else
- sethi %hi(_C_LABEL(errno)), %g1
- st %o0, [%g1 + %lo(_C_LABEL(errno))]
-#endif
- mov -1, %o0
- retl
- mov -1, %o1
diff --git a/lib/libc/arch/sparc/sys/fork.S b/lib/libc/arch/sparc/sys/fork.S
deleted file mode 100644
index 911fce204dd..00000000000
--- a/lib/libc/arch/sparc/sys/fork.S
+++ /dev/null
@@ -1,38 +0,0 @@
-/* $OpenBSD: fork.S,v 1.6 2015/04/07 01:27:07 guenther Exp $ */
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/sparc/sys/sigsuspend.S b/lib/libc/arch/sparc/sys/sigsuspend.S
index ee728bd4f9f..0dcd0dbaff0 100644
--- a/lib/libc/arch/sparc/sys/sigsuspend.S
+++ b/lib/libc/arch/sparc/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.6 2015/09/10 13:29:09 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.7 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,9 +34,9 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ld [%o0], %o0 ! indirect to mask argument
mov SYS_sigsuspend, %g1
t ST_SYSCALL
ERROR() ! always terminates with EINTR
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/arch/sparc64/SYS.h b/lib/libc/arch/sparc64/SYS.h
index 85c48829f8c..891323eb508 100644
--- a/lib/libc/arch/sparc64/SYS.h
+++ b/lib/libc/arch/sparc64/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.15 2015/10/23 04:39:25 guenther Exp $ */
+/* $OpenBSD: SYS.h,v 1.16 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -41,6 +41,9 @@
#include <sys/syscall.h>
#include <machine/trap.h>
+/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
+#define TCB_OFFSET_ERRNO 24
+
#define _CAT(x,y) x##y
#define __ENTRY(p,x) ENTRY(_CAT(p,x)) ; .weak x; x = _CAT(p,x)
@@ -76,23 +79,12 @@
#define __END(p,x) __END_HIDDEN(p,x); END(x)
/*
- * ERROR branches to cerror. This is done with a macro so that I can
- * change it to be position independent later, if need be.
+ * ERROR sets the thread's errno and returns
*/
-#ifdef __PIC__
-#define CALL(name) \
- PIC_PROLOGUE(%g1,%g2); \
- sethi %hi(name),%g2; \
- or %g2,%lo(name),%g2; \
- ldx [%g1+%g2],%g2; \
- jmp %g2; \
- nop
-#else
-#define CALL(name) \
- sethi %hi(name),%g1; or %lo(name),%g1,%g1; \
- jmp %g1; nop
-#endif
-#define ERROR() CALL(_C_LABEL(__cerror))
+#define ERROR() \
+ st %o0, [%g7 + TCB_OFFSET_ERRNO]; \
+ retl; \
+ mov -1, %o0
/*
* SYSCALL is used when further action must be taken before returning.
@@ -155,8 +147,6 @@
__ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
t ST_SYSCALL; __END(p,x)
- .globl _C_LABEL(__cerror)
-
/*
* SYSENTRY is for functions that pretend to be syscalls.
*/
diff --git a/lib/libc/arch/sparc64/sys/Ovfork.S b/lib/libc/arch/sparc64/sys/Ovfork.S
index 86860d38482..a34a0ea3117 100644
--- a/lib/libc/arch/sparc64/sys/Ovfork.S
+++ b/lib/libc/arch/sparc64/sys/Ovfork.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: Ovfork.S,v 1.3 2015/03/31 04:32:02 guenther Exp $ */
+/* $OpenBSD: Ovfork.S,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -37,4 +37,4 @@
#include "SYS.h"
-RSYSCALL(vfork)
+RSYSCALL_HIDDEN(vfork)
diff --git a/lib/libc/arch/sparc64/sys/cerror.S b/lib/libc/arch/sparc64/sys/cerror.S
deleted file mode 100644
index d00ed87c596..00000000000
--- a/lib/libc/arch/sparc64/sys/cerror.S
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $OpenBSD: cerror.S,v 1.6 2015/09/05 06:22:47 guenther Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-#include "SYS.h"
-
-WEAK_ALIAS(__cerror, ___cerror)
-
- .globl _C_LABEL(errno)
-FUNC(___cerror)
-#ifdef __PIC__
- PIC_PROLOGUE(%g1, %o3)
- sethi %hi(_C_LABEL(errno)), %o3
- or %o3, %lo(_C_LABEL(errno)), %o3
- ldx [ %g1 + %o3 ], %g1
- st %o0, [%g1]
-#else
- sethi %hi(_C_LABEL(errno)), %g1
- st %o0, [%g1 + %lo(_C_LABEL(errno))]
-#endif
- mov -1, %o0
- retl
- mov -1, %o1
-END(___cerror)
diff --git a/lib/libc/arch/sparc64/sys/fork.S b/lib/libc/arch/sparc64/sys/fork.S
deleted file mode 100644
index f432448d4ad..00000000000
--- a/lib/libc/arch/sparc64/sys/fork.S
+++ /dev/null
@@ -1,41 +0,0 @@
-/* $OpenBSD: fork.S,v 1.4 2015/04/07 01:27:07 guenther Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-#include "SYS.h"
-
-RSYSCALL_HIDDEN(fork)
-WEAK_ALIAS(_thread_fork,_thread_sys_fork)
diff --git a/lib/libc/arch/sparc64/sys/sigsuspend.S b/lib/libc/arch/sparc64/sys/sigsuspend.S
index c81c9d4310e..0bede84ef73 100644
--- a/lib/libc/arch/sparc64/sys/sigsuspend.S
+++ b/lib/libc/arch/sparc64/sys/sigsuspend.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsuspend.S,v 1.3 2015/09/05 06:22:47 guenther Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,9 +36,9 @@
#include "SYS.h"
-SYSENTRY(sigsuspend)
+SYSENTRY_HIDDEN(sigsuspend)
ld [%o0], %o0 /* indirect to mask argument */
mov SYS_sigsuspend, %g1
t ST_SYSCALL
ERROR() /* always terminates with EINTR */
-SYSCALL_END(sigsuspend)
+SYSCALL_END_HIDDEN(sigsuspend)
diff --git a/lib/libc/dlfcn/Makefile.inc b/lib/libc/dlfcn/Makefile.inc
index f88b0f3fc0b..6605c7f113e 100644
--- a/lib/libc/dlfcn/Makefile.inc
+++ b/lib/libc/dlfcn/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.4 2016/03/20 02:32:39 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2016/05/07 19:05:22 guenther Exp $
.PATH: ${LIBCSRCDIR}/dlfcn
.include <bsd.own.mk>
-SRCS+= dlfcn_stubs.c init.c
+SRCS+= dlfcn_stubs.c init.c tib.c
diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c
index 9e6af9d92f2..3147f9ba7f1 100644
--- a/lib/libc/dlfcn/init.c
+++ b/lib/libc/dlfcn/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.3 2016/03/21 00:41:13 guenther Exp $ */
+/* $OpenBSD: init.c,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
*
@@ -22,10 +22,15 @@
#include <sys/exec_elf.h>
#include <sys/syscall.h>
+#ifndef PIC
+#include <sys/mman.h>
+#endif
+
+#include <tib.h>
#include <limits.h> /* NAME_MAX */
#include <stdlib.h> /* atexit */
#include <string.h>
-#include <unistd.h> /* _pagesize */
+#include <unistd.h>
/* XXX should be in an include file shared with csu */
char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void));
@@ -43,6 +48,7 @@ char *__progname __attribute__((weak)) = NULL;
#ifndef PIC
static inline void early_static_init(char **_argv, char **_envp);
+static inline void setup_static_tib(Elf_Phdr *_phdr, int _phnum);
#endif /* PIC */
@@ -55,8 +61,10 @@ char ***
_csu_finish(char **argv, char **envp, void (*cleanup)(void))
{
AuxInfo *aux;
-
#ifndef PIC
+ Elf_Phdr *phdr = NULL;
+ int phnum = 0;
+
/* static libc in a static link? */
if (cleanup == NULL)
early_static_init(argv, envp);
@@ -70,9 +78,23 @@ _csu_finish(char **argv, char **envp, void (*cleanup)(void))
case AUX_pagesz:
_pagesize = aux->au_v;
break;
+#ifndef PIC
+ case AUX_phdr:
+ phdr = (void *)aux->au_v;
+ break;
+ case AUX_phnum:
+ phnum = aux->au_v;
+ break;
+#endif /* !PIC */
}
}
+#ifndef PIC
+ /* static libc in a static link? */
+ if (cleanup == NULL)
+ setup_static_tib(phdr, phnum);
+#endif /* !PIC */
+
if (cleanup != NULL)
atexit(cleanup);
@@ -106,4 +128,84 @@ early_static_init(char **argv, char **envp)
}
__progname = progname_storage;
}
+
+/*
+ * static TLS handling
+ */
+#define ELF_ROUND(x,malign) (((x) + (malign)-1) & ~((malign)-1))
+
+/* for static binaries, the location and size of the TLS image */
+static void *static_tls;
+static size_t static_tls_fsize;
+
+size_t _static_tls_size = 0;
+
+static inline void
+setup_static_tib(Elf_Phdr *phdr, int phnum)
+{
+ struct tib *tib;
+ char *base;
+ int i;
+
+ if (phdr != NULL) {
+ for (i = 0; i < phnum; i++) {
+ if (phdr[i].p_type != PT_TLS)
+ continue;
+ if (phdr[i].p_memsz == 0)
+ break;
+ if (phdr[i].p_memsz < phdr[i].p_filesz)
+ break; /* invalid */
+#if TLS_VARIANT == 1
+ _static_tls_size = phdr[i].p_memsz;
+#elif TLS_VARIANT == 2
+ /*
+ * variant 2 places the data before the TIB
+ * so we need to round up to the alignment
+ */
+ _static_tls_size = ELF_ROUND(phdr[i].p_memsz,
+ phdr[i].p_align);
+#endif
+ if (phdr[i].p_vaddr != 0 && phdr[i].p_filesz != 0) {
+ static_tls = (void *)phdr[i].p_vaddr;
+ static_tls_fsize = phdr[i].p_filesz;
+ }
+ break;
+ }
+ }
+
+ /*
+ * We call getpagesize() here instead of using _pagesize because
+ * there's no aux-vector in non-PIE static links, so _pagesize
+ * might not be set yet. If so getpagesize() will get the value.
+ */
+ base = mmap(NULL, ELF_ROUND(_static_tls_size + sizeof *tib,
+ getpagesize()), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+# if TLS_VARIANT == 1
+ tib = (struct tib *)base;
+# elif TLS_VARIANT == 2
+ tib = (struct tib *)(base + _static_tls_size);
+# endif
+
+ _static_tls_init(base);
+ TIB_INIT(tib, NULL, NULL);
+ tib->tib_tid = getthrid();
+ TCB_SET(TIB_TO_TCB(tib));
+#if ! TCB_HAVE_MD_GET
+ _libc_single_tcb = TIB_TO_TCB(tib);
+#endif
+}
+
+void
+_static_tls_init(char *base)
+{
+ if (_static_tls_size) {
+#if TLS_VARIANT == 1
+ base += sizeof(struct tib);
+#endif
+ if (static_tls != NULL)
+ memcpy(base, static_tls, static_tls_fsize);
+ memset(base + static_tls_fsize, 0,
+ _static_tls_size - static_tls_fsize);
+ }
+}
#endif /* !PIC */
diff --git a/lib/libc/dlfcn/tib.c b/lib/libc/dlfcn/tib.c
new file mode 100644
index 00000000000..4aba706e363
--- /dev/null
+++ b/lib/libc/dlfcn/tib.c
@@ -0,0 +1,86 @@
+/* $OpenBSD: tib.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
+/*
+ * Copyright (c) 2016 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>
+
+#ifndef PIC
+# include <stdlib.h> /* malloc and free */
+#endif
+
+#define ELF_ROUND(x,malign) (((x) + (malign)-1) & ~((malign)-1))
+
+
+/*
+ * The functions here are weak so that the ld.so versions are used
+ * in dynamic links, whether or not libc is static
+ */
+void *_dl_allocate_tib(size_t _extra) __attribute__((weak));
+void _dl_free_tib(void *_tib, size_t _extra) __attribute__((weak));
+
+/*
+ * Allocate a TIB for passing to __tfork for a new thread. 'extra'
+ * is the amount of space to allocate on the side of the TIB opposite
+ * of the TLS data: before the TIB for variant 1 and after the TIB
+ * for variant 2. If non-zero, tib_thread is set to point to that area.
+ */
+void *
+_dl_allocate_tib(size_t extra)
+{
+#ifdef PIC
+ return NULL; /* overriden by ld.so */
+#else
+ char *base;
+ char *thread;
+ struct tib *tib;
+
+# if TLS_VARIANT == 1
+ /* round up the extra size to align the tib after it */
+ extra = ELF_ROUND(extra, sizeof(void *));
+ base = malloc(extra + sizeof(struct tib) + _static_tls_size);
+ tib = (struct tib *)(base + extra);
+ thread = base;
+
+# elif TLS_VARIANT == 2
+ /* round up the tib size to align the extra area after it */
+ base = malloc(ELF_ROUND(sizeof(struct tib), TIB_EXTRA_ALIGN) +
+ extra + _static_tls_size);
+ tib = (struct tib *)(base + _static_tls_size);
+ thread = (char *)tib + ELF_ROUND(sizeof(struct tib), TIB_EXTRA_ALIGN);
+# endif
+
+ _static_tls_init(base);
+ TIB_INIT(tib, NULL, thread);
+
+ return (tib);
+#endif /* !PIC */
+}
+
+void
+_dl_free_tib(void *tib, size_t extra)
+{
+#ifndef PIC
+ size_t tib_offset;
+
+# if TLS_VARIANT == 1
+ tib_offset = ELF_ROUND(extra, sizeof(void *));
+# elif TLS_VARIANT == 2
+ tib_offset = _static_tls_size;
+# endif
+
+ free((char *)tib - tib_offset);
+#endif /* !PIC */
+}
diff --git a/lib/libc/gen/errno.c b/lib/libc/gen/errno.c
index 62c0978c6aa..d706b0807a7 100644
--- a/lib/libc/gen/errno.c
+++ b/lib/libc/gen/errno.c
@@ -1,21 +1,72 @@
-/* $OpenBSD: errno.c,v 1.5 2005/08/08 08:05:34 espie Exp $ */
+/* $OpenBSD: errno.c,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
+#include <tib.h>
#include <errno.h>
-#undef errno
+#include <unistd.h>
+#include "thread_private.h"
+
+#ifdef TCB_HAVE_MD_GET
/*
- * global errno for unthreaded programs.
+ * If there's an MD TCB_GET() macro, then getting the TCB address is
+ * cheap enough that we can do it even in single-threaded programs,
+ * so the tc_errnoptr and tc_tcb callbacks will be unused, and __errno()
+ * can just use TIB_GET().
*/
-int errno;
+int *
+__errno(void)
+{
+ return (&TIB_GET()->tib_errno);
+}
+DEF_STRONG(__errno);
+#else /* ! TCB_HAVE_MD_GET */
/*
- * weak version of function used by unthreaded programs.
+ * Otherwise, getting the TCB address requires the __get_tcb()
+ * syscall. Rather than pay that cost for single-threaded programs,
+ * the syscall stubs will invoke the tc_errnoptr callback to set errno
+ * and other code will invoke the tc_tcb callback to get the TCB
+ * for cancelation checks, etc. The default callbacks will just
+ * work from the cached location of the initial thread's TCB;
+ * libpthread can override them to the necessary more expensive
+ * versions that use __get_tcb().
+ */
+
+/* cached pointer to the TCB of the only thread in single-threaded programs */
+void *_libc_single_tcb = NULL;
+
+static inline void *
+single_threaded_tcb(void)
+{
+ if (__predict_false(_libc_single_tcb == NULL))
+ _libc_single_tcb = TCB_GET();
+ return (_libc_single_tcb);
+}
+
+static int *
+single_threaded_errnoptr(void)
+{
+ return &TCB_TO_TIB(single_threaded_tcb())->tib_errno;
+}
+
+/*
+ * __errno(): just use the callback to get the applicable current method
*/
int *
-___errno(void)
+__errno(void)
{
- return &errno;
+ return (_thread_cb.tc_errnoptr());
}
+DEF_STRONG(__errno);
+
+#endif /* !TCB_HAVE_MD_GET */
-__weak_alias(__errno, ___errno);
+
+struct thread_callbacks _thread_cb =
+{
+#ifndef TCB_HAVE_MD_GET
+ .tc_errnoptr = &single_threaded_errnoptr,
+ .tc_tcb = &single_threaded_tcb,
+#endif
+};
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index d1d55756975..8c1d04764fe 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getcwd.c,v 1.19 2013/09/30 12:02:33 millert Exp $ */
+/* $OpenBSD: getcwd.c,v 1.20 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2005 Marius Eriksen <marius@openbsd.org>
@@ -44,3 +44,4 @@ getcwd(char *buf, size_t size)
return (buf);
}
+DEF_WEAK(getcwd);
diff --git a/lib/libc/hidden/errno.h b/lib/libc/hidden/errno.h
index d54317ff4c9..d94d6bcd9d9 100644
--- a/lib/libc/hidden/errno.h
+++ b/lib/libc/hidden/errno.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: errno.h,v 1.3 2015/09/19 04:02:21 guenther Exp $ */
+/* $OpenBSD: errno.h,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -31,6 +31,6 @@ extern PROTO_NORMAL(sys_nerr);
extern PROTO_NORMAL(sys_errlist);
#endif
-/*PROTO_OVERRIDABLE(__errno);*/
+PROTO_NORMAL(__errno);
#endif /* _LIBC_ERRNO_H_ */
diff --git a/lib/libc/hidden/fcntl.h b/lib/libc/hidden/fcntl.h
index 583a6aeb3d1..b5f069768fc 100644
--- a/lib/libc/hidden/fcntl.h
+++ b/lib/libc/hidden/fcntl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fcntl.h,v 1.1 2015/09/12 16:40:50 guenther Exp $ */
+/* $OpenBSD: fcntl.h,v 1.2 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -21,9 +21,9 @@
#include_next <fcntl.h>
PROTO_DEPRECATED(creat);
-/*PROTO_CANCEL(fcntl);*/
+PROTO_CANCEL(fcntl);
PROTO_NORMAL(flock);
-/*PROTO_CANCEL(open);*/
-/*PROTO_CANCEL(openat);*/
+PROTO_CANCEL(open);
+PROTO_CANCEL(openat);
#endif /* !_LIBC_FCNTL_H_ */
diff --git a/lib/libc/hidden/poll.h b/lib/libc/hidden/poll.h
new file mode 100644
index 00000000000..636c6964901
--- /dev/null
+++ b/lib/libc/hidden/poll.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: poll.h,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.
+ */
+/* $OpenBSD: poll.h,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
+
+#ifndef _LIBC_POLL_H_
+#define _LIBC_POLL_H_
+
+#include_next <poll.h>
+
+PROTO_CANCEL(poll);
+PROTO_CANCEL(ppoll);
+
+#endif /* !_LIBC_POLL_H_ */
diff --git a/lib/libc/hidden/signal.h b/lib/libc/hidden/signal.h
index 5a1f17fb5c1..33e2b7b3acb 100644
--- a/lib/libc/hidden/signal.h
+++ b/lib/libc/hidden/signal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: signal.h,v 1.10 2015/11/10 04:30:59 guenther Exp $ */
+/* $OpenBSD: signal.h,v 1.11 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -29,6 +29,9 @@ extern PROTO_NORMAL(sys_siglist);
extern PROTO_NORMAL(sys_signame);
#endif
+/* prototyped for and used by the inline functions */
+PROTO_NORMAL(__errno);
+
PROTO_DEPRECATED(bsd_signal);
PROTO_NORMAL(kill); /* wrap to ban SIGTHR? */
PROTO_DEPRECATED(killpg);
@@ -50,7 +53,7 @@ PROTO_NORMAL(sigpending);
PROTO_WRAP(sigprocmask);
PROTO_NORMAL(sigreturn);
PROTO_NORMAL(sigsetmask);
-/*PROTO_CANCEL(sigsuspend); wrap to hide SIGTHR */
+PROTO_CANCEL(sigsuspend);
PROTO_DEPRECATED(sigvec);
PROTO_NORMAL(thrkill);
diff --git a/lib/libc/hidden/stdio.h b/lib/libc/hidden/stdio.h
index 5d33bd3b98c..1240a3a0bf3 100644
--- a/lib/libc/hidden/stdio.h
+++ b/lib/libc/hidden/stdio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stdio.h,v 1.5 2015/09/19 04:02:21 guenther Exp $ */
+/* $OpenBSD: stdio.h,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -51,7 +51,7 @@ PROTO_NORMAL(fgetln);
PROTO_NORMAL(fgetpos);
PROTO_NORMAL(fgets);
PROTO_NORMAL(fileno);
-/*PROTO_NORMAL(flockfile);*/
+PROTO_NORMAL(flockfile);
PROTO_NORMAL(fmemopen);
PROTO_NORMAL(fopen);
PROTO_NORMAL(fprintf);
@@ -66,8 +66,8 @@ PROTO_NORMAL(fseeko);
PROTO_NORMAL(fsetpos);
PROTO_NORMAL(ftell);
PROTO_NORMAL(ftello);
-/*PROTO_NORMAL(ftrylockfile);*/
-/*PROTO_NORMAL(funlockfile);*/
+PROTO_NORMAL(ftrylockfile);
+PROTO_NORMAL(funlockfile);
PROTO_NORMAL(funopen);
PROTO_NORMAL(fwrite);
PROTO_NORMAL(getc);
diff --git a/lib/libc/hidden/sys/mman.h b/lib/libc/hidden/sys/mman.h
index b01a4a9deff..655bf571ca5 100644
--- a/lib/libc/hidden/sys/mman.h
+++ b/lib/libc/hidden/sys/mman.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mman.h,v 1.2 2015/09/12 15:01:33 guenther Exp $ */
+/* $OpenBSD: mman.h,v 1.3 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -28,7 +28,7 @@ PROTO_NORMAL(mlockall);
PROTO_NORMAL(mmap);
PROTO_NORMAL(mprotect);
PROTO_NORMAL(mquery);
-/*PROTO_CANCEL(msync);*/
+PROTO_CANCEL(msync);
PROTO_NORMAL(munlock);
PROTO_NORMAL(munlockall);
PROTO_NORMAL(munmap);
diff --git a/lib/libc/hidden/sys/msg.h b/lib/libc/hidden/sys/msg.h
new file mode 100644
index 00000000000..8208c739f6d
--- /dev/null
+++ b/lib/libc/hidden/sys/msg.h
@@ -0,0 +1,28 @@
+/* $OpenBSD: msg.h,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.
+ */
+
+#ifndef _LIBC_SYS_MSG_H_
+#define _LIBC_SYS_MSG_H_
+
+#include_next <sys/msg.h>
+
+PROTO_NORMAL(msgctl);
+PROTO_NORMAL(msgget);
+PROTO_CANCEL(msgrcv);
+PROTO_CANCEL(msgsnd);
+
+#endif /* !_LIBC_SYS_MSG_H_ */
diff --git a/lib/libc/hidden/sys/select.h b/lib/libc/hidden/sys/select.h
new file mode 100644
index 00000000000..f67f3e5ee7e
--- /dev/null
+++ b/lib/libc/hidden/sys/select.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: select.h,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.
+ */
+/* $OpenBSD: select.h,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
+
+#ifndef _LIBC_SYS_SELECT_H_
+#define _LIBC_SYS_SELECT_H_
+
+#include_next <sys/select.h>
+
+PROTO_CANCEL(select);
+PROTO_CANCEL(pselect);
+
+#endif /* !_LIBC_SYS_SELECT_H_ */
diff --git a/lib/libc/hidden/sys/socket.h b/lib/libc/hidden/sys/socket.h
index d262e0f3bac..2d8b3e4f120 100644
--- a/lib/libc/hidden/sys/socket.h
+++ b/lib/libc/hidden/sys/socket.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.h,v 1.3 2015/10/04 07:17:27 guenther Exp $ */
+/* $OpenBSD: socket.h,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -20,7 +20,10 @@
#include_next <sys/socket.h>
+PROTO_CANCEL(accept);
+PROTO_CANCEL(accept4);
PROTO_NORMAL(bind);
+PROTO_CANCEL(connect);
PROTO_DEPRECATED(getpeereid);
PROTO_NORMAL(getpeername);
PROTO_NORMAL(getrtable);
@@ -28,7 +31,11 @@ PROTO_NORMAL(getsockname);
PROTO_NORMAL(getsockopt);
PROTO_NORMAL(listen);
PROTO_NORMAL(recv);
+PROTO_CANCEL(recvfrom);
+PROTO_CANCEL(recvmsg);
PROTO_NORMAL(send);
+PROTO_CANCEL(sendmsg);
+PROTO_CANCEL(sendto);
PROTO_NORMAL(setrtable);
PROTO_NORMAL(setsockopt);
PROTO_NORMAL(shutdown);
diff --git a/lib/libc/hidden/sys/uio.h b/lib/libc/hidden/sys/uio.h
new file mode 100644
index 00000000000..8db874ed537
--- /dev/null
+++ b/lib/libc/hidden/sys/uio.h
@@ -0,0 +1,28 @@
+/* $OpenBSD: uio.h,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.
+ */
+
+#ifndef _LIBC_SYS_UIO_H_
+#define _LIBC_SYS_UIO_H_
+
+#include_next <sys/uio.h>
+
+PROTO_CANCEL(preadv);
+PROTO_CANCEL(pwritev);
+PROTO_CANCEL(readv);
+PROTO_CANCEL(writev);
+
+#endif /* !_LIBC_SYS_UIO_H_ */
diff --git a/lib/libc/hidden/sys/wait.h b/lib/libc/hidden/sys/wait.h
index 4fdf0be1690..b73d383220b 100644
--- a/lib/libc/hidden/sys/wait.h
+++ b/lib/libc/hidden/sys/wait.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: wait.h,v 1.1 2015/10/25 19:15:56 guenther Exp $ */
+/* $OpenBSD: wait.h,v 1.2 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -23,6 +23,6 @@
PROTO_DEPRECATED(wait);
PROTO_NORMAL(waitpid);
PROTO_DEPRECATED(wait3);
-/*PROTO_CANCEL(wait4);*/
+PROTO_CANCEL(wait4);
#endif /* !_LIBC_SYS_WAIT_H_ */
diff --git a/lib/libc/hidden/tib.h b/lib/libc/hidden/tib.h
new file mode 100644
index 00000000000..49a562dbad9
--- /dev/null
+++ b/lib/libc/hidden/tib.h
@@ -0,0 +1,46 @@
+/* $OpenBSD: tib.h,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.
+ */
+
+#ifndef _LIBC_TIB_H_
+#define _LIBC_TIB_H_
+
+#include_next <tib.h>
+
+__BEGIN_HIDDEN_DECLS
+
+#ifndef PIC
+void _static_tls_init(char *_base);
+
+/* size of static TLS allocation in staticly linked programs */
+extern size_t _static_tls_size;
+#endif
+
+#if ! TCB_HAVE_MD_GET
+/*
+ * For archs without a fast TCB_GET(): the pointer to the TCB in
+ * single-threaded programs, whether linked staticly or dynamically.
+ */
+extern void *_libc_single_tcb;
+#endif
+
+__END_HIDDEN_DECLS
+
+
+PROTO_NORMAL(__get_tcb);
+PROTO_NORMAL(__set_tcb);
+
+#endif /* _LIBC_TIB_H_ */
diff --git a/lib/libc/hidden/time.h b/lib/libc/hidden/time.h
index ec118c393ac..47dbd30beea 100644
--- a/lib/libc/hidden/time.h
+++ b/lib/libc/hidden/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.3 2015/09/19 04:02:21 guenther Exp $ */
+/* $OpenBSD: time.h,v 1.4 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -39,7 +39,7 @@ PROTO_NORMAL(gmtime_r);
PROTO_NORMAL(localtime);
PROTO_NORMAL(localtime_r);
PROTO_NORMAL(mktime);
-/*PROTO_CANCEL(nanosleep);*/
+PROTO_CANCEL(nanosleep);
PROTO_NORMAL(strftime);
PROTO_NORMAL(strptime);
PROTO_NORMAL(time);
diff --git a/lib/libc/hidden/unistd.h b/lib/libc/hidden/unistd.h
index 3565869772a..a7ac1a5824e 100644
--- a/lib/libc/hidden/unistd.h
+++ b/lib/libc/hidden/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.7 2016/03/30 07:52:47 guenther Exp $ */
+/* $OpenBSD: unistd.h,v 1.8 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -34,8 +34,8 @@ PROTO_DEPRECATED(brk);
PROTO_NORMAL(chdir);
PROTO_NORMAL(chown);
PROTO_NORMAL(chroot);
-/*PROTO_CANCEL(close);*/
-/*PROTO_CANCEL(closefrom);*/
+PROTO_CANCEL(close);
+PROTO_CANCEL(closefrom);
PROTO_DEPRECATED(confstr);
PROTO_NORMAL(crypt);
PROTO_NORMAL(crypt_checkpass);
@@ -57,11 +57,11 @@ PROTO_NORMAL(fchown);
PROTO_NORMAL(fchownat);
/*PROTO_CANCEL(fdatasync);*/
PROTO_DEPRECATED(fflagstostr);
-/*PROTO_WRAP(fork);*/
+PROTO_WRAP(fork);
PROTO_NORMAL(fpathconf);
-/*PROTO_CANCEL(fsync);*/
+PROTO_CANCEL(fsync);
PROTO_NORMAL(ftruncate);
-/*PROTO_BARE(getcwd);*/
+PROTO_NORMAL(getcwd);
PROTO_NORMAL(getdomainname);
PROTO_NORMAL(getdtablecount);
PROTO_DEPRECATED(getdtablesize);
@@ -111,14 +111,14 @@ PROTO_NORMAL(pathconf);
PROTO_NORMAL(pipe);
PROTO_NORMAL(pipe2);
PROTO_NORMAL(pledge);
-/*PROTO_CANCEL(pread);*/
+PROTO_CANCEL(pread);
PROTO_NORMAL(profil);
-/*PROTO_CANCEL(pwrite);*/
+PROTO_CANCEL(pwrite);
PROTO_NORMAL(quotactl);
PROTO_DEPRECATED(rcmd);
PROTO_NORMAL(rcmd_af);
PROTO_NORMAL(rcmdsh);
-/*PROTO_CANCEL(read);*/
+PROTO_CANCEL(read);
PROTO_NORMAL(readlink);
PROTO_NORMAL(readlinkat);
PROTO_NORMAL(reboot);
@@ -128,7 +128,7 @@ PROTO_DEPRECATED(rresvport);
PROTO_NORMAL(rresvport_af);
PROTO_DEPRECATED(ruserok);
PROTO_DEPRECATED(sbrk);
-/*PROTO_CANCEL(select);*/
+PROTO_CANCEL(select);
PROTO_DEPRECATED(setdomainname);
PROTO_NORMAL(setegid);
PROTO_NORMAL(seteuid);
@@ -165,7 +165,7 @@ PROTO_DEPRECATED(ualarm);
PROTO_NORMAL(unlink);
PROTO_NORMAL(unlinkat);
PROTO_DEPRECATED(usleep);
-/*PROTO_WRAP(vfork);*/
-/*PROTO_CANCEL(write);*/
+PROTO_WRAP(vfork);
+PROTO_CANCEL(write);
#endif /* !_LIBC_UNISTD_H_ */
diff --git a/lib/libc/include/cancel.h b/lib/libc/include/cancel.h
new file mode 100644
index 00000000000..4f4add471b7
--- /dev/null
+++ b/lib/libc/include/cancel.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: cancel.h,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.
+ */
+
+#ifndef _CANCEL_H_
+#define _CANCEL_H_
+
+#include <tib.h>
+#include "thread_private.h"
+
+__BEGIN_HIDDEN_DECLS
+/* process a cancel request at a cancel point */
+__dead void _thread_canceled(void);
+__END_HIDDEN_DECLS
+
+#ifdef LIBC
+/*
+ * Redirect macros that would use the syscall to instead use our callback
+ */
+#define __get_tcb() _thread_cb.tc_tcb()
+#endif
+
+#define PREP_CANCEL_POINT(tib) \
+ int _cantcancel = (tib)->tib_cantcancel
+
+#define ENTER_CANCEL_POINT_INNER(tib, can_cancel, delay) \
+ if (_cantcancel == 0) { \
+ (tib)->tib_cancel_point = (delay) ? \
+ CANCEL_POINT_DELAYED : CANCEL_POINT; \
+ if (can_cancel) { \
+ __asm volatile("":::"memory"); \
+ if (__predict_false((tib)->tib_canceled)) \
+ _thread_canceled(); \
+ } \
+ }
+
+#define LEAVE_CANCEL_POINT_INNER(tib, can_cancel) \
+ if (_cantcancel == 0) { \
+ (tib)->tib_cancel_point = 0; \
+ if (can_cancel) { \
+ __asm volatile("":::"memory"); \
+ if (__predict_false((tib)->tib_canceled)) \
+ _thread_canceled(); \
+ } \
+ }
+
+/*
+ * Enter or leave a cancelation point, optionally processing pending
+ * cancelation requests. Note that ENTER_CANCEL_POINT opens a block
+ * and LEAVE_CANCEL_POINT must close that same block.
+ */
+#define ENTER_CANCEL_POINT(can_cancel) \
+ { \
+ struct tib *_tib = TIB_GET(); \
+ PREP_CANCEL_POINT(_tib); \
+ ENTER_CANCEL_POINT_INNER(_tib, can_cancel, 0)
+
+#define LEAVE_CANCEL_POINT(can_cancel) \
+ LEAVE_CANCEL_POINT_INNER(_tib, can_cancel); \
+ }
+
+#endif /* _CANCEL_H_ */
diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h
index 16d524f666f..980c1a8dd61 100644
--- a/lib/libc/include/namespace.h
+++ b/lib/libc/include/namespace.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: namespace.h,v 1.9 2016/04/05 04:28:32 guenther Exp $ */
+/* $OpenBSD: namespace.h,v 1.10 2016/05/07 19:05:22 guenther Exp $ */
#ifndef _LIBC_NAMESPACE_H_
#define _LIBC_NAMESPACE_H_
@@ -139,12 +139,14 @@
#define CANCEL(x) _libc_##x##_cancel
#define WRAP(x) _libc_##x##_wrap
#define HIDDEN_STRING(x) "_libc_" __STRING(x)
+#define CANCEL_STRING(x) "_libc_" __STRING(x) "_cancel"
#define WRAP_STRING(x) "_libc_" __STRING(x) "_wrap"
#define PROTO_NORMAL(x) __dso_hidden typeof(x) x asm(HIDDEN_STRING(x))
#define PROTO_STD_DEPRECATED(x) typeof(x) x __attribute__((deprecated))
#define PROTO_DEPRECATED(x) typeof(x) x __attribute__((deprecated, weak))
-#define PROTO_CANCEL(x) PROTO_NORMAL(x), CANCEL(x)
+#define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \
+ x asm(CANCEL_STRING(x))
#define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x)
#define DEF_STRONG(x) __strong_alias(x, HIDDEN(x))
diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h
index 43ebf7d96e8..c2e0cf0b3fd 100644
--- a/lib/libc/include/thread_private.h
+++ b/lib/libc/include/thread_private.h
@@ -1,52 +1,108 @@
-/* $OpenBSD: thread_private.h,v 1.26 2015/04/07 01:27:07 guenther Exp $ */
+/* $OpenBSD: thread_private.h,v 1.27 2016/05/07 19:05:22 guenther Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
#ifndef _THREAD_PRIVATE_H_
#define _THREAD_PRIVATE_H_
-/*
- * This file defines the thread library interface to libc. Thread
- * libraries must implement the functions described here for proper
- * inter-operation with libc. libc contains weak versions of the
- * described functions for operation in a non-threaded environment.
- */
+#include <stdio.h> /* for FILE and __isthreaded */
/*
- * This variable is 0 until a second thread is created.
+ * The callbacks needed by libc to handle the threaded case.
+ * NOTE: Bump the version when you change the struct contents!
+ *
+ * tc_canceled:
+ * If not NULL, what to do when canceled (otherwise _exit(0))
+ *
+ * tc_flockfile, tc_ftrylockfile, and tc_funlockfile:
+ * If not NULL, these implement the flockfile() family.
+ * XXX In theory, you should be able to lock a FILE before
+ * XXX loading libpthread and have that be a real lock on it,
+ * XXX but that doesn't work without the libc base version
+ * XXX tracking the recursion count.
+ *
+ * tc_malloc_lock and tc_malloc_unlock:
+ * tc_atexit_lock and tc_atexit_unlock:
+ * tc_atfork_lock and tc_atfork_unlock:
+ * tc_arc4_lock and tc_arc4_unlock:
+ * The locks used by the malloc, atexit, atfork, and arc4 subsystems.
+ * These have to be ordered specially in the fork/vfork wrappers
+ * and may be implemented differently than the general mutexes
+ * in the callbacks below.
+ *
+ * tc_mutex_lock and tc_mutex_unlock:
+ * Lock and unlock the given mutex. If the given mutex is NULL
+ * a mutex is allocated and initialized automatically.
+ *
+ * tc_mutex_destroy:
+ * Destroy/deallocate the given mutex.
+ *
+ * tc_tag_lock and tc_tag_unlock:
+ * Lock and unlock the mutex associated with the given tag.
+ * If the given tag is NULL a tag is allocated and initialized
+ * automatically.
+ *
+ * tc_tag_storage:
+ * Returns a pointer to per-thread instance of data associated
+ * with the given tag. If the given tag is NULL a tag is
+ * allocated and initialized automatically.
+ *
+ * tc_fork, tc_vfork:
+ * If not NULL, they are called instead of the syscall stub, so that
+ * the thread library can do necessary locking and reinitialization.
+ *
+ *
+ * If <machine/tcb.h> doesn't define TCB_GET(), then locating the TCB in a
+ * threaded process requires a syscall (__get_tcb(2)) which is too much
+ * overhead for single-threaded processes. For those archs, there are two
+ * additional callbacks, though they are placed first in the struct for
+ * convenience in ASM:
+ *
+ * tc_errnoptr:
+ * Returns the address of the thread's errno.
+ *
+ * tc_tcb:
+ * Returns the address of the thread's TCB.
*/
-extern int __isthreaded;
+struct thread_callbacks {
+ int *(*tc_errnoptr)(void); /* MUST BE FIRST */
+ void *(*tc_tcb)(void);
+ __dead void (*tc_canceled)(void);
+ void (*tc_flockfile)(FILE *);
+ int (*tc_ftrylockfile)(FILE *);
+ void (*tc_funlockfile)(FILE *);
+ void (*tc_malloc_lock)(void);
+ void (*tc_malloc_unlock)(void);
+ void (*tc_atexit_lock)(void);
+ void (*tc_atexit_unlock)(void);
+ void (*tc_atfork_lock)(void);
+ void (*tc_atfork_unlock)(void);
+ void (*tc_arc4_lock)(void);
+ void (*tc_arc4_unlock)(void);
+ void (*tc_mutex_lock)(void **);
+ void (*tc_mutex_unlock)(void **);
+ void (*tc_mutex_destroy)(void **);
+ void (*tc_tag_lock)(void **);
+ void (*tc_tag_unlock)(void **);
+ void *(*tc_tag_storage)(void **, void *, size_t, void *);
+ __pid_t (*tc_fork)(void);
+ __pid_t (*tc_vfork)(void);
+};
+
+__BEGIN_PUBLIC_DECLS
/*
- * Weak symbols are used in libc so that the thread library can
- * efficiently wrap libc functions.
- *
- * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n),
- * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n,
- * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n).
+ * Set the callbacks used by libc
*/
-#define WEAK_NAME(name) __CONCAT(_weak_,name)
-#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name))
-#ifdef __GNUC__
-#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name)
-#else
-#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */
-#endif
+void _thread_set_callbacks(const struct thread_callbacks *_cb, size_t _len);
+__END_PUBLIC_DECLS
-/*
- * Ditto for hand-written syscall stubs:
- *
- * Use STUB_NAME(n) to get the strong name of the stub: _thread_sys_n
- * STUB_ALIAS(n) to generate the weak symbol n pointing to _thread_sys_n,
- * STUB_PROTOTYPE(n) to generate a prototype for _thread_sys_n (based on n).
- */
-#define STUB_NAME(name) __CONCAT(_thread_sys_,name)
-#define STUB_ALIAS(name) __weak_alias(name, STUB_NAME(name))
-#ifdef __GNUC__
-#define STUB_PROTOTYPE(name) __typeof__(name) STUB_NAME(name)
-#else
-#define STUB_PROTOTYPE(name) /* typeof() only in gcc */
-#endif
+#ifdef __LIBC__
+__BEGIN_HIDDEN_DECLS
+/* the current set */
+extern struct thread_callbacks _thread_cb;
+__END_HIDDEN_DECLS
+#endif /* __LIBC__ */
/*
* helper macro to make unique names in the thread namespace
@@ -54,39 +110,11 @@ extern int __isthreaded;
#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name)
/*
- * helper functions that exist as (weak) null functions in libc and
- * (strong) functions in the thread library. These functions:
- *
- * _thread_tag_lock:
- * lock the mutex associated with the given tag. If the given
- * tag is NULL a tag is first allocated.
- *
- * _thread_tag_unlock:
- * unlock the mutex associated with the given tag. If the given
- * tag is NULL a tag is first allocated.
- *
- * _thread_tag_storage:
- * return a pointer to per thread instance of data associated
- * with the given tag. If the given tag is NULL a tag is first
- * allocated.
- *
- * _thread_mutex_lock:
- * lock the given mutex. If the given mutex is NULL,
- * rely on rthreads/pthreads implementation to initialize
- * the mutex before locking.
- *
- * _thread_mutex_unlock:
- * unlock the given mutex.
- *
- * _thread_mutex_destroy:
- * destroy the given mutex.
+ * Resolver code is special cased in that it uses global keys.
*/
-void _thread_tag_lock(void **);
-void _thread_tag_unlock(void **);
-void *_thread_tag_storage(void **, void *, size_t, void *);
-void _thread_mutex_lock(void **);
-void _thread_mutex_unlock(void **);
-void _thread_mutex_destroy(void **);
+extern void *__THREAD_NAME(_res);
+extern void *__THREAD_NAME(_res_ext);
+extern void *__THREAD_NAME(serv_mutex);
/*
* Macros used in libc to access thread mutex, keys, and per thread storage.
@@ -99,13 +127,40 @@ void _thread_mutex_destroy(void **);
static void *__THREAD_NAME(name)
#define _THREAD_PRIVATE_MUTEX(name) \
static void *__THREAD_NAME(name)
+
+
+#ifndef __LIBC__ /* building some sort of reach around */
+
+#define _THREAD_PRIVATE_MUTEX_LOCK(name) do {} while (0)
+#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) do {} while (0)
+#define _THREAD_PRIVATE(keyname, storage, error) &(storage)
+#define _MUTEX_LOCK(mutex) do {} while (0)
+#define _MUTEX_UNLOCK(mutex) do {} while (0)
+#define _MUTEX_DESTROY(mutex) do {} while (0)
+#define _MALLOC_LOCK() do {} while (0)
+#define _MALLOC_UNLOCK() do {} while (0)
+#define _ATEXIT_LOCK() do {} while (0)
+#define _ATEXIT_UNLOCK() do {} while (0)
+#define _ATFORK_LOCK() do {} while (0)
+#define _ATFORK_UNLOCK() do {} while (0)
+#define _ARC4_LOCK() do {} while (0)
+#define _ARC4_UNLOCK() do {} while (0)
+
+#else /* building libc */
#define _THREAD_PRIVATE_MUTEX_LOCK(name) \
- _thread_tag_lock(&(__THREAD_NAME(name)))
+ do { \
+ if (_thread_cb.tc_tag_lock != NULL) \
+ _thread_cb.tc_tag_lock(&(__THREAD_NAME(name))); \
+ } while (0)
#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
- _thread_tag_unlock(&(__THREAD_NAME(name)))
+ do { \
+ if (_thread_cb.tc_tag_unlock != NULL) \
+ _thread_cb.tc_tag_unlock(&(__THREAD_NAME(name))); \
+ } while (0)
#define _THREAD_PRIVATE(keyname, storage, error) \
- _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \
- sizeof (storage), error)
+ (_thread_cb.tc_tag_storage == NULL ? &(storage) : \
+ _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \
+ &(storage), sizeof(storage), error))
/*
* Macros used in libc to access mutexes.
@@ -113,80 +168,65 @@ void _thread_mutex_destroy(void **);
#define _MUTEX_LOCK(mutex) \
do { \
if (__isthreaded) \
- _thread_mutex_lock(mutex); \
+ _thread_cb.tc_mutex_lock(mutex); \
} while (0)
#define _MUTEX_UNLOCK(mutex) \
do { \
if (__isthreaded) \
- _thread_mutex_unlock(mutex); \
+ _thread_cb.tc_mutex_unlock(mutex); \
} while (0)
#define _MUTEX_DESTROY(mutex) \
do { \
if (__isthreaded) \
- _thread_mutex_destroy(mutex); \
+ _thread_cb.tc_mutex_destroy(mutex); \
} while (0)
/*
- * Resolver code is special cased in that it uses global keys.
- */
-extern void *__THREAD_NAME(_res);
-extern void *__THREAD_NAME(_res_ext);
-extern void *__THREAD_NAME(serv_mutex);
-
-/*
* malloc lock/unlock prototypes and definitions
*/
-void _thread_malloc_lock(void);
-void _thread_malloc_unlock(void);
-
-#define _MALLOC_LOCK() do { \
- if (__isthreaded) \
- _thread_malloc_lock(); \
- } while (0)
-#define _MALLOC_UNLOCK() do { \
- if (__isthreaded) \
- _thread_malloc_unlock();\
- } while (0)
-
-void _thread_atexit_lock(void);
-void _thread_atexit_unlock(void);
-
-#define _ATEXIT_LOCK() do { \
- if (__isthreaded) \
- _thread_atexit_lock(); \
- } while (0)
-#define _ATEXIT_UNLOCK() do { \
- if (__isthreaded) \
- _thread_atexit_unlock();\
- } while (0)
-
-void _thread_atfork_lock(void);
-void _thread_atfork_unlock(void);
-
-#define _ATFORK_LOCK() do { \
- if (__isthreaded) \
- _thread_atfork_lock(); \
- } while (0)
-#define _ATFORK_UNLOCK() do { \
- if (__isthreaded) \
- _thread_atfork_unlock();\
- } while (0)
-
-void _thread_arc4_lock(void);
-void _thread_arc4_unlock(void);
-
-#define _ARC4_LOCK() do { \
- if (__isthreaded) \
- _thread_arc4_lock(); \
- } while (0)
-#define _ARC4_UNLOCK() do { \
- if (__isthreaded) \
- _thread_arc4_unlock();\
- } while (0)
+#define _MALLOC_LOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_malloc_lock(); \
+ } while (0)
+#define _MALLOC_UNLOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_malloc_unlock(); \
+ } while (0)
-/*
- * Wrapper for _thread_sys_fork()
- */
-pid_t _thread_fork(void);
+#define _ATEXIT_LOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_atexit_lock(); \
+ } while (0)
+#define _ATEXIT_UNLOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_atexit_unlock(); \
+ } while (0)
+
+#define _ATFORK_LOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_atfork_lock(); \
+ } while (0)
+#define _ATFORK_UNLOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_atfork_unlock(); \
+ } while (0)
+
+#define _ARC4_LOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_arc4_lock(); \
+ } while (0)
+#define _ARC4_UNLOCK() \
+ do { \
+ if (__isthreaded) \
+ _thread_cb.tc_arc4_unlock(); \
+ } while (0)
+#endif /* __LIBC__ */
#endif /* _THREAD_PRIVATE_H_ */
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 4e98453d062..6e2036560cb 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
-major=86
+major=87
minor=0
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then librthread/shlib_version also be updated.
diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c
index 5ffcae57609..88d90b8e4b1 100644
--- a/lib/libc/stdio/flockfile.c
+++ b/lib/libc/stdio/flockfile.c
@@ -1,41 +1,29 @@
-/* $OpenBSD: flockfile.c,v 1.8 2012/09/01 01:08:16 fgsch Exp $ */
+/* $OpenBSD: flockfile.c,v 1.9 2016/05/07 19:05:22 guenther Exp $ */
-#include <sys/time.h>
#include <stdio.h>
-#include "thread_private.h"
-
-/*
- * Subroutine versions of the macros in <stdio.h>
- * Note that these are all no-ops because libc does not do threads.
- * Strong implementation of file locking in librthread/rthread_file.c
- */
-
-#undef flockfile
-#undef ftrylockfile
-#undef funlockfile
-
-WEAK_PROTOTYPE(flockfile);
-WEAK_PROTOTYPE(ftrylockfile);
-WEAK_PROTOTYPE(funlockfile);
-
-WEAK_ALIAS(flockfile);
-WEAK_ALIAS(ftrylockfile);
-WEAK_ALIAS(funlockfile);
+#include "local.h"
void
-WEAK_NAME(flockfile)(FILE * fp)
+flockfile(FILE *fp)
{
+ FLOCKFILE(fp);
}
+DEF_WEAK(flockfile);
int
-WEAK_NAME(ftrylockfile)(FILE *fp)
+ftrylockfile(FILE *fp)
{
+ if (_thread_cb.tc_ftrylockfile != NULL)
+ return (_thread_cb.tc_ftrylockfile(fp));
return 0;
}
+DEF_WEAK(ftrylockfile);
void
-WEAK_NAME(funlockfile)(FILE * fp)
+funlockfile(FILE *fp)
{
+ FUNLOCKFILE(fp);
}
+DEF_WEAK(funlockfile);
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index 94b2804ff18..ad888b0fd50 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: local.h,v 1.23 2015/10/25 18:01:24 guenther Exp $ */
+/* $OpenBSD: local.h,v 1.24 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -40,6 +40,7 @@
#include <wchar.h>
#include "wcio.h"
#include "fileext.h"
+#include "thread_private.h"
void _cleanup(void);
int _fwalk(int (*)(FILE *));
@@ -96,5 +97,13 @@ __END_HIDDEN_DECLS
(fp)->_lb._base = NULL; \
}
-#define FLOCKFILE(fp) do { if (__isthreaded) flockfile(fp); } while (0)
-#define FUNLOCKFILE(fp) do { if (__isthreaded) funlockfile(fp); } while (0)
+#define FLOCKFILE(fp) \
+ do { \
+ if (_thread_cb.tc_flockfile != NULL) \
+ _thread_cb.tc_flockfile(fp); \
+ } while (0)
+#define FUNLOCKFILE(fp) \
+ do { \
+ if (_thread_cb.tc_funlockfile != NULL) \
+ _thread_cb.tc_funlockfile(fp); \
+ } while (0)
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/thread/unithread_mutex.c b/lib/libc/sys/w_vfork.c
index 44009de7c01..9716f57ec6b 100644
--- a/lib/libc/thread/unithread_mutex.c
+++ b/lib/libc/sys/w_vfork.c
@@ -1,7 +1,6 @@
-/* $OpenBSD: unithread_mutex.c,v 1.1 2007/06/05 18:11:48 kurt Exp $ */
-
+/* $OpenBSD: w_vfork.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
/*
- * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org>
+ * 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
@@ -16,34 +15,20 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
+#include <tib.h>
+#include <unistd.h>
#include "thread_private.h"
-WEAK_PROTOTYPE(_thread_mutex_lock);
-WEAK_PROTOTYPE(_thread_mutex_unlock);
-WEAK_PROTOTYPE(_thread_mutex_destroy);
-
-WEAK_ALIAS(_thread_mutex_lock);
-WEAK_ALIAS(_thread_mutex_unlock);
-WEAK_ALIAS(_thread_mutex_destroy);
-
-/* ARGSUSED */
-void
-WEAK_NAME(_thread_mutex_lock)(void **mutex)
-{
- return;
-}
-
-/* ARGSUSED */
-void
-WEAK_NAME(_thread_mutex_unlock)(void **mutex)
+pid_t
+WRAP(vfork)(void)
{
- return;
-}
+ pid_t newid;
-/* ARGSUSED */
-void
-WEAK_NAME(_thread_mutex_destroy)(void **mutex)
-{
- return;
+ 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);
diff --git a/lib/libc/termios/tcdrain.c b/lib/libc/termios/tcdrain.c
index ac74b496fa8..f9ff00cb2ba 100644
--- a/lib/libc/termios/tcdrain.c
+++ b/lib/libc/termios/tcdrain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcdrain.c,v 1.5 2005/08/05 13:03:00 espie Exp $ */
+/* $OpenBSD: tcdrain.c,v 1.6 2016/05/07 19:05:22 guenther Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,8 +31,15 @@
#include <sys/ioctl.h>
#include <termios.h>
+#include "cancel.h"
+
int
tcdrain(int fd)
{
- return (ioctl(fd, TIOCDRAIN, 0));
+ int ret;
+
+ ENTER_CANCEL_POINT(1);
+ ret = ioctl(fd, TIOCDRAIN, 0);
+ LEAVE_CANCEL_POINT(ret == -1);
+ return (ret);
}
diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc
index b5d3cb147dc..8c0cecf92d7 100644
--- a/lib/libc/thread/Makefile.inc
+++ b/lib/libc/thread/Makefile.inc
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.9 2015/04/07 01:27:07 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2016/05/07 19:05:22 guenther Exp $
.PATH: ${LIBCSRCDIR}/thread
-SRCS+= unithread_malloc_lock.c unithread_mutex.c unithread_tag.c atfork.c
+SRCS+= callbacks.c atfork.c
diff --git a/lib/libc/thread/callbacks.c b/lib/libc/thread/callbacks.c
new file mode 100644
index 00000000000..c57a931b08c
--- /dev/null
+++ b/lib/libc/thread/callbacks.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014 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 <stdio.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include "thread_private.h"
+
+void
+_thread_set_callbacks(const struct thread_callbacks *cb, size_t len)
+{
+ sigset_t allmask, omask;
+
+ if (sizeof(*cb) != len) {
+ fprintf(stderr, "library mismatch: libc expected %z but"
+ " libpthread gave %z\n", sizeof(*cb), len);
+ fflush(stderr);
+ _exit(44);
+ }
+
+ sigfillset(&allmask);
+ if (sigprocmask(SIG_BLOCK, &allmask, &omask) == 0) {
+ /* mprotect RW */
+ memcpy(&_thread_cb, cb, sizeof(_thread_cb));
+ /* mprotect RO | LOCKPERM | NOUNMAP */
+ sigprocmask(SIG_SETMASK, &omask, NULL);
+ }
+}
diff --git a/lib/libc/thread/unithread_malloc_lock.c b/lib/libc/thread/unithread_malloc_lock.c
deleted file mode 100644
index d813bc708f2..00000000000
--- a/lib/libc/thread/unithread_malloc_lock.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* $OpenBSD: unithread_malloc_lock.c,v 1.9 2015/04/07 01:27:07 guenther Exp $ */
-
-#include <sys/time.h>
-#include "thread_private.h"
-
-WEAK_PROTOTYPE(_thread_malloc_lock);
-WEAK_PROTOTYPE(_thread_malloc_unlock);
-
-WEAK_ALIAS(_thread_malloc_lock);
-WEAK_ALIAS(_thread_malloc_unlock);
-
-WEAK_PROTOTYPE(_thread_atexit_lock);
-WEAK_PROTOTYPE(_thread_atexit_unlock);
-
-WEAK_ALIAS(_thread_atexit_lock);
-WEAK_ALIAS(_thread_atexit_unlock);
-
-WEAK_PROTOTYPE(_thread_atfork_lock);
-WEAK_PROTOTYPE(_thread_atfork_unlock);
-
-WEAK_ALIAS(_thread_atfork_lock);
-WEAK_ALIAS(_thread_atfork_unlock);
-
-WEAK_PROTOTYPE(_thread_arc4_lock);
-WEAK_PROTOTYPE(_thread_arc4_unlock);
-
-WEAK_ALIAS(_thread_arc4_lock);
-WEAK_ALIAS(_thread_arc4_unlock);
-
-void
-WEAK_NAME(_thread_malloc_lock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_malloc_unlock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_atexit_lock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_atexit_unlock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_atfork_lock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_atfork_unlock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_arc4_lock)(void)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_arc4_unlock)(void)
-{
- return;
-}
diff --git a/lib/libc/thread/unithread_tag.c b/lib/libc/thread/unithread_tag.c
deleted file mode 100644
index c7ac928b994..00000000000
--- a/lib/libc/thread/unithread_tag.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* $OpenBSD: unithread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */
-
-/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
-
-#include <sys/time.h>
-#include "thread_private.h"
-
-WEAK_PROTOTYPE(_thread_tag_lock);
-WEAK_PROTOTYPE(_thread_tag_unlock);
-WEAK_PROTOTYPE(_thread_tag_storage);
-
-WEAK_ALIAS(_thread_tag_lock);
-WEAK_ALIAS(_thread_tag_unlock);
-WEAK_ALIAS(_thread_tag_storage);
-
-void
-WEAK_NAME(_thread_tag_lock)(void **tag)
-{
- return;
-}
-
-void
-WEAK_NAME(_thread_tag_unlock)(void **tag)
-{
- return;
-}
-
-void *
-WEAK_NAME(_thread_tag_storage)(void **tag, void *init, size_t initsz, void *err)
-{
- return init;
-}