Rename __atomic_fork to __locked_fork and give it &errno as argument.
rtld and libc use different storage, so the initial version would incorrectly report the failure reason for fork(). There is still a small race condition inside ld.elf_so as it doesn't use thread-safe errno internally, but that's a more contained internal issue.
This commit is contained in:
parent
77abcafc06
commit
25a494ecc4
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: pthread_atfork.c,v 1.13 2020/04/16 14:39:58 joerg Exp $ */
|
/* $NetBSD: pthread_atfork.c,v 1.14 2020/04/19 01:06:15 joerg Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||||
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
__RCSID("$NetBSD: pthread_atfork.c,v 1.13 2020/04/16 14:39:58 joerg Exp $");
|
__RCSID("$NetBSD: pthread_atfork.c,v 1.14 2020/04/19 01:06:15 joerg Exp $");
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
@ -48,10 +48,10 @@ __weak_alias(fork, _fork)
|
|||||||
#endif /* __weak_alias */
|
#endif /* __weak_alias */
|
||||||
|
|
||||||
pid_t __fork(void); /* XXX */
|
pid_t __fork(void); /* XXX */
|
||||||
pid_t __atomic_fork(void) __weak; /* XXX */
|
pid_t __locked_fork(int *) __weak; /* XXX */
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
__atomic_fork(void)
|
__locked_fork(int *my_errno)
|
||||||
{
|
{
|
||||||
return __fork();
|
return __fork();
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ fork(void)
|
|||||||
SIMPLEQ_FOREACH(iter, &prepareq, next)
|
SIMPLEQ_FOREACH(iter, &prepareq, next)
|
||||||
(*iter->fn)();
|
(*iter->fn)();
|
||||||
|
|
||||||
ret = __atomic_fork();
|
ret = __locked_fork(&errno);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
/*
|
/*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rtld.c,v 1.204 2020/04/16 14:39:58 joerg Exp $ */
|
/* $NetBSD: rtld.c,v 1.205 2020/04/19 01:06:15 joerg Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1996 John D. Polstra.
|
* Copyright 1996 John D. Polstra.
|
||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__RCSID("$NetBSD: rtld.c,v 1.204 2020/04/16 14:39:58 joerg Exp $");
|
__RCSID("$NetBSD: rtld.c,v 1.205 2020/04/19 01:06:15 joerg Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -1535,13 +1535,15 @@ __dl_cxa_refcount(void *addr, ssize_t delta)
|
|||||||
pid_t __fork(void);
|
pid_t __fork(void);
|
||||||
|
|
||||||
__dso_public pid_t
|
__dso_public pid_t
|
||||||
__atomic_fork(void)
|
__locked_fork(int *my_errno)
|
||||||
{
|
{
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
pid_t result;
|
pid_t result;
|
||||||
|
|
||||||
_rtld_exclusive_enter(&mask);
|
_rtld_exclusive_enter(&mask);
|
||||||
result = __fork();
|
result = __fork();
|
||||||
|
if (result == -1)
|
||||||
|
*my_errno = errno;
|
||||||
_rtld_exclusive_exit(&mask);
|
_rtld_exclusive_exit(&mask);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rtld.h,v 1.139 2020/04/16 14:39:58 joerg Exp $ */
|
/* $NetBSD: rtld.h,v 1.140 2020/04/19 01:06:15 joerg Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1996 John D. Polstra.
|
* Copyright 1996 John D. Polstra.
|
||||||
@ -370,7 +370,7 @@ __dso_public int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
|
|||||||
__dso_public void *_dlauxinfo(void) __pure;
|
__dso_public void *_dlauxinfo(void) __pure;
|
||||||
__dso_public void __dl_cxa_refcount(void *addr, ssize_t delta);
|
__dso_public void __dl_cxa_refcount(void *addr, ssize_t delta);
|
||||||
|
|
||||||
__dso_public pid_t __atomic_fork(void);
|
__dso_public pid_t __locked_fork(int *);
|
||||||
|
|
||||||
#if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
|
#if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
|
||||||
/*
|
/*
|
||||||
|
@ -23,6 +23,6 @@
|
|||||||
___tls_get_addr;
|
___tls_get_addr;
|
||||||
__gnu_Unwind_Find_exidx;
|
__gnu_Unwind_Find_exidx;
|
||||||
__dl_cxa_refcount;
|
__dl_cxa_refcount;
|
||||||
__atomic_fork;
|
__locked_fork;
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user