From db74dbb3f73ff083f0574d551415aa5cb95baae7 Mon Sep 17 00:00:00 2001 From: liubinyu Date: Fri, 12 Jul 2024 13:35:34 +0800 Subject: [PATCH 1/2] move isCJAbility to cjruntime Change-Id: I41dadfea299e97f78b8c35fd1e454c9823fb09d4 --- .../frameworks/cj_environment/src/cj_environment.cpp | 11 ----------- cj_environment/interfaces/inner_api/cj_environment.h | 1 - cj_environment/interfaces/inner_api/cj_envsetup.h | 1 - frameworks/native/runtime/cj_runtime.cpp | 5 ++++- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp index 84131c4384..4b56f08019 100644 --- a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp +++ b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp @@ -15,7 +15,6 @@ #include "cj_environment.h" -#include #include #include "cj_hilog.h" @@ -476,13 +475,6 @@ bool CJEnvironment::StartDebugger() return true; } -bool IsCJAbility(const std::string& info) -{ - // in cj application, the srcEntry format should be packageName.AbilityClassName. - std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$"; - return std::regex_match(info, std::regex(pattern)); -} - CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance() { static CJEnvMethods gCJEnvMethods { @@ -519,9 +511,6 @@ CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance() .registerCJUncaughtExceptionHandler = [](const CJUncaughtExceptionInfo& handle) { return CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(handle); }, - .isCJAbility = [](const std::string& info) { - return IsCJAbility(info); - }, .setSanitizerKindRuntimeVersion = [](SanitizerKind kind) { return CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(kind); } diff --git a/cj_environment/interfaces/inner_api/cj_environment.h b/cj_environment/interfaces/inner_api/cj_environment.h index 228de02dc3..9ba9163634 100644 --- a/cj_environment/interfaces/inner_api/cj_environment.h +++ b/cj_environment/interfaces/inner_api/cj_environment.h @@ -91,7 +91,6 @@ private: SanitizerKind sanitizerKind_ {SanitizerKind::NONE}; }; -CJ_EXPORT bool IsCJAbility(const std::string& info); } #endif //OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H diff --git a/cj_environment/interfaces/inner_api/cj_envsetup.h b/cj_environment/interfaces/inner_api/cj_envsetup.h index c7809d27c4..ae425359c7 100644 --- a/cj_environment/interfaces/inner_api/cj_envsetup.h +++ b/cj_environment/interfaces/inner_api/cj_envsetup.h @@ -50,7 +50,6 @@ struct CJEnvMethods { void* (*loadCJLibrary)(const char* dllName) = nullptr; bool (*startDebugger)() = nullptr; void (*registerCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) = nullptr; - bool (*isCJAbility)(const std::string& info) = nullptr; void (*setSanitizerKindRuntimeVersion)(SanitizerKind kind) = nullptr; }; diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 0c8b305362..d290fb8444 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "cj_envsetup.h" #include "hilog_tag_wrapper.h" @@ -113,7 +114,9 @@ void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& bool CJRuntime::IsCJAbility(const std::string& info) { - return OHOS::CJEnv::LoadInstance()->isCJAbility(info); + // in cj application, the srcEntry format should be packageName.AbilityClassName. + std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$"; + return std::regex_match(info, std::regex(pattern)); } bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) From 3bed1ce0ff1696b1c10363014caf97b3c29ca69f Mon Sep 17 00:00:00 2001 From: liubinyu Date: Mon, 15 Jul 2024 22:23:10 +0800 Subject: [PATCH 2/2] fix codecheck CJEnv loadInstance Change-Id: Ic0a33e4038ad2a318974f67d99e906bf411cc2fe --- frameworks/native/runtime/cj_runtime.cpp | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index d290fb8444..438d462fcb 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -78,10 +78,15 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths) appPath += appPath.empty() ? libPath : ":" + libPath; } } - OHOS::CJEnv::LoadInstance()->initCJChipSDKNS(CJ_CHIPSDK_PATH); - OHOS::CJEnv::LoadInstance()->initCJAppNS(appPath); - OHOS::CJEnv::LoadInstance()->initCJSDKNS(CJ_RT_PATH + ":" + CJ_LIB_PATH); - OHOS::CJEnv::LoadInstance()->initCJSysNS(CJ_SYSLIB_PATH); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return; + } + cjEnv->initCJChipSDKNS(CJ_CHIPSDK_PATH); + cjEnv->initCJAppNS(appPath); + cjEnv->initCJSDKNS(CJ_RT_PATH + ":" + CJ_LIB_PATH); + cjEnv->initCJSysNS(CJ_SYSLIB_PATH); } bool CJRuntime::Initialize(const Options& options) @@ -90,11 +95,16 @@ bool CJRuntime::Initialize(const Options& options) TAG_LOGE(AAFwkTag::CJRUNTIME, "CJRuntime Initialize fail, language mismatch"); return false; } - if (!OHOS::CJEnv::LoadInstance()->startRuntime()) { + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return false; + } + if (!cjEnv->startRuntime()) { TAG_LOGE(AAFwkTag::CJRUNTIME, "start cj runtime failed"); return false; } - if (!OHOS::CJEnv::LoadInstance()->startUIScheduler()) { + if (!cjEnv->startUIScheduler()) { TAG_LOGE(AAFwkTag::CJRUNTIME, "start cj ui context failed"); return false; } @@ -109,7 +119,12 @@ bool CJRuntime::Initialize(const Options& options) void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) { - OHOS::CJEnv::LoadInstance()->registerCJUncaughtExceptionHandler(uncaughtExceptionInfo); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return; + } + cjEnv->registerCJUncaughtExceptionHandler(uncaughtExceptionInfo); } bool CJRuntime::IsCJAbility(const std::string& info) @@ -121,6 +136,11 @@ bool CJRuntime::IsCJAbility(const std::string& info) bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) { + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return false; + } void* handle = nullptr; for (const auto& libPath : appLibPaths) { for (auto& itor : std::filesystem::directory_iterator(libPath)) { @@ -128,7 +148,7 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) if (itor.path().string().find("ohos_app_cangjie") == std::string::npos) { continue; } - handle = OHOS::CJEnv::LoadInstance()->loadCJLibrary(itor.path().c_str()); + handle = cjEnv->loadCJLibrary(itor.path().c_str()); if (handle == nullptr) { char* errMsg = dlerror(); TAG_LOGE(AAFwkTag::CJRUNTIME, @@ -143,17 +163,32 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) void CJRuntime::SetAsanVersion() { - OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::ASAN); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return; + } + cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::ASAN); } void CJRuntime::SetTsanVersion() { - OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::TSAN); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return; + } + cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::TSAN); } void CJRuntime::SetHWAsanVersion() { - OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::HWASAN); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return; + } + cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::HWASAN); } void CJRuntime::StartDebugMode(const DebugOption dOption) @@ -195,7 +230,12 @@ void CJRuntime::StartDebugMode(const DebugOption dOption) bool CJRuntime::StartDebugger() { - return OHOS::CJEnv::LoadInstance()->startDebugger(); + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed."); + return false; + } + return cjEnv->startDebugger(); } void CJRuntime::UnLoadCJAppLibrary()