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