aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-09-22 01:45:48 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-09-22 01:45:48 +0200
commite67f54ab1a6253dd69cb2c770d785c7eb6d2172c (patch)
tree69632c1338d0f7f0790b0f1b3a17ac11e9b1847f
parent87ab10d6524fe4faabd7eb3eac5868165ecfb323 (diff)
downloadglibc-e67f54ab1a6253dd69cb2c770d785c7eb6d2172c.tar
glibc-e67f54ab1a6253dd69cb2c770d785c7eb6d2172c.tar.gz
glibc-e67f54ab1a6253dd69cb2c770d785c7eb6d2172c.tar.bz2
glibc-e67f54ab1a6253dd69cb2c770d785c7eb6d2172c.zip
hurdmalloc: Run fork handler as late as possible [BZ #19431]
This is the hurd-specific follow-up for 29d794863cd6e03115d3670707cc873a9965ba92 : 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.
-rw-r--r--ChangeLog17
-rw-r--r--hurd/hurdmalloc.c15
-rw-r--r--hurd/hurdmalloc.h4
-rw-r--r--sysdeps/mach/hurd/fork.c15
4 files changed, 36 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index e9289778f0..b2add6a3e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2016-09-22 Samuel Thibault <samuel.thibault@ens-lyon.org>
+
+ * 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.
+
2016-09-21 James Greenhalgh <james.greenhalgh@arm.com>
* soft-fp/extendhftf2.c: New.
diff --git a/hurd/hurdmalloc.c b/hurd/hurdmalloc.c
index 58c29fa07d..65fb959d84 100644
--- a/hurd/hurdmalloc.c
+++ b/hurd/hurdmalloc.c
@@ -405,8 +405,8 @@ print_malloc_free_list (void)
}
#endif /* DEBUG */
-static void
-malloc_fork_prepare(void)
+void
+_hurd_malloc_fork_prepare(void)
/*
* Prepare the malloc module for a fork by insuring that no thread is in a
* malloc critical section.
@@ -419,8 +419,8 @@ malloc_fork_prepare(void)
}
}
-static void
-malloc_fork_parent(void)
+void
+_hurd_malloc_fork_parent(void)
/*
* Called in the parent process after a fork() to resume normal operation.
*/
@@ -432,8 +432,8 @@ malloc_fork_parent(void)
}
}
-static void
-malloc_fork_child(void)
+void
+_hurd_malloc_fork_child(void)
/*
* Called in the child process after a fork() to resume normal operation.
*/
@@ -446,7 +446,4 @@ malloc_fork_child(void)
}
-text_set_element (_hurd_fork_prepare_hook, malloc_fork_prepare);
-text_set_element (_hurd_fork_parent_hook, malloc_fork_parent);
-text_set_element (_hurd_fork_child_hook, malloc_fork_child);
text_set_element (_hurd_preinit_hook, malloc_init);
diff --git a/hurd/hurdmalloc.h b/hurd/hurdmalloc.h
index e11c208a8f..3520ffacd8 100644
--- a/hurd/hurdmalloc.h
+++ b/hurd/hurdmalloc.h
@@ -12,6 +12,10 @@ extern void *_hurd_malloc (size_t);
extern void *_hurd_realloc (void *, size_t);
extern void _hurd_free (void *);
+extern void _hurd_malloc_fork_prepare (void);
+extern void _hurd_malloc_fork_parent (void);
+extern void _hurd_malloc_fork_child (void);
+
#define malloc _hurd_malloc
#define realloc _hurd_realloc
#define free _hurd_free
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index 9973b1bb9e..9e863a8033 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -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. */