1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions * Copyright (c) 2013-2015 Apple Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions *
4*bbb1b6f9SApple OSS Distributions * @APPLE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions *
6*bbb1b6f9SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions * compliance with the License. Please obtain a copy of the License at
10*bbb1b6f9SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this
11*bbb1b6f9SApple OSS Distributions * file.
12*bbb1b6f9SApple OSS Distributions *
13*bbb1b6f9SApple OSS Distributions * The Original Code and all software distributed under the License are
14*bbb1b6f9SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*bbb1b6f9SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*bbb1b6f9SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*bbb1b6f9SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*bbb1b6f9SApple OSS Distributions * Please see the License for the specific language governing rights and
19*bbb1b6f9SApple OSS Distributions * limitations under the License.
20*bbb1b6f9SApple OSS Distributions *
21*bbb1b6f9SApple OSS Distributions * @APPLE_LICENSE_HEADER_END@
22*bbb1b6f9SApple OSS Distributions */
23*bbb1b6f9SApple OSS Distributions
24*bbb1b6f9SApple OSS Distributions #ifndef __OS_TRACE_H__
25*bbb1b6f9SApple OSS Distributions #define __OS_TRACE_H__
26*bbb1b6f9SApple OSS Distributions
27*bbb1b6f9SApple OSS Distributions #include <Availability.h>
28*bbb1b6f9SApple OSS Distributions #include <os/base.h>
29*bbb1b6f9SApple OSS Distributions #include <sys/types.h>
30*bbb1b6f9SApple OSS Distributions #include <stdint.h>
31*bbb1b6f9SApple OSS Distributions #include <stdbool.h>
32*bbb1b6f9SApple OSS Distributions #include <stdarg.h>
33*bbb1b6f9SApple OSS Distributions #if __has_include(<xpc/xpc.h>)
34*bbb1b6f9SApple OSS Distributions #include <xpc/xpc.h>
35*bbb1b6f9SApple OSS Distributions #else
36*bbb1b6f9SApple OSS Distributions typedef void *xpc_object_t;
37*bbb1b6f9SApple OSS Distributions #endif
38*bbb1b6f9SApple OSS Distributions
39*bbb1b6f9SApple OSS Distributions #if !__GNUC__
40*bbb1b6f9SApple OSS Distributions #error "must be GNU C compatible"
41*bbb1b6f9SApple OSS Distributions #endif
42*bbb1b6f9SApple OSS Distributions
43*bbb1b6f9SApple OSS Distributions __BEGIN_DECLS
44*bbb1b6f9SApple OSS Distributions
45*bbb1b6f9SApple OSS Distributions extern void *__dso_handle;
46*bbb1b6f9SApple OSS Distributions
47*bbb1b6f9SApple OSS Distributions OS_ALWAYS_INLINE
48*bbb1b6f9SApple OSS Distributions static inline void
_os_trace_verify_printf(const char * msg,...)49*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(const char *msg, ...)
50*bbb1b6f9SApple OSS Distributions __attribute__((format(printf, 1, 2)))
51*bbb1b6f9SApple OSS Distributions {
52*bbb1b6f9SApple OSS Distributions #pragma unused(msg)
53*bbb1b6f9SApple OSS Distributions }
54*bbb1b6f9SApple OSS Distributions
55*bbb1b6f9SApple OSS Distributions #if !defined OS_COUNT_ARGS
56*bbb1b6f9SApple OSS Distributions #define OS_COUNT_ARGS(...) OS_COUNT_ARGS1(, ##__VA_ARGS__, _8, _7, _6, _5, _4, _3, _2, _1, _0)
57*bbb1b6f9SApple OSS Distributions #define OS_COUNT_ARGS1(z, a, b, c, d, e, f, g, h, cnt, ...) cnt
58*bbb1b6f9SApple OSS Distributions #endif
59*bbb1b6f9SApple OSS Distributions
60*bbb1b6f9SApple OSS Distributions /* use old macros for anything less than iOS 10 and MacOS 10.12 */
61*bbb1b6f9SApple OSS Distributions #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0) \
62*bbb1b6f9SApple OSS Distributions || (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_3_0) \
63*bbb1b6f9SApple OSS Distributions || (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED < __TVOS_10_0) \
64*bbb1b6f9SApple OSS Distributions || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12)
65*bbb1b6f9SApple OSS Distributions
66*bbb1b6f9SApple OSS Distributions #define _os_trace_0(_l, _m, _t) __extension__({ \
67*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l); \
68*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, NULL); \
69*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
70*bbb1b6f9SApple OSS Distributions })
71*bbb1b6f9SApple OSS Distributions
72*bbb1b6f9SApple OSS Distributions #define _os_trace_1(_l, _m, _t, _1) __extension__({ \
73*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
74*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
75*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
76*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1); \
77*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
78*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
79*bbb1b6f9SApple OSS Distributions uint8_t _s[1]; \
80*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
81*bbb1b6f9SApple OSS Distributions } _buf = { \
82*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
83*bbb1b6f9SApple OSS Distributions ._cnt = 1, \
84*bbb1b6f9SApple OSS Distributions }; \
85*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
86*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
87*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
88*bbb1b6f9SApple OSS Distributions })
89*bbb1b6f9SApple OSS Distributions
90*bbb1b6f9SApple OSS Distributions #define _os_trace_2(_l, _m, _t, _1, _2) __extension__({ \
91*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
92*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
93*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
94*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
95*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2); \
96*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
97*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
98*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
99*bbb1b6f9SApple OSS Distributions uint8_t _s[2]; \
100*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
101*bbb1b6f9SApple OSS Distributions } _buf = { \
102*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
103*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
104*bbb1b6f9SApple OSS Distributions ._cnt = 2, \
105*bbb1b6f9SApple OSS Distributions }; \
106*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
107*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
108*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
109*bbb1b6f9SApple OSS Distributions })
110*bbb1b6f9SApple OSS Distributions
111*bbb1b6f9SApple OSS Distributions #define _os_trace_3(_l, _m, _t, _1, _2, _3) __extension__({ \
112*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
113*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
114*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
115*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
116*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
117*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3); \
118*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
119*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
120*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
121*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
122*bbb1b6f9SApple OSS Distributions uint8_t _s[3]; \
123*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
124*bbb1b6f9SApple OSS Distributions } _buf = { \
125*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
126*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
127*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
128*bbb1b6f9SApple OSS Distributions ._cnt = 3, \
129*bbb1b6f9SApple OSS Distributions }; \
130*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
131*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
132*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
133*bbb1b6f9SApple OSS Distributions })
134*bbb1b6f9SApple OSS Distributions
135*bbb1b6f9SApple OSS Distributions #define _os_trace_4(_l, _m, _t, _1, _2, _3, _4) __extension__({ \
136*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
137*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
138*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
139*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
140*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
141*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
142*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \
143*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
144*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
145*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
146*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
147*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
148*bbb1b6f9SApple OSS Distributions uint8_t _s[4]; \
149*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
150*bbb1b6f9SApple OSS Distributions } _buf = { \
151*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
152*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
153*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
154*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
155*bbb1b6f9SApple OSS Distributions ._cnt = 4, \
156*bbb1b6f9SApple OSS Distributions }; \
157*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
158*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
159*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
160*bbb1b6f9SApple OSS Distributions })
161*bbb1b6f9SApple OSS Distributions
162*bbb1b6f9SApple OSS Distributions #define _os_trace_5(_l, _m, _t, _1, _2, _3, _4, _5) __extension__({ \
163*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
164*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
165*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
166*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
167*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
168*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
169*bbb1b6f9SApple OSS Distributions const __typeof__(_5) _c5 = _5; \
170*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \
171*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
172*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
173*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
174*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
175*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
176*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
177*bbb1b6f9SApple OSS Distributions uint8_t _s[5]; \
178*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
179*bbb1b6f9SApple OSS Distributions } _buf = { \
180*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
181*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
182*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
183*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
184*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
185*bbb1b6f9SApple OSS Distributions ._cnt = 5, \
186*bbb1b6f9SApple OSS Distributions }; \
187*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
188*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
189*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
190*bbb1b6f9SApple OSS Distributions })
191*bbb1b6f9SApple OSS Distributions
192*bbb1b6f9SApple OSS Distributions #define _os_trace_6(_l, _m, _t, _1, _2, _3, _4, _5, _6) __extension__({ \
193*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
194*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
195*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
196*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
197*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
198*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
199*bbb1b6f9SApple OSS Distributions const __typeof__(_5) _c5 = _5; \
200*bbb1b6f9SApple OSS Distributions const __typeof__(_6) _c6 = _6; \
201*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \
202*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
203*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
204*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
205*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
206*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
207*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
208*bbb1b6f9SApple OSS Distributions __typeof__(_c6) _f6; \
209*bbb1b6f9SApple OSS Distributions uint8_t _s[6]; \
210*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
211*bbb1b6f9SApple OSS Distributions } _buf = { \
212*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
213*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
214*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
215*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
216*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
217*bbb1b6f9SApple OSS Distributions ._f6 = _c6, ._s[5] = sizeof(_c6), \
218*bbb1b6f9SApple OSS Distributions ._cnt = 6, \
219*bbb1b6f9SApple OSS Distributions }; \
220*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
221*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
222*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
223*bbb1b6f9SApple OSS Distributions })
224*bbb1b6f9SApple OSS Distributions
225*bbb1b6f9SApple OSS Distributions #define _os_trace_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7) __extension__({ \
226*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
227*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
228*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
229*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
230*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
231*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
232*bbb1b6f9SApple OSS Distributions const __typeof__(_5) _c5 = _5; \
233*bbb1b6f9SApple OSS Distributions const __typeof__(_6) _c6 = _6; \
234*bbb1b6f9SApple OSS Distributions const __typeof__(_7) _c7 = _7; \
235*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \
236*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
237*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
238*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
239*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
240*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
241*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
242*bbb1b6f9SApple OSS Distributions __typeof__(_c6) _f6; \
243*bbb1b6f9SApple OSS Distributions __typeof__(_c7) _f7; \
244*bbb1b6f9SApple OSS Distributions uint8_t _s[7]; \
245*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
246*bbb1b6f9SApple OSS Distributions } _buf = { \
247*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
248*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
249*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
250*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
251*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
252*bbb1b6f9SApple OSS Distributions ._f6 = _c6, ._s[5] = sizeof(_c6), \
253*bbb1b6f9SApple OSS Distributions ._f7 = _c7, ._s[6] = sizeof(_c7), \
254*bbb1b6f9SApple OSS Distributions ._cnt = 7, \
255*bbb1b6f9SApple OSS Distributions }; \
256*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
257*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
258*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
259*bbb1b6f9SApple OSS Distributions })
260*bbb1b6f9SApple OSS Distributions
261*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \
262*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l); \
263*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, _payload); \
264*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
265*bbb1b6f9SApple OSS Distributions })
266*bbb1b6f9SApple OSS Distributions
267*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \
268*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
269*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
270*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
271*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1); \
272*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
273*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
274*bbb1b6f9SApple OSS Distributions uint8_t _s[1]; \
275*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
276*bbb1b6f9SApple OSS Distributions } _buf = { \
277*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
278*bbb1b6f9SApple OSS Distributions ._cnt = 1, \
279*bbb1b6f9SApple OSS Distributions }; \
280*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
281*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
282*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
283*bbb1b6f9SApple OSS Distributions })
284*bbb1b6f9SApple OSS Distributions
285*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \
286*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
287*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
288*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
289*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
290*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2); \
291*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
292*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
293*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
294*bbb1b6f9SApple OSS Distributions uint8_t _s[2]; \
295*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
296*bbb1b6f9SApple OSS Distributions } _buf = { \
297*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
298*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
299*bbb1b6f9SApple OSS Distributions ._cnt = 2, \
300*bbb1b6f9SApple OSS Distributions }; \
301*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
302*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
303*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
304*bbb1b6f9SApple OSS Distributions })
305*bbb1b6f9SApple OSS Distributions
306*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \
307*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
308*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
309*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
310*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
311*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
312*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3); \
313*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
314*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
315*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
316*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
317*bbb1b6f9SApple OSS Distributions uint8_t _s[3]; \
318*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
319*bbb1b6f9SApple OSS Distributions } _buf = { \
320*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
321*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
322*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
323*bbb1b6f9SApple OSS Distributions ._cnt = 3, \
324*bbb1b6f9SApple OSS Distributions }; \
325*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
326*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
327*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
328*bbb1b6f9SApple OSS Distributions })
329*bbb1b6f9SApple OSS Distributions
330*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \
331*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
332*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
333*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
334*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
335*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
336*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
337*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \
338*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
339*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
340*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
341*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
342*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
343*bbb1b6f9SApple OSS Distributions uint8_t _s[4]; \
344*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
345*bbb1b6f9SApple OSS Distributions } _buf = { \
346*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
347*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
348*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
349*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
350*bbb1b6f9SApple OSS Distributions ._cnt = 4, \
351*bbb1b6f9SApple OSS Distributions }; \
352*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
353*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
354*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
355*bbb1b6f9SApple OSS Distributions })
356*bbb1b6f9SApple OSS Distributions
357*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \
358*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
359*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
360*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
361*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
362*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
363*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
364*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c5 = _5; \
365*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \
366*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
367*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
368*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
369*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
370*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
371*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
372*bbb1b6f9SApple OSS Distributions uint8_t _s[5]; \
373*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
374*bbb1b6f9SApple OSS Distributions } _buf = { \
375*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
376*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
377*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
378*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
379*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
380*bbb1b6f9SApple OSS Distributions ._cnt = 5, \
381*bbb1b6f9SApple OSS Distributions }; \
382*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
383*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
384*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
385*bbb1b6f9SApple OSS Distributions })
386*bbb1b6f9SApple OSS Distributions
387*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \
388*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
389*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
390*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
391*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
392*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
393*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
394*bbb1b6f9SApple OSS Distributions const __typeof__(_5) _c5 = _5; \
395*bbb1b6f9SApple OSS Distributions const __typeof__(_6) _c6 = _6; \
396*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \
397*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
398*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
399*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
400*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
401*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
402*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
403*bbb1b6f9SApple OSS Distributions __typeof__(_c6) _f6; \
404*bbb1b6f9SApple OSS Distributions uint8_t _s[6]; \
405*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
406*bbb1b6f9SApple OSS Distributions } _buf = { \
407*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
408*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
409*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
410*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
411*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
412*bbb1b6f9SApple OSS Distributions ._f6 = _c6, ._s[5] = sizeof(_c6), \
413*bbb1b6f9SApple OSS Distributions ._cnt = 6, \
414*bbb1b6f9SApple OSS Distributions }; \
415*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
416*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
417*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
418*bbb1b6f9SApple OSS Distributions })
419*bbb1b6f9SApple OSS Distributions
420*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \
421*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
422*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wpacked\"") \
423*bbb1b6f9SApple OSS Distributions const __typeof__(_1) _c1 = _1; \
424*bbb1b6f9SApple OSS Distributions const __typeof__(_2) _c2 = _2; \
425*bbb1b6f9SApple OSS Distributions const __typeof__(_3) _c3 = _3; \
426*bbb1b6f9SApple OSS Distributions const __typeof__(_4) _c4 = _4; \
427*bbb1b6f9SApple OSS Distributions const __typeof__(_5) _c5 = _5; \
428*bbb1b6f9SApple OSS Distributions const __typeof__(_6) _c6 = _6; \
429*bbb1b6f9SApple OSS Distributions const __typeof__(_7) _c7 = _7; \
430*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \
431*bbb1b6f9SApple OSS Distributions const struct __attribute__((packed)) { \
432*bbb1b6f9SApple OSS Distributions __typeof__(_c1) _f1; \
433*bbb1b6f9SApple OSS Distributions __typeof__(_c2) _f2; \
434*bbb1b6f9SApple OSS Distributions __typeof__(_c3) _f3; \
435*bbb1b6f9SApple OSS Distributions __typeof__(_c4) _f4; \
436*bbb1b6f9SApple OSS Distributions __typeof__(_c5) _f5; \
437*bbb1b6f9SApple OSS Distributions __typeof__(_c6) _f6; \
438*bbb1b6f9SApple OSS Distributions __typeof__(_c7) _f7; \
439*bbb1b6f9SApple OSS Distributions uint8_t _s[7]; \
440*bbb1b6f9SApple OSS Distributions uint8_t _cnt; \
441*bbb1b6f9SApple OSS Distributions } _buf = { \
442*bbb1b6f9SApple OSS Distributions ._f1 = _c1, ._s[0] = sizeof(_c1), \
443*bbb1b6f9SApple OSS Distributions ._f2 = _c2, ._s[1] = sizeof(_c2), \
444*bbb1b6f9SApple OSS Distributions ._f3 = _c3, ._s[2] = sizeof(_c3), \
445*bbb1b6f9SApple OSS Distributions ._f4 = _c4, ._s[3] = sizeof(_c4), \
446*bbb1b6f9SApple OSS Distributions ._f5 = _c5, ._s[4] = sizeof(_c5), \
447*bbb1b6f9SApple OSS Distributions ._f6 = _c6, ._s[5] = sizeof(_c6), \
448*bbb1b6f9SApple OSS Distributions ._f7 = _c7, ._s[6] = sizeof(_c7), \
449*bbb1b6f9SApple OSS Distributions ._cnt = 7, \
450*bbb1b6f9SApple OSS Distributions }; \
451*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
452*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
453*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
454*bbb1b6f9SApple OSS Distributions })
455*bbb1b6f9SApple OSS Distributions
456*bbb1b6f9SApple OSS Distributions #define OS_TRACE_CALL(format, _m, _t, ...) __extension__({ \
457*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic push") \
458*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \
459*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, _t, ##__VA_ARGS__); \
460*bbb1b6f9SApple OSS Distributions _Pragma("clang diagnostic pop") \
461*bbb1b6f9SApple OSS Distributions })
462*bbb1b6f9SApple OSS Distributions
463*bbb1b6f9SApple OSS Distributions #else
464*bbb1b6f9SApple OSS Distributions
465*bbb1b6f9SApple OSS Distributions // Use a new layout in Mac OS 10.12+ and iOS 10.0+
466*bbb1b6f9SApple OSS Distributions #define OS_TRACE_CALL(_l, _m, _t, ...) __extension__({ \
467*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
468*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, ##__VA_ARGS__); \
469*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, ##__VA_ARGS__); \
470*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, NULL); \
471*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
472*bbb1b6f9SApple OSS Distributions })
473*bbb1b6f9SApple OSS Distributions
474*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \
475*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l); \
476*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, NULL, 0, _payload); \
477*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
478*bbb1b6f9SApple OSS Distributions })
479*bbb1b6f9SApple OSS Distributions
480*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \
481*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1); \
482*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
483*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1); \
484*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
485*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
486*bbb1b6f9SApple OSS Distributions })
487*bbb1b6f9SApple OSS Distributions
488*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \
489*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2); \
490*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
491*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2); \
492*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
493*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
494*bbb1b6f9SApple OSS Distributions })
495*bbb1b6f9SApple OSS Distributions
496*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \
497*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2, _3); \
498*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
499*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3); \
500*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
501*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
502*bbb1b6f9SApple OSS Distributions })
503*bbb1b6f9SApple OSS Distributions
504*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \
505*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2, _3, _4); \
506*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
507*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4); \
508*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
509*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
510*bbb1b6f9SApple OSS Distributions })
511*bbb1b6f9SApple OSS Distributions
512*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \
513*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2, _3, _4, _5); \
514*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
515*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5); \
516*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
517*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
518*bbb1b6f9SApple OSS Distributions })
519*bbb1b6f9SApple OSS Distributions
520*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \
521*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6); \
522*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
523*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6); \
524*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
525*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
526*bbb1b6f9SApple OSS Distributions })
527*bbb1b6f9SApple OSS Distributions
528*bbb1b6f9SApple OSS Distributions #define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \
529*bbb1b6f9SApple OSS Distributions _os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6, _7); \
530*bbb1b6f9SApple OSS Distributions uint8_t buf[1024]; \
531*bbb1b6f9SApple OSS Distributions size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6, _7); \
532*bbb1b6f9SApple OSS Distributions _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
533*bbb1b6f9SApple OSS Distributions __asm__(""); /* avoid tailcall */ \
534*bbb1b6f9SApple OSS Distributions })
535*bbb1b6f9SApple OSS Distributions
536*bbb1b6f9SApple OSS Distributions #endif /* if Mac OS >= 10.12 or iPhone OS >= 10.0 */
537*bbb1b6f9SApple OSS Distributions
538*bbb1b6f9SApple OSS Distributions /*!
539*bbb1b6f9SApple OSS Distributions *
540*bbb1b6f9SApple OSS Distributions * @abstract
541*bbb1b6f9SApple OSS Distributions * Hashtags in trace messages
542*bbb1b6f9SApple OSS Distributions *
543*bbb1b6f9SApple OSS Distributions * @discussion
544*bbb1b6f9SApple OSS Distributions * Developers are encouraged to include hashtags in log messages, regardless of what API you use.
545*bbb1b6f9SApple OSS Distributions * A hashtag is composed of a hash (#) symbol, followed by at least three non-whitespace characters,
546*bbb1b6f9SApple OSS Distributions * terminated by whitespace or the end of the message. Hashtags may not begin with a number.
547*bbb1b6f9SApple OSS Distributions *
548*bbb1b6f9SApple OSS Distributions * Below is the list of predefined tags:
549*bbb1b6f9SApple OSS Distributions * #System - Message in the context of a system process.
550*bbb1b6f9SApple OSS Distributions * #User - Message in the context of a user process.
551*bbb1b6f9SApple OSS Distributions * #Developer - Message in the context of software development. For example, deprecated APIs and debugging messages.
552*bbb1b6f9SApple OSS Distributions * #Attention - Message that should be investigated by a system administrator, because it may be a sign of a larger issue.
553*bbb1b6f9SApple OSS Distributions * For example, errors from a hard drive controller that typically occur when the drive is about to fail.
554*bbb1b6f9SApple OSS Distributions * #Critical - Message in the context of a critical event or critical failure.
555*bbb1b6f9SApple OSS Distributions * #Error - Message that is a noncritical error.
556*bbb1b6f9SApple OSS Distributions * #Comment - Message that is a comment.
557*bbb1b6f9SApple OSS Distributions * #Marker - Message that marks a change to divide the messages around it into those before and those after the change.
558*bbb1b6f9SApple OSS Distributions * #Clue - Message containing extra key/value pairs with additional information to help reconstruct the context.
559*bbb1b6f9SApple OSS Distributions * #Security - Message related to security concerns.
560*bbb1b6f9SApple OSS Distributions * #Filesystem - Message describing a file system related event.
561*bbb1b6f9SApple OSS Distributions * #Network - Message describing a network-related event.
562*bbb1b6f9SApple OSS Distributions * #Hardware - Message describing a hardware-related event.
563*bbb1b6f9SApple OSS Distributions * #CPU - Message describing CPU related event, e.g., initiating heavy work load
564*bbb1b6f9SApple OSS Distributions * #State - Message describing state changed, e.g., global state, preference, etc.
565*bbb1b6f9SApple OSS Distributions * #Graphics - Message describing significant graphics event
566*bbb1b6f9SApple OSS Distributions * #Disk - Message describing disk activity
567*bbb1b6f9SApple OSS Distributions *
568*bbb1b6f9SApple OSS Distributions */
569*bbb1b6f9SApple OSS Distributions
570*bbb1b6f9SApple OSS Distributions #pragma mark - Other defines
571*bbb1b6f9SApple OSS Distributions
572*bbb1b6f9SApple OSS Distributions /*!
573*bbb1b6f9SApple OSS Distributions * @define OS_TRACE_TYPE_RELEASE
574*bbb1b6f9SApple OSS Distributions * Trace messages to be captured on a typical user install. These should be
575*bbb1b6f9SApple OSS Distributions * limited to things which improve diagnosis of a failure/crash/hang. Trace
576*bbb1b6f9SApple OSS Distributions * buffers are generally smaller on a production system.
577*bbb1b6f9SApple OSS Distributions */
578*bbb1b6f9SApple OSS Distributions #define OS_TRACE_TYPE_RELEASE (1u << 0)
579*bbb1b6f9SApple OSS Distributions
580*bbb1b6f9SApple OSS Distributions /*!
581*bbb1b6f9SApple OSS Distributions * @define OS_TRACE_TYPE_DEBUG
582*bbb1b6f9SApple OSS Distributions * Trace messages to be captured while debugger or other development tool is
583*bbb1b6f9SApple OSS Distributions * attached to the originator.
584*bbb1b6f9SApple OSS Distributions */
585*bbb1b6f9SApple OSS Distributions #define OS_TRACE_TYPE_DEBUG (1u << 1)
586*bbb1b6f9SApple OSS Distributions
587*bbb1b6f9SApple OSS Distributions /*!
588*bbb1b6f9SApple OSS Distributions * @define OS_TRACE_TYPE_INFO
589*bbb1b6f9SApple OSS Distributions * Trace messages that are captured when a debugger is attached, system or
590*bbb1b6f9SApple OSS Distributions * Application mode has been increased to include additional information.
591*bbb1b6f9SApple OSS Distributions */
592*bbb1b6f9SApple OSS Distributions #define OS_TRACE_TYPE_INFO (1u << 2)
593*bbb1b6f9SApple OSS Distributions
594*bbb1b6f9SApple OSS Distributions /*!
595*bbb1b6f9SApple OSS Distributions * @define OS_TRACE_TYPE_ERROR
596*bbb1b6f9SApple OSS Distributions * Trace the message as an error and force a collection as a failure may be
597*bbb1b6f9SApple OSS Distributions * imminent.
598*bbb1b6f9SApple OSS Distributions */
599*bbb1b6f9SApple OSS Distributions #define OS_TRACE_TYPE_ERROR ((1u << 6) | (1u << 0))
600*bbb1b6f9SApple OSS Distributions
601*bbb1b6f9SApple OSS Distributions /*!
602*bbb1b6f9SApple OSS Distributions * @define OS_TRACE_TYPE_FAULT
603*bbb1b6f9SApple OSS Distributions * Trace the message as a fatal error which forces a collection and a diagnostic
604*bbb1b6f9SApple OSS Distributions * to be initiated.
605*bbb1b6f9SApple OSS Distributions */
606*bbb1b6f9SApple OSS Distributions #define OS_TRACE_TYPE_FAULT ((1u << 7) | (1u << 6) | (1u << 0))
607*bbb1b6f9SApple OSS Distributions
608*bbb1b6f9SApple OSS Distributions /*!
609*bbb1b6f9SApple OSS Distributions * @typedef os_trace_payload_t
610*bbb1b6f9SApple OSS Distributions * A block that populates an xpc_object_t of type XPC_TYPE_DICTIONARY to represent
611*bbb1b6f9SApple OSS Distributions * complex data. This block will only be invoked under conditions where tools
612*bbb1b6f9SApple OSS Distributions * have attached to the process. The payload can be used to send arbitrary data
613*bbb1b6f9SApple OSS Distributions * via the trace call. Tools may use the data to validate state for integration
614*bbb1b6f9SApple OSS Distributions * tests or provide other introspection services. No assumptions are made about
615*bbb1b6f9SApple OSS Distributions * the format or structure of the data.
616*bbb1b6f9SApple OSS Distributions */
617*bbb1b6f9SApple OSS Distributions typedef void (^os_trace_payload_t)(xpc_object_t xdict);
618*bbb1b6f9SApple OSS Distributions
619*bbb1b6f9SApple OSS Distributions #pragma mark - function declarations
620*bbb1b6f9SApple OSS Distributions
621*bbb1b6f9SApple OSS Distributions /*!
622*bbb1b6f9SApple OSS Distributions * @function os_trace
623*bbb1b6f9SApple OSS Distributions *
624*bbb1b6f9SApple OSS Distributions * @abstract
625*bbb1b6f9SApple OSS Distributions * Always inserts a trace message into a buffer pool for later decoding.
626*bbb1b6f9SApple OSS Distributions *
627*bbb1b6f9SApple OSS Distributions * @discussion
628*bbb1b6f9SApple OSS Distributions * Trace message that will be recorded on a typical user install. These should
629*bbb1b6f9SApple OSS Distributions * be limited to things which help diagnose a failure during postmortem
630*bbb1b6f9SApple OSS Distributions * analysis. Trace buffers are generally smaller on a production system.
631*bbb1b6f9SApple OSS Distributions *
632*bbb1b6f9SApple OSS Distributions * @param format
633*bbb1b6f9SApple OSS Distributions * A printf-style format string to generate a human-readable log message when
634*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported, attempts
635*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
636*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
637*bbb1b6f9SApple OSS Distributions *
638*bbb1b6f9SApple OSS Distributions * os_trace("network event: %ld, last seen: %ld, avg: %g", event_id, last_seen, avg);
639*bbb1b6f9SApple OSS Distributions */
640*bbb1b6f9SApple OSS Distributions #define os_trace(format, ...) __extension__({ \
641*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
642*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
643*bbb1b6f9SApple OSS Distributions OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \
644*bbb1b6f9SApple OSS Distributions })
645*bbb1b6f9SApple OSS Distributions
646*bbb1b6f9SApple OSS Distributions
647*bbb1b6f9SApple OSS Distributions #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_10_0) \
648*bbb1b6f9SApple OSS Distributions || (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED >= __WATCHOS_3_0) \
649*bbb1b6f9SApple OSS Distributions || (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED >= __TVOS_10_0) \
650*bbb1b6f9SApple OSS Distributions || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12)
651*bbb1b6f9SApple OSS Distributions
652*bbb1b6f9SApple OSS Distributions /*!
653*bbb1b6f9SApple OSS Distributions * @function os_trace_info
654*bbb1b6f9SApple OSS Distributions *
655*bbb1b6f9SApple OSS Distributions * @abstract
656*bbb1b6f9SApple OSS Distributions * Optionally inserts a trace message containing additional information into a
657*bbb1b6f9SApple OSS Distributions * buffer pool for later decoding.
658*bbb1b6f9SApple OSS Distributions *
659*bbb1b6f9SApple OSS Distributions * @discussion
660*bbb1b6f9SApple OSS Distributions * Trace messages that will be captured when additional information is needed
661*bbb1b6f9SApple OSS Distributions * and are not captured by default. They will only be captured if the
662*bbb1b6f9SApple OSS Distributions * system/process/activity mode has been increased or if a Development tool has
663*bbb1b6f9SApple OSS Distributions * been attached to the process.
664*bbb1b6f9SApple OSS Distributions *
665*bbb1b6f9SApple OSS Distributions * @param format
666*bbb1b6f9SApple OSS Distributions * A printf-style format string that represents a human-readable message when
667*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported, attempts
668*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
669*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
670*bbb1b6f9SApple OSS Distributions *
671*bbb1b6f9SApple OSS Distributions * os_trace_info("network interface status %ld", status);
672*bbb1b6f9SApple OSS Distributions */
673*bbb1b6f9SApple OSS Distributions #define os_trace_info(format, ...) __extension__({ \
674*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
675*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
676*bbb1b6f9SApple OSS Distributions OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \
677*bbb1b6f9SApple OSS Distributions })
678*bbb1b6f9SApple OSS Distributions
679*bbb1b6f9SApple OSS Distributions #endif
680*bbb1b6f9SApple OSS Distributions
681*bbb1b6f9SApple OSS Distributions /*!
682*bbb1b6f9SApple OSS Distributions * @function os_trace_debug
683*bbb1b6f9SApple OSS Distributions *
684*bbb1b6f9SApple OSS Distributions * @abstract
685*bbb1b6f9SApple OSS Distributions * Insert debug trace message into a buffer pool for later decoding.
686*bbb1b6f9SApple OSS Distributions *
687*bbb1b6f9SApple OSS Distributions * @discussion
688*bbb1b6f9SApple OSS Distributions * Debug trace message to be recorded while debugger or other development tool is
689*bbb1b6f9SApple OSS Distributions * attached to the originator. This is transported interprocess to help
690*bbb1b6f9SApple OSS Distributions * diagnose the entire call chain including external helpers.
691*bbb1b6f9SApple OSS Distributions *
692*bbb1b6f9SApple OSS Distributions * @param format
693*bbb1b6f9SApple OSS Distributions * A printf-style format string that represents a human-readable message when
694*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported, attempts
695*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
696*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
697*bbb1b6f9SApple OSS Distributions *
698*bbb1b6f9SApple OSS Distributions * os_trace_debug("network interface status %ld", status);
699*bbb1b6f9SApple OSS Distributions */
700*bbb1b6f9SApple OSS Distributions #define os_trace_debug(format, ...) __extension__({ \
701*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
702*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
703*bbb1b6f9SApple OSS Distributions OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
704*bbb1b6f9SApple OSS Distributions })
705*bbb1b6f9SApple OSS Distributions
706*bbb1b6f9SApple OSS Distributions /*!
707*bbb1b6f9SApple OSS Distributions * @function os_trace_info_enabled
708*bbb1b6f9SApple OSS Distributions *
709*bbb1b6f9SApple OSS Distributions * @abstract
710*bbb1b6f9SApple OSS Distributions * Avoid unnecessary work for a trace point by checking if additional information
711*bbb1b6f9SApple OSS Distributions * is enabled.
712*bbb1b6f9SApple OSS Distributions *
713*bbb1b6f9SApple OSS Distributions * @discussion
714*bbb1b6f9SApple OSS Distributions * Avoid unnecessary work for a trace point by checking if additional information
715*bbb1b6f9SApple OSS Distributions * is enabled. Generally trace points should not involve expensive operations, but some
716*bbb1b6f9SApple OSS Distributions * circumstances warrant it. Use this function to avoid doing the work unless
717*bbb1b6f9SApple OSS Distributions * debug level trace messages are requested.
718*bbb1b6f9SApple OSS Distributions *
719*bbb1b6f9SApple OSS Distributions * if (os_trace_info_enabled()) {
720*bbb1b6f9SApple OSS Distributions * os_trace_info("value = %d, average = %d",
721*bbb1b6f9SApple OSS Distributions * [[dict objectForKey: @"myKey"] intValue],
722*bbb1b6f9SApple OSS Distributions * (int) [self getAverage: dict]);
723*bbb1b6f9SApple OSS Distributions * }
724*bbb1b6f9SApple OSS Distributions *
725*bbb1b6f9SApple OSS Distributions * @result
726*bbb1b6f9SApple OSS Distributions * Returns true if development mode is enabled.
727*bbb1b6f9SApple OSS Distributions */
728*bbb1b6f9SApple OSS Distributions __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
729*bbb1b6f9SApple OSS Distributions OS_EXPORT OS_NOTHROW OS_WARN_RESULT
730*bbb1b6f9SApple OSS Distributions bool
731*bbb1b6f9SApple OSS Distributions os_trace_info_enabled(void);
732*bbb1b6f9SApple OSS Distributions
733*bbb1b6f9SApple OSS Distributions /*!
734*bbb1b6f9SApple OSS Distributions * @function os_trace_debug_enabled
735*bbb1b6f9SApple OSS Distributions *
736*bbb1b6f9SApple OSS Distributions * @abstract
737*bbb1b6f9SApple OSS Distributions * Avoid unnecessary work for a trace point by checking if debug level is enabled.
738*bbb1b6f9SApple OSS Distributions *
739*bbb1b6f9SApple OSS Distributions * @discussion
740*bbb1b6f9SApple OSS Distributions * Avoid unnecessary work for a trace point by checking if debug level is enabled.
741*bbb1b6f9SApple OSS Distributions * Generally trace points should not involve expensive operations, but some
742*bbb1b6f9SApple OSS Distributions * circumstances warrant it. Use this function to avoid doing the work unless
743*bbb1b6f9SApple OSS Distributions * debug level trace messages are requested.
744*bbb1b6f9SApple OSS Distributions *
745*bbb1b6f9SApple OSS Distributions * if (os_trace_debug_enabled()) {
746*bbb1b6f9SApple OSS Distributions * os_trace_debug("value = %d, average = %d",
747*bbb1b6f9SApple OSS Distributions * [[dict objectForKey: @"myKey"] intValue],
748*bbb1b6f9SApple OSS Distributions * (int) [self getAverage: dict]);
749*bbb1b6f9SApple OSS Distributions * }
750*bbb1b6f9SApple OSS Distributions *
751*bbb1b6f9SApple OSS Distributions * @result
752*bbb1b6f9SApple OSS Distributions * Returns true if debug mode is enabled.
753*bbb1b6f9SApple OSS Distributions */
754*bbb1b6f9SApple OSS Distributions __OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0)
755*bbb1b6f9SApple OSS Distributions OS_EXPORT OS_NOTHROW OS_WARN_RESULT
756*bbb1b6f9SApple OSS Distributions bool
757*bbb1b6f9SApple OSS Distributions os_trace_debug_enabled(void);
758*bbb1b6f9SApple OSS Distributions
759*bbb1b6f9SApple OSS Distributions /*!
760*bbb1b6f9SApple OSS Distributions * @function os_trace_error
761*bbb1b6f9SApple OSS Distributions *
762*bbb1b6f9SApple OSS Distributions * @abstract
763*bbb1b6f9SApple OSS Distributions * Trace the message as an error and force a collection of the trace buffer as a
764*bbb1b6f9SApple OSS Distributions * failure may be imminent.
765*bbb1b6f9SApple OSS Distributions *
766*bbb1b6f9SApple OSS Distributions * @discussion
767*bbb1b6f9SApple OSS Distributions * Trace the message as an error and force a collection of the trace buffer as a
768*bbb1b6f9SApple OSS Distributions * failure may be imminent.
769*bbb1b6f9SApple OSS Distributions *
770*bbb1b6f9SApple OSS Distributions * @param format
771*bbb1b6f9SApple OSS Distributions * A printf-style format string to generate a human-readable log message when
772*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported, attempts
773*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
774*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
775*bbb1b6f9SApple OSS Distributions *
776*bbb1b6f9SApple OSS Distributions * os_trace_error("socket %d connection timeout %ld", fd, secs);
777*bbb1b6f9SApple OSS Distributions */
778*bbb1b6f9SApple OSS Distributions #define os_trace_error(format, ...) __extension__({ \
779*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
780*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
781*bbb1b6f9SApple OSS Distributions OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \
782*bbb1b6f9SApple OSS Distributions })
783*bbb1b6f9SApple OSS Distributions
784*bbb1b6f9SApple OSS Distributions /*!
785*bbb1b6f9SApple OSS Distributions * @function os_trace_fault
786*bbb1b6f9SApple OSS Distributions *
787*bbb1b6f9SApple OSS Distributions * @abstract
788*bbb1b6f9SApple OSS Distributions * Trace the message as a fault which forces a collection of the trace buffer
789*bbb1b6f9SApple OSS Distributions * and diagnostic of the activity.
790*bbb1b6f9SApple OSS Distributions *
791*bbb1b6f9SApple OSS Distributions * @discussion
792*bbb1b6f9SApple OSS Distributions * Trace the message as a fault which forces a collection of the trace buffer
793*bbb1b6f9SApple OSS Distributions * and diagnostic of the activity.
794*bbb1b6f9SApple OSS Distributions *
795*bbb1b6f9SApple OSS Distributions * @param format
796*bbb1b6f9SApple OSS Distributions * A printf-style format string to generate a human-readable log message when
797*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported, attempts
798*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
799*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
800*bbb1b6f9SApple OSS Distributions *
801*bbb1b6f9SApple OSS Distributions * os_trace_fault("failed to lookup uid %d - aborting", uid);
802*bbb1b6f9SApple OSS Distributions */
803*bbb1b6f9SApple OSS Distributions #define os_trace_fault(format, ...) __extension__({ \
804*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
805*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
806*bbb1b6f9SApple OSS Distributions OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \
807*bbb1b6f9SApple OSS Distributions })
808*bbb1b6f9SApple OSS Distributions
809*bbb1b6f9SApple OSS Distributions #if __has_include(<xpc/xpc.h>)
810*bbb1b6f9SApple OSS Distributions /*!
811*bbb1b6f9SApple OSS Distributions * @function os_trace_with_payload
812*bbb1b6f9SApple OSS Distributions *
813*bbb1b6f9SApple OSS Distributions * @abstract
814*bbb1b6f9SApple OSS Distributions * Add a trace entry containing the provided values and call the block if
815*bbb1b6f9SApple OSS Distributions * appropriate.
816*bbb1b6f9SApple OSS Distributions *
817*bbb1b6f9SApple OSS Distributions * @discussion
818*bbb1b6f9SApple OSS Distributions * Will insert a trace entry into a limited ring buffer for an activity or
819*bbb1b6f9SApple OSS Distributions * process. Trace points are for recording interesting data that would improve
820*bbb1b6f9SApple OSS Distributions * diagnosis of unexpected crashes, failures and hangs. The block will only be
821*bbb1b6f9SApple OSS Distributions * called under the required conditions.
822*bbb1b6f9SApple OSS Distributions *
823*bbb1b6f9SApple OSS Distributions * @param trace_msg
824*bbb1b6f9SApple OSS Distributions * A printf-style format string to generate a human-readable log message when
825*bbb1b6f9SApple OSS Distributions * the trace line is decoded. Only scalar types are supported. Attempts
826*bbb1b6f9SApple OSS Distributions * to pass arbitrary strings will store a pointer that is unresolvable and
827*bbb1b6f9SApple OSS Distributions * will generate an error during decode.
828*bbb1b6f9SApple OSS Distributions *
829*bbb1b6f9SApple OSS Distributions * The final parameter must be a block of type os_trace_payload_t.
830*bbb1b6f9SApple OSS Distributions *
831*bbb1b6f9SApple OSS Distributions * os_trace_with_payload("network event %ld", event, ^(xpc_object_t xdict) {
832*bbb1b6f9SApple OSS Distributions *
833*bbb1b6f9SApple OSS Distributions * // validate the network interface and address where what was expected
834*bbb1b6f9SApple OSS Distributions * xpc_dictionary_set_string(xdict, "network", ifp->ifa_name);
835*bbb1b6f9SApple OSS Distributions * xpc_dictionary_set_string(xdict, "ip_address", _get_address(ifp));
836*bbb1b6f9SApple OSS Distributions * });
837*bbb1b6f9SApple OSS Distributions */
838*bbb1b6f9SApple OSS Distributions #define os_trace_with_payload(format, ...) __extension__({ \
839*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
840*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
841*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \
842*bbb1b6f9SApple OSS Distributions })
843*bbb1b6f9SApple OSS Distributions
844*bbb1b6f9SApple OSS Distributions #define os_trace_info_with_payload(format, ...) __extension__({ \
845*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
846*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
847*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \
848*bbb1b6f9SApple OSS Distributions })
849*bbb1b6f9SApple OSS Distributions
850*bbb1b6f9SApple OSS Distributions #define os_trace_debug_with_payload(format, ...) __extension__({ \
851*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
852*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
853*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
854*bbb1b6f9SApple OSS Distributions })
855*bbb1b6f9SApple OSS Distributions
856*bbb1b6f9SApple OSS Distributions #define os_trace_error_with_payload(format, ...) __extension__({ \
857*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
858*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
859*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \
860*bbb1b6f9SApple OSS Distributions })
861*bbb1b6f9SApple OSS Distributions
862*bbb1b6f9SApple OSS Distributions #define os_trace_fault_with_payload(format, ...) __extension__({ \
863*bbb1b6f9SApple OSS Distributions _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
864*bbb1b6f9SApple OSS Distributions __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
865*bbb1b6f9SApple OSS Distributions OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \
866*bbb1b6f9SApple OSS Distributions })
867*bbb1b6f9SApple OSS Distributions
868*bbb1b6f9SApple OSS Distributions #endif // __has_include(<xpc/xpc.h>)
869*bbb1b6f9SApple OSS Distributions
870*bbb1b6f9SApple OSS Distributions // TODO: change this once we have compiler support
871*bbb1b6f9SApple OSS Distributions __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
872*bbb1b6f9SApple OSS Distributions OS_EXPORT OS_NOTHROW
873*bbb1b6f9SApple OSS Distributions size_t
874*bbb1b6f9SApple OSS Distributions _os_trace_encode(uint8_t *buf, size_t buf_size, const char *format, ...);
875*bbb1b6f9SApple OSS Distributions
876*bbb1b6f9SApple OSS Distributions __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
877*bbb1b6f9SApple OSS Distributions OS_EXPORT OS_NOTHROW
878*bbb1b6f9SApple OSS Distributions void
879*bbb1b6f9SApple OSS Distributions _os_trace_internal(void *dso, uint8_t type, const char *format, const uint8_t *buf, size_t buf_size, os_trace_payload_t payload);
880*bbb1b6f9SApple OSS Distributions
881*bbb1b6f9SApple OSS Distributions /*!
882*bbb1b6f9SApple OSS Distributions * @function _os_trace_with_buffer
883*bbb1b6f9SApple OSS Distributions *
884*bbb1b6f9SApple OSS Distributions * @abstract
885*bbb1b6f9SApple OSS Distributions * Internal function to support pre-encoded buffer.
886*bbb1b6f9SApple OSS Distributions */
887*bbb1b6f9SApple OSS Distributions __OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0)
888*bbb1b6f9SApple OSS Distributions OS_EXPORT OS_NOTHROW
889*bbb1b6f9SApple OSS Distributions void
890*bbb1b6f9SApple OSS Distributions _os_trace_with_buffer(void *dso, const char *message, uint8_t type, const void *buffer, size_t buffer_size, os_trace_payload_t payload);
891*bbb1b6f9SApple OSS Distributions
892*bbb1b6f9SApple OSS Distributions __END_DECLS
893*bbb1b6f9SApple OSS Distributions
894*bbb1b6f9SApple OSS Distributions #endif // __OS_TRACE_H__
895