From 329917cf5df81449037cd8bf6c5b1f1009744d61 Mon Sep 17 00:00:00 2001 From: wanglei Date: Sat, 16 Aug 2025 12:26:34 +0000 Subject: [PATCH] dlopen arkweb so after OTA scan Signed-off-by: wanglei --- modules/ace_adapter/BUILD.gn | 3 --- modules/ace_adapter/ace_adapter.cpp | 35 +---------------------------- standard/BUILD.gn | 10 +++++++++ standard/appspawn_reclaim.cpp | 24 ++++++++++++++++++++ standard/appspawn_reclaim.h | 29 ++++++++++++++++++++++++ standard/appspawn_service.c | 8 ++++++- 6 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 standard/appspawn_reclaim.cpp create mode 100644 standard/appspawn_reclaim.h diff --git a/modules/ace_adapter/BUILD.gn b/modules/ace_adapter/BUILD.gn index 5f94d3bb..6b648902 100644 --- a/modules/ace_adapter/BUILD.gn +++ b/modules/ace_adapter/BUILD.gn @@ -30,9 +30,6 @@ ohos_shared_library("appspawn_ace") { "${appspawn_path}/util:libappspawn_util", ] defines = [] - if (target_cpu == "arm64") { - defines += [ "PRE_DLOPEN_ARKWEB_LIB" ] - } if (asan_detector || is_asan) { defines += [ "ASAN_DETECTOR" ] } diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index c24a2525..e92c046d 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -326,37 +326,6 @@ APPSPAWN_STATIC int DoDlopenLibs(const cJSON *root, ParseJsonContext *context) return 0; } -#ifdef PRE_DLOPEN_ARKWEB_LIB -static void DlopenArkWebLib() -{ - char packageName[PATH_MAX] = {0}; - GetParameter("persist.arkwebcore.package_name", "", packageName, PATH_MAX); - if (strlen(packageName) == 0) { - APPSPAWN_LOGE("persist.arkwebcore.package_name is empty"); - return; - } - - std::string arkwebLibPath = "/data/app/el1/bundle/public/" + std::string(packageName) + - "/libs/arm64:/data/storage/el1/bundle/arkwebcore/libs/arm64"; - APPSPAWN_LOGI("DlopenArkWebLib arkwebLibPath: %{public}s", arkwebLibPath.c_str()); - - Dl_namespace dlns; - dlns_init(&dlns, "nweb_ns"); - dlns_create(&dlns, arkwebLibPath.c_str()); - - Dl_namespace ndkns; - dlns_get("ndk", &ndkns); - dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); - - void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_GLOBAL); - if (!webEngineHandle) { - APPSPAWN_LOGE("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); - } else { - APPSPAWN_LOGI("SUCCESS to dlopen libarkweb_engine.so in appspawn"); - } -} -#endif - APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) { if (!(IsAppSpawnMode(content) || IsHybridSpawnMode(content))) { @@ -364,9 +333,7 @@ APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) } (void)ParseJsonConfig("etc/appspawn", SYSTEMLIB_JSON, DoDlopenLibs, nullptr); -#ifdef PRE_DLOPEN_ARKWEB_LIB - DlopenArkWebLib(); -#endif + APPSPAWN_LOGI("DlopenAppSpawn: Start reclaim file cache"); OHOS::Ace::AceForwardCompatibility::ReclaimFileCache(getpid()); return 0; diff --git a/standard/BUILD.gn b/standard/BUILD.gn index 69e06378..82c87b03 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -50,6 +50,12 @@ ohos_executable("appspawn") { "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", ] + if (!defined(ohos_lite)) { + sources += [ + "${appspawn_path}/standard/appspawn_reclaim.h", + "${appspawn_path}/standard/appspawn_reclaim.cpp", + ] + } defines = [] if (target_cpu == "arm64") { @@ -82,6 +88,10 @@ ohos_executable("appspawn") { "hitrace:hitrace_meter", "init:libbegetutil", ] + if (!defined(ohos_lite)) { + external_deps += [ "ace_engine:ace_forward_compatibility" ] + } + if (enable_appspawn_dump_catcher) { external_deps += [ "faultloggerd:libdfx_dumpcatcher" ] } diff --git a/standard/appspawn_reclaim.cpp b/standard/appspawn_reclaim.cpp new file mode 100644 index 00000000..9f5cffb7 --- /dev/null +++ b/standard/appspawn_reclaim.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "appspawn_reclaim.h" + +#include +#include "ace_forward_compatibility.h" + +extern "C" void ReclaimFileCache() +{ + OHOS::Ace::AceForwardCompatibility::ReclaimFileCache(getpid()); +} \ No newline at end of file diff --git a/standard/appspawn_reclaim.h b/standard/appspawn_reclaim.h new file mode 100644 index 00000000..b04fea4a --- /dev/null +++ b/standard/appspawn_reclaim.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APPSPAWN_RECLAIM_H +#define APPSPAWN_RECLAIM_H + +#ifdef __cplusplus +extern "C" { +#endif + +void ReclaimFileCache(); + +#ifdef __cplusplus +} +#endif + +#endif // APPSPAWN_RECLAIM_H \ No newline at end of file diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index d80261f1..8a0a5989 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -43,6 +43,9 @@ #include "init_utils.h" #include "parameter.h" #include "appspawn_adapter.h" +#ifndef OHOS_LITE +#include "appspawn_reclaim.h" +#endif #include "securec.h" #include "cJSON.h" #ifdef APPSPAWN_HISYSEVENT @@ -1758,7 +1761,7 @@ static void ProcessSpawnDlopenMsg(AppSpawnConnection *connection, AppSpawnMsgNod msg->msgLen, msg->processName); -#ifdef PRE_DLOPEN_ARKWEB_LIB +#if (defined(PRE_DLOPEN_ARKWEB_LIB) && !defined(ASAN_DETECTOR)) Dl_namespace dlns; if (dlns_get("nweb_ns", &dlns) != 0) { char arkwebLibPath[PATH_SIZE] = ""; @@ -1786,6 +1789,9 @@ static void ProcessSpawnDlopenMsg(AppSpawnConnection *connection, AppSpawnMsgNod } else { APPSPAWN_LOGI("SUCCESS to dlopen libarkweb_engine.so in appspawn"); SendResponse(connection, msg, 0, 0); +#ifndef OHOS_LITE + ReclaimFileCache(); +#endif } #else SendResponse(connection, msg, 0, 0); -- Gitee