2019-03-21 04:06:53 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
|
|
|
|
2019-03-23 03:53:11 +08:00
|
|
|
static void (*safety_check_abort)(const char *message);
|
|
|
|
|
|
|
|
void safety_check_set_abort(void (*abort_fn)(const char *)) {
|
|
|
|
safety_check_abort = abort_fn;
|
|
|
|
}
|
|
|
|
|
2019-03-21 04:06:53 +08:00
|
|
|
void safety_check_fail(const char *format, ...) {
|
2019-03-23 03:53:11 +08:00
|
|
|
char buf[MALLOC_PRINTF_BUFSIZE];
|
2019-03-21 04:06:53 +08:00
|
|
|
|
2019-03-23 03:53:11 +08:00
|
|
|
va_list ap;
|
2019-03-21 04:06:53 +08:00
|
|
|
va_start(ap, format);
|
2019-03-23 03:53:11 +08:00
|
|
|
malloc_vsnprintf(buf, MALLOC_PRINTF_BUFSIZE, format, ap);
|
2019-03-21 04:06:53 +08:00
|
|
|
va_end(ap);
|
2019-03-23 03:53:11 +08:00
|
|
|
|
|
|
|
if (safety_check_abort == NULL) {
|
|
|
|
malloc_write(buf);
|
|
|
|
abort();
|
|
|
|
} else {
|
|
|
|
safety_check_abort(buf);
|
|
|
|
}
|
2019-03-21 04:06:53 +08:00
|
|
|
}
|