mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-03-04 14:06:13 +08:00
Cygwin 3.3 only: Replace SRWLOCK usage for malloc synchronization with the first incarnation of the patch splitting malloc_init into two parts. The SRWLOCK usage requires TryAcquireSRWLockExclusive, which isn't available on Vista / Server 2008, unfortunately. 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, split malloc_init into malloc_init_0, called from dll_crt0_0, and malloc_init_1, called from dll_crt_0_1. malloc_init_0 just initializes the muto, malloc_init_1 checks for user space provided malloc. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/* cygmalloc.h: cygwin DLL malloc stuff
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#include "regparm.h"
|
|
|
|
void __reg1 dlfree (void *p);
|
|
void __reg1 *dlmalloc (size_t size);
|
|
void __reg2 *dlrealloc (void *p, size_t size);
|
|
void __reg2 *dlcalloc (size_t nmemb, size_t size);
|
|
void __reg2 *dlmemalign (size_t alignment, size_t bytes);
|
|
void __reg1 *dlvalloc (size_t bytes);
|
|
size_t __reg1 dlmalloc_usable_size (void *p);
|
|
int __reg1 dlmalloc_trim (size_t);
|
|
int __reg2 dlmallopt (int p, int v);
|
|
void dlmalloc_stats ();
|
|
|
|
#ifdef __x86_64__
|
|
#define MALLOC_ALIGNMENT ((size_t)16U)
|
|
#endif
|
|
|
|
#if defined (DLMALLOC_VERSION) /* Building malloc.cc */
|
|
|
|
extern "C" void __set_ENOMEM ();
|
|
void *mmap64 (void *, size_t, int, int, int, off_t);
|
|
# define mmap mmap64
|
|
# define MALLOC_FAILURE_ACTION __set_ENOMEM ()
|
|
# define USE_DL_PREFIX 1
|
|
|
|
#elif defined (__INSIDE_CYGWIN__)
|
|
|
|
# define __malloc_lock() mallock.acquire ()
|
|
# define __malloc_unlock() mallock.release ()
|
|
extern muto mallock;
|
|
inline void malloc_init_0 () { mallock.init ("mallock"); }
|
|
extern void malloc_init_1 ();
|
|
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|