• 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 #ifndef PROC_NODE_H
13 #define PROC_NODE_H
14 
15 #ifdef CHCORE_OH_TEE
16 #include <spawn_ext.h>
17 #endif /* CHCORE_OH_TEE */
18 #include <pthread.h>
19 #include <chcore/container/list.h>
20 #include <chcore/ipc.h>
21 #include <chcore-internal/procmgr_defs.h>
22 
23 #define INIT_BADGE 1
24 
25 extern pthread_mutex_t recycle_lock;
26 
27 enum proc_state {
28     PROC_STATE_INIT = 1,
29     PROC_STATE_RUNNING,
30     PROC_STATE_EXIT,
31     PROC_STATE_MAX
32 };
33 
34 enum PROC_TYPE {
35     SYSTEM_SERVER = 1,
36     SYSTEM_DRIVER,
37     COMMON_APP,
38 };
39 
40 struct proc_node {
41     char *name; /* The name of the process. */
42     /* The capability of the process owned in procmgr. */
43     cap_t proc_cap;
44     /* The capability of the process's main thread (MT) owned in procmgr. */
45     cap_t proc_mt_cap;
46     pid_t pid;
47     u64 pcid; /* Used for initializing pgtbl */
48     badge_t badge; /* Used for recognizing a process. */
49     enum proc_state state;
50     pthread_mutex_t wait_lock;
51     pthread_cond_t wait_cv;
52     int exitstatus;
53 
54     /* Connecters */
55     struct proc_node *parent;
56     /* A lock: used to coordinate the access to child procs list */
57     pthread_mutex_t lock;
58     struct list_head children; /* A list of child procs. */
59     struct list_head node; /* The node in the parent's child list. */
60 
61     struct hlist_node hash_node; /* node in badge2proc hash table */
62 
63     size_t stack_size;
64 #ifdef CHCORE_OH_TEE
65     spawn_uuid_t puuid;
66     struct hlist_node pid_hash_node; /* node in pid2proc hash table */
67 #endif /* CHCORE_OH_TEE */
68 };
69 
70 void init_proc_node_mgr(void);
71 struct proc_node *new_proc_node(struct proc_node *parent, char *name,
72                                 int proc_type);
73 void del_proc_node(struct proc_node *proc);
74 void free_proc_node_resource(struct proc_node *proc);
75 struct proc_node *get_proc_node(badge_t client_badge);
76 #ifdef CHCORE_OH_TEE
77 struct proc_node *get_proc_node_by_pid(int pid);
78 #endif /* CHCORE_OH_TEE */
79 void init_root_proc_node(void);
80 
81 #endif /* PROC_NODE_H */