From 50814f129b03f665b7fb9803172a91b96cda99d1 Mon Sep 17 00:00:00 2001 From: meteors117 Date: Mon, 17 Mar 2025 10:20:03 +0800 Subject: [PATCH] set param to enable memory_debug. Signed-off-by: meteors117 --- interfaces/innerkits/client/appspawn_msg.c | 3 ++- modules/asan/BUILD.gn | 5 ++++- modules/asan/asan_detector.c | 26 +++++++--------------- standard/appspawn_service.c | 11 ++++----- util/include/appspawn_utils.h | 2 ++ util/src/appspawn_utils.c | 16 +++++++++++++ 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_msg.c b/interfaces/innerkits/client/appspawn_msg.c index a14f0db0..ec6277e6 100644 --- a/interfaces/innerkits/client/appspawn_msg.c +++ b/interfaces/innerkits/client/appspawn_msg.c @@ -413,7 +413,8 @@ int AppSpawnReqMsgSetAppFlag(AppSpawnReqMsgHandle reqHandle, AppFlagsIndex flagI if (!reqNode->isAsan && (flagIndex == APP_FLAGS_UBSAN_ENABLED || flagIndex == APP_FLAGS_ASANENABLED || flagIndex == APP_FLAGS_TSAN_ENABLED || flagIndex == APP_FLAGS_HWASAN_ENABLED || - (flagIndex == APP_FLAGS_COLD_BOOT && CheckEnabled("startup.appspawn.cold.boot", "true")))) { + (flagIndex == APP_FLAGS_COLD_BOOT && CheckEnabled("startup.appspawn.cold.boot", "true")) || + (IsDeveloperModeOpen() && CheckSupportColdStart(reqNode->msg->processName) == 0))) { reqNode->isAsan = 1; } diff --git a/modules/asan/BUILD.gn b/modules/asan/BUILD.gn index 29cec579..f462c305 100644 --- a/modules/asan/BUILD.gn +++ b/modules/asan/BUILD.gn @@ -22,7 +22,10 @@ ohos_shared_library("appspawn_asan") { "${appspawn_path}/standard", ] defines = [] - deps = [ "${appspawn_path}/modules/module_engine:libappspawn_module_engine" ] + deps = [ + "${appspawn_path}/modules/module_engine:libappspawn_module_engine", + "${appspawn_path}/util:libappspawn_util", + ] if (is_asan) { defines += [ "APPSPAWN_ASAN" ] } diff --git a/modules/asan/asan_detector.c b/modules/asan/asan_detector.c index 901bc27a..bca5fa1e 100644 --- a/modules/asan/asan_detector.c +++ b/modules/asan/asan_detector.c @@ -80,6 +80,14 @@ static int SetAsanEnabledEnv(const AppSpawnMgr *content, const AppSpawningCtx *p return 0; } } + if (IsDeveloperModeOpen() && CheckSupportColdStart(GetBundleName(property)) == 0) { + setenv("LD_PRELOAD", HWASAN_LD_PRELOAD, 1); + setenv("HWASAN_OPTIONS", HWASAN_OPTIONS, 1); + unsetenv("ASAN_OPTIONS"); + unsetenv("TSAN_OPTIONS"); + unsetenv("UBSAN_OPTIONS"); + return 0; + } return -1; } #endif @@ -91,24 +99,6 @@ static void SetGwpAsanEnabled(const AppSpawnMgr *content, const AppSpawningCtx * may_init_gwp_asan(enforce); } -#ifdef ASAN_DETECTOR -#define WRAP_VALUE_MAX_LENGTH 96 -static int CheckSupportColdStart(const char *bundleName) -{ - char wrapBundleNameKey[WRAP_VALUE_MAX_LENGTH] = {0}; - char wrapBundleNameValue[WRAP_VALUE_MAX_LENGTH] = {0}; - - int len = sprintf_s(wrapBundleNameKey, WRAP_VALUE_MAX_LENGTH, "wrap.%s", bundleName); - APPSPAWN_CHECK(len > 0 && (len < WRAP_VALUE_MAX_LENGTH), return -1, "Invalid to format wrapBundleNameKey"); - - int ret = GetParameter(wrapBundleNameKey, "", wrapBundleNameValue, WRAP_VALUE_MAX_LENGTH); - APPSPAWN_CHECK(ret > 0 && (!strcmp(wrapBundleNameValue, "asan_wrapper")), return -1, - "Not wrap %{public}s.", bundleName); - APPSPAWN_LOGI("Asan: GetParameter %{public}s the value is %{public}s.", wrapBundleNameKey, wrapBundleNameValue); - return 0; -} -#endif - static int AsanSpawnGetSpawningFlag(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_LOGV("Prepare spawn app %{public}s", GetProcessName(property)); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index aae3dd26..3e03c415 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -649,11 +649,12 @@ static void WatchChildProcessFd(AppSpawningCtx *property) static int IsChildColdRun(AppSpawningCtx *property) { - return CheckAppMsgFlagsSet(property, APP_FLAGS_UBSAN_ENABLED) - || CheckAppMsgFlagsSet(property, APP_FLAGS_ASANENABLED) - || CheckAppMsgFlagsSet(property, APP_FLAGS_TSAN_ENABLED) - || CheckAppMsgFlagsSet(property, APP_FLAGS_HWASAN_ENABLED) - || (property->client.flags & APP_COLD_START); + return CheckAppMsgFlagsSet(property, APP_FLAGS_UBSAN_ENABLED) || + CheckAppMsgFlagsSet(property, APP_FLAGS_ASANENABLED) || + CheckAppMsgFlagsSet(property, APP_FLAGS_TSAN_ENABLED) || + CheckAppMsgFlagsSet(property, APP_FLAGS_HWASAN_ENABLED) || + (property->client.flags & APP_COLD_START) || + (IsDeveloperModeOpen() && CheckSupportColdStart(GetBundleName(property)) == 0); } static int AddChildWatcher(AppSpawningCtx *property) diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 6b585c58..6025319b 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -150,6 +150,8 @@ void InitCommonEnv(void); int ConvertEnvValue(const char *srcEnv, char *dstEnv, int len); int EnableNewNetNamespace(void); +// for param check +int CheckSupportColdStart(const char *bundleName); #ifndef APP_FILE_NAME #define APP_FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) diff --git a/util/src/appspawn_utils.c b/util/src/appspawn_utils.c index 774b11f8..55a1cddd 100644 --- a/util/src/appspawn_utils.c +++ b/util/src/appspawn_utils.c @@ -435,3 +435,19 @@ int EnableNewNetNamespace(void) close(fd); return (ret >= 0) ? 0 : APPSPAWN_SYSTEM_ERROR; } + +#define WRAP_VALUE_MAX_LENGTH 96 +int CheckSupportColdStart(const char *bundleName) +{ + char wrapBundleNameKey[WRAP_VALUE_MAX_LENGTH] = {0}; + char wrapBundleNameValue[WRAP_VALUE_MAX_LENGTH] = {0}; + + int len = sprintf_s(wrapBundleNameKey, WRAP_VALUE_MAX_LENGTH, "wrap.%s", bundleName); + APPSPAWN_CHECK(len > 0 && (len < WRAP_VALUE_MAX_LENGTH), return -1, "Invalid to format wrapBundleNameKey"); + + int ret = GetParameter(wrapBundleNameKey, "", wrapBundleNameValue, WRAP_VALUE_MAX_LENGTH); + APPSPAWN_CHECK(ret > 0 && (!strcmp(wrapBundleNameValue, "asan_wrapper")), return -1, + "Not wrap %{public}s.", bundleName); + APPSPAWN_LOGI("Asan: GetParameter %{public}s the value is %{public}s.", wrapBundleNameKey, wrapBundleNameValue); + return 0; +} -- Gitee