Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ld.elf_so Rename __atomic_fork to __locked_fork and ...



details:   https://anonhg.NetBSD.org/src/rev/18b827699ece
branches:  trunk
changeset: 1009268:18b827699ece
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sun Apr 19 01:06:15 2020 +0000

description:
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.

diffstat:

 lib/libc/gen/pthread_atfork.c |  10 +++++-----
 libexec/ld.elf_so/rtld.c      |   8 +++++---
 libexec/ld.elf_so/rtld.h      |   4 ++--
 libexec/ld.elf_so/symbols.map |   2 +-
 4 files changed, 13 insertions(+), 11 deletions(-)

diffs (104 lines):

diff -r bc2b98bfb4bd -r 18b827699ece lib/libc/gen/pthread_atfork.c
--- a/lib/libc/gen/pthread_atfork.c     Sat Apr 18 23:55:50 2020 +0000
+++ b/lib/libc/gen/pthread_atfork.c     Sun Apr 19 01:06:15 2020 +0000
@@ -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.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #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 */
 
 #include "namespace.h"
@@ -48,10 +48,10 @@
 #endif /* __weak_alias */
 
 pid_t  __fork(void);   /* XXX */
-pid_t  __atomic_fork(void) __weak; /* XXX */
+pid_t  __locked_fork(int *) __weak; /* XXX */
 
 pid_t
-__atomic_fork(void)
+__locked_fork(int *my_errno)
 {
        return __fork();
 }
@@ -164,7 +164,7 @@
        SIMPLEQ_FOREACH(iter, &prepareq, next)
                (*iter->fn)();
 
-       ret = __atomic_fork();
+       ret = __locked_fork(&errno);
 
        if (ret != 0) {
                /*
diff -r bc2b98bfb4bd -r 18b827699ece libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Sat Apr 18 23:55:50 2020 +0000
+++ b/libexec/ld.elf_so/rtld.c  Sun Apr 19 01:06:15 2020 +0000
@@ -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.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #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 */
 
 #include <sys/param.h>
@@ -1535,13 +1535,15 @@
 pid_t __fork(void);
 
 __dso_public pid_t
-__atomic_fork(void)
+__locked_fork(int *my_errno)
 {
        sigset_t mask;
        pid_t result;
 
        _rtld_exclusive_enter(&mask);
        result = __fork();
+       if (result == -1)
+               *my_errno = errno;
        _rtld_exclusive_exit(&mask);
 
        return result;
diff -r bc2b98bfb4bd -r 18b827699ece libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Sat Apr 18 23:55:50 2020 +0000
+++ b/libexec/ld.elf_so/rtld.h  Sun Apr 19 01:06:15 2020 +0000
@@ -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.
@@ -370,7 +370,7 @@
 __dso_public void *_dlauxinfo(void) __pure;
 __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__)
 /*
diff -r bc2b98bfb4bd -r 18b827699ece libexec/ld.elf_so/symbols.map
--- a/libexec/ld.elf_so/symbols.map     Sat Apr 18 23:55:50 2020 +0000
+++ b/libexec/ld.elf_so/symbols.map     Sun Apr 19 01:06:15 2020 +0000
@@ -23,6 +23,6 @@
     ___tls_get_addr;
     __gnu_Unwind_Find_exidx;
     __dl_cxa_refcount;
-    __atomic_fork;
+    __locked_fork;
   local: *;
 };



Home | Main Index | Thread Index | Old Index