1/*
2 * Copyright (c) 2015-2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef log_encode_types_h
25#define log_encode_types_h
26
27/*
28 * These are IPIs between xnu and libtrace, used to have common encoding
29 * and implementation for kernel logging and user logging. They are subject
30 * to change at any point.
31 */
32
33#include <os/base.h>
34#include <os/log.h>
35#include <stdint.h>
36#include <stdbool.h>
37#include <stddef.h>
38
39#include "log_mem.h"
40
41#pragma mark - buffer support structures, enums
42
43OS_ENUM(os_log_fmt_hdr_flags, uint8_t,
44 OSLF_HDR_FLAG_HAS_PRIVATE = 0x01,
45 OSLF_HDR_FLAG_HAS_NON_SCALAR = 0x02,
46 );
47
48OS_ENUM(os_log_fmt_cmd_type, uint8_t,
49 OSLF_CMD_TYPE_SCALAR = 0, // %u, %lld, %x, %p, %g, ...
50 OSLF_CMD_TYPE_COUNT = 1, // %.16P, %.*s
51 OSLF_CMD_TYPE_STRING = 2, // %s
52 OSLF_CMD_TYPE_POINTER = 3, // %P
53 OSLF_CMD_TYPE_OBJECT = 4, // %@
54 OSLF_CMD_TYPE_WIDE_STRING = 5, // %S
55 OSLF_CMD_TYPE_ERRNO = 6, // %m
56 OSLF_CMD_TYPE_MASK = 7, // %{mask.foo}...
57 );
58
59OS_ENUM(os_log_fmt_cmd_flags, uint8_t,
60 OSLF_CMD_FLAG_PRIVATE = 0x1,
61 OSLF_CMD_FLAG_PUBLIC = 0x2,
62 OSLF_CMD_FLAG_SENSITIVE = 0x4 | OSLF_CMD_FLAG_PRIVATE,
63 );
64
65enum os_log_int_types_t {
66 OST_CHAR = -2,
67 OST_SHORT = -1,
68 OST_INT = 0,
69 OST_LONG = 1,
70 OST_LONGLONG = 2,
71 OST_SIZE = 3,
72 OST_INTMAX = 4,
73 OST_PTRDIFF = 5,
74};
75
76union os_log_fmt_types_u {
77 uint16_t u16;
78 uint32_t u32;
79 uint64_t u64;
80 char ch;
81 short s;
82 int i;
83 void *p;
84 char *pch;
85 size_t z;
86 intmax_t im;
87 ptrdiff_t pd;
88 long l;
89 long long ll;
90};
91
92typedef struct os_log_fmt_hdr_s {
93 os_log_fmt_hdr_flags_t hdr_flags;
94 uint8_t hdr_cmd_cnt;
95 uint8_t hdr_data[];
96} *os_log_fmt_hdr_t;
97
98typedef struct os_log_fmt_cmd_s {
99 os_log_fmt_cmd_flags_t cmd_flags : 4;
100 os_log_fmt_cmd_type_t cmd_type : 4;
101 uint8_t cmd_size;
102 uint8_t cmd_data[];
103} *os_log_fmt_cmd_t;
104
105typedef struct os_log_fmt_range_s {
106 uint16_t offset;
107 uint16_t length : 15;
108 uint16_t truncated : 1;
109} *os_log_fmt_range_t;
110
111#define OS_LOG_MAX_PUB_ARGS (32)
112
113typedef struct os_log_context_s {
114 logmem_t *ctx_logmem;
115 uint8_t *ctx_buffer;
116 size_t ctx_buffer_sz;
117 os_log_fmt_hdr_t ctx_hdr;
118 char *ctx_pubdata[OS_LOG_MAX_PUB_ARGS];
119 uint16_t ctx_content_off; // offset into buffer->hdr_data
120 uint16_t ctx_content_sz; // size not including the header
121 uint16_t ctx_pubdata_sz;
122 uint16_t ctx_pubdata_cnt;
123 uint8_t ctx_truncated : 1;
124 uint8_t ctx_allocated : 1;
125} *os_log_context_t;
126
127#endif /* log_encode_types_h */
128