diff --git a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp index 149b74238f0d98f3ad2a22d7a90e700116159583..451eb2739226b960e97ec1acbdca2473c446be1d 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp +++ b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp @@ -108,6 +108,13 @@ void GuardedPoolAllocator::installAtFork() { if (auto *S = getSingleton()) S->enable(); }; +#if defined(__OHOS__) + // We need to run the gwpasan handler to unlock first after the fork, + // otherwise other handlers may call gwpasan malloc to cause a deadlock. + // This interface will let the gwpasan handler to be executed first after the fork. + pthread_atfork_for_gwpasan(Disable, Enable, Enable); // OHOS_LOCAL +#else pthread_atfork(Disable, Enable, Enable); +#endif } } // namespace gwp_asan