• 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_FOR_HYBRID_SPAWN,
36     MODE_INVALID
37 } RunMode;
38 
39 typedef enum {
40     PROCESS_FOR_APP_SPAWN,
41     PROCESS_FOR_NWEB_SPAWN,
42     PROCESS_FOR_APP_COLD_RUN,
43     PROCESS_FOR_NWEB_COLD_RUN,
44     PROCESS_FOR_NATIVE_SPAWN,
45     PROCESS_FOR_NWEB_RESTART,
46     PROCESS_FOR_HYBRID_SPAWN,
47     PROCESS_INVALID
48 } RunProcess;
49 
50 typedef enum {
51     CJPROCESS_FOR_APP_SPAWN,
52     CJPROCESS_FOR_APP_COLD_RUN,
53     CJPROCESS_INVALID
54 } CJRunProcess;
55 
56 typedef struct AppSpawnClient {
57     uint32_t id;
58     uint32_t flags;  // Save negotiated flags
59 } AppSpawnClient;
60 
61 typedef struct AppSpawnPreforkMsg {
62     uint32_t id;
63     uint32_t flags;  // Save negotiated flags
64     uint32_t msgLen;
65 } AppSpawnPreforkMsg;
66 
67 typedef struct AppSpawnContent {
68     char *longProcName;
69     uint32_t longProcNameLen;
70     uint32_t sandboxNsFlags;
71     int wdgOpened;
72     bool isLinux;
73     int sandboxType;
74     RunMode mode;
75     int signalFd;
76 #ifndef OHOS_LITE
77     int32_t preforkFd[2];
78     int32_t parentToChildFd[2];
79     char *propertyBuffer;
80     pid_t reservedPid;
81     int enablePerfork;
82 #endif
83     // system
84     void (*runAppSpawn)(struct AppSpawnContent *content, int argc, char *const argv[]);
85     void (*notifyResToParent)(struct AppSpawnContent *content, AppSpawnClient *client, int result);
86     int (*runChildProcessor)(struct AppSpawnContent *content, AppSpawnClient *client);
87     // for cold start
88     int (*coldStartApp)(struct AppSpawnContent *content, AppSpawnClient *client);
89 } AppSpawnContent;
90 
91 typedef struct TagAppSpawnForkArg {
92     struct AppSpawnContent *content;
93     AppSpawnClient *client;
94 } AppSpawnForkArg;
95 
96 AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcName, uint32_t longProcNameLen, int cold);
97 int AppSpawnExecuteClearEnvHook(AppSpawnContent *content, AppSpawnClient *client);
98 int AppSpawnExecuteSpawningHook(AppSpawnContent *content, AppSpawnClient *client);
99 int AppSpawnExecutePreReplyHook(AppSpawnContent *content, AppSpawnClient *client);
100 int AppSpawnExecutePostReplyHook(AppSpawnContent *content, AppSpawnClient *client);
101 void AppSpawnEnvClear(AppSpawnContent *content, AppSpawnClient *client);
102 int AppSpawnProcessMsg(AppSpawnContent *content, AppSpawnClient *client, pid_t *childPid);
103 void ProcessExit(int code);
104 int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client);
105 #ifdef __cplusplus
106 }
107 #endif
108 #endif  // APPSPAWN_SERVER_H
109