|
| 1 | +// |
| 2 | +// Taken from https://github.com/llvm-mirror/lldb/blob/master/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h |
| 3 | +// by Tanner Bennett on 03/03/2019 with minimal modifications. |
| 4 | +// |
| 5 | + |
| 6 | +//===-- ActivityStreamAPI.h -------------------------------------*- C++ -*-===// |
| 7 | +// |
| 8 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 9 | +// See https://llvm.org/LICENSE.txt for license information. |
| 10 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#ifndef ActivityStreamSPI_h |
| 15 | +#define ActivityStreamSPI_h |
| 16 | + |
| 17 | +#include <Foundation/Foundation.h> |
| 18 | + |
| 19 | +#include <sys/time.h> |
| 20 | +// #include <xpc/xpc.h> |
| 21 | + |
| 22 | +/* By default, XPC objects are declared as Objective-C types when building with |
| 23 | + * an Objective-C compiler. This allows them to participate in ARC, in RR |
| 24 | + * management by the Blocks runtime and in leaks checking by the static |
| 25 | + * analyzer, and enables them to be added to Cocoa collections. |
| 26 | + * |
| 27 | + * See <os/object.h> for details. |
| 28 | + */ |
| 29 | +#if !TARGET_OS_MACCATALYST |
| 30 | +#if OS_OBJECT_USE_OBJC |
| 31 | +OS_OBJECT_DECL(xpc_object); |
| 32 | +#else |
| 33 | +typedef void * xpc_object_t; |
| 34 | +#endif |
| 35 | +#endif |
| 36 | + |
| 37 | +#define OS_ACTIVITY_MAX_CALLSTACK 32 |
| 38 | + |
| 39 | +// Enums |
| 40 | + |
| 41 | +typedef NS_ENUM(uint32_t, os_activity_stream_flag_t) { |
| 42 | + OS_ACTIVITY_STREAM_PROCESS_ONLY = 0x00000001, |
| 43 | + OS_ACTIVITY_STREAM_SKIP_DECODE = 0x00000002, |
| 44 | + OS_ACTIVITY_STREAM_PAYLOAD = 0x00000004, |
| 45 | + OS_ACTIVITY_STREAM_HISTORICAL = 0x00000008, |
| 46 | + OS_ACTIVITY_STREAM_CALLSTACK = 0x00000010, |
| 47 | + OS_ACTIVITY_STREAM_DEBUG = 0x00000020, |
| 48 | + OS_ACTIVITY_STREAM_BUFFERED = 0x00000040, |
| 49 | + OS_ACTIVITY_STREAM_NO_SENSITIVE = 0x00000080, |
| 50 | + OS_ACTIVITY_STREAM_INFO = 0x00000100, |
| 51 | + OS_ACTIVITY_STREAM_PROMISCUOUS = 0x00000200, |
| 52 | + OS_ACTIVITY_STREAM_PRECISE_TIMESTAMPS = 0x00000200 |
| 53 | +}; |
| 54 | + |
| 55 | +typedef NS_ENUM(uint32_t, os_activity_stream_type_t) { |
| 56 | + OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE = 0x0201, |
| 57 | + OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION = 0x0202, |
| 58 | + OS_ACTIVITY_STREAM_TYPE_ACTIVITY_USERACTION = 0x0203, |
| 59 | + |
| 60 | + OS_ACTIVITY_STREAM_TYPE_TRACE_MESSAGE = 0x0300, |
| 61 | + |
| 62 | + OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400, |
| 63 | + OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480, |
| 64 | + |
| 65 | + OS_ACTIVITY_STREAM_TYPE_SIGNPOST_BEGIN = 0x0601, |
| 66 | + OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602, |
| 67 | + OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603, |
| 68 | + |
| 69 | + OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00, |
| 70 | +}; |
| 71 | + |
| 72 | +typedef NS_ENUM(uint32_t, os_activity_stream_event_t) { |
| 73 | + OS_ACTIVITY_STREAM_EVENT_STARTED = 1, |
| 74 | + OS_ACTIVITY_STREAM_EVENT_STOPPED = 2, |
| 75 | + OS_ACTIVITY_STREAM_EVENT_FAILED = 3, |
| 76 | + OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED = 4, |
| 77 | + OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED = 5, |
| 78 | +}; |
| 79 | + |
| 80 | +// Types |
| 81 | + |
| 82 | +typedef uint64_t os_activity_id_t; |
| 83 | +typedef struct os_activity_stream_s *os_activity_stream_t; |
| 84 | +typedef struct os_activity_stream_entry_s *os_activity_stream_entry_t; |
| 85 | + |
| 86 | +#define OS_ACTIVITY_STREAM_COMMON() \ |
| 87 | +uint64_t trace_id; \ |
| 88 | +uint64_t timestamp; \ |
| 89 | +uint64_t thread; \ |
| 90 | +const uint8_t *image_uuid; \ |
| 91 | +const char *image_path; \ |
| 92 | +struct timeval tv_gmt; \ |
| 93 | +struct timezone tz; \ |
| 94 | +uint32_t offset |
| 95 | + |
| 96 | +typedef struct os_activity_stream_common_s { |
| 97 | + OS_ACTIVITY_STREAM_COMMON(); |
| 98 | +} * os_activity_stream_common_t; |
| 99 | + |
| 100 | +struct os_activity_create_s { |
| 101 | + OS_ACTIVITY_STREAM_COMMON(); |
| 102 | + const char *name; |
| 103 | + os_activity_id_t creator_aid; |
| 104 | + uint64_t unique_pid; |
| 105 | +}; |
| 106 | + |
| 107 | +struct os_activity_transition_s { |
| 108 | + OS_ACTIVITY_STREAM_COMMON(); |
| 109 | + os_activity_id_t transition_id; |
| 110 | +}; |
| 111 | + |
| 112 | +typedef struct os_log_message_s { |
| 113 | + OS_ACTIVITY_STREAM_COMMON(); |
| 114 | + const char *format; |
| 115 | + const uint8_t *buffer; |
| 116 | + size_t buffer_sz; |
| 117 | + const uint8_t *privdata; |
| 118 | + size_t privdata_sz; |
| 119 | + const char *subsystem; |
| 120 | + const char *category; |
| 121 | + uint32_t oversize_id; |
| 122 | + uint8_t ttl; |
| 123 | + bool persisted; |
| 124 | +} * os_log_message_t; |
| 125 | + |
| 126 | +typedef struct os_trace_message_v2_s { |
| 127 | + OS_ACTIVITY_STREAM_COMMON(); |
| 128 | + const char *format; |
| 129 | + const void *buffer; |
| 130 | + size_t bufferLen; |
| 131 | + xpc_object_t __unsafe_unretained payload; |
| 132 | +} * os_trace_message_v2_t; |
| 133 | + |
| 134 | +typedef struct os_activity_useraction_s { |
| 135 | + OS_ACTIVITY_STREAM_COMMON(); |
| 136 | + const char *action; |
| 137 | + bool persisted; |
| 138 | +} * os_activity_useraction_t; |
| 139 | + |
| 140 | +typedef struct os_signpost_s { |
| 141 | + OS_ACTIVITY_STREAM_COMMON(); |
| 142 | + const char *format; |
| 143 | + const uint8_t *buffer; |
| 144 | + size_t buffer_sz; |
| 145 | + const uint8_t *privdata; |
| 146 | + size_t privdata_sz; |
| 147 | + const char *subsystem; |
| 148 | + const char *category; |
| 149 | + uint64_t duration_nsec; |
| 150 | + uint32_t callstack_depth; |
| 151 | + uint64_t callstack[OS_ACTIVITY_MAX_CALLSTACK]; |
| 152 | +} * os_signpost_t; |
| 153 | + |
| 154 | +typedef struct os_activity_statedump_s { |
| 155 | + OS_ACTIVITY_STREAM_COMMON(); |
| 156 | + char *message; |
| 157 | + size_t message_size; |
| 158 | + char image_path_buffer[PATH_MAX]; |
| 159 | +} * os_activity_statedump_t; |
| 160 | + |
| 161 | +struct os_activity_stream_entry_s { |
| 162 | + os_activity_stream_type_t type; |
| 163 | + |
| 164 | + // information about the process streaming the data |
| 165 | + pid_t pid; |
| 166 | + uint64_t proc_id; |
| 167 | + const uint8_t *proc_imageuuid; |
| 168 | + const char *proc_imagepath; |
| 169 | + |
| 170 | + // the activity associated with this streamed event |
| 171 | + os_activity_id_t activity_id; |
| 172 | + os_activity_id_t parent_id; |
| 173 | + |
| 174 | + union { |
| 175 | + struct os_activity_stream_common_s common; |
| 176 | + struct os_activity_create_s activity_create; |
| 177 | + struct os_activity_transition_s activity_transition; |
| 178 | + struct os_log_message_s log_message; |
| 179 | + struct os_trace_message_v2_s trace_message; |
| 180 | + struct os_activity_useraction_s useraction; |
| 181 | + struct os_signpost_s signpost; |
| 182 | + struct os_activity_statedump_s statedump; |
| 183 | + }; |
| 184 | +}; |
| 185 | + |
| 186 | +// Blocks |
| 187 | + |
| 188 | +typedef bool (^os_activity_stream_block_t)(os_activity_stream_entry_t entry, |
| 189 | + int error); |
| 190 | + |
| 191 | +typedef void (^os_activity_stream_event_block_t)( |
| 192 | + os_activity_stream_t stream, os_activity_stream_event_t event); |
| 193 | + |
| 194 | +// SPI entry point prototypes |
| 195 | + |
| 196 | +typedef os_activity_stream_t (*os_activity_stream_for_pid_t)( |
| 197 | + pid_t pid, os_activity_stream_flag_t flags, |
| 198 | + os_activity_stream_block_t stream_block); |
| 199 | + |
| 200 | +typedef void (*os_activity_stream_resume_t)(os_activity_stream_t stream); |
| 201 | + |
| 202 | +typedef void (*os_activity_stream_cancel_t)(os_activity_stream_t stream); |
| 203 | + |
| 204 | +typedef char *(*os_log_copy_formatted_message_t)(os_log_message_t log_message); |
| 205 | + |
| 206 | +typedef void (*os_activity_stream_set_event_handler_t)( |
| 207 | + os_activity_stream_t stream, os_activity_stream_event_block_t block); |
| 208 | + |
| 209 | +#endif /* ActivityStreamSPI_h */ |
0 commit comments