From 3421d7f5a1ed7ec5d19d01f8edda434ab17ae2c8 Mon Sep 17 00:00:00 2001 From: wwq Date: Mon, 2 Sep 2024 20:41:32 +0800 Subject: [PATCH] Prevent OH_JSVM_Init reentrancy Signed-off-by: wwq --- src/js_native_api_v8.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index e8a24ce8d..0b9053263 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -1,5 +1,6 @@ #include #include +#include #include // INT_MAX #include #include "v8-debug.h" @@ -1349,6 +1350,11 @@ v8::Platform* JSVM_Env__::platform() { JSVM_Status JSVM_CDECL OH_JSVM_Init(const JSVM_InitOptions* options) { + static std::atomic initialized(false); + if (initialized.load()) { + return JSVM_GENERIC_FAILURE; + } + initialized.store(true); #ifdef TARGET_OHOS v8impl::ResourceSchedule::ReportKeyThread(getuid(), getprocpid(), getproctid(), v8impl::ResourceSchedule::ResType::ThreadRole::IMPORTANT_DISPLAY); -- Gitee