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
67kern_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
70void task_id_token_release(task_id_token_t token);
71
72ipc_port_t convert_task_id_token_to_port(task_id_token_t token);
73
74task_id_token_t convert_port_to_task_id_token(ipc_port_t port);
75
76#if MACH_KERNEL_PRIVATE
77kern_return_t task_identity_token_get_task_grp(task_id_token_t token, task_t *taskp, task_grp_t grp);
78#endif /* MACH_KERNEL_PRIVATE */
79
80#else /* !XNU_KERNEL_PRIVATE */
81kern_return_t task_id_token_port_name_to_task(mach_port_name_t name, task_t *taskp);
82#endif /* !XNU_KERNEL_PRIVATE */
83
84__END_DECLS
85
86#endif /* KERNEL_PRIVATE */
87
88#endif /* _KERN_TASK_IDENT_H */
89