Source-Changes-D archive

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

Re: CVS commit: src/lib/libc/gen



On 03.02.2020 17:24, Kamil Rytarowski wrote:
> On 03.02.2020 17:21, Joerg Sonnenberger wrote:
>> On Sat, Feb 01, 2020 at 03:38:46PM +0000, Kamil Rytarowski wrote:
>>> Module Name:	src
>>> Committed By:	kamil
>>> Date:		Sat Feb  1 15:38:46 UTC 2020
>>>
>>> Modified Files:
>>> 	src/lib/libc/gen: pthread_atfork.c
>>>
>>> Log Message:
>>> Switch atform allocations from malloc()+free() to mmap()+munmap()
>>>
>>> This avoid bootstrapping malloc too early when libc+libpthread are not
>>> ready. It is called through pthread__init() -> _pthread_atfork().
>>>
>>> This also helps LLVM Leak Sanitizer to pacify false positive reports.
>>
>> Can we please stop adding more and more hacks for the still questionable
>> "new" jemalloc and sit down for a sane init model first please? I'm
>> still at the point to ask to just revert to the known-to-be-working
>> version and therefore would also strongly prefer this change to be
>> reverted.
>>
>> Joerg
>>
> 
> This change was reverted as there was a fallout. Init model is sane
> except for pthread_atfork()+malloc() called prematurely in pthread__init().
> 

OK. The pthread_atfork(3) call was introduced with the following change.

Maybe we should fix Python?

commit 25c9c068b18fceac33cc6fec61a1277b5dc6107c
Author: joerg <joerg%NetBSD.org@localhost>
Date:   Wed Dec 25 00:44:45 2019 +0000

    Since pthread_setspecific requires locks, ensure that they are acquired
    before fork and dropped in both parent and child. At least Python
    depends on TSD after fork, even though it is undefined behavior in
    POSIX.

diff --git a/lib/libpthread/pthread_tsd.c b/lib/libpthread/pthread_tsd.c
index 666cbab85f1b..d6e261de0bb9 100644
--- a/lib/libpthread/pthread_tsd.c
+++ b/lib/libpthread/pthread_tsd.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $	*/

 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */

 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp
$");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $");

 /* Functions and structures dealing with thread-specific data */
 #include <errno.h>
@@ -61,6 +61,18 @@ null_destructor(void *p)
 #include <stdlib.h>
 #include <stdio.h>

+static void
+pthread_tsd_prefork(void)
+{
+	pthread_mutex_lock(&tsd_mutex);
+}
+
+static void
+pthread_tsd_postfork(void)
+{
+	pthread_mutex_unlock(&tsd_mutex);
+}
+
 void *
 pthread_tsd_init(size_t *tlen)
 {
@@ -68,6 +80,8 @@ pthread_tsd_init(size_t *tlen)
 	size_t alen;
 	char *arena;

+	pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork,
pthread_tsd_postfork);
+
 	if ((pkm = pthread__getenv("PTHREAD_KEYS_MAX")) != NULL) {
 		pthread_keys_max = (int)strtol(pkm, NULL, 0);
 		if (pthread_keys_max < _POSIX_THREAD_KEYS_MAX)





Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index