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>
31 #include <os/availability.h>
34 #include <os/object.h>
35 #include "voucher_private.h"
37 #define OS_VOUCHER_ACTIVITY_SPI_VERSION 20161003
39 #if OS_VOUCHER_WEAK_IMPORT
40 #define OS_VOUCHER_EXPORT OS_EXPORT OS_WEAK_IMPORT
42 #define OS_VOUCHER_EXPORT OS_EXPORT
48 * @const VOUCHER_CURRENT
49 * Shorthand for the currently adopted voucher
51 * This value can only be used as an argument to functions, and is never
52 * actually returned. It looks enough like a tagged pointer object that ARC
53 * won't crash if this is assigned to a temporary variable.
55 #define VOUCHER_CURRENT ((OS_OBJECT_BRIDGE voucher_t)(void *)~2ul)
58 * @function voucher_get_activity_id
61 * Returns the activity_id associated with the specified voucher at the time
65 * When the passed voucher is VOUCHER_CURRENT this returns the current
69 * The specified voucher.
72 * An out parameter to return the parent ID of the returned activity ID.
75 * The current activity identifier, if any. When 0 is returned, parent_id will
78 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(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 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
108 OS_VOUCHER_EXPORT OS_NOTHROW
109 firehose_activity_id_t
110 voucher_get_activity_id_and_creator(voucher_t voucher
, uint64_t *creator_pid
,
111 firehose_activity_id_t
*parent_id
);
114 * @function voucher_activity_create_with_data
117 * Creates a voucher object with a new activity identifier.
120 * As part of voucher transport, activities are automatically propagated by the
121 * system to other threads and processes (across IPC).
123 * When a voucher with an activity identifier is applied to a thread, work
124 * on that thread is done on behalf of this activity.
127 * Tracepoint identifier returned by voucher_activity_trace_id(), intended for
128 * identification of the automatic tracepoint generated as part of creating the
132 * The base voucher used to create the activity. If the base voucher has an
133 * activity identifier, then the created activity will be parented to that one.
134 * If the passed in base has no activity identifier, the activity identifier
135 * will be a top-level one, on behalf of the process that created the base
138 * If base is VOUCHER_NONE, the activity is a top-level one, on behalf of the
141 * If base is VOUCHER_CURRENT, then the activity is naturally based on the
142 * one currently applied to the current thread (the one voucher_copy() would
146 * See voucher_activity_flag_t documentation for effect.
149 * Pointer to packed buffer of tracepoint data.
152 * Length of data at 'pubdata'.
155 * A new voucher with an activity identifier.
157 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
158 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
160 voucher_activity_create_with_data(firehose_tracepoint_id_t
*trace_id
,
161 voucher_t base
, firehose_activity_flags_t flags
,
162 const void *pubdata
, size_t publen
);
164 API_DEPRECATED_WITH_REPLACEMENT("voucher_activity_create_with_data",
165 macos(10.12,10.12), ios(10.0,10.0), tvos(10.0,10.0), watchos(3.0,3.0))
166 OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
168 voucher_activity_create_with_location(firehose_tracepoint_id_t
*trace_id
,
169 voucher_t base
, firehose_activity_flags_t flags
, uint64_t location
);
172 * @group Voucher Activity Trace SPI
173 * SPI intended for libtrace only
177 * @function voucher_activity_id_allocate
180 * Allocate a new system-wide unique activity ID.
183 * The bottom-most 8 bits of the flags will be used to generate the ID.
184 * See firehose_activity_flags_t.
186 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
187 OS_VOUCHER_EXPORT OS_NOTHROW
188 firehose_activity_id_t
189 voucher_activity_id_allocate(firehose_activity_flags_t flags
);
192 * @function voucher_activity_flush
195 * Force flushing the specified stream.
198 * This maks all the buffers currently being written to as full, so that
199 * their current content is pushed in a timely fashion.
201 * When this call returns, the actual flush may or may not yet have happened.
204 * The stream to flush.
206 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
207 OS_VOUCHER_EXPORT OS_NOTHROW
209 voucher_activity_flush(firehose_stream_t stream
);
212 * @function voucher_activity_trace
215 * Add a tracepoint to the specified stream.
218 * The stream to trace this entry into.
221 * Tracepoint identifier returned by voucher_activity_trace_id()
224 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
227 * Pointer to packed buffer of tracepoint data.
230 * Length of data at 'pubdata'.
232 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
233 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4
234 firehose_tracepoint_id_t
235 voucher_activity_trace(firehose_stream_t stream
,
236 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
237 const void *pubdata
, size_t publen
);
240 * @function voucher_activity_trace_v
243 * Add a tracepoint to the specified stream, with private data.
246 * The stream to trace this entry into.
249 * Tracepoint identifier returned by voucher_activity_trace_id()
252 * The mach_approximate_time()/mach_absolute_time() value for this tracepoint.
255 * Array of `struct iovec` pointing to the data to layout.
256 * The total size of this iovec must span exactly `publen + privlen` bytes.
257 * The `publen` boundary must coincide with the end of an iovec (each iovec
258 * must either be pure public or pure private data).
261 * Total length of data to read from the iovec for the public data.
264 * Length of data to read from the iovec after the public data for the private
267 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
268 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4
269 firehose_tracepoint_id_t
270 voucher_activity_trace_v(firehose_stream_t stream
,
271 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
272 const struct iovec
*iov
, size_t publen
, size_t privlen
);
275 API_DEPRECATED_WITH_REPLACEMENT("voucher_activity_trace_v",
276 macos(10.12,10.12), ios(10.0,10.0), tvos(10.0,10.0), watchos(3.0,3.0))
277 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL4 OS_NONNULL6
278 firehose_tracepoint_id_t
279 voucher_activity_trace_with_private_strings(firehose_stream_t stream
,
280 firehose_tracepoint_id_t trace_id
, uint64_t timestamp
,
281 const void *pubdata
, size_t publen
,
282 const void *privdata
, size_t privlen
);
284 typedef const struct voucher_activity_hooks_s
{
285 #define VOUCHER_ACTIVITY_HOOKS_VERSION 5
287 mach_port_t (*vah_get_logd_port
)(void);
288 dispatch_mach_handler_function_t vah_debug_channel_handler
;
289 kern_return_t (*vah_get_reconnect_info
)(mach_vm_address_t
*, mach_vm_size_t
*);
290 void (*vah_metadata_init
)(void *metadata_buffer
, size_t size
);
291 void (*vah_quarantine_starts
)(void);
292 } *voucher_activity_hooks_t
;
295 * @function voucher_activity_initialize_4libtrace
298 * Configure upcall hooks for libtrace.
301 * A pointer to a voucher_activity_hooks_s structure.
303 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
304 OS_VOUCHER_EXPORT OS_NOTHROW OS_NONNULL_ALL
306 voucher_activity_initialize_4libtrace(voucher_activity_hooks_t hooks
);
309 * @function voucher_activity_get_metadata_buffer
312 * Return address and length of buffer in the process trace memory area
313 * reserved for libtrace metadata.
316 * Pointer to size_t variable, filled with length of metadata buffer.
319 * Address of metadata buffer.
321 API_AVAILABLE(macos(10.10), ios(8.0))
322 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW OS_NONNULL_ALL
324 voucher_activity_get_metadata_buffer(size_t *length
);
327 * @function voucher_get_activity_id_4dyld
330 * Return the current voucher activity ID. Available for the dyld client stub
333 API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
334 OS_VOUCHER_EXPORT OS_WARN_RESULT OS_NOTHROW
335 firehose_activity_id_t
336 voucher_get_activity_id_4dyld(void);
340 #endif // OS_VOUCHER_ACTIVITY_SPI
342 #endif // __OS_VOUCHER_ACTIVITY_PRIVATE__