Safety checks: Indirect through a function.

This will let us share code on failure pathways.pathways
This commit is contained in:
David Goldblatt 2019-03-20 13:06:53 -07:00 committed by David Goldblatt
parent f95a88fcd9
commit b92c9a1a81
4 changed files with 20 additions and 1 deletions

View File

@ -117,6 +117,7 @@ C_SRCS := $(srcroot)src/jemalloc.c \
$(srcroot)src/prng.c \
$(srcroot)src/prof.c \
$(srcroot)src/rtree.c \
$(srcroot)src/safety_check.c \
$(srcroot)src/stats.c \
$(srcroot)src/sc.c \
$(srcroot)src/sz.c \

View File

@ -0,0 +1,6 @@
#ifndef JEMALLOC_INTERNAL_SAFETY_CHECK_H
#define JEMALLOC_INTERNAL_SAFETY_CHECK_H
void safety_check_fail(const char *format, ...);
#endif /*JEMALLOC_INTERNAL_SAFETY_CHECK_H */

11
src/safety_check.c Normal file
View File

@ -0,0 +1,11 @@
#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/jemalloc_internal_includes.h"
void safety_check_fail(const char *format, ...) {
va_list ap;
va_start(ap, format);
malloc_vcprintf(NULL, NULL, format, ap);
va_end(ap);
abort();
}

View File

@ -4,6 +4,7 @@
#include "jemalloc/internal/assert.h"
#include "jemalloc/internal/mutex.h"
#include "jemalloc/internal/safety_check.h"
#include "jemalloc/internal/sc.h"
/******************************************************************************/
@ -122,7 +123,7 @@ tbin_extents_lookup_size_check(tsdn_t *tsdn, cache_bin_t *tbin, szind_t binind,
sz_sum -= szind;
}
if (sz_sum != 0) {
malloc_printf("<jemalloc>: size mismatch in thread cache "
safety_check_fail("<jemalloc>: size mismatch in thread cache "
"detected, likely caused by sized deallocation bugs by "
"application. Abort.\n");
abort();