• 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 OBJECT_OBJECT_H
13 #define OBJECT_OBJECT_H
14 
15 #include <common/types.h>
16 #include <common/errno.h>
17 #include <common/lock.h>
18 #include <common/list.h>
19 
20 struct object {
21     u64 type;
22     u64 size;
23     /* Link all slots point to this object */
24     struct list_head copies_head;
25     /* Currently only protect copies list */
26     struct lock copies_lock;
27     /*
28      * refcount is added when a slot points to it and when get_object is
29      * called. Object is freed when it reaches 0.
30      */
31     unsigned long refcount;
32 
33     /*
34      * opaque marks the end of this struct and the real object will be
35      * stored here. Now its address will be 8-byte aligned.
36      */
37     u64 opaque[];
38 };
39 
40 enum object_type {
41     TYPE_CAP_GROUP = 0,
42     TYPE_THREAD,
43     TYPE_CONNECTION,
44     TYPE_NOTIFICATION,
45     TYPE_IRQ,
46     TYPE_PMO,
47     TYPE_VMSPACE,
48 #ifdef CHCORE_OH_TEE
49     TYPE_CHANNEL,
50     TYPE_MSG_HDL,
51 #endif /* CHCORE_OH_TEE */
52     TYPE_NR,
53 };
54 
55 struct cap_group;
56 
57 typedef void (*obj_deinit_func)(void *);
58 extern const obj_deinit_func obj_deinit_tbl[TYPE_NR];
59 
60 void *obj_get(struct cap_group *cap_group, cap_t slot_id, int type);
61 void obj_put(void *obj);
62 void obj_ref(void *obj);
63 
64 void *obj_alloc(u64 type, u64 size);
65 void obj_free(void *obj);
66 void free_object_internal(struct object *object);
67 cap_t cap_alloc(struct cap_group *cap_group, void *obj);
68 int cap_free(struct cap_group *cap_group, cap_t slot_id);
69 cap_t cap_copy(struct cap_group *src_cap_group,
70                struct cap_group *dest_cap_group, cap_t src_slot_id);
71 
72 int cap_free_all(struct cap_group *cap_group, cap_t slot_id);
73 
74 /* Syscalls */
75 int sys_revoke_cap(cap_t obj_cap, bool revoke_copy);
76 int sys_transfer_caps(cap_t dest_group_cap, unsigned long src_caps_buf,
77                       int nr_caps, unsigned long dst_caps_buf);
78 
79 #endif /* OBJECT_OBJECT_H */
80