1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

hurdmalloc: Run fork handler as late as possible [BZ #19431]

This is the hurd-specific follow-up for
29d794863c : hurdmalloc also needs the
same fix

	* hurd/hurdmalloc.c (malloc_fork_prepare): Rename to
	_hurd_malloc_fork_prepare.
	(malloc_fork_parent): Rename to _hurd_malloc_fork_parent.
	(malloc_fork_child): Rename to _hurd_malloc_fork_child.
	(_hurd_fork_prepare_hook): Drop malloc_fork_prepare.
	(_hurd_fork_parent_hook): Drop malloc_fork_parent.
	(_hurd_fork_child_hook): Drop malloc_fork_child.
	* hurd/hurdmalloc.h (_hurd_malloc_fork_prepare,
	_hurd_malloc_fork_parent, _hurd_malloc_fork_child): Add declarations.
	* sysdeps/mach/hurd/fork.c (__fork): Call __malloc_fork_lock_parent
	after locking locks (notably hurd_dtable_lock). Call
	_hurd_malloc_fork_prepare after that. Call _hurd_malloc_fork_parent
	before __malloc_fork_unlock_parent and _hurd_malloc_fork_child before
	__malloc_fork_unlock_child.
This commit is contained in:
Samuel Thibault
2016-09-22 01:45:48 +02:00
parent 87ab10d652
commit e67f54ab1a
4 changed files with 36 additions and 15 deletions

View File

@ -108,12 +108,6 @@ __fork (void)
/* Run things that prepare for forking before we create the task. */
RUN_HOOK (_hurd_fork_prepare_hook, ());
/* Acquire malloc locks. This needs to come last because fork
handlers may use malloc, and the libio list lock has an
indirect malloc dependency as well (via the getdelim
function). */
call_function_static_weak (__malloc_fork_lock_parent);
/* Lock things that want to be locked before we fork. */
{
void *const *p;
@ -124,6 +118,13 @@ __fork (void)
}
__mutex_lock (&_hurd_siglock);
/* Acquire malloc locks. This needs to come last because fork
handlers may use malloc, and the libio list lock has an
indirect malloc dependency as well (via the getdelim
function). */
call_function_static_weak (__malloc_fork_lock_parent);
_hurd_malloc_fork_prepare ();
newtask = MACH_PORT_NULL;
thread = sigthread = MACH_PORT_NULL;
newproc = MACH_PORT_NULL;
@ -612,6 +613,7 @@ __fork (void)
}
/* Release malloc locks. */
_hurd_malloc_fork_parent ();
call_function_static_weak (__malloc_fork_unlock_parent);
/* Run things that want to run in the parent to restore it to
@ -666,6 +668,7 @@ __fork (void)
__sigemptyset (&_hurdsig_traced);
/* Release malloc locks. */
_hurd_malloc_fork_child ();
call_function_static_weak (__malloc_fork_unlock_child);
/* Run things that want to run in the child task to set up. */