2 * Copyright (c) 2012-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _ATM_ATM_INTERNAL_H_
30 #define _ATM_ATM_INTERNAL_H_
33 #include <mach/mach_types.h>
34 #include <atm/atm_types.h>
36 #ifdef MACH_KERNEL_PRIVATE
38 #include <kern/thread.h>
39 #include <kern/locks.h>
40 #include <kern/queue.h>
41 #include <ipc/ipc_voucher.h>
43 /* Flags for atm task descriptor */
44 #define ATM_TASK_DEAD 0x1
46 /* Default value for Voucher Attribute Manager for ATM */
47 #define VAM_DEFAULT_VALUE NULL
49 typedef mach_voucher_attr_value_handle_t atm_voucher_id_t
;
51 struct atm_task_descriptor
{
52 decl_lck_mtx_data(,lock
) /* lock to protect reference count */
53 mach_port_t trace_buffer
; /* named memory entry registered by user */
54 uint64_t trace_buffer_size
; /* size of the trace_buffer registered */
55 uint32_t reference_count
;
57 #if DEVELOPMENT || DEBUG
58 task_t task
; /* task pointer for debugging purposes */
59 queue_chain_t descriptor_elt
; /* global chain of all descriptors */
63 #define atm_task_desc_reference_internal(elem) \
64 (hw_atomic_add(&(elem)->reference_count, 1))
66 #define atm_task_desc_release_internal(elem) \
67 (hw_atomic_sub(&(elem)->reference_count, 1))
69 typedef struct atm_task_descriptor
*atm_task_descriptor_t
;
70 #define ATM_TASK_DESCRIPTOR_NULL NULL
73 aid_t aid
; /* activity id */
74 queue_head_t listeners
; /* List of listeners who register for this activity */
75 decl_lck_mtx_data( ,listener_lock
) /* Lock to protect listener list */
76 queue_chain_t vid_hash_elt
; /* Next hash element in the global hash table */
77 #if DEVELOPMENT || DEBUG
78 queue_chain_t value_elt
; /* global chain of all values */
80 uint32_t sync
; /* Made ref count given to voucher sub system. */
81 uint32_t listener_count
; /* Number of Listerners listening on the value. */
82 uint32_t reference_count
; /* use count on the atm value, 1 taken by the global hash table */
85 #define atm_value_reference_internal(elem) \
86 (hw_atomic_add(&(elem)->reference_count, 1))
88 #define atm_value_release_internal(elem) \
89 (hw_atomic_sub(&(elem)->reference_count, 1))
91 #define atm_listener_count_incr_internal(elem) \
92 (hw_atomic_add(&(elem)->listener_count, 1))
94 #define atm_listener_count_decr_internal(elem) \
95 (hw_atomic_sub(&(elem)->listener_count, 1))
97 #define atm_sync_reference_internal(elem) \
98 (hw_atomic_add(&(elem)->sync, 1))
100 typedef struct atm_value
*atm_value_t
;
101 #define ATM_VALUE_NULL NULL
103 /* Flags for atm link objects */
104 #define ATM_LINK_REMOVE 0x1
106 struct atm_link_object
{
107 atm_task_descriptor_t descriptor
;
108 queue_chain_t listeners_element
; /* Head is atm_value->listeners. */
109 atm_guard_t guard
; /* Guard registered by the user for an activity. */
110 uint32_t reference_count
; /* Refernece count for link object */
113 typedef struct atm_link_object
*atm_link_object_t
;
115 #define atm_link_object_reference_internal(elem) \
116 (hw_atomic_add(&(elem)->reference_count, 1))
118 #define atm_link_object_release_internal(elem) \
119 (hw_atomic_sub(&(elem)->reference_count, 1))
121 struct atm_value_hash
{
122 queue_head_t hash_list
;
123 decl_lck_mtx_data(, hash_list_lock
) /* lock to protect bucket list. */
126 typedef struct atm_value_hash
*atm_value_hash_t
;
129 void atm_task_descriptor_destroy(atm_task_descriptor_t task_descriptor
);
130 kern_return_t
atm_register_trace_memory(task_t task
, uint64_t trace_buffer_address
, uint64_t buffer_size
);
131 kern_return_t
atm_send_proc_inspect_notification(task_t task
, int32_t traced_pid
, uint64_t traced_uniqueid
);
133 #endif /* MACH_KERNEL_PRIVATE */
135 kern_return_t
atm_set_diagnostic_config(uint32_t);
136 uint32_t atm_get_diagnostic_config(void);
138 #endif /* _ATM_ATM_INTERNAL_H_ */