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