From 0155a3773f874eba99ba0a8bebbf5404a3fb2d52 Mon Sep 17 00:00:00 2001 From: wanglei Date: Thu, 4 Sep 2025 12:42:09 +0000 Subject: [PATCH] move dlopen arkweb so to webview Signed-off-by: wanglei --- standard/BUILD.gn | 17 ++--- standard/appspawn_reclaim.cpp | 24 ------- standard/appspawn_reclaim.h | 29 -------- standard/appspawn_service.c | 123 ++++------------------------------ 4 files changed, 18 insertions(+), 175 deletions(-) delete mode 100644 standard/appspawn_reclaim.cpp delete mode 100644 standard/appspawn_reclaim.h diff --git a/standard/BUILD.gn b/standard/BUILD.gn index 1aca6758..8ee79107 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -50,17 +50,8 @@ 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") { - defines += [ "PRE_DLOPEN_ARKWEB_LIB" ] - } configs = [ ":appspawn_server_config", "${appspawn_path}:appspawn_config", @@ -88,9 +79,6 @@ 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" ] @@ -111,6 +99,11 @@ ohos_executable("appspawn") { "selinux_adapter:libhap_restorecon", ] } + + if (appspawn_support_nweb) { + external_deps += [ "webview:libarkweb_utils" ] + defines += [ "ARKWEB_UTILS_ENABLE" ] + } cflags = [] #ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64z" ] diff --git a/standard/appspawn_reclaim.cpp b/standard/appspawn_reclaim.cpp deleted file mode 100644 index 9f5cffb7..00000000 --- a/standard/appspawn_reclaim.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 deleted file mode 100644 index b04fea4a..00000000 --- a/standard/appspawn_reclaim.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 54e673b2..179c5a59 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -41,15 +41,15 @@ #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 #include "appspawn_hisysevent.h" #include "hisysevent_adapter.h" #endif +#ifdef ARKWEB_UTILS_ENABLE +#include "arkweb_preload.h" +#endif #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 #define FD_PATH_SIZE 128 @@ -63,11 +63,6 @@ #define PIDFD_NONBLOCK O_NONBLOCK #endif -#if (defined(PRE_DLOPEN_ARKWEB_LIB) && !defined(ASAN_DETECTOR)) -#define MAX_DLCLOSE_COUNT 10 -#define LIB_ARKWEB_ENGINE "libarkweb_engine.so" -#endif - static void WaitChildTimeout(const TimerHandle taskHandle, void *context); static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_t *events, const void *context); static void WaitChildDied(pid_t pid); @@ -1661,106 +1656,6 @@ APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connecti DeleteAppSpawnMsg(&message); } -#if (defined(PRE_DLOPEN_ARKWEB_LIB) && !defined(ASAN_DETECTOR)) -static bool IsNWebLibLoaded(Dl_namespace dlns) -{ - void* handler = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE, RTLD_NOW | RTLD_NOLOAD); - if (handler) { - dlclose(handler); - return true; - } - return false; -} -#endif - -static void ProcessSpawnDlcloseMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) -{ - AppSpawnMsg* msg = &message->msgHeader; - APPSPAWN_LOGI("Recv ProcessSpawnDlcloseMsg message header magic: 0x%{public}x type: %{public}u" - "id: %{public}u len: %{public}u processName: %{public}s", - msg->magic, - msg->msgType, - msg->msgId, - msg->msgLen, - msg->processName); - -#if (defined(PRE_DLOPEN_ARKWEB_LIB) && !defined(ASAN_DETECTOR)) - Dl_namespace dlns; - if (dlns_get("nweb_ns", &dlns) != 0) { - APPSPAWN_LOGI("Failed to get nweb_ns"); - SendResponse(connection, msg, 0, 0); - return; - } - - void* webEngineHandle = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE, RTLD_NOW | RTLD_NOLOAD); - if (!webEngineHandle) { - APPSPAWN_LOGE("FAILED to find %{public}s in appspawn %{public}s", LIB_ARKWEB_ENGINE, dlerror()); - SendResponse(connection, msg, 0, 0); - return; - } - - int cnt = MAX_DLCLOSE_COUNT; - do { - cnt--; - dlclose(webEngineHandle); - } while (cnt > 0 && IsNWebLibLoaded(dlns)); - - if (cnt == 0 && IsNWebLibLoaded(dlns)) { - SendResponse(connection, msg, -1, 0); - return; - } -#endif - SendResponse(connection, msg, 0, 0); -} - -static void ProcessSpawnDlopenMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) -{ - AppSpawnMsg* msg = &message->msgHeader; - APPSPAWN_LOGI("Recv ProcessSpawnReqMsg message header magic: 0x%{public}x type: %{public}u" - "id: %{public}u len: %{public}u processName: %{public}s", - msg->magic, - msg->msgType, - msg->msgId, - msg->msgLen, - msg->processName); - -#if (defined(PRE_DLOPEN_ARKWEB_LIB) && !defined(ASAN_DETECTOR)) - Dl_namespace dlns; - if (dlns_get("nweb_ns", &dlns) != 0) { - char arkwebLibPath[PATH_SIZE] = ""; - if (snprintf_s(arkwebLibPath, sizeof(arkwebLibPath), sizeof(arkwebLibPath) - 1, - "%s%s%s", "/data/app/el1/bundle/public/", msg->processName, - "/libs/arm64:/data/storage/el1/bundle/arkwebcore/libs/arm64") < 0) { - APPSPAWN_LOGE("FAILED to get arkwebLibPath"); - SendResponse(connection, msg, -1, 0); - return; - } - APPSPAWN_LOGI("ProcessSpawnDlopenMsg arkwebLibPath: %{public}s", arkwebLibPath); - - dlns_init(&dlns, "nweb_ns"); - dlns_create(&dlns, arkwebLibPath); - - Dl_namespace ndkns; - dlns_get("ndk", &ndkns); - dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); - } - - void* webEngineHandle = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE, RTLD_NOW | RTLD_GLOBAL); - if (!webEngineHandle) { - APPSPAWN_LOGE("FAILED to dlopen %{public}s in appspawn %{public}s", LIB_ARKWEB_ENGINE, dlerror()); - SendResponse(connection, msg, -1, 0); - } else { - APPSPAWN_LOGI("SUCCESS to dlopen %{public}s in appspawn", LIB_ARKWEB_ENGINE); - SendResponse(connection, msg, 0, 0); -#ifndef OHOS_LITE - ReclaimFileCache(); -#endif - } -#else - SendResponse(connection, msg, 0, 0); -#endif -} - static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { AppSpawnMsg *msg = &message->msgHeader; @@ -1822,11 +1717,19 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess ProcessObserveProcessSignalMsg(connection, message); break; case MSG_UNLOAD_WEBLIB_IN_APPSPAWN: - ProcessSpawnDlcloseMsg(connection, message); +#ifdef ARKWEB_UTILS_ENABLE + ret = ProcessSpawnDlcloseMsg(); +#else + ret = 0; +#endif + SendResponse(connection, msg, ret, 0); DeleteAppSpawnMsg(&message); break; case MSG_LOAD_WEBLIB_IN_APPSPAWN: - ProcessSpawnDlopenMsg(connection, message); +#ifdef ARKWEB_UTILS_ENABLE + ProcessSpawnDlopenMsg(); +#endif + SendResponse(connection, msg, 0, 0); DeleteAppSpawnMsg(&message); break; default: -- Gitee