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 <mach/task_info.h> 33 #include <stdint.h> 34 #include <sys/_types/_pid_t.h> 35 #include <sys/cdefs.h> 36 #include <kern/smr_types.h> 37 38 __BEGIN_DECLS __ASSUME_PTR_ABI_SINGLE_BEGIN 39 #pragma GCC visibility push(hidden) 40 41 struct proc; 42 struct task; 43 struct ucred; 44 45 struct proc_platform_ro_data { 46 uint32_t p_platform; 47 uint32_t p_min_sdk; 48 uint32_t p_sdk; 49 }; 50 51 struct task_token_ro_data { 52 security_token_t sec_token; 53 audit_token_t audit_token; 54 }; 55 56 struct task_filter_ro_data { 57 uint8_t *__unsafe_indexable mach_trap_filter_mask; /* Mach trap filter bitmask (len: mach_trap_count bits) */ 58 uint8_t *__unsafe_indexable mach_kobj_filter_mask; /* Mach kobject filter bitmask (len: mach_kobj_count bits) */ 59 }; 60 61 /*! 62 * @struct proc_ro 63 * 64 * @brief 65 * Store read-only data associated to a task and/or proc 66 * 67 * @discussion 68 * The lifetime of a @c proc_ro structure is 1:1 with that 69 * of a @c proc_t or a @c task_t. @c proc_t and @c task_t 70 * point to the same @c proc_ro, except for corpses which 71 * have an invalid and uninitialized @c proc_t, and the 72 * proc_data field is uninitalized. 73 */ 74 struct proc_ro { 75 struct proc *pr_proc; 76 struct task *pr_task; 77 78 __xnu_struct_group(proc_ro_data, proc_data, { 79 uint64_t p_uniqueid; /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */ 80 int p_idversion; /* version of process identity */ 81 pid_t p_orig_ppid; /* process's original parent pid, doesn't change if reparented */ 82 int p_orig_ppidversion; /* process's original parent pid version, doesn't change if reparented */ 83 uint32_t p_csflags; 84 SMR_POINTER(struct ucred *) p_ucred; /* Process owner's identity. (PUCL) */ 85 uint8_t *__unsafe_indexable syscall_filter_mask; /* syscall filter bitmask (length: nsysent bits) */ 86 struct proc_platform_ro_data p_platform_data; 87 }); 88 89 __xnu_struct_group(task_ro_data, task_data, { 90 /* Task security and audit tokens */ 91 struct task_token_ro_data task_tokens; 92 #ifdef CONFIG_MACF 93 struct task_filter_ro_data task_filters; 94 #endif 95 uint32_t t_flags_ro; /* RO-protected task flags (see osfmk/kern/task.h) */ 96 97 /* This is not inherited on fork/exec, must be re-evaluated */ 98 task_control_port_options_t task_control_port_options; 99 }); 100 }; 101 102 typedef const struct proc_ro_data *proc_ro_data_t; 103 typedef const struct task_ro_data *task_ro_data_t; 104 typedef struct proc_ro *proc_ro_t; 105 106 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); 107 extern proc_ro_t proc_ro_ref_task(proc_ro_t pr, struct task *t, task_ro_data_t t_data); 108 extern void proc_ro_erase_task(proc_ro_t pr); 109 110 extern proc_ro_t proc_get_ro(struct proc *p) __pure2; 111 extern proc_ro_t task_get_ro(struct task *t) __pure2; 112 113 extern struct task *proc_ro_task(proc_ro_t pr) __pure2; 114 115 #pragma GCC visibility pop 116 __ASSUME_PTR_ABI_SINGLE_END __END_DECLS 117 118 #endif /* _SYS_PROC_RO_H_ */ 119