From 620c93b8ce5957c4036035f17e409a12e0cf82e3 Mon Sep 17 00:00:00 2001 From: wanglei Date: Wed, 7 May 2025 03:46:36 +0000 Subject: [PATCH 1/4] dlopen arkweb so in appspawen Signed-off-by: wanglei --- interfaces/innerkits/client/appspawn_client.c | 94 ++++++++++++---- .../client/libappspawn_client.versionscript | 2 + interfaces/innerkits/include/appspawn.h | 20 +++- modules/ace_adapter/BUILD.gn | 3 + modules/ace_adapter/ace_adapter.cpp | 25 +++++ standard/appspawn_service.c | 64 ++++++++++- .../app_spawn_interface_test.cpp | 29 +++++ .../app_spawn_service_test.cpp | 100 ++++++++++++++++++ 8 files changed, 312 insertions(+), 25 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 563b0569..da504d36 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -41,6 +41,9 @@ static AppSpawnReqMsgMgr *g_clientInstance[CLIENT_MAX] = {NULL}; static pthread_mutex_t g_spawnListenMutex = PTHREAD_MUTEX_INITIALIZER; static int g_spawnListenFd = 0; static bool g_spawnListenStart = false; +static pthread_mutex_t g_nativeSpawnListenMutex = PTHREAD_MUTEX_INITIALIZER; +static int g_nativeSpawnListenFd = 0; +static bool g_nativeSpawnListenStart = false; APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processName); @@ -271,6 +274,21 @@ APPSPAWN_STATIC void TryCreateSocket(AppSpawnReqMsgMgr *reqMgr) } } +static void SendSpawnListenMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode) +{ + if (reqMgr->type == CLIENT_FOR_APPSPAWN && reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { + pthread_mutex_lock(&g_spawnListenMutex); + SpawnListen(reqMgr, reqNode->msg->processName); + pthread_mutex_unlock(&g_spawnListenMutex); + } + + if (reqMgr->type == CLIENT_FOR_NATIVESPAWN && reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { + pthread_mutex_lock(&g_nativeSpawnListenMutex); + SpawnListen(reqMgr, reqNode->msg->processName); + pthread_mutex_unlock(&g_nativeSpawnListenMutex); + } +} + static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, AppSpawnResult *result) { uint32_t retryCount = 1; @@ -284,11 +302,8 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, continue; } } - if (reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { - pthread_mutex_lock(&g_spawnListenMutex); - SpawnListen(reqMgr, reqNode->msg->processName); - pthread_mutex_unlock(&g_spawnListenMutex); - } + SendSpawnListenMsg(reqMgr, reqNode); + if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) { UpdateSocketTimeout(ASAN_TIMEOUT, reqMgr->socketId); } @@ -317,33 +332,48 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, return APPSPAWN_TIMEOUT; } -APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processName) +APPSPAWN_STATIC int SpawnListenBase(AppSpawnReqMsgMgr *reqMgr, const char *processName, int fd, bool startFlag) { - AppSpawnClientType type = reqMgr->type; - if (g_spawnListenFd <= 0 || g_spawnListenStart) { - APPSPAWN_LOGV("Spawn Listen fail,fd:%{public}d,start:%{public}d", g_spawnListenFd, g_spawnListenStart); - return; + if (fd <= 0 || startFlag) { + APPSPAWN_LOGV("Spawn Listen fail, fd:%{public}d, startFlag:%{public}d", fd, startFlag); + return -1; } - APPSPAWN_CHECK((type == CLIENT_FOR_APPSPAWN), return, "Invalid type"); - APPSPAWN_CHECK(processName != NULL, return, "Invalid process name"); - - APPSPAWN_LOGI("Spawn Listen start type:%{public}d,fd:%{public}d", type, g_spawnListenFd); + AppSpawnClientType type = reqMgr->type; + APPSPAWN_LOGI("Spawn Listen start type:%{public}d, fd:%{public}d", type, fd); AppSpawnReqMsgHandle reqHandle; int ret = AppSpawnReqMsgCreate(MSG_OBSERVE_PROCESS_SIGNAL_STATUS, processName, &reqHandle); - APPSPAWN_CHECK(ret == 0, return, "Failed to create type:%{public}d req msg, ret = %{public}d", type, ret); + APPSPAWN_CHECK(ret == 0, return ret, "Failed to create type:%{public}d req msg, ret %{public}d", type, ret); - ret = AppSpawnReqMsgAddFd(reqHandle, SPAWN_LISTEN_FD_NAME, g_spawnListenFd); + ret = AppSpawnReqMsgAddFd(reqHandle, SPAWN_LISTEN_FD_NAME, fd); APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); - return, "Failed to add info message, ret=%{public}d", ret); + return ret, "Failed to add fd info to msg, ret %{public}d", ret); AppSpawnResult result = {0}; ret = ClientSendMsg(reqMgr, (AppSpawnReqMsgNode *)reqHandle, &result); - APPSPAWN_CHECK(ret == 0, return, "Send msg to type:%{public}d failed, ret=%{public}d", type, ret); - APPSPAWN_CHECK(result.result == 0, return, "Appspawn failed to handle message, result=%{public}d", result.result); + APPSPAWN_CHECK(ret == 0, return ret, "Send msg to type:%{public}d fail, ret %{public}d", type, ret); + APPSPAWN_CHECK(result.result == 0, return result.result, + "Spawn failed to handle listen msg, result %{public}d", result.result); + + APPSPAWN_LOGI("Spawn Listen client type:%{public}d send fd:%{public}d success", type, fd); + return 0; +} + +APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processName) +{ + APPSPAWN_CHECK(reqMgr != NULL, return, "Invalid reqMgr"); + APPSPAWN_CHECK(processName != NULL, return, "Invalid process name"); + + int ret = 0; + if (reqMgr->type == CLIENT_FOR_APPSPAWN) { + ret = SpawnListenBase(reqMgr, processName, g_spawnListenFd, g_spawnListenStart); + APPSPAWN_ONLY_EXPER(ret == 0, g_spawnListenStart = true); + } - g_spawnListenStart = true; - APPSPAWN_LOGI("Spawn Listen client type[%{public}d] Send fd[%{public}d] success", type, g_spawnListenFd); + if (reqMgr->type == CLIENT_FOR_NATIVESPAWN) { + ret = SpawnListenBase(reqMgr, processName, g_nativeSpawnListenFd, g_nativeSpawnListenStart); + APPSPAWN_ONLY_EXPER(ret == 0, g_nativeSpawnListenStart = true); + } } int AppSpawnClientInit(const char *serviceName, AppSpawnClientHandle *handle) @@ -455,6 +485,17 @@ int SpawnListenFdSet(int fd) return 0; } +int NativeSpawnListenFdSet(int fd) +{ + if (fd <= 0) { + APPSPAWN_LOGE("NativeSpawn Listen fd set[%{public}d] failed", fd); + return APPSPAWN_ARG_INVALID; + } + g_nativeSpawnListenFd = fd; + APPSPAWN_LOGI("NativeSpawn Listen fd set[%{public}d] success", fd); + return 0; +} + int SpawnListenCloseSet(void) { pthread_mutex_lock(&g_spawnListenMutex); @@ -462,4 +503,13 @@ int SpawnListenCloseSet(void) pthread_mutex_unlock(&g_spawnListenMutex); APPSPAWN_LOGI("Spawn Listen close set success"); return 0; -} \ No newline at end of file +} + +int NativeSpawnListenCloseSet(void) +{ + pthread_mutex_lock(&g_nativeSpawnListenMutex); + g_nativeSpawnListenStart = false; + pthread_mutex_unlock(&g_nativeSpawnListenMutex); + APPSPAWN_LOGI("NativeSpawn Listen close set success"); + return 0; +} diff --git a/interfaces/innerkits/client/libappspawn_client.versionscript b/interfaces/innerkits/client/libappspawn_client.versionscript index dce211fc..9e5ec6e7 100644 --- a/interfaces/innerkits/client/libappspawn_client.versionscript +++ b/interfaces/innerkits/client/libappspawn_client.versionscript @@ -37,6 +37,8 @@ GetPermissionIndex; GetMaxPermissionIndex; GetPermissionByIndex; + NativeSpawnListenFdSet; + NativeSpawnListenCloseSet; SpawnListenFdSet; SpawnListenCloseSet; local: diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index bd2f16d1..5058b77a 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -120,6 +120,7 @@ typedef enum { MSG_UNINSTALL_DEBUG_HAP, MSG_LOCK_STATUS, MSG_OBSERVE_PROCESS_SIGNAL_STATUS, + MSG_DLCLOSE_WEBLIB_IN_SPAWNER, MAX_TYPE_INVALID } AppSpawnMsgType; @@ -345,7 +346,7 @@ int32_t GetMaxPermissionIndex(AppSpawnClientHandle handle); const char *GetPermissionByIndex(AppSpawnClientHandle handle, int32_t index); /** - * @brief set up a pipe fd to capture the exit reason of a child process + * @brief set up a pipe fd to capture the exit reason of appspawn's child process * * @param fd fd for write signal info * @return if succeed return 0,else return other value @@ -353,12 +354,27 @@ const char *GetPermissionByIndex(AppSpawnClientHandle handle, int32_t index); int SpawnListenFdSet(int fd); /** - * @brief close the listener for child process exit + * @brief close the listener for appspawn's child process exits * * @return if succeed return 0,else return other value */ int SpawnListenCloseSet(void); +/** + * @brief set up a pipe fd to capture the exit reason of nativespawn's child process + * + * @param fd fd for write signal info + * @return if succeed return 0,else return other value + */ +int NativeSpawnListenFdSet(int fd); + +/** + * @brief close the listener for nativespawn's child process exits + * + * @return if succeed return 0,else return other value + */ +int NativeSpawnListenCloseSet(void); + #ifdef __cplusplus } #endif diff --git a/modules/ace_adapter/BUILD.gn b/modules/ace_adapter/BUILD.gn index 4c274652..d5c1fb76 100644 --- a/modules/ace_adapter/BUILD.gn +++ b/modules/ace_adapter/BUILD.gn @@ -30,6 +30,9 @@ ohos_shared_library("appspawn_ace") { "${appspawn_path}/util:libappspawn_util", ] defines = [] + if (target_cpu == "arm64") { + defines += [ "webview_arm64" ] + } 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 37da3a22..a86487dc 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -312,6 +312,31 @@ APPSPAWN_STATIC int DoDlopenLibs(const cJSON *root, ParseJsonContext *context) APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) { +#if defined(webview_arm64) + Dl_namespace dlns; + dlns_init(&dlns, "nweb_ns"); + dlns_create(&dlns, + "/data/app/el1/bundle/public/com.huawei.hmos.arkwebcore/libs/arm64:" + "/data/storage/el1/bundle/arkwebcore/libs/arm64"); + void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_GLOBAL); + if (!webEngineHandle) { + APPSPAWN_LOGI("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); + } else { + APPSPAWN_LOGI("SUCCESS to dlopen libarkweb_engine.so in appspawn"); + } + + // preload dlopen libohos_adapter_glue_source.z.so + const std::string libName = "/system/lib64/libohos_adapter_glue_source.z.so"; + void *handle = dlopen(libName.c_str(), RTLD_NOW | RTLD_GLOBAL); + if (handle == nullptr) { + APPSPAWN_LOGI("FAILED to dlopen libohos_adapter_glue_source.so in appspawn %{public}s", dlerror()); + } else { + APPSPAWN_LOGI("SUCCESS to dlopen libohos_adapter_glue_source.so in appspawn"); + } + + OHOS::Ace::AceForwardCompatibility::ReclaimFileCache(getpid()); +#endif + if (!IsAppSpawnMode(content)) { return 0; } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index de1f3c89..010bc646 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -15,6 +15,7 @@ #include "appspawn_service.h" +#include #include #include #include @@ -67,6 +68,9 @@ static void WaitChildDied(pid_t pid); static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, uint32_t buffLen); static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message); +// When arkweb is upgraded, the maximum number of dlclose loop iterations. +const int MAX_DLCLOSE_COUNT = 10; + // FD_CLOEXEC static inline void SetFdCtrl(int fd, int opt) { @@ -167,7 +171,7 @@ APPSPAWN_STATIC void WriteSignalInfoToFd(AppSpawnedProcess *appInfo, AppSpawnCon APPSPAWN_LOGE("Spawn Listen failed to write signal info to fd errno %{public}d", errno); return; } - APPSPAWN_LOGV("Spawn Listen successfully write signal info[%{public}s] to fd", jsonString); + APPSPAWN_LOGV("Spawn Listen write signal info %{public}s to fd %{public}d success", jsonString, content->signalFd); free(jsonString); } @@ -1528,6 +1532,14 @@ static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNod #else static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { + AppSpawnMsg* msg = &message->msgHeader; + APPSPAWN_LOGI("Recv ProcessSpawnRemountMsg 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); char srcPath[PATH_SIZE] = {0}; int len = GetArkWebInstallPath("persist.arkwebcore.install_path", srcPath); APPSPAWN_CHECK(len > 0, return -1, "Failed to get arkwebcore install path"); @@ -1582,6 +1594,51 @@ static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNod } #endif +static bool IsNWebLibLoaded(Dl_namespace dlns) +{ + void* handler = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_NOLOAD); + if (handler) { + dlclose(handler); + return true; + } + return false; +} + +static int ProcessSpawnDlcloseMsg(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); + Dl_namespace dlns; + if (dlns_get("nweb_ns", &dlns) != 0) { + APPSPAWN_LOGE("Failed to get nweb ns"); + return 0; + } + + void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_GLOBAL); + if (!webEngineHandle) { + APPSPAWN_LOGI("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); + return 0; + } + + int cnt = MAX_DLCLOSE_COUNT; + do { + cnt--; + dlclose(webEngineHandle); + + if (cnt == 0 && IsNWebLibLoaded(dlns)) { + APPSPAWN_LOGE("ProcessSpawnReqMsg dlclose retry 10 times, return"); + } + } while (cnt > 0 && IsNWebLibLoaded(dlns)); + + return 0; +} + static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { AppSpawnContent *content = GetAppSpawnContent(); @@ -1874,6 +1931,11 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_OBSERVE_PROCESS_SIGNAL_STATUS: ProcessObserveProcessSignalMsg(connection, message); break; + case MSG_DLCLOSE_WEBLIB_IN_SPAWNER: + ret = ProcessSpawnDlcloseMsg(connection, message); + SendResponse(connection, msg, ret, 0); + DeleteAppSpawnMsg(&message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(&message); diff --git a/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp b/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp index 3edef90a..755c1c3f 100644 --- a/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp +++ b/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp @@ -638,6 +638,35 @@ HWTEST_F(AppSpawnInterfaceTest, App_SpawnListenCloseSet_001, TestSize.Level0) EXPECT_EQ(ret, 0); } +/** + * @brief 测试接口:NativeSpawnListenFdSet + * + */ +HWTEST_F(AppSpawnInterfaceTest, Native_SpawnListenFdSet_001, TestSize.Level0) +{ + int ret = NativeSpawnListenFdSet(-1); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + + int pipefd[2]; + EXPECT_EQ(pipe(pipefd), 0); + + ret = NativeSpawnListenFdSet(pipefd[1]); + EXPECT_EQ(ret, 0); + + close(pipefd[0]); + close(pipefd[1]); +} + +/** + * @brief 测试接口:NativeSpawnListenCloseSet + * + */ +HWTEST_F(AppSpawnInterfaceTest, Native_SpawnListenCloseSet_001, TestSize.Level0) +{ + int ret = NativeSpawnListenCloseSet(); + EXPECT_EQ(ret, 0); +} + /** * @brief 测试接口:AppSpawnClientSendUserLockStatus * diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index 84e41d9d..9f5dfe1b 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -743,6 +743,106 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_012, TestSize.Level0) } while (0); } +/** + * @brief 测试子进程退出时,nativespawn通过fd中发送子进程退出状态,发送失败 + * + */ +HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_013, TestSize.Level0) +{ + int ret = 0; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnResult result = {}; + do { + int pipefd[2]; // 2 pipe fd + char buffer[1024]; // 1024 1k + APPSPAWN_CHECK(pipe(pipefd) == 0, break, "Failed to pipe fd errno:%{public}d", errno); + ret = NativeSpawnListenFdSet(pipefd[0]); + + ret = AppSpawnClientInit(NATIVESPAWN_SERVER_NAME, &clientHandle); + APPSPAWN_CHECK(ret == 0, break, "Failed to create client %{public}s", NATIVESPAWN_SERVER_NAME); + AppSpawnReqMsgHandle reqHandle = testServer->CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); + AppSpawnClientDestroy(clientHandle); + sleep(1); // wait child process stand up + + AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); + ASSERT_NE(app, nullptr); + char commamd[16]; // command len 16 + APPSPAWN_CHECK(sprintf_s(commamd, 16, "kill -9 %d", app->pid) > 0, break, "sprintf command unsuccess"); + system(commamd); + + bool isFind = false; + int count = 0; + while (count < 10) { + if (read(pipefd[1], buffer, sizeof(buffer)) <= 0) { + count++; + continue; + } + if (strstr(buffer, std::to_string(app->pid).c_str()) != NULL) { + isFind = true; + break; + } + count++; + } + close(pipefd[0]); + close(pipefd[1]); + ASSERT_EQ(isFind, false); + NativeSpawnListenCloseSet(); + } while (0); +} + +/** + * @brief 测试子进程退出时,nativespawn通过fd中发送子进程退出状态,发送成功 + * + */ +HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_014, TestSize.Level0) +{ + int ret = 0; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnResult result = {}; + do { + int pipefd[2]; // 2 pipe fd + char buffer[1024]; // 1024 1k + APPSPAWN_CHECK(pipe(pipefd) == 0, break, "Failed to pipe fd errno:%{public}d", errno); + ret = NativeSpawnListenFdSet(pipefd[1]); + + ret = AppSpawnClientInit(NATIVESPAWN_SERVER_NAME, &clientHandle); + APPSPAWN_CHECK(ret == 0, break, "Failed to create client %{public}s", NATIVESPAWN_SERVER_NAME); + AppSpawnReqMsgHandle reqHandle = testServer->CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); + AppSpawnClientDestroy(clientHandle); + sleep(1); // wait child process stand up + + AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); + ASSERT_NE(app, nullptr); + char commamd[16]; // command len 16 + APPSPAWN_CHECK(sprintf_s(commamd, 16, "kill -9 %d", app->pid) > 0, break, "sprintf command unsuccess"); + system(commamd); + + bool isFind = false; + int count = 0; + while (count < 10) { + if (read(pipefd[0], buffer, sizeof(buffer)) <= 0) { + count++; + continue; + } + if (strstr(buffer, std::to_string(app->pid).c_str()) != NULL) { + isFind = true; + break; + } + count++; + } + close(pipefd[0]); + close(pipefd[1]); + ASSERT_EQ(isFind, true); + NativeSpawnListenCloseSet(); + } while (0); +} + /** * @brief 必须最后一个,kill nwebspawn,appspawn的线程结束 * -- Gitee From 33f2867cacbc10780c2225d8cd5bff8d14eb3cc5 Mon Sep 17 00:00:00 2001 From: wanglei Date: Wed, 7 May 2025 08:30:05 +0000 Subject: [PATCH 2/4] fix codecheck Signed-off-by: wanglei --- standard/appspawn_service.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 010bc646..ee3ce524 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1532,14 +1532,10 @@ static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNod #else static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { - AppSpawnMsg* msg = &message->msgHeader; - APPSPAWN_LOGI("Recv ProcessSpawnRemountMsg message header magic: 0x%{public}x type: %{public}u" + AppSpawnMsg* msg = &message->msgHeader; + APPSPAWN_LOGI("Recv ProcessSpawnRemountMsg 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); + msg->magic, msg->msgType, msg->msgId, msg->msgLen, msg->processName); char srcPath[PATH_SIZE] = {0}; int len = GetArkWebInstallPath("persist.arkwebcore.install_path", srcPath); APPSPAWN_CHECK(len > 0, return -1, "Failed to get arkwebcore install path"); -- Gitee From 6e9984165b80b301bee1af2c16fd4ce6addf1059 Mon Sep 17 00:00:00 2001 From: wanglei Date: Mon, 12 May 2025 01:52:35 +0000 Subject: [PATCH 3/4] fix review comments Signed-off-by: wanglei --- modules/ace_adapter/BUILD.gn | 2 +- modules/ace_adapter/ace_adapter.cpp | 6 +++--- standard/appspawn_service.c | 15 ++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/ace_adapter/BUILD.gn b/modules/ace_adapter/BUILD.gn index d5c1fb76..747f3609 100644 --- a/modules/ace_adapter/BUILD.gn +++ b/modules/ace_adapter/BUILD.gn @@ -31,7 +31,7 @@ ohos_shared_library("appspawn_ace") { ] defines = [] if (target_cpu == "arm64") { - defines += [ "webview_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 a86487dc..83ee7045 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -312,7 +312,7 @@ APPSPAWN_STATIC int DoDlopenLibs(const cJSON *root, ParseJsonContext *context) APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) { -#if defined(webview_arm64) +#if defined(PRE_DLOPEN_ARKWEB_LIB) Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, @@ -320,7 +320,7 @@ APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) "/data/storage/el1/bundle/arkwebcore/libs/arm64"); void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_GLOBAL); if (!webEngineHandle) { - APPSPAWN_LOGI("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); + APPSPAWN_LOGE("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); } else { APPSPAWN_LOGI("SUCCESS to dlopen libarkweb_engine.so in appspawn"); } @@ -329,7 +329,7 @@ APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) const std::string libName = "/system/lib64/libohos_adapter_glue_source.z.so"; void *handle = dlopen(libName.c_str(), RTLD_NOW | RTLD_GLOBAL); if (handle == nullptr) { - APPSPAWN_LOGI("FAILED to dlopen libohos_adapter_glue_source.so in appspawn %{public}s", dlerror()); + APPSPAWN_LOGE("FAILED to dlopen libohos_adapter_glue_source.so in appspawn %{public}s", dlerror()); } else { APPSPAWN_LOGI("SUCCESS to dlopen libohos_adapter_glue_source.so in appspawn"); } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index ee3ce524..0ef58df6 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1532,10 +1532,6 @@ static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNod #else static int ProcessSpawnRemountMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { - AppSpawnMsg* msg = &message->msgHeader; - APPSPAWN_LOGI("Recv ProcessSpawnRemountMsg 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); char srcPath[PATH_SIZE] = {0}; int len = GetArkWebInstallPath("persist.arkwebcore.install_path", srcPath); APPSPAWN_CHECK(len > 0, return -1, "Failed to get arkwebcore install path"); @@ -1616,7 +1612,7 @@ static int ProcessSpawnDlcloseMsg(AppSpawnConnection *connection, AppSpawnMsgNod return 0; } - void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_GLOBAL); + void* webEngineHandle = dlopen_ns(&dlns, "libarkweb_engine.so", RTLD_NOW | RTLD_NOLOAD); if (!webEngineHandle) { APPSPAWN_LOGI("FAILED to dlopen libarkweb_engine.so in appspawn %{public}s", dlerror()); return 0; @@ -1626,12 +1622,13 @@ static int ProcessSpawnDlcloseMsg(AppSpawnConnection *connection, AppSpawnMsgNod do { cnt--; dlclose(webEngineHandle); - - if (cnt == 0 && IsNWebLibLoaded(dlns)) { - APPSPAWN_LOGE("ProcessSpawnReqMsg dlclose retry 10 times, return"); - } } while (cnt > 0 && IsNWebLibLoaded(dlns)); + if (cnt == 0 && IsNWebLibLoaded(dlns)) { + APPSPAWN_LOGE("MAX_DLCLOSE_COUNT"); + return -1; + } + return 0; } -- Gitee From 0a4d42fcddc272371a94f93af42f7dae0fc374ec Mon Sep 17 00:00:00 2001 From: wanglei Date: Sat, 17 May 2025 06:21:53 +0000 Subject: [PATCH 4/4] Do not pre dlopen glue so in appspawn any more Signed-off-by: wanglei --- modules/ace_adapter/ace_adapter.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 83ee7045..a0ea2202 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -325,15 +325,6 @@ APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) APPSPAWN_LOGI("SUCCESS to dlopen libarkweb_engine.so in appspawn"); } - // preload dlopen libohos_adapter_glue_source.z.so - const std::string libName = "/system/lib64/libohos_adapter_glue_source.z.so"; - void *handle = dlopen(libName.c_str(), RTLD_NOW | RTLD_GLOBAL); - if (handle == nullptr) { - APPSPAWN_LOGE("FAILED to dlopen libohos_adapter_glue_source.so in appspawn %{public}s", dlerror()); - } else { - APPSPAWN_LOGI("SUCCESS to dlopen libohos_adapter_glue_source.so in appspawn"); - } - OHOS::Ace::AceForwardCompatibility::ReclaimFileCache(getpid()); #endif -- Gitee