Module Name: src
Committed By: christos
Date: Fri Feb 28 16:00:27 UTC 2025
Modified Files:
src/lib/libc/gen: pthread_atfork.c
Log Message:
PR/59112: Martin Husemann: switch to using mmap instead of malloc
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/gen/pthread_atfork.c
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/pthread_atfork.c
diff -u src/lib/libc/gen/pthread_atfork.c:1.18 src/lib/libc/gen/pthread_atfork.c:1.19
--- src/lib/libc/gen/pthread_atfork.c:1.18 Sat Jan 20 09:52:47 2024
+++ src/lib/libc/gen/pthread_atfork.c Fri Feb 28 11:00:26 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_atfork.c,v 1.18 2024/01/20 14:52:47 christos Exp $ */
+/* $NetBSD: pthread_atfork.c,v 1.19 2025/02/28 16:00:26 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,15 +31,17 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pthread_atfork.c,v 1.18 2024/01/20 14:52:47 christos Exp $");
+__RCSID("$NetBSD: pthread_atfork.c,v 1.19 2025/02/28 16:00:26 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
+#include <sys/queue.h>
+#include <sys/mman.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
-#include <sys/queue.h>
+
#include "extern.h"
#include "reentrant.h"
@@ -78,11 +80,14 @@ static struct atfork_callback_q childq =
static struct atfork_callback *
af_alloc(void)
{
+ void *rv;
if (atfork_builtin.fn == NULL)
return &atfork_builtin;
- return malloc(sizeof(atfork_builtin));
+ rv = mmap(0, sizeof(atfork_builtin), PROT_READ|PROT_WRITE, MAP_PRIVATE,
+ -1, 0);
+ return rv == MAP_FAILED ? NULL : rv;
}
static void
@@ -90,7 +95,7 @@ af_free(struct atfork_callback *af)
{
if (af != &atfork_builtin)
- free(af);
+ munmap(af, sizeof(*af));
}
int