Lines Matching defs:property
511 APPSPAWN_STATIC int WriteMsgToChild(AppSpawningCtx *property, bool isNweb)
513 APPSPAWN_CHECK(property != NULL && property->message != NULL, return APPSPAWN_MSG_INVALID,
514 "Failed to WriteMsgToChild property invalid");
515 const uint32_t memSize = (property->message->msgHeader.msgLen / 4096 + 1) * 4096; // 4096 4K
516 char *buffer = GetMapMem(property->client.id, GetProcessName(property), memSize, false, isNweb);
518 "Failed to map memory error %{public}d fileName %{public}s ", errno, GetProcessName(property));
520 int ret = memcpy_s(buffer, memSize, &property->message->msgHeader, sizeof(AppSpawnMsg));
523 property->message->buffer, property->message->msgHeader.msgLen - sizeof(AppSpawnMsg));
526 APPSPAWN_LOGE("Failed to copy msg fileName %{public}s ", GetProcessName(property));
530 property->forkCtx.msgSize = memSize;
531 property->forkCtx.childMsg = buffer;
532 APPSPAWN_LOGV("Write msg to child: %{public}u success", property->client.id);
536 static int InitForkContext(AppSpawningCtx *property)
538 if (pipe(property->forkCtx.fd) == -1) {
542 int option = fcntl(property->forkCtx.fd[0], F_GETFD);
544 (void)fcntl(property->forkCtx.fd[0], F_SETFD, (unsigned int)option | O_NONBLOCK);
580 static void WatchChildProcessFd(AppSpawningCtx *property)
582 if (property->pid <= 0) {
590 AppSpawnedProcess *appInfo = GetSpawnedProcess(property->pid);
592 APPSPAWN_LOGW("Cannot get app info of pid %{public}d", property->pid);
595 int fd = OpenPidFd(property->pid, PIDFD_NONBLOCK); // PIDFD_NONBLOCK since Linux kernel 5.10
598 GetBundleName(property), errno);
601 APPSPAWN_LOGI("watch app process pid %{public}d, pidFd %{public}d", property->pid, fd);
611 *appPid = property->pid;
612 LE_STATUS status = LE_StartWatcher(LE_GetDefaultLoop(), &property->forkCtx.pidFdWatcherHandle, &watchInfo, appPid);
617 APPSPAWN_LOGW("Failed to watch child pid fd, pid is %{public}d", property->pid);
621 static int IsChildColdRun(AppSpawningCtx *property)
623 return CheckAppMsgFlagsSet(property, APP_FLAGS_UBSAN_ENABLED)
624 || CheckAppMsgFlagsSet(property, APP_FLAGS_ASANENABLED)
625 || CheckAppMsgFlagsSet(property, APP_FLAGS_TSAN_ENABLED)
626 || CheckAppMsgFlagsSet(property, APP_FLAGS_HWASAN_ENABLED)
627 || (property->client.flags & APP_COLD_START);
630 static int AddChildWatcher(AppSpawningCtx *property)
632 uint32_t defTimeout = IsChildColdRun(property) ? COLD_CHILD_RESPONSE_TIMEOUT : WAIT_CHILD_RESPONSE_TIMEOUT;
635 watchInfo.fd = property->forkCtx.fd[0];
639 LE_STATUS status = LE_StartWatcher(LE_GetDefaultLoop(), &property->forkCtx.watcherHandle, &watchInfo, property);
641 return APPSPAWN_SYSTEM_ERROR, "Failed to watch child %{public}d", property->pid);
642 status = LE_CreateTimer(LE_GetDefaultLoop(), &property->forkCtx.timer, WaitChildTimeout, property);
644 status = LE_StartTimer(LE_GetDefaultLoop(), property->forkCtx.timer, timeout * 1000, 0); // 1000 1s
647 if (property->forkCtx.timer != NULL) {
648 LE_StopTimer(LE_GetDefaultLoop(), property->forkCtx.timer);
650 property->forkCtx.timer = NULL;
651 LE_RemoveWatcher(LE_GetDefaultLoop(), property->forkCtx.watcherHandle);
652 property->forkCtx.watcherHandle = NULL;
653 APPSPAWN_LOGE("Failed to watch child %{public}d", property->pid);
675 static int WritePreforkMsg(AppSpawningCtx *property)
683 int ret = memcpy_s(content->propertyBuffer, MAX_MEM_SIZE, &property->message->msgHeader, sizeof(AppSpawnMsg));
686 property->message->buffer, property->message->msgHeader.msgLen - sizeof(AppSpawnMsg));
696 static int GetAppSpawnMsg(AppSpawningCtx *property)
698 uint8_t *buffer = (uint8_t *)GetMapMem(property->client.id, "prefork", MAX_MEM_SIZE, true, false);
705 property->forkCtx.childMsg = (char *)buffer;
706 property->forkCtx.msgSize = MAX_MEM_SIZE;
712 property->message = message;
760 static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property)
774 (void)close(property->forkCtx.fd[0]);
775 (void)close(property->forkCtx.fd[1]);
785 property->client.id = client.id;
786 property->client.flags = client.flags;
787 property->isPrefork = true;
788 property->forkCtx.fd[0] = content->preforkFd[0];
789 property->forkCtx.fd[1] = content->preforkFd[1];
790 property->state = APP_STATE_SPAWNING;
791 if (GetAppSpawnMsg(property) == -1) {
793 ClearMMAP(property->client.id);
794 content->notifyResToParent(content, &property->client, APPSPAWN_MSG_INVALID);
798 ClearMMAP(property->client.id);
799 ProcessExit(AppSpawnChild(content, &property->client));
808 AppSpawningCtx *property = (AppSpawningCtx *)client;
817 content->propertyBuffer = GetMapMem(property->client.id, "prefork", MAX_MEM_SIZE, false, false);
819 ret = WritePreforkMsg(property);
823 property->forkCtx.fd[0] = content->preforkFd[0];
824 property->forkCtx.fd[1] = content->preforkFd[1];
826 int option = fcntl(property->forkCtx.fd[0], F_GETFD);
828 ret = fcntl(property->forkCtx.fd[0], F_SETFD, (unsigned int)option | O_NONBLOCK);
838 ProcessPreFork(content, property);
851 AppSpawningCtx *property = (AppSpawningCtx *)client;
853 if (content->mode == MODE_FOR_APP_SPAWN && !IsChildColdRun(property)
854 && !CheckAppMsgFlagsSet(property, APP_FLAGS_CHILDPROCESS)) {
901 AppSpawningCtx *property = CreateAppSpawningCtx();
902 if (property == NULL) {
908 property->state = APP_STATE_SPAWNING;
909 property->message = message;
913 AppSpawnHookExecute(STAGE_PARENT_PRE_FORK, 0, GetAppSpawnContent(), &property->client);
914 DumpAppSpawnMsg(property->message);
916 clock_gettime(CLOCK_MONOTONIC, &property->spawnStart);
917 ret = RunAppSpawnProcessMsg(GetAppSpawnContent(), &property->client, &property->pid);
918 AppSpawnHookExecute(STAGE_PARENT_POST_FORK, 0, GetAppSpawnContent(), &property->client);
921 DeleteAppSpawningCtx(property);
924 if (AddChildWatcher(property) != 0) { // wait child process result
925 kill(property->pid, SIGKILL);
927 DeleteAppSpawningCtx(property);
937 AppSpawningCtx *property = GetAppSpawningCtxByPid(pid);
938 if (property != NULL && property->state == APP_STATE_SPAWNING) {
940 GetProcessName(property), property->pid, property->client.id);
941 if (property->client.id == g_lastDiedAppId + 1) {
946 g_lastDiedAppId = property->client.id;
948 SendResponse(property->message->connection, &property->message->msgHeader, APPSPAWN_CHILD_CRASH, 0);
949 DeleteAppSpawningCtx(property);
960 AppSpawningCtx *property = (AppSpawningCtx *)context;
962 GetProcessName(property), property->pid, property->client.id);
963 if (property->pid > 0) {
965 DumpSpawnStack(property->pid);
967 kill(property->pid, SIGKILL);
969 SendResponse(property->message->connection, &property->message->msgHeader, APPSPAWN_SPAWN_TIMEOUT, 0);
970 DeleteAppSpawningCtx(property);
973 static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult)
978 GetProcessName(property), property->pid, property->client.id, result);
979 APPSPAWN_CHECK(property->message != NULL, return -1, "Invalid message in ctx %{public}d", property->client.id);
982 SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid);
983 DeleteAppSpawningCtx(property);
995 AppSpawningCtx *property = (AppSpawningCtx *)context;
996 property->forkCtx.watcherHandle = NULL; // delete watcher
1000 if (ProcessChildFdCheck(fd, property, &result) != 0) {
1005 bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE) == 1 ? true : false;
1006 AppSpawnedProcess *appInfo = AddSpawnedProcess(property->pid, GetBundleName(property), isDebuggable);
1009 pidMaxStr = GetAppPropertyExt(property, MSG_EXT_NAME_MAX_CHILD_PROCCESS_MAX, &len);
1018 AppSpawnMsgDacInfo *dacInfo = GetAppProperty(property, TLV_DAC_INFO);
1021 appInfo->spawnStart.tv_sec = property->spawnStart.tv_sec;
1022 appInfo->spawnStart.tv_nsec = property->spawnStart.tv_nsec;
1025 appInfo->message = property->message;
1031 WatchChildProcessFd(property);
1034 AppSpawnHookExecute(STAGE_PARENT_PRE_RELY, 0, GetAppSpawnContent(), &property->client);
1035 SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid);
1036 AppSpawnHookExecute(STAGE_PARENT_POST_RELY, 0, GetAppSpawnContent(), &property->client);
1039 property->message = NULL;
1042 DeleteAppSpawningCtx(property);
1047 AppSpawningCtx *property = (AppSpawningCtx *)client;
1048 int fd = property->forkCtx.fd[1];
1052 property->forkCtx.fd[1] = -1;
1111 AppSpawningCtx *property = (AppSpawningCtx *)client;
1113 char *path = property->forkCtx.coldRunPath != NULL ? property->forkCtx.coldRunPath : "/system/bin/cjappspawn";
1115 char *path = property->forkCtx.coldRunPath != NULL ? property->forkCtx.coldRunPath : "/system/bin/nativespawn";
1117 char *path = property->forkCtx.coldRunPath != NULL ? property->forkCtx.coldRunPath : "/system/bin/appspawn";
1119 APPSPAWN_LOGI("ColdStartApp::processName: %{public}s path: %{public}s", GetProcessName(property), path);
1122 APPSPAWN_LOGV("Write msg to child %{public}s", GetProcessName(property));
1123 int ret = WriteMsgToChild(property, IsNWebSpawnMode((AppSpawnMgr *)content));
1127 int len = sprintf_s(buffer[0], sizeof(buffer[0]), " %d ", property->forkCtx.fd[1]);
1129 len = sprintf_s(buffer[1], sizeof(buffer[1]), " %u ", property->client.flags);
1131 len = sprintf_s(buffer[2], sizeof(buffer[2]), " %u ", property->forkCtx.msgSize); // 2 2 index for dest path
1133 len = sprintf_s(buffer[3], sizeof(buffer[3]), " %u ", property->client.id); // 3 3 index for client id
1141 "-param", GetProcessName(property), buffer[3], NULL
1149 APPSPAWN_LOGV("ColdStartApp::processName: %{public}s end", GetProcessName(property));
1155 AppSpawningCtx *property = CreateAppSpawningCtx();
1156 APPSPAWN_CHECK(property != NULL, return NULL, "Create app spawning ctx fail");
1157 property->forkCtx.fd[1] = atoi(argv[FD_VALUE_INDEX]);
1158 property->client.flags = (uint32_t)atoi(argv[FLAGS_VALUE_INDEX]);
1159 property->client.flags &= ~APP_COLD_START;
1163 property->client.id = (uint32_t)atoi(argv[CLIENT_ID_INDEX]);
1164 uint8_t *buffer = (uint8_t *)GetMapMem(property->client.id,
1167 APPSPAWN_LOGE("Failed to map errno %{public}d %{public}s", property->client.id, argv[PARAM_VALUE_INDEX]);
1168 NotifyResToParent(&content->content, &property->client, APPSPAWN_SYSTEM_ERROR);
1169 DeleteAppSpawningCtx(property);
1182 isNweb ? "nwebspawn" : "appspawn", argv[PARAM_VALUE_INDEX], property->client.id);
1188 property->message = message;
1190 return property;
1192 NotifyResToParent(&content->content, &property->client, APPSPAWN_MSG_INVALID);
1194 DeleteAppSpawningCtx(property);
1204 AppSpawningCtx *property = GetAppSpawningCtxFromArg(appSpawnContent, argc, argv);
1205 if (property == NULL) {
1206 APPSPAWN_LOGE("Failed to get property from arg");
1209 DumpAppSpawnMsg(property->message);
1211 int ret = AppSpawnExecuteSpawningHook(content, &property->client);
1213 ret = AppSpawnExecutePreReplyHook(content, &property->client);
1215 NotifyResToParent(content, &property->client, ret);
1217 (void)AppSpawnExecutePostReplyHook(content, &property->client);
1221 ret = content->runChildProcessor(content, &property->client);
1224 NotifyResToParent(content, &property->client, ret);
1228 AppSpawnEnvClear(content, &property->client);
1255 APPSPAWN_STATIC int AppSpawnClearEnv(AppSpawnMgr *content, AppSpawningCtx *property)
1258 DeleteAppSpawningCtx(property);