diff options
author | Sverker Eriksson <[email protected]> | 2013-04-15 14:07:42 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2013-04-15 14:07:42 +0200 |
commit | 4caf3f8b94a38e738314f484d18b531dfa16ff8a (patch) | |
tree | 76a9ad62cec2628baef0288eb808b64196ac9688 /erts/emulator/beam/erl_alloc.h | |
parent | 0e9c7394b12d627b08a5f1acd1ba1c21dbfd6e2a (diff) | |
download | otp-4caf3f8b94a38e738314f484d18b531dfa16ff8a.tar.gz otp-4caf3f8b94a38e738314f484d18b531dfa16ff8a.tar.bz2 otp-4caf3f8b94a38e738314f484d18b531dfa16ff8a.zip |
erts: Fix locking order violation for allocation wrappers
Some query functions in erl_alloc_util.c lock the allocator mutex
and then use erts_printf that in turn may call the sys allocator
through the wrappers. To avoid breaking locking order these
query functions first "pre-locks" all allocator wrappers.
Diffstat (limited to 'erts/emulator/beam/erl_alloc.h')
-rw-r--r-- | erts/emulator/beam/erl_alloc.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_alloc.h b/erts/emulator/beam/erl_alloc.h index ba5ec9c367..9cafd8ddc8 100644 --- a/erts/emulator/beam/erl_alloc.h +++ b/erts/emulator/beam/erl_alloc.h @@ -135,6 +135,18 @@ typedef struct { extern ErtsAllocatorThrSpec_t erts_allctr_thr_spec[ERTS_ALC_A_MAX+1]; +typedef struct ErtsAllocatorWrapper_t_ { + void (*lock)(void); + void (*unlock)(void); + struct ErtsAllocatorWrapper_t_* next; +}ErtsAllocatorWrapper_t; +ErtsAllocatorWrapper_t *erts_allctr_wrappers; +extern int erts_allctr_wrapper_prelocked; +extern erts_tsd_key_t erts_allctr_prelock_tsd_key; +void erts_allctr_wrapper_prelock_init(ErtsAllocatorWrapper_t* wrapper); +void erts_allctr_wrapper_pre_lock(void); +void erts_allctr_wrapper_pre_unlock(void); + void erts_alloc_register_scheduler(void *vesdp); #ifdef ERTS_SMP void erts_alloc_scheduler_handle_delayed_dealloc(void *vesdp, @@ -188,6 +200,7 @@ void *erts_realloc(ErtsAlcType_t type, void *ptr, Uint size); void erts_free(ErtsAlcType_t type, void *ptr); void *erts_alloc_fnf(ErtsAlcType_t type, Uint size); void *erts_realloc_fnf(ErtsAlcType_t type, void *ptr, Uint size); +int erts_is_allctr_wrapper_prelocked(void); #endif /* #if !ERTS_ALC_DO_INLINE */ @@ -258,6 +271,13 @@ void *erts_realloc_fnf(ErtsAlcType_t type, void *ptr, Uint size) size); } +ERTS_ALC_INLINE +int erts_is_allctr_wrapper_prelocked(void) +{ + return erts_allctr_wrapper_prelocked /* locked */ + && !!erts_tsd_get(erts_allctr_prelock_tsd_key); /* by me */ +} + #endif /* #if ERTS_ALC_DO_INLINE || defined(ERTS_ALC_INTERNAL__) */ #define ERTS_ALC_GET_THR_IX() ((int) erts_get_scheduler_id()) |