]> git.saurik.com Git - apple/xnu.git/blame - osfmk/atm/atm_internal.h
xnu-3248.30.4.tar.gz
[apple/xnu.git] / osfmk / atm / atm_internal.h
CommitLineData
fe8ab488
A
1/*
2 * Copyright (c) 2012-2013 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
36#ifdef MACH_KERNEL_PRIVATE
37
38#include <kern/thread.h>
39#include <kern/locks.h>
40#include <kern/queue.h>
41#include <ipc/ipc_voucher.h>
42
43/* Flags for atm task descriptor */
44#define ATM_TASK_DEAD 0x1
45
46/* Default value for Voucher Attribute Manager for ATM */
47#define VAM_DEFAULT_VALUE NULL
48
49typedef mach_voucher_attr_value_handle_t atm_voucher_id_t;
50
51struct atm_task_descriptor {
3e170ce0
A
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;
56 uint8_t flags;
fe8ab488 57#if DEVELOPMENT || DEBUG
3e170ce0
A
58 task_t task; /* task pointer for debugging purposes */
59 queue_chain_t descriptor_elt; /* global chain of all descriptors */
fe8ab488
A
60#endif
61};
62
3e170ce0
A
63#define atm_task_desc_reference_internal(elem) \
64 (hw_atomic_add(&(elem)->reference_count, 1))
65
66#define atm_task_desc_release_internal(elem) \
67 (hw_atomic_sub(&(elem)->reference_count, 1))
68
fe8ab488
A
69typedef struct atm_task_descriptor *atm_task_descriptor_t;
70#define ATM_TASK_DESCRIPTOR_NULL NULL
71
72struct atm_value {
3e170ce0
A
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 */
fe8ab488 77#if DEVELOPMENT || DEBUG
3e170ce0 78 queue_chain_t value_elt; /* global chain of all values */
fe8ab488 79#endif
3e170ce0
A
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 */
fe8ab488
A
83};
84
3e170ce0
A
85#define atm_value_reference_internal(elem) \
86 (hw_atomic_add(&(elem)->reference_count, 1))
87
88#define atm_value_release_internal(elem) \
89 (hw_atomic_sub(&(elem)->reference_count, 1))
90
91#define atm_listener_count_incr_internal(elem) \
92 (hw_atomic_add(&(elem)->listener_count, 1))
93
94#define atm_listener_count_decr_internal(elem) \
95 (hw_atomic_sub(&(elem)->listener_count, 1))
96
97#define atm_sync_reference_internal(elem) \
98 (hw_atomic_add(&(elem)->sync, 1))
99
fe8ab488
A
100typedef struct atm_value *atm_value_t;
101#define ATM_VALUE_NULL NULL
102
103/* Flags for atm link objects */
104#define ATM_LINK_REMOVE 0x1
105
106struct atm_link_object {
107 atm_task_descriptor_t descriptor;
fe8ab488 108 queue_chain_t listeners_element; /* Head is atm_value->listeners. */
3e170ce0
A
109 atm_guard_t guard; /* Guard registered by the user for an activity. */
110 uint32_t reference_count; /* Refernece count for link object */
fe8ab488
A
111};
112
113typedef struct atm_link_object *atm_link_object_t;
114
115#define atm_link_object_reference_internal(elem) \
116 (hw_atomic_add(&(elem)->reference_count, 1))
117
118#define atm_link_object_release_internal(elem) \
119 (hw_atomic_sub(&(elem)->reference_count, 1))
120
121struct atm_value_hash {
122 queue_head_t hash_list;
123 decl_lck_mtx_data(, hash_list_lock) /* lock to protect bucket list. */
124};
125
126typedef struct atm_value_hash *atm_value_hash_t;
127
128void atm_init(void);
129void atm_task_descriptor_destroy(atm_task_descriptor_t task_descriptor);
3e170ce0 130kern_return_t atm_register_trace_memory(task_t task, uint64_t trace_buffer_address, uint64_t buffer_size);
fe8ab488
A
131kern_return_t atm_send_proc_inspect_notification(task_t task, int32_t traced_pid, uint64_t traced_uniqueid);
132
3e170ce0
A
133kern_return_t atm_set_diagnostic_config(uint32_t);
134uint32_t atm_get_diagnostic_config(void);
135
fe8ab488
A
136#endif /* MACH_KERNEL_PRIVATE */
137
138#endif /* _ATM_ATM_INTERNAL_H_ */