2021-11-05 02:10:19 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_SAN_BUMP_H
|
|
|
|
#define JEMALLOC_INTERNAL_SAN_BUMP_H
|
|
|
|
|
2023-06-10 08:37:47 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
2021-11-05 02:10:19 +08:00
|
|
|
#include "jemalloc/internal/edata.h"
|
|
|
|
#include "jemalloc/internal/exp_grow.h"
|
|
|
|
#include "jemalloc/internal/mutex.h"
|
2023-06-10 08:37:47 +08:00
|
|
|
#include "jemalloc/internal/witness.h"
|
2021-11-05 02:10:19 +08:00
|
|
|
|
2021-10-29 03:08:10 +08:00
|
|
|
#define SBA_RETAINED_ALLOC_SIZE ((size_t)4 << 20)
|
|
|
|
|
|
|
|
extern bool opt_retain;
|
2021-11-05 02:10:19 +08:00
|
|
|
|
|
|
|
typedef struct ehooks_s ehooks_t;
|
|
|
|
typedef struct pac_s pac_t;
|
|
|
|
|
|
|
|
typedef struct san_bump_alloc_s san_bump_alloc_t;
|
|
|
|
struct san_bump_alloc_s {
|
|
|
|
malloc_mutex_t mtx;
|
|
|
|
|
|
|
|
edata_t *curr_reg;
|
|
|
|
};
|
|
|
|
|
2021-10-29 03:08:10 +08:00
|
|
|
static inline bool
|
2023-07-06 04:33:34 +08:00
|
|
|
san_bump_enabled(void) {
|
2021-10-29 03:08:10 +08:00
|
|
|
/*
|
|
|
|
* We enable san_bump allocator only when it's possible to break up a
|
|
|
|
* mapping and unmap a part of it (maps_coalesce). This is needed to
|
|
|
|
* ensure the arena destruction process can destroy all retained guarded
|
|
|
|
* extents one by one and to unmap a trailing part of a retained guarded
|
|
|
|
* region when it's too small to fit a pending allocation.
|
|
|
|
* opt_retain is required, because this allocator retains a large
|
|
|
|
* virtual memory mapping and returns smaller parts of it.
|
|
|
|
*/
|
|
|
|
return maps_coalesce && opt_retain;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
san_bump_alloc_init(san_bump_alloc_t* sba) {
|
|
|
|
bool err = malloc_mutex_init(&sba->mtx, "sanitizer_bump_allocator",
|
|
|
|
WITNESS_RANK_SAN_BUMP_ALLOC, malloc_mutex_rank_exclusive);
|
|
|
|
if (err) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
sba->curr_reg = NULL;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-05 02:10:19 +08:00
|
|
|
|
|
|
|
edata_t *
|
|
|
|
san_bump_alloc(tsdn_t *tsdn, san_bump_alloc_t* sba, pac_t *pac, ehooks_t *ehooks,
|
|
|
|
size_t size, bool zero);
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_SAN_BUMP_H */
|