]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2012-2019 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 _ATM_ATM_INTERNAL_H_ | |
30 | #define _ATM_ATM_INTERNAL_H_ | |
31 | ||
32 | #include <stdint.h> | |
33 | #include <mach/mach_types.h> | |
34 | #include <atm/atm_types.h> | |
35 | #include <os/refcnt.h> | |
36 | ||
37 | #ifdef MACH_KERNEL_PRIVATE | |
38 | ||
39 | #include <kern/thread.h> | |
40 | #include <kern/locks.h> | |
41 | #include <kern/queue.h> | |
42 | #include <ipc/ipc_voucher.h> | |
43 | ||
44 | /* Flags for atm task descriptor */ | |
45 | #define ATM_TASK_DEAD 0x1 | |
46 | ||
47 | /* Default value for Voucher Attribute Manager for ATM */ | |
48 | #define VAM_DEFAULT_VALUE NULL | |
49 | ||
50 | typedef mach_voucher_attr_value_handle_t atm_voucher_id_t; | |
51 | ||
52 | struct atm_task_descriptor { | |
53 | decl_lck_mtx_data(, lock); /* lock to protect reference count */ | |
54 | mach_port_t trace_buffer; /* named memory entry registered by user */ | |
55 | uint64_t trace_buffer_size; /* size of the trace_buffer registered */ | |
56 | os_refcnt_t reference_count; | |
57 | uint8_t flags; | |
58 | #if DEVELOPMENT || DEBUG | |
59 | task_t task; /* task pointer for debugging purposes */ | |
60 | queue_chain_t descriptor_elt; /* global chain of all descriptors */ | |
61 | #endif | |
62 | }; | |
63 | ||
64 | typedef struct atm_task_descriptor *atm_task_descriptor_t; | |
65 | #define ATM_TASK_DESCRIPTOR_NULL NULL | |
66 | ||
67 | struct atm_value { | |
68 | aid_t aid; /* activity id */ | |
69 | queue_head_t listeners; /* List of listeners who register for this activity */ | |
70 | decl_lck_mtx_data(, listener_lock); /* Lock to protect listener list */ | |
71 | queue_chain_t vid_hash_elt; /* Next hash element in the global hash table */ | |
72 | #if DEVELOPMENT || DEBUG | |
73 | queue_chain_t value_elt; /* global chain of all values */ | |
74 | #endif | |
75 | uint32_t sync; /* Made ref count given to voucher sub system. */ | |
76 | ||
77 | uint32_t listener_count; | |
78 | os_refcnt_t reference_count; /* use count on the atm value, 1 taken by the global hash table */ | |
79 | }; | |
80 | ||
81 | #define atm_listener_count_incr_internal(elem) \ | |
82 | (os_atomic_inc(&(elem)->listener_count, relaxed)) | |
83 | ||
84 | #define atm_listener_count_decr_internal(elem) \ | |
85 | (os_atomic_dec(&(elem)->listener_count, relaxed)) | |
86 | ||
87 | #define atm_sync_reference_internal(elem) \ | |
88 | (os_atomic_inc(&(elem)->sync, relaxed)) | |
89 | ||
90 | typedef struct atm_value *atm_value_t; | |
91 | #define ATM_VALUE_NULL NULL | |
92 | ||
93 | /* Flags for atm link objects */ | |
94 | #define ATM_LINK_REMOVE 0x1 | |
95 | ||
96 | struct atm_link_object { | |
97 | atm_task_descriptor_t descriptor; | |
98 | queue_chain_t listeners_element; /* Head is atm_value->listeners. */ | |
99 | atm_guard_t guard; /* Guard registered by the user for an activity. */ | |
100 | os_refcnt_t reference_count; | |
101 | }; | |
102 | ||
103 | typedef struct atm_link_object *atm_link_object_t; | |
104 | ||
105 | struct atm_value_hash { | |
106 | queue_head_t hash_list; | |
107 | decl_lck_mtx_data(, hash_list_lock); /* lock to protect bucket list. */ | |
108 | }; | |
109 | ||
110 | typedef struct atm_value_hash *atm_value_hash_t; | |
111 | ||
112 | void atm_init(void); | |
113 | void atm_task_descriptor_destroy(atm_task_descriptor_t task_descriptor); | |
114 | kern_return_t atm_register_trace_memory(task_t task, uint64_t trace_buffer_address, uint64_t buffer_size); | |
115 | kern_return_t atm_send_proc_inspect_notification(task_t task, int32_t traced_pid, uint64_t traced_uniqueid); | |
116 | ||
117 | #endif /* MACH_KERNEL_PRIVATE */ | |
118 | ||
119 | kern_return_t atm_set_diagnostic_config(uint32_t); | |
120 | uint32_t atm_get_diagnostic_config(void); | |
121 | ||
122 | #endif /* _ATM_ATM_INTERNAL_H_ */ |