Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ set_property(CACHE MI_OPT_ARCH PROPERTY STRINGS "OFF" "ON" "avx2" "armv8.1" "arm
set(MI_DEBUG "DEFAULT" CACHE STRING "Enable assertion checks: OFF, ON, INTERNAL, FULL, DEFAULT. INTERNAL adds extra internal invariant checks, while FULL adds expensive heap invariant checks")
set_property(CACHE MI_DEBUG PROPERTY STRINGS "OFF" "ON" "INTERNAL" "FULL" "DEFAULT")

set(MI_TRACK "OFF" CACHE STRING "Enable tracking: OFF, ASAN (address sanitizer), VALGRIND, ETW (Windows event tracing). Adds a small overhead.")
set_property(CACHE MI_TRACK PROPERTY STRINGS "OFF" "ASAN" "VALGRIND" "ETW")
set(MI_TRACK "OFF" CACHE STRING "Enable tracking: OFF, ASAN (address sanitizer), VALGRIND, ETW (Windows event tracing), CUSTOM (application-defined hooks). Adds a small overhead.")
set_property(CACHE MI_TRACK PROPERTY STRINGS "OFF" "ASAN" "VALGRIND" "ETW" "CUSTOM")

set(MI_STATS "DEFAULT" CACHE STRING "Enable statistics.")
set_property(CACHE MI_STATS PROPERTY STRINGS "OFF" "ON" "FULL" "DEFAULT")
Expand Down Expand Up @@ -385,6 +385,9 @@ elseif(MI_TRACK STREQUAL "ETW")
message(STATUS "Compile with Windows event tracing support (MI_TRACK=ETW)")
list(APPEND mi_defines MI_TRACK_ETW=1)
endif()
elseif(MI_TRACK STREQUAL "CUSTOM")
message(STATUS "Compile with custom allocation hooks (MI_TRACK=CUSTOM)")
list(APPEND mi_defines MI_TRACK_CUSTOM=1)
elseif(MI_TRACK)
message(STATUS "Invalid option value: MI_TRACK=${MI_TRACK} (ignored)")
endif()
Expand Down
5 changes: 5 additions & 0 deletions include/mimalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ mi_decl_nodiscard mi_decl_export size_t mi_good_size(size_t size) mi_attr_no
// `mi_free_size` can be more efficient (as it calls mi_free_small internally).
mi_decl_export void mi_free_size(void* p, size_t size) mi_attr_noexcept;

#if defined(MI_TRACK_CUSTOM)
void mi_track_malloc_hook(const void* p, size_t reqsize, size_t size, bool zero) mi_attr_noexcept;
void mi_track_free_hook(const void* p, size_t size) mi_attr_noexcept;
#endif

// `mi_free_small` is for special applications like language runtimes.
// it should only be used to free objects from `mi_*alloc_small` and is potentially a tiny bit faster than `mi_free`
mi_decl_export void mi_free_small(void* p) mi_attr_noexcept;
Expand Down
10 changes: 10 additions & 0 deletions include/mimalloc/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ defined, undefined, or not accessible at all:
#define mi_track_malloc_size(p,reqsize,size,zero) EventWriteETW_MI_ALLOC((UINT64)(p), size)
#define mi_track_free_size(p,size) EventWriteETW_MI_FREE((UINT64)(p), size)

#elif defined(MI_TRACK_CUSTOM)
// application-defined hooks

#define MI_TRACK_ENABLED 0
#define MI_TRACK_HEAP_DESTROY 0
#define MI_TRACK_TOOL "custom"

#define mi_track_malloc_size(p,reqsize,size,zero) mi_track_malloc_hook((p),(reqsize),(size),(zero))
#define mi_track_free_size(p,size) mi_track_free_hook((p),(size))

#else
// no tracking

Expand Down
1 change: 1 addition & 0 deletions include/mimalloc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ terms of the MIT license. A copy of the license can be found in the file
// #define MI_TRACK_VALGRIND 1
// #define MI_TRACK_ASAN 1
// #define MI_TRACK_ETW 1
// #define MI_TRACK_CUSTOM 1

// Define MI_STATS as 1 to maintain statistics; set it to 2 to have detailed statistics (but costs some performance).
// #define MI_STATS 1
Expand Down