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