2 * Copyright (c) 2013-2016 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 __FIREHOSE_ACTIVITY__
22 #define __FIREHOSE_ACTIVITY__
24 #include <machine/cpu_capabilities.h>
25 #include <mach/mach_time.h>
28 #include <atm/atm_internal.h>
30 #include "firehose_types_private.h"
32 OS_ASSUME_NONNULL_BEGIN
35 * @typedef firehose_tracepoint_id_u
38 * Broken down tracepoint identifier.
42 firehose_tracepoint_namespace_t _namespace
;
43 firehose_tracepoint_type_t _type
;
44 firehose_tracepoint_flags_t _flags
;
47 firehose_tracepoint_id_t ftid_value
;
48 } firehose_tracepoint_id_u
;
50 #define FIREHOSE_STAMP_SLOP (1ULL << 36) // ~1minute
53 * @typedef firehose_trace_uuid_info_t
56 * Info needed by logd when kexts are loaded or unloaded
59 typedef struct firehose_trace_uuid_info_s
{
60 uuid_t ftui_uuid
; /* uuid of binary */
61 uint64_t ftui_address
; /* load address */
62 uint64_t ftui_size
; /* load size */
63 char ftui_path
[]; /* full path of binary - Unused in the kernel*/
64 } *firehose_trace_uuid_info_t
;
67 * @typedef firehose_tracepoint_t
69 typedef struct firehose_tracepoint_s
{
70 firehose_tracepoint_id_u ft_id
;
74 uint64_t ft_timestamp_delta
: 48;
75 uint64_t ft_length
: 16;
77 uint64_t ft_stamp_and_length
;
80 } *firehose_tracepoint_t
;
82 #define FIREHOSE_TRACE_ID_MAKE(ns, type, flags, code) \
83 (((firehose_tracepoint_id_u){ .ftid = { \
90 #define FIREHOSE_TRACE_ID_SET_NS(tid, ns) \
91 ((tid).ftid._namespace = firehose_tracepoint_namespace_##ns)
93 #define FIREHOSE_TRACE_ID_SET_TYPE(tid, ns, type) \
94 ((tid).ftid._type = _firehose_tracepoint_type_##ns##_##type)
96 #define FIREHOSE_TRACE_ID_HAS_FLAG(tid, ns, flag) \
97 ((tid).ftid._flags & _firehose_tracepoint_flags_##ns##_##flag)
98 #define FIREHOSE_TRACE_ID_SET_FLAG(tid, ns, flag) \
99 ((void)((tid).ftid._flags |= _firehose_tracepoint_flags_##ns##_##flag))
100 #define FIREHOSE_TRACE_ID_CLEAR_FLAG(tid, ns, flag) \
101 ((void)((tid).ftid._flags &= ~_firehose_tracepoint_flags_##ns##_##flag))
103 #define FIREHOSE_TRACE_ID_SET_CODE(tid, code) \
104 ((tid).ftid._code = code)
108 #if __has_feature(address_sanitizer)
109 __attribute__((no_sanitize("address")))
111 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
112 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
115 firehose_precise_timestamps_enabled(void)
118 return (atm_get_diagnostic_config() & 0x80) == 0;
120 return (*((volatile uint32_t *)_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG
) & 0x80) == 0;
124 #if __has_feature(address_sanitizer)
125 __attribute__((no_sanitize("address")))
127 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
128 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
130 static inline uint64_t
131 firehose_tracepoint_time(firehose_activity_flags_t flags
)
133 if (firehose_precise_timestamps_enabled() ||
134 (flags
& firehose_activity_flags_precise_timestamp
)) {
135 return mach_continuous_time();
137 return mach_continuous_approximate_time();
142 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
143 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
145 firehose_trace_metadata(firehose_stream_t stream
, firehose_tracepoint_id_u ftid
,
146 uint64_t stamp
, const void* pubdata
, size_t publen
);
150 OS_ASSUME_NONNULL_END
152 #endif // __FIREHOSE_FIREHOSE__