Introduce unsafe reentrancy guards.

We have to work to circumvent the safety checks in pre_reentrancy when going
down extent hook pathways.  Instead, let's explicitly have checked and unchecked
guards.
This commit is contained in:
David Goldblatt 2019-12-02 16:45:40 -08:00 committed by David Goldblatt
parent ae0d8e8591
commit 703fbc0ff5
2 changed files with 28 additions and 14 deletions

View File

@ -151,24 +151,12 @@ static inline void
pre_reentrancy(tsd_t *tsd, arena_t *arena) { pre_reentrancy(tsd_t *tsd, arena_t *arena) {
/* arena is the current context. Reentry from a0 is not allowed. */ /* arena is the current context. Reentry from a0 is not allowed. */
assert(arena != arena_get(tsd_tsdn(tsd), 0, false)); assert(arena != arena_get(tsd_tsdn(tsd), 0, false));
tsd_pre_reentrancy_raw(tsd);
bool fast = tsd_fast(tsd);
assert(tsd_reentrancy_level_get(tsd) < INT8_MAX);
++*tsd_reentrancy_levelp_get(tsd);
if (fast) {
/* Prepare slow path for reentrancy. */
tsd_slow_update(tsd);
assert(tsd_state_get(tsd) == tsd_state_nominal_slow);
}
} }
static inline void static inline void
post_reentrancy(tsd_t *tsd) { post_reentrancy(tsd_t *tsd) {
int8_t *reentrancy_level = tsd_reentrancy_levelp_get(tsd); tsd_post_reentrancy_raw(tsd);
assert(*reentrancy_level > 0);
if (--*reentrancy_level == 0) {
tsd_slow_update(tsd);
}
} }
#endif /* JEMALLOC_INTERNAL_INLINES_A_H */ #endif /* JEMALLOC_INTERNAL_INLINES_A_H */

View File

@ -446,4 +446,30 @@ tsd_state_nocleanup(tsd_t *tsd) {
tsd_state_get(tsd) == tsd_state_minimal_initialized; tsd_state_get(tsd) == tsd_state_minimal_initialized;
} }
/*
* These "raw" tsd reentrancy functions don't have any debug checking to make
* sure that we're not touching arena 0. Better is to call pre_reentrancy and
* post_reentrancy if this is possible.
*/
static inline void
tsd_pre_reentrancy_raw(tsd_t *tsd) {
bool fast = tsd_fast(tsd);
assert(tsd_reentrancy_level_get(tsd) < INT8_MAX);
++*tsd_reentrancy_levelp_get(tsd);
if (fast) {
/* Prepare slow path for reentrancy. */
tsd_slow_update(tsd);
assert(tsd_state_get(tsd) == tsd_state_nominal_slow);
}
}
static inline void
tsd_post_reentrancy_raw(tsd_t *tsd) {
int8_t *reentrancy_level = tsd_reentrancy_levelp_get(tsd);
assert(*reentrancy_level > 0);
if (--*reentrancy_level == 0) {
tsd_slow_update(tsd);
}
}
#endif /* JEMALLOC_INTERNAL_TSD_H */ #endif /* JEMALLOC_INTERNAL_TSD_H */