]>
Commit | Line | Data |
---|---|---|
39037602 A |
1 | /* |
2 | * Copyright (c) 2013-2016 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_APACHE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
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. | |
17 | * | |
18 | * @APPLE_APACHE_LICENSE_HEADER_END@ | |
19 | */ | |
20 | ||
21 | #ifndef __FIREHOSE_ACTIVITY__ | |
22 | #define __FIREHOSE_ACTIVITY__ | |
23 | ||
24 | #include <machine/cpu_capabilities.h> | |
25 | #include <mach/mach_time.h> | |
26 | #include <os/base.h> | |
27 | #if KERNEL | |
28 | #include <atm/atm_internal.h> | |
29 | #endif | |
c3c9b80d | 30 | #if __has_include(<os/atomic_private.h>) |
f427ee49 | 31 | #include <os/atomic_private.h> |
c3c9b80d A |
32 | #else |
33 | #include <os/internal/internal_shared.h> | |
34 | #endif | |
39037602 A |
35 | #include "firehose_types_private.h" |
36 | ||
37 | OS_ASSUME_NONNULL_BEGIN | |
38 | ||
39 | /*! | |
40 | * @typedef firehose_tracepoint_id_u | |
41 | * | |
42 | * @abstract | |
43 | * Broken down tracepoint identifier. | |
44 | */ | |
45 | typedef union { | |
46 | struct { | |
47 | firehose_tracepoint_namespace_t _namespace; | |
48 | firehose_tracepoint_type_t _type; | |
49 | firehose_tracepoint_flags_t _flags; | |
50 | uint32_t _code; | |
51 | } ftid; | |
52 | firehose_tracepoint_id_t ftid_value; | |
f427ee49 | 53 | os_atomic(firehose_tracepoint_id_t) ftid_atomic_value; |
39037602 A |
54 | } firehose_tracepoint_id_u; |
55 | ||
56 | #define FIREHOSE_STAMP_SLOP (1ULL << 36) // ~1minute | |
57 | ||
58 | /*! | |
59 | * @typedef firehose_trace_uuid_info_t | |
60 | * | |
61 | * @abstract | |
62 | * Info needed by logd when kexts are loaded or unloaded | |
63 | * | |
64 | */ | |
65 | typedef struct firehose_trace_uuid_info_s { | |
66 | uuid_t ftui_uuid; /* uuid of binary */ | |
67 | uint64_t ftui_address; /* load address */ | |
68 | uint64_t ftui_size; /* load size */ | |
69 | char ftui_path[]; /* full path of binary - Unused in the kernel*/ | |
70 | } *firehose_trace_uuid_info_t; | |
71 | ||
72 | /*! | |
73 | * @typedef firehose_tracepoint_t | |
74 | */ | |
75 | typedef struct firehose_tracepoint_s { | |
76 | firehose_tracepoint_id_u ft_id; | |
77 | uint64_t ft_thread; | |
78 | union { | |
79 | struct { | |
80 | uint64_t ft_timestamp_delta : 48; | |
81 | uint64_t ft_length : 16; | |
82 | }; | |
83 | uint64_t ft_stamp_and_length; | |
f427ee49 | 84 | os_atomic(uint64_t) ft_atomic_stamp_and_length; |
39037602 A |
85 | }; |
86 | uint8_t ft_data[]; | |
87 | } *firehose_tracepoint_t; | |
88 | ||
89 | #define FIREHOSE_TRACE_ID_MAKE(ns, type, flags, code) \ | |
90 | (((firehose_tracepoint_id_u){ .ftid = { \ | |
0a7de745 A |
91 | ._namespace = ns, \ |
92 | ._type = type, \ | |
93 | ._flags = flags, \ | |
94 | ._code = code, \ | |
39037602 A |
95 | } }).ftid_value) |
96 | ||
97 | #define FIREHOSE_TRACE_ID_SET_NS(tid, ns) \ | |
98 | ((tid).ftid._namespace = firehose_tracepoint_namespace_##ns) | |
99 | ||
100 | #define FIREHOSE_TRACE_ID_SET_TYPE(tid, ns, type) \ | |
101 | ((tid).ftid._type = _firehose_tracepoint_type_##ns##_##type) | |
102 | ||
813fb2f6 | 103 | #define FIREHOSE_TRACE_ID_PC_STYLE(tid) \ |
0a7de745 | 104 | ((tid).ftid._flags & _firehose_tracepoint_flags_pc_style_mask) |
813fb2f6 A |
105 | |
106 | #define FIREHOSE_TRACE_ID_SET_PC_STYLE(tid, flag) ({ \ | |
0a7de745 A |
107 | firehose_tracepoint_id_u _tmp_tid = (tid); \ |
108 | _tmp_tid.ftid._flags &= ~_firehose_tracepoint_flags_pc_style_mask; \ | |
109 | _tmp_tid.ftid._flags |= _firehose_tracepoint_flags_pc_style_##flag; \ | |
813fb2f6 A |
110 | }) |
111 | ||
39037602 A |
112 | #define FIREHOSE_TRACE_ID_HAS_FLAG(tid, ns, flag) \ |
113 | ((tid).ftid._flags & _firehose_tracepoint_flags_##ns##_##flag) | |
114 | #define FIREHOSE_TRACE_ID_SET_FLAG(tid, ns, flag) \ | |
115 | ((void)((tid).ftid._flags |= _firehose_tracepoint_flags_##ns##_##flag)) | |
116 | #define FIREHOSE_TRACE_ID_CLEAR_FLAG(tid, ns, flag) \ | |
117 | ((void)((tid).ftid._flags &= ~_firehose_tracepoint_flags_##ns##_##flag)) | |
118 | ||
119 | #define FIREHOSE_TRACE_ID_SET_CODE(tid, code) \ | |
120 | ((tid).ftid._code = code) | |
121 | ||
d9a64523 A |
122 | /*! |
123 | * @typedef firehose_loss_payload_s | |
124 | * | |
125 | * @abstract | |
126 | * The payload for tracepoints in the loss namespace, generated by the firehose | |
127 | * itself when unreliable tracepoints are lost. | |
128 | */ | |
129 | typedef struct firehose_loss_payload_s { | |
130 | uint64_t start_stamp; /* may (rarely!) disagree with the tracepoint stamp */ | |
131 | uint64_t end_stamp; | |
132 | #define FIREHOSE_LOSS_COUNT_WIDTH 6 /* as many bits as can be spared */ | |
133 | #define FIREHOSE_LOSS_COUNT_MAX ((1u << FIREHOSE_LOSS_COUNT_WIDTH) - 1) | |
134 | uint32_t count; | |
135 | } firehose_loss_payload_s, *firehose_loss_payload_t; | |
136 | ||
39037602 A |
137 | __BEGIN_DECLS |
138 | ||
139 | #if __has_feature(address_sanitizer) | |
140 | __attribute__((no_sanitize("address"))) | |
141 | #endif | |
142 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
143 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
144 | OS_ALWAYS_INLINE | |
145 | static inline bool | |
146 | firehose_precise_timestamps_enabled(void) | |
147 | { | |
148 | #if KERNEL | |
149 | return (atm_get_diagnostic_config() & 0x80) == 0; | |
150 | #else | |
151 | return (*((volatile uint32_t *)_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG) & 0x80) == 0; | |
152 | #endif | |
153 | } | |
154 | ||
155 | #if __has_feature(address_sanitizer) | |
156 | __attribute__((no_sanitize("address"))) | |
157 | #endif | |
158 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
159 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
160 | OS_ALWAYS_INLINE | |
161 | static inline uint64_t | |
162 | firehose_tracepoint_time(firehose_activity_flags_t flags) | |
163 | { | |
164 | if (firehose_precise_timestamps_enabled() || | |
0a7de745 | 165 | (flags & firehose_activity_flags_precise_timestamp)) { |
39037602 A |
166 | return mach_continuous_time(); |
167 | } else { | |
168 | return mach_continuous_approximate_time(); | |
169 | } | |
170 | } | |
171 | ||
172 | #ifdef KERNEL | |
173 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
174 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
175 | void | |
176 | firehose_trace_metadata(firehose_stream_t stream, firehose_tracepoint_id_u ftid, | |
0a7de745 | 177 | uint64_t stamp, const void* pubdata, size_t publen); |
39037602 A |
178 | #endif |
179 | __END_DECLS | |
180 | ||
0a7de745 | 181 | OS_ASSUME_NONNULL_END |
39037602 A |
182 | |
183 | #endif // __FIREHOSE_FIREHOSE__ |