diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2021-10-26 18:53:08 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2021-10-26 19:47:22 +0300 |
commit | 44a79a6eca3d322020dda0919023d78dda129d4d (patch) | |
tree | c1241dc7277a6f5ce52d22a56d30948d40866669 /winsup/cygwin/malloc_wrapper.cc | |
parent | 23b1400f83a5f64dfab60cba2e25b0d858f44b5c (diff) |
Cygwin: convert malloc lock to SRWLOCK
Per https://cygwin.com/pipermail/cygwin-developers/2021-October/012429.html,
we may encounter a crash when starting multiple threads during process
startup (here: fhandler_fifo::fixup_after_{fork,exec}) which in turn
allocate memory via malloc.
The problem is concurrent usage of malloc before the malloc muto has
been initialized.
To fix this issue, convert the muto to a SRWLOCK and make sure it is
statically initalized. Thus, malloc can be called as early as necessary
and malloc_init is only required to check for user space provided malloc.
Note that this requires to implement a __malloc_trylock macro to be
called from fork.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/malloc_wrapper.cc')
-rw-r--r-- | winsup/cygwin/malloc_wrapper.cc | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc index 3b245800a..2842e5398 100644 --- a/winsup/cygwin/malloc_wrapper.cc +++ b/winsup/cygwin/malloc_wrapper.cc @@ -269,13 +269,11 @@ strdup (const char *s) newlib will call __malloc_lock and __malloc_unlock at appropriate times. */ -muto NO_COPY mallock; +SRWLOCK NO_COPY mallock = SRWLOCK_INIT; void malloc_init () { - mallock.init ("mallock"); - /* Check if malloc is provided by application. If so, redirect all calls to malloc/free/realloc to application provided. This may happen if some other dll calls cygwin's malloc, but main code provides |