add mi_decl_externc, nice layout

This commit is contained in:
Daan 2021-11-02 21:53:20 -07:00
parent 5360639748
commit 751a2249c8

View File

@ -36,6 +36,12 @@ terms of the MIT license. A copy of the license can be found in the file
#define __wasi__
#endif
#if defined(__cplusplus)
#define mi_decl_externc extern "C"
#else
#define mi_decl_externc
#endif
// "options.c"
void _mi_fputs(mi_output_fun* out, void* arg, const char* prefix, const char* message);
void _mi_fprintf(mi_output_fun* out, void* arg, const char* fmt, ...);
@ -299,6 +305,7 @@ mi_heap_t* _mi_heap_main_get(void); // statically allocated main backing hea
#if defined(MI_MALLOC_OVERRIDE)
#if defined(__APPLE__) // macOS
#define MI_TLS_SLOT 89 // seems unused?
// #define MI_TLS_RECURSE_GUARD 1
// other possible unused ones are 9, 29, __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 (94), __PTK_FRAMEWORK_GC_KEY9 (112) and __PTK_FRAMEWORK_OLDGC_KEY9 (89)
// see <https://github.com/rweichler/substrate/blob/master/include/pthread_machdep.h>
#elif defined(__OpenBSD__)
@ -336,10 +343,12 @@ extern pthread_key_t _mi_heap_default_key;
// However, on the Apple M1 we do use the address of this variable as the unique thread-id (issue #356).
extern mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from
static inline mi_heap_t* mi_get_default_heap(void) {
#if defined(MI_TLS_SLOT)
mi_heap_t* heap = (mi_heap_t*)mi_tls_slot(MI_TLS_SLOT);
return (mi_unlikely(heap == NULL) ? (mi_heap_t*)&_mi_heap_empty : heap);
if (mi_unlikely(heap == NULL)) { heap = (mi_heap_t*)&_mi_heap_empty; } //_mi_heap_empty_get(); }
return heap;
#elif defined(MI_TLS_PTHREAD_SLOT_OFS)
mi_heap_t* heap = *mi_tls_pthread_heap_slot();
return (mi_unlikely(heap == NULL) ? (mi_heap_t*)&_mi_heap_empty : heap);
@ -716,12 +725,12 @@ static inline void* mi_tls_slot(size_t slot) mi_attr_noexcept {
res = tcb[slot];
#elif defined(__aarch64__)
void** tcb; UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
#if defined(__APPLE__) // M1, issue #343
__asm__ volatile ("mrs %0, tpidrro_el0" : "=r" (tcb));
tcb = (void**)((uintptr_t)tcb & ~0x07UL); // clear lower 3 bits
#else
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
#endif
#endif
res = tcb[slot];
#endif
return res;
@ -744,12 +753,12 @@ static inline void mi_tls_slot_set(size_t slot, void* value) mi_attr_noexcept {
tcb[slot] = value;
#elif defined(__aarch64__)
void** tcb; UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
#if defined(__APPLE__) // M1, issue #343
__asm__ volatile ("mrs %0, tpidrro_el0" : "=r" (tcb));
tcb = (void**)((uintptr_t)tcb & ~0x07UL); // clear lower 3 bits
#else
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
#endif
#endif
tcb[slot] = value;
#endif
}