diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-05-07 19:05:25 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-05-07 19:05:25 +0000 |
commit | be4e94637d7117375492627b79c41629c7da9bc3 (patch) | |
tree | 61a9fabcc07d38d2720bbb937e83103928286550 | |
parent | 33d8693716b4a6d503e0ba97f94a783905b87f28 (diff) |
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread
and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable!
Make libpthread dlopen'able by moving the cancelation wrappers into libc
and doing locking and fork/errno handling via callbacks that libpthread
registers when it first initializes. 'errno' *must* be declared via
<errno.h> now!
Clean up libpthread's symbol exports like libc.
On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec.
Testing by various, particularly sthen@ and patrick@
ok kettenis@
228 files changed, 3119 insertions, 3402 deletions
diff --git a/distrib/sets/lists/base/md.alpha b/distrib/sets/lists/base/md.alpha index 0fef6889948..b34ff8a05b5 100644 --- a/distrib/sets/lists/base/md.alpha +++ b/distrib/sets/lists/base/md.alpha @@ -2042,6 +2042,7 @@ ./usr/libdata/perl5/site_perl/alpha-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/alpha-openbsd/termios.ph ./usr/libdata/perl5/site_perl/alpha-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/alpha-openbsd/tib.ph ./usr/libdata/perl5/site_perl/alpha-openbsd/time.ph ./usr/libdata/perl5/site_perl/alpha-openbsd/tls.ph ./usr/libdata/perl5/site_perl/alpha-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.amd64 b/distrib/sets/lists/base/md.amd64 index e387aa63ff3..76d2a9cbc71 100644 --- a/distrib/sets/lists/base/md.amd64 +++ b/distrib/sets/lists/base/md.amd64 @@ -2076,6 +2076,7 @@ ./usr/libdata/perl5/site_perl/amd64-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/amd64-openbsd/termios.ph ./usr/libdata/perl5/site_perl/amd64-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/amd64-openbsd/tib.ph ./usr/libdata/perl5/site_perl/amd64-openbsd/time.ph ./usr/libdata/perl5/site_perl/amd64-openbsd/tls.ph ./usr/libdata/perl5/site_perl/amd64-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.armish b/distrib/sets/lists/base/md.armish index 169d5d617b3..dd8ee579129 100644 --- a/distrib/sets/lists/base/md.armish +++ b/distrib/sets/lists/base/md.armish @@ -2058,6 +2058,7 @@ ./usr/libdata/perl5/site_perl/arm-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/arm-openbsd/termios.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/arm-openbsd/tib.ph ./usr/libdata/perl5/site_perl/arm-openbsd/time.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tls.ph ./usr/libdata/perl5/site_perl/arm-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.armv7 b/distrib/sets/lists/base/md.armv7 index 8233e3597aa..eed9a4e8468 100644 --- a/distrib/sets/lists/base/md.armv7 +++ b/distrib/sets/lists/base/md.armv7 @@ -2058,6 +2058,7 @@ ./usr/libdata/perl5/site_perl/arm-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/arm-openbsd/termios.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/arm-openbsd/tib.ph ./usr/libdata/perl5/site_perl/arm-openbsd/time.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tls.ph ./usr/libdata/perl5/site_perl/arm-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.hppa b/distrib/sets/lists/base/md.hppa index 91a8fe70aaf..b9256cbc3c9 100644 --- a/distrib/sets/lists/base/md.hppa +++ b/distrib/sets/lists/base/md.hppa @@ -2044,6 +2044,7 @@ ./usr/libdata/perl5/site_perl/hppa-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/hppa-openbsd/termios.ph ./usr/libdata/perl5/site_perl/hppa-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/hppa-openbsd/tib.ph ./usr/libdata/perl5/site_perl/hppa-openbsd/time.ph ./usr/libdata/perl5/site_perl/hppa-openbsd/tls.ph ./usr/libdata/perl5/site_perl/hppa-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.hppa64 b/distrib/sets/lists/base/md.hppa64 index ca17f432eb6..84093b0e0dd 100644 --- a/distrib/sets/lists/base/md.hppa64 +++ b/distrib/sets/lists/base/md.hppa64 @@ -1971,6 +1971,7 @@ ./usr/libdata/perl5/site_perl/hppa64-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/hppa64-openbsd/termios.ph ./usr/libdata/perl5/site_perl/hppa64-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/hppa64-openbsd/tib.ph ./usr/libdata/perl5/site_perl/hppa64-openbsd/time.ph ./usr/libdata/perl5/site_perl/hppa64-openbsd/tls.ph ./usr/libdata/perl5/site_perl/hppa64-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.i386 b/distrib/sets/lists/base/md.i386 index db57c19b4bd..1cc1047df79 100644 --- a/distrib/sets/lists/base/md.i386 +++ b/distrib/sets/lists/base/md.i386 @@ -2079,6 +2079,7 @@ ./usr/libdata/perl5/site_perl/i386-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/i386-openbsd/termios.ph ./usr/libdata/perl5/site_perl/i386-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/i386-openbsd/tib.ph ./usr/libdata/perl5/site_perl/i386-openbsd/time.ph ./usr/libdata/perl5/site_perl/i386-openbsd/tls.ph ./usr/libdata/perl5/site_perl/i386-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.landisk b/distrib/sets/lists/base/md.landisk index ce2f341526a..e13ecc10a9e 100644 --- a/distrib/sets/lists/base/md.landisk +++ b/distrib/sets/lists/base/md.landisk @@ -2057,6 +2057,7 @@ ./usr/libdata/perl5/site_perl/sh-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/sh-openbsd/termios.ph ./usr/libdata/perl5/site_perl/sh-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/sh-openbsd/tib.ph ./usr/libdata/perl5/site_perl/sh-openbsd/time.ph ./usr/libdata/perl5/site_perl/sh-openbsd/tls.ph ./usr/libdata/perl5/site_perl/sh-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.loongson b/distrib/sets/lists/base/md.loongson index ee015dabc67..a32e324e04d 100644 --- a/distrib/sets/lists/base/md.loongson +++ b/distrib/sets/lists/base/md.loongson @@ -2064,6 +2064,7 @@ ./usr/libdata/perl5/site_perl/mips64el-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/mips64el-openbsd/termios.ph ./usr/libdata/perl5/site_perl/mips64el-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/mips64el-openbsd/tib.ph ./usr/libdata/perl5/site_perl/mips64el-openbsd/time.ph ./usr/libdata/perl5/site_perl/mips64el-openbsd/tls.ph ./usr/libdata/perl5/site_perl/mips64el-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.luna88k b/distrib/sets/lists/base/md.luna88k index 4d79ce71bb9..fda5ba3c1f3 100644 --- a/distrib/sets/lists/base/md.luna88k +++ b/distrib/sets/lists/base/md.luna88k @@ -1954,6 +1954,7 @@ ./usr/libdata/perl5/site_perl/m88k-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/m88k-openbsd/termios.ph ./usr/libdata/perl5/site_perl/m88k-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/m88k-openbsd/tib.ph ./usr/libdata/perl5/site_perl/m88k-openbsd/time.ph ./usr/libdata/perl5/site_perl/m88k-openbsd/tls.ph ./usr/libdata/perl5/site_perl/m88k-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.macppc b/distrib/sets/lists/base/md.macppc index cdbc6a251f1..e69370bdb64 100644 --- a/distrib/sets/lists/base/md.macppc +++ b/distrib/sets/lists/base/md.macppc @@ -2089,6 +2089,7 @@ ./usr/libdata/perl5/site_perl/powerpc-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/termios.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/powerpc-openbsd/tib.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/time.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/tls.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.octeon b/distrib/sets/lists/base/md.octeon index ecbf7f07ab9..eb17af53da2 100644 --- a/distrib/sets/lists/base/md.octeon +++ b/distrib/sets/lists/base/md.octeon @@ -2027,6 +2027,7 @@ ./usr/libdata/perl5/site_perl/mips64-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/termios.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/mips64-openbsd/tib.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/time.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/tls.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.sgi b/distrib/sets/lists/base/md.sgi index 15a50360040..b21fb2ab811 100644 --- a/distrib/sets/lists/base/md.sgi +++ b/distrib/sets/lists/base/md.sgi @@ -2091,6 +2091,7 @@ ./usr/libdata/perl5/site_perl/mips64-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/termios.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/mips64-openbsd/tib.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/time.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/tls.ph ./usr/libdata/perl5/site_perl/mips64-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.socppc b/distrib/sets/lists/base/md.socppc index e8530eadc31..d2a80dac4ef 100644 --- a/distrib/sets/lists/base/md.socppc +++ b/distrib/sets/lists/base/md.socppc @@ -2076,6 +2076,7 @@ ./usr/libdata/perl5/site_perl/powerpc-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/termios.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/powerpc-openbsd/tib.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/time.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/tls.ph ./usr/libdata/perl5/site_perl/powerpc-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.sparc b/distrib/sets/lists/base/md.sparc index bd8b193ba73..11ef7de0005 100644 --- a/distrib/sets/lists/base/md.sparc +++ b/distrib/sets/lists/base/md.sparc @@ -1591,6 +1591,7 @@ ./usr/libdata/perl5/site_perl/sparc-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/sparc-openbsd/termios.ph ./usr/libdata/perl5/site_perl/sparc-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/sparc-openbsd/tib.ph ./usr/libdata/perl5/site_perl/sparc-openbsd/time.ph ./usr/libdata/perl5/site_perl/sparc-openbsd/tls.ph ./usr/libdata/perl5/site_perl/sparc-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.sparc64 b/distrib/sets/lists/base/md.sparc64 index a46820df03c..126b8a958cf 100644 --- a/distrib/sets/lists/base/md.sparc64 +++ b/distrib/sets/lists/base/md.sparc64 @@ -1651,6 +1651,7 @@ ./usr/libdata/perl5/site_perl/sparc64-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/sparc64-openbsd/termios.ph ./usr/libdata/perl5/site_perl/sparc64-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/sparc64-openbsd/tib.ph ./usr/libdata/perl5/site_perl/sparc64-openbsd/time.ph ./usr/libdata/perl5/site_perl/sparc64-openbsd/tls.ph ./usr/libdata/perl5/site_perl/sparc64-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/md.zaurus b/distrib/sets/lists/base/md.zaurus index 01067239021..1f43b6df990 100644 --- a/distrib/sets/lists/base/md.zaurus +++ b/distrib/sets/lists/base/md.zaurus @@ -2012,6 +2012,7 @@ ./usr/libdata/perl5/site_perl/arm-openbsd/termcap.ph ./usr/libdata/perl5/site_perl/arm-openbsd/termios.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tgmath.ph +./usr/libdata/perl5/site_perl/arm-openbsd/tib.ph ./usr/libdata/perl5/site_perl/arm-openbsd/time.ph ./usr/libdata/perl5/site_perl/arm-openbsd/tls.ph ./usr/libdata/perl5/site_perl/arm-openbsd/ttyent.ph diff --git a/distrib/sets/lists/base/mi b/distrib/sets/lists/base/mi index 78bb15241ad..3251f28ac0e 100644 --- a/distrib/sets/lists/base/mi +++ b/distrib/sets/lists/base/mi @@ -610,8 +610,8 @@ ./usr/games ./usr/include ./usr/lib -./usr/lib/libc.so.86.0 -./usr/lib/libc.so.86.0.a +./usr/lib/libc.so.87.0 +./usr/lib/libc.so.87.0.a ./usr/lib/libcrypto.so.38.0 ./usr/lib/libcurses.so.14.0 ./usr/lib/libedit.so.5.2 @@ -633,7 +633,7 @@ ./usr/lib/libpanelw.so.6.0 ./usr/lib/libpcap.so.8.1 ./usr/lib/libperl.so.17.1 -./usr/lib/libpthread.so.21.0 +./usr/lib/libpthread.so.22.0 ./usr/lib/libradius.so.1.0 ./usr/lib/libreadline.so.4.0 ./usr/lib/librpcsvc.so.2.0 diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index c1ab44c3f84..86057434657 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -1410,6 +1410,7 @@ ./usr/include/termcap.h ./usr/include/termios.h ./usr/include/tgmath.h +./usr/include/tib.h ./usr/include/time.h ./usr/include/tls.h ./usr/include/ttyent.h diff --git a/distrib/special/libstubs/Makefile b/distrib/special/libstubs/Makefile index 8853173e095..8f07014debc 100644 --- a/distrib/special/libstubs/Makefile +++ b/distrib/special/libstubs/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.17 2015/10/17 21:48:42 guenther Exp $ +# $OpenBSD: Makefile,v 1.18 2016/05/07 19:05:24 guenther Exp $ .include <bsd.own.mk> LIB= stubs @@ -30,7 +30,7 @@ NOPIC= Yes NOPROFILE=Yes CFLAGS+=-DSHA2_SMALL -UYP -DNO_LOG_BAD_DNS_RESPONSES \ - -DFLOATING_POINT -DASRNODEBUG \ + -DFLOATING_POINT -DASRNODEBUG -D__LIBC__ \ -I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/hidden \ -I${LIBCSRCDIR}/asr -I${LIBCSRCDIR}/locale -I${LIBCSRCDIR}/gdtoa \ -I${LIBCSRCDIR}/arch/${MACHINE_CPU}/gdtoa -I${LIBCSRCDIR}/stdio \ diff --git a/include/Makefile b/include/Makefile index 72a1af0d831..b10865bdf30 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.210 2016/03/09 16:28:46 deraadt Exp $ +# $OpenBSD: Makefile,v 1.211 2016/05/07 19:05:21 guenther Exp $ # $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $ # @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91 @@ -18,7 +18,7 @@ FILES= a.out.h ar.h asr.h assert.h bitstring.h blf.h bsd_auth.h \ nlist.h nl_types.h paths.h poll.h pwd.h ranlib.h readpassphrase.h \ regex.h resolv.h rmd160.h search.h setjmp.h sha1.h sha2.h signal.h \ siphash.h sndio.h spawn.h stdbool.h stddef.h stdio.h stdlib.h \ - string.h strings.h struct.h sysexits.h tar.h tgmath.h time.h \ + string.h strings.h struct.h sysexits.h tar.h tgmath.h tib.h time.h \ ttyent.h unistd.h utime.h utmp.h uuid.h vis.h wchar.h wctype.h MFILES= frame.h diff --git a/include/tib.h b/include/tib.h index 74459f9c7dd..7dff1168ec9 100644 --- a/include/tib.h +++ b/include/tib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tib.h,v 1.2 2016/03/20 02:30:28 guenther Exp $ */ +/* $OpenBSD: tib.h,v 1.3 2016/05/07 19:05:21 guenther Exp $ */ /* * Copyright (c) 2011,2014 Philip Guenther <guenther@openbsd.org> * @@ -46,19 +46,13 @@ * TIB_TO_TCB(tib) * Given a TIB pointer, return the matching TCB pointer * - * TIB_INIT(tib, dtv) + * TIB_INIT(tib, dtv, thread) * Initializes a TIB for a new thread, using the supplied - * value for the dtv pointer - * - * TIB_TO_THREAD(tib) - * Given a TIB pointer, return a pointer to the struct pthread + * values for its dtv and thread pointers * * TIB_GET() * Short-hand for TCB_TO_TIB(TCB_GET()) * - * TIB_THREAD() - * Returns a pointer to this thread's struct pthread - * * TIB_EXTRA_ALIGN * On TLS varaint 2 archs, what alignment is sufficient * for the extra space that will be used for struct pthread? @@ -66,24 +60,24 @@ * The following functions are provided by either ld.so (dynamic) or * libc (static) for allocating and freeing a common memory block that * will hold both the TIB and the pthread structure: - * _dl_allocate_tib(sizeof(struct pthread), flags) + * _dl_allocate_tib(sizeof(struct pthread)) * Allocates a combined TIB and pthread memory region. - * The first argument is the amount of space to reserve - * for the pthread structure; the second argument is - * either zero or DAT_UPDATE_CURRENT, the latter meaning - * this call is to update/replace the current thread's - * TIB. Returns a pointer to the TIB inside the - * allocated block. + * The argument is the amount of space to reserve + * for the pthread structure. Returns a pointer to + * the TIB inside the allocated block. * * _dl_free_tib(tib, sizeof(struct pthread)) * Frees a TIB and pthread block previously allocated - * with _dl_allocate_tls(). Must be passed the return + * with _dl_allocate_tib(). Must be passed the return * value of that previous call. */ /* * Regarding <machine/tcb.h>: * - it must define the TLS_VARIANT macro + * - it may define TCB_OFFSET if the TCB address in the kernel and/or + * register is offset from the actual TCB address. TCB_OFFSET > 0 + * means the kernel/register points to *after* the real data. * - if there's a faster way to get or set the TCB pointer for the thread * than the __{get,set}_tcb() syscalls, it should define either or both * the TCB_{GET,SET} macros to do so. @@ -101,6 +95,23 @@ #else # define TCB_SET(tcb) __set_tcb(tcb) #endif +#ifndef TCB_OFFSET +# define TCB_OFFSET 0 +#endif + +/* + * tib_cantcancel values is non-zero is the thread should skip all + * cancellation processing + */ +#define CANCEL_DISABLED 1 +#define CANCEL_DYING 2 + +/* + * tib_cancel_point is non-zero if we're in a cancel point; its modified + * by the cancel point code and read by the cancellation signal handler + */ +#define CANCEL_POINT 1 +#define CANCEL_POINT_DELAYED 2 #if TLS_VARIANT == 1 @@ -108,17 +119,16 @@ * ABI specifies that the static TLS data starts two words after the * (notional) thread pointer, with the first of those two words being * the TLS dtv pointer. The other (second) word is reserved for the - * implementation, so we place the thread's locale there, but we place - * our thread bits before the TCB, at negative offsets from the - * TCB pointer. Ergo, memory is laid out, low to high, as: + * implementation, so we place the pointer to the thread structure there, + * but we place our actual thread bits before the TCB, at negative offsets + * from the TCB pointer. Ergo, memory is laid out, low to high, as: * * [pthread structure] * TIB { - * int cancel_flags - * int cancel_requested + * ...cancelation and other int-sized info... * int errno * void *locale - * TCB { + * TCB (- TCB_OFFSET) { * void *dtv * struct pthread *thread * } @@ -127,21 +137,17 @@ */ struct tib { -#ifdef __LP64__ - int __tib_padding; /* padding for 8byte alignment */ -#endif - int tib_cancel_flags; - int tib_cancel; + int tib_thread_flags; /* internal to libpthread */ + pid_t tib_tid; + int tib_cantcancel; + int tib_cancel_point; + int tib_canceled; int tib_errno; void *tib_locale; void *tib_dtv; /* internal to the runtime linker */ void *tib_thread; }; -#ifdef __LP64__ -# define _TIB_PREP(tib) ((void)((tib)->__tib_padding = 0)) -#endif -#define _TIBO_PTHREAD (- _ALIGN(sizeof(struct pthread))) #elif TLS_VARIANT == 2 /* @@ -152,15 +158,14 @@ struct tib { * out, low to high, as: * static TLS data * TIB { - * TCB { + * TCB (- TCB_OFFSET) { * self pointer [i386/amd64 only] * void *dtv * } * struct pthread *thread * void *locale * int errno - * int cancel_count_flags - * int cancel_requested + * ...cancelation and other int-sized info... * } * [pthread structure] */ @@ -174,19 +179,20 @@ struct tib { void *tib_thread; void *tib_locale; int tib_errno; - int tib_cancel; /* set to request cancelation */ - int tib_cancel_flags; -#if defined(__LP64__) || defined(__i386) + int tib_canceled; + int tib_cancel_point; + int tib_cantcancel; + pid_t tib_tid; + int tib_thread_flags; /* internal to libpthread */ +#if !defined(__LP64__) && !defined(__i386) int __tib_padding; /* padding for 8byte alignment */ #endif }; -#define _TIBO_PTHREAD _ALIGN(sizeof(struct tib)) - #if defined(__i386) || defined(__amd64) # define _TIB_PREP(tib) \ - ((void)((tib)->__tib_self = (tib), (tib)->__tib_padding = 0)) -#elif defined(__LP64__) + ((void)((tib)->__tib_self = (tib))) +#elif !defined(__LP64__) && !defined(__i386) # define _TIB_PREP(tib) ((void)((tib)->__tib_padding = 0)) #endif @@ -204,8 +210,9 @@ struct tib { #define TIB_INIT(tib, dtv, thread) do { \ (tib)->tib_thread = (thread); \ (tib)->tib_locale = NULL; \ - (tib)->tib_cancel_flags = 0; \ - (tib)->tib_cancel = 0; \ + (tib)->tib_cantcancel = 0; \ + (tib)->tib_cancel_point = 0; \ + (tib)->tib_canceled = 0; \ (tib)->tib_dtv = (dtv); \ (tib)->tib_errno = 0; \ _TIB_PREP(tib); \ @@ -214,13 +221,11 @@ struct tib { #ifndef __tib_tcb # define __tib_tcb tib_dtv #endif -#define _TIBO_TCB offsetof(struct tib, __tib_tcb) +#define _TIBO_TCB (offsetof(struct tib, __tib_tcb) + TCB_OFFSET) #define TCB_TO_TIB(tcb) ((struct tib *)((char *)(tcb) - _TIBO_TCB)) #define TIB_TO_TCB(tib) ((char *)(tib) + _TIBO_TCB) -#define TIB_TO_THREAD(tib) ((struct pthread *)(tib)->tib_thread) #define TIB_GET() TCB_TO_TIB(TCB_GET()) -#define TCB_THREAD() TIB_TO_THREAD(TIB_GET()) __BEGIN_DECLS 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/librthread/arch/hppa/cerror.S b/lib/libc/sys/canceled.c index 941651a40ff..7bf02c93552 100644 --- a/lib/librthread/arch/hppa/cerror.S +++ b/lib/libc/sys/canceled.c @@ -1,7 +1,5 @@ -/* $OpenBSD: cerror.S,v 1.2 2013/06/03 04:41:31 miod Exp $ */ - /* - * Copyright (c) 2011 Mark Kettenis + * 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 @@ -16,18 +14,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "SYS.h" - -#define ERRNOPTR_OFFSET 32 +#include <stdlib.h> +#include "cancel.h" -ENTRY(__cerror,0) - mfctl cr27, r1 - ldw 4(r1), r1 - ldw ERRNOPTR_OFFSET(r1), r1 - stw t1, 0(r1) - ldi -1, ret0 - bv r0(rp) - ldi -1, ret1 -EXIT(__cerror) +void +_thread_canceled(void) +{ + if (_thread_cb.tc_canceled != NULL) + _thread_cb.tc_canceled(); + exit(0); +} - .end 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/librthread/arch/hppa64/cerror.S b/lib/libc/sys/w_close.c index a0786cc4d4c..e481c1e11c6 100644 --- a/lib/librthread/arch/hppa64/cerror.S +++ b/lib/libc/sys/w_close.c @@ -1,7 +1,6 @@ -/* $OpenBSD: cerror.S,v 1.2 2013/06/03 04:41:31 miod Exp $ */ - +/* $OpenBSD: w_close.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ /* - * Copyright (c) 2011 Mark Kettenis + * 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,18 +15,17 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "SYS.h" - -#define ERRNOPTR_OFFSET 32 +#include <unistd.h> +#include "cancel.h" -ENTRY(__cerror,0) - mfctl %cr27, %r1 - ldw 4(%r1), %r1 - ldw ERRNOPTR_OFFSET(%r1), %r1 - stw %t1, 0(%r1) - ldi -1, %ret0 - bv %r0(%rp) - ldi -1, %ret1 -EXIT(__cerror) +int +close(int fd) +{ + int ret; - .end + 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; -} diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile index 28d35a0052b..b135df0ece7 100644 --- a/lib/librthread/Makefile +++ b/lib/librthread/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.41 2016/04/02 19:56:53 guenther Exp $ +# $OpenBSD: Makefile,v 1.42 2016/05/07 19:05:22 guenther Exp $ LIB=pthread LIBCSRCDIR= ${.CURDIR}/../libc @@ -9,18 +9,19 @@ CFLAGS+=-Wsign-compare CFLAGS+=-I${.CURDIR} -include namespace.h \ -I${LIBCSRCDIR}/arch/${MACHINE_CPU} -I${LIBCSRCDIR}/include CDIAGFLAGS= -LDADD = -Wl,-znodelete,-zinitfirst,-znodlopen +LDADD = -Wl,-znodelete .if defined(NOPIC) CFLAGS+=-DNO_PIC .endif +VERSION_SCRIPT= ${.CURDIR}/Symbols.map + .PATH: ${.CURDIR}/arch/${MACHINE_CPU} SRCS= rthread.c \ rthread_attr.c \ rthread_barrier.c \ rthread_barrier_attr.c \ - rthread_cancel.c \ rthread_condattr.c \ rthread_debug.c \ rthread_file.c \ @@ -42,7 +43,7 @@ SRCS= rthread.c \ rthread_tls.c \ sched_prio.c -OBJS+= _atomic_lock.o cerror.o +OBJS+= _atomic_lock.o SRCDIR= ${.CURDIR}/../libpthread .include "${SRCDIR}/include/Makefile.inc" diff --git a/lib/librthread/Symbols.map b/lib/librthread/Symbols.map new file mode 100644 index 00000000000..72ed373ae20 --- /dev/null +++ b/lib/librthread/Symbols.map @@ -0,0 +1,146 @@ +{ + global: + /* symbols that no one should be using currently */ + _init; + _fini; + __data_start; + __bss_start; + _edata; + _end; + __end; + _SDA2_BASE; + _SDA_BASE; + + /* needed by ld.so until we switch to RELRO */ + __got_start; + __got_end; + __plt_start; + __plt_end; + + /* pthread implementation */ + pthread_attr_destroy; + pthread_attr_getdetachstate; + pthread_attr_getguardsize; + pthread_attr_getinheritsched; + pthread_attr_getschedparam; + pthread_attr_getschedpolicy; + pthread_attr_getscope; + pthread_attr_getstack; + pthread_attr_getstackaddr; + pthread_attr_getstacksize; + pthread_attr_init; + pthread_attr_setdetachstate; + pthread_attr_setguardsize; + pthread_attr_setinheritsched; + pthread_attr_setschedparam; + pthread_attr_setschedpolicy; + pthread_attr_setscope; + pthread_attr_setstack; + pthread_attr_setstackaddr; + pthread_attr_setstacksize; + pthread_barrier_destroy; + pthread_barrier_init; + pthread_barrier_wait; + pthread_barrierattr_destroy; + pthread_barrierattr_getpshared; + pthread_barrierattr_init; + pthread_barrierattr_setpshared; + pthread_cancel; + pthread_cleanup_pop; + pthread_cleanup_push; + pthread_cond_broadcast; + pthread_cond_destroy; + pthread_cond_init; + pthread_cond_signal; + pthread_cond_timedwait; + pthread_cond_wait; + pthread_condattr_destroy; + pthread_condattr_getclock; + pthread_condattr_init; + pthread_condattr_setclock; + pthread_create; + pthread_detach; + pthread_equal; + pthread_exit; + pthread_getconcurrency; + pthread_getcpuclockid; + pthread_getprio; + pthread_getschedparam; + pthread_getspecific; + pthread_join; + pthread_key_create; + pthread_key_delete; + pthread_kill; + pthread_main_np; + pthread_mutex_destroy; + pthread_mutex_getprioceiling; + pthread_mutex_init; + pthread_mutex_lock; + pthread_mutex_setprioceiling; + pthread_mutex_timedlock; + pthread_mutex_trylock; + pthread_mutex_unlock; + pthread_mutexattr_destroy; + pthread_mutexattr_getkind_np; + pthread_mutexattr_getprioceiling; + pthread_mutexattr_getprotocol; + pthread_mutexattr_gettype; + pthread_mutexattr_init; + pthread_mutexattr_setkind_np; + pthread_mutexattr_setprioceiling; + pthread_mutexattr_setprotocol; + pthread_mutexattr_settype; + pthread_once; + pthread_rwlock_destroy; + pthread_rwlock_init; + pthread_rwlock_rdlock; + pthread_rwlock_timedrdlock; + pthread_rwlock_timedwrlock; + pthread_rwlock_tryrdlock; + pthread_rwlock_trywrlock; + pthread_rwlock_unlock; + pthread_rwlock_wrlock; + pthread_rwlockattr_destroy; + pthread_rwlockattr_getpshared; + pthread_rwlockattr_init; + pthread_rwlockattr_setpshared; + pthread_self; + pthread_set_name_np; + pthread_setcancelstate; + pthread_setcanceltype; + pthread_setconcurrency; + pthread_setprio; + pthread_setschedparam; + pthread_setspecific; + pthread_spin_destroy; + pthread_spin_init; + pthread_spin_lock; + pthread_spin_trylock; + pthread_spin_unlock; + pthread_stackseg_np; + pthread_testcancel; + pthread_yield; + sched_get_priority_max; + sched_get_priority_min; + sem_close; + sem_destroy; + sem_getvalue; + sem_init; + sem_open; + sem_post; + sem_timedwait; + sem_trywait; + sem_unlink; + sem_wait; + sigwait; + + /* used for debugging & regress */ + _thread_dump_info; + + /* other overrides of libc */ + _atomic_lock; + + _dlctl; + local: + *; +}; diff --git a/lib/librthread/arch/alpha/cerror.S b/lib/librthread/arch/alpha/cerror.S deleted file mode 100644 index af21adebee7..00000000000 --- a/lib/librthread/arch/alpha/cerror.S +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/10/17 06:39:20 guenther Exp $ */ -/* $NetBSD: cerror.S,v 1.3 1996/10/17 03:08:17 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" - -#define FRAME_SIZE 16 -#define FRAME_RA_OFFSET 0 -#define FRAME_V0_OFFSET 8 - -NESTED(__cerror, 0, FRAME_SIZE, ra, IM_RA|IM_V0, 0) -LEAF_NOPROFILE(__cerror, 0) - br t0, L1 -L1: LDGP(t0) - - 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) diff --git a/lib/librthread/arch/amd64/cerror.S b/lib/librthread/arch/amd64/cerror.S deleted file mode 100644 index 2d9fe89d6e0..00000000000 --- a/lib/librthread/arch/amd64/cerror.S +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/10/17 06:39:20 guenther 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" - -#define ERRNOPTR_OFFSET 24 - -_ENTRY(CERROR) - movq %fs:(ERRNOPTR_OFFSET), %rcx - movl %eax, (%rcx) - movq $-1,%rax - ret - -#if 0 /* generic code works */ -NENTRY(__errno) - movq %fs:(ERRNOPTR_OFFSET),%rax - ret -#endif - diff --git a/lib/librthread/arch/arm/cerror.S b/lib/librthread/arch/arm/cerror.S deleted file mode 100644 index cdf3eed62f7..00000000000 --- a/lib/librthread/arch/arm/cerror.S +++ /dev/null @@ -1,44 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.2 2012/02/27 20:22:08 miod Exp $ */ -/* $NetBSD: cerror.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: @(#)cerror.s 5.1 (Berkeley) 4/23/90 - */ - -#include "SYS.h" - -_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 - ldmfd sp!, {r4, pc} diff --git a/lib/librthread/arch/i386/cerror.S b/lib/librthread/arch/i386/cerror.S deleted file mode 100644 index e2a298b83c8..00000000000 --- a/lib/librthread/arch/i386/cerror.S +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/10/17 06:39:20 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" - -#define ERRNOPTR_OFFSET 12 - -_ENTRY(CERROR) - movl %gs:(ERRNOPTR_OFFSET),%ecx - movl %eax,(%ecx) - movl $-1,%eax - movl $-1,%edx - ret - -#if 0 /* generic code works */ -NENTRY(__errno) - movl %gs:(ERRNOPTR_OFFSET),%eax - ret -#endif diff --git a/lib/librthread/arch/m88k/cerror.S b/lib/librthread/arch/m88k/cerror.S deleted file mode 100644 index d31dc807c50..00000000000 --- a/lib/librthread/arch/m88k/cerror.S +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.5 2013/08/26 21:38:08 miod 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 "DEFS.h" - - .globl _C_LABEL(__errno) - -/* - * 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__ - bsr.n _C_LABEL(__errno)#plt -#else - 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 */ - - 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 - or %r3, %r0, %r2 -END(__cerror) diff --git a/lib/librthread/arch/mips64/cerror.S b/lib/librthread/arch/mips64/cerror.S deleted file mode 100644 index 0e46796953b..00000000000 --- a/lib/librthread/arch/mips64/cerror.S +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.2 2012/02/26 17:41:50 miod 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 <machine/asm.h> - -FRAMESZ= 4*REGSZ -S0OFF= FRAMESZ-3*REGSZ -GPOFF= FRAMESZ-2*REGSZ -RAOFF= FRAMESZ-1*REGSZ - - .globl _C_LABEL(__errno) -NON_LEAF(__cerror, FRAMESZ, ra) - PTR_SUBU sp, FRAMESZ - SETUP_GP64(GPOFF, __cerror) - .set reorder - REG_S ra, RAOFF(sp) - REG_S s0, S0OFF(sp) - - move s0, v0 - jal _C_LABEL(__errno) - - sw s0, 0(v0) - - LI v0, -1 - REG_L s0, S0OFF(sp) - REG_L ra, RAOFF(sp) - RESTORE_GP64 - PTR_ADDU sp, FRAMESZ - j ra -END(__cerror) diff --git a/lib/librthread/arch/powerpc/cerror.S b/lib/librthread/arch/powerpc/cerror.S deleted file mode 100644 index d34ea9d6398..00000000000 --- a/lib/librthread/arch/powerpc/cerror.S +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/11/09 15:36:23 kettenis 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. - */ - -#include "SYS.h" -#include <machine/asm.h> - -#define ERRNOPTR_OFFSET 16 - - .text -ASENTRY(__cerror) - lwz 5, 4(2) - lwz 5, ERRNOPTR_OFFSET(5) - - stw 0, 0(5) - addi 3, 0, -1 - addi 4, 0, -1 - blr diff --git a/lib/librthread/arch/sh/cerror.S b/lib/librthread/arch/sh/cerror.S deleted file mode 100644 index 6e67cf8aadf..00000000000 --- a/lib/librthread/arch/sh/cerror.S +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.2 2012/02/26 19:43:56 miod Exp $ */ -/* $NetBSD: cerror.S,v 1.10 2006/01/06 05:14:39 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: @(#)cerror.s 5.1 (Berkeley) 4/23/90 - */ - -#include "SYS.h" - -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, r0 - - .align 2 -.L_got: PIC_GOT_DATUM -.L___errno: CALL_DATUM(_C_LABEL(__errno), 1b) - SET_ASENTRY_SIZE(CERROR) - diff --git a/lib/librthread/arch/sparc/cerror.S b/lib/librthread/arch/sparc/cerror.S deleted file mode 100644 index 92b85f0338a..00000000000 --- a/lib/librthread/arch/sparc/cerror.S +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/10/17 06:39:20 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" - -#define ERRNOPTR_OFFSET 12 - - .globl _C_LABEL(errno) -FUNC(_C_LABEL(__cerror)) - ld [%g7 + ERRNOPTR_OFFSET], %g1 - st %o0, [%g1] - mov -1, %o0 - retl - mov -1, %o1 - -#if 0 /* generic code works */ -NENTRY(__errno) - retl - ld [%g7 + ERRNOPTR_OFFSET], %o0 -#endif diff --git a/lib/librthread/arch/sparc64/cerror.S b/lib/librthread/arch/sparc64/cerror.S deleted file mode 100644 index 18c4663bd44..00000000000 --- a/lib/librthread/arch/sparc64/cerror.S +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2011/10/17 06:39:20 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" - -#define ERRNOPTR_OFFSET 24 - - .globl _C_LABEL(errno) -FUNC(__cerror) - ldx [%g7 + ERRNOPTR_OFFSET], %g1 - st %o0, [%g1] - mov -1, %o0 - retl - mov -1, %o1 - -#if 0 /* generic code works */ -FUNC(__errno) - retl - ldx [%g7 + ERRNOPTR_OFFSET], %o0 -#endif diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index a622214d2fe..b7e82feabc7 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.90 2016/04/02 19:56:53 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.91 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -21,11 +21,6 @@ */ #include <sys/types.h> -#include <sys/uio.h> -#include <sys/wait.h> -#include <sys/socket.h> -#include <sys/mman.h> -#include <sys/msg.h> #ifndef NO_PIC #include <sys/exec_elf.h> #pragma weak _DYNAMIC @@ -38,22 +33,25 @@ #include <string.h> #include <errno.h> #include <dlfcn.h> -#include <fcntl.h> -#include <poll.h> +#include <tib.h> #include <pthread.h> -#include "thread_private.h" /* in libc/include */ +#include "cancel.h" /* in libc/include */ #include "rthread.h" -#include "tcb.h" +#include "rthread_cb.h" /* * Call nonstandard functions via names in the reserved namespace: - * NOT YET dlctl() -> _dlctl() + * dlctl() -> _dlctl() * getthrid -> _thread_sys_getthrid */ +typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak)); REDIRECT_SYSCALL(getthrid); +/* weak stub to be overriden by ld.so */ +int dlctl(void *handle, int cmd, void *data) { return 0; } + /* * libc's signal wrappers hide SIGTHR; we need to call the real syscall * stubs _thread_sys_* directly. @@ -74,7 +72,6 @@ static struct pthread_queue _thread_gc_list = TAILQ_HEAD_INITIALIZER(_thread_gc_list); static struct _spinlock _thread_gc_lock = _SPINLOCK_UNLOCKED; static struct pthread _initial_thread; -static struct thread_control_block _initial_thread_tcb; struct pthread_attr _rthread_attr_default = { .stack_addr = NULL, @@ -109,38 +106,6 @@ _spinunlock(volatile struct _spinlock *lock) lock->ticket = _ATOMIC_LOCK_UNLOCKED; } -/* - * This sets up the thread base for the initial thread so that it - * references the errno location provided by libc. For other threads - * this is handled by __tfork_thread() - */ -void _rthread_initlib(void) __attribute__((constructor)); -void -_rthread_initlib(void) -{ - static int tcb_set; - struct thread_control_block *tcb; - - if (__predict_false(tcb_set == 0)) { - tcb_set = 1; - - tcb = __get_tcb(); - if (tcb == NULL) { - tcb = &_initial_thread_tcb; - TCB_SET(tcb); - } - - /* use libc's errno for the main thread */ - TCB_INIT(tcb, &_initial_thread, ___errno()); - } -} - -int * -__errno(void) -{ - return (TCB_ERRNOPTR()); -} - static void _rthread_start(void *v) { @@ -154,7 +119,8 @@ _rthread_start(void *v) static void sigthr_handler(__unused int sig) { - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self = tib->tib_thread; /* * Do nothing unless @@ -162,8 +128,7 @@ sigthr_handler(__unused int sig) * 2) cancelation is enabled for it, and * 3) we're not already in cancelation processing */ - if ((self->flags & (THREAD_CANCELED|THREAD_CANCEL_ENABLE|THREAD_DYING)) - != (THREAD_CANCELED|THREAD_CANCEL_ENABLE)) + if (!tib->tib_canceled || tib->tib_cantcancel) return; /* @@ -171,7 +136,7 @@ sigthr_handler(__unused int sig) * pthread_join, etc), just mark that this has happened to * prevent a race with going to sleep */ - if (self->flags & THREAD_CANCEL_DELAY) { + if (tib->tib_cancel_point & CANCEL_POINT_DELAYED) { self->delayed_cancel = 1; return; } @@ -180,20 +145,49 @@ sigthr_handler(__unused int sig) * otherwise, if in a cancel point or async cancels are * enabled, then exit */ - if (self->cancel_point || (self->flags & THREAD_CANCEL_DEFERRED) == 0) + if (tib->tib_cancel_point || + (tib->tib_thread_flags & TIB_THREAD_ASYNC_CANCEL)) pthread_exit(PTHREAD_CANCELED); } -int + +/* + * A few basic callbacks for libc. The first couple are only used + * on archs where there isn't a fast TCB_GET() + */ +#ifndef TCB_HAVE_MD_GET +static int * +multi_threaded_errnoptr(void) +{ + return (&TIB_GET()->tib_errno); +} + +static void * +multi_threaded_tcb(void) +{ + return (TCB_GET()); +} +#endif /* TCB_HAVE_MD_GET */ + +void +_thread_canceled(void) +{ + pthread_exit(PTHREAD_CANCELED); +} + +void _rthread_init(void) { pthread_t thread = &_initial_thread; + struct tib *tib; struct sigaction sa; - thread->tid = getthrid(); + tib = TIB_GET(); + tib->tib_thread = thread; + thread->tib = tib; + thread->donesem.lock = _SPINLOCK_UNLOCKED_ASSIGN; - thread->flags |= THREAD_CANCEL_ENABLE | THREAD_CANCEL_DEFERRED | - THREAD_ORIGINAL | THREAD_INITIAL_STACK; + tib->tib_thread_flags = TIB_THREAD_INITIAL_STACK; thread->flags_lock = _SPINLOCK_UNLOCKED_ASSIGN; strlcpy(thread->name, "Main process", sizeof(thread->name)); LIST_INSERT_HEAD(&_thread_list, thread, threads); @@ -203,11 +197,36 @@ _rthread_init(void) _rthread_attr_default.guard_size = _thread_pagesize; thread->attr = _rthread_attr_default; - _rthread_initlib(); + /* get libc to start using our callbacks */ + { + struct thread_callbacks cb = { 0 }; - _threads_ready = 1; - - _rthread_debug(1, "rthread init\n"); +#ifndef TCB_HAVE_MD_GET + cb.tc_errnoptr = multi_threaded_errnoptr; + cb.tc_tcb = multi_threaded_tcb; +#endif + cb.tc_canceled = _thread_canceled; + cb.tc_flockfile = _thread_flockfile; + cb.tc_ftrylockfile = _thread_ftrylockfile; + cb.tc_funlockfile = _thread_funlockfile; + cb.tc_malloc_lock = _thread_malloc_lock; + cb.tc_malloc_unlock = _thread_malloc_unlock; + cb.tc_atexit_lock = _thread_atexit_lock; + cb.tc_atexit_unlock = _thread_atexit_unlock; + cb.tc_atfork_lock = _thread_atfork_lock; + cb.tc_atfork_unlock = _thread_atfork_unlock; + cb.tc_arc4_lock = _thread_arc4_lock; + cb.tc_arc4_unlock = _thread_arc4_unlock; + cb.tc_mutex_lock = _thread_mutex_lock; + cb.tc_mutex_unlock = _thread_mutex_unlock; + cb.tc_mutex_destroy = _thread_mutex_destroy; + cb.tc_tag_lock = _thread_tag_lock; + cb.tc_tag_unlock = _thread_tag_unlock; + cb.tc_tag_storage = _thread_tag_storage; + cb.tc_fork = _thread_fork; + cb.tc_vfork = _thread_vfork; + _thread_set_callbacks(&cb, sizeof(cb)); + } #ifndef NO_PIC if (_DYNAMIC) { @@ -226,38 +245,17 @@ _rthread_init(void) sigaddset(&sa.sa_mask, SIGTHR); sigprocmask(SIG_UNBLOCK, &sa.sa_mask, NULL); - return (0); + _threads_ready = 1; + + _rthread_debug(1, "rthread init\n"); } static void _rthread_free(pthread_t thread) { - /* _initial_thread is static, so don't free it */ - if (thread != &_initial_thread) { - /* - * thread->tid is written to by __threxit in the thread - * itself, so it's not safe to touch it here - */ - _spinlock(&_thread_gc_lock); - TAILQ_INSERT_TAIL(&_thread_gc_list, thread, waiting); - _spinunlock(&_thread_gc_lock); - } -} - -void -_rthread_setflag(pthread_t thread, int flag) -{ - _spinlock(&thread->flags_lock); - thread->flags |= flag; - _spinunlock(&thread->flags_lock); -} - -void -_rthread_clearflag(pthread_t thread, int flag) -{ - _spinlock(&thread->flags_lock); - thread->flags &= ~flag; - _spinunlock(&thread->flags_lock); + _spinlock(&_thread_gc_lock); + TAILQ_INSERT_TAIL(&_thread_gc_list, thread, waiting); + _spinunlock(&_thread_gc_lock); } /* @@ -267,10 +265,9 @@ pthread_t pthread_self(void) { if (!_threads_ready) - if (_rthread_init()) - return (NULL); + _rthread_init(); - return (TCB_THREAD()); + return (TIB_GET()->tib_thread); } DEF_STD(pthread_self); @@ -282,16 +279,21 @@ _rthread_reaper(void) restart: _spinlock(&_thread_gc_lock); TAILQ_FOREACH(thread, &_thread_gc_list, waiting) { - if (thread->tid != 0) + if (thread->tib->tib_tid != 0) continue; TAILQ_REMOVE(&_thread_gc_list, thread, waiting); _spinunlock(&_thread_gc_lock); - _rthread_debug(3, "rthread reaping %p stack %p\n", - (void *)thread, (void *)thread->stack); - _rthread_free_stack(thread->stack); - _rtld_free_tls(thread->tcb, - sizeof(struct thread_control_block), sizeof(void *)); - free(thread); + if (thread != &_initial_thread) { + _rthread_debug(3, "rthread reaping %p stack %p\n", + (void *)thread, (void *)thread->stack); + _rthread_free_stack(thread->stack); + _dl_free_tib(thread->tib, sizeof(*thread)); + } else { + /* initial thread isn't part of TIB allocation */ + _rthread_debug(3, "rthread reaping %p (initial)\n", + (void *)thread); + _dl_free_tib(thread->tib, 0); + } goto restart; } _spinunlock(&_thread_gc_lock); @@ -301,17 +303,23 @@ void pthread_exit(void *retval) { struct rthread_cleanup_fn *clfn; - pthread_t thread = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t thread; + + if (!_threads_ready) + _rthread_init(); + thread = tib->tib_thread; - if (thread->flags & THREAD_DYING) { + if (tib->tib_cantcancel & CANCEL_DYING) { /* * Called pthread_exit() from destructor or cancelation * handler: blow up. XXX write something to stderr? */ - _exit(42); + abort(); + //_exit(42); } - _rthread_setflag(thread, THREAD_DYING); + tib->tib_cantcancel |= CANCEL_DYING; thread->retval = retval; @@ -336,7 +344,7 @@ pthread_exit(void *retval) _sem_post(&thread->donesem); } - __threxit(&thread->tid); + __threxit(&tib->tib_tid); for(;;); } DEF_STD(pthread_exit); @@ -345,10 +353,16 @@ int pthread_join(pthread_t thread, void **retval) { int e; - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self; + PREP_CANCEL_POINT(tib); + + if (!_threads_ready) + _rthread_init(); + self = tib->tib_thread; e = 0; - _enter_delayed_cancel(self); + ENTER_DELAYED_CANCEL_POINT(tib, self); if (thread == NULL) e = EINVAL; else if (thread == self) @@ -369,7 +383,7 @@ pthread_join(pthread_t thread, void **retval) _rthread_free(thread); } - _leave_delayed_cancel(self, e); + LEAVE_CANCEL_POINT_INNER(tib, e); _rthread_reaper(); return (e); } @@ -399,25 +413,27 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { extern int __isthreaded; - struct thread_control_block *tcb; + struct tib *tib; pthread_t thread; struct __tfork param; - int rc = 0; + int rc; if (!_threads_ready) - if ((rc = _rthread_init())) - return (rc); + _rthread_init(); _rthread_reaper(); - thread = calloc(1, sizeof(*thread)); - if (!thread) - return (errno); + tib = _dl_allocate_tib(sizeof(*thread)); + if (tib == NULL) + return (ENOMEM); + thread = tib->tib_thread; + memset(thread, 0, sizeof(*thread)); + thread->tib = tib; thread->donesem.lock = _SPINLOCK_UNLOCKED_ASSIGN; thread->flags_lock = _SPINLOCK_UNLOCKED_ASSIGN; thread->fn = start_routine; thread->arg = arg; - thread->tid = -1; + tib->tib_tid = -1; thread->attr = attr != NULL ? *(*attr) : _rthread_attr_default; if (thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED) { @@ -428,7 +444,6 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, } if (thread->attr.detach_state == PTHREAD_CREATE_DETACHED) thread->flags |= THREAD_DETACHED; - thread->flags |= THREAD_CANCEL_ENABLE|THREAD_CANCEL_DEFERRED; thread->stack = _rthread_alloc_stack(thread); if (!thread->stack) { @@ -436,16 +451,8 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, goto fail1; } - tcb = _rtld_allocate_tls(NULL, sizeof(*tcb), sizeof(void *)); - if (tcb == NULL) { - rc = errno; - goto fail2; - } - TCB_INIT(tcb, thread, &thread->myerrno); - thread->tcb = tcb; - - param.tf_tcb = tcb; - param.tf_tid = &thread->tid; + param.tf_tcb = TIB_TO_TCB(tib); + param.tf_tid = &tib->tib_tid; param.tf_stack = thread->stack->sp; _spinlock(&_thread_lock); @@ -466,11 +473,9 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, _spinlock(&_thread_lock); LIST_REMOVE(thread, threads); _spinunlock(&_thread_lock); - _rtld_free_tls(tcb, sizeof(*tcb), sizeof(void *)); -fail2: _rthread_free_stack(thread->stack); fail1: - _rthread_free(thread); + _dl_free_tib(tib, sizeof(*thread)); return (rc); } @@ -478,9 +483,11 @@ fail1: int pthread_kill(pthread_t thread, int sig) { + struct tib *tib = thread->tib; + if (sig == SIGTHR) return (EINVAL); - if (thrkill(thread->tid, sig, thread->tcb)) + if (thrkill(tib->tib_tid, sig, TIB_TO_TCB(tib))) return (errno); return (0); } @@ -494,45 +501,42 @@ pthread_equal(pthread_t t1, pthread_t t2) int pthread_cancel(pthread_t thread) { - pid_t tid; + struct tib *tib = thread->tib; + pid_t tid = tib->tib_tid; - _spinlock(&thread->flags_lock); - tid = thread->tid; - if ((thread->flags & (THREAD_DYING | THREAD_CANCELED)) == 0 && - tid != 0) { - thread->flags |= THREAD_CANCELED; - - if (thread->flags & THREAD_CANCEL_ENABLE) { - _spinunlock(&thread->flags_lock); - thrkill(tid, SIGTHR, thread->tcb); + if (tib->tib_canceled == 0 && tid != 0 && + (tib->tib_cantcancel & CANCEL_DYING) == 0) { + tib->tib_canceled = 1; + + if ((tib->tib_cantcancel & CANCEL_DISABLED) == 0) { + thrkill(tid, SIGTHR, TIB_TO_TCB(tib)); return (0); } } - _spinunlock(&thread->flags_lock); return (0); } void pthread_testcancel(void) { - if ((pthread_self()->flags & (THREAD_CANCELED|THREAD_CANCEL_ENABLE)) == - (THREAD_CANCELED|THREAD_CANCEL_ENABLE)) - pthread_exit(PTHREAD_CANCELED); + struct tib *tib = TIB_GET(); + if (tib->tib_canceled && (tib->tib_cantcancel & CANCEL_DISABLED) == 0) + pthread_exit(PTHREAD_CANCELED); } int pthread_setcancelstate(int state, int *oldstatep) { - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); int oldstate; - oldstate = self->flags & THREAD_CANCEL_ENABLE ? - PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE; + oldstate = tib->tib_cantcancel & CANCEL_DISABLED ? + PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE; if (state == PTHREAD_CANCEL_ENABLE) { - _rthread_setflag(self, THREAD_CANCEL_ENABLE); + tib->tib_cantcancel &= ~CANCEL_DISABLED; } else if (state == PTHREAD_CANCEL_DISABLE) { - _rthread_clearflag(self, THREAD_CANCEL_ENABLE); + tib->tib_cantcancel |= CANCEL_DISABLED; } else { return (EINVAL); } @@ -546,15 +550,15 @@ DEF_STD(pthread_setcancelstate); int pthread_setcanceltype(int type, int *oldtypep) { - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); int oldtype; - oldtype = self->flags & THREAD_CANCEL_DEFERRED ? - PTHREAD_CANCEL_DEFERRED : PTHREAD_CANCEL_ASYNCHRONOUS; + oldtype = tib->tib_thread_flags & TIB_THREAD_ASYNC_CANCEL ? + PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED; if (type == PTHREAD_CANCEL_DEFERRED) { - _rthread_setflag(self, THREAD_CANCEL_DEFERRED); + tib->tib_thread_flags &=~ TIB_THREAD_ASYNC_CANCEL; } else if (type == PTHREAD_CANCEL_ASYNCHRONOUS) { - _rthread_clearflag(self, THREAD_CANCEL_DEFERRED); + tib->tib_thread_flags |= TIB_THREAD_ASYNC_CANCEL; } else { return (EINVAL); } @@ -619,8 +623,8 @@ _thread_dump_info(void) _spinlock(&_thread_lock); LIST_FOREACH(thread, &_thread_list, threads) - printf("thread %d flags %d name %s\n", - thread->tid, thread->flags, thread->name); + printf("thread %d flags 0x%x name %s\n", thread->tib->tib_tid, + thread->tib->tib_thread_flags, thread->name); _spinunlock(&_thread_lock); } @@ -680,67 +684,3 @@ _rthread_dl_lock(int what) } } #endif - - -/* - * XXX: Bogus type signature, but we only need to be able to emit a - * reference to it below. - */ -extern void __cerror(void); - -/* - * All weak references used within libc that are redefined in libpthread - * MUST be in this table. This is necessary to force the proper version to - * be used when linking -static. - */ -static void *__libc_overrides[] __used = { - &__cerror, - &__errno, - &_thread_arc4_lock, - &_thread_arc4_unlock, - &_thread_atexit_lock, - &_thread_atexit_unlock, - &_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, - &accept, - &close, - &closefrom, - &connect, - &fcntl, - &flockfile, - &fork, - &fsync, - &ftrylockfile, - &funlockfile, - &msgrcv, - &msgsnd, - &msync, - &nanosleep, - &open, - &openat, - &poll, - &pread, - &preadv, - &pwrite, - &pwritev, - &read, - &readv, - &recvfrom, - &recvmsg, - &select, - &sendmsg, - &sendto, - &sigsuspend, - &vfork, - &wait4, - &write, - &writev, -}; diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h index 6ef9a8c9733..10973208184 100644 --- a/lib/librthread/rthread.h +++ b/lib/librthread/rthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.h,v 1.57 2016/04/15 17:54:17 tedu Exp $ */ +/* $OpenBSD: rthread.h,v 1.58 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -30,7 +30,6 @@ #include <sys/queue.h> #include <semaphore.h> #include <machine/spinlock.h> -#include <machine/tcb.h> /* for TLS_VARIANT */ #ifdef __LP64__ #define RTHREAD_STACK_SIZE_DEF (512 * 1024) @@ -155,15 +154,12 @@ struct pthread_spinlock { pthread_t owner; }; +struct tib; struct pthread { struct __sem donesem; -#if TLS_VARIANT == 1 - int *errno_ptr; -#endif - pid_t tid; unsigned int flags; struct _spinlock flags_lock; - void *tcb; + struct tib *tib; void *retval; void *(*fn)(void *); void *arg; @@ -177,44 +173,32 @@ struct pthread { struct rthread_cleanup_fn *cleanup_fns; int myerrno; - /* currently in a cancel point? */ - int cancel_point; - /* cancel received in a delayed cancel block? */ int delayed_cancel; }; +/* flags in pthread->flags */ #define THREAD_DONE 0x001 #define THREAD_DETACHED 0x002 -#define THREAD_CANCELED 0x004 -#define THREAD_CANCEL_ENABLE 0x008 -#define THREAD_CANCEL_DEFERRED 0x010 -#define THREAD_CANCEL_DELAY 0x020 -#define THREAD_DYING 0x040 -#define THREAD_ORIGINAL 0x080 /* original thread from fork */ -#define THREAD_INITIAL_STACK 0x100 /* thread with stack from exec */ -#define IS_CANCELED(thread) \ - (((thread)->flags & (THREAD_CANCELED|THREAD_DYING)) == THREAD_CANCELED) +/* flags in tib->tib_thread_flags */ +#define TIB_THREAD_ASYNC_CANCEL 0x001 +#define TIB_THREAD_INITIAL_STACK 0x002 /* has stack from exec */ - -extern int _threads_ready; -extern size_t _thread_pagesize; -extern LIST_HEAD(listhead, pthread) _thread_list; -extern struct _spinlock _thread_lock; -extern struct pthread_attr _rthread_attr_default; +#define ENTER_DELAYED_CANCEL_POINT(tib, self) \ + (self)->delayed_cancel = 0; \ + ENTER_CANCEL_POINT_INNER(tib, 1, 1) #define ROUND_TO_PAGE(size) \ (((size) + (_thread_pagesize - 1)) & ~(_thread_pagesize - 1)) +__BEGIN_HIDDEN_DECLS void _spinlock(volatile struct _spinlock *); int _spinlocktry(volatile struct _spinlock *); void _spinunlock(volatile struct _spinlock *); int _sem_wait(sem_t, int, const struct timespec *, int *); int _sem_post(sem_t); -int _rthread_init(void); -void _rthread_setflag(pthread_t, int); -void _rthread_clearflag(pthread_t, int); +void _rthread_init(void); struct stack *_rthread_alloc_stack(pthread_t); void _rthread_free_stack(struct stack *); void _rthread_tls_destructors(pthread_t); @@ -226,11 +210,12 @@ void _rthread_dl_lock(int what); #endif void _thread_malloc_reinit(void); -/* rthread_cancel.c */ -void _enter_cancel(pthread_t); -void _leave_cancel(pthread_t); -void _enter_delayed_cancel(pthread_t); -void _leave_delayed_cancel(pthread_t, int); +extern int _threads_ready; +extern size_t _thread_pagesize; +extern LIST_HEAD(listhead, pthread) _thread_list; +extern struct _spinlock _thread_lock; +extern struct pthread_attr _rthread_attr_default; +__END_HIDDEN_DECLS void _thread_dump_info(void); diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c index b4c0f8b3a2c..c25ae9c3faa 100644 --- a/lib/librthread/rthread_attr.c +++ b/lib/librthread/rthread_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_attr.c,v 1.21 2016/04/02 19:56:53 guenther Exp $ */ +/* $OpenBSD: rthread_attr.c,v 1.22 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -44,12 +44,10 @@ int pthread_attr_init(pthread_attr_t *attrp) { pthread_attr_t attr; - int error; /* make sure _rthread_attr_default has been initialized */ if (!_threads_ready) - if ((error = _rthread_init())) - return (error); + _rthread_init(); attr = calloc(1, sizeof(*attr)); if (!attr) diff --git a/lib/librthread/rthread_cancel.c b/lib/librthread/rthread_cancel.c deleted file mode 100644 index 0a7a35cdb44..00000000000 --- a/lib/librthread/rthread_cancel.c +++ /dev/null @@ -1,624 +0,0 @@ -/* $OpenBSD: rthread_cancel.c,v 1.10 2015/10/15 16:38:04 deraadt Exp $ */ -/* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/msg.h> -#include <sys/mman.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/resource.h> -#include <sys/uio.h> -#include <sys/wait.h> -#include <fcntl.h> -#include <poll.h> -#include <signal.h> -#include <stdarg.h> -#include <termios.h> -#include <unistd.h> - -#include <pthread.h> -#include <stdlib.h> -#include <string.h> - -#include "thread_private.h" /* in libc/include */ - -#include "rthread.h" - -/* - * If you add anything here, make sure to add it to the list in the - * pthread_testcancel(3) manpage too. - */ - -int _thread_sys_accept(int, struct sockaddr *, socklen_t *); -int _thread_sys_accept4(int, struct sockaddr *, socklen_t *, int); -int _thread_sys_close(int); -int _thread_sys_closefrom(int); -int _thread_sys_connect(int, const struct sockaddr *, socklen_t); -int _thread_sys_fcntl(int, int, ...); -int _thread_sys_fsync(int); -int _thread_sys_msgrcv(int, void *, size_t, long, int); -int _thread_sys_msgsnd(int, const void *, size_t, int); -int _thread_sys_msync(void *, size_t, int); -int _thread_sys_nanosleep(const struct timespec *, struct timespec *); -int _thread_sys_open(const char *, int, ...); -int _thread_sys_openat(int, const char *, int, ...); -int _thread_sys_poll(struct pollfd *, nfds_t, int); -int _thread_sys_ppoll(struct pollfd *, nfds_t, const struct timespec *, - const sigset_t *); -ssize_t _thread_sys_pread(int, void *, size_t, off_t); -ssize_t _thread_sys_preadv(int, const struct iovec *, int, off_t); -int _thread_sys_pselect(int, fd_set *, fd_set *, fd_set *, - const struct timespec *, const sigset_t *); -ssize_t _thread_sys_pwrite(int, const void *, size_t, off_t); -ssize_t _thread_sys_pwritev(int, const struct iovec *, int, off_t); -ssize_t _thread_sys_read(int, void *, size_t); -ssize_t _thread_sys_readv(int, const struct iovec *, int); -ssize_t _thread_sys_recvfrom(int, void *, size_t, int, struct sockaddr *, - socklen_t *); -ssize_t _thread_sys_recvmsg(int, struct msghdr *, int); -int _thread_sys_select(int, fd_set *, fd_set *, fd_set *, - struct timeval *); -ssize_t _thread_sys_sendmsg(int, const struct msghdr *, int); -ssize_t _thread_sys_sendto(int, const void *, size_t, int, - const struct sockaddr *, socklen_t); -int _thread_sys_sigsuspend(const sigset_t *); -pid_t _thread_sys_wait4(pid_t, int *, int, struct rusage *); -ssize_t _thread_sys_write(int, const void *, size_t); -ssize_t _thread_sys_writev(int, const struct iovec *, int); - -void -_enter_cancel(pthread_t self) -{ - if (self->flags & THREAD_CANCEL_ENABLE) { - self->cancel_point++; - if (IS_CANCELED(self)) - pthread_exit(PTHREAD_CANCELED); - } -} - -void -_leave_cancel(pthread_t self) -{ - if (self->flags & THREAD_CANCEL_ENABLE) - self->cancel_point--; -} - -void -_enter_delayed_cancel(pthread_t self) -{ - if (self->flags & THREAD_CANCEL_ENABLE) { - self->delayed_cancel = 0; - self->cancel_point++; - if (IS_CANCELED(self)) - pthread_exit(PTHREAD_CANCELED); - _rthread_setflag(self, THREAD_CANCEL_DELAY); - } -} - -void -_leave_delayed_cancel(pthread_t self, int can_cancel) -{ - if (self->flags & THREAD_CANCEL_ENABLE) { - if (self->flags & THREAD_CANCEL_DELAY) { - self->cancel_point--; - _rthread_clearflag(self, THREAD_CANCEL_DELAY); - } - if (IS_CANCELED(self) && can_cancel) - pthread_exit(PTHREAD_CANCELED); - self->delayed_cancel = 0; - } -} - -int -accept(int fd, struct sockaddr *addr, socklen_t *addrlen) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_accept(fd, addr, addrlen); - _leave_cancel(self); - return (rv); -} - -int -accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_accept4(fd, addr, addrlen, flags); - _leave_cancel(self); - return (rv); -} - -#if 0 -aio_suspend() /* don't have yet */ -clock_nanosleep() /* don't have yet */ -#endif - -int -close(int fd) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_close(fd); - _leave_cancel(self); - return (rv); -} - - -int -closefrom(int fd) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_closefrom(fd); - _leave_cancel(self); - return (rv); -} - -int -connect(int fd, const struct sockaddr *addr, socklen_t addrlen) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_connect(fd, addr, addrlen); - _leave_cancel(self); - return (rv); -} - -#if 0 -creat() /* built on open() */ -#endif - -int -fcntl(int fd, int cmd, ...) -{ - va_list ap; - int rv; - - va_start(ap, cmd); - switch (cmd) { - case F_DUPFD: - case F_DUPFD_CLOEXEC: - case F_SETFD: - case F_SETFL: - case F_SETOWN: - rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, int)); - break; - case F_GETFD: - case F_GETFL: - case F_GETOWN: - case F_ISATTY: - rv = _thread_sys_fcntl(fd, cmd); - break; - case F_GETLK: - case F_SETLK: - rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, struct flock *)); - break; - case F_SETLKW: - { - pthread_t self = pthread_self(); - - _enter_cancel(self); - rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, struct flock *)); - _leave_cancel(self); - break; - } - default: /* should never happen? */ - rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, void *)); - break; - } - va_end(ap); - return (rv); -} - -#if 0 -fdatasync() /* built on fsync() */ -#endif - -int -fsync(int fd) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_fsync(fd); - _leave_cancel(self); - return (rv); -} - -#if 0 -getmsg() /* don't have: dumb STREAMS stuff */ -getpmsg() /* don't have: dumb STREAMS stuff */ -lockf() /* built on fcntl() */ -mq_receive() /* don't have yet */ -mq_send() /* don't have yet */ -mq_timedreceive() /* don't have yet */ -mq_timedsend() /* don't have yet */ -#endif - -int -msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg); - _leave_cancel(self); - return (rv); -} - -int -msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_msgsnd(msqid, msgp, msgsz, msgflg); - _leave_cancel(self); - return (rv); -} - -int -msync(void *addr, size_t len, int flags) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_msync(addr, len, flags); - _leave_cancel(self); - return (rv); -} - -int -nanosleep(const struct timespec *rqtp, struct timespec *rmtp) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_nanosleep(rqtp, rmtp); - _leave_cancel(self); - return (rv); -} - -int -open(const char *path, int flags, ...) -{ - pthread_t self = pthread_self(); - - va_list ap; - mode_t mode = 0; - int rv; - - if (flags & O_CREAT) { - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - _enter_cancel(self); - rv = _thread_sys_open(path, flags, mode); - _leave_cancel(self); - return (rv); -} - - -int -openat(int fd, const char *path, int flags, ...) -{ - pthread_t self = pthread_self(); - - va_list ap; - mode_t mode = 0; - int rv; - - if (flags & O_CREAT) { - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - _enter_cancel(self); - rv = _thread_sys_openat(fd, path, flags, mode); - _leave_cancel(self); - return (rv); -} - -#if 0 -pause() /* built on sigsuspend() */ -#endif - -int -poll(struct pollfd *fds, nfds_t nfds, int timeout) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_poll(fds, nfds, timeout); - _leave_cancel(self); - return (rv); -} - -int -ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, - const sigset_t *sigmask) -{ - pthread_t self = pthread_self(); - sigset_t set; - int rv; - - if (sigmask != NULL && sigismember(sigmask, SIGTHR)) { - set = *sigmask; - sigdelset(&set, SIGTHR); - sigmask = &set; - } - - _enter_cancel(self); - rv = _thread_sys_ppoll(fds, nfds, timeout, sigmask); - _leave_cancel(self); - return (rv); -} - -ssize_t -pread(int fd, void *buf, size_t nbytes, off_t offset) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_pread(fd, buf, nbytes, offset); - _leave_cancel(self); - return (rv); -} - -ssize_t -preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_preadv(fd, iov, iovcnt, offset); - _leave_cancel(self); - return (rv); -} - -int -pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - const struct timespec *timeout, const sigset_t *sigmask) -{ - pthread_t self = pthread_self(); - sigset_t set; - int rv; - - if (sigmask != NULL && sigismember(sigmask, SIGTHR)) { - set = *sigmask; - sigdelset(&set, SIGTHR); - sigmask = &set; - } - - _enter_cancel(self); - rv = _thread_sys_pselect(nfds, readfds, writefds, exceptfds, timeout, - sigmask); - _leave_cancel(self); - return (rv); -} - -#if 0 -putmsg() /* don't have: dumb STREAMS stuff */ -putpmsg() /* don't have: dumb STREAMS stuff */ -#endif - -ssize_t -pwrite(int fd, const void *buf, size_t nbytes, off_t offset) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_pwrite(fd, buf, nbytes, offset); - _leave_cancel(self); - return (rv); -} - -ssize_t -pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_pwritev(fd, iov, iovcnt, offset); - _leave_cancel(self); - return (rv); -} - -ssize_t -read(int fd, void *buf, size_t nbytes) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_read(fd, buf, nbytes); - _leave_cancel(self); - return (rv); -} - -ssize_t -readv(int fd, const struct iovec *iov, int iovcnt) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_readv(fd, iov, iovcnt); - _leave_cancel(self); - return (rv); -} - -#if 0 -recv() /* built on recvfrom() */ -#endif - -ssize_t -recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, - socklen_t *addrlen) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_recvfrom(fd, buf, len, flags, addr, addrlen); - _leave_cancel(self); - return (rv); -} - -ssize_t -recvmsg(int fd, struct msghdr *msg, int flags) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_recvmsg(fd, msg, flags); - _leave_cancel(self); - return (rv); -} - -int -select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = _thread_sys_select(nfds, readfds, writefds, exceptfds, timeout); - _leave_cancel(self); - return (rv); -} - -#if 0 -sem_timedwait() /* in rthread_sem.c */ -sem_wait() /* in rthread_sem.c */ -send() /* built on sendto() */ -#endif - -ssize_t -sendmsg(int fd, const struct msghdr *msg, int flags) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_sendmsg(fd, msg, flags); - _leave_cancel(self); - return (rv); -} - -ssize_t -sendto(int fd, const void *msg, size_t len, int flags, - const struct sockaddr *to, socklen_t tolen) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_sendto(fd, msg, len, flags, to, tolen); - _leave_cancel(self); - return (rv); -} - - -int -sigsuspend(const sigset_t *sigmask) -{ - pthread_t self = pthread_self(); - sigset_t set = *sigmask; - int rv; - - sigdelset(&set, SIGTHR); - _enter_cancel(self); - rv = _thread_sys_sigsuspend(&set); - _leave_cancel(self); - return (rv); -} - -#if 0 -sigtimedwait() /* don't have yet */ -sigwait() /* in rthread_sig.c */ -sigwaitinfo() /* don't have yet */ -sleep() /* built on nanosleep() */ -system() /* built on wait4()? XXX */ -#endif - -int -tcdrain(int fd) -{ - pthread_t self = pthread_self(); - int rv; - - _enter_cancel(self); - rv = ioctl(fd, TIOCDRAIN, 0); - _leave_cancel(self); - return (rv); -} - -#if 0 -wait() /* built on wait4() */ -waitid() /* don't have yet */ -waitpid() /* built on wait4() */ -#endif - -pid_t -wait4(pid_t wpid, int *status, int options, struct rusage *rusage) -{ - pthread_t self = pthread_self(); - pid_t rv; - - _enter_cancel(self); - rv = _thread_sys_wait4(wpid, status, options, rusage); - _leave_cancel(self); - return (rv); -} - -ssize_t -write(int fd, const void *buf, size_t nbytes) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_write(fd, buf, nbytes); - _leave_cancel(self); - return (rv); -} - -ssize_t -writev(int fd, const struct iovec *iov, int iovcnt) -{ - pthread_t self = pthread_self(); - ssize_t rv; - - _enter_cancel(self); - rv = _thread_sys_writev(fd, iov, iovcnt); - _leave_cancel(self); - return (rv); -} diff --git a/lib/librthread/rthread_cb.h b/lib/librthread/rthread_cb.h new file mode 100644 index 00000000000..459d59006bf --- /dev/null +++ b/lib/librthread/rthread_cb.h @@ -0,0 +1,41 @@ +/* $OpenBSD: rthread_cb.h,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ +/* + * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org> + * All Rights Reserved. + * + * 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> + +__BEGIN_HIDDEN_DECLS +pid_t _thread_fork(void); +pid_t _thread_vfork(void); +void _thread_flockfile(FILE *); +int _thread_ftrylockfile(FILE *); +void _thread_funlockfile(FILE *); +void _thread_malloc_lock(void); +void _thread_malloc_unlock(void); +void _thread_atexit_lock(void); +void _thread_atexit_unlock(void); +void _thread_atfork_lock(void); +void _thread_atfork_unlock(void); +void _thread_arc4_lock(void); +void _thread_arc4_unlock(void); +void _thread_mutex_lock(void **); +void _thread_mutex_unlock(void **); +void _thread_mutex_destroy(void **); +void _thread_tag_lock(void **); +void _thread_tag_unlock(void **); +void *_thread_tag_storage(void **, void *, size_t, void *); +__END_HIDDEN_DECLS diff --git a/lib/librthread/rthread_file.c b/lib/librthread/rthread_file.c index 50693b61aeb..e9572ea117b 100644 --- a/lib/librthread/rthread_file.c +++ b/lib/librthread/rthread_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_file.c,v 1.7 2013/11/21 17:45:10 fgsch Exp $ */ +/* $OpenBSD: rthread_file.c,v 1.8 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -43,6 +43,7 @@ #include <sys/queue.h> #include <pthread.h> #include "rthread.h" +#include "rthread_cb.h" /* * The FILE lock structure. The FILE *fp is locked if the owner is @@ -167,7 +168,7 @@ do_lock(int idx, FILE *fp) } void -(flockfile)(FILE * fp) +_thread_flockfile(FILE * fp) { int idx = file_idx(fp); struct file_lock *p; @@ -215,7 +216,7 @@ void } int -(ftrylockfile)(FILE * fp) +_thread_ftrylockfile(FILE * fp) { int ret = -1; int idx = file_idx(fp); @@ -264,7 +265,7 @@ int } void -(funlockfile)(FILE * fp) +_thread_funlockfile(FILE * fp) { int idx = file_idx(fp); struct file_lock *p; diff --git a/lib/librthread/rthread_fork.c b/lib/librthread/rthread_fork.c index 3f7a5faa32c..a292679298e 100644 --- a/lib/librthread/rthread_fork.c +++ b/lib/librthread/rthread_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_fork.c,v 1.16 2016/04/02 19:00:51 guenther Exp $ */ +/* $OpenBSD: rthread_fork.c,v 1.17 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2008 Kurt Miller <kurt@openbsd.org> @@ -39,27 +39,25 @@ #include <errno.h> #include <pthread.h> #include <stdlib.h> +#include <tib.h> #include <unistd.h> #include "thread_private.h" /* in libc/include */ #include "rthread.h" +#include "rthread_cb.h" +/* make {fork,vfork,getthrid} call _thread_sys_{fork,vfork,getthrid} */ +REDIRECT_SYSCALL(fork); +REDIRECT_SYSCALL(vfork); REDIRECT_SYSCALL(getthrid); -pid_t _thread_sys_fork(void); -pid_t _thread_sys_vfork(void); -pid_t _dofork(int); - -pid_t -_dofork(int is_vfork) +static pid_t +_dofork(pid_t (*sys_fork)(void)) { pthread_t me; - pid_t (*sys_fork)(void); pid_t newid; - sys_fork = is_vfork ? &_thread_sys_vfork : &_thread_sys_fork; - if (!_threads_ready) return sys_fork(); @@ -91,20 +89,17 @@ _dofork(int is_vfork) _thread_atexit_unlock(); if (newid == 0) { + struct tib *tib = me->tib; #ifndef NO_PIC /* reinitialize the lock in the child */ if (_DYNAMIC) _rthread_dl_lock(2); #endif /* update this thread's structure */ - me->tid = getthrid(); + tib->tib_tid = getthrid(); me->donesem.lock = _SPINLOCK_UNLOCKED_ASSIGN; - me->flags &= ~THREAD_DETACHED; me->flags_lock = _SPINLOCK_UNLOCKED_ASSIGN; - /* this thread is the initial thread for the new process */ - me->flags |= THREAD_ORIGINAL; - /* reinit the thread list */ LIST_INIT(&_thread_list); LIST_INSERT_HEAD(&_thread_list, me, threads); @@ -123,11 +118,11 @@ _dofork(int is_vfork) pid_t _thread_fork(void) { - return _dofork(0); + return _dofork(&fork); } pid_t -vfork(void) +_thread_vfork(void) { - return _dofork(1); + return _dofork(&vfork); } diff --git a/lib/librthread/rthread_getcpuclockid.c b/lib/librthread/rthread_getcpuclockid.c index 52d50c6ad68..76d07b9f490 100644 --- a/lib/librthread/rthread_getcpuclockid.c +++ b/lib/librthread/rthread_getcpuclockid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_getcpuclockid.c,v 1.1 2013/06/17 19:11:54 guenther Exp $ */ +/* $OpenBSD: rthread_getcpuclockid.c,v 1.2 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2013 Philip Guenther <guenther@openbsd.org> * @@ -15,14 +15,16 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <time.h> #include <pthread.h> +#include <tib.h> +#include <time.h> #include "rthread.h" int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id) { - *clock_id = __CLOCK_ENCODE(CLOCK_THREAD_CPUTIME_ID, thread->tid); + *clock_id = __CLOCK_ENCODE(CLOCK_THREAD_CPUTIME_ID, + thread->tib->tib_tid); return (0); } diff --git a/lib/librthread/rthread_libc.c b/lib/librthread/rthread_libc.c index 8eff5369a83..ec768d4e803 100644 --- a/lib/librthread/rthread_libc.c +++ b/lib/librthread/rthread_libc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_libc.c,v 1.13 2016/01/27 08:40:05 kettenis Exp $ */ +/* $OpenBSD: rthread_libc.c,v 1.14 2016/05/07 19:05:22 guenther Exp $ */ /* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ @@ -12,6 +12,7 @@ #include "thread_private.h" /* in libc/include */ #include "rthread.h" +#include "rthread_cb.h" /* * A thread tag is a pointer to a structure of this type. An opaque diff --git a/lib/librthread/rthread_np.c b/lib/librthread/rthread_np.c index ed866820c27..d8a78110358 100644 --- a/lib/librthread/rthread_np.c +++ b/lib/librthread/rthread_np.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_np.c,v 1.18 2016/04/02 19:00:51 guenther Exp $ */ +/* $OpenBSD: rthread_np.c,v 1.19 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org> @@ -24,16 +24,15 @@ #include <sys/queue.h> #include <sys/sysctl.h> -#include <stdint.h> #include <errno.h> #include <pthread.h> #include <pthread_np.h> #include <stddef.h> +#include <stdint.h> #include <string.h> +#include <tib.h> #include <unistd.h> -#include <machine/spinlock.h> - #include "rthread.h" REDIRECT_SYSCALL(sysctl); @@ -47,8 +46,8 @@ pthread_set_name_np(pthread_t thread, const char *name) int pthread_main_np(void) { - return (!_threads_ready || (pthread_self()->flags & THREAD_ORIGINAL) - ? 1 : 0); + return (!_threads_ready || + (TIB_GET()->tib_thread_flags & TIB_THREAD_INITIAL_STACK) ? 1 : 0); } @@ -76,7 +75,7 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo) sinfo->ss_size -= thread->stack->guardsize; sinfo->ss_flags = 0; return (0); - } else if (thread->flags & THREAD_INITIAL_STACK) { + } else if (thread->tib->tib_thread_flags & TIB_THREAD_INITIAL_STACK) { static struct _ps_strings _ps; static struct rlimit rl; static int gotself; diff --git a/lib/librthread/rthread_sem.c b/lib/librthread/rthread_sem.c index e7a8e4e0733..dcf51afc26c 100644 --- a/lib/librthread/rthread_sem.c +++ b/lib/librthread/rthread_sem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sem.c,v 1.22 2016/04/02 19:56:53 guenther Exp $ */ +/* $OpenBSD: rthread_sem.c,v 1.23 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005,2013 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -32,6 +32,7 @@ #include <pthread.h> #include "rthread.h" +#include "cancel.h" /* in libc/include */ #define SHARED_IDENT ((void *)-1) @@ -229,18 +230,24 @@ sem_post(sem_t *semp) int sem_wait(sem_t *semp) { - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self; sem_t sem; int r; + PREP_CANCEL_POINT(tib); + + if (!_threads_ready) + _rthread_init(); + self = tib->tib_thread; if (!semp || !(sem = *semp)) { errno = EINVAL; return (-1); } - _enter_delayed_cancel(self); + ENTER_DELAYED_CANCEL_POINT(tib, self); r = _sem_wait(sem, 0, NULL, &self->delayed_cancel); - _leave_delayed_cancel(self, r); + LEAVE_CANCEL_POINT_INNER(tib, r); if (r) { errno = r; @@ -253,18 +260,24 @@ sem_wait(sem_t *semp) int sem_timedwait(sem_t *semp, const struct timespec *abstime) { - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self; sem_t sem; int r; + PREP_CANCEL_POINT(tib); + + if (!_threads_ready) + _rthread_init(); + self = tib->tib_thread; if (!semp || !(sem = *semp)) { errno = EINVAL; return (-1); } - _enter_delayed_cancel(self); + ENTER_DELAYED_CANCEL_POINT(tib, self); r = _sem_wait(sem, 0, abstime, &self->delayed_cancel); - _leave_delayed_cancel(self, r); + LEAVE_CANCEL_POINT_INNER(tib, r); if (r) { errno = r == EWOULDBLOCK ? ETIMEDOUT : r; @@ -314,6 +327,9 @@ sem_open(const char *name, int oflag, ...) unsigned int value = 0; int created = 0, fd; + if (!_threads_ready) + _rthread_init(); + if (oflag & ~(O_CREAT | O_EXCL)) { errno = EINVAL; return (SEM_FAILED); diff --git a/lib/librthread/rthread_sig.c b/lib/librthread/rthread_sig.c index 3fbf9b4c200..65d193cbf58 100644 --- a/lib/librthread/rthread_sig.c +++ b/lib/librthread/rthread_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sig.c,v 1.17 2015/10/23 04:39:24 guenther Exp $ */ +/* $OpenBSD: rthread_sig.c,v 1.18 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -25,19 +25,19 @@ #include <pthread.h> #include "rthread.h" +#include "cancel.h" /* in libc/include */ int sigwait(const sigset_t *set, int *sig) { - pthread_t self = pthread_self(); sigset_t s = *set; int ret; sigdelset(&s, SIGTHR); do { - _enter_cancel(self); + ENTER_CANCEL_POINT(1); ret = __thrsigdivert(s, NULL, NULL); - _leave_cancel(self); + LEAVE_CANCEL_POINT(ret == -1); } while (ret == -1 && errno == EINTR); if (ret == -1) return (errno); @@ -49,14 +49,13 @@ sigwait(const sigset_t *set, int *sig) int sigwaitinfo(const sigset_t *set, siginfo_t *info) { - pthread_t self = pthread_self(); sigset_t s = *set; int ret; sigdelset(&s, SIGTHR); - _enter_cancel(self); + ENTER_CANCEL_POINT(1); ret = __thrsigdivert(s, info, NULL); - _leave_cancel(self); + LEAVE_CANCEL_POINT(ret == -1); return (ret); } @@ -64,14 +63,13 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) { - pthread_t self = pthread_self(); sigset_t s = *set; int ret; sigdelset(&s, SIGTHR); - _enter_cancel(self); + ENTER_CANCEL_POINT(1); ret = __thrsigdivert(s, info, timeout); - _leave_cancel(self); + LEAVE_CANCEL_POINT(ret == -1); return (ret); } #endif diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index 32331952906..7deb9fbea1a 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.41 2016/04/15 21:04:04 guenther Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.42 2016/05/07 19:05:22 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -30,6 +30,7 @@ #include <pthread.h> #include "rthread.h" +#include "cancel.h" /* in libc/include */ static struct _spinlock static_init_lock = _SPINLOCK_UNLOCKED; @@ -290,12 +291,14 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, { pthread_cond_t cond; struct pthread_mutex *mutex = (struct pthread_mutex *)*mutexp; - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self = tib->tib_thread; pthread_t next; int mutex_count; int canceled = 0; int rv = 0; int error; + PREP_CANCEL_POINT(tib); if (!*condp) if ((error = pthread_cond_init(condp, NULL))) @@ -322,7 +325,7 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, abstime->tv_nsec >= 1000000000) return (EINVAL); - _enter_delayed_cancel(self); + ENTER_DELAYED_CANCEL_POINT(tib, self); _spinlock(&cond->lock); @@ -333,7 +336,7 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, } else if (cond->mutex != mutex) { assert(cond->mutex == mutex); _spinunlock(&cond->lock); - _leave_delayed_cancel(self, 1); + LEAVE_CANCEL_POINT_INNER(tib, 1); return (EINVAL); } else assert(! TAILQ_EMPTY(&cond->waiters)); @@ -376,7 +379,8 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, * cancellation) then we should just go back to * sleep without changing state (timeouts, etc). */ - if (error == EINTR && !IS_CANCELED(self)) { + if (error == EINTR && (tib->tib_canceled == 0 || + (tib->tib_cantcancel & CANCEL_DISABLED))) { _spinlock(&mutex->lock); continue; } @@ -388,7 +392,7 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, * we'll no longer time out or be cancelable. */ abstime = NULL; - _leave_delayed_cancel(self, 0); + LEAVE_CANCEL_POINT_INNER(tib, 0); /* * If we're no longer in the condvar's queue then @@ -432,7 +436,7 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, mutex->count = mutex_count; _spinunlock(&mutex->lock); - _leave_delayed_cancel(self, canceled); + LEAVE_CANCEL_POINT_INNER(tib, canceled); return (rv); } @@ -442,11 +446,13 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) { pthread_cond_t cond; struct pthread_mutex *mutex = (struct pthread_mutex *)*mutexp; - pthread_t self = pthread_self(); + struct tib *tib = TIB_GET(); + pthread_t self = tib->tib_thread; pthread_t next; int mutex_count; int canceled = 0; int error; + PREP_CANCEL_POINT(tib); if (!*condp) if ((error = pthread_cond_init(condp, NULL))) @@ -469,7 +475,7 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) abort(); } - _enter_delayed_cancel(self); + ENTER_DELAYED_CANCEL_POINT(tib, self); _spinlock(&cond->lock); @@ -480,7 +486,7 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) } else if (cond->mutex != mutex) { assert(cond->mutex == mutex); _spinunlock(&cond->lock); - _leave_delayed_cancel(self, 1); + LEAVE_CANCEL_POINT_INNER(tib, 1); return (EINVAL); } else assert(! TAILQ_EMPTY(&cond->waiters)); @@ -512,7 +518,8 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) * cancellation) then we should just go back to * sleep without changing state (timeouts, etc). */ - if (error == EINTR && !IS_CANCELED(self)) { + if (error == EINTR && (tib->tib_canceled == 0 || + (tib->tib_cantcancel & CANCEL_DISABLED))) { _spinlock(&mutex->lock); continue; } @@ -523,7 +530,7 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) * be staying in the condvar queue and we'll no * longer be cancelable. */ - _leave_delayed_cancel(self, 0); + LEAVE_CANCEL_POINT_INNER(tib, 0); /* * If we're no longer in the condvar's queue then @@ -565,7 +572,7 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) mutex->count = mutex_count; _spinunlock(&mutex->lock); - _leave_delayed_cancel(self, canceled); + LEAVE_CANCEL_POINT_INNER(tib, canceled); return (0); } diff --git a/lib/librthread/shlib_version b/lib/librthread/shlib_version index 83b24802061..629f8a9fc41 100644 --- a/lib/librthread/shlib_version +++ b/lib/librthread/shlib_version @@ -1,2 +1,2 @@ -major=21 +major=22 minor=0 diff --git a/lib/librthread/tcb.h b/lib/librthread/tcb.h deleted file mode 100644 index 12c5ec8fa63..00000000000 --- a/lib/librthread/tcb.h +++ /dev/null @@ -1,144 +0,0 @@ -/* $OpenBSD: tcb.h,v 1.6 2013/02/15 22:01:24 guenther Exp $ */ -/* - * Copyright (c) 2011 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 _TCB_H_ -#define _TCB_H_ - -/* - * We define the structure for the TCB, plus three macros: - * TCB_THREAD() - * Expands to a pointer-to-pthread rvalue that points - * to this thread's struct pthread - * TCB_ERRNOPTR() - * Expands to a pointer-to-int lvalue that points to - * this thread's errno - * TCB_INIT(tcb, thread, errnoptr) - * Expands to a code to initialize the TCB pointed to by - * its first argument - * - * <machine/tcb.h> must define the TLS_VARIANT macro. If it defines - * that to 1, then may also defined the macro - * THREAD_ERRNOPTR_OFFSET - * Byte offset in struct pthread of the pointer to the - * thread's errno - * - * By default, we get and set the TCB pointer for a thread using the - * __get_tcb() and __set_tcb() syscalls. If there's a faster way to do - * either of those, <machine/tcb.h> should define the macros - * TCB_SET(tcb) - * Set the TCB pointer for this thread - * TCB_GET() - * Return the TCB pointer for this thread - * If it defines TCB_GET, then it must also define: - * TCB_GET_MEMBER(member) - * Return the pointer in the 'member' slot in the TCB - */ - -#include <machine/tcb.h> - -#include <stddef.h> - -struct pthread; - -void *__get_tcb(void); -void __set_tcb(void *); - -#ifdef TCB_GET_MEMBER -#define TCB_THREAD() ((struct pthread *)TCB_GET_MEMBER(tcb_thread)) -#else -#define TCB_THREAD() \ - (((struct thread_control_block *)__get_tcb())->tcb_thread) -#endif - - -#if TLS_VARIANT == 1 -/* - * Small TCB, with TLS data after the TCB. - * Errno pointer stored in struct pthread - */ - -struct thread_control_block { - void *tcb_dtv; /* internal to the runtime linker */ - struct pthread *tcb_thread; -}; - -#ifndef THREAD_ERRNOPTR_OFFSET -# define THREAD_ERRNOPTR_OFFSET offsetof(struct pthread, errno_ptr) -#endif -#define __ERRNOPTR(thread) \ - (((int **)(thread))[THREAD_ERRNOPTR_OFFSET / sizeof(int *)]) -#define TCB_ERRNOPTR() \ - __ERRNOPTR(TCB_THREAD()) -#define TCB_INIT(tcb, thread, errnoptr) \ - do { \ - (tcb)->tcb_dtv = 0; \ - (tcb)->tcb_thread = (thread); \ - __ERRNOPTR(thread) = (errnoptr); \ - } while (0) - - -#elif TLS_VARIANT == 2 -/* - * Large TCB, with TLS data before the TCB (i.e., negative offsets) - * Errno pointer stored in the TCB - */ - -struct thread_control_block { - struct thread_control_block *__tcb_self; - void *tcb_dtv; /* internal to the runtime linker */ - struct pthread *tcb_thread; - int *__tcb_errno; -}; - -#ifdef TCB_GET_MEMBER -#define TCB_ERRNOPTR() ((int *)TCB_GET_MEMBER(__tcb_errno)) -#else -#define TCB_ERRNOPTR() \ - (((struct thread_control_block *)__get_tcb())->__tcb_errno) -#endif -#define TCB_INIT(tcb, thread, errnoptr) \ - do { \ - (tcb)->__tcb_self = (tcb); \ - (tcb)->tcb_dtv = 0; \ - (tcb)->tcb_thread = (thread); \ - (tcb)->__tcb_errno = (errnoptr); \ - } while (0) - - -#else -# error "unknown TLS variant" -#endif - - -/* If there isn't a better way, use the default */ -#ifndef TCB_SET -#define TCB_SET(tcb) __set_tcb(tcb) -#endif - -#if 0 -void *_rtld_allocate_tls(void *, size_t, size_t); -void _rtld_free_tls(void *, size_t, size_t); -#else -/* - * XXX Until we have these in ld.so and support __thread, just use - * malloc/free. The main thread's TCB cannot be allocated or freed with these. - */ -#define _rtld_allocate_tls(old, size, align) malloc(size) -#define _rtld_free_tls(old, size, align) free(old) -#endif - -#endif /* _TCB_H_ */ diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile index 50be47137fd..5c6da586143 100644 --- a/libexec/ld.so/Makefile +++ b/libexec/ld.so/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.60 2015/08/31 02:53:57 guenther Exp $ +# $OpenBSD: Makefile,v 1.61 2016/05/07 19:05:23 guenther Exp $ SUBDIR=ldconfig ldd MAN= ld.so.1 @@ -19,7 +19,7 @@ VPATH=${.CURDIR}/../../lib/libc/string SRCS= ldasm.S boot.c loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c SRCS+= path.c util.c sod.c strsep.c strtol.c dir.c library_subr.c dl_prebind.c SRCS+= dl_realpath.c dl_uname.c dl_dirname.c strlcat.c strlen.c trace.c -SRCS+= malloc.c reallocarray.c +SRCS+= malloc.c reallocarray.c tib.c .if (${MACHINE_ARCH} == "i386") SRCS+= library_mquery.c diff --git a/libexec/ld.so/Symbols.map b/libexec/ld.so/Symbols.map index e167f603dfe..795caac6108 100644 --- a/libexec/ld.so/Symbols.map +++ b/libexec/ld.so/Symbols.map @@ -14,6 +14,10 @@ /* alias in reserved namespace for libpthread to use */ _dlctl; + /* TLS related bits */ + _dl_allocate_tib; + _dl_free_tib; + /* looked up by gdb */ _dl_bind; _dl_debug_state; diff --git a/libexec/ld.so/alpha/ldasm.S b/libexec/ld.so/alpha/ldasm.S index f71de97c74d..952b0c7e174 100644 --- a/libexec/ld.so/alpha/ldasm.S +++ b/libexec/ld.so/alpha/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.34 2016/03/21 22:41:28 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.35 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -317,6 +317,7 @@ DL_SYSCALL(sendsyslog) DL_SYSCALL(pledge) DL_SYSCALL(gettimeofday) DL_SYSCALL_NOERR(issetugid) +DL_SYSCALL_NOERR(getthrid) DL_SYSCALL(lstat) DL_SYSCALL(mprotect) DL_SYSCALL(munmap) @@ -324,6 +325,7 @@ DL_SYSCALL(open) DL_SYSCALL(read) DL_SYSCALL(readlink) DL_SYSCALL2(_syscall,__syscall) +DL_SYSCALL2_NOERR(set_tcb,__set_tcb) DL_SYSCALL(sysctl) DL_SYSCALL(utrace) DL_SYSCALL(write) diff --git a/libexec/ld.so/alpha/syscall.h b/libexec/ld.so/alpha/syscall.h index df364c4715e..8005b3e3307 100644 --- a/libexec/ld.so/alpha/syscall.h +++ b/libexec/ld.so/alpha/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.32 2016/03/21 22:41:28 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.33 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -41,6 +41,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); void * _dl_mmap(void *, size_t, int, int, int, off_t); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/amd64/ldasm.S b/libexec/ld.so/amd64/ldasm.S index 2dc0fe096ed..922c1b8aea2 100644 --- a/libexec/ld.so/amd64/ldasm.S +++ b/libexec/ld.so/amd64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.23 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.24 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -87,6 +87,7 @@ DL_SYSCALL(read) DL_SYSCALL(write) DL_SYSCALL(close) DL_SYSCALL(issetugid) +DL_SYSCALL(getthrid) DL_SYSCALL(getdents) DL_SYSCALL(mprotect) DL_SYSCALL(munmap) diff --git a/libexec/ld.so/amd64/syscall.h b/libexec/ld.so/amd64/syscall.h index 26ebf6c4092..270e9bb2468 100644 --- a/libexec/ld.so/amd64/syscall.h +++ b/libexec/ld.so/amd64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.20 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/arm/ldasm.S b/libexec/ld.so/arm/ldasm.S index 36f1ab62bc2..80365b9b9c8 100644 --- a/libexec/ld.so/arm/ldasm.S +++ b/libexec/ld.so/arm/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.21 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.22 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -113,6 +113,7 @@ _dl_exit: b 1b DL_SYSCALL(issetugid) +DL_SYSCALL(getthrid) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(munmap) DL_SYSCALL(mprotect) @@ -129,6 +130,7 @@ DL_SYSCALL(sendsyslog) DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) +DL_SYSCALL2(set_tcb,__set_tcb) DL_SYSCALL(getdents) diff --git a/libexec/ld.so/arm/syscall.h b/libexec/ld.so/arm/syscall.h index d9ecc3b2c3a..d74a9e26c3d 100644 --- a/libexec/ld.so/arm/syscall.h +++ b/libexec/ld.so/arm/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.20 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/hppa/ldasm.S b/libexec/ld.so/hppa/ldasm.S index 59e5902e676..1663eb65f04 100644 --- a/libexec/ld.so/hppa/ldasm.S +++ b/libexec/ld.so/hppa/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.20 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -182,6 +182,12 @@ ENTRY(_dl_issetugid,0) nop EXIT(_dl_issetugid) +ENTRY(_dl_getthrid,0) + SYSCALL(getthrid) + bv r0(rp) + nop +EXIT(_dl_getthrid) + ENTRY(_dl__syscall,0) SYSCALL(__syscall) bv r0(rp) @@ -278,6 +284,12 @@ ENTRY(_dl_sendsyslog,0) nop EXIT(_dl_sendsyslog) +ENTRY(_dl_set_tcb,0) + SYSCALL(__set_tcb) + bv r0(rp) + nop +EXIT(_dl_set_tcb) + ENTRY(_dl_pledge,0) SYSCALL(pledge) bv r0(rp) diff --git a/libexec/ld.so/hppa/syscall.h b/libexec/ld.so/hppa/syscall.h index 26ebf6c4092..270e9bb2468 100644 --- a/libexec/ld.so/hppa/syscall.h +++ b/libexec/ld.so/hppa/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.20 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/i386/ldasm.S b/libexec/ld.so/i386/ldasm.S index 86c5f0d7376..621a1c503be 100644 --- a/libexec/ld.so/i386/ldasm.S +++ b/libexec/ld.so/i386/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.25 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.26 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -109,6 +109,7 @@ _dl_exit: DL_SYSCALL(issetugid) +DL_SYSCALL(getthrid) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(munmap) DL_SYSCALL(mprotect) @@ -126,6 +127,7 @@ DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) DL_SYSCALL(getdents) +DL_SYSCALL2(set_tcb,__set_tcb) .L_cerr: /* error: result = -errno; - handled here. */ diff --git a/libexec/ld.so/i386/syscall.h b/libexec/ld.so/i386/syscall.h index 811c8acbdae..9b8a4bc352a 100644 --- a/libexec/ld.so/i386/syscall.h +++ b/libexec/ld.so/i386/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.24 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.25 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c index 9a945b37b37..5318af38592 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.74 2016/03/20 02:29:51 guenther Exp $ */ +/* $OpenBSD: library.c,v 1.75 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -104,6 +104,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) Elf_Dyn *dynp = NULL; Elf_Ehdr *ehdr; Elf_Phdr *phdp; + Elf_Phdr *ptls = NULL; struct stat sb; void *prebind_data; @@ -164,6 +165,17 @@ _dl_tryload_shlib(const char *libname, int type, int flags) dynp = (Elf_Dyn *)phdp->p_vaddr; break; case PT_TLS: + if (phdp->p_filesz > phdp->p_memsz) { + _dl_printf("%s: invalid tls data in %s.\n", + __progname, libname); + _dl_close(libfile); + _dl_errno = DL_CANT_LOAD_OBJ; + return(0); + } + if (!_dl_tib_static_done) { + ptls = phdp; + break; + } _dl_printf("%s: unsupported TLS program header in %s\n", __progname, libname); _dl_close(libfile); @@ -283,6 +295,8 @@ _dl_tryload_shlib(const char *libname, int type, int flags) object->inode = sb.st_ino; object->obj_flags |= flags; _dl_set_sod(object->load_name, &object->sod); + if (ptls != NULL && ptls->p_memsz) + _dl_set_tls(object, ptls, libaddr, libname); } else { _dl_munmap((void *)libaddr, maxva - minva); _dl_load_list_free(load_list); diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 48151f6d4fa..870f54d7065 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.52 2016/03/20 02:29:51 guenther Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.53 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -108,6 +108,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) Elf_Phdr *phdp; Elf_Addr load_end = 0; Elf_Addr align = _dl_pagesz - 1, off, size; + Elf_Phdr *ptls = NULL; struct stat sb; void *prebind_data; char hbuf[4096]; @@ -205,6 +206,17 @@ _dl_tryload_shlib(const char *libname, int type, int flags) dynp = (Elf_Dyn *)phdp->p_vaddr; break; case PT_TLS: + if (phdp->p_filesz > phdp->p_memsz) { + _dl_printf("%s: invalid tls data in %s.\n", + __progname, libname); + _dl_close(libfile); + _dl_errno = DL_CANT_LOAD_OBJ; + return(0); + } + if (!_dl_tib_static_done) { + ptls = phdp; + break; + } _dl_printf("%s: unsupported TLS program header in %s\n", __progname, libname); _dl_close(libfile); @@ -309,6 +321,9 @@ retry: object->inode = sb.st_ino; object->obj_flags |= flags; _dl_set_sod(object->load_name, &object->sod); + if (ptls != NULL && ptls->p_memsz) + _dl_set_tls(object, ptls, (Elf_Addr)lowld->start, + libname); } else { _dl_load_list_free(lowld); } diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index e5e4ebebaab..609103d4c53 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.158 2016/03/24 05:27:19 guenther Exp $ */ +/* $OpenBSD: loader.c,v 1.159 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -391,6 +391,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) int failed; struct dep_node *n; Elf_Addr minva, maxva, exe_loff; + Elf_Phdr *ptls = NULL; int align; _dl_setup_env(argv[0], envp); @@ -480,9 +481,12 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) } break; case PT_TLS: - _dl_printf("%s: unsupported TLS program header\n", - __progname); - _dl_exit(1); + if (phdp->p_filesz > phdp->p_memsz) { + _dl_printf("%s: invalid tls data.\n", + __progname); + _dl_exit(5); + } + ptls = phdp; break; } phdp++; @@ -492,6 +496,10 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) exe_obj->load_size = maxva - minva; _dl_set_sod(exe_obj->load_name, &exe_obj->sod); + /* TLS bits in the base executable */ + if (ptls != NULL && ptls->p_memsz) + _dl_set_tls(exe_obj, ptls, exe_loff, NULL); + n = _dl_malloc(sizeof *n); if (n == NULL) _dl_exit(5); @@ -522,6 +530,9 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) dyn_obj->status |= STAT_RELOC_DONE; _dl_set_sod(dyn_obj->load_name, &dyn_obj->sod); + /* calculate the offsets for static TLS allocations */ + _dl_allocate_tls_offsets(); + /* * Everything should be in place now for doing the relocation * and binding. Call _dl_rtld to do the job. Fingers crossed. @@ -551,6 +562,9 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) _dl_loading_object = NULL; + /* set up the TIB for the initial thread */ + _dl_allocate_first_tib(); + _dl_fixup_user_env(); /* diff --git a/libexec/ld.so/m88k/ldasm.S b/libexec/ld.so/m88k/ldasm.S index c5ce9333855..ca2c33a854d 100644 --- a/libexec/ld.so/m88k/ldasm.S +++ b/libexec/ld.so/m88k/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.18 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.19 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -173,6 +173,9 @@ ENTRY(_dl_exit) DL_SYSCALL(issetugid) jmp %r1 +DL_SYSCALL(getthrid) + jmp %r1 + DL_SYSCALL2(_syscall,__syscall) jmp %r1 diff --git a/libexec/ld.so/m88k/syscall.h b/libexec/ld.so/m88k/syscall.h index f67e610c9d2..d1de184c957 100644 --- a/libexec/ld.so/m88k/syscall.h +++ b/libexec/ld.so/m88k/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.16 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.17 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); diff --git a/libexec/ld.so/mips64/ldasm.S b/libexec/ld.so/mips64/ldasm.S index ec2e63e06af..a3172abfb03 100644 --- a/libexec/ld.so/mips64/ldasm.S +++ b/libexec/ld.so/mips64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.18 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.19 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -28,6 +28,7 @@ #include <machine/asm.h> #include <sys/syscall.h> +#define __cerror _dl_cerror #include <SYS.h> /* Stack at this stage is: @@ -155,6 +156,7 @@ DL_SYSCALL(sendsyslog) DL_SYSCALL(pledge) DL_SYSCALL(gettimeofday) DL_SYSCALL_NOERR(issetugid) +DL_SYSCALL_NOERR(getthrid) DL_SYSCALL(lstat) DL_SYSCALL(mprotect) DL_SYSCALL(munmap) @@ -162,6 +164,7 @@ DL_SYSCALL(open) DL_SYSCALL(read) DL_SYSCALL(readlink) DL_SYSCALL2(_syscall,__syscall) +DL_SYSCALL2_NOERR(set_tcb,__set_tcb) DL_SYSCALL(sysctl) DL_SYSCALL(utrace) DL_SYSCALL(write) diff --git a/libexec/ld.so/mips64/syscall.h b/libexec/ld.so/mips64/syscall.h index 30fe1458a98..8b85bed5124 100644 --- a/libexec/ld.so/mips64/syscall.h +++ b/libexec/ld.so/mips64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.22 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.23 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -45,12 +45,14 @@ int _dl_getcwd(char *, size_t); ssize_t _dl_getdents(int, char *, size_t); int _dl_gettimeofday(struct timeval *, struct timezone *); int _dl_issetugid(void); +int _dl_getthrid(void); int _dl_lstat(const char *, struct stat *); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); int _dl_open(const char *, int); ssize_t _dl_read(int, const char *, size_t); ssize_t _dl_readlink(const char *, char *, size_t); +void _dl_set_tcb(void *); int _dl_pledge(const char *, const char **); long _dl__syscall(quad_t, ...); int _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t); diff --git a/libexec/ld.so/powerpc/ldasm.S b/libexec/ld.so/powerpc/ldasm.S index 0b2c9753d58..1ad7d009259 100644 --- a/libexec/ld.so/powerpc/ldasm.S +++ b/libexec/ld.so/powerpc/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.28 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.29 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -151,6 +151,7 @@ DL_SYSCALL(sendsyslog) DL_SYSCALL(pledge) DL_SYSCALL(gettimeofday) DL_SYSCALL_NOERR(issetugid) +DL_SYSCALL_NOERR(getthrid) DL_SYSCALL(lstat) DL_SYSCALL(mmap) DL_SYSCALL(mprotect) diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h index 24da619b6eb..42dbcfd57c2 100644 --- a/libexec/ld.so/powerpc/syscall.h +++ b/libexec/ld.so/powerpc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.40 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.41 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -45,6 +45,7 @@ int _dl_getcwd(char *, size_t); ssize_t _dl_getdents(int, char *, size_t); int _dl_gettimeofday(struct timeval *, struct timezone *); int _dl_issetugid(void); +int _dl_getthrid(void); int _dl_lstat(const char *, struct stat *); void * _dl_mmap(void *, size_t, int, int, int, off_t); int _dl_mprotect(const void *, size_t, int); diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 8a1b2845dfb..7881b4a89a5 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.76 2016/03/20 02:29:51 guenther Exp $ */ +/* $OpenBSD: resolve.h,v 1.77 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -143,6 +143,13 @@ struct elf_object { dev_t dev; ino_t inode; + /* thread local storage info */ + Elf_Addr tls_fsize; + Elf_Addr tls_msize; + Elf_Addr tls_align; + const void *tls_static_data; + int tls_offset; + /* generation number of last grpsym insert on this object */ unsigned int grpsym_gen; @@ -245,6 +252,13 @@ void _dl_trace_setup(char **); void _dl_trace_object_setup(elf_object_t *); int _dl_trace_plt(const elf_object_t *, const char *); +/* tib.c */ +void _dl_allocate_tls_offsets(void); +void _dl_allocate_first_tib(void); +void _dl_set_tls(elf_object_t *_object, Elf_Phdr *_ptls, Elf_Addr _libaddr, + const char *_libname); +extern int _dl_tib_static_done; + extern elf_object_t *_dl_objects; extern elf_object_t *_dl_last_object; diff --git a/libexec/ld.so/sh/ldasm.S b/libexec/ld.so/sh/ldasm.S index cafd90ea8f8..095533c726f 100644 --- a/libexec/ld.so/sh/ldasm.S +++ b/libexec/ld.so/sh/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.23 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.24 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2006 Dale Rahn @@ -172,6 +172,7 @@ _dl_exit: nop DL_SYSCALL(issetugid) +DL_SYSCALL(getthrid) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(munmap) DL_SYSCALL(mprotect) @@ -194,6 +195,7 @@ DL_SYSCALL(sendsyslog) DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) +DL_SYSCALL2_NOERR(set_tcb,__set_tcb) DL_SYSCALL(getdents) diff --git a/libexec/ld.so/sh/syscall.h b/libexec/ld.so/sh/syscall.h index e5069e066af..c98b8e11cec 100644 --- a/libexec/ld.so/sh/syscall.h +++ b/libexec/ld.so/sh/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.18 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.19 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); @@ -58,6 +59,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +void _dl_set_tcb(void *); static inline off_t _dl_lseek(int fildes, off_t offset, int whence) diff --git a/libexec/ld.so/sparc/ldasm.S b/libexec/ld.so/sparc/ldasm.S index 3bcf14814fd..0d5788bb01c 100644 --- a/libexec/ld.so/sparc/ldasm.S +++ b/libexec/ld.so/sparc/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.30 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.31 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Jason L. Wright (jason@thought.net) @@ -176,6 +176,18 @@ _dl_issetugid: .section ".text" .align 4 + .global _dl_getthrid + .type _dl_getthrid,@function +_dl_getthrid: + mov SYS_getthrid | SYSCALL_G2RFLAG, %g1 ! call sys_getthrid + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 .global _dl__syscall .type _dl__syscall,@function _dl__syscall: diff --git a/libexec/ld.so/sparc/syscall.h b/libexec/ld.so/sparc/syscall.h index df5293ba4ea..a1f1cff714c 100644 --- a/libexec/ld.so/sparc/syscall.h +++ b/libexec/ld.so/sparc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.25 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.26 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); diff --git a/libexec/ld.so/sparc64/ldasm.S b/libexec/ld.so/sparc64/ldasm.S index 47949f6d7c5..d0f6aa7b2c5 100644 --- a/libexec/ld.so/sparc64/ldasm.S +++ b/libexec/ld.so/sparc64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.42 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: ldasm.S,v 1.43 2016/05/07 19:05:23 guenther Exp $ */ /* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */ /* @@ -230,6 +230,13 @@ _ENTRY(_dl_issetugid) retl sub %g0, %o0, %o0 ! error: result = -errno +_ENTRY(_dl_getthrid) + mov SYS_getthrid | SYSCALL_G2RFLAG, %g1 ! call sys_getthrid + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + _ENTRY(_dl__syscall) mov SYS___syscall | SYSCALL_G2RFLAG, %g1 ! call sys___syscall add %o7, 8, %g2 ! just return on success diff --git a/libexec/ld.so/sparc64/syscall.h b/libexec/ld.so/sparc64/syscall.h index 0abb05b7314..6fc3aa31934 100644 --- a/libexec/ld.so/sparc64/syscall.h +++ b/libexec/ld.so/sparc64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.32 2016/03/21 22:41:29 bluhm Exp $ */ +/* $OpenBSD: syscall.h,v 1.33 2016/05/07 19:05:23 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -42,6 +42,7 @@ int _dl_close(int); __dead int _dl_exit(int); int _dl_issetugid(void); +int _dl_getthrid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, size_t, int); int _dl_munmap(const void *, size_t); diff --git a/libexec/ld.so/tib.c b/libexec/ld.so/tib.c new file mode 100644 index 00000000000..ed190ea90ad --- /dev/null +++ b/libexec/ld.so/tib.c @@ -0,0 +1,186 @@ +/* + * 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. + */ + +/* + * Thread Information Block (TIB) and Thread Local Storage (TLS) handling + * (the TCB, Thread Control Block, is part of the TIB) + */ + +#define _DYN_LOADER + +#include <sys/types.h> +#include <sys/exec_elf.h> + +#include <tib.h> + +#include "archdep.h" +#include "resolve.h" +#include "util.h" +#include "syscall.h" + +/* If we need the syscall, use our local syscall definition */ +#define __set_tcb(tcb) _dl_set_tcb(tcb) + + +static int static_tls_size; + +int _dl_tib_static_done; + +/* + * 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) +{ + char *base; + struct tib *tib; + char *thread = NULL; + struct elf_object *obj; + +#if TLS_VARIANT == 1 + /* round up the extra size to align the tib after it */ + extra = ELF_ROUND(extra, sizeof(void *)); + base = _dl_malloc(extra + sizeof *tib + static_tls_size); + tib = (struct tib *)(base + extra); + if (extra) + thread = base; +#define TLS_ADDR(tibp, offset) ((char *)(tibp) + sizeof(struct tib) + (offset)) + +#elif TLS_VARIANT == 2 + /* round up the tib size to align the extra area after it */ + base = _dl_malloc(ELF_ROUND(sizeof *tib, TIB_EXTRA_ALIGN) + + extra + static_tls_size); + tib = (struct tib *)(base + static_tls_size); + if (extra) + thread = (char *)tib + ELF_ROUND(sizeof *tib, TIB_EXTRA_ALIGN); +#define TLS_ADDR(tibp, offset) ((char *)(tibp) - (offset)) + +#endif + + for (obj = _dl_objects; obj != NULL; obj = obj->next) { + if (obj->tls_msize != 0) { + char *addr = TLS_ADDR(tib, obj->tls_offset); + + _dl_memset(addr + obj->tls_fsize, 0, + obj->tls_msize - obj->tls_fsize); + if (obj->tls_static_data != NULL) + _dl_bcopy(obj->tls_static_data, addr, + obj->tls_fsize); + DL_DEB(("\t%s has index %u addr %p msize %u fsize %u\n", + obj->load_name, obj->tls_offset, + (void *)addr, obj->tls_msize, obj->tls_fsize)); + } + } + + TIB_INIT(tib, NULL, thread); + + DL_DEB(("tib new=%p\n", (void *)tib)); + + return (tib); +} + +void +_dl_free_tib(void *tib, size_t extra) +{ + 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 + + DL_DEB(("free tib=%p\n", (void *)tib)); + _dl_free((char *)tib - tib_offset); +} + + +/* + * Record what's necessary for handling TLS for an object. + */ +void +_dl_set_tls(elf_object_t *object, Elf_Phdr *ptls, Elf_Addr libaddr, + const char *libname) +{ + if (ptls->p_vaddr != 0 && ptls->p_filesz != 0) + object->tls_static_data = (void *)(ptls->p_vaddr + libaddr); + object->tls_fsize = ptls->p_filesz; + object->tls_msize = ptls->p_memsz; + object->tls_align = ptls->p_align; + + DL_DEB(("tls %x %x %x %x\n", + object->tls_static_data, object->tls_fsize, object->tls_msize, + object->tls_align)); +} + +static inline Elf_Addr +allocate_tls_offset(Elf_Addr msize, Elf_Addr align) +{ + Elf_Addr offset; + +#if TLS_VARIANT == 1 + /* round up to the required alignment, then allocate the space */ + offset = ELF_ROUND(static_tls_size, align); + static_tls_size += msize; +#elif TLS_VARIANT == 2 + /* + * allocate the space, then round up to the alignment + * (these are negative offsets, so rounding up really rounds the + * address down) + */ + static_tls_size = ELF_ROUND(static_tls_size + msize, align); + offset = static_tls_size; +#else +# error "unknown TLS_VARIANT" +#endif + return offset; +} + +/* + * Calculate the TLS offset for each object with static TLS. + */ +void +_dl_allocate_tls_offsets(void) +{ + struct elf_object *obj; + + for (obj = _dl_objects; obj != NULL; obj = obj->next) { + if (obj->tls_msize != 0) { + obj->tls_offset = allocate_tls_offset(obj->tls_msize, + obj->tls_align); + } + } + + /* no more static TLS allocations after this */ + _dl_tib_static_done = 1; +} + +/* + * Allocate the TIB + TLS for the initial thread. + */ +void +_dl_allocate_first_tib(void) +{ + struct tib *tib; + + tib = _dl_allocate_tib(0); + tib->tib_tid = _dl_getthrid(); + + TCB_SET(TIB_TO_TCB(tib)); +} diff --git a/sys/arch/powerpc/include/tcb.h b/sys/arch/powerpc/include/tcb.h index c0aa2967e47..445502196f5 100644 --- a/sys/arch/powerpc/include/tcb.h +++ b/sys/arch/powerpc/include/tcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcb.h,v 1.3 2014/03/29 18:09:30 guenther Exp $ */ +/* $OpenBSD: tcb.h,v 1.4 2016/05/07 19:05:21 guenther Exp $ */ /* * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org> @@ -31,6 +31,9 @@ /* ELF TLS ABI calls for small TCB, with static TLS data after it */ #define TLS_VARIANT 1 +/* powerpc offsets the TCB pointer 0x7000 bytes after the data */ +#define TCB_OFFSET 0x7000 + #if 0 /* XXX perhaps use the gcc global register extension? */ struct thread_control_block; __register__ struct thread_control_block *__tcb __asm__ ("%r2"); |