From c25ec2dae9c43009ec1e2de2bf306bc4ec376aba Mon Sep 17 00:00:00 2001 From: wanglei Date: Sat, 16 Aug 2025 12:26:34 +0000 Subject: [PATCH 1/2] 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 7b7befe0..cabdd720 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 f780bccd..eb42eacd 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -329,37 +329,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))) { @@ -367,9 +336,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()); #ifdef ARKWEB_UTILS_ENABLE 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 From 7ae37128174208fc886a749ca46aefa968c99015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Mon, 18 Aug 2025 16:06:34 +0800 Subject: [PATCH 2/2] modify res MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- common/appspawn_server.c | 6 ++++-- modules/ace_adapter/ace_adapter.cpp | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 2b7b2cea..09ec5c65 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -104,8 +104,8 @@ int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) AppSpawnEnvClear(content, client); return 0); - // notify success to father process and start app process - NotifyResToParent(content, client, 0); + APPSPAWN_CHECK_ONLY_EXPER(IsAppSpawnMode((AppSpawnMgr *)content), + NotifyResToParent(content, client, 0)); StartAppspawnTrace("AppSpawnExecutePostReplyHook"); (void)AppSpawnExecutePostReplyHook(content, client); @@ -115,6 +115,8 @@ int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) ret = content->runChildProcessor(content, client); } if (ret != 0) { + APPSPAWN_CHECK_ONLY_EXPER(!IsAppSpawnMode((AppSpawnMgr *)content), + NotifyResToParent(content, client, ret)); AppSpawnEnvClear(content, client); } return 0; diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index eb42eacd..bee2c182 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -220,6 +220,19 @@ static int BuildFdInfoMap(const AppSpawnMsgNode *message, std::mapforkCtx.fd[1]; + property->forkCtx.fd[1] = -1; + AppSpawnEnvClear(content, client); + APPSPAWN_CHECK(fd >= 0, return, "invalid fd for notify parent"); + int ret = 0; + (void)write(fd, &ret, sizeof(ret)); + (void)close(fd); +} + APPSPAWN_STATIC int RunChildThread(const AppSpawnMgr *content, const AppSpawningCtx *property) { std::string checkExit; @@ -230,10 +243,10 @@ APPSPAWN_STATIC int RunChildThread(const AppSpawnMgr *content, const AppSpawning if (CheckAppMsgFlagsSet(property, APP_FLAGS_CHILDPROCESS)) { std::map fdMap; BuildFdInfoMap(property->message, fdMap, IsColdRunMode(content)); - AppSpawnEnvClear((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); + ClearEnvAndReturnSuccess((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); OHOS::AppExecFwk::MainThread::StartChild(fdMap); } else { - AppSpawnEnvClear((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); + ClearEnvAndReturnSuccess((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); OHOS::AppExecFwk::MainThread::Start(); } unsetenv(APPSPAWN_CHECK_EXIT); @@ -265,7 +278,7 @@ APPSPAWN_STATIC int RunChildByRenderCmd(const AppSpawnMgr *content, const AppSpa } options.push_back(nullptr); // clear appspawn env, do not user any content and property - AppSpawnEnvClear((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); + ClearEnvAndReturnSuccess((AppSpawnContent *)&content->content, (AppSpawnClient *)&property->client); execvp(args[0].c_str(), options.data()); // If it succeeds calling execvp, it never returns. int err = errno; -- Gitee