xref: /freebsd/contrib/jemalloc/src/safety_check.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 #include "jemalloc/internal/jemalloc_preamble.h"
2 #include "jemalloc/internal/jemalloc_internal_includes.h"
3 
4 static void (*safety_check_abort)(const char *message);
5 
6 void safety_check_set_abort(void (*abort_fn)(const char *)) {
7 	safety_check_abort = abort_fn;
8 }
9 
10 void safety_check_fail(const char *format, ...) {
11 	char buf[MALLOC_PRINTF_BUFSIZE];
12 
13 	va_list ap;
14 	va_start(ap, format);
15 	malloc_vsnprintf(buf, MALLOC_PRINTF_BUFSIZE, format, ap);
16 	va_end(ap);
17 
18 	if (safety_check_abort == NULL) {
19 		malloc_write(buf);
20 		abort();
21 	} else {
22 		safety_check_abort(buf);
23 	}
24 }
25