Fix witness/fork() interactions.

Fix witness to clear its list of owned mutexes in the child if
platform-specific malloc_mutex code re-initializes mutexes rather than
unlocking them.
This commit is contained in:
Jason Evans
2016-04-26 10:47:22 -07:00
parent 174c0c3a9c
commit 108c4a11e9
5 changed files with 42 additions and 9 deletions

View File

@@ -2770,8 +2770,8 @@ _malloc_prefork(void)
narenas = narenas_total_get();
/* Acquire all mutexes in a safe order. */
witness_prefork(tsd);
/* Acquire all mutexes in a safe order. */
ctl_prefork(tsd);
malloc_mutex_prefork(tsd, &arenas_lock);
prof_prefork0(tsd);
@@ -2815,6 +2815,7 @@ _malloc_postfork(void)
tsd = tsd_fetch();
witness_postfork_parent(tsd);
/* Release all mutexes, now that fork() has completed. */
chunk_postfork_parent(tsd);
base_postfork_parent(tsd);
@@ -2827,7 +2828,6 @@ _malloc_postfork(void)
prof_postfork_parent(tsd);
malloc_mutex_postfork_parent(tsd, &arenas_lock);
ctl_postfork_parent(tsd);
witness_postfork(tsd);
}
void
@@ -2840,6 +2840,7 @@ jemalloc_postfork_child(void)
tsd = tsd_fetch();
witness_postfork_child(tsd);
/* Release all mutexes, now that fork() has completed. */
chunk_postfork_child(tsd);
base_postfork_child(tsd);
@@ -2852,7 +2853,6 @@ jemalloc_postfork_child(void)
prof_postfork_child(tsd);
malloc_mutex_postfork_child(tsd, &arenas_lock);
ctl_postfork_child(tsd);
witness_postfork(tsd);
}
/******************************************************************************/

View File

@@ -222,8 +222,20 @@ witness_prefork(tsd_t *tsd)
}
void
witness_postfork(tsd_t *tsd)
witness_postfork_parent(tsd_t *tsd)
{
tsd_witness_fork_set(tsd, false);
}
void
witness_postfork_child(tsd_t *tsd)
{
#ifndef JEMALLOC_MUTEX_INIT_CB
witness_list_t *witnesses;
witnesses = tsd_witnessesp_get(tsd);
ql_new(witnesses);
#endif
tsd_witness_fork_set(tsd, false);
}