#include "mimalloc.h"
#include "mimalloc/internal.h"
#include "mimalloc/prim.h"
#include <string.h>
#include <stdlib.h>
const mi_page_t _mi_page_empty;
#define MI_PAGE_EMPTY() …
#if (MI_SMALL_WSIZE_MAX==128)
#if (MI_PADDING>0) && (MI_INTPTR_SIZE >= 8)
#define MI_SMALL_PAGES_EMPTY …
#elif (MI_PADDING>0)
#define MI_SMALL_PAGES_EMPTY …
#else
#define MI_SMALL_PAGES_EMPTY …
#endif
#else
#error "define right initialization sizes corresponding to MI_SMALL_WSIZE_MAX"
#endif
#define QNULL(sz) …
#define MI_PAGE_QUEUES_EMPTY …
#define MI_STAT_COUNT_NULL() …
#if MI_STAT>1
#define MI_STAT_COUNT_END_NULL …
#else
#define MI_STAT_COUNT_END_NULL() …
#endif
#define MI_STATS_NULL …
#define SQNULL(sz) …
#define MI_SEGMENT_SPAN_QUEUES_EMPTY …
mi_decl_cache_align const mi_heap_t _mi_heap_empty = …;
#define tld_empty_stats …
#define tld_empty_os …
mi_decl_cache_align static const mi_tld_t tld_empty = …;
mi_threadid_t _mi_thread_id(void) mi_attr_noexcept { … }
mi_decl_thread mi_heap_t* _mi_heap_default = …;
extern mi_heap_t _mi_heap_main;
static mi_tld_t tld_main = …;
mi_heap_t _mi_heap_main = …;
bool _mi_process_is_initialized = …;
mi_stats_t _mi_stats_main = …;
static void mi_heap_main_init(void) { … }
mi_heap_t* _mi_heap_main_get(void) { … }
mi_thread_data_t;
#define TD_CACHE_SIZE …
static _Atomic(mi_thread_data_t*) td_cache[TD_CACHE_SIZE];
static mi_thread_data_t* mi_thread_data_zalloc(void) { … }
static void mi_thread_data_free( mi_thread_data_t* tdfree ) { … }
void _mi_thread_data_collect(void) { … }
static bool _mi_heap_init(void) { … }
void _mi_tld_init(mi_tld_t* tld, mi_heap_t* bheap) { … }
static bool _mi_heap_done(mi_heap_t* heap) { … }
static void mi_process_setup_auto_thread_done(void) { … }
bool _mi_is_main_thread(void) { … }
static _Atomic(size_t) thread_count = …;
size_t _mi_current_thread_count(void) { … }
void mi_thread_init(void) mi_attr_noexcept
{ … }
void mi_thread_done(void) mi_attr_noexcept { … }
void _mi_thread_done(mi_heap_t* heap)
{ … }
void _mi_heap_set_default_direct(mi_heap_t* heap) { … }
static void mi_cdecl mi_process_done(void);
static bool os_preloading = …;
static bool mi_redirected = …;
bool mi_decl_noinline _mi_preloading(void) { … }
mi_decl_nodiscard bool mi_is_redirected(void) mi_attr_noexcept { … }
#if defined(_WIN32) && defined(MI_SHARED_LIB) && !defined(MI_WIN_NOREDIRECT)
#ifdef __cplusplus
extern "C" {
#endif
mi_decl_export void _mi_redirect_entry(DWORD reason) {
if (reason == DLL_PROCESS_ATTACH) {
mi_redirected = true;
}
else if (reason == DLL_PROCESS_DETACH) {
mi_redirected = false;
}
else if (reason == DLL_THREAD_DETACH) {
mi_thread_done();
}
}
__declspec(dllimport) bool mi_cdecl mi_allocator_init(const char** message);
__declspec(dllimport) void mi_cdecl mi_allocator_done(void);
#ifdef __cplusplus
}
#endif
#else
static bool mi_allocator_init(const char** message) { … }
static void mi_allocator_done(void) { … }
#endif
static void mi_process_load(void) { … }
#if defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
mi_decl_cache_align bool _mi_cpu_has_fsrm = false;
static void mi_detect_cpu_features(void) {
int32_t cpu_info[4];
__cpuid(cpu_info, 7);
_mi_cpu_has_fsrm = ((cpu_info[3] & (1 << 4)) != 0);
}
#else
static void mi_detect_cpu_features(void) { … }
#endif
void mi_process_init(void) mi_attr_noexcept { … }
static void mi_cdecl mi_process_done(void) { … }
#if defined(_WIN32) && defined(MI_SHARED_LIB)
__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
MI_UNUSED(reserved);
MI_UNUSED(inst);
if (reason==DLL_PROCESS_ATTACH) {
mi_process_load();
}
else if (reason==DLL_PROCESS_DETACH) {
mi_process_done();
}
else if (reason==DLL_THREAD_DETACH) {
if (!mi_is_redirected()) {
mi_thread_done();
}
}
return TRUE;
}
#elif defined(_MSC_VER)
static int _mi_process_init(void) {
mi_process_load();
return 0;
}
typedef int(*_mi_crt_callback_t)(void);
#if defined(_M_X64) || defined(_M_ARM64)
__pragma(comment(linker, "/include:" "_mi_msvc_initu"))
#pragma section(".CRT$XIU", long, read)
#else
__pragma(comment(linker, "/include:" "__mi_msvc_initu"))
#endif
#pragma data_seg(".CRT$XIU")
mi_decl_externc _mi_crt_callback_t _mi_msvc_initu[] = { &_mi_process_init };
#pragma data_seg()
#elif defined(__cplusplus)
static bool _mi_process_init(void) {
mi_process_load();
return (_mi_heap_main.thread_id != 0);
}
static bool mi_initialized = _mi_process_init();
#elif defined(__GNUC__) || defined(__clang__)
static void __attribute__((constructor)) _mi_process_init(void) { … }
#else
#pragma message("define a way to call mi_process_load on your platform")
#endif