xref: /xnu-11215/bsd/sys/proc_ro.h (revision 8d741a5d)
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 /*!
61  * @struct proc_ro
62  *
63  * @brief
64  * Store read-only data associated to a task and/or proc
65  *
66  * @discussion
67  * The lifetime of a @c proc_ro structure is 1:1 with that
68  * of a @c proc_t or a @c task_t. @c proc_t and @c task_t
69  * point to the same @c proc_ro, except for corpses which
70  * have an invalid and uninitialized @c proc_t, and the
71  * proc_data field is uninitalized.
72  */
73 struct proc_ro {
74 	struct proc *pr_proc;
75 	struct task *pr_task;
76 
77 	__xnu_struct_group(proc_ro_data, proc_data, {
78 		uint64_t p_uniqueid;                               /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */
79 		int p_idversion;                                   /* version of process identity */
80 		uint32_t p_csflags;
81 		SMR_POINTER(struct ucred *) p_ucred;               /* Process owner's identity. (PUCL) */
82 		uint8_t *__unsafe_indexable syscall_filter_mask;   /* syscall filter bitmask (length: nsysent bits) */
83 		struct proc_platform_ro_data p_platform_data;
84 	});
85 
86 	__xnu_struct_group(task_ro_data, task_data, {
87 		/* Task security and audit tokens */
88 		struct task_token_ro_data task_tokens;
89 #ifdef CONFIG_MACF
90 		struct task_filter_ro_data task_filters;
91 #endif
92 		uint32_t t_flags_ro;                               /* RO-protected task flags (see osfmk/kern/task.h) */
93 		uint32_t task_control_port_options;
94 	});
95 };
96 
97 typedef const struct proc_ro_data *proc_ro_data_t;
98 typedef const struct task_ro_data *task_ro_data_t;
99 typedef struct proc_ro *proc_ro_t;
100 
101 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);
102 extern proc_ro_t proc_ro_ref_task(proc_ro_t pr, struct task *t, task_ro_data_t t_data);
103 extern void proc_ro_erase_task(proc_ro_t pr);
104 
105 extern proc_ro_t proc_get_ro(struct proc *p) __pure2;
106 extern proc_ro_t task_get_ro(struct task *t) __pure2;
107 
108 extern struct task *proc_ro_task(proc_ro_t pr) __pure2;
109 
110 #pragma GCC visibility pop
111 __ASSUME_PTR_ABI_SINGLE_END __END_DECLS
112 
113 #endif /* _SYS_PROC_RO_H_ */
114