diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp index 817008253fc0ef55018041afd38b414ada9542bf..81cc94e3365ff46918b61e251de885738c3da882 100644 --- a/compiler-rt/lib/asan/asan_interceptors.cpp +++ b/compiler-rt/lib/asan/asan_interceptors.cpp @@ -137,6 +137,17 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *) CheckNoDeepBind(filename, flag); \ REAL(dlopen)(filename, flag); \ }) +// OHOS_LOCAL begin +#if SANITIZER_OHOS +# define COMMON_INTERCEPTOR_DLOPEN_IMPL(filename, flag, namespace, caller_addr, extinfo) \ + ({ \ + if (flags()->strict_init_order) \ + StopInitOrderChecking(); \ + CheckNoDeepBind(filename, flag); \ + REAL(dlopen_impl)(filename, flag, namespace, caller_addr, extinfo); \ + }) +#endif +// OHOS_LOCAL end # define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit() # define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) # define COMMON_INTERCEPTOR_LIBRARY_UNLOADED() diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index c489cb2979f1835b2310484fbbcf4fd044ee228a..c9f5c174fc4d9ff4553a457761174f295ab3904d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -281,6 +281,14 @@ extern const short *_tolower_tab_; ({ CheckNoDeepBind(filename, flag); REAL(dlopen)(filename, flag); }) #endif +// OHOS_LOCAL begin +#if SANITIZER_OHOS +#ifndef COMMON_INTERCEPTOR_DLOPEN_IMPL +#define COMMON_INTERCEPTOR_DLOPEN_IMPL(filename, flag, namespace, caller_addr, extinfo) \ + ({ CheckNoDeepBind(filename, flag); REAL(dlopen_impl)(filename, flag, namespace, caller_addr, extinfo); }) +#endif +// OHOS_LOCAL end + #ifndef COMMON_INTERCEPTOR_GET_TLS_RANGE #define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end) *begin = *end = 0; #endif @@ -6534,6 +6542,24 @@ INTERCEPTOR(int, fclose, __sanitizer_FILE *fp) { #endif #if SANITIZER_INTERCEPT_DLOPEN_DLCLOSE +// OHOS_LOCAL begin +#if SANITIZER_OHOS +INTERCEPTOR(void*, dlopen_impl, const char *filename, int flag, const char *ns, const void *caller_addr, + const void *extinfo) { + void *ctx; + COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlopen_impl, filename, flag, ns, caller_addr, extinfo); + if (filename) COMMON_INTERCEPTOR_READ_STRING(ctx, filename, 0); + void *res = COMMON_INTERCEPTOR_DLOPEN_IMPL(filename, flag, ns, caller_addr, extinfo); + Symbolizer::GetOrInit()->InvalidateModuleList(); + COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, res); + return res; +} + +#define INIT_DLOPEN_DLCLOSE \ + COMMON_INTERCEPT_FUNCTION(dlopen_impl); \ + COMMON_INTERCEPT_FUNCTION(dlclose); + +#else INTERCEPTOR(void*, dlopen, const char *filename, int flag) { void *ctx; COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlopen, filename, flag); @@ -6544,6 +6570,12 @@ INTERCEPTOR(void*, dlopen, const char *filename, int flag) { return res; } +#define INIT_DLOPEN_DLCLOSE \ + COMMON_INTERCEPT_FUNCTION(dlopen); \ + COMMON_INTERCEPT_FUNCTION(dlclose); +#endif +// OHOS_LOCAL end + INTERCEPTOR(int, dlclose, void *handle) { void *ctx; COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlclose, handle); @@ -6552,9 +6584,6 @@ INTERCEPTOR(int, dlclose, void *handle) { COMMON_INTERCEPTOR_LIBRARY_UNLOADED(); return res; } -#define INIT_DLOPEN_DLCLOSE \ - COMMON_INTERCEPT_FUNCTION(dlopen); \ - COMMON_INTERCEPT_FUNCTION(dlclose); #else #define INIT_DLOPEN_DLCLOSE #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 66ace37d4d6256f8efb7db99c34df2164e0c5ad1..244516284ba78d2d45f6d8702dfe7bf3d3dea2d7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -450,9 +450,9 @@ #define SANITIZER_INTERCEPT_FCLOSE SI_POSIX #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE -// OHOS_LOCAL +. #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \ - (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && !SI_OHOS) || SI_MAC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID) || SI_MAC || SI_SOLARIS) #endif #define SANITIZER_INTERCEPT_GETPASS \ diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index 825814f54d824a1c24b169c041682d712029e957..579bbb1737c658c564f683e4d41dda5a993dc7c0 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -2391,7 +2391,18 @@ static void HandleRecvmsg(ThreadState *thr, uptr pc, ThreadIgnoreEnd(thr); \ res; \ }) - +// OHOS_LOCAL begin +#if SANITIZER_OHOS +#define COMMON_INTERCEPTOR_DLOPEN_IMPL(filename, flag, namespace, caller_addr, extinfo) \ + ({ \ + CheckNoDeepBind(filename, flag); \ + ThreadIgnoreBegin(thr, 0); \ + void *res = REAL(dlopen_impl)(filename, flag, namespace, caller_addr, extinfo); \ + ThreadIgnoreEnd(thr); \ + res; \ + }) +#endif +// OHOS_LOCAL end #define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) \ libignore()->OnLibraryLoaded(filename)