2019-03-21 04:06:53 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_SAFETY_CHECK_H
|
|
|
|
#define JEMALLOC_INTERNAL_SAFETY_CHECK_H
|
|
|
|
|
2022-07-21 06:25:56 +08:00
|
|
|
#define SAFETY_CHECK_DOUBLE_FREE_MAX_SCAN_DEFAULT 32
|
|
|
|
|
2021-02-06 09:26:45 +08:00
|
|
|
void safety_check_fail_sized_dealloc(bool current_dealloc, const void *ptr,
|
|
|
|
size_t true_size, size_t input_size);
|
2019-03-21 04:06:53 +08:00
|
|
|
void safety_check_fail(const char *format, ...);
|
2022-04-22 07:31:33 +08:00
|
|
|
|
|
|
|
typedef void (*safety_check_abort_hook_t)(const char *message);
|
|
|
|
|
2019-03-23 03:53:11 +08:00
|
|
|
/* Can set to NULL for a default. */
|
2022-04-22 07:31:33 +08:00
|
|
|
void safety_check_set_abort(safety_check_abort_hook_t abort_fn);
|
2019-03-23 03:53:11 +08:00
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
|
|
safety_check_set_redzone(void *ptr, size_t usize, size_t bumped_usize) {
|
|
|
|
assert(usize < bumped_usize);
|
|
|
|
for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) {
|
2019-07-04 07:48:47 +08:00
|
|
|
*((unsigned char *)ptr + i) = 0xBC;
|
2019-03-23 03:53:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
|
|
safety_check_verify_redzone(const void *ptr, size_t usize, size_t bumped_usize)
|
|
|
|
{
|
|
|
|
for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) {
|
2019-07-04 07:48:47 +08:00
|
|
|
if (unlikely(*((unsigned char *)ptr + i) != 0xBC)) {
|
2019-03-23 03:53:11 +08:00
|
|
|
safety_check_fail("Use after free error\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 04:06:53 +08:00
|
|
|
|
|
|
|
#endif /*JEMALLOC_INTERNAL_SAFETY_CHECK_H */
|