Module Name: src
Committed By: riastradh
Date: Tue Mar 4 00:33:01 UTC 2025
Modified Files:
src/lib/libc/gen: arc4random.c pthread_atfork.c
Removed Files:
src/lib/libc/include: atfork.h
Log Message:
Revert __libc_atfork addition.
This reverts the following revisions:
lib/libc/gen/arc4random.c 1.40-41 (but not 1.42 which is independent)
lib/libc/gen/pthread_atfork.c 1.24
lib/libc/include/atfork.h 1.1
This additionally updates the comments in arc4random.c to reflect the
current state.
Requested by kre:
https://mail-index.netbsd.org/source-changes-d/2025/03/03/msg014388.html
Since the new symbol __libc_atfork has not been used outside libc,
this poses no ABI compatibility issues.
To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/libc/gen/arc4random.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/gen/pthread_atfork.c
cvs rdiff -u -r1.1 -r0 src/lib/libc/include/atfork.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/gen/arc4random.c
diff -u src/lib/libc/gen/arc4random.c:1.42 src/lib/libc/gen/arc4random.c:1.43
--- src/lib/libc/gen/arc4random.c:1.42 Sun Mar 2 22:54:11 2025
+++ src/lib/libc/gen/arc4random.c Tue Mar 4 00:33:01 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: arc4random.c,v 1.42 2025/03/02 22:54:11 riastradh Exp $ */
+/* $NetBSD: arc4random.c,v 1.43 2025/03/04 00:33:01 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -42,16 +42,17 @@
*
* The arc4random(3) API may abort the process if:
*
- * (a) the crypto self-test fails, or
- * (b) sysctl(KERN_ARND) fails when reseeding the PRNG.
+ * (a) the crypto self-test fails,
+ * (b) pthread_atfork fails, or
+ * (c) sysctl(KERN_ARND) fails when reseeding the PRNG.
*
- * The crypto self-test occurs only once, on the first use of any of
- * the arc4random(3) API. KERN_ARND is unlikely to fail later unless
- * the kernel is seriously broken.
+ * The crypto self-test and pthread_atfork occur only once, on the
+ * first use of any of the arc4random(3) API. KERN_ARND is unlikely to
+ * fail later unless the kernel is seriously broken.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: arc4random.c,v 1.42 2025/03/02 22:54:11 riastradh Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.43 2025/03/04 00:33:01 riastradh Exp $");
#include "namespace.h"
#include "reentrant.h"
@@ -72,7 +73,6 @@ __RCSID("$NetBSD: arc4random.c,v 1.42 20
#include <unistd.h>
#include "arc4random.h"
-#include "atfork.h"
#include "reentrant.h"
#ifdef __weak_alias
@@ -521,7 +521,6 @@ struct arc4random_global_state arc4rando
.initialized = false,
};
-static struct atfork_callback arc4random_atfork_prepare_cb;
static void
arc4random_atfork_prepare(void)
{
@@ -531,7 +530,6 @@ arc4random_atfork_prepare(void)
sizeof arc4random_global.prng);
}
-static struct atfork_callback arc4random_atfork_parent_cb;
static void
arc4random_atfork_parent(void)
{
@@ -539,7 +537,6 @@ arc4random_atfork_parent(void)
mutex_unlock(&arc4random_global.lock);
}
-static struct atfork_callback arc4random_atfork_child_cb;
static void
arc4random_atfork_child(void)
{
@@ -565,10 +562,10 @@ arc4random_initialize(void)
if (!arc4random_global.initialized) {
if (crypto_core_selftest() != 0)
abort();
- __libc_atfork(
- &arc4random_atfork_prepare_cb, &arc4random_atfork_prepare,
- &arc4random_atfork_parent_cb, &arc4random_atfork_parent,
- &arc4random_atfork_child_cb, &arc4random_atfork_child);
+ if (pthread_atfork(&arc4random_atfork_prepare,
+ &arc4random_atfork_parent, &arc4random_atfork_child)
+ != 0)
+ abort();
#ifdef _REENTRANT
if (thr_keycreate(&arc4random_global.thread_key,
&arc4random_tsd_destructor) == 0)
Index: src/lib/libc/gen/pthread_atfork.c
diff -u src/lib/libc/gen/pthread_atfork.c:1.24 src/lib/libc/gen/pthread_atfork.c:1.25
--- src/lib/libc/gen/pthread_atfork.c:1.24 Sun Mar 2 22:46:23 2025
+++ src/lib/libc/gen/pthread_atfork.c Tue Mar 4 00:33:01 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_atfork.c,v 1.24 2025/03/02 22:46:23 riastradh Exp $ */
+/* $NetBSD: pthread_atfork.c,v 1.25 2025/03/04 00:33:01 riastradh Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,18 +31,15 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pthread_atfork.c,v 1.24 2025/03/02 22:46:23 riastradh Exp $");
+__RCSID("$NetBSD: pthread_atfork.c,v 1.25 2025/03/04 00:33:01 riastradh Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
-#include <sys/queue.h>
-
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
-
-#include "atfork.h"
+#include <sys/queue.h>
#include "extern.h"
#include "reentrant.h"
@@ -57,6 +54,12 @@ __locked_fork(int *my_errno)
return __fork();
}
+struct atfork_callback {
+ SIMPLEQ_ENTRY(atfork_callback) next;
+ void (*fn)(void);
+};
+
+
/*
* Keep a cache for of 3, one for prepare, one for parent, one for child.
* This is so that we don't have to allocate memory for the call from the
@@ -102,53 +105,6 @@ af_free(struct atfork_callback *af)
free(af);
}
-static void
-__libc_atfork_locked(
- struct atfork_callback *restrict newprepare, void (*prepare)(void),
- struct atfork_callback *restrict newparent, void (*parent)(void),
- struct atfork_callback *restrict newchild, void (*child)(void))
-{
-
- /*
- * The order in which the functions are called is specified as
- * LIFO for the prepare handler and FIFO for the others; insert
- * at the head and tail as appropriate so that SIMPLEQ_FOREACH()
- * produces the right order.
- */
- if (prepare) {
- newprepare->fn = prepare;
- SIMPLEQ_INSERT_HEAD(&prepareq, newprepare, next);
- }
- if (parent) {
- newparent->fn = parent;
- SIMPLEQ_INSERT_TAIL(&parentq, newparent, next);
- }
- if (child) {
- newchild->fn = child;
- SIMPLEQ_INSERT_TAIL(&childq, newchild, next);
- }
-}
-
-void
-__libc_atfork(
- struct atfork_callback *restrict newprepare, void (*prepare)(void),
- struct atfork_callback *restrict newparent, void (*parent)(void),
- struct atfork_callback *restrict newchild, void (*child)(void))
-{
- sigset_t mask, omask;
-
- sigfillset(&mask);
- thr_sigsetmask(SIG_SETMASK, &mask, &omask);
-
- mutex_lock(&atfork_lock);
- __libc_atfork_locked(newprepare, prepare,
- newparent, parent,
- newchild, child);
- mutex_unlock(&atfork_lock);
-
- thr_sigsetmask(SIG_SETMASK, &omask, NULL);
-}
-
int
pthread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void))
@@ -169,6 +125,7 @@ pthread_atfork(void (*prepare)(void), vo
error = ENOMEM;
goto out;
}
+ newprepare->fn = prepare;
}
if (parent != NULL) {
@@ -179,6 +136,7 @@ pthread_atfork(void (*prepare)(void), vo
error = ENOMEM;
goto out;
}
+ newparent->fn = parent;
}
if (child != NULL) {
@@ -191,11 +149,21 @@ pthread_atfork(void (*prepare)(void), vo
error = ENOMEM;
goto out;
}
+ newchild->fn = child;
}
- __libc_atfork_locked(newprepare, prepare,
- newparent, parent,
- newchild, child);
+ /*
+ * The order in which the functions are called is specified as
+ * LIFO for the prepare handler and FIFO for the others; insert
+ * at the head and tail as appropriate so that SIMPLEQ_FOREACH()
+ * produces the right order.
+ */
+ if (prepare)
+ SIMPLEQ_INSERT_HEAD(&prepareq, newprepare, next);
+ if (parent)
+ SIMPLEQ_INSERT_TAIL(&parentq, newparent, next);
+ if (child)
+ SIMPLEQ_INSERT_TAIL(&childq, newchild, next);
error = 0;
out: mutex_unlock(&atfork_lock);