mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-09 16:59:32 +03:00
fix compilation on macOS
This commit is contained in:
parent
636931874f
commit
95a8196490
3 changed files with 42 additions and 24 deletions
|
@ -65,7 +65,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||
#endif
|
||||
|
||||
#if !defined(MI_DEBUG_TRACE_LEN)
|
||||
#define MI_DEBUG_TRACE_LEN (7) // store up to N frames if tracing is enabled
|
||||
#define MI_DEBUG_TRACE_LEN (8) // store up to N frames if tracing is enabled
|
||||
#endif
|
||||
|
||||
#if !defined(MI_PADDING_EXTRA) // use extra padding bytes? (so a stack trace can be preserved or next block corruption prevented)
|
||||
|
|
|
@ -434,7 +434,7 @@ static void mi_allocator_done(void) {
|
|||
// Called once by the process loader
|
||||
static void mi_process_load(void) {
|
||||
mi_heap_main_init();
|
||||
#if defined(MI_TLS_RECURSE_GUARD)
|
||||
#if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD)
|
||||
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
|
||||
MI_UNUSED(dummy);
|
||||
#endif
|
||||
|
|
|
@ -375,22 +375,31 @@ void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
|||
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
||||
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
||||
(msg==NULL ? "block" : msg), block, avail, bsize);
|
||||
PSYMBOL_INFO info = (PSYMBOL_INFO)_malloca(sizeof(SYMBOL_INFO) + 256 * sizeof(TCHAR));
|
||||
if (info==NULL) return;
|
||||
memset(info, 0, sizeof(info));
|
||||
info->MaxNameLen = 255;
|
||||
info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
HANDLE current_process = GetCurrentProcess();
|
||||
if (!SymInitialize(current_process, NULL, TRUE)) return;
|
||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||
if (SymFromAddr(current_process, (DWORD64)(strace[i]), 0, info)) {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], info->Name);
|
||||
}
|
||||
else {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: <unknown address: error: 0x%04x>\n", i, strace[i], GetLastError());
|
||||
}
|
||||
uintptr_t uninit = 0;
|
||||
for( size_t i = 0; i < MI_INTPTR_SIZE; i++ ) {
|
||||
uninit = (uninit << 8) | MI_DEBUG_UNINIT;
|
||||
}
|
||||
if (strace == NULL || uninit == (uintptr_t)strace[0]) {
|
||||
_mi_fprintf(NULL, NULL, " (uninitialized trace)\n");
|
||||
}
|
||||
else {
|
||||
PSYMBOL_INFO info = (PSYMBOL_INFO)_malloca(sizeof(SYMBOL_INFO) + 256 * sizeof(TCHAR));
|
||||
if (info==NULL) return;
|
||||
memset(info, 0, sizeof(info));
|
||||
info->MaxNameLen = 255;
|
||||
info->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
HANDLE current_process = GetCurrentProcess();
|
||||
if (!SymInitialize(current_process, NULL, TRUE)) return;
|
||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||
if (SymFromAddr(current_process, (DWORD64)(strace[i]), 0, info)) {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], info->Name);
|
||||
}
|
||||
else {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: <unknown address: error: 0x%04x>\n", i, strace[i], GetLastError());
|
||||
}
|
||||
}
|
||||
SymCleanup(current_process);
|
||||
}
|
||||
SymCleanup(current_process);
|
||||
}
|
||||
#elif (MI_DEBUG_TRACE > 0) && (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__))
|
||||
#include <execinfo.h>
|
||||
|
@ -413,13 +422,22 @@ void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
|||
void _mi_stack_trace_print(const char* msg, void** strace, size_t len, const mi_block_t* block, size_t bsize, size_t avail) {
|
||||
_mi_fprintf(NULL, NULL, "trace %s at %p of size %zu (%zub usable), allocated at:\n",
|
||||
(msg==NULL ? "block" : msg), block, avail, bsize);
|
||||
while( len > 0 && strace[len-1] == NULL) { len--; }
|
||||
if (len == 0) return;
|
||||
char** names = backtrace_symbols(strace, len);
|
||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], (names == NULL || names[i] == NULL ? "<unknown>" : names[i]));
|
||||
uintptr_t uninit = 0;
|
||||
for( size_t i = 0; i < MI_INTPTR_SIZE; i++ ) {
|
||||
uninit = (uninit << 8) | MI_DEBUG_UNINIT;
|
||||
}
|
||||
if (strace == NULL || uninit == (uintptr_t)strace[0]) {
|
||||
_mi_fprintf(NULL, NULL, " (uninitialized trace)\n");
|
||||
}
|
||||
else {
|
||||
while( len > 0 && strace[len-1] == NULL) { len--; }
|
||||
if (len == 0) return;
|
||||
char** names = backtrace_symbols(strace, len);
|
||||
for (size_t i = 0; i < len && strace[i] != NULL; i++) {
|
||||
_mi_fprintf(NULL, NULL, " %2zu: %8p: %s\n", i, strace[i], (names == NULL || names[i] == NULL ? "<unknown>" : names[i]));
|
||||
}
|
||||
// free(names); // avoid potential recursion and leak the trace
|
||||
}
|
||||
// free(names); // avoid potential recursion and leak the trace
|
||||
}
|
||||
#else
|
||||
void _mi_stack_trace_capture(void** strace, size_t len, size_t skip) {
|
||||
|
|
Loading…
Add table
Reference in a new issue