|
21 | 21 | #include <wchar.h>
|
22 | 22 |
|
23 | 23 | #include "os_trace_blob.h"
|
24 |
| - |
25 |
| -#ifndef os_fastpath |
26 |
| -#define os_fastpath(x) ((__typeof__(x))OS_EXPECT((long)(x), ~0l)) |
27 |
| -#endif |
28 |
| -#ifndef os_slowpath |
29 |
| -#define os_slowpath(x) ((__typeof__(x))OS_EXPECT((long)(x), 0l)) |
30 |
| -#endif |
31 |
| -#ifndef os_likely |
32 |
| -#define os_likely(x) OS_EXPECT(!!(x), 1) |
33 |
| -#endif |
34 |
| -#ifndef os_unlikely |
35 |
| -#define os_unlikely(x) OS_EXPECT(!!(x), 0) |
36 |
| -#endif |
37 |
| - |
38 |
| -#ifndef MIN |
39 |
| -#define MIN(a, b) (((a)<(b))?(a):(b)) |
40 |
| -#endif |
| 24 | +#include "thunks.h" |
41 | 25 |
|
42 | 26 | #define OST_FORMAT_MAX_STRING_SIZE 1024
|
43 | 27 | #define OS_LOG_FMT_MAX_CMDS 48
|
|
92 | 76 | uint8_t cmd_data[];
|
93 | 77 | } os_log_fmt_cmd_s, *os_log_fmt_cmd_t;
|
94 | 78 |
|
95 |
| - |
96 | 79 | typedef struct os_log_fmt_hdr_s {
|
97 | 80 | os_log_fmt_hdr_flags_t hdr_flags;
|
98 | 81 | uint8_t hdr_cmd_cnt;
|
99 | 82 | uint8_t hdr_data[];
|
100 | 83 | } os_log_fmt_hdr_s, *os_log_fmt_hdr_t;
|
101 | 84 |
|
| 85 | +typedef struct os_log_pack_s { |
| 86 | + uint64_t olp_continuous_time; |
| 87 | + struct timespec olp_wall_time; |
| 88 | + const void *olp_mh; |
| 89 | + const void *olp_pc; |
| 90 | + const char *olp_format; |
| 91 | + uint8_t olp_data[0]; |
| 92 | +} os_log_pack_s, *os_log_pack_t; |
| 93 | + |
| 94 | +API_AVAILABLE(macosx(10.12.4), ios(10.3), tvos(10.2), watchos(3.2)) |
| 95 | +size_t |
| 96 | +_os_log_pack_size(size_t os_log_format_buffer_size); |
| 97 | + |
| 98 | +API_AVAILABLE(macosx(10.12.4), ios(10.3), tvos(10.2), watchos(3.2)) |
| 99 | +uint8_t * |
| 100 | +_os_log_pack_fill(os_log_pack_t pack, size_t size, int saved_errno, const void *dso, const char *fmt); |
| 101 | + |
| 102 | +API_AVAILABLE(macosx(10.12.4), ios(10.3), tvos(10.2), watchos(3.2)) |
| 103 | +void |
| 104 | +os_log_pack_send(os_log_pack_t pack, os_log_t log, os_log_type_t type); |
| 105 | + |
102 | 106 | static inline void
|
103 | 107 | _os_log_encode_arg(os_trace_blob_t ob, os_log_fmt_cmd_t cmd, const void *data)
|
104 | 108 | {
|
|
299 | 303 |
|
300 | 304 | __attribute__((__visibility__("default")))
|
301 | 305 | void
|
302 |
| -_swift_os_log(void *dso, os_log_t oslog, os_log_type_t type, const char *format, va_list args) |
| 306 | +_swift_os_log(void *dso, void *retaddr, os_log_t oslog, os_log_type_t type, const char *format, va_list args) |
303 | 307 | {
|
304 |
| - int save_errno = errno; // %m |
| 308 | + int saved_errno = errno; // %m |
305 | 309 | char buf[OS_LOG_FMT_BUF_SIZE];
|
306 | 310 | os_trace_blob_s ob = {
|
307 | 311 | .ob_s = buf,
|
308 | 312 | .ob_size = OS_LOG_FMT_BUF_SIZE,
|
309 | 313 | .ob_binary = true
|
310 | 314 | };
|
311 | 315 |
|
312 |
| - if (_os_log_encode(buf, format, args, save_errno, &ob)) { |
313 |
| - _os_log_impl(dso, oslog, type, format, (uint8_t *)buf, ob.ob_len); |
| 316 | + if (_os_log_encode(buf, format, args, saved_errno, &ob)) { |
| 317 | + // Use os_log_pack_send where available. |
| 318 | + if (os_log_pack_send) { |
| 319 | + size_t sz = _os_log_pack_size(ob.ob_len); |
| 320 | + union { os_log_pack_s pack; uint8_t buf[OS_LOG_FMT_BUF_SIZE + sizeof(os_log_pack_s)]; } u; |
| 321 | + // _os_log_encode has already packed `saved_errno` into a OSLF_CMD_TYPE_SCALAR command |
| 322 | + // as the OSLF_CMD_TYPE_ERRNO does not deploy backwards, so passes zero for errno here. |
| 323 | + uint8_t *ptr = _os_log_pack_fill(&u.pack, sz, 0, dso, format); |
| 324 | + u.pack.olp_pc = retaddr; |
| 325 | + memcpy(ptr, buf, ob.ob_len); |
| 326 | + os_log_pack_send(&u.pack, oslog, type); |
| 327 | + } else { |
| 328 | + _os_log_impl(dso, oslog, type, format, (uint8_t *)buf, ob.ob_len); |
| 329 | + } |
314 | 330 | }
|
315 | 331 | }
|
| 332 | + |
| 333 | +__attribute__((__visibility__("default"))) |
| 334 | +void * |
| 335 | +_swift_os_log_return_address(void) |
| 336 | +{ |
| 337 | + return __builtin_return_address(1); |
| 338 | +} |
| 339 | + |
0 commit comments