2 * Copyright (c) 2013-2015 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #ifndef __OS_VOUCHER_ACTIVITY_PRIVATE__
22 #define __OS_VOUCHER_ACTIVITY_PRIVATE__
24 #if OS_VOUCHER_ACTIVITY_SPI
25 #if __has_include(<mach/mach_time.h>)
26 #include <mach/mach_time.h>
27 #include <firehose/tracepoint_private.h>
32 #include <os/object.h>
33 #include "voucher_private.h"
35 #define OS_VOUCHER_ACTIVITY_SPI_VERSION 20160329
37 #if OS_VOUCHER_WEAK_IMPORT
38 #define OS_VOUCHER_EXPORT OS_EXPORT OS_WEAK_IMPORT
40 #define OS_VOUCHER_EXPORT OS_EXPORT
43 #define __VOUCHER_ACTIVITY_IGNORE_DEPRECATION_PUSH \
44 _Pragma("clang diagnostic push") \
45 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
46 #define __VOUCHER_ACTIVITY_IGNORE_DEPRECATION_POP \
47 _Pragma("clang diagnostic pop")
52 * @const VOUCHER_CURRENT
53 * Shorthand for the currently adopted voucher
55 * This value can only be used as an argument to functions, and is never
56 * actually returned. It looks enough like a tagged pointer object that ARC
57 * won't crash if this is assigned to a temporary variable.
59 #define VOUCHER_CURRENT ((OS_OBJECT_BRIDGE voucher_t)(void *)~2ul)
62 * @function voucher_get_activity_id
65 * Returns the activity_id associated with the specified voucher at the time
69 * When the passed voucher is VOUCHER_CURRENT this returns the current
73 * The specified voucher.
76 * An out parameter to return the parent ID of the returned activity ID.
79 * The current activity identifier, if any. When 0 is returned, parent_id will
82 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
83 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
84 OS_VOUCHER_EXPORT OS_NOTHROW
85 firehose_activity_id_t
86 voucher_get_activity_id(voucher_t voucher
, firehose_activity_id_t
*parent_id
);
89 * @function voucher_get_activity_id_and_creator
92 * Returns the activity_id associated with the specified voucher at the time
96 * When the passed voucher is VOUCHER_CURRENT this returns the current
100 * The specified voucher.
103 * The unique pid of the process that created the returned activity ID if any.
106 * An out parameter to return the parent ID of the returned activity ID.
109 * The current activity identifier, if any. When 0 is returned, parent_id will
112 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
113 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
114 OS_VOUCHER_EXPORT OS_NOTHROW
115 firehose_activity_id_t
116 voucher_get_activity_id_and_creator(voucher_t voucher
, uint64_t *creator_pid
,
117 firehose_activity_id_t
*parent_id
);
120 * @function voucher_activity_create
123 * Creates a voucher object with a new activity identifier.
126 * As part of voucher transport, activities are automatically propagated by the
127 * system to other threads and processes (across IPC).
129 * When a voucher with an activity identifier is applied to a thread, work
130 * on that thread is done on behalf of this activity.
133 * Tracepoint identifier returned by voucher_activity_trace_id(), intended for
134 * identification of the automatic tracepoint generated as part of creating the
138 * The base voucher used to create the activity. If the base voucher has an
139 * activity identifier, then the created activity will be parented to that one.
140 * If the passed in base has no activity identifier, the activity identifier
141 * will be a top-level one, on behalf of the process that created the base
144 * If base is VOUCHER_NONE, the activity is a top-level one, on behalf of the
147 * If base is VOUCHER_CURRENT, then the activity is naturally based on the
148 * one currently applied to the current thread (the one voucher_copy() would
152 * See voucher_activity_flag_t documentation for effect.
155 * Location identifier for the automatic tracepoint generated as part of
156 * creating the new activity.
159 * A new voucher with an activity identifier.
161 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
162 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
163 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
165 voucher_activity_create(firehose_tracepoint_id_t trace_id
,
166 voucher_t base
, firehose_activity_flags_t flags
, uint64_t location
);
168 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
169 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
170 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
172 voucher_activity_create_with_location(firehose_tracepoint_id_t
*trace_id
,
173 voucher_t base
, firehose_activity_flags_t flags
, uint64_t location
);
176 * @group Voucher Activity Trace SPI
177 * SPI intended for libtrace only
181 * @function voucher_activity_flush
184 * Force flushing the specified stream.
187 * This maks all the buffers currently being written to as full, so that
188 * their current content is pushed in a timely fashion.
190 * When this call returns, the actual flush may or may not yet have happened.
193 * The stream to flush.
195 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
196 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
197 OS_VOUCHER_EXPORT OS_NOTHROW
199 voucher_activity_flush(firehose_stream_t stream
);
202 * @function voucher_activity_trace
205 * Add a tracepoint to the specified stream.
208 * The stream to trace this entry into.
211 * Tracepoint identifier returned by voucher_activity_trace_id()
214 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
217 * Pointer to packed buffer of tracepoint data.
220 * Length of data at 'pubdata'.
222 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
223 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
224 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4
225 firehose_tracepoint_id_t
226 voucher_activity_trace(firehose_stream_t stream
,
227 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
228 const void *pubdata
, size_t publen
);
231 * @function voucher_activity_trace_with_private_strings
234 * Add a tracepoint to the specified stream, with private data.
237 * The stream to trace this entry into.
240 * Tracepoint identifier returned by voucher_activity_trace_id()
243 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
246 * Pointer to packed buffer of tracepoint data.
249 * Length of data at 'pubdata'.
252 * Pointer to packed buffer of private tracepoint data.
255 * Length of data at 'privdata'.
257 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
258 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
259 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4 OS_NONNULL6
260 firehose_tracepoint_id_t
261 voucher_activity_trace_with_private_strings(firehose_stream_t stream
,
262 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
263 const void *pubdata
, size_t publen
,
264 const void *privdata
, size_t privlen
);
266 typedef struct voucher_activity_hooks_s
{
267 #define VOUCHER_ACTIVITY_HOOKS_VERSION 3
270 mach_port_t (*vah_get_logd_port
)(void);
272 dispatch_mach_handler_function_t vah_debug_channel_handler
;
274 kern_return_t (*vah_get_reconnect_info
)(mach_vm_address_t
*, mach_vm_size_t
*);
275 } *voucher_activity_hooks_t
;
278 * @function voucher_activity_initialize_4libtrace
281 * Configure upcall hooks for libtrace.
284 * A pointer to a voucher_activity_hooks_s structure.
286 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
287 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
288 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL_ALL
290 voucher_activity_initialize_4libtrace(voucher_activity_hooks_t hooks
);
293 * @function voucher_activity_get_metadata_buffer
296 * Return address and length of buffer in the process trace memory area
297 * reserved for libtrace metadata.
300 * Pointer to size_t variable, filled with length of metadata buffer.
303 * Address of metadata buffer.
305 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
)
306 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW OS_NONNULL_ALL
308 voucher_activity_get_metadata_buffer(size_t *length
);
311 * @function voucher_get_activity_id_4dyld
314 * Return the current voucher activity ID. Available for the dyld client stub
317 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
318 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
319 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW
320 firehose_activity_id_t
321 voucher_get_activity_id_4dyld(void);
325 #endif // OS_VOUCHER_ACTIVITY_SPI
327 #endif // __OS_VOUCHER_ACTIVITY_PRIVATE__