fx bug for asan

Signed-off-by: zhongning5 <zhongning5@huawei.com>
This commit is contained in:
zhongning5 2024-04-18 21:51:49 +08:00
parent 686fe467c3
commit ea342b99a6
5 changed files with 29 additions and 10 deletions

View File

@ -29,6 +29,11 @@ extern "C" {
#endif
#define HOOK_STOP_WHEN_ERROR 0x2
#if defined(__aarch64__) || defined(__x86_64__)
#define ASAN_MODULE_PATH "/system/lib64/appspawn/libappspawn_asan"
#else
#define ASAN_MODULE_PATH "/system/lib/appspawn/libappspawn_asan"
#endif
typedef enum {
MODULE_DEFAULT,

View File

@ -374,16 +374,12 @@ static int InitForkContext(AppSpawningCtx *property)
if (option > 0) {
(void)fcntl(property->forkCtx.fd[0], F_SETFD, option | O_NONBLOCK);
}
if (property->client.flags & APP_COLD_START) { // for cold run, use shared memory to exchange message
APPSPAWN_LOGV("Write msg to child %{public}s", GetProcessName(property));
return WriteMsgToChild(property);
}
return 0;
}
static int AddChildWatcher(AppSpawningCtx *property)
{
uint32_t timeout = WAIT_CHILD_RESPONSE_TIMEOUT;
LE_WatchInfo watchInfo = {};
watchInfo.fd = property->forkCtx.fd[0];
watchInfo.flags = WATCHER_ONCE;
@ -394,7 +390,7 @@ static int AddChildWatcher(AppSpawningCtx *property)
return APPSPAWN_SYSTEM_ERROR, "Failed to watch child %{public}d", property->pid);
status = LE_CreateTimer(LE_GetDefaultLoop(), &property->forkCtx.timer, WaitChildTimeout, property);
if (status == LE_SUCCESS) {
status = LE_StartTimer(LE_GetDefaultLoop(), property->forkCtx.timer, WAIT_CHILD_RESPONSE_TIMEOUT, 0);
status = LE_StartTimer(LE_GetDefaultLoop(), property->forkCtx.timer, timeout * 1000, 0); // 1000 1s
}
if (status != LE_SUCCESS) {
if (property->forkCtx.timer != NULL) {
@ -576,6 +572,11 @@ static int AppSpawnColdStartApp(struct AppSpawnContent *content, AppSpawnClient
char *path = property->forkCtx.coldRunPath != NULL ? property->forkCtx.coldRunPath : "/system/bin/appspawn";
APPSPAWN_LOGI("ColdStartApp::processName: %{public}s path: %{public}s", GetProcessName(property), path);
// for cold run, use shared memory to exchange message
APPSPAWN_LOGV("Write msg to child %{public}s", GetProcessName(property));
int ret = WriteMsgToChild(property);
APPSPAWN_CHECK(ret == 0, return APPSPAWN_SYSTEM_ERROR, "Failed to write msg to child");
char buffer[4][32] = {0}; // 4 32 buffer for fd
char *mode = IsNWebSpawnMode((AppSpawnMgr *)content) ? "nweb_cold" : "app_cold";
int len = sprintf_s(buffer[0], sizeof(buffer[0]), " %d ", property->forkCtx.fd[1]);
@ -593,7 +594,7 @@ static int AppSpawnColdStartApp(struct AppSpawnContent *content, AppSpawnClient
"-param", GetProcessName(property), buffer[3], NULL
};
int ret = execv(path, (char **)formatCmds);
ret = execv(path, (char **)formatCmds);
if (ret != 0) {
APPSPAWN_LOGE("Failed to execv, errno: %{public}d", errno);
}
@ -762,7 +763,7 @@ AppSpawnContent *StartSpawnService(const AppSpawnStartArg *startArg, uint32_t ar
// load module appspawn/common
AppSpawnLoadAutoRunModules(MODULE_COMMON);
AppSpawnModuleMgrInstall("libappspawn_asan");
AppSpawnModuleMgrInstall(ASAN_MODULE_PATH);
APPSPAWN_CHECK(LE_GetDefaultLoop() != NULL, return NULL, "Invalid default loop");
AppSpawnContent *content = AppSpawnCreateContent(arg->socketName, argv[0], argvSize, arg->mode);

View File

@ -33,7 +33,7 @@ extern "C" {
#endif
#define MAX_WAIT_MSG_COMPLETE (5 * 1000) // 5s
#define WAIT_CHILD_RESPONSE_TIMEOUT 3000 //3s
#define WAIT_CHILD_RESPONSE_TIMEOUT 3 //3s
typedef struct TagAppSpawnMsgNode AppSpawnMsgNode;
typedef struct TagAppSpawnMsgReceiverCtx {

View File

@ -105,7 +105,7 @@ void SetDumpToStream(FILE *stream);
typedef int (*SplitStringHandle)(const char *str, void *context);
int32_t StringSplit(const char *str, const char *separator, void *context, SplitStringHandle handle);
char *GetLastStr(const char *str, const char *dst);
uint32_t GetSpawnTimeout(uint32_t def);
void DumpCurrentDir(char *buffer, uint32_t bufferLen, const char *dirPath);
#ifndef APP_FILE_NAME

View File

@ -308,3 +308,16 @@ void AppSpawnDump(const char *fmt, ...)
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif
uint32_t GetSpawnTimeout(uint32_t def)
{
uint32_t value = def;
char data[32] = {}; // 32 length
int ret = GetParameter("persist.appspawn.reqMgr.timeout", "0", data, sizeof(data));
if (ret > 0 && strcmp(data, "0") != 0) {
errno = 0;
value = atoi(data);
return (errno != 0) ? def : ((value < def) ? def : value);
}
return value;
}