diff --git a/modules/ace_adapter/BUILD.gn b/modules/ace_adapter/BUILD.gn index 5f94d3bb8fdc8d42364f9bf404bcc4b26c206115..6b6489020af5cb67cd7901e41d5587808c8a57b2 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 c24a25259f27173236c34af9a7b9a8488c6f2b85..e92c046dfdf225481adeabe1f079fb2d651540f9 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 69e0637800332984d8d401b98561eeb98e70ef96..82c87b039b7aeb01d75a581b54af0f9cfee561c7 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 0000000000000000000000000000000000000000..9f5cffb7675f49d45b971909f5adf23a7c9bd4a3 --- /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 0000000000000000000000000000000000000000..b04fea4a0006df81d068f007631c71f2dba57d01 --- /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 d80261f10a9954c44d0ad004d2bc34bafa3fd5a8..8a0a598931cb40ce3b9c529320b81ae0aa879681 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);