You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.8 KiB

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