summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/w_fork.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2016-05-07 19:05:21 +0000
committerguenther <guenther@openbsd.org>2016-05-07 19:05:21 +0000
commitfe38b55cb0aae270de3f844146814682e8cd345c (patch)
tree9825cc8aa96314e8e79ea1802ccbc9349772680b /lib/libc/sys/w_fork.c
parentImplement ACPI 5.0 GeneralPurposeIo OpRegion support. This basically allows (diff)
downloadwireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.tar.xz
wireguard-openbsd-fe38b55cb0aae270de3f844146814682e8cd345c.zip
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
Diffstat (limited to 'lib/libc/sys/w_fork.c')
-rw-r--r--lib/libc/sys/w_fork.c26
1 files changed, 19 insertions, 7 deletions
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);