• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 /**
13  * @file liblaunch.h
14  *
15  * @brief This library is used to launch a process in ChCore,
16  * whose memory image is given by an ELF file.
17  */
18 #ifndef LIBLAUNCH_H
19 #define LIBLAUNCH_H
20 
21 #include <chcore/type.h>
22 #include "libchcoreelf.h"
23 #ifdef CHCORE_OH_TEE
24 #include <spawn_ext.h>
25 #endif /* CHCORE_OH_TEE */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct cap_group_args {
32     badge_t badge;
33     vaddr_t name;
34     unsigned long name_len;
35     unsigned long pcid;
36 #ifdef CHCORE_OH_TEE
37     int pid;
38     vaddr_t puuid;
39     unsigned long heap_size;
40 #endif /* CHCORE_OH_TEE */
41 };
42 
43 struct launch_process_args {
44     /** input parameters */
45     /**
46      * user_elf struct of the new process.
47      * This struct represents the memory image of the new process,
48      * or to be executed program.
49      */
50     struct user_elf *user_elf;
51     /**
52      * It non-zero, then the user_elf would be mapped starting at
53      * load_offset instead of 0 in the new process's address space.
54      */
55     vaddr_t load_offset;
56     /**
57      * Custom PMOs (except for the PMOs in the user_elf) to be mapped
58      * into the new process's address space.
59      */
60     struct pmo_map_request *pmo_map_reqs;
61     int nr_pmo_map_reqs;
62     /**
63      * Custom capabilities to be transfered to the new process. We would
64      * transfer caps of 3 fundamental system server, i.e procmgr, fsm and lwip,
65      * to the new process by default.
66      */
67     cap_t *caps;
68     int nr_caps;
69     /**
70      * CPU affinity of the main thread of the new process.
71      */
72     s32 cpuid;
73     int argc;
74     /**
75      * NULL-termiated array of arguments to be passed to the new process. It should
76      * contain @argc valid parameters, otherwise the behavior is undefined.
77      */
78     char **argv;
79     /**
80      * Unique badge used to identify different processes by the ChCore kernel.
81      */
82     badge_t badge;
83     int pid;
84     /**
85      * Address space ID for the new process, it should be unique to reduce TLB
86      * flush when switching between two processes if possible.
87      */
88     u64 pcid;
89     /**
90      * Name of the new process, which would be stored in the kernel for debugging.
91      */
92     char *process_name;
93 
94     int envp_argc;
95     char **envp_argv;
96     unsigned long stack_size;
97 
98 #ifdef CHCORE_OH_TEE
99     spawn_uuid_t *puuid;
100     unsigned long heap_size;
101 #endif /* CHCORE_OH_TEE */
102 
103     /** output parameters */
104     cap_t *child_process_cap;
105     cap_t *child_main_thread_cap;
106 };
107 
108 /**
109  * @brief Launch a new process in ChCore. The new process would execute
110  * programs in the given ELF file.
111  *
112  * @param lp_args [In] see documentation of struct launch_process_args.
113  * @return 0 on success, otherwise an error code. All memory resources
114  * allocated by this function would be freed on error.
115  */
116 int launch_process_with_pmos_caps(struct launch_process_args *lp_args);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif /* LIBLAUCH_H */