1 /* 2 * Copyright (c) 2020 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 /* 30 * 31 * A task identity token represents the identity of a mach task without carrying task 32 * access capabilities. In applicable scenarios, task identity token can be moved between 33 * tasks and be upgraded to desired level of task port flavor (namely, task name port, 34 * inspect port, read port or control port) upon use. 35 * 36 */ 37 38 #ifndef _KERN_TASK_IDENT_H 39 #define _KERN_TASK_IDENT_H 40 41 #if KERNEL_PRIVATE 42 43 #include <kern/kern_types.h> 44 #include <mach/mach_types.h> 45 46 __BEGIN_DECLS 47 48 #define TASK_IDENTITY_TOKEN_KPI_VERSION 1 49 50 /*! 51 * @function task_id_token_port_name_to_task() 52 * 53 * @abstract 54 * Produces a task reference from task identity token port name. 55 * 56 * For export to kexts only. _DO NOT_ use in kenel proper for correct task 57 * reference counting. 58 * 59 * @param name port name for the task identity token to operate on 60 * @param taskp task_t pointer 61 * 62 * @returns KERN_SUCCESS A valid task reference is produced. 63 * KERN_NOT_FOUND Cannot find task represented by token. 64 * KERN_INVALID_ARGUMENT Passed identity token is invalid. 65 */ 66 #if XNU_KERNEL_PRIVATE 67 kern_return_t task_id_token_port_name_to_task(mach_port_name_t name, task_t *taskp) 68 __XNU_INTERNAL(task_id_token_port_name_to_task); 69 70 struct proc_ident { 71 uint64_t p_uniqueid; 72 pid_t p_pid; 73 int p_idversion; 74 }; 75 76 struct task_id_token { 77 struct proc_ident ident; 78 ipc_port_t port; 79 uint64_t task_uniqueid; /* for corpse task */ 80 os_refcnt_t tidt_refs; 81 }; 82 83 void task_id_token_release(task_id_token_t token); 84 85 ipc_port_t convert_task_id_token_to_port(task_id_token_t token); 86 87 task_id_token_t convert_port_to_task_id_token(ipc_port_t port); 88 89 #if MACH_KERNEL_PRIVATE 90 kern_return_t task_identity_token_get_task_grp(task_id_token_t token, task_t *taskp, task_grp_t grp); 91 #endif /* MACH_KERNEL_PRIVATE */ 92 93 #else /* !XNU_KERNEL_PRIVATE */ 94 kern_return_t task_id_token_port_name_to_task(mach_port_name_t name, task_t *taskp); 95 #endif /* !XNU_KERNEL_PRIVATE */ 96 97 __END_DECLS 98 99 #endif /* KERNEL_PRIVATE */ 100 101 #endif /* _KERN_TASK_IDENT_H */ 102