• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef APPSPAWN_SERVER_H
17 #define APPSPAWN_SERVER_H
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdbool.h>
21 #include <unistd.h>
22 
23 #include "appspawn_utils.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef enum {
29     MODE_FOR_APP_SPAWN,
30     MODE_FOR_NWEB_SPAWN,
31     MODE_FOR_APP_COLD_RUN,
32     MODE_FOR_NWEB_COLD_RUN,
33     MODE_FOR_NATIVE_SPAWN,
34     MODE_FOR_CJAPP_SPAWN,
35     MODE_INVALID
36 } RunMode;
37 
38 typedef enum {
39     PROCESS_FOR_APP_SPAWN,
40     PROCESS_FOR_NWEB_SPAWN,
41     PROCESS_FOR_APP_COLD_RUN,
42     PROCESS_FOR_NWEB_COLD_RUN,
43     PROCESS_FOR_NATIVE_SPAWN,
44     PROCESS_FOR_NWEB_RESTART,
45     PROCESS_INVALID
46 } RunProcess;
47 
48 typedef enum {
49     CJPROCESS_FOR_APP_SPAWN,
50     CJPROCESS_FOR_APP_COLD_RUN,
51     CJPROCESS_INVALID
52 } CJRunProcess;
53 
54 typedef struct AppSpawnClient {
55     uint32_t id;
56     uint32_t flags;  // Save negotiated flags
57 } AppSpawnClient;
58 
59 typedef struct AppSpawnPreforkMsg {
60     uint32_t id;
61     uint32_t flags;  // Save negotiated flags
62     uint32_t msgLen;
63 } AppSpawnPreforkMsg;
64 
65 typedef struct AppSpawnContent {
66     char *longProcName;
67     uint32_t longProcNameLen;
68     uint32_t sandboxNsFlags;
69     int wdgOpened;
70     bool isLinux;
71     int sandboxType;
72     RunMode mode;
73     int signalFd;
74 #ifndef OHOS_LITE
75     int32_t preforkFd[2];
76     int32_t parentToChildFd[2];
77     char *propertyBuffer;
78     pid_t reservedPid;
79     int enablePerfork;
80 #endif
81     // system
82     void (*runAppSpawn)(struct AppSpawnContent *content, int argc, char *const argv[]);
83     void (*notifyResToParent)(struct AppSpawnContent *content, AppSpawnClient *client, int result);
84     int (*runChildProcessor)(struct AppSpawnContent *content, AppSpawnClient *client);
85     // for cold start
86     int (*coldStartApp)(struct AppSpawnContent *content, AppSpawnClient *client);
87 } AppSpawnContent;
88 
89 typedef struct TagAppSpawnForkArg {
90     struct AppSpawnContent *content;
91     AppSpawnClient *client;
92 } AppSpawnForkArg;
93 
94 AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcName, uint32_t longProcNameLen, int cold);
95 int AppSpawnExecuteClearEnvHook(AppSpawnContent *content, AppSpawnClient *client);
96 int AppSpawnExecuteSpawningHook(AppSpawnContent *content, AppSpawnClient *client);
97 int AppSpawnExecutePreReplyHook(AppSpawnContent *content, AppSpawnClient *client);
98 int AppSpawnExecutePostReplyHook(AppSpawnContent *content, AppSpawnClient *client);
99 void AppSpawnEnvClear(AppSpawnContent *content, AppSpawnClient *client);
100 int AppSpawnProcessMsg(AppSpawnContent *content, AppSpawnClient *client, pid_t *childPid);
101 void ProcessExit(int code);
102 int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client);
103 #ifdef __cplusplus
104 }
105 #endif
106 #endif  // APPSPAWN_SERVER_H
107