1/*
2 * Copyright (c) 2015-2016 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#pragma mark - buffer support structures, enums
40
41OS_ENUM(os_log_value_type, uint8_t,
42 OS_LOG_BUFFER_VALUE_TYPE_SCALAR = 0,
43 OS_LOG_BUFFER_VALUE_TYPE_COUNT = 1,
44 OS_LOG_BUFFER_VALUE_TYPE_STRING = 2,
45#ifndef KERNEL
46 OS_LOG_BUFFER_VALUE_TYPE_POINTER = 3,
47 OS_LOG_BUFFER_VALUE_TYPE_OBJECT = 4,
48#endif
49 );
50
51OS_ENUM(os_log_value_subtype, uint8_t,
52 OS_LOG_BUFFER_VALUE_SUBTYPE_NONE = 0,
53 OS_LOG_BUFFER_VALUE_SUBTYPE_INTEGER = 1,
54#ifndef KERNEL
55 OS_LOG_BUFFER_VALUE_SUBTYPE_FLOAT = 2,
56#endif
57 );
58
59enum os_log_int_types_t {
60 OST_CHAR = -2,
61 OST_SHORT = -1,
62 OST_INT = 0,
63 OST_LONG = 1,
64 OST_LONGLONG = 2,
65 OST_SIZE = 3,
66 OST_INTMAX = 4,
67 OST_PTRDIFF = 5,
68};
69
70union os_log_format_types_u {
71 uint16_t u16;
72 uint32_t u32;
73 uint64_t u64;
74 char ch;
75 short s;
76 int i;
77 void *p;
78 char *pch;
79#ifndef KERNEL
80 wchar_t wch;
81 wchar_t *pwch;
82#endif
83 size_t z;
84 intmax_t im;
85 ptrdiff_t pd;
86 long l;
87 long long ll;
88#ifndef KERNEL
89 double d;
90 float f;
91 long double ld;
92#endif
93};
94
95typedef struct os_log_format_value_s {
96 union os_log_format_types_u type;
97 os_log_value_type_t ctype;
98 uint16_t size;
99} *os_log_format_value_t;
100
101#define OST_FORMAT_MAX_ARGS 48
102#ifdef KERNEL
103#define OST_FORMAT_MAX_STRING_SIZE 512
104#else
105#define OST_FORMAT_MAX_STRING_SIZE 1024
106#endif
107
108#define OST_FORMAT_NON_STATIC ~0
109
110typedef struct os_log_buffer_value_s {
111#define OS_LOG_CONTENT_FLAG_PRIVATE 0x1
112 uint8_t flags : 4;
113 os_log_value_type_t type : 4;
114 uint8_t size;
115 uint8_t value[];
116} *os_log_buffer_value_t;
117
118typedef struct os_log_buffer_s {
119#define OS_LOG_BUFFER_HAS_PRIVATE 0x1
120#define OS_LOG_BUFFER_HAS_NON_SCALAR 0x2
121#ifdef KERNEL
122#define OS_LOG_BUFFER_MAX_SIZE 256
123#else
124#define OS_LOG_BUFFER_MAX_SIZE 1024
125#endif
126 uint8_t flags;
127 uint8_t arg_cnt;
128 uint8_t content[];
129} *os_log_buffer_t;
130
131typedef struct os_log_buffer_context_s {
132 os_log_t log;
133 os_log_buffer_t buffer;
134 uint8_t *pubdata;
135 uint8_t *privdata;
136
137 // composed string
138 char *comp;
139 size_t comp_off;
140 size_t comp_sz;
141
142 // sizes and offsets
143 uint16_t content_off; // offset into buffer->content
144 uint16_t content_sz; // size not including the header
145 uint16_t pubdata_off;
146 uint16_t pubdata_sz;
147 uint16_t privdata_off;
148 uint16_t privdata_sz;
149
150 uint8_t arg_idx;
151
152 // if argument content was limited with %.* or %.#
153
154#ifndef KERNEL
155 const char *symptom_str;
156 const void *symptom_ptr;
157 uint16_t symptom_ptr_len;
158 char *annotated;
159#endif
160 int arg_content_sz;
161 bool need_size;
162 bool shimmed;
163} *os_log_buffer_context_t;
164
165typedef struct os_log_arginfo_s {
166 uint16_t offset;
167 uint16_t length;
168} *os_log_arginfo_t;
169
170/* Clients of these interfaces/structures may be expected to provide implementations of the following functions */
171
172#ifndef KERNEL
173extern bool
174_NSCF2data(const void *obj, char *string_value, size_t string_sz, bool *is_private);
175#endif
176
177extern bool
178_os_log_string_is_public(const char *str);
179
180#endif /* log_encode_types_h */
181