xref: /xnu-11215/osfmk/kern/task_ref.h (revision 5c2921b0)
1 /*
2  * Copyright (c) 2000-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 #ifndef _KERN_TASK_REF_H_
30 #define _KERN_TASK_REF_H_
31 
32 #include <mach/mach_types.h>
33 
34 #include <stdint.h>
35 
36 #if MACH_KERNEL_PRIVATE
37 
38 
39 extern void task_ref_init(void);
40 
41 extern void task_ref_count_fini(task_t);
42 extern kern_return_t task_ref_count_init(task_t);
43 
44 extern void task_reference_external(task_t task);
45 extern void task_deallocate_external(task_t task);
46 
47 #endif /* MACH_KERNEL_PRIVATE */
48 
49 #if XNU_KERNEL_PRIVATE
50 
51 #include <os/refcnt.h>
52 
53 __BEGIN_DECLS
54 
55 extern struct os_refgrp task_external_refgrp;
56 
57 __options_closed_decl(task_grp_t, uint32_t, {
58 	TASK_GRP_KERNEL,
59 	TASK_GRP_INTERNAL,
60 	TASK_GRP_MIG,
61 	TASK_GRP_EXTERNAL,
62 
63 	TASK_GRP_COUNT,
64 });
65 
66 extern void task_reference_grp(task_t, task_grp_t);
67 extern void task_deallocate_grp(task_t, task_grp_t);
68 
69 #define task_reference_mig(task) task_reference_grp(task, TASK_GRP_MIG)
70 #define task_deallocate_mig(task) task_deallocate_grp(task, TASK_GRP_MIG)
71 
72 /*
73  * Exported symbols get mapped to their _external versions. Internal consumers of
74  * these functions need to pick up the _kernel version.
75  */
76 
77 #define task_reference(task) task_reference_grp(task, TASK_GRP_KERNEL)
78 #define task_deallocate(task) task_deallocate_grp(task, TASK_GRP_KERNEL)
79 
80 #define convert_task_to_port(task) convert_task_to_port_kernel(task)
81 #define convert_task_read_to_port(task) convert_task_read_to_port_kernel(task)
82 
83 #define port_name_to_task(name) port_name_to_task_kernel(name)
84 
85 #define convert_port_to_task_suspension_token(port) convert_port_to_task_suspension_token_kernel(port)
86 #define convert_task_suspension_token_to_port(token) convert_task_suspension_token_to_port_kernel(token)
87 
88 #define task_resume2(token) task_resume2_kernel(token)
89 #define task_suspend2(task, token) task_suspend2_kernel(task, token)
90 
91 __END_DECLS
92 
93 #else /* XNU_KERNEL_PRIVATE */
94 
95 __BEGIN_DECLS
96 
97 extern void             task_reference(task_t);
98 extern void             task_deallocate(task_t);
99 
100 __END_DECLS
101 #endif /* XNU_KERNEL_PRIVATE */
102 
103 #endif /*_KERN_TASK_REF_H_ */
104