]>
Commit | Line | Data |
---|---|---|
fe8ab488 | 1 | /* |
cb323159 | 2 | * Copyright (c) 2012-2019 Apple Inc. All rights reserved. |
fe8ab488 A |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
0a7de745 | 5 | * |
fe8ab488 A |
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. | |
0a7de745 | 14 | * |
fe8ab488 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
fe8ab488 A |
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. | |
0a7de745 | 25 | * |
fe8ab488 A |
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> | |
cb323159 | 35 | #include <os/refcnt.h> |
fe8ab488 | 36 | |
0a7de745 | 37 | #ifdef MACH_KERNEL_PRIVATE |
fe8ab488 A |
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 { | |
cb323159 | 53 | decl_lck_mtx_data(, lock); /* lock to protect reference count */ |
0a7de745 | 54 | mach_port_t trace_buffer; /* named memory entry registered by user */ |
3e170ce0 | 55 | uint64_t trace_buffer_size; /* size of the trace_buffer registered */ |
cb323159 | 56 | os_refcnt_t reference_count; |
3e170ce0 | 57 | uint8_t flags; |
fe8ab488 | 58 | #if DEVELOPMENT || DEBUG |
3e170ce0 A |
59 | task_t task; /* task pointer for debugging purposes */ |
60 | queue_chain_t descriptor_elt; /* global chain of all descriptors */ | |
fe8ab488 A |
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 { | |
3e170ce0 A |
68 | aid_t aid; /* activity id */ |
69 | queue_head_t listeners; /* List of listeners who register for this activity */ | |
cb323159 | 70 | decl_lck_mtx_data(, listener_lock); /* Lock to protect listener list */ |
3e170ce0 | 71 | queue_chain_t vid_hash_elt; /* Next hash element in the global hash table */ |
fe8ab488 | 72 | #if DEVELOPMENT || DEBUG |
3e170ce0 | 73 | queue_chain_t value_elt; /* global chain of all values */ |
fe8ab488 | 74 | #endif |
3e170ce0 | 75 | uint32_t sync; /* Made ref count given to voucher sub system. */ |
3e170ce0 | 76 | |
cb323159 A |
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 | }; | |
3e170ce0 | 80 | |
0a7de745 | 81 | #define atm_listener_count_incr_internal(elem) \ |
cb323159 | 82 | (os_atomic_inc(&(elem)->listener_count, relaxed)) |
3e170ce0 | 83 | |
0a7de745 | 84 | #define atm_listener_count_decr_internal(elem) \ |
cb323159 | 85 | (os_atomic_dec(&(elem)->listener_count, relaxed)) |
3e170ce0 | 86 | |
0a7de745 | 87 | #define atm_sync_reference_internal(elem) \ |
cb323159 | 88 | (os_atomic_inc(&(elem)->sync, relaxed)) |
3e170ce0 | 89 | |
fe8ab488 A |
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; | |
0a7de745 A |
98 | queue_chain_t listeners_element; /* Head is atm_value->listeners. */ |
99 | atm_guard_t guard; /* Guard registered by the user for an activity. */ | |
cb323159 | 100 | os_refcnt_t reference_count; |
fe8ab488 A |
101 | }; |
102 | ||
103 | typedef struct atm_link_object *atm_link_object_t; | |
104 | ||
fe8ab488 | 105 | struct atm_value_hash { |
0a7de745 | 106 | queue_head_t hash_list; |
cb323159 | 107 | decl_lck_mtx_data(, hash_list_lock); /* lock to protect bucket list. */ |
fe8ab488 A |
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); | |
0a7de745 | 114 | kern_return_t atm_register_trace_memory(task_t task, uint64_t trace_buffer_address, uint64_t buffer_size); |
fe8ab488 A |
115 | kern_return_t atm_send_proc_inspect_notification(task_t task, int32_t traced_pid, uint64_t traced_uniqueid); |
116 | ||
39037602 A |
117 | #endif /* MACH_KERNEL_PRIVATE */ |
118 | ||
3e170ce0 A |
119 | kern_return_t atm_set_diagnostic_config(uint32_t); |
120 | uint32_t atm_get_diagnostic_config(void); | |
121 | ||
fe8ab488 | 122 | #endif /* _ATM_ATM_INTERNAL_H_ */ |