xref: /xnu-8792.61.2/bsd/sys/proc_ro.h (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1 /*
2  * Copyright (c) 2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifndef _SYS_PROC_RO_H_
30 #define _SYS_PROC_RO_H_
31 
32 #include <stdint.h>
33 #include <sys/_types/_pid_t.h>
34 #include <sys/cdefs.h>
35 
36 __BEGIN_DECLS __ASSUME_PTR_ABI_SINGLE_BEGIN
37 #pragma GCC visibility push(hidden)
38 
39 struct proc;
40 struct task;
41 struct ucred;
42 
43 struct proc_platform_ro_data {
44 	uint32_t p_platform;
45 	uint32_t p_min_sdk;
46 	uint32_t p_sdk;
47 };
48 
49 struct task_token_ro_data {
50 	security_token_t sec_token;
51 	audit_token_t audit_token;
52 };
53 
54 struct task_filter_ro_data {
55 	uint8_t *__unsafe_indexable mach_trap_filter_mask; /* Mach trap filter bitmask (len: mach_trap_count bits) */
56 	uint8_t *__unsafe_indexable mach_kobj_filter_mask; /* Mach kobject filter bitmask (len: mach_kobj_count bits) */
57 };
58 
59 struct proc_ro {
60 	struct proc *pr_proc;
61 	struct task *pr_task;
62 
63 	__xnu_struct_group(proc_ro_data, proc_data, {
64 		uint64_t p_uniqueid;                               /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */
65 		int p_idversion;                                   /* version of process identity */
66 		uint32_t p_csflags;
67 		struct ucred *p_ucred;                             /* Process owner's identity. (PUCL) */
68 		uint8_t *__unsafe_indexable syscall_filter_mask;   /* syscall filter bitmask (length: nsysent bits) */
69 		struct proc_platform_ro_data p_platform_data;
70 	});
71 
72 	__xnu_struct_group(task_ro_data, task_data, {
73 		/* Task security and audit tokens */
74 		struct task_token_ro_data task_tokens;
75 #ifdef CONFIG_MACF
76 		struct task_filter_ro_data task_filters;
77 #endif
78 		uint32_t t_flags_ro;                               /* RO-protected task flags (see osfmk/kern/task.h) */
79 		uint32_t task_control_port_options;
80 	});
81 };
82 
83 typedef const struct proc_ro_data *proc_ro_data_t;
84 typedef const struct task_ro_data *task_ro_data_t;
85 typedef struct proc_ro *proc_ro_t;
86 
87 extern proc_ro_t proc_ro_alloc(struct proc *p, proc_ro_data_t p_data, struct task *t, task_ro_data_t t_data);
88 extern void proc_ro_free(proc_ro_t pr);
89 extern proc_ro_t proc_ro_ref_task(proc_ro_t pr, struct task *t, task_ro_data_t t_data);
90 extern void proc_switch_ro(struct proc *p, proc_ro_t new_ro);
91 extern proc_ro_t proc_ro_release_proc(proc_ro_t pr);
92 extern proc_ro_t proc_ro_release_task(proc_ro_t pr);
93 
94 extern proc_ro_t proc_get_ro(struct proc *p) __pure2;
95 extern proc_ro_t current_proc_ro(void) __pure2;
96 extern proc_ro_t task_get_ro(struct task *t) __pure2;
97 
98 extern struct proc *proc_ro_proc(proc_ro_t pr) __pure2;
99 extern struct task *proc_ro_task(proc_ro_t pr) __pure2;
100 
101 #pragma GCC visibility pop
102 __ASSUME_PTR_ABI_SINGLE_END __END_DECLS
103 
104 #endif /* _SYS_PROC_RO_H_ */
105