trigger early initialization in a conservative way
parent
2ec65306dd
commit
7733047c7b
6
malloc.c
6
malloc.c
|
@ -651,6 +651,12 @@ static inline void init(void) {
|
||||||
init_slow_path();
|
init_slow_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trigger early initialization to set up pthread_atfork and protect state as soon as possible
|
||||||
|
COLD __attribute__((constructor(101))) static void trigger_early_init(void) {
|
||||||
|
// avoid calling init directly to skip it if this isn't the malloc implementation
|
||||||
|
h_free(h_malloc(16));
|
||||||
|
}
|
||||||
|
|
||||||
static inline void enforce_init(void) {
|
static inline void enforce_init(void) {
|
||||||
if (!atomic_load_explicit(&ro.initialized, memory_order_acquire)) {
|
if (!atomic_load_explicit(&ro.initialized, memory_order_acquire)) {
|
||||||
fatal_error("invalid uninitialized allocator usage");
|
fatal_error("invalid uninitialized allocator usage");
|
||||||
|
|
Loading…
Reference in New Issue