xref: /xnu-10002.41.9/bsd/sys/proc_ro.h (revision 699cd48037512bf4380799317ca44ca453c82f57)
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 #include <kern/smr_types.h>
36 
37 __BEGIN_DECLS __ASSUME_PTR_ABI_SINGLE_BEGIN
38 #pragma GCC visibility push(hidden)
39 
40 struct proc;
41 struct task;
42 struct ucred;
43 
44 struct proc_platform_ro_data {
45 	uint32_t p_platform;
46 	uint32_t p_min_sdk;
47 	uint32_t p_sdk;
48 };
49 
50 struct task_token_ro_data {
51 	security_token_t sec_token;
52 	audit_token_t audit_token;
53 };
54 
55 struct task_filter_ro_data {
56 	uint8_t *__unsafe_indexable mach_trap_filter_mask; /* Mach trap filter bitmask (len: mach_trap_count bits) */
57 	uint8_t *__unsafe_indexable mach_kobj_filter_mask; /* Mach kobject filter bitmask (len: mach_kobj_count bits) */
58 };
59 
60 struct proc_ro {
61 	struct proc *pr_proc;
62 	struct task *pr_task;
63 
64 	__xnu_struct_group(proc_ro_data, proc_data, {
65 		uint64_t p_uniqueid;                               /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */
66 		int p_idversion;                                   /* version of process identity */
67 		uint32_t p_csflags;
68 		SMR_POINTER(struct ucred *) p_ucred;               /* Process owner's identity. (PUCL) */
69 		uint8_t *__unsafe_indexable syscall_filter_mask;   /* syscall filter bitmask (length: nsysent bits) */
70 		struct proc_platform_ro_data p_platform_data;
71 	});
72 
73 	__xnu_struct_group(task_ro_data, task_data, {
74 		/* Task security and audit tokens */
75 		struct task_token_ro_data task_tokens;
76 #ifdef CONFIG_MACF
77 		struct task_filter_ro_data task_filters;
78 #endif
79 		uint32_t t_flags_ro;                               /* RO-protected task flags (see osfmk/kern/task.h) */
80 		uint32_t task_control_port_options;
81 	});
82 };
83 
84 typedef const struct proc_ro_data *proc_ro_data_t;
85 typedef const struct task_ro_data *task_ro_data_t;
86 typedef struct proc_ro *proc_ro_t;
87 
88 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);
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_ro_erase_task(proc_ro_t pr);
91 
92 extern proc_ro_t proc_get_ro(struct proc *p) __pure2;
93 extern proc_ro_t task_get_ro(struct task *t) __pure2;
94 
95 extern struct task *proc_ro_task(proc_ro_t pr) __pure2;
96 
97 #pragma GCC visibility pop
98 __ASSUME_PTR_ABI_SINGLE_END __END_DECLS
99 
100 #endif /* _SYS_PROC_RO_H_ */
101