]>
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 | |
30 | #include "firehose_types_private.h" | |
31 | ||
32 | OS_ASSUME_NONNULL_BEGIN | |
33 | ||
34 | /*! | |
35 | * @typedef firehose_tracepoint_id_u | |
36 | * | |
37 | * @abstract | |
38 | * Broken down tracepoint identifier. | |
39 | */ | |
40 | typedef union { | |
41 | struct { | |
42 | firehose_tracepoint_namespace_t _namespace; | |
43 | firehose_tracepoint_type_t _type; | |
44 | firehose_tracepoint_flags_t _flags; | |
45 | uint32_t _code; | |
46 | } ftid; | |
47 | firehose_tracepoint_id_t ftid_value; | |
813fb2f6 | 48 | _Atomic(firehose_tracepoint_id_t) ftid_atomic_value; |
39037602 A |
49 | } firehose_tracepoint_id_u; |
50 | ||
51 | #define FIREHOSE_STAMP_SLOP (1ULL << 36) // ~1minute | |
52 | ||
53 | /*! | |
54 | * @typedef firehose_trace_uuid_info_t | |
55 | * | |
56 | * @abstract | |
57 | * Info needed by logd when kexts are loaded or unloaded | |
58 | * | |
59 | */ | |
60 | typedef struct firehose_trace_uuid_info_s { | |
61 | uuid_t ftui_uuid; /* uuid of binary */ | |
62 | uint64_t ftui_address; /* load address */ | |
63 | uint64_t ftui_size; /* load size */ | |
64 | char ftui_path[]; /* full path of binary - Unused in the kernel*/ | |
65 | } *firehose_trace_uuid_info_t; | |
66 | ||
67 | /*! | |
68 | * @typedef firehose_tracepoint_t | |
69 | */ | |
70 | typedef struct firehose_tracepoint_s { | |
71 | firehose_tracepoint_id_u ft_id; | |
72 | uint64_t ft_thread; | |
73 | union { | |
74 | struct { | |
75 | uint64_t ft_timestamp_delta : 48; | |
76 | uint64_t ft_length : 16; | |
77 | }; | |
78 | uint64_t ft_stamp_and_length; | |
813fb2f6 | 79 | _Atomic(uint64_t) ft_atomic_stamp_and_length; |
39037602 A |
80 | }; |
81 | uint8_t ft_data[]; | |
82 | } *firehose_tracepoint_t; | |
83 | ||
84 | #define FIREHOSE_TRACE_ID_MAKE(ns, type, flags, code) \ | |
85 | (((firehose_tracepoint_id_u){ .ftid = { \ | |
86 | ._namespace = ns, \ | |
87 | ._type = type, \ | |
88 | ._flags = flags, \ | |
89 | ._code = code, \ | |
90 | } }).ftid_value) | |
91 | ||
92 | #define FIREHOSE_TRACE_ID_SET_NS(tid, ns) \ | |
93 | ((tid).ftid._namespace = firehose_tracepoint_namespace_##ns) | |
94 | ||
95 | #define FIREHOSE_TRACE_ID_SET_TYPE(tid, ns, type) \ | |
96 | ((tid).ftid._type = _firehose_tracepoint_type_##ns##_##type) | |
97 | ||
813fb2f6 A |
98 | #define FIREHOSE_TRACE_ID_PC_STYLE(tid) \ |
99 | ((tid).ftid._flags & _firehose_tracepoint_flags_pc_style_mask) | |
100 | ||
101 | #define FIREHOSE_TRACE_ID_SET_PC_STYLE(tid, flag) ({ \ | |
102 | firehose_tracepoint_id_u _tmp_tid = (tid); \ | |
103 | _tmp_tid.ftid._flags &= ~_firehose_tracepoint_flags_pc_style_mask; \ | |
104 | _tmp_tid.ftid._flags |= _firehose_tracepoint_flags_pc_style_##flag; \ | |
105 | }) | |
106 | ||
39037602 A |
107 | #define FIREHOSE_TRACE_ID_HAS_FLAG(tid, ns, flag) \ |
108 | ((tid).ftid._flags & _firehose_tracepoint_flags_##ns##_##flag) | |
109 | #define FIREHOSE_TRACE_ID_SET_FLAG(tid, ns, flag) \ | |
110 | ((void)((tid).ftid._flags |= _firehose_tracepoint_flags_##ns##_##flag)) | |
111 | #define FIREHOSE_TRACE_ID_CLEAR_FLAG(tid, ns, flag) \ | |
112 | ((void)((tid).ftid._flags &= ~_firehose_tracepoint_flags_##ns##_##flag)) | |
113 | ||
114 | #define FIREHOSE_TRACE_ID_SET_CODE(tid, code) \ | |
115 | ((tid).ftid._code = code) | |
116 | ||
117 | __BEGIN_DECLS | |
118 | ||
119 | #if __has_feature(address_sanitizer) | |
120 | __attribute__((no_sanitize("address"))) | |
121 | #endif | |
122 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
123 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
124 | OS_ALWAYS_INLINE | |
125 | static inline bool | |
126 | firehose_precise_timestamps_enabled(void) | |
127 | { | |
128 | #if KERNEL | |
129 | return (atm_get_diagnostic_config() & 0x80) == 0; | |
130 | #else | |
131 | return (*((volatile uint32_t *)_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG) & 0x80) == 0; | |
132 | #endif | |
133 | } | |
134 | ||
135 | #if __has_feature(address_sanitizer) | |
136 | __attribute__((no_sanitize("address"))) | |
137 | #endif | |
138 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
139 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
140 | OS_ALWAYS_INLINE | |
141 | static inline uint64_t | |
142 | firehose_tracepoint_time(firehose_activity_flags_t flags) | |
143 | { | |
144 | if (firehose_precise_timestamps_enabled() || | |
145 | (flags & firehose_activity_flags_precise_timestamp)) { | |
146 | return mach_continuous_time(); | |
147 | } else { | |
148 | return mach_continuous_approximate_time(); | |
149 | } | |
150 | } | |
151 | ||
152 | #ifdef KERNEL | |
153 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) | |
154 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) | |
155 | void | |
156 | firehose_trace_metadata(firehose_stream_t stream, firehose_tracepoint_id_u ftid, | |
157 | uint64_t stamp, const void* pubdata, size_t publen); | |
158 | #endif | |
159 | __END_DECLS | |
160 | ||
161 | OS_ASSUME_NONNULL_END | |
162 | ||
163 | #endif // __FIREHOSE_FIREHOSE__ |