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>
33 #include <os/object.h>
34 #include "voucher_private.h"
36 #define OS_VOUCHER_ACTIVITY_SPI_VERSION 20161003
38 #if OS_VOUCHER_WEAK_IMPORT
39 #define OS_VOUCHER_EXPORT OS_EXPORT OS_WEAK_IMPORT
41 #define OS_VOUCHER_EXPORT OS_EXPORT
47 * @const VOUCHER_CURRENT
48 * Shorthand for the currently adopted voucher
50 * This value can only be used as an argument to functions, and is never
51 * actually returned. It looks enough like a tagged pointer object that ARC
52 * won't crash if this is assigned to a temporary variable.
54 #define VOUCHER_CURRENT ((OS_OBJECT_BRIDGE voucher_t)(void *)~2ul)
57 * @function voucher_get_activity_id
60 * Returns the activity_id associated with the specified voucher at the time
64 * When the passed voucher is VOUCHER_CURRENT this returns the current
68 * The specified voucher.
71 * An out parameter to return the parent ID of the returned activity ID.
74 * The current activity identifier, if any. When 0 is returned, parent_id will
77 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
78 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
79 OS_VOUCHER_EXPORT OS_NOTHROW
80 firehose_activity_id_t
81 voucher_get_activity_id(voucher_t voucher
, firehose_activity_id_t
*parent_id
);
84 * @function voucher_get_activity_id_and_creator
87 * Returns the activity_id associated with the specified voucher at the time
91 * When the passed voucher is VOUCHER_CURRENT this returns the current
95 * The specified voucher.
98 * The unique pid of the process that created the returned activity ID if any.
101 * An out parameter to return the parent ID of the returned activity ID.
104 * The current activity identifier, if any. When 0 is returned, parent_id will
107 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
108 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
109 OS_VOUCHER_EXPORT OS_NOTHROW
110 firehose_activity_id_t
111 voucher_get_activity_id_and_creator(voucher_t voucher
, uint64_t *creator_pid
,
112 firehose_activity_id_t
*parent_id
);
115 * @function voucher_activity_create_with_data
118 * Creates a voucher object with a new activity identifier.
121 * As part of voucher transport, activities are automatically propagated by the
122 * system to other threads and processes (across IPC).
124 * When a voucher with an activity identifier is applied to a thread, work
125 * on that thread is done on behalf of this activity.
128 * Tracepoint identifier returned by voucher_activity_trace_id(), intended for
129 * identification of the automatic tracepoint generated as part of creating the
133 * The base voucher used to create the activity. If the base voucher has an
134 * activity identifier, then the created activity will be parented to that one.
135 * If the passed in base has no activity identifier, the activity identifier
136 * will be a top-level one, on behalf of the process that created the base
139 * If base is VOUCHER_NONE, the activity is a top-level one, on behalf of the
142 * If base is VOUCHER_CURRENT, then the activity is naturally based on the
143 * one currently applied to the current thread (the one voucher_copy() would
147 * See voucher_activity_flag_t documentation for effect.
150 * Pointer to packed buffer of tracepoint data.
153 * Length of data at 'pubdata'.
156 * A new voucher with an activity identifier.
158 __OSX_AVAILABLE(10.12.4) __IOS_AVAILABLE(10.3)
159 __TVOS_AVAILABLE(10.2) __WATCHOS_AVAILABLE(3.2)
160 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
162 voucher_activity_create_with_data(firehose_tracepoint_id_t
*trace_id
,
163 voucher_t base
, firehose_activity_flags_t flags
,
164 const void *pubdata
, size_t publen
);
166 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
167 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
168 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
170 voucher_activity_create_with_location(firehose_tracepoint_id_t
*trace_id
,
171 voucher_t base
, firehose_activity_flags_t flags
, uint64_t location
);
174 * @group Voucher Activity Trace SPI
175 * SPI intended for libtrace only
179 * @function voucher_activity_flush
182 * Force flushing the specified stream.
185 * This maks all the buffers currently being written to as full, so that
186 * their current content is pushed in a timely fashion.
188 * When this call returns, the actual flush may or may not yet have happened.
191 * The stream to flush.
193 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
194 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
195 OS_VOUCHER_EXPORT OS_NOTHROW
197 voucher_activity_flush(firehose_stream_t stream
);
200 * @function voucher_activity_trace
203 * Add a tracepoint to the specified stream.
206 * The stream to trace this entry into.
209 * Tracepoint identifier returned by voucher_activity_trace_id()
212 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
215 * Pointer to packed buffer of tracepoint data.
218 * Length of data at 'pubdata'.
220 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
221 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
222 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4
223 firehose_tracepoint_id_t
224 voucher_activity_trace(firehose_stream_t stream
,
225 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
226 const void *pubdata
, size_t publen
);
229 * @function voucher_activity_trace_v
232 * Add a tracepoint to the specified stream, with private data.
235 * The stream to trace this entry into.
238 * Tracepoint identifier returned by voucher_activity_trace_id()
241 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
244 * Array of `struct iovec` pointing to the data to layout.
245 * The total size of this iovec must span exactly `publen + privlen` bytes.
246 * The `publen` boundary must coincide with the end of an iovec (each iovec
247 * must either be pure public or pure private data).
250 * Total length of data to read from the iovec for the public data.
253 * Length of data to read from the iovec after the public data for the private
256 __OSX_AVAILABLE(10.12.4) __IOS_AVAILABLE(10.3)
257 __TVOS_AVAILABLE(10.2) __WATCHOS_AVAILABLE(3.2)
258 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4
259 firehose_tracepoint_id_t
260 voucher_activity_trace_v(firehose_stream_t stream
,
261 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
262 const struct iovec
*iov
, size_t publen
, size_t privlen
);
265 __OSX_DEPRECATED(10.12, 10.12.4, "Use voucher_activity_trace_v")
266 __IOS_DEPRECATED(10.0, 10.3, "Use voucher_activity_trace_v")
267 __TVOS_DEPRECATED(10.0, 10.2, "Use voucher_activity_trace_v")
268 __WATCHOS_DEPRECATED(3.0, 3.2, "Use voucher_activity_trace_v")
269 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4 OS_NONNULL6
270 firehose_tracepoint_id_t
271 voucher_activity_trace_with_private_strings(firehose_stream_t stream
,
272 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
273 const void *pubdata
, size_t publen
,
274 const void *privdata
, size_t privlen
);
276 typedef const struct voucher_activity_hooks_s
{
277 #define VOUCHER_ACTIVITY_HOOKS_VERSION 4
279 mach_port_t (*vah_get_logd_port
)(void);
280 dispatch_mach_handler_function_t vah_debug_channel_handler
;
281 kern_return_t (*vah_get_reconnect_info
)(mach_vm_address_t
*, mach_vm_size_t
*);
282 void (*vah_metadata_init
)(void *metadata_buffer
, size_t size
);
283 } *voucher_activity_hooks_t
;
286 * @function voucher_activity_initialize_4libtrace
289 * Configure upcall hooks for libtrace.
292 * A pointer to a voucher_activity_hooks_s structure.
294 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
295 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
296 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL_ALL
298 voucher_activity_initialize_4libtrace(voucher_activity_hooks_t hooks
);
301 * @function voucher_activity_get_metadata_buffer
304 * Return address and length of buffer in the process trace memory area
305 * reserved for libtrace metadata.
308 * Pointer to size_t variable, filled with length of metadata buffer.
311 * Address of metadata buffer.
313 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
)
314 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW OS_NONNULL_ALL
316 voucher_activity_get_metadata_buffer(size_t *length
);
319 * @function voucher_get_activity_id_4dyld
322 * Return the current voucher activity ID. Available for the dyld client stub
325 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
326 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
327 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW
328 firehose_activity_id_t
329 voucher_get_activity_id_4dyld(void);
333 #endif // OS_VOUCHER_ACTIVITY_SPI
335 #endif // __OS_VOUCHER_ACTIVITY_PRIVATE__