diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h index 79ec524e6f..caa9be1cce 100644 --- a/headers/private/libroot/libroot_private.h +++ b/headers/private/libroot/libroot_private.h @@ -39,6 +39,8 @@ void __heap_terminate_after(void); void __heap_before_fork(void); void __heap_after_fork_child(void); void __heap_after_fork_parent(void); +void __heap_thread_init(void); +void __heap_thread_exit(void); void __init_time(addr_t commPageTable); void __arch_init_time(struct real_time_data *data, bool setDefaults); diff --git a/src/system/libroot/os/thread.c b/src/system/libroot/os/thread.c index 41e105e4c5..c92ce075f3 100644 --- a/src/system/libroot/os/thread.c +++ b/src/system/libroot/os/thread.c @@ -37,11 +37,13 @@ thread_entry(void* _entry, void* _thread) { thread_func entry = (thread_func)_entry; pthread_thread* thread = (pthread_thread*)_thread; - status_t returnCode; - returnCode = entry(thread->entry_argument); + __heap_thread_init(); + + status_t returnCode = entry(thread->entry_argument); _thread_do_exit_work(); + __heap_thread_exit(); return returnCode; } @@ -168,6 +170,7 @@ void exit_thread(status_t status) { _thread_do_exit_work(); + __heap_thread_exit(); _kern_exit_thread(status); } diff --git a/src/system/libroot/posix/malloc/wrapper.cpp b/src/system/libroot/posix/malloc/wrapper.cpp index 4465f512ea..ead5d22b4b 100644 --- a/src/system/libroot/posix/malloc/wrapper.cpp +++ b/src/system/libroot/posix/malloc/wrapper.cpp @@ -285,6 +285,18 @@ __heap_after_fork_parent(void) } +extern "C" void +__heap_thread_init(void) +{ +} + + +extern "C" void +__heap_thread_exit(void) +{ +} + + // #pragma mark - public functions diff --git a/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp b/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp index bf38d4c9e7..4a0f87022a 100644 --- a/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp +++ b/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp @@ -220,6 +220,18 @@ __heap_after_fork_parent(void) } +extern "C" void +__heap_thread_init(void) +{ +} + + +extern "C" void +__heap_thread_exit(void) +{ +} + + // #pragma mark - Public API diff --git a/src/system/libroot/posix/pthread/pthread.cpp b/src/system/libroot/posix/pthread/pthread.cpp index 967fb70024..6bd62f9f36 100644 --- a/src/system/libroot/posix/pthread/pthread.cpp +++ b/src/system/libroot/posix/pthread/pthread.cpp @@ -40,6 +40,8 @@ pthread_thread_entry(void*, void* _thread) { pthread_thread* thread = (pthread_thread*)_thread; + __heap_thread_init(); + pthread_exit(thread->entry(thread->entry_argument)); return 0; } diff --git a/src/system/libroot/stubbed/libroot_stubs.c b/src/system/libroot/stubbed/libroot_stubs.c index 370a85126b..cd05405dcf 100644 --- a/src/system/libroot/stubbed/libroot_stubs.c +++ b/src/system/libroot/stubbed/libroot_stubs.c @@ -880,6 +880,8 @@ void __heap_after_fork_child() {} void __heap_after_fork_parent() {} void __heap_before_fork() {} void __heap_terminate_after() {} +void __heap_thread_init() {} +void __heap_thread_exit() {} void __hypot() {} void __hypotf() {} void __hypotl() {}