summaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
authordaan <daan@microsoft.com>2019-07-02 12:49:28 -0700
committerdaan <daan@microsoft.com>2019-07-02 12:49:28 -0700
commitaeff1db32b8dd552a9f643b71241519acafc125c (patch)
tree3a53949cd79dc86f642abfd0e2bb839a30341a5c /src/init.c
parentd35fc6cdc44d209fcb12d5311a91f76604d5a8b5 (diff)
Fixing interpose on macOS
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/init.c b/src/init.c
index 6b05907..5a75050 100644
--- a/src/init.c
+++ b/src/init.c
@@ -102,7 +102,7 @@ mi_heap_t _mi_heap_main = {
NULL,
0,
0,
- 0,
+ 0xCDCDCDCDCDCDCDL,
0,
false // can reclaim
};
@@ -355,11 +355,15 @@ static void mi_process_done(void);
void mi_process_init(void) mi_attr_noexcept {
// ensure we are called once
if (_mi_process_is_initialized) return;
+ // access _mi_heap_default before setting _mi_process_is_initialized to ensure
+ // that the TLS slot is allocated without getting into recursion on macOS
+ // when using dynamic linking with interpose.
+ mi_heap_t* h = _mi_heap_default;
_mi_process_is_initialized = true;
_mi_heap_main.thread_id = _mi_thread_id();
_mi_verbose_message("process init: 0x%zx\n", _mi_heap_main.thread_id);
- uintptr_t random = _mi_random_init(_mi_heap_main.thread_id);
+ uintptr_t random = _mi_random_init(_mi_heap_main.thread_id) ^ (uintptr_t)h;
_mi_heap_main.cookie = (uintptr_t)&_mi_heap_main ^ random;
_mi_heap_main.random = _mi_random_shuffle(random);
#if (MI_DEBUG)