1 1.1 christos #ifndef JEMALLOC_INTERNAL_SAN_BUMP_H 2 1.1 christos #define JEMALLOC_INTERNAL_SAN_BUMP_H 3 1.1 christos 4 1.1 christos #include "jemalloc/internal/edata.h" 5 1.1 christos #include "jemalloc/internal/exp_grow.h" 6 1.1 christos #include "jemalloc/internal/mutex.h" 7 1.1 christos 8 1.1 christos #define SBA_RETAINED_ALLOC_SIZE ((size_t)4 << 20) 9 1.1 christos 10 1.1 christos extern bool opt_retain; 11 1.1 christos 12 1.1 christos typedef struct ehooks_s ehooks_t; 13 1.1 christos typedef struct pac_s pac_t; 14 1.1 christos 15 1.1 christos typedef struct san_bump_alloc_s san_bump_alloc_t; 16 1.1 christos struct san_bump_alloc_s { 17 1.1 christos malloc_mutex_t mtx; 18 1.1 christos 19 1.1 christos edata_t *curr_reg; 20 1.1 christos }; 21 1.1 christos 22 1.1 christos static inline bool 23 1.1 christos san_bump_enabled(void) { 24 1.1 christos /* 25 1.1 christos * We enable san_bump allocator only when it's possible to break up a 26 1.1 christos * mapping and unmap a part of it (maps_coalesce). This is needed to 27 1.1 christos * ensure the arena destruction process can destroy all retained guarded 28 1.1 christos * extents one by one and to unmap a trailing part of a retained guarded 29 1.1 christos * region when it's too small to fit a pending allocation. 30 1.1 christos * opt_retain is required, because this allocator retains a large 31 1.1 christos * virtual memory mapping and returns smaller parts of it. 32 1.1 christos */ 33 1.1 christos return maps_coalesce && opt_retain; 34 1.1 christos } 35 1.1 christos 36 1.1 christos static inline bool 37 1.1 christos san_bump_alloc_init(san_bump_alloc_t* sba) { 38 1.1 christos bool err = malloc_mutex_init(&sba->mtx, "sanitizer_bump_allocator", 39 1.1 christos WITNESS_RANK_SAN_BUMP_ALLOC, malloc_mutex_rank_exclusive); 40 1.1 christos if (err) { 41 1.1 christos return true; 42 1.1 christos } 43 1.1 christos sba->curr_reg = NULL; 44 1.1 christos 45 1.1 christos return false; 46 1.1 christos } 47 1.1 christos 48 1.1 christos edata_t * 49 1.1 christos san_bump_alloc(tsdn_t *tsdn, san_bump_alloc_t* sba, pac_t *pac, ehooks_t *ehooks, 50 1.1 christos size_t size, bool zero); 51 1.1 christos 52 1.1 christos #endif /* JEMALLOC_INTERNAL_SAN_BUMP_H */ 53