From 811c7eef2dc21086b14d44ba1da8389f3969ecf6 Mon Sep 17 00:00:00 2001 From: zzhengxiang <2646125453@qq.com> Date: Tue, 9 Sep 2025 21:12:33 +0800 Subject: [PATCH] change hisysevent param type to bool Signed-off-by: zzhengxiang <2646125453@qq.com> --- src/js_native_api_v8.cpp | 15 +++---- src/platform/platform_ohos.cpp | 81 +++++++++++++++++++++------------- src/platform/platform_ohos.h | 4 +- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/js_native_api_v8.cpp b/src/js_native_api_v8.cpp index 5b4d54f..03041ea 100644 --- a/src/js_native_api_v8.cpp +++ b/src/js_native_api_v8.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include "v8-debug.h" @@ -245,10 +244,6 @@ static constexpr const char* INTERNAL_TRACE_CATEGORIES[] = { constexpr uint32_t DEFAULT_CATEGORY_COUNT = 4; static constexpr JSVM_TraceCategory DEFAULT_CATAGORIES[] = { JSVM_TRACE_VM, JSVM_TRACE_EXECUTE, JSVM_TRACE_COMPILE, JSVM_TRACE_RUNTIME }; -const std::string jitEventMessage = "The application does not have ACL certificate authorization or has enable " - "the Sercure Shield Mode. The WASM capability will be disabled, and the " - "performance of JS execution will degrade. For details, see " - "\"Requesting Restricted Permission\" in the developer documentation."; static inline v8::ArrayBuffer::Allocator* GetOrCreateDefaultArrayBufferAllocator() { @@ -1069,7 +1064,7 @@ JSVM_Status OH_JSVM_Init(const JSVM_InitOptions* options) } initialized.store(true); - OHOS_CALL(platform::ohos::WriteHisysevent("Init jsvm.")); + OHOS_CALL(platform::ohos::WriteJSVMInitToHisysevent()); OHOS_CALL(platform::ohos::ReportKeyThread(platform::ohos::ThreadRole::IMPORTANT_DISPLAY)); v8::V8::InitializePlatform(v8impl::g_platform.get()); @@ -1563,7 +1558,7 @@ JSVM_Status OH_JSVM_RunScript(JSVM_Env env, JSVM_Script script, JSVM_Value* resu std::call_once(jitCheckFlag, []() { LOG(Info) << "Run OH_JSVM_RunScript may failed: The application does not have ACL certificate " "authorization or has enabled the Secure Shield Mode."; - OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); + OHOS_CALL(platform::ohos::WriteJitBlockedToHisysevent()); }); } @@ -4932,7 +4927,7 @@ JSVM_Status OH_JSVM_CompileWasmModule(JSVM_Env env, if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CompileWasmModule failed: The application does not have ACL certificate " "authorization or has enabled the Secure Shield Mode."; - OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); + OHOS_CALL(platform::ohos::WriteJitBlockedToHisysevent()); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmBytecode); @@ -4967,7 +4962,7 @@ JSVM_Status OH_JSVM_CompileWasmFunction(JSVM_Env env, if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CompileWasmFunction failed: The application does not have ACL certificate " "authorization or has enabled the Secure Shield Mode."; - OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); + OHOS_CALL(platform::ohos::WriteJitBlockedToHisysevent()); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmModule); @@ -5015,7 +5010,7 @@ JSVM_Status OH_JSVM_CreateWasmCache(JSVM_Env env, JSVM_Value wasmModule, const u if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CreateWasmCache failed: The application does not have ACL certificate authorization" " or has enabled the Secure Shield Mode."; - OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); + OHOS_CALL(platform::ohos::WriteJitBlockedToHisysevent()); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmModule); diff --git a/src/platform/platform_ohos.cpp b/src/platform/platform_ohos.cpp index 8d65e53..ae837f3 100644 --- a/src/platform/platform_ohos.cpp +++ b/src/platform/platform_ohos.cpp @@ -144,7 +144,7 @@ namespace ohos { #define JITFORT_QUERY_ENCAPS 'E' #define HM_PR_SET_JITFORT 0x6a6974 -bool ProcessBundleName(std::string& bundleName); +bool ProcessBundleNameParam(std::string& bundleName); bool InJitMode() { @@ -254,53 +254,72 @@ bool LoadStringFromFile(const std::string& filePath, std::string& content) return true; } -bool ProcessBundleName(std::string& bundleName) +std::unique_ptr ProcessBundleNameParam() { int pid = getprocpid(); - std::string filePath = "/proc/" + std::to_string(pid) + "/cmdline"; - if (!LoadStringFromFile(filePath, bundleName)) { - return false; - } - if (bundleName.empty()) { - return false; + static std::string bundleName; + if (bundleName == "") { + std::string filePath = "/proc/" + std::to_string(pid) + "/cmdline"; + if (LoadStringFromFile(filePath, bundleName) && !bundleName.empty()) { + auto pos = bundleName.find(":"); + if (pos != std::string::npos) { + bundleName = bundleName.substr(0, pos); + } + } else { + bundleName = "INVALID_BUNDLE_NAME"; + } } - auto pos = bundleName.find(":"); - if (pos != std::string::npos) { - bundleName = bundleName.substr(0, pos); + std::unique_ptr name = std::make_unique(bundleName.size() + 1); + errno_t ret = strcpy_s(name.get(), bundleName.size() + 1, bundleName.c_str()); + if (ret != EOK) { + name.get()[0] = '\0'; } - bundleName = bundleName.substr(0, strlen(bundleName.c_str())); - return true; + return std::move(name); } -void WriteHisysevent(const std::string& message) +void WriteHisysevent(HiSysEventParam* params, int size) +{ + OH_HiSysEvent_Write(OHOS::HiviewDFX::HiSysEvent::Domain::JSVM_RUNTIME, "APP_STATS", + HiSysEventEventType::HISYSEVENT_STATISTIC, + params, size); +} + +void WriteJSVMInitToHisysevent() { #ifdef ENABLE_HISYSEVENT - static std::string bundleName = ""; - if (bundleName == "") { - if (!ProcessBundleName(bundleName)) { - bundleName = "INVALID_BUNDLE_NAME"; - } - } - std::unique_ptr name = std::make_unique(bundleName.size() + 1); - strcpy_s(name.get(), bundleName.size() + 1, bundleName.c_str()); + std::unique_ptr name = ProcessBundleNameParam(); HiSysEventParam param = { .name = "BUNDLE_NAME", .t = HISYSEVENT_STRING, .v = { .s = name.get() }, .arraySize = 0, }; - std::unique_ptr eventMessage = std::make_unique(message.size() + 1); - strcpy_s(eventMessage.get(), message.size() + 1, message.c_str()); - HiSysEventParam messageParam = { - .name = "MESSAGE", + HiSysEventParam params[] = { param }; + WriteHisysevent(params, sizeof(params) / sizeof(params[0])); +#endif +} + +void WriteJitBlockedToHisysevent() +{ +#ifdef ENABLE_HISYSEVENT + static bool blockHasWritten = false; + if (blockHasWritten) { return; } + blockHasWritten = true; + std::unique_ptr name = ProcessBundleNameParam(); + HiSysEventParam param = { + .name = "BUNDLE_NAME", .t = HISYSEVENT_STRING, - .v = { .s = eventMessage.get() }, + .v = { .s = name.get() }, .arraySize = 0, }; - HiSysEventParam params[] = { param, messageParam }; - OH_HiSysEvent_Write(OHOS::HiviewDFX::HiSysEvent::Domain::JSVM_RUNTIME, "APP_STATS", - HiSysEventEventType::HISYSEVENT_STATISTIC, - params, sizeof(params) / sizeof(params[0])); + HiSysEventParam runJitParam = { + .name = "IF_JIT_BLOCKED", + .t = HISYSEVENT_BOOL, + .v = { .b = true }, + .arraySize = 0, + }; + HiSysEventParam params[] = { param, runJitParam }; + WriteHisysevent(params, sizeof(params) / sizeof(params[0])); #endif } } // namespace ohos diff --git a/src/platform/platform_ohos.h b/src/platform/platform_ohos.h index 12caafd..be9725f 100644 --- a/src/platform/platform_ohos.h +++ b/src/platform/platform_ohos.h @@ -34,7 +34,9 @@ void ReportKeyThread(ThreadRole role); void SetSecurityMode(); -void WriteHisysevent(const std::string& message); +void WriteJSVMInitToHisysevent(); + +void WriteJitBlockedToHisysevent(); bool InJitMode(); } // namespace ohos -- Gitee