this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Working new libc and fat build, added machdep calls table and implemented sys_getentropy()

+2708 -202
+14 -3
cmake/darling_lib.cmake
··· 71 71 endif (CIRCULAR_SOURCES) 72 72 73 73 # Then create a shared Darling library, while ignoring all dependencies and using flat namespace 74 - add_darling_library("${name}_firstpass" SHARED ${all_objects})# $<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS}) 74 + add_darling_library("${name}_firstpass" SHARED ${all_objects}) 75 75 set_property(TARGET "${name}_firstpass" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress") 76 + 77 + #if (DYLIB_INSTALL_NAME) 78 + # set_property(TARGET "${name}_firstpass" PROPERTY FULL_PATH "${DYLIB_INSTALL_NAME}") 79 + #endif (DYLIB_INSTALL_NAME) 80 + #set_property(GLOBAL APPEND_STRING PROPERTY FIRSTPASS_MAP " -Wl,-dylib_file,${DYLIB_INSTALL_NAME}:$<TARGET_FILE:${name}_firstpass>") 76 81 77 82 foreach(dep ${CIRCULAR_STRONG_SIBLINGS}) 78 83 target_link_libraries("${name}_firstpass" PRIVATE "${dep}_firstpass") ··· 83 88 endif (CIRCULAR_FAT) 84 89 85 90 # Then build the final product while linking against firstpass libraries 86 - add_darling_library(${name} SHARED ${all_objects}) #$<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS}) 87 - set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}") 91 + add_darling_library(${name} SHARED ${all_objects}) 88 92 93 + #set(dylib_files "") 89 94 foreach(dep ${CIRCULAR_SIBLINGS}) 95 + #get_property(full_path TARGET "${name}_firstpass" PROPERTY FULL_PATH) 96 + #set(dylib_files "${dylib_files} -Wl,-dylib_file,${full_path}:$<TARGET_FILE:${name}_firstpass>") 90 97 target_link_libraries("${name}" PRIVATE "${dep}_firstpass") 91 98 endforeach(dep) 99 + 100 + get_property(dylib_files GLOBAL PROPERTY FIRSTPASS_MAP) 101 + set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}") 102 + 92 103 target_link_libraries("${name}" PRIVATE ${CIRCULAR_DEPENDENCIES}) 93 104 94 105 if (CIRCULAR_FAT)
+20 -17
cmake/use_ld64.cmake
··· 3 3 LINK_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ld64/src/ \ 4 4 -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ \ 5 5 -target x86_64-apple-darwin11 \ 6 - -Wl,-dylib_file,/usr/lib/system/libsystem_c.dylib:${CMAKE_BINARY_DIR}/src/libc/libsystem_c.dylib \ 7 - -Wl,-dylib_file,/usr/lib/system/libsystem_kernel.dylib:${CMAKE_BINARY_DIR}/src/kernel/libsystem_kernel.dylib \ 8 - -Wl,-dylib_file,/usr/lib/system/libunwind.dylib:${CMAKE_BINARY_DIR}/src/libunwind/libunwind.dylib \ 9 - -Wl,-dylib_file,/usr/lib/system/libsystem_m.dylib:${CMAKE_BINARY_DIR}/src/libm/libsystem_m.dylib \ 10 - -Wl,-dylib_file,/usr/lib/system/libcompiler_rt.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/builtins/libcompiler_rt.dylib \ 11 - -Wl,-dylib_file,/usr/lib/system/libdyld.dylib:${CMAKE_BINARY_DIR}/src/dyld-apple/libdyld.dylib \ 12 - -Wl,-dylib_file,/usr/lib/system/libsystem_info.dylib:${CMAKE_BINARY_DIR}/src/libinfo/libsystem_info.dylib \ 13 - -Wl,-dylib_file,/usr/lib/system/libsystem_blocks.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/BlocksRuntime/libsystem_blocks.dylib \ 6 + -Wl,-dylib_file,/usr/lib/system/libsystem_c.dylib:${CMAKE_BINARY_DIR}/src/libc/libsystem_c_firstpass.dylib \ 7 + -Wl,-dylib_file,/usr/lib/system/libsystem_kernel.dylib:${CMAKE_BINARY_DIR}/src/kernel/libsystem_kernel_firstpass.dylib \ 8 + -Wl,-dylib_file,/usr/lib/system/libunwind.dylib:${CMAKE_BINARY_DIR}/src/libunwind/libunwind_firstpass.dylib \ 9 + -Wl,-dylib_file,/usr/lib/system/libsystem_m.dylib:${CMAKE_BINARY_DIR}/src/libm/libsystem_m_firstpass.dylib \ 10 + -Wl,-dylib_file,/usr/lib/system/libcompiler_rt.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/builtins/libcompiler_rt_firstpass.dylib \ 11 + -Wl,-dylib_file,/usr/lib/system/libdyld.dylib:${CMAKE_BINARY_DIR}/src/dyld-apple/libsystem_dyld_firstpass.dylib \ 12 + -Wl,-dylib_file,/usr/lib/system/libsystem_info.dylib:${CMAKE_BINARY_DIR}/src/libinfo/libsystem_info_firstpass.dylib \ 13 + -Wl,-dylib_file,/usr/lib/system/libsystem_blocks.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/BlocksRuntime/libsystem_blocks_firstpass.dylib \ 14 14 -Wl,-dylib_file,/usr/lib/libc++abi.dylib:${CMAKE_BINARY_DIR}/src/external/libcxxabi/src/libc++abi.dylib \ 15 - -Wl,-dylib_file,/usr/lib/system/liblaunch.dylib:${CMAKE_BINARY_DIR}/src/launchd/liblaunch/liblaunch.dylib \ 16 - -Wl,-dylib_file,/usr/lib/system/libkeymgr.dylib:${CMAKE_BINARY_DIR}/src/keymgr/libkeymgr.dylib \ 15 + -Wl,-dylib_file,/usr/lib/system/liblaunch.dylib:${CMAKE_BINARY_DIR}/src/launchd/liblaunch/liblaunch_firstpass.dylib \ 16 + -Wl,-dylib_file,/usr/lib/system/libkeymgr.dylib:${CMAKE_BINARY_DIR}/src/keymgr/libkeymgr_firstpass.dylib \ 17 17 -Wl,-dylib_file,/usr/lib/system/libquarantine.dylib:${CMAKE_BINARY_DIR}/src/quarantine/libquarantine.dylib \ 18 18 -Wl,-dylib_file,/usr/lib/system/libremovefile.dylib:${CMAKE_BINARY_DIR}/src/libremovefile/libremovefile.dylib \ 19 19 -Wl,-dylib_file,/usr/lib/system/libcopyfile.dylib:${CMAKE_BINARY_DIR}/src/copyfile/libcopyfile.dylib \ 20 20 -Wl,-dylib_file,/usr/lib/system/libsystem_coreservices.dylib:${CMAKE_BINARY_DIR}/src/libsystem_coreservices/libsystem_coreservices.dylib \ 21 - -Wl,-dylib_file,/usr/lib/system/libsystem_notify.dylib:${CMAKE_BINARY_DIR}/src/libnotify/libsystem_notify.dylib \ 22 - -Wl,-dylib_file,/usr/lib/system/libdispatch.dylib:${CMAKE_BINARY_DIR}/src/external/libdispatch/src/libdispatch.dylib \ 23 - -Wl,-dylib_file,/usr/lib/system/libmacho.dylib:${CMAKE_BINARY_DIR}/src/libmacho/libmacho.dylib \ 21 + -Wl,-dylib_file,/usr/lib/system/libsystem_notify.dylib:${CMAKE_BINARY_DIR}/src/libnotify/libsystem_notify_firstpass.dylib \ 22 + -Wl,-dylib_file,/usr/lib/system/libdispatch.dylib:${CMAKE_BINARY_DIR}/src/external/libdispatch/src/liblibdispatch_shared_firstpass.dylib \ 23 + -Wl,-dylib_file,/usr/lib/system/libmacho.dylib:${CMAKE_BINARY_DIR}/src/libmacho/libmacho_firstpass.dylib \ 24 24 -Wl,-dylib_file,/usr/lib/system/libsystem_sandbox.dylib:${CMAKE_BINARY_DIR}/src/sandbox/libsystem_sandbox.dylib \ 25 - -Wl,-dylib_file,/usr/lib/system/libsystem_duct.dylib:${CMAKE_BINARY_DIR}/src/duct/src/libsystem_duct.dylib \ 26 - -Wl,-dylib_file,/usr/lib/system/libsystem_pthread.dylib:${CMAKE_BINARY_DIR}/src/external/libpthread/src/libsystem_pthread.dylib \ 27 - -Wl,-dylib_file,/usr/lib/system/libsystem_platform.dylib:${CMAKE_BINARY_DIR}/src/external/libplatform/libsystem_platform.dylib \ 25 + -Wl,-dylib_file,/usr/lib/system/libsystem_duct.dylib:${CMAKE_BINARY_DIR}/src/duct/src/libsystem_duct_firstpass.dylib \ 26 + -Wl,-dylib_file,/usr/lib/system/libsystem_pthread.dylib:${CMAKE_BINARY_DIR}/src/external/libpthread/src/libsystem_pthread_firstpass.dylib \ 27 + -Wl,-dylib_file,/usr/lib/system/libsystem_platform.dylib:${CMAKE_BINARY_DIR}/src/external/libplatform/libplatform_firstpass.dylib \ 28 28 -Wl,-dylib_file,/usr/lib/libcommonCrypto.dylib:${CMAKE_BINARY_DIR}/src/CommonCrypto/libcommonCrypto.dylib \ 29 - -Wl,-dylib_file,/usr/lib/system/libsystem_malloc.dylib:${CMAKE_BINARY_DIR}/src/libmalloc/libsystem_malloc.dylib ") 29 + -Wl,-dylib_file,/usr/lib/system/libsystem_asl.dylib:${CMAKE_BINARY_DIR}/src/external/syslog/libsystem_asl.tproj/libsystem_asl_firstpass.dylib \ 30 + -Wl,-dylib_file,/usr/lib/libresolv.9.dylib:${CMAKE_BINARY_DIR}/src/libresolv/libresolv.9.dylib \ 31 + -W;,-dylib_file,/usr/lib/system/libxpc.dylib:${CMAKE_BINARY_DIR}/src/external/libxpc/libxpc_firstpass.dylib \ 32 + -Wl,-dylib_file,/usr/lib/system/libsystem_malloc.dylib:${CMAKE_BINARY_DIR}/src/libmalloc/libsystem_malloc_firstpass.dylib ") 30 33 31 34 add_dependencies(${target} x86_64-apple-darwin11-ld) 32 35
+3 -3
platform-include/mach/i386/syscall_sw.h
··· 87 87 #define UNIX_SYSCALL_TRAP \ 88 88 call __darling_bsd_syscall 89 89 #define MACHDEP_SYSCALL_TRAP \ 90 - ud2 90 + call __darling_machdep_syscall 91 91 92 92 #endif 93 93 ··· 110 110 #ifndef KERNEL 111 111 112 112 #define UNIX_SYSCALL_TRAP \ 113 - syscall 113 + call __darling_bsd_syscall 114 114 #define MACHDEP_SYSCALL_TRAP \ 115 - syscall 115 + call __darling_machdep_syscall 116 116 117 117 /* 118 118 * Macro to generate Mach call stubs in Libc.
+2 -1
src/CMakeLists.txt
··· 88 88 add_subdirectory(libffi) 89 89 add_subdirectory(dyld-apple) 90 90 #add_subdirectory(external/objc4/runtime) 91 + add_subdirectory(external/syslog/libsystem_asl.tproj) 91 92 add_subdirectory(external/libdispatch) 92 93 add_subdirectory(external/zlib) 93 94 add_subdirectory(external/bzip2) ··· 129 130 #add_subdirectory(Cocoa) 130 131 131 132 add_subdirectory(external/file/file) 132 - #add_subdirectory(external/libxpc) 133 + add_subdirectory(external/libxpc) 133 134 add_subdirectory(external/openssl_certificates) 134 135 135 136 if (NOT DARLING_NO_EXECUTABLES)
+232
src/duct/include/firehose/firehose_types_private.h
··· 1 + /* 2 + * Copyright (c) 2015-2016 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_APACHE_LICENSE_HEADER_START@ 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + * 18 + * @APPLE_APACHE_LICENSE_HEADER_END@ 19 + */ 20 + 21 + #ifndef __FIREHOSE_TYPES_PRIVATE__ 22 + #define __FIREHOSE_TYPES_PRIVATE__ 23 + 24 + #include <mach/mach_types.h> 25 + #include <mach/std_types.h> 26 + #include <os/base.h> 27 + 28 + OS_ASSUME_NONNULL_BEGIN 29 + 30 + __BEGIN_DECLS 31 + 32 + /*! 33 + * @enum firehose_activity_flags_t 34 + * 35 + * @discussion 36 + * The lower 8 bits are or-ed in the upper 8 bits of Activity ID and propagated 37 + * to children activities 38 + */ 39 + OS_ENUM(firehose_activity_flags, unsigned long, 40 + firehose_activity_flags_default = 0x0000, 41 + 42 + firehose_activity_flags_info_mode = 0x0001, 43 + firehose_activity_flags_debug_mode = 0x0002, 44 + firehose_activity_flags_stream_live_mode = 0x0004, 45 + 46 + firehose_activity_flags_precise_timestamp = 0x0080, 47 + ); 48 + 49 + /*! 50 + * @typedef firehose_activity_id_t 51 + * 52 + * @abstract 53 + * Opaque activity identifier. 54 + * 55 + * @discussion 56 + * Scalar value type, not reference counted. 57 + */ 58 + typedef uint64_t firehose_activity_id_t; 59 + #define FIREHOSE_ACTIVITY_ID_NULL ((firehose_activity_id_t)0) 60 + #define FIREHOSE_ACTIVITY_ID_INVALID ((firehose_activity_id_t)~0ULL) 61 + #define FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT 56 62 + #define FIREHOSE_ACTIVITY_ID_FLAGS(aid) \ 63 + ((firehose_activity_flags_t)((aid) >> FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT)) 64 + #define FIREHOSE_ACTIVITY_ID_MERGE_FLAGS(aid, flags) (\ 65 + ((firehose_activity_id_t)(aid)) | \ 66 + ((firehose_activity_id_t)(flags) << FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT)) 67 + 68 + /*! 69 + * @enum firehose_stream_t 70 + */ 71 + OS_ENUM(firehose_stream, uint8_t, 72 + firehose_stream_persist = 0, 73 + firehose_stream_special = 1, 74 + firehose_stream_memory = 2, 75 + firehose_stream_metadata = 3, 76 + firehose_stream_memory_high_traffic = 4, 77 + firehose_stream_memory_wifi = 5, 78 + firehose_stream_memory_baseband = 6, 79 + 80 + _firehose_stream_max, 81 + ); 82 + 83 + /*! 84 + * @enum firehose_tracepoint_namespace_t 85 + * 86 + * @abstract 87 + * Namespaces of tracepoints. 88 + */ 89 + OS_ENUM(firehose_tracepoint_namespace, uint8_t, 90 + firehose_tracepoint_namespace_activity = 0x02, 91 + firehose_tracepoint_namespace_trace = 0x03, 92 + firehose_tracepoint_namespace_log = 0x04, 93 + firehose_tracepoint_namespace_metadata = 0x05, 94 + ); 95 + 96 + /*! 97 + * @enum firehose_tracepoint_code_t 98 + * 99 + * @abstract 100 + * Codes of tracepoints. 101 + */ 102 + OS_ENUM(firehose_tracepoint_code, uint32_t, 103 + firehose_tracepoint_code_load = 0x01, 104 + firehose_tracepoint_code_unload = 0x02, 105 + ); 106 + 107 + /*! 108 + * @typedef firehose_tracepoint_type_t 109 + * 110 + * @abstract 111 + * Type of tracepoints. 112 + */ 113 + typedef uint8_t firehose_tracepoint_type_t; 114 + 115 + /*! 116 + * @typedef firehose_tracepoint_flags_t 117 + * 118 + * @abstract 119 + * Flags for tracepoints. 120 + */ 121 + OS_ENUM(firehose_tracepoint_flags, uint16_t, 122 + _firehose_tracepoint_flags_base_has_current_aid = 0x0001, 123 + _firehose_tracepoint_flags_base_main_executable = 0x0002, 124 + _firehose_tracepoint_flags_base_shared_cache = 0x0004, 125 + _firehose_tracepoint_flags_base_caller_pc = 0x0008, 126 + _firehose_tracepoint_flags_base_has_unique_pid = 0x0010, 127 + ); 128 + 129 + /*! 130 + * @typedef firehose_tracepoint_id_t 131 + * 132 + * @abstract 133 + * Opaque tracepoint identifier. 134 + */ 135 + typedef uint64_t firehose_tracepoint_id_t; 136 + 137 + /*! 138 + * @enum _firehose_tracepoint_type_activity_t 139 + * 140 + * @abstract 141 + * Types of Activity tracepoints (namespace activity). 142 + */ 143 + OS_ENUM(_firehose_tracepoint_type_activity, firehose_tracepoint_type_t, 144 + _firehose_tracepoint_type_activity_create = 0x01, 145 + _firehose_tracepoint_type_activity_swap = 0x02, 146 + _firehose_tracepoint_type_activity_useraction = 0x03, 147 + ); 148 + 149 + /*! 150 + * @enum firehose_tracepoint_flags_activity_t 151 + * 152 + * @abstract 153 + * Flags for Activity tracepoints (namespace activity). 154 + */ 155 + OS_ENUM(_firehose_tracepoint_flags_activity, uint16_t, 156 + _firehose_tracepoint_flags_activity_user_interface = 0x0100, 157 + _firehose_tracepoint_flags_activity_has_other_aid = 0x0200, 158 + ); 159 + 160 + /*! 161 + * @enum firehose_tracepoint_type_trace_t 162 + * 163 + * @abstract 164 + * Types of trace tracepoints (namespace trace). 165 + */ 166 + OS_ENUM(_firehose_tracepoint_type_trace, firehose_tracepoint_type_t, 167 + _firehose_tracepoint_type_trace_default = 0x00, 168 + _firehose_tracepoint_type_trace_info = 0x01, 169 + _firehose_tracepoint_type_trace_debug = 0x02, 170 + _firehose_tracepoint_type_trace_error = 0x10, 171 + _firehose_tracepoint_type_trace_fault = 0x11, 172 + ); 173 + 174 + /*! 175 + * @enum firehose_tracepoint_type_log_t 176 + * 177 + * @abstract 178 + * Types of Log tracepoints (namespace log). 179 + */ 180 + OS_ENUM(_firehose_tracepoint_type_log, firehose_tracepoint_type_t, 181 + _firehose_tracepoint_type_log_default = 0x00, 182 + _firehose_tracepoint_type_log_info = 0x01, 183 + _firehose_tracepoint_type_log_debug = 0x02, 184 + _firehose_tracepoint_type_log_error = 0x10, 185 + _firehose_tracepoint_type_log_fault = 0x11, 186 + ); 187 + 188 + /*! 189 + * @enum firehose_tracepoint_flags_log_t 190 + * 191 + * @abstract 192 + * Flags for Log tracepoints (namespace log). 193 + */ 194 + OS_ENUM(_firehose_tracepoint_flags_log, uint16_t, 195 + _firehose_tracepoint_flags_log_has_private_data = 0x0100, 196 + _firehose_tracepoint_flags_log_has_subsystem = 0x0200, 197 + _firehose_tracepoint_flags_log_has_rules = 0x0400, 198 + _firehose_tracepoint_flags_log_has_oversize = 0x0800, 199 + ); 200 + 201 + /*! 202 + * @enum _firehose_tracepoint_type_metadata_t 203 + * 204 + * @abstract 205 + * Types for metadata tracepoints (namespace metadata). 206 + */ 207 + OS_ENUM(_firehose_tracepoint_type_metadata, firehose_tracepoint_type_t, 208 + _firehose_tracepoint_type_metadata_dyld = 0x01, 209 + _firehose_tracepoint_type_metadata_subsystem = 0x02, 210 + _firehose_tracepoint_type_metadata_kext = 0x03, 211 + ); 212 + 213 + /* MIG firehose push reply structure */ 214 + typedef struct firehose_push_reply_s { 215 + uint64_t fpr_mem_flushed_pos; 216 + uint64_t fpr_io_flushed_pos; 217 + } firehose_push_reply_t; 218 + 219 + typedef struct firehose_buffer_map_info_s { 220 + mach_vm_address_t fbmi_addr; 221 + mach_vm_size_t fbmi_size; 222 + } firehose_buffer_map_info_t; 223 + 224 + #define FIREHOSE_PUSH_REPLY_CORRUPTED ((firehose_push_reply_t){ ~0ULL, ~0ULL }) 225 + 226 + typedef union firehose_buffer_u *firehose_buffer_t; 227 + 228 + __END_DECLS 229 + 230 + OS_ASSUME_NONNULL_END 231 + 232 + #endif // __FIREHOSE_TYPES__
+152
src/duct/include/firehose/tracepoint_private.h
··· 1 + /* 2 + * Copyright (c) 2013-2016 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_APACHE_LICENSE_HEADER_START@ 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + * 18 + * @APPLE_APACHE_LICENSE_HEADER_END@ 19 + */ 20 + 21 + #ifndef __FIREHOSE_ACTIVITY__ 22 + #define __FIREHOSE_ACTIVITY__ 23 + 24 + #include <machine/cpu_capabilities.h> 25 + #include <mach/mach_time.h> 26 + #include <os/base.h> 27 + #if KERNEL 28 + #include <atm/atm_internal.h> 29 + #endif 30 + #include "firehose_types_private.h" 31 + 32 + OS_ASSUME_NONNULL_BEGIN 33 + 34 + /*! 35 + * @typedef firehose_tracepoint_id_u 36 + * 37 + * @abstract 38 + * Broken down tracepoint identifier. 39 + */ 40 + typedef union { 41 + struct { 42 + firehose_tracepoint_namespace_t _namespace; 43 + firehose_tracepoint_type_t _type; 44 + firehose_tracepoint_flags_t _flags; 45 + uint32_t _code; 46 + } ftid; 47 + firehose_tracepoint_id_t ftid_value; 48 + } firehose_tracepoint_id_u; 49 + 50 + #define FIREHOSE_STAMP_SLOP (1ULL << 36) // ~1minute 51 + 52 + /*! 53 + * @typedef firehose_trace_uuid_info_t 54 + * 55 + * @abstract 56 + * Info needed by logd when kexts are loaded or unloaded 57 + * 58 + */ 59 + typedef struct firehose_trace_uuid_info_s { 60 + uuid_t ftui_uuid; /* uuid of binary */ 61 + uint64_t ftui_address; /* load address */ 62 + uint64_t ftui_size; /* load size */ 63 + char ftui_path[]; /* full path of binary - Unused in the kernel*/ 64 + } *firehose_trace_uuid_info_t; 65 + 66 + /*! 67 + * @typedef firehose_tracepoint_t 68 + */ 69 + typedef struct firehose_tracepoint_s { 70 + firehose_tracepoint_id_u ft_id; 71 + uint64_t ft_thread; 72 + union { 73 + struct { 74 + uint64_t ft_timestamp_delta : 48; 75 + uint64_t ft_length : 16; 76 + }; 77 + uint64_t ft_stamp_and_length; 78 + }; 79 + uint8_t ft_data[]; 80 + } *firehose_tracepoint_t; 81 + 82 + #define FIREHOSE_TRACE_ID_MAKE(ns, type, flags, code) \ 83 + (((firehose_tracepoint_id_u){ .ftid = { \ 84 + ._namespace = ns, \ 85 + ._type = type, \ 86 + ._flags = flags, \ 87 + ._code = code, \ 88 + } }).ftid_value) 89 + 90 + #define FIREHOSE_TRACE_ID_SET_NS(tid, ns) \ 91 + ((tid).ftid._namespace = firehose_tracepoint_namespace_##ns) 92 + 93 + #define FIREHOSE_TRACE_ID_SET_TYPE(tid, ns, type) \ 94 + ((tid).ftid._type = _firehose_tracepoint_type_##ns##_##type) 95 + 96 + #define FIREHOSE_TRACE_ID_HAS_FLAG(tid, ns, flag) \ 97 + ((tid).ftid._flags & _firehose_tracepoint_flags_##ns##_##flag) 98 + #define FIREHOSE_TRACE_ID_SET_FLAG(tid, ns, flag) \ 99 + ((void)((tid).ftid._flags |= _firehose_tracepoint_flags_##ns##_##flag)) 100 + #define FIREHOSE_TRACE_ID_CLEAR_FLAG(tid, ns, flag) \ 101 + ((void)((tid).ftid._flags &= ~_firehose_tracepoint_flags_##ns##_##flag)) 102 + 103 + #define FIREHOSE_TRACE_ID_SET_CODE(tid, code) \ 104 + ((tid).ftid._code = code) 105 + 106 + __BEGIN_DECLS 107 + 108 + #if __has_feature(address_sanitizer) 109 + __attribute__((no_sanitize("address"))) 110 + #endif 111 + __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) 112 + __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) 113 + OS_ALWAYS_INLINE 114 + static inline bool 115 + firehose_precise_timestamps_enabled(void) 116 + { 117 + #if KERNEL 118 + return (atm_get_diagnostic_config() & 0x80) == 0; 119 + #else 120 + return (*((volatile uint32_t *)_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG) & 0x80) == 0; 121 + #endif 122 + } 123 + 124 + #if __has_feature(address_sanitizer) 125 + __attribute__((no_sanitize("address"))) 126 + #endif 127 + __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) 128 + __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) 129 + OS_ALWAYS_INLINE 130 + static inline uint64_t 131 + firehose_tracepoint_time(firehose_activity_flags_t flags) 132 + { 133 + if (firehose_precise_timestamps_enabled() || 134 + (flags & firehose_activity_flags_precise_timestamp)) { 135 + return mach_continuous_time(); 136 + } else { 137 + return mach_continuous_approximate_time(); 138 + } 139 + } 140 + 141 + #ifdef KERNEL 142 + __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) 143 + __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) 144 + void 145 + firehose_trace_metadata(firehose_stream_t stream, firehose_tracepoint_id_u ftid, 146 + uint64_t stamp, const void* pubdata, size_t publen); 147 + #endif 148 + __END_DECLS 149 + 150 + OS_ASSUME_NONNULL_END 151 + 152 + #endif // __FIREHOSE_FIREHOSE__
+501
src/duct/include/os/log.h
··· 1 + /* 2 + * Copyright (c) 2015 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 __os_log_h 25 + #define __os_log_h 26 + 27 + #include <os/object.h> 28 + #include <stdint.h> 29 + #include <stdbool.h> 30 + 31 + #ifndef __has_attribute 32 + #define __has_attribute(x) 0 33 + #endif 34 + 35 + #ifndef __has_builtin 36 + #define __has_builtin(x) 0 37 + #endif 38 + 39 + #if __has_attribute(not_tail_called) 40 + #define OS_LOG_NOTAILCALL __attribute__((not_tail_called)) 41 + #define OS_LOG_NOTAILCALL_MARKER 42 + #else 43 + #define OS_LOG_NOTAILCALL 44 + #define OS_LOG_NOTAILCALL_MARKER __asm__("") 45 + #endif 46 + 47 + __BEGIN_DECLS 48 + 49 + extern void *__dso_handle; 50 + 51 + OS_ALWAYS_INLINE static inline void _os_log_verify_format_str(__unused const char *msg, ...) __attribute__((format(os_trace, 1, 2))); 52 + OS_ALWAYS_INLINE static inline void _os_log_verify_format_str(__unused const char *msg, ...) { /* placeholder */ } 53 + 54 + #if OS_OBJECT_USE_OBJC 55 + OS_OBJECT_DECL(os_log); 56 + #else 57 + typedef struct os_log_s *os_log_t; 58 + #endif /* OS_OBJECT_USE_OBJC */ 59 + 60 + /*! 61 + * @const OS_LOG_DISABLED 62 + * 63 + * @discussion 64 + * Use this to disable a specific log message. 65 + */ 66 + #define OS_LOG_DISABLED NULL 67 + 68 + /*! 69 + * @const OS_LOG_DEFAULT 70 + * 71 + * @discussion 72 + * Use this to log a message in accordance with current system settings. 73 + */ 74 + #define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default) 75 + __OSX_AVAILABLE_STARTING(__MAC_10_12,__IPHONE_10_0) 76 + OS_EXPORT 77 + struct os_log_s _os_log_default; 78 + 79 + /*! 80 + * @enum os_log_type_t 81 + * 82 + * @discussion 83 + * Supported log message types. 84 + * 85 + * @constant OS_LOG_TYPE_DEFAULT 86 + * Equivalent type for "os_log()" messages, i.e., default messages that are always 87 + * captured to memory or disk. 88 + * 89 + * @constant OS_LOG_TYPE_INFO 90 + * Equivalent type for "os_log_info()" messages, i.e., Additional informational messages. 91 + * 92 + * @constant OS_LOG_TYPE_DEBUG 93 + * Equivalent type for "os_log_debug()" messages, i.e., Debug messages. 94 + * 95 + * @constant OS_LOG_TYPE_ERROR 96 + * Equivalent type for "os_log_error()" messages, i.e., local process error messages. 97 + * 98 + * @constant OS_LOG_TYPE_FAULT 99 + * Equivalent type for "os_log_fault()" messages, i.e., a system error that involves 100 + * potentially more than one process, usually used by daemons and services. 101 + */ 102 + OS_ENUM(os_log_type, uint8_t, 103 + OS_LOG_TYPE_DEFAULT = 0x00, 104 + OS_LOG_TYPE_INFO = 0x01, 105 + OS_LOG_TYPE_DEBUG = 0x02, 106 + OS_LOG_TYPE_ERROR = 0x10, 107 + OS_LOG_TYPE_FAULT = 0x11); 108 + 109 + /*! 110 + * @function os_log_create 111 + * 112 + * @abstract 113 + * Creates a log object to be used with other log related functions. 114 + * 115 + * @discussion 116 + * Creates a log object to be used with other log related functions. The 117 + * log object serves two purposes: (1) tag related messages by subsystem 118 + * and category name for easy filtering, and (2) control logging system 119 + * behavior for messages. 120 + * 121 + * A log object may customize logging system behavior for its messages by 122 + * adding a configuration file in /Library/LogPreferences. Most options 123 + * accept 3 values: "Default", "Yes" or "No" as strings, where "Default" 124 + * signifies follow system behavior for the level of messages. 125 + * 126 + * For log: 127 + * 128 + * os_log_create("com.company.mysubsystem", "connections"); 129 + * 130 + * System-provided preferences are located in /System/Library/LogPreferences/<subsystem>.plist 131 + * 132 + * <dict> 133 + * 134 + * <!-- Default options applied to message types in each category, which can be overriden. --> 135 + * <key>DEFAULT-OPTIONS</key> 136 + * <dict> 137 + * <key>Enabled</key> <!-- Enabled state follows system defaults --> 138 + * <string>Default</string> 139 + * <key>Persist</key> <!-- Do not persist to disk, use memory-only buffer if enabled --> 140 + * <string>No</string> 141 + * <key>TTL</key> <!-- Follow system default behavior if persistence is enabled --> 142 + * <string>Default</string> <!-- Can specify in days with "d" or hours "h" (e.g., "4h" = 4 hours) --> 143 + * </dict> 144 + * 145 + * <!-- category named “connections” --> 146 + * <key>connections</key> 147 + * <dict> 148 + * 149 + * <!-- Options that control "os_log()" behavior. The "Enabled" option is ignored. --> 150 + * <key>Default</key> 151 + * <dict> 152 + * <key>Persist</key> <!-- Always persist to disk --> 153 + * <string>Yes</string> 154 + * <key>TTL</key> <!-- Store default messages for maximum 4 days --> 155 + * <integer>4d</integer> 156 + * </dict> 157 + * 158 + * <!-- Subdictionary of options that control "os_log_info()" behavior --> 159 + * <key>Info</key> 160 + * <dict> 161 + * <key>Persist</key> <!-- If enabled persist to disk --> 162 + * <string>Yes</string> 163 + * <key>TTL</key> <!-- Store Info messages for 2 days --> 164 + * <string>2d</string> 165 + * </dict> 166 + * 167 + * <!-- Subdictionary of options that control "os_log_debug()" behavior --> 168 + * <key>Debug</key> 169 + * <dict> 170 + * <key>Enabled</key> <!-- Not enabled, must be enabled specifically --> 171 + * <string>No</string> 172 + * </dict> 173 + * </dict> 174 + * </dict> 175 + * 176 + * All other preferences and system-overrides are stored in /Library/LogPreferences/. 177 + * 178 + * @param subsystem 179 + * The identifier of the given subsystem should be in reverse DNS form 180 + * (i.e., com.company.mysubsystem). This string must be a constant string, 181 + * not dynamically generated. 182 + * 183 + * @param category 184 + * The category within the given subsystem that specifies the settings for 185 + * the log object. This string must be a constant string, not dynamically 186 + * generated. 187 + * 188 + * @result 189 + * Returns an os_log_t value to be passed to other os_log API calls. This 190 + * should be called once at log initialization and rely on system to detect 191 + * changes to settings. This object should be released when no longer used 192 + * via os_release or -[release] method. 193 + * 194 + * A value will always be returned to allow for dynamic enablement. 195 + */ 196 + __OSX_AVAILABLE_STARTING(__MAC_10_12,__IPHONE_10_0) 197 + OS_EXPORT OS_NOTHROW OS_WARN_RESULT OS_OBJECT_RETURNS_RETAINED 198 + os_log_t 199 + os_log_create(const char *subsystem, const char *category); 200 + 201 + /*! 202 + * @function os_log_info_enabled 203 + * 204 + * @abstract 205 + * Returns if development log messages are enabled for a particular log object. 206 + * 207 + * @discussion 208 + * Returns if development log messages are enabled for a particular log object. 209 + * 210 + * @param log 211 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 212 + * 213 + * @result 214 + * Returns ‘true’ if debug log messages are enabled. 215 + */ 216 + __WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) 217 + OS_EXPORT OS_NOTHROW OS_WARN_RESULT 218 + bool 219 + os_log_info_enabled(os_log_t log); 220 + 221 + /*! 222 + * @function os_log_debug_enabled 223 + * 224 + * @abstract 225 + * Returns if debug log messages are enabled for a particular log object. 226 + * 227 + * @discussion 228 + * Returns if debug log messages are enabled for a particular log object. 229 + * 230 + * @param log 231 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 232 + * 233 + * @result 234 + * Returns ‘true’ if debug log messages are enabled. 235 + */ 236 + __WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) 237 + OS_EXPORT OS_NOTHROW OS_WARN_RESULT 238 + bool 239 + os_log_debug_enabled(os_log_t log); 240 + 241 + /*! 242 + * @function os_log 243 + * 244 + * @abstract 245 + * Insert a log message into the Unified Logging and Tracing system. 246 + * 247 + * @discussion 248 + * Insert a log message into the Unified Logging and Tracing system in 249 + * accordance with the preferences specified by the provided log object. 250 + * These messages cannot be disabled and therefore always captured either 251 + * to memory or disk. 252 + * 253 + * When an os_activity_id_t is present, the log message will also be scoped by 254 + * that identifier. Activities provide granular filtering of log messages 255 + * across threads and processes. 256 + * 257 + * There is a physical cap of 256 bytes per entry for dynamic content, 258 + * i.e., %s and %@, that can be written to the persistence store. As such, 259 + * all content exceeding the limit will be truncated before written to disk. 260 + * Live streams will continue to show the full content. 261 + * 262 + * @param log 263 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 264 + * 265 + * @param format 266 + * A format string to generate a human-readable log message when the log 267 + * line is decoded. This string must be a constant string, not dynamically 268 + * generated. Supports all standard printf types and %@ (objects). 269 + */ 270 + #define os_log(log, format, ...) __extension__({ \ 271 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 272 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 273 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 274 + _os_log_internal(&__dso_handle, log, OS_LOG_TYPE_DEFAULT, _os_log_fmt, ##__VA_ARGS__); \ 275 + __asm__(""); /* avoid tailcall */ \ 276 + }) 277 + 278 + /*! 279 + * @function os_log_info 280 + * 281 + * @abstract 282 + * Insert a development log message into the Unified Logging and Tracing system. 283 + * 284 + * @discussion 285 + * Insert a log message into the Unified Logging and Tracing system in 286 + * accordance with the preferences specified by the provided log object. 287 + * 288 + * When an os_activity_id_t is present, the log message will also be scoped by 289 + * that identifier. Activities provide granular filtering of log messages 290 + * across threads and processes. 291 + * 292 + * There is a physical cap of 256 bytes per entry for dynamic content, 293 + * i.e., %s and %@, that can be written to the persistence store. As such, 294 + * all content exceeding the limit will be truncated before written to disk. 295 + * Live streams will continue to show the full content. 296 + * 297 + * @param log 298 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 299 + * 300 + * @param format 301 + * A format string to generate a human-readable log message when the log 302 + * line is decoded. This string must be a constant string, not dynamically 303 + * generated. Supports all standard printf types and %@ (objects). 304 + */ 305 + #define os_log_info(log, format, ...) __extension__({ \ 306 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 307 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 308 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 309 + _os_log_internal(&__dso_handle, log, OS_LOG_TYPE_INFO, _os_log_fmt, ##__VA_ARGS__); \ 310 + __asm__(""); /* avoid tailcall */ \ 311 + }) 312 + 313 + /*! 314 + * @function os_log_debug 315 + * 316 + * @abstract 317 + * Insert a debug log message into the Unified Logging and Tracing system. 318 + * 319 + * @discussion 320 + * Insert a debug log message into the Unified Logging and Tracing system in 321 + * accordance with the preferences specified by the provided log object. 322 + * 323 + * When an os_activity_id_t is present, the log message will also be scoped by 324 + * that identifier. Activities provide granular filtering of log messages 325 + * across threads and processes. 326 + * 327 + * There is a physical cap of 256 bytes per entry for dynamic content, 328 + * i.e., %s and %@, that can be written to the persistence store. As such, 329 + * all content exceeding the limit will be truncated before written to disk. 330 + * Live streams will continue to show the full content. 331 + * 332 + * @param log 333 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 334 + * 335 + * @param format 336 + * A format string to generate a human-readable log message when the log 337 + * line is decoded. This string must be a constant string, not dynamically 338 + * generated. Supports all standard printf types and %@ (objects). 339 + */ 340 + #define os_log_debug(log, format, ...) __extension__({ \ 341 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 342 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 343 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 344 + _os_log_internal(&__dso_handle, log, OS_LOG_TYPE_DEBUG, _os_log_fmt, ##__VA_ARGS__); \ 345 + __asm__(""); /* avoid tailcall */ \ 346 + }) 347 + 348 + /*! 349 + * @function os_log_error 350 + * 351 + * @abstract 352 + * Insert an error log message into the Unified Logging and Tracing system. 353 + * 354 + * @discussion 355 + * Insert an error log message into the Unified Logging and Tracing system. 356 + * 357 + * When an os_activity_id_t is present, the log message will also be scoped by 358 + * that identifier. Activities provide granular filtering of log messages 359 + * across threads and processes. 360 + * 361 + * There is a physical cap of 256 bytes per entry for dynamic content, 362 + * i.e., %s and %@, that can be written to the persistence store. As such, 363 + * all content exceeding the limit will be truncated before written to disk. 364 + * Live streams will continue to show the full content. 365 + * 366 + * @param log 367 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 368 + * 369 + * @param format 370 + * A format string to generate a human-readable log message when the log 371 + * line is decoded. This string must be a constant string, not dynamically 372 + * generated. Supports all standard printf types and %@ (objects). 373 + */ 374 + #define os_log_error(log, format, ...) __extension__({ \ 375 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 376 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 377 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 378 + _os_log_internal(&__dso_handle, log, OS_LOG_TYPE_ERROR, _os_log_fmt, ##__VA_ARGS__); \ 379 + __asm__(""); /* avoid tailcall */ \ 380 + }) 381 + 382 + /*! 383 + * @function os_log_fault 384 + * 385 + * @abstract 386 + * Insert a fault log message into the Unified Logging and Tracing system. 387 + * 388 + * @discussion 389 + * Log a fault message issue into the Unified Logging and Tracing system 390 + * signifying a multi-process (i.e., system error) related issue, either 391 + * due to interaction via IPC or some other. Faults will gather information 392 + * from the entire process chain and record it for later inspection. 393 + * 394 + * When an os_activity_id_t is present, the log message will also be scoped by 395 + * that identifier. Activities provide granular filtering of log messages 396 + * across threads and processes. 397 + * 398 + * There is a physical cap of 256 bytes per entry for dynamic content, 399 + * i.e., %s and %@, that can be written to the persistence store. As such, 400 + * all content exceeding the limit will be truncated before written to disk. 401 + * Live streams will continue to show the full content. 402 + * 403 + * @param log 404 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 405 + * 406 + * @param format 407 + * A format string to generate a human-readable log message when the log 408 + * line is decoded. This string must be a constant string, not dynamically 409 + * generated. Supports all standard printf types and %@ (objects). 410 + */ 411 + #define os_log_fault(log, format, ...) __extension__({ \ 412 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 413 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 414 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 415 + _os_log_internal(&__dso_handle, log, OS_LOG_TYPE_FAULT, _os_log_fmt, ##__VA_ARGS__); \ 416 + __asm__(""); /* avoid tailcall */ \ 417 + }) 418 + 419 + /*! 420 + * @function os_log_with_type 421 + * 422 + * @abstract 423 + * Log a message using a specific type. 424 + * 425 + * @discussion 426 + * Will log a message with the provided os_log_type_t. 427 + * 428 + * @param log 429 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 430 + * 431 + * @param type 432 + * Pass a valid type from os_log_type_t. 433 + * 434 + * @param format 435 + * A format string to generate a human-readable log message when the log 436 + * line is decoded. This string must be a constant string, not dynamically 437 + * generated. Supports all standard printf types and %@ (objects). 438 + */ 439 + #define os_log_with_type(log, type, format, ...) __extension__({ \ 440 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 441 + __attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \ 442 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 443 + _os_log_internal(&__dso_handle, log, type, _os_log_fmt, ##__VA_ARGS__); \ 444 + __asm__(""); /* avoid tailcall */ \ 445 + }) 446 + 447 + /*! 448 + * @function os_log_sensitive_debug 449 + * 450 + * @abstract 451 + * Insert a debug log message containing sensitive content (i.e., personal 452 + * identifying information). 453 + * 454 + * @discussion 455 + * Insert a debug log message containing sensitive content (i.e., personal 456 + * identifying information) in accordance with the preferences specified by 457 + * the provided log object. 458 + * 459 + * All strings are considered potentially sensitive, though this call 460 + * specifically signifies the message as containing sensitive content. 461 + * The message will be stored separately from other messages. 462 + * 463 + * When an os_activity_id_t is present, the log message will also be scoped by 464 + * that identifier. Activities provide granular filtering of log messages 465 + * across threads and processes. 466 + * 467 + * There is a physical cap of 256 bytes per entry for dynamic content, 468 + * i.e., %s and %@, that can be written to the persistence store. As such, 469 + * all content exceeding the limit will be truncated before written to disk. 470 + * Live streams will continue to show the full content. 471 + * 472 + * @param log 473 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 474 + * 475 + * @param format 476 + * A format string to generate a human-readable log message when the log 477 + * line is decoded. This string must be a constant string, not dynamically 478 + * generated. Supports all standard printf types and %@ (objects). 479 + */ 480 + #define os_log_sensitive_debug(log, format, ...) __extension__({ \ 481 + _Static_assert(__builtin_constant_p(format), "format string must be constant"); \ 482 + __attribute__((section("__TEXT,__os_log_sens"))) static const char _os_log_fmt[] = format; \ 483 + _os_log_verify_format_str(format, ##__VA_ARGS__); \ 484 + _os_log_sensitive(&__dso_handle, log, OS_LOG_TYPE_DEBUG, _os_log_fmt, ##__VA_ARGS__); \ 485 + __asm__(""); /* avoid tailcall */ \ 486 + }) 487 + 488 + /*! 489 + * @function _os_log_internal 490 + * 491 + * @abstract 492 + * Internal function used by macros. 493 + */ 494 + __WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) 495 + OS_EXPORT OS_NOTHROW 496 + void 497 + _os_log_internal(void *dso, os_log_t log, os_log_type_t type, const char *message, ...); 498 + 499 + __END_DECLS 500 + 501 + #endif /* __os_log_h */
+94
src/duct/include/os/log_private.h
··· 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 __os_log_private_h 25 + #define __os_log_private_h 26 + 27 + #include <os/log.h> 28 + #include <firehose/tracepoint_private.h> 29 + #include <sys/queue.h> 30 + 31 + __BEGIN_DECLS 32 + 33 + /*! 34 + * @function os_log_with_args 35 + * 36 + * @abstract 37 + * os_log variant that supports va_list args. 38 + * 39 + * @discussion 40 + * os_log variant that supports va_list args. This SPI should only be used 41 + * to shim legacy logging systems through os_log. 42 + * 43 + * @param oslog 44 + * Pass OS_LOG_DEFAULT or a log object previously created with os_log_create. 45 + * 46 + * @param type 47 + * Pass one of the following message types. 48 + * OS_LOG_TYPE_DEFAULT 49 + * OS_LOG_TYPE_DEBUG 50 + * OS_LOG_TYPE_INFO 51 + * OS_LOG_TYPE_ERROR 52 + * OS_LOG_TYPE_FAULT 53 + * 54 + * @param format 55 + * A format string to generate a human-readable log message when the log 56 + * line is decoded. Supports all standard printf types in addition to %@ 57 + * and %m (objects and errno respectively). 58 + * 59 + * @param args 60 + * A va_list containing the values for the format string. 61 + * 62 + * @param ret_addr 63 + * Pass the __builtin_return_address(0) of the function that created the 64 + * va_list from variadic arguments. The caller must be the same binary 65 + * that generated the message and provided the format string. 66 + */ 67 + __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0) 68 + OS_EXPORT OS_NOTHROW OS_LOG_NOTAILCALL 69 + void 70 + os_log_with_args(os_log_t oslog, os_log_type_t type, const char *format, va_list args, void *ret_addr); 71 + 72 + /*! 73 + * @enum oslog_stream_link_type_t 74 + */ 75 + OS_ENUM(oslog_stream_link_type, uint8_t, 76 + oslog_stream_link_type_log = 0x0, 77 + oslog_stream_link_type_metadata = 0x1, 78 + ); 79 + 80 + /*! 81 + * @typedef oslog_stream_buf_entry_t 82 + */ 83 + typedef struct oslog_stream_buf_entry_s { 84 + STAILQ_ENTRY(oslog_stream_buf_entry_s) buf_entries; 85 + uint64_t timestamp; 86 + int offset; 87 + uint16_t size; 88 + oslog_stream_link_type_t type; 89 + struct firehose_tracepoint_s metadata[]; 90 + } *oslog_stream_buf_entry_t; 91 + 92 + __END_DECLS 93 + 94 + #endif // __os_log_private_h
+893
src/duct/include/os/trace.h
··· 1 + /* 2 + * Copyright (c) 2013-2015 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 __OS_TRACE_H__ 25 + #define __OS_TRACE_H__ 26 + 27 + #include <Availability.h> 28 + #include <os/base.h> 29 + #include <sys/types.h> 30 + #include <stdint.h> 31 + #include <stdbool.h> 32 + #include <stdarg.h> 33 + #if __has_include(<xpc/xpc.h>) 34 + #include <xpc/xpc.h> 35 + #else 36 + typedef void *xpc_object_t; 37 + #endif 38 + 39 + #if !__GNUC__ 40 + #error "must be GNU C compatible" 41 + #endif 42 + 43 + __BEGIN_DECLS 44 + 45 + extern void *__dso_handle; 46 + 47 + OS_ALWAYS_INLINE 48 + static inline void 49 + _os_trace_verify_printf(const char *msg, ...) __attribute__((format(printf, 1, 2))) 50 + { 51 + #pragma unused(msg) 52 + } 53 + 54 + #if !defined OS_COUNT_ARGS 55 + #define OS_COUNT_ARGS(...) OS_COUNT_ARGS1(, ##__VA_ARGS__, _8, _7, _6, _5, _4, _3, _2, _1, _0) 56 + #define OS_COUNT_ARGS1(z, a, b, c, d, e, f, g, h, cnt, ...) cnt 57 + #endif 58 + 59 + /* use old macros for anything less than iOS 10 and MacOS 10.12 */ 60 + #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0) \ 61 + || (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_3_0) \ 62 + || (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED < __TVOS_10_0) \ 63 + || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12) 64 + 65 + #define _os_trace_0(_l, _m, _t) __extension__({ \ 66 + _os_trace_verify_printf(_l); \ 67 + _os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, NULL); \ 68 + __asm__(""); /* avoid tailcall */ \ 69 + }) 70 + 71 + #define _os_trace_1(_l, _m, _t, _1) __extension__({ \ 72 + _Pragma("clang diagnostic push") \ 73 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 74 + const __typeof__(_1) _c1 = _1; \ 75 + _os_trace_verify_printf(_l, _c1); \ 76 + const struct __attribute__((packed)) { \ 77 + __typeof__(_c1) _f1; \ 78 + uint8_t _s[1]; \ 79 + uint8_t _cnt; \ 80 + } _buf = { \ 81 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 82 + ._cnt = 1, \ 83 + }; \ 84 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 85 + __asm__(""); /* avoid tailcall */ \ 86 + _Pragma("clang diagnostic pop") \ 87 + }) 88 + 89 + #define _os_trace_2(_l, _m, _t, _1, _2) __extension__({ \ 90 + _Pragma("clang diagnostic push") \ 91 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 92 + const __typeof__(_1) _c1 = _1; \ 93 + const __typeof__(_2) _c2 = _2; \ 94 + _os_trace_verify_printf(_l, _c1, _c2); \ 95 + const struct __attribute__((packed)) { \ 96 + __typeof__(_c1) _f1; \ 97 + __typeof__(_c2) _f2; \ 98 + uint8_t _s[2]; \ 99 + uint8_t _cnt; \ 100 + } _buf = { \ 101 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 102 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 103 + ._cnt = 2, \ 104 + }; \ 105 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 106 + __asm__(""); /* avoid tailcall */ \ 107 + _Pragma("clang diagnostic pop") \ 108 + }) 109 + 110 + #define _os_trace_3(_l, _m, _t, _1, _2, _3) __extension__({ \ 111 + _Pragma("clang diagnostic push") \ 112 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 113 + const __typeof__(_1) _c1 = _1; \ 114 + const __typeof__(_2) _c2 = _2; \ 115 + const __typeof__(_3) _c3 = _3; \ 116 + _os_trace_verify_printf(_l, _c1, _c2, _c3); \ 117 + const struct __attribute__((packed)) { \ 118 + __typeof__(_c1) _f1; \ 119 + __typeof__(_c2) _f2; \ 120 + __typeof__(_c3) _f3; \ 121 + uint8_t _s[3]; \ 122 + uint8_t _cnt; \ 123 + } _buf = { \ 124 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 125 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 126 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 127 + ._cnt = 3, \ 128 + }; \ 129 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 130 + __asm__(""); /* avoid tailcall */ \ 131 + _Pragma("clang diagnostic pop") \ 132 + }) 133 + 134 + #define _os_trace_4(_l, _m, _t, _1, _2, _3, _4) __extension__({ \ 135 + _Pragma("clang diagnostic push") \ 136 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 137 + const __typeof__(_1) _c1 = _1; \ 138 + const __typeof__(_2) _c2 = _2; \ 139 + const __typeof__(_3) _c3 = _3; \ 140 + const __typeof__(_4) _c4 = _4; \ 141 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \ 142 + const struct __attribute__((packed)) { \ 143 + __typeof__(_c1) _f1; \ 144 + __typeof__(_c2) _f2; \ 145 + __typeof__(_c3) _f3; \ 146 + __typeof__(_c4) _f4; \ 147 + uint8_t _s[4]; \ 148 + uint8_t _cnt; \ 149 + } _buf = { \ 150 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 151 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 152 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 153 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 154 + ._cnt = 4, \ 155 + }; \ 156 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 157 + __asm__(""); /* avoid tailcall */ \ 158 + _Pragma("clang diagnostic pop") \ 159 + }) 160 + 161 + #define _os_trace_5(_l, _m, _t, _1, _2, _3, _4, _5) __extension__({ \ 162 + _Pragma("clang diagnostic push") \ 163 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 164 + const __typeof__(_1) _c1 = _1; \ 165 + const __typeof__(_2) _c2 = _2; \ 166 + const __typeof__(_3) _c3 = _3; \ 167 + const __typeof__(_4) _c4 = _4; \ 168 + const __typeof__(_5) _c5 = _5; \ 169 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \ 170 + const struct __attribute__((packed)) { \ 171 + __typeof__(_c1) _f1; \ 172 + __typeof__(_c2) _f2; \ 173 + __typeof__(_c3) _f3; \ 174 + __typeof__(_c4) _f4; \ 175 + __typeof__(_c5) _f5; \ 176 + uint8_t _s[5]; \ 177 + uint8_t _cnt; \ 178 + } _buf = { \ 179 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 180 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 181 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 182 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 183 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 184 + ._cnt = 5, \ 185 + }; \ 186 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 187 + __asm__(""); /* avoid tailcall */ \ 188 + _Pragma("clang diagnostic pop") \ 189 + }) 190 + 191 + #define _os_trace_6(_l, _m, _t, _1, _2, _3, _4, _5, _6) __extension__({ \ 192 + _Pragma("clang diagnostic push") \ 193 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 194 + const __typeof__(_1) _c1 = _1; \ 195 + const __typeof__(_2) _c2 = _2; \ 196 + const __typeof__(_3) _c3 = _3; \ 197 + const __typeof__(_4) _c4 = _4; \ 198 + const __typeof__(_5) _c5 = _5; \ 199 + const __typeof__(_6) _c6 = _6; \ 200 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \ 201 + const struct __attribute__((packed)) { \ 202 + __typeof__(_c1) _f1; \ 203 + __typeof__(_c2) _f2; \ 204 + __typeof__(_c3) _f3; \ 205 + __typeof__(_c4) _f4; \ 206 + __typeof__(_c5) _f5; \ 207 + __typeof__(_c6) _f6; \ 208 + uint8_t _s[6]; \ 209 + uint8_t _cnt; \ 210 + } _buf = { \ 211 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 212 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 213 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 214 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 215 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 216 + ._f6 = _c6, ._s[5] = sizeof(_c6), \ 217 + ._cnt = 6, \ 218 + }; \ 219 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 220 + __asm__(""); /* avoid tailcall */ \ 221 + _Pragma("clang diagnostic pop") \ 222 + }) 223 + 224 + #define _os_trace_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7) __extension__({ \ 225 + _Pragma("clang diagnostic push") \ 226 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 227 + const __typeof__(_1) _c1 = _1; \ 228 + const __typeof__(_2) _c2 = _2; \ 229 + const __typeof__(_3) _c3 = _3; \ 230 + const __typeof__(_4) _c4 = _4; \ 231 + const __typeof__(_5) _c5 = _5; \ 232 + const __typeof__(_6) _c6 = _6; \ 233 + const __typeof__(_7) _c7 = _7; \ 234 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \ 235 + const struct __attribute__((packed)) { \ 236 + __typeof__(_c1) _f1; \ 237 + __typeof__(_c2) _f2; \ 238 + __typeof__(_c3) _f3; \ 239 + __typeof__(_c4) _f4; \ 240 + __typeof__(_c5) _f5; \ 241 + __typeof__(_c6) _f6; \ 242 + __typeof__(_c7) _f7; \ 243 + uint8_t _s[7]; \ 244 + uint8_t _cnt; \ 245 + } _buf = { \ 246 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 247 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 248 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 249 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 250 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 251 + ._f6 = _c6, ._s[5] = sizeof(_c6), \ 252 + ._f7 = _c7, ._s[6] = sizeof(_c7), \ 253 + ._cnt = 7, \ 254 + }; \ 255 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \ 256 + __asm__(""); /* avoid tailcall */ \ 257 + _Pragma("clang diagnostic pop") \ 258 + }) 259 + 260 + #define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \ 261 + _os_trace_verify_printf(_l); \ 262 + _os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, _payload); \ 263 + __asm__(""); /* avoid tailcall */ \ 264 + }) 265 + 266 + #define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \ 267 + _Pragma("clang diagnostic push") \ 268 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 269 + const __typeof__(_1) _c1 = _1; \ 270 + _os_trace_verify_printf(_l, _c1); \ 271 + const struct __attribute__((packed)) { \ 272 + __typeof__(_c1) _f1; \ 273 + uint8_t _s[1]; \ 274 + uint8_t _cnt; \ 275 + } _buf = { \ 276 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 277 + ._cnt = 1, \ 278 + }; \ 279 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 280 + __asm__(""); /* avoid tailcall */ \ 281 + _Pragma("clang diagnostic pop") \ 282 + }) 283 + 284 + #define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \ 285 + _Pragma("clang diagnostic push") \ 286 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 287 + const __typeof__(_1) _c1 = _1; \ 288 + const __typeof__(_2) _c2 = _2; \ 289 + _os_trace_verify_printf(_l, _c1, _c2); \ 290 + const struct __attribute__((packed)) { \ 291 + __typeof__(_c1) _f1; \ 292 + __typeof__(_c2) _f2; \ 293 + uint8_t _s[2]; \ 294 + uint8_t _cnt; \ 295 + } _buf = { \ 296 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 297 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 298 + ._cnt = 2, \ 299 + }; \ 300 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 301 + __asm__(""); /* avoid tailcall */ \ 302 + _Pragma("clang diagnostic pop") \ 303 + }) 304 + 305 + #define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \ 306 + _Pragma("clang diagnostic push") \ 307 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 308 + const __typeof__(_1) _c1 = _1; \ 309 + const __typeof__(_2) _c2 = _2; \ 310 + const __typeof__(_3) _c3 = _3; \ 311 + _os_trace_verify_printf(_l, _c1, _c2, _c3); \ 312 + const struct __attribute__((packed)) { \ 313 + __typeof__(_c1) _f1; \ 314 + __typeof__(_c2) _f2; \ 315 + __typeof__(_c3) _f3; \ 316 + uint8_t _s[3]; \ 317 + uint8_t _cnt; \ 318 + } _buf = { \ 319 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 320 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 321 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 322 + ._cnt = 3, \ 323 + }; \ 324 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 325 + __asm__(""); /* avoid tailcall */ \ 326 + _Pragma("clang diagnostic pop") \ 327 + }) 328 + 329 + #define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \ 330 + _Pragma("clang diagnostic push") \ 331 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 332 + const __typeof__(_1) _c1 = _1; \ 333 + const __typeof__(_2) _c2 = _2; \ 334 + const __typeof__(_3) _c3 = _3; \ 335 + const __typeof__(_4) _c4 = _4; \ 336 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \ 337 + const struct __attribute__((packed)) { \ 338 + __typeof__(_c1) _f1; \ 339 + __typeof__(_c2) _f2; \ 340 + __typeof__(_c3) _f3; \ 341 + __typeof__(_c4) _f4; \ 342 + uint8_t _s[4]; \ 343 + uint8_t _cnt; \ 344 + } _buf = { \ 345 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 346 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 347 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 348 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 349 + ._cnt = 4, \ 350 + }; \ 351 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 352 + __asm__(""); /* avoid tailcall */ \ 353 + _Pragma("clang diagnostic pop") \ 354 + }) 355 + 356 + #define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \ 357 + _Pragma("clang diagnostic push") \ 358 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 359 + const __typeof__(_1) _c1 = _1; \ 360 + const __typeof__(_2) _c2 = _2; \ 361 + const __typeof__(_3) _c3 = _3; \ 362 + const __typeof__(_4) _c4 = _4; \ 363 + const __typeof__(_4) _c5 = _5; \ 364 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \ 365 + const struct __attribute__((packed)) { \ 366 + __typeof__(_c1) _f1; \ 367 + __typeof__(_c2) _f2; \ 368 + __typeof__(_c3) _f3; \ 369 + __typeof__(_c4) _f4; \ 370 + __typeof__(_c5) _f5; \ 371 + uint8_t _s[5]; \ 372 + uint8_t _cnt; \ 373 + } _buf = { \ 374 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 375 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 376 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 377 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 378 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 379 + ._cnt = 5, \ 380 + }; \ 381 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 382 + __asm__(""); /* avoid tailcall */ \ 383 + _Pragma("clang diagnostic pop") \ 384 + }) 385 + 386 + #define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \ 387 + _Pragma("clang diagnostic push") \ 388 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 389 + const __typeof__(_1) _c1 = _1; \ 390 + const __typeof__(_2) _c2 = _2; \ 391 + const __typeof__(_3) _c3 = _3; \ 392 + const __typeof__(_4) _c4 = _4; \ 393 + const __typeof__(_5) _c5 = _5; \ 394 + const __typeof__(_6) _c6 = _6; \ 395 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \ 396 + const struct __attribute__((packed)) { \ 397 + __typeof__(_c1) _f1; \ 398 + __typeof__(_c2) _f2; \ 399 + __typeof__(_c3) _f3; \ 400 + __typeof__(_c4) _f4; \ 401 + __typeof__(_c5) _f5; \ 402 + __typeof__(_c6) _f6; \ 403 + uint8_t _s[6]; \ 404 + uint8_t _cnt; \ 405 + } _buf = { \ 406 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 407 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 408 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 409 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 410 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 411 + ._f6 = _c6, ._s[5] = sizeof(_c6), \ 412 + ._cnt = 6, \ 413 + }; \ 414 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 415 + __asm__(""); /* avoid tailcall */ \ 416 + _Pragma("clang diagnostic pop") \ 417 + }) 418 + 419 + #define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \ 420 + _Pragma("clang diagnostic push") \ 421 + _Pragma("clang diagnostic ignored \"-Wpacked\"") \ 422 + const __typeof__(_1) _c1 = _1; \ 423 + const __typeof__(_2) _c2 = _2; \ 424 + const __typeof__(_3) _c3 = _3; \ 425 + const __typeof__(_4) _c4 = _4; \ 426 + const __typeof__(_5) _c5 = _5; \ 427 + const __typeof__(_6) _c6 = _6; \ 428 + const __typeof__(_7) _c7 = _7; \ 429 + _os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \ 430 + const struct __attribute__((packed)) { \ 431 + __typeof__(_c1) _f1; \ 432 + __typeof__(_c2) _f2; \ 433 + __typeof__(_c3) _f3; \ 434 + __typeof__(_c4) _f4; \ 435 + __typeof__(_c5) _f5; \ 436 + __typeof__(_c6) _f6; \ 437 + __typeof__(_c7) _f7; \ 438 + uint8_t _s[7]; \ 439 + uint8_t _cnt; \ 440 + } _buf = { \ 441 + ._f1 = _c1, ._s[0] = sizeof(_c1), \ 442 + ._f2 = _c2, ._s[1] = sizeof(_c2), \ 443 + ._f3 = _c3, ._s[2] = sizeof(_c3), \ 444 + ._f4 = _c4, ._s[3] = sizeof(_c4), \ 445 + ._f5 = _c5, ._s[4] = sizeof(_c5), \ 446 + ._f6 = _c6, ._s[5] = sizeof(_c6), \ 447 + ._f7 = _c7, ._s[6] = sizeof(_c7), \ 448 + ._cnt = 7, \ 449 + }; \ 450 + _os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \ 451 + __asm__(""); /* avoid tailcall */ \ 452 + _Pragma("clang diagnostic pop") \ 453 + }) 454 + 455 + #define OS_TRACE_CALL(format, _m, _t, ...) __extension__({ \ 456 + _Pragma("clang diagnostic push") \ 457 + _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \ 458 + OS_CONCAT(_os_trace, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, _t, ##__VA_ARGS__); \ 459 + _Pragma("clang diagnostic pop") \ 460 + }) 461 + 462 + #else 463 + 464 + // Use a new layout in Mac OS 10.12+ and iOS 10.0+ 465 + #define OS_TRACE_CALL(_l, _m, _t, ...) __extension__({ \ 466 + uint8_t buf[1024]; \ 467 + _os_trace_verify_printf(_l, ##__VA_ARGS__); \ 468 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, ##__VA_ARGS__); \ 469 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, NULL); \ 470 + __asm__(""); /* avoid tailcall */ \ 471 + }) 472 + 473 + #define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \ 474 + _os_trace_verify_printf(_l); \ 475 + _os_trace_internal(&__dso_handle, _t, _m, NULL, 0, _payload); \ 476 + __asm__(""); /* avoid tailcall */ \ 477 + }) 478 + 479 + #define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \ 480 + _os_trace_verify_printf(_l, _1); \ 481 + uint8_t buf[1024]; \ 482 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1); \ 483 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 484 + __asm__(""); /* avoid tailcall */ \ 485 + }) 486 + 487 + #define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \ 488 + _os_trace_verify_printf(_l, _1, _2); \ 489 + uint8_t buf[1024]; \ 490 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2); \ 491 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 492 + __asm__(""); /* avoid tailcall */ \ 493 + }) 494 + 495 + #define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \ 496 + _os_trace_verify_printf(_l, _1, _2, _3); \ 497 + uint8_t buf[1024]; \ 498 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3); \ 499 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 500 + __asm__(""); /* avoid tailcall */ \ 501 + }) 502 + 503 + #define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \ 504 + _os_trace_verify_printf(_l, _1, _2, _3, _4); \ 505 + uint8_t buf[1024]; \ 506 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4); \ 507 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 508 + __asm__(""); /* avoid tailcall */ \ 509 + }) 510 + 511 + #define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \ 512 + _os_trace_verify_printf(_l, _1, _2, _3, _4, _5); \ 513 + uint8_t buf[1024]; \ 514 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5); \ 515 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 516 + __asm__(""); /* avoid tailcall */ \ 517 + }) 518 + 519 + #define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \ 520 + _os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6); \ 521 + uint8_t buf[1024]; \ 522 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6); \ 523 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 524 + __asm__(""); /* avoid tailcall */ \ 525 + }) 526 + 527 + #define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \ 528 + _os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6, _7); \ 529 + uint8_t buf[1024]; \ 530 + size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6, _7); \ 531 + _os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \ 532 + __asm__(""); /* avoid tailcall */ \ 533 + }) 534 + 535 + #endif /* if Mac OS >= 10.12 or iPhone OS >= 10.0 */ 536 + 537 + /*! 538 + * 539 + * @abstract 540 + * Hashtags in trace messages 541 + * 542 + * @discussion 543 + * Developers are encouraged to include hashtags in log messages, regardless of what API you use. 544 + * A hashtag is composed of a hash (#) symbol, followed by at least three non-whitespace characters, 545 + * terminated by whitespace or the end of the message. Hashtags may not begin with a number. 546 + * 547 + * Below is the list of predefined tags: 548 + * #System - Message in the context of a system process. 549 + * #User - Message in the context of a user process. 550 + * #Developer - Message in the context of software development. For example, deprecated APIs and debugging messages. 551 + * #Attention - Message that should be investigated by a system administrator, because it may be a sign of a larger issue. 552 + * For example, errors from a hard drive controller that typically occur when the drive is about to fail. 553 + * #Critical - Message in the context of a critical event or critical failure. 554 + * #Error - Message that is a noncritical error. 555 + * #Comment - Message that is a comment. 556 + * #Marker - Message that marks a change to divide the messages around it into those before and those after the change. 557 + * #Clue - Message containing extra key/value pairs with additional information to help reconstruct the context. 558 + * #Security - Message related to security concerns. 559 + * #Filesystem - Message describing a file system related event. 560 + * #Network - Message describing a network-related event. 561 + * #Hardware - Message describing a hardware-related event. 562 + * #CPU - Message describing CPU related event, e.g., initiating heavy work load 563 + * #State - Message describing state changed, e.g., global state, preference, etc. 564 + * #Graphics - Message describing significant graphics event 565 + * #Disk - Message describing disk activity 566 + * 567 + */ 568 + 569 + #pragma mark - Other defines 570 + 571 + /*! 572 + * @define OS_TRACE_TYPE_RELEASE 573 + * Trace messages to be captured on a typical user install. These should be 574 + * limited to things which improve diagnosis of a failure/crash/hang. Trace 575 + * buffers are generally smaller on a production system. 576 + */ 577 + #define OS_TRACE_TYPE_RELEASE (1u << 0) 578 + 579 + /*! 580 + * @define OS_TRACE_TYPE_DEBUG 581 + * Trace messages to be captured while debugger or other development tool is 582 + * attached to the originator. 583 + */ 584 + #define OS_TRACE_TYPE_DEBUG (1u << 1) 585 + 586 + /*! 587 + * @define OS_TRACE_TYPE_INFO 588 + * Trace messages that are captured when a debugger is attached, system or 589 + * Application mode has been increased to include additional information. 590 + */ 591 + #define OS_TRACE_TYPE_INFO (1u << 2) 592 + 593 + /*! 594 + * @define OS_TRACE_TYPE_ERROR 595 + * Trace the message as an error and force a collection as a failure may be 596 + * imminent. 597 + */ 598 + #define OS_TRACE_TYPE_ERROR ((1u << 6) | (1u << 0)) 599 + 600 + /*! 601 + * @define OS_TRACE_TYPE_FAULT 602 + * Trace the message as a fatal error which forces a collection and a diagnostic 603 + * to be initiated. 604 + */ 605 + #define OS_TRACE_TYPE_FAULT ((1u << 7) | (1u << 6) | (1u << 0)) 606 + 607 + /*! 608 + * @typedef os_trace_payload_t 609 + * A block that populates an xpc_object_t of type XPC_TYPE_DICTIONARY to represent 610 + * complex data. This block will only be invoked under conditions where tools 611 + * have attached to the process. The payload can be used to send arbitrary data 612 + * via the trace call. Tools may use the data to validate state for integration 613 + * tests or provide other introspection services. No assumptions are made about 614 + * the format or structure of the data. 615 + */ 616 + typedef void (^os_trace_payload_t)(xpc_object_t xdict); 617 + 618 + #pragma mark - function declarations 619 + 620 + /*! 621 + * @function os_trace 622 + * 623 + * @abstract 624 + * Always inserts a trace message into a buffer pool for later decoding. 625 + * 626 + * @discussion 627 + * Trace message that will be recorded on a typical user install. These should 628 + * be limited to things which help diagnose a failure during postmortem 629 + * analysis. Trace buffers are generally smaller on a production system. 630 + * 631 + * @param format 632 + * A printf-style format string to generate a human-readable log message when 633 + * the trace line is decoded. Only scalar types are supported, attempts 634 + * to pass arbitrary strings will store a pointer that is unresolvable and 635 + * will generate an error during decode. 636 + * 637 + * os_trace("network event: %ld, last seen: %ld, avg: %g", event_id, last_seen, avg); 638 + */ 639 + #define os_trace(format, ...) __extension__({ \ 640 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 641 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 642 + OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \ 643 + }) 644 + 645 + 646 + #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_10_0) \ 647 + || (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED >= __WATCHOS_3_0) \ 648 + || (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED >= __TVOS_10_0) \ 649 + || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12) 650 + 651 + /*! 652 + * @function os_trace_info 653 + * 654 + * @abstract 655 + * Optionally inserts a trace message containing additional information into a 656 + * buffer pool for later decoding. 657 + * 658 + * @discussion 659 + * Trace messages that will be captured when additional information is needed 660 + * and are not captured by default. They will only be captured if the 661 + * system/process/activity mode has been increased or if a Development tool has 662 + * been attached to the process. 663 + * 664 + * @param format 665 + * A printf-style format string that represents a human-readable message when 666 + * the trace line is decoded. Only scalar types are supported, attempts 667 + * to pass arbitrary strings will store a pointer that is unresolvable and 668 + * will generate an error during decode. 669 + * 670 + * os_trace_info("network interface status %ld", status); 671 + */ 672 + #define os_trace_info(format, ...) __extension__({ \ 673 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 674 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 675 + OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \ 676 + }) 677 + 678 + #endif 679 + 680 + /*! 681 + * @function os_trace_debug 682 + * 683 + * @abstract 684 + * Insert debug trace message into a buffer pool for later decoding. 685 + * 686 + * @discussion 687 + * Debug trace message to be recorded while debugger or other development tool is 688 + * attached to the originator. This is transported interprocess to help 689 + * diagnose the entire call chain including external helpers. 690 + * 691 + * @param format 692 + * A printf-style format string that represents a human-readable message when 693 + * the trace line is decoded. Only scalar types are supported, attempts 694 + * to pass arbitrary strings will store a pointer that is unresolvable and 695 + * will generate an error during decode. 696 + * 697 + * os_trace_debug("network interface status %ld", status); 698 + */ 699 + #define os_trace_debug(format, ...) __extension__({ \ 700 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 701 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 702 + OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \ 703 + }) 704 + 705 + /*! 706 + * @function os_trace_info_enabled 707 + * 708 + * @abstract 709 + * Avoid unnecessary work for a trace point by checking if additional information 710 + * is enabled. 711 + * 712 + * @discussion 713 + * Avoid unnecessary work for a trace point by checking if additional information 714 + * is enabled. Generally trace points should not involve expensive operations, but some 715 + * circumstances warrant it. Use this function to avoid doing the work unless 716 + * debug level trace messages are requested. 717 + * 718 + * if (os_trace_info_enabled()) { 719 + * os_trace_info("value = %d, average = %d", 720 + * [[dict objectForKey: @"myKey"] intValue], 721 + * (int) [self getAverage: dict]); 722 + * } 723 + * 724 + * @result 725 + * Returns true if development mode is enabled. 726 + */ 727 + __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0) 728 + OS_EXPORT OS_NOTHROW OS_WARN_RESULT 729 + bool 730 + os_trace_info_enabled(void); 731 + 732 + /*! 733 + * @function os_trace_debug_enabled 734 + * 735 + * @abstract 736 + * Avoid unnecessary work for a trace point by checking if debug level is enabled. 737 + * 738 + * @discussion 739 + * Avoid unnecessary work for a trace point by checking if debug level is enabled. 740 + * Generally trace points should not involve expensive operations, but some 741 + * circumstances warrant it. Use this function to avoid doing the work unless 742 + * debug level trace messages are requested. 743 + * 744 + * if (os_trace_debug_enabled()) { 745 + * os_trace_debug("value = %d, average = %d", 746 + * [[dict objectForKey: @"myKey"] intValue], 747 + * (int) [self getAverage: dict]); 748 + * } 749 + * 750 + * @result 751 + * Returns true if debug mode is enabled. 752 + */ 753 + __OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0) 754 + OS_EXPORT OS_NOTHROW OS_WARN_RESULT 755 + bool 756 + os_trace_debug_enabled(void); 757 + 758 + /*! 759 + * @function os_trace_error 760 + * 761 + * @abstract 762 + * Trace the message as an error and force a collection of the trace buffer as a 763 + * failure may be imminent. 764 + * 765 + * @discussion 766 + * Trace the message as an error and force a collection of the trace buffer as a 767 + * failure may be imminent. 768 + * 769 + * @param format 770 + * A printf-style format string to generate a human-readable log message when 771 + * the trace line is decoded. Only scalar types are supported, attempts 772 + * to pass arbitrary strings will store a pointer that is unresolvable and 773 + * will generate an error during decode. 774 + * 775 + * os_trace_error("socket %d connection timeout %ld", fd, secs); 776 + */ 777 + #define os_trace_error(format, ...) __extension__({ \ 778 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 779 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 780 + OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \ 781 + }) 782 + 783 + /*! 784 + * @function os_trace_fault 785 + * 786 + * @abstract 787 + * Trace the message as a fault which forces a collection of the trace buffer 788 + * and diagnostic of the activity. 789 + * 790 + * @discussion 791 + * Trace the message as a fault which forces a collection of the trace buffer 792 + * and diagnostic of the activity. 793 + * 794 + * @param format 795 + * A printf-style format string to generate a human-readable log message when 796 + * the trace line is decoded. Only scalar types are supported, attempts 797 + * to pass arbitrary strings will store a pointer that is unresolvable and 798 + * will generate an error during decode. 799 + * 800 + * os_trace_fault("failed to lookup uid %d - aborting", uid); 801 + */ 802 + #define os_trace_fault(format, ...) __extension__({ \ 803 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 804 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 805 + OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \ 806 + }) 807 + 808 + #if __has_include(<xpc/xpc.h>) 809 + /*! 810 + * @function os_trace_with_payload 811 + * 812 + * @abstract 813 + * Add a trace entry containing the provided values and call the block if 814 + * appropriate. 815 + * 816 + * @discussion 817 + * Will insert a trace entry into a limited ring buffer for an activity or 818 + * process. Trace points are for recording interesting data that would improve 819 + * diagnosis of unexpected crashes, failures and hangs. The block will only be 820 + * called under the required conditions. 821 + * 822 + * @param trace_msg 823 + * A printf-style format string to generate a human-readable log message when 824 + * the trace line is decoded. Only scalar types are supported. Attempts 825 + * to pass arbitrary strings will store a pointer that is unresolvable and 826 + * will generate an error during decode. 827 + * 828 + * The final parameter must be a block of type os_trace_payload_t. 829 + * 830 + * os_trace_with_payload("network event %ld", event, ^(xpc_object_t xdict) { 831 + * 832 + * // validate the network interface and address where what was expected 833 + * xpc_dictionary_set_string(xdict, "network", ifp->ifa_name); 834 + * xpc_dictionary_set_string(xdict, "ip_address", _get_address(ifp)); 835 + * }); 836 + */ 837 + #define os_trace_with_payload(format, ...) __extension__({ \ 838 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 839 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 840 + OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \ 841 + }) 842 + 843 + #define os_trace_info_with_payload(format, ...) __extension__({ \ 844 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 845 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 846 + OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \ 847 + }) 848 + 849 + #define os_trace_debug_with_payload(format, ...) __extension__({ \ 850 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 851 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 852 + OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \ 853 + }) 854 + 855 + #define os_trace_error_with_payload(format, ...) __extension__({ \ 856 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 857 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 858 + OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \ 859 + }) 860 + 861 + #define os_trace_fault_with_payload(format, ...) __extension__({ \ 862 + _Static_assert(__builtin_constant_p(format), "format must be a constant string"); \ 863 + __attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \ 864 + OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \ 865 + }) 866 + 867 + #endif // __has_include(<xpc/xpc.h>) 868 + 869 + // TODO: change this once we have compiler support 870 + __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0) 871 + OS_EXPORT OS_NOTHROW 872 + size_t 873 + _os_trace_encode(uint8_t *buf, size_t buf_size, const char *format, ...); 874 + 875 + __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0) 876 + OS_EXPORT OS_NOTHROW 877 + void 878 + _os_trace_internal(void *dso, uint8_t type, const char *format, const uint8_t *buf, size_t buf_size, os_trace_payload_t payload); 879 + 880 + /*! 881 + * @function _os_trace_with_buffer 882 + * 883 + * @abstract 884 + * Internal function to support pre-encoded buffer. 885 + */ 886 + __OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0) 887 + OS_EXPORT OS_NOTHROW 888 + void 889 + _os_trace_with_buffer(void *dso, const char *message, uint8_t type, const void *buffer, size_t buffer_size, os_trace_payload_t payload); 890 + 891 + __END_DECLS 892 + 893 + #endif // __OS_TRACE_H__
+10 -4
src/duct/src/CMakeLists.txt
··· 8 8 add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080) 9 9 10 10 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") 11 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress") 11 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load") 12 12 13 13 SET(duct_sources 14 14 commpage.c libnotify.c numcpus.c 15 15 CRGetCrashLogMessage.c acl.c bootstrap.c dns_sd.c 16 - sa_dst_compare.c asl.c) 16 + sa_dst_compare.c os_log.c) 17 17 18 18 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_duct.dylib") 19 - add_darling_library(system_duct SHARED ${duct_sources}) 20 - make_fat(system_duct) 19 + add_circular(system_duct FAT 20 + SOURCES 21 + ${duct_sources} 22 + SIBLINGS 23 + system_kernel 24 + system_dyld 25 + ) 26 + #make_fat(system_duct) 21 27 22 28 set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar") 23 29 set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib")
-8
src/duct/src/acl.c
··· 7 7 { 8 8 return 0; 9 9 } 10 - 11 - void _simple_asl_msg_set() 12 - { 13 - } 14 - 15 - void _simple_asl_send() 16 - { 17 - }
-71
src/duct/src/asl.c
··· 1 - #include <stddef.h> 2 - 3 - int asl_close() 4 - { 5 - return 0; 6 - } 7 - 8 - int asl_get() 9 - { 10 - return 0; 11 - } 12 - 13 - int asl_open() 14 - { 15 - return 0; 16 - } 17 - 18 - int asl_set_query() 19 - { 20 - return 0; 21 - } 22 - 23 - int asl_store_match_timeout() 24 - { 25 - return 0; 26 - } 27 - 28 - int asl_new() 29 - { 30 - return 0; 31 - } 32 - 33 - int asl_free() 34 - { 35 - return 0; 36 - } 37 - 38 - int aslresponse_free() 39 - { 40 - return 0; 41 - } 42 - 43 - int asl_set() 44 - { 45 - return 0; 46 - } 47 - 48 - int aslresponse_next() 49 - { 50 - return 0; 51 - } 52 - 53 - int asl_store_open_read() 54 - { 55 - return 0; 56 - } 57 - 58 - int asl_send() 59 - { 60 - return 0; 61 - } 62 - 63 - int asl_store_close() 64 - { 65 - return 0; 66 - } 67 - 68 - void* _simple_asl_msg_new() 69 - { 70 - return NULL; 71 - }
+11
src/duct/src/os_log.c
··· 1 + int _os_log_default; 2 + 3 + int os_log_shim_legacy_logging_enabled(void) 4 + { 5 + return 0; 6 + } 7 + 8 + int os_log_shim_with_va_list() 9 + { 10 + return 0; 11 + }
+1 -1
src/duct/src/sa_dst_compare.c
··· 1 1 // This function is called from _gai_addr_sort() 2 - // No implementation seems to be available. 2 + // On macOS, it resides in libsystem_network.dylib, which is not open source. 3 3 4 4 int sa_dst_compare() 5 5 {
+16 -6
src/dyld-apple/CMakeLists.txt
··· 34 34 ${CMAKE_CURRENT_SOURCE_DIR}/include/mach-o) 35 35 36 36 set(DYLIB_INSTALL_NAME "/usr/lib/system/libdyld.dylib") 37 - add_darling_library(system_dyld SHARED 37 + add_circular(system_dyld FAT 38 + SOURCES 38 39 src/dyldAPIsInLibSystem.cpp 39 40 src/dyld_stub_binder.S 40 41 src/dyldLibSystemGlue.c ··· 42 43 src/dyldLock.cpp 43 44 src/threadLocalVariables.c 44 45 src/start_glue.S 46 + SIBLINGS 47 + system_c system_kernel compiler_rt platform 48 + DEPENDENCIES 49 + launch 45 50 ) 46 51 set_target_properties(system_dyld PROPERTIES 47 - OUTPUT_NAME "dyld" 48 - COMPILE_FLAGS "-fno-exceptions -fno-rtti") 49 - target_link_libraries(system_dyld PRIVATE system_c system_kernel compiler_rt launch) 52 + OUTPUT_NAME "dyld") 53 + set_property(TARGET system_dyld_obj APPEND_STRING PROPERTY 54 + COMPILE_FLAGS " -fno-exceptions -fno-rtti") 55 + #target_link_libraries(system_dyld PRIVATE platform_static32 platform_static64 system_c system_kernel compiler_rt launch) 50 56 51 57 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_SAVED} -nostdlib") 52 58 ··· 74 80 use_ld64(system_loader) 75 81 set_target_properties(system_loader PROPERTIES OUTPUT_NAME "dyld") 76 82 set_property(TARGET system_loader APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dylinker -Wl,-dead_strip -nostdlib -Wl,-e,__dyld_start") 77 - target_link_libraries(system_loader libc_static system_blocks_static unwind_static system_kernel_static system_m_static cxxabi_static keymgr_static compiler_rt_static32 compiler_rt_static64 system_duct_static) 83 + target_link_libraries(system_loader libc_static system_blocks_static 84 + libc_static32 libc_static64 85 + unwind_static system_kernel_static system_m_static cxxabi_static 86 + keymgr_static compiler_rt_static32 compiler_rt_static64 system_duct_static 87 + platform_static32 platform_static64 pthread_static) 78 88 79 - make_fat(system_dyld) 89 + #make_fat(system_dyld) 80 90 81 91 install(TARGETS system_dyld DESTINATION libexec/darling/usr/lib/system) 82 92 install(TARGETS system_loader DESTINATION libexec/darling/usr/lib)
+1
src/dyld/CMakeLists.txt
··· 20 20 mldr.c 21 21 threads.c 22 22 gdb.c 23 + commpage.c 23 24 ) 24 25 add_executable(mldr ${mldr_sources}) 25 26 target_link_libraries(mldr -lpthread -ldl)
+138
src/dyld/commpage.c
··· 1 + #include "commpage.h" 2 + #include <sys/mman.h> 3 + #include <stdio.h> 4 + #include <errno.h> 5 + #include <string.h> 6 + #include <stdlib.h> 7 + #include <cpuid.h> 8 + #include <unistd.h> 9 + #include <sys/sysinfo.h> 10 + 11 + // Include commpage definitions 12 + #define PRIVATE 13 + #include "../../kernel-include/i386/cpu_capabilities.h" 14 + 15 + static const char* SIGNATURE32 = "commpage 32-bit"; 16 + static const char* SIGNATURE64 = "commpage 64-bit"; 17 + 18 + static uint64_t get_cpu_caps(void); 19 + 20 + void commpage_setup(bool _64bit) 21 + { 22 + void* commpage; 23 + uint64_t* cpu_caps64; 24 + uint32_t* cpu_caps; 25 + uint16_t* version; 26 + char* signature; 27 + uint64_t my_caps; 28 + uint8_t *ncpus, *nactivecpus; 29 + struct sysinfo si; 30 + 31 + commpage = mmap((void*)(_64bit ? _COMM_PAGE64_BASE_ADDRESS : _COMM_PAGE32_BASE_ADDRESS), 32 + _64bit ? _COMM_PAGE64_AREA_LENGTH : _COMM_PAGE32_AREA_LENGTH, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 33 + if (commpage == MAP_FAILED) 34 + { 35 + fprintf(stderr, "Cannot mmap commpage: %s\n", strerror(errno)); 36 + exit(1); 37 + } 38 + 39 + signature = (char*)_COMM_PAGE_SIGNATURE; 40 + version = (uint16_t*)_COMM_PAGE_VERSION; 41 + cpu_caps64 = (uint64_t*)_COMM_PAGE_CPU_CAPABILITIES64; 42 + cpu_caps = (uint32_t*)_COMM_PAGE_CPU_CAPABILITIES; 43 + 44 + strcpy(signature, _64bit ? SIGNATURE64 : SIGNATURE32); 45 + *version = _COMM_PAGE_THIS_VERSION; 46 + 47 + ncpus = (uint8_t*)_COMM_PAGE_NCPUS; 48 + *ncpus = sysconf(_SC_NPROCESSORS_CONF); 49 + 50 + nactivecpus = (uint8_t*)_COMM_PAGE_ACTIVE_CPUS; 51 + *nactivecpus = sysconf(_SC_NPROCESSORS_ONLN); 52 + 53 + my_caps = get_cpu_caps(); 54 + if (*ncpus == 1) 55 + my_caps |= kUP; 56 + 57 + *cpu_caps = (uint32_t) my_caps; 58 + *cpu_caps64 = my_caps; 59 + 60 + if (sysinfo(&si) == 0) 61 + { 62 + uint64_t* memsize = (uint64_t*)_COMM_PAGE_MEMORY_SIZE; 63 + *memsize = si.totalram * si.mem_unit; 64 + } 65 + } 66 + 67 + uint64_t get_cpu_caps(void) 68 + { 69 + uint64_t caps = 0; 70 + 71 + { 72 + union cpu_flags1 eax; 73 + union cpu_flags2 ecx; 74 + union cpu_flags3 edx; 75 + uint32_t ebx; 76 + 77 + eax.reg = ecx.reg = edx.reg = 0; 78 + __cpuid(1, eax.reg, ebx, ecx.reg, edx.reg); 79 + 80 + if (ecx.mmx) 81 + caps |= kHasMMX; 82 + if (ecx.sse) 83 + caps |= kHasSSE; 84 + if (ecx.sse2) 85 + caps |= kHasSSE2; 86 + if (edx.sse3) 87 + caps |= kHasSSE3; 88 + if (ecx.ia64) 89 + caps |= k64Bit; 90 + if (edx.ssse3) 91 + caps |= kHasSupplementalSSE3; 92 + if (edx.sse41) 93 + caps |= kHasSSE4_1; 94 + if (edx.sse42) 95 + caps |= kHasSSE4_2; 96 + if (edx.aes) 97 + caps |= kHasAES; 98 + if (edx.avx) 99 + caps |= kHasAVX1_0; 100 + if (edx.rdrnd) 101 + caps |= kHasRDRAND; 102 + if (edx.fma) 103 + caps |= kHasFMA; 104 + if (edx.f16c) 105 + caps |= kHasF16C; 106 + } 107 + { 108 + union cpu_flags4 ebx; 109 + union cpu_flags5 ecx; 110 + uint32_t edx = 0, eax = 7; 111 + 112 + __cpuid(7, eax, ebx.reg, ecx.reg, edx); 113 + 114 + if (ebx.erms) 115 + caps |= kHasENFSTRG; 116 + if (ebx.avx2) 117 + caps |= kHasAVX2_0; 118 + if (ebx.bmi1) 119 + caps |= kHasBMI1; 120 + if (ebx.bmi2) 121 + caps |= kHasBMI2; 122 + if (ebx.rtm) 123 + caps |= kHasRTM; 124 + if (ebx.hle) 125 + caps |= kHasHLE; 126 + if (ebx.rdseed) 127 + caps |= kHasRDSEED; 128 + if (ebx.adx) 129 + caps |= kHasADX; 130 + if (ebx.mpx) 131 + caps |= kHasMPX; 132 + if (ebx.sgx) 133 + caps |= kHasSGX; 134 + } 135 + 136 + return caps; 137 + } 138 +
+146
src/dyld/commpage.h
··· 1 + #ifndef _COMMPAGE_H 2 + #define _COMMPAGE_H 3 + #include <stdbool.h> 4 + #include <stdint.h> 5 + 6 + void commpage_setup(bool _64bit); 7 + 8 + union cpu_flags1 { 9 + struct { 10 + uint8_t step: 4; 11 + uint8_t model: 4; 12 + uint8_t family: 4; 13 + uint8_t type: 2; 14 + uint8_t pad1: 2; 15 + uint8_t emodel: 4; 16 + uint8_t efamily: 8; 17 + uint8_t pad2: 4; 18 + }; 19 + uint32_t reg; 20 + }; 21 + 22 + union cpu_flags2 { 23 + struct { 24 + uint8_t fpu: 1; 25 + uint8_t vme: 1; 26 + uint8_t de: 1; 27 + uint8_t pse: 1; 28 + uint8_t tsc: 1; 29 + uint8_t msr: 1; 30 + uint8_t pae: 1; 31 + uint8_t mce: 1; 32 + uint8_t cx8: 1; 33 + uint8_t apic: 1; 34 + uint8_t reserved1: 1; 35 + uint8_t sep: 1; 36 + uint8_t mtrr: 1; 37 + uint8_t pge: 1; 38 + uint8_t mca: 1; 39 + uint8_t cmov: 1; 40 + uint8_t pat: 1; 41 + uint8_t pse36: 1; 42 + uint8_t psn: 1; 43 + uint8_t clfsh: 1; 44 + uint8_t reserved2: 1; 45 + uint8_t ds: 1; 46 + uint8_t acpi: 1; 47 + uint8_t mmx: 1; 48 + uint8_t fxsr: 1; 49 + uint8_t sse: 1; 50 + uint8_t sse2: 1; 51 + uint8_t ss: 1; 52 + uint8_t htt: 1; 53 + uint8_t tm: 1; 54 + uint8_t ia64: 1; 55 + uint8_t pbe: 1; 56 + }; 57 + uint32_t reg; 58 + }; 59 + 60 + union cpu_flags3 { 61 + struct { 62 + uint32_t sse3: 1; 63 + uint32_t pclmulqdq: 1; 64 + uint32_t dtes64: 1; 65 + uint32_t monitor: 1; 66 + uint32_t dscpl: 1; 67 + uint32_t vmx: 1; 68 + uint32_t smx: 1; 69 + uint32_t est: 1; 70 + uint32_t tm2: 1; 71 + uint32_t ssse3: 1; 72 + uint32_t cntxid: 1; 73 + uint32_t sdbg: 1; 74 + uint32_t fma: 1; 75 + uint32_t cx16: 1; 76 + uint32_t xtpr: 1; 77 + uint32_t pdcm: 1; 78 + uint32_t reserved1: 1; 79 + uint32_t pcid: 1; 80 + uint32_t dca: 1; 81 + uint32_t sse41: 1; 82 + uint32_t sse42: 1; 83 + uint32_t x2apic: 1; 84 + uint32_t movbe: 1; 85 + uint32_t popcnt: 1; 86 + uint32_t tscdadline: 1; 87 + uint32_t aes: 1; 88 + uint32_t xsave: 1; 89 + uint32_t osxsave: 1; 90 + uint32_t avx: 1; 91 + uint32_t f16c: 1; 92 + uint32_t rdrnd: 1; 93 + uint32_t hypervisor: 1; 94 + }; 95 + uint32_t reg; 96 + }; 97 + 98 + union cpu_flags4 { 99 + struct { 100 + uint8_t fsgsbase: 1; 101 + uint8_t ia32tscadjust: 1; 102 + uint8_t sgx: 1; 103 + uint8_t bmi1: 1; 104 + uint8_t hle: 1; 105 + uint8_t avx2: 1; 106 + uint8_t reserved1: 1; 107 + uint8_t smep: 1; 108 + uint8_t bmi2: 1; 109 + uint8_t erms: 1; 110 + uint8_t invpcid: 1; 111 + uint8_t rtm: 1; 112 + uint8_t pqm: 1; 113 + uint8_t fpucsdsdeprecated: 1; 114 + uint8_t mpx: 1; 115 + uint8_t pqe: 1; 116 + uint8_t avx512f: 1; 117 + uint8_t avx512dq: 1; 118 + uint8_t rdseed: 1; 119 + uint8_t adx: 1; 120 + uint8_t smap: 1; 121 + uint8_t avx512ifma: 1; 122 + uint8_t pcommit: 1; 123 + uint8_t clflushopt: 1; 124 + uint8_t clwb: 1; 125 + uint8_t intelproctrace: 1; 126 + uint8_t avx512pf: 1; 127 + uint8_t avx512er: 1; 128 + uint8_t avx512cd: 1; 129 + uint8_t sha: 1; 130 + uint8_t avx512bw: 1; 131 + uint8_t avx512vl: 1; 132 + }; 133 + uint32_t reg; 134 + }; 135 + 136 + union cpu_flags5 { 137 + struct { 138 + uint8_t prefetchwt1: 1; 139 + uint8_t avx512vbmi: 1; 140 + uint32_t reserved: 30; 141 + }; 142 + uint32_t reg; 143 + }; 144 + 145 + #endif 146 +
+21 -2
src/dyld/mldr.c
··· 1 1 /* 2 2 This file is part of Darling. 3 3 4 - Copyright (C) 2016 Lubos Dolezel 4 + Copyright (C) 2017 Lubos Dolezel 5 5 6 6 Darling is free software: you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by ··· 34 34 #include "elfcalls.h" 35 35 #include "threads.h" 36 36 #include "gdb.h" 37 + #include "commpage.h" 37 38 38 39 #ifndef PAGE_SIZE 39 40 # define PAGE_SIZE 4096 ··· 54 55 static int native_prot(int prot); 55 56 static void apply_root_path(char* path); 56 57 static char* elfcalls_make(void); 58 + static char* apple0_make(const char* filepath); 57 59 58 60 int main(int argc, char** argv, char** envp) 59 61 { ··· 106 108 # error Unsupported platform! 107 109 #endif 108 110 109 - apple[0] = filename; 111 + apple[0] = apple0_make(filename); 110 112 apple[1] = elfcalls_make(); 111 113 apple[2] = NULL; 112 114 ··· 157 159 158 160 if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) 159 161 { 162 + if (mh_out) 163 + commpage_setup(true); 164 + 160 165 lseek(fd, 0, SEEK_SET); 161 166 load64(fd, entryPoint_out, mh_out); 162 167 } 163 168 else if (magic == FAT_MAGIC || magic == FAT_CIGAM) 164 169 { 170 + if (mh_out) 171 + commpage_setup(false); 165 172 } 166 173 else 167 174 { ··· 412 419 return param; 413 420 } 414 421 422 + char* apple0_make(const char* filepath) 423 + { 424 + const char prefix[] = "executable_path="; 425 + char* apple0; 426 + 427 + apple0 = (char*) malloc(strlen(filepath) + sizeof(prefix)); 428 + strcpy(apple0, prefix); 429 + strcat(apple0, filepath); 430 + 431 + return apple0; 432 + } 433 +
+21 -11
src/kernel/CMakeLists.txt
··· 21 21 # -> dyld places stubs -> stubs go into dyld_stub_binder at first use 22 22 # -> there is a temporary loss of 16-byte stack alignment in __darling_bsd_syscall 23 23 # -> dyld_stub_binder checks for this and bails out with a SIGSEGV 24 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc -Wl,-bind_at_load -Wl,-undefined,suppress -Wl,-flat_namespace") 24 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc -Wl,-bind_at_load") 25 25 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 26 26 27 + #set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_c.dylib") 28 + #add_darling_library(fakelibc SHARED fakelibc.c) 29 + #make_fat(fakelibc) 30 + #set(DYLIB_INSTALL_NAME "/usr/lib/system/libdyld.dylib") 31 + #add_darling_library(fakedyld SHARED fakedyld.c) 32 + #make_fat(fakedyld) 27 33 28 34 add_definitions(-DTARGET_OS_MAC=1) 29 35 add_definitions(-DHAVE_STDINT_H=1) ··· 33 39 add_subdirectory(mach_server/client) 34 40 35 41 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_kernel.dylib") 36 - add_darling_library(system_kernel SHARED 37 - $<TARGET_OBJECTS:libsyscall> 38 - $<TARGET_OBJECTS:libsyscall_dynamic> 39 - #$<TARGET_OBJECTS:kqueue> 40 - $<TARGET_OBJECTS:emulation> 41 - ${extra_objs} 42 - $<TARGET_OBJECTS:mach_server_client>) 43 - target_link_libraries(system_kernel system_duct) 42 + add_circular(system_kernel FAT 43 + OBJECTS 44 + $<TARGET_OBJECTS:libsyscall> 45 + $<TARGET_OBJECTS:libsyscall_dynamic> 46 + #$<TARGET_OBJECTS:kqueue> 47 + $<TARGET_OBJECTS:emulation> 48 + $<TARGET_OBJECTS:mach_server_client> 49 + SIBLINGS 50 + system_c 51 + compiler_rt 52 + system_dyld 53 + ) 54 + #target_link_libraries(system_kernel system_duct platform_static32 platform_static64) 44 55 make_fat(system_kernel) 45 56 46 57 add_library(system_kernel_static STATIC 47 58 $<TARGET_OBJECTS:libsyscall> 48 - $<TARGET_OBJECTS:libsyscall_static> 59 + #$<TARGET_OBJECTS:libsyscall_static> 49 60 #$<TARGET_OBJECTS:kqueue> 50 61 $<TARGET_OBJECTS:emulation_dyld> 51 - ${extra_objs} 52 62 $<TARGET_OBJECTS:mach_server_client_dyld>) 53 63 54 64 install(TARGETS system_kernel DESTINATION libexec/darling/usr/lib/system)
+5 -1
src/kernel/emulation/linux/CMakeLists.txt
··· 13 13 -DEMULATED_RELEASE="12.0.0" 14 14 -DEMULATED_VERSION="Darwin Kernel Version 12.0.0") 15 15 16 + 16 17 include_directories(${CMAKE_SOURCE_DIR}/src/dyld) 17 18 include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 18 19 ··· 22 23 syscalls.c 23 24 simple.c 24 25 errno.c 25 - tls.c 26 26 readline.c 27 + machdep/machdeps.c 28 + machdep/machdep-table.S 29 + machdep/tls.c 27 30 unistd/write.c 28 31 unistd/read.c 29 32 unistd/pread.c ··· 97 100 signal/sigprocmask.c 98 101 signal/sig_restorer.S 99 102 signal/sigsuspend.c 103 + misc/getentropy.c 100 104 misc/syscall.c 101 105 misc/shared_region_check_np.c 102 106 misc/ioctl.c
+6
src/kernel/emulation/linux/base.c
··· 11 11 return -ENOSYS; 12 12 } 13 13 14 + long __unknown_syscall_machdep(int nr, ...) 15 + { 16 + __simple_printf("Unimplemented machdep trap (%d)\n", nr); 17 + return -ENOSYS; 18 + } 19 + 14 20 int __linux_syscall(int nr, long a1, long a2, long a3, long a4, long a5, long a6) 15 21 { 16 22 return linux_syscall(a1, a2, a3, a4, a5, a6, nr);
+69
src/kernel/emulation/linux/machdep/machdep-table.S
··· 1 + .text 2 + .globl __darling_machdep_syscall 3 + .private_extern __darling_machdep_syscall 4 + 5 + #if defined(__x86_64__) 6 + 7 + __darling_machdep_syscall: 8 + movq ___machdep_syscall_table@GOTPCREL(%rip), %r10 9 + andq $0xff, %rax 10 + movq (%r10,%rax,8), %r10 11 + test %r10, %r10 12 + jz .no_sys 13 + # Re-push possible 7th and 8th arg 14 + movq 24(%rsp), %r11 15 + pushq %r11 16 + movq 24(%rsp), %r11 17 + pushq %r11 18 + call *%r10 19 + addq $16, %rsp 20 + ret 21 + .no_sys: 22 + movq %rax, %rdi 23 + call ___unknown_syscall_machdep 24 + ret 25 + 26 + #elif defined(__i386__) 27 + 28 + #define copy_arg(off) \ 29 + movl 8+off(%esp), %ecx ;\ 30 + movl %ecx, -24+off(%esp) 31 + 32 + __darling_machdep_syscall: 33 + calll .L0$pb 34 + .L0$pb: 35 + popl %ecx 36 + .Ltmp0: 37 + movl L___machdep_syscall_table$non_lazy_ptr-.L0$pb(%ecx), %ecx 38 + andl $0xffff, %eax // Because there is some extra stuff in upper bytes we don't need 39 + movl (%ecx,%eax,4), %eax 40 + test %eax, %eax 41 + jz .no_sys 42 + // Copy arguments 43 + copy_arg(0) 44 + copy_arg(4) 45 + copy_arg(8) 46 + copy_arg(12) 47 + copy_arg(16) 48 + copy_arg(20) 49 + subl $24, %esp 50 + call *%eax 51 + addl $24, %esp 52 + ret 53 + .no_sys: 54 + pushl %ecx 55 + call ___unknown_syscall_machdep 56 + addl $4, %esp 57 + ret 58 + 59 + .section __IMPORT,__pointers,non_lazy_symbol_pointers 60 + L___machdep_syscall_table$non_lazy_ptr: 61 + .indirect_symbol ___machdep_syscall_table 62 + .long 0 63 + 64 + .subsections_via_symbols 65 + 66 + #else 67 + # error Missing assembly 68 + #endif 69 +
+7
src/kernel/emulation/linux/machdep/machdeps.c
··· 1 + #include "machdeps.h" 2 + #include "tls.h" 3 + 4 + void* __machdep_syscall_table[10] = { 5 + [3] = sys_thread_set_tsd_base, 6 + }; 7 +
+7
src/kernel/emulation/linux/machdep/machdeps.h
··· 1 + #ifndef _MACHDEPS_H 2 + #define _MACHDEPS_H 3 + 4 + extern void* __machdep_syscall_table[10]; 5 + 6 + #endif 7 +
+8
src/kernel/emulation/linux/machdep/tls.h
··· 1 + #ifndef LINUX_TLS_H 2 + #define LINUX_TLS_H 3 + #include "base.h" 4 + 5 + void sys_thread_set_tsd_base(void* ptr, int unk); 6 + 7 + #endif 8 +
+18
src/kernel/emulation/linux/misc/getentropy.c
··· 1 + #include "getentropy.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <linux-syscalls/linux.h> 5 + 6 + #define LINUX_GRND_RANDOM 2 7 + 8 + long sys_getentropy(void* buf, unsigned long size) 9 + { 10 + int ret; 11 + 12 + ret = LINUX_SYSCALL(__NR_getrandom, buf, size, LINUX_GRND_RANDOM); 13 + if (ret < 0) 14 + ret = errno_linux_to_bsd(ret); 15 + 16 + return ret; 17 + } 18 +
+7
src/kernel/emulation/linux/misc/getentropy.h
··· 1 + #ifndef LINUX_GETENTROPY_H 2 + #define LINUX_GETENTROPY_H 3 + 4 + long sys_getentropy(void* buf, unsigned long size); 5 + 6 + #endif 7 +
+14
src/kernel/emulation/linux/misc/sysctl.c
··· 319 319 __simple_printf("Unknown sysctl: %s\n", name); 320 320 return -ENOTDIR; 321 321 } 322 + 323 + long sys_sysctlbyname(const char* name, unsigned long namelen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen) 324 + { 325 + long rv; 326 + int oid[4]; 327 + unsigned long oid_len = 4; 328 + 329 + rv = sysctl_name_to_oid(name, oid, &oid_len); 330 + if (rv < 0) 331 + return rv; 332 + 333 + return sys_sysctl(oid, oid_len, old, oldlen, _new, newlen); 334 + } 335 +
+1
src/kernel/emulation/linux/misc/sysctl.h
··· 2 2 #define LINUX_SYSCTL_H 3 3 4 4 long sys_sysctl(int* name, unsigned int nlen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen); 5 + long sys_sysctlbyname(const char* name, unsigned long namelen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen); 5 6 6 7 #endif 7 8
-1
src/kernel/emulation/linux/process/execve.c
··· 20 20 extern int strcmp(const char *s1, const char *s2); 21 21 extern char *strcat(char *dest, const char *src); 22 22 extern char *strcpy(char *dest, const char *src); 23 - extern void* memchr(const void* s, int c, __SIZE_TYPE__ n); 24 23 extern char* strchr(const char* s, int c); 25 24 extern int strncmp(const char *s1, const char *s2, __SIZE_TYPE__ n); 26 25 extern __SIZE_TYPE__ strlen(const char *s);
+1 -1
src/kernel/emulation/linux/readline.c
··· 2 2 #include <stddef.h> 3 3 #include "unistd/read.h" 4 4 5 - extern void *memchr(const void *s, int c, __SIZE_TYPE__ n); 6 5 extern void *memmove(void *dest, const void *src, __SIZE_TYPE__ n); 6 + extern char* memchr(char* buf, int c, __SIZE_TYPE__ n); 7 7 8 8 const char* _readline(int fd, struct rdline_buffer* buf) 9 9 {
+1 -1
src/kernel/emulation/linux/simple.c
··· 5 5 #include <linux-syscalls/linux.h> 6 6 7 7 void __simple_vsprintf(char* buf, const char* format, va_list vl); 8 + extern char* memchr(char* buf, int c, __SIZE_TYPE__ n); 8 9 9 10 int __simple_strlen(const char* text) 10 11 { ··· 190 191 191 192 extern void *memmove(void *dest, const void *src, __SIZE_TYPE__ n); 192 193 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 193 - extern void *memchr(const void *s, int c, __SIZE_TYPE__ n); 194 194 extern long sys_read(int fd, void* buf, __SIZE_TYPE__ n); 195 195 196 196 #ifndef min
+3
src/kernel/emulation/linux/syscalls.c
··· 68 68 #include "process/wait4.h" 69 69 #include "process/waitid.h" 70 70 #include "process/execve.h" 71 + #include "misc/getentropy.h" 71 72 #include "misc/getlogin.h" 72 73 #include "misc/shared_region_check_np.h" 73 74 #include "ioctl/ioctl.h" ··· 278 279 [240] = sys_listxattr, 279 280 [241] = sys_flistxattr, 280 281 [244] = sys_posix_spawn, 282 + [274] = sys_sysctlbyname, 281 283 [282] = sys_chmod_extended, 282 284 [283] = sys_fchmod_extended, 283 285 [294] = sys_shared_region_check_np, ··· 330 332 [415] = sys_pwrite_nocancel, 331 333 [417] = sys_poll_nocancel, 332 334 [423] = sys_semwait_signal_nocancel, 335 + [500] = sys_getentropy, 333 336 }; 334 337
+1 -1
src/kernel/emulation/linux/tls.c src/kernel/emulation/linux/machdep/tls.c
··· 3 3 4 4 #define ARCH_SET_GS 0x1001 5 5 6 - void __pthread_set_self(void* ptr) 6 + void sys_thread_set_tsd_base(void* ptr, int unk) 7 7 { 8 8 #ifdef __x86_64__ 9 9 LINUX_SYSCALL(__NR_arch_prctl, ARCH_SET_GS, ptr);
-8
src/kernel/emulation/linux/tls.h
··· 1 - #ifndef LINUX_TLS_H 2 - #define LINUX_TLS_H 3 - #include "base.h" 4 - 5 - VISIBLE void __pthread_set_self(void* ptr); 6 - 7 - #endif 8 -
+5 -3
src/kernel/libsyscall/CMakeLists.txt
··· 77 77 wrappers/clonefile.c 78 78 wrappers/coalition.c 79 79 wrappers/__commpage_gettimeofday.c 80 + wrappers/__commpage_gettimeofday_asm.S 81 + wrappers/__get_cpu_capabilities.S 80 82 wrappers/csr.c 81 83 wrappers/fs_snapshot.c 82 84 wrappers/gethostuuid.c ··· 617 619 make_fat(libsyscall) 618 620 make_fat(libsyscall_dynamic) 619 621 620 - add_library(libsyscall_static OBJECT wrappers/_libc_funcptr.c) 621 - set_target_properties(libsyscall_static PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD") 622 - make_fat(libsyscall_static) 622 + #add_library(libsyscall_static OBJECT wrappers/_libc_funcptr.c) 623 + #set_target_properties(libsyscall_static PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD") 624 + #make_fat(libsyscall_static) 623 625 624 626 # For i386 625 627 #add_library(libsyscall_legacy_extra OBJECT wrappers/legacy/select.c)
+2 -1
src/kernel/libsyscall/os/alloc_once.c
··· 34 34 void *ptr; 35 35 }; 36 36 37 + // XXX: I had to add an initializer here. Without it, the symbol wasn't being exported 37 38 __attribute__((visibility("default"))) 38 39 extern struct _os_alloc_once_s _os_alloc_once_table[]; 39 - struct _os_alloc_once_s _os_alloc_once_table[OS_ALLOC_ONCE_KEY_MAX]; 40 + struct _os_alloc_once_s _os_alloc_once_table[OS_ALLOC_ONCE_KEY_MAX] = { {0,0} };
src/kernel/libsyscall/wrappers/__commpage_gettimeofday.s src/kernel/libsyscall/wrappers/__commpage_gettimeofday_asm.S
src/kernel/libsyscall/wrappers/__get_cpu_capabilities.s src/kernel/libsyscall/wrappers/__get_cpu_capabilities.S
+2 -2
src/kernel/libsyscall/wrappers/_libc_funcptr.c
··· 97 97 _libkernel_voucher_functions = fns; 98 98 return KERN_SUCCESS; 99 99 } 100 - 100 + #if 0 101 101 boolean_t 102 102 voucher_mach_msg_set(mach_msg_header_t *msg) 103 103 { ··· 131 131 return _libkernel_voucher_functions->voucher_mach_msg_revert(state); 132 132 } 133 133 } 134 - 134 + #endif
+14
src/kernel/mach_server/client/mach_traps.c
··· 554 554 return ioctl(driver_fd, NR_bsdthread_terminate_trap, &args); 555 555 } 556 556 557 + typedef struct voucher_mach_msg_state_s *voucher_mach_msg_state_t; 558 + 559 + boolean_t voucher_mach_msg_set(mach_msg_header_t *msg) 560 + { 561 + return 0; 562 + } 563 + 564 + void voucher_mach_msg_revert(voucher_mach_msg_state_t state) 565 + { 566 + } 567 + 568 + voucher_mach_msg_state_t voucher_mach_msg_adopt(mach_msg_header_t *msg) 569 + { 570 + } 557 571
+13 -3
src/keymgr/CMakeLists.txt
··· 18 18 ) 19 19 20 20 set(DYLIB_INSTALL_NAME "/usr/lib/system/libkeymgr.dylib") 21 - add_darling_library(keymgr SHARED ${keymgr_sources}) 22 - target_link_libraries(keymgr PRIVATE system_c system_dyld system_malloc system_pthread) 23 - make_fat(keymgr) 21 + add_circular(keymgr FAT 22 + SOURCES 23 + ${keymgr_sources} 24 + SIBLINGS 25 + system_c 26 + system_dyld 27 + system_malloc 28 + system_pthread 29 + platform 30 + system_kernel 31 + ) 32 + #target_link_libraries(keymgr PRIVATE system_c system_dyld system_malloc system_pthread) 33 + #make_fat(keymgr) 24 34 25 35 set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar") 26 36 set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib")
+9 -3
src/launchd/liblaunch/CMakeLists.txt
··· 31 31 ) 32 32 33 33 set(DYLIB_INSTALL_NAME "/usr/lib/system/liblaunch.dylib") 34 - add_darling_library(launch SHARED ${launch_sources}) 35 - target_link_libraries(launch PRIVATE system_c system_kernel) 36 - make_fat(launch) 34 + add_circular(launch FAT 35 + SOURCES 36 + ${launch_sources} 37 + SIBLINGS 38 + system_c 39 + system_kernel 40 + ) 41 + #target_link_libraries(launch PRIVATE system_c system_kernel) 42 + #make_fat(launch) 37 43 38 44 install(TARGETS launch DESTINATION libexec/darling/usr/lib/system) 39 45
+33 -6
src/libc/CMakeLists.txt
··· 26 26 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -fPIC -w ") 27 27 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${CMAKE_CURRENT_SOURCE_DIR}/weak_reference.h") 28 28 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") # development flags 29 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress") 29 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load") 30 30 31 31 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/fbsdcompat") 32 32 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/darwin") ··· 127 127 #) 128 128 129 129 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_c.dylib") 130 - add_darling_library(system_c SHARED 130 + add_circular(system_c FAT OBJECTS 131 131 $<TARGET_OBJECTS:libc-db> 132 132 $<TARGET_OBJECTS:libc-compat> 133 133 $<TARGET_OBJECTS:libc-compat_cancelable> ··· 144 144 $<TARGET_OBJECTS:libc-util> 145 145 $<TARGET_OBJECTS:libc-string> 146 146 $<TARGET_OBJECTS:libc-string-x86_64> 147 + $<TARGET_OBJECTS:libc-string-i386> 147 148 $<TARGET_OBJECTS:libc-stdtime> 148 149 $<TARGET_OBJECTS:libc-sys> 149 150 $<TARGET_OBJECTS:libc-sys_noinode64> ··· 173 174 $<TARGET_OBJECTS:libc-regex_legacy> 174 175 $<TARGET_OBJECTS:libc-locale_legacy> 175 176 $<TARGET_OBJECTS:libc-net_legacy> 177 + STRONG_SIBLINGS 178 + platform 179 + SIBLINGS 180 + system_kernel 181 + compiler_rt 182 + system_dyld 183 + system_malloc 184 + system_pthread 185 + system_blocks 186 + system_m 187 + platform 188 + launch 189 + system_notify 190 + libdispatch_shared 191 + system_info 192 + macho 193 + system_duct 194 + system_asl 195 + LINK_FLAGS 196 + "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/xcodescripts/alias.list" 176 197 ) 177 - target_link_libraries(system_c system_kernel system_m macho system_malloc platform) 178 - make_fat(system_c) 179 - set_property(TARGET system_c APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/xcodescripts/alias.list") 198 + #target_link_libraries(system_c system_kernel system_m macho system_malloc platform system_blocks system_pthread compiler_rt) 199 + #make_fat(system_c) 200 + #set_property(TARGET system_c APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/xcodescripts/alias.list -Wl,-sub_library,libsystem_platform") 180 201 181 202 install(TARGETS system_c DESTINATION libexec/darling/usr/lib/system) 182 203 ··· 190 211 $<TARGET_OBJECTS:libc-locale> 191 212 $<TARGET_OBJECTS:libc-stdio> 192 213 $<TARGET_OBJECTS:libc-stdtime> 193 - $<TARGET_OBJECTS:libc-gdtoa> 214 + $<TARGET_OBJECTS:libc-string> 215 + $<TARGET_OBJECTS:libc-gdtoa_dyld> 194 216 $<TARGET_OBJECTS:libc-secure> 195 217 $<TARGET_OBJECTS:libc-os> 196 218 $<TARGET_OBJECTS:libc-stdio_extsn> ··· 198 220 add_dependencies(libc_static ranlib x86_64-apple-darwin11-ar) 199 221 set_target_properties(libc_static PROPERTIES COMPILE_FLAGS "-ffunction-sections") 200 222 223 + add_library(libc_static64 STATIC $<TARGET_OBJECTS:libc-x86_64>) 224 + add_dependencies(libc_static64 ranlib x86_64-apple-darwin11-ar) 225 + add_library(libc_static32 STATIC $<TARGET_OBJECTS:libc-i386>) 226 + add_dependencies(libc_static32 ranlib x86_64-apple-darwin11-ar) 227 +
+3
src/libc/gdtoa/CMakeLists.txt
··· 39 39 #SET_SOURCE_FILES_PROPERTIES(FreeBSD/gdtoa-strtof.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_STRTOF -DLIBC_ALIAS_STRTOF_L") 40 40 41 41 add_library(libc-gdtoa OBJECT ${gdtoa_sources}) 42 + add_library(libc-gdtoa_dyld OBJECT ${gdtoa_sources}) 43 + set_target_properties(libc-gdtoa_dyld PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD") 44 + make_fat(libc-gdtoa_dyld) 42 45 43 46 # Legacy variant 44 47 set(gdtoa-legacy_sources
+2
src/libc/gdtoa/FreeBSD/gdtoa-misc.c
··· 87 87 #ifdef GDTOA_TSD 88 88 Bigint **freelist; 89 89 90 + #ifndef VARIANT_DYLD 90 91 if (gdtoa_tsd_key == (pthread_key_t)-1) { 91 92 pthread_mutex_lock(&gdtoa_tsd_lock); 92 93 if (gdtoa_tsd_key == (pthread_key_t)-1) { ··· 95 96 } 96 97 pthread_mutex_unlock(&gdtoa_tsd_lock); 97 98 } 99 + #endif 98 100 if ((freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key)) == NULL) { 99 101 freelist = (Bigint **)MALLOC((Kmax+1) * sizeof(Bigint *)); 100 102 bzero(freelist, (Kmax+1) * sizeof(Bigint *));
+3 -3
src/libc/gen/CMakeLists.txt
··· 187 187 FreeBSD/seekdir.c FreeBSD/setmode.c FreeBSD/sleep.c FreeBSD/telldir.c 188 188 FreeBSD/ttyname.c FreeBSD/usleep.c FreeBSD/wait.c FreeBSD/waitpid.c 189 189 FreeBSD/timezone.c FreeBSD/termios.c FreeBSD/nice.c 190 - confstr.c crypt.c nftw.c FreeBSD/opendir.c) 190 + confstr.c crypt.c nftw.c FreeBSD/opendir.c nanosleep.c) 191 191 192 192 add_library(libc-gen_legacy OBJECT ${gen-legacy_sources}) 193 193 SET_TARGET_PROPERTIES(libc-gen_legacy PROPERTIES COMPILE_FLAGS ··· 222 222 223 223 add_library(libc-gen_dyld OBJECT FreeBSD/arc4random.c FreeBSD/closedir.c dirfd.c FreeBSD/getcwd.c FreeBSD/getpagesize.c nanosleep.c FreeBSD/opendir.c 224 224 FreeBSD/readdir.c FreeBSD/scandir.c FreeBSD/sysctl.c FreeBSD/sysctlbyname.c FreeBSD/telldir.c FreeBSD/usleep.c FreeBSD/sysconf.c 225 - FreeBSD/isatty.c FreeBSD/termios.c FreeBSD/getprogname.c errlst.c) 225 + FreeBSD/isatty.c FreeBSD/termios.c FreeBSD/getprogname.c FreeBSD/vis.c FreeBSD/err.c FreeBSD/usleep.c errlst.c) 226 226 227 - SET_TARGET_PROPERTIES(libc-gen_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN -U__DARWIN_NON_CANCELABLE") 227 + SET_TARGET_PROPERTIES(libc-gen_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_DARWINEXTSN -D__DARWIN_NON_CANCELABLE=1 -D__DARWIN_UNIX03=1") 228 228
+3
src/libc/secure/CMakeLists.txt
··· 6 6 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa/FreeBSD") 7 7 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa") 8 8 9 + include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/dyld-apple/include) 10 + 9 11 set(secure_sources 10 12 chk_fail.c 11 13 memcpy_chk.c ··· 24 26 strncpy_chk.c 25 27 vsnprintf_chk.c 26 28 vsprintf_chk.c 29 + secure.c 27 30 ) 28 31 29 32 #SET_SOURCE_FILES_PROPERTIES(FreeBSD/snprintf.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS}")
+38
src/libc/secure/chk_fail.c
··· 27 27 #include <unistd.h> 28 28 #include <stdlib.h> 29 29 #include <TargetConditionals.h> 30 + #include <mach-o/dyld_priv.h> 31 + #include "secure.h" 30 32 33 + extern void __abort(void) __dead2; 34 + 35 + void 36 + __attribute__ ((noreturn)) 37 + __chk_fail (void) 38 + { 39 + //const char message[] = "[%d] detected buffer overflow"; 40 + 41 + //syslog(LOG_CRIT, message, getpid()); 42 + 43 + const char message[] = "detected buffer overflow"; 44 + write(2, message, sizeof(message)-1); 45 + 46 + __abort(); 47 + } 48 + 49 + static void __chk_assert_no_overlap_callback(const struct mach_header* mh, intptr_t vmaddr_slide) 50 + { 51 + if (__chk_assert_no_overlap) 52 + { 53 + if (dyld_get_sdk_version(mh) < DYLD_MACOSX_VERSION_10_9) 54 + __chk_assert_no_overlap = 0; 55 + } 56 + } 57 + 58 + void 59 + __chk_init (void) 60 + { 61 + if (dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_9) 62 + { 63 + _dyld_register_func_for_add_image(&__chk_assert_no_overlap_callback); 64 + __chk_assert_no_overlap = 1; 65 + } 66 + else 67 + __chk_assert_no_overlap = 0; 68 + }
+35
src/libc/secure/secure.c
··· 1 + #include <stdint.h> 2 + #include "secure.h" 3 + #include <syslog.h> 4 + #include <sys/sysctl.h> 5 + #include <sys/param.h> 6 + #include <unistd.h> 7 + 8 + __attribute__ ((visibility ("hidden"))) 9 + uint32_t __chk_assert_no_overlap = 1; 10 + 11 + extern void __abort(void) __dead2; 12 + extern void __chk_fail (void) __attribute__((__noreturn__)); 13 + 14 + void __chk_fail_overflow (void) __attribute__((__noreturn__)) 15 + { 16 + __chk_fail(); 17 + } 18 + 19 + void __chk_fail_overlap (void) __attribute__((__noreturn__)) 20 + { 21 + //const char message[] = "[%d] detected illegal buffer overlap"; 22 + 23 + //syslog(LOG_CRIT, message, getpid()); 24 + const char message[] = "detected illegal buffer overlap"; 25 + write(2, message, sizeof(message)-1); 26 + 27 + __abort(); 28 + } 29 + 30 + void __chk_overlap (const void *a, size_t an, const void *b, size_t bn) 31 + { 32 + if (((uintptr_t)a) <= ((uintptr_t)b)+bn && ((uintptr_t)b) <= ((uintptr_t)a)+an) 33 + __chk_fail_overlap(); 34 + } 35 +
+11 -1
src/libc/stdio/CMakeLists.txt
··· 8 8 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa/FreeBSD") 9 9 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa") 10 10 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/FreeBSD") 11 + include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 11 12 12 13 set(stdio_sources 13 14 xprintf_all_in_one.c ··· 54 55 FreeBSD/fwrite.c 55 56 FreeBSD/fwscanf.c 56 57 FreeBSD/getc.c 57 - FreeBSD/getchar.c 58 58 FreeBSD/getdelim.c 59 + FreeBSD/getchar.c 59 60 FreeBSD/getline.c 60 61 FreeBSD/gets.c 61 62 FreeBSD/getw.c ··· 110 111 FreeBSD/wprintf.c 111 112 FreeBSD/wscanf.c 112 113 FreeBSD/wsetup.c 114 + FreeBSD/xprintf.c 115 + FreeBSD/xprintf_errno.c 116 + FreeBSD/xprintf_float.c 117 + FreeBSD/xprintf_hexdump.c 118 + FreeBSD/xprintf_int.c 119 + FreeBSD/xprintf_quote.c 120 + FreeBSD/xprintf_str.c 121 + FreeBSD/xprintf_time.c 122 + FreeBSD/xprintf_vis.c 113 123 ) 114 124 115 125 set_source_files_properties(FreeBSD/fopen.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_FOPEN")
+1 -1
src/libc/stdlib/CMakeLists.txt
··· 104 104 SET_TARGET_PROPERTIES(libc-stdlib_extsn PROPERTIES COMPILE_DEFINITIONS "BUILDING_VARIANT;VARIANT_DARWINEXTSN") 105 105 106 106 # DYLD variant 107 - add_library(libc-stdlib_dyld OBJECT FreeBSD/atexit.c FreeBSD/exit.c FreeBSD/heapsort.c FreeBSD/merge.c FreeBSD/qsort.c FreeBSD/reallocf.c FreeBSD/realpath.c FreeBSD/strtoul.c FreeBSD/strtol.c FreeBSD/getenv.c FreeBSD/exit.c) 107 + add_library(libc-stdlib_dyld OBJECT FreeBSD/atexit.c FreeBSD/exit.c FreeBSD/heapsort.c FreeBSD/abort.c FreeBSD/merge.c FreeBSD/qsort.c FreeBSD/reallocf.c FreeBSD/realpath.c FreeBSD/strtoul.c FreeBSD/strtol.c FreeBSD/getenv.c FreeBSD/exit.c) 108 108 SET_TARGET_PROPERTIES(libc-stdlib_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") 109 109
+7
src/libc/string/CMakeLists.txt
··· 23 23 strlcpy.c 24 24 ) 25 25 26 + # i386 only, vice versa 27 + set(string_i386_sources 28 + FreeBSD/strnlen.c) 29 + 26 30 set(string_sources ${string_sources} 27 31 FreeBSD/index.c 28 32 FreeBSD/memmem.c ··· 86 90 add_library(libc-string OBJECT ${string_sources}) 87 91 add_library(libc-string-x86_64 OBJECT ${string_x86_64_sources}) 88 92 set_target_properties(libc-string-x86_64 PROPERTIES COMPILE_FLAGS "-arch x86_64") 93 + 94 + add_library(libc-string-i386 OBJECT ${string_i386_sources}) 95 + set_target_properties(libc-string-i386 PROPERTIES COMPILE_FLAGS "-arch i386") 89 96 90 97 # Legacy variant 91 98 set(string-legacy_sources
+1 -1
src/libc/sys/CMakeLists.txt
··· 48 48 add_library(libc-sys_noinode64 OBJECT ${sys-noinode64_sources}) 49 49 SET_TARGET_PROPERTIES(libc-sys_noinode64 PROPERTIES COMPILE_FLAGS "-U__DARWIN_UNIX03 -U__DARWIN_64_BIT_INO_T -DVARIANT_INODE32 -DBUILDING_VARIANT -D_DARWIN_NO_64_BIT_INODE") 50 50 51 - add_library(libc-sys_dyld OBJECT gettimeofday.c crt_externs.c) 51 + add_library(libc-sys_dyld OBJECT gettimeofday.c crt_externs.c sigaction.c) 52 52 SET_TARGET_PROPERTIES(libc-sys_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") 53 53
+1
src/libedit/CMakeLists.txt
··· 54 54 55 55 set(DYLIB_INSTALL_NAME "/usr/lib/libedit.3.dylib") 56 56 add_darling_library(edit SHARED ${edit_SRCS}) 57 + make_fat(edit) 57 58 set_target_properties(edit PROPERTIES OUTPUT_NAME "edit.3") 58 59 target_link_libraries(edit PRIVATE system ncurses) 59 60
+2 -2
src/libgcc/CMakeLists.txt
··· 7 7 endif(COMMAND cmake_policy) 8 8 9 9 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc") 10 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 10 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-sub_library,libcompiler_rt") 11 11 12 12 set(libgcc_sources 13 13 dummy.c 14 14 ) 15 15 16 16 add_darling_library(gcc_s SHARED ${libgcc_sources}) 17 - target_link_libraries(gcc_s PRIVATE compiler_rt -sub_library libcompiler_rt) 17 + target_link_libraries(gcc_s PRIVATE compiler_rt) 18 18 set_target_properties(gcc_s PROPERTIES OUTPUT_NAME "gcc_s.1") 19 19 20 20 InstallSymlink("libgcc_s.1.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libgcc_s.dylib")
+25 -10
src/libinfo/CMakeLists.txt
··· 42 42 ) 43 43 44 44 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_info.dylib") 45 - add_darling_library(system_info SHARED $<TARGET_OBJECTS:info-util> 46 - $<TARGET_OBJECTS:info-dns> 47 - $<TARGET_OBJECTS:info-gen> 48 - $<TARGET_OBJECTS:info-nis> 49 - $<TARGET_OBJECTS:info-rpc> 50 - $<TARGET_OBJECTS:info-lookup> 51 - $<TARGET_OBJECTS:info-membership> 52 - $<TARGET_OBJECTS:darling-resolver> 45 + add_circular(system_info FAT 46 + OBJECTS 47 + $<TARGET_OBJECTS:info-util> 48 + $<TARGET_OBJECTS:info-dns> 49 + $<TARGET_OBJECTS:info-gen> 50 + $<TARGET_OBJECTS:info-nis> 51 + $<TARGET_OBJECTS:info-rpc> 52 + $<TARGET_OBJECTS:info-lookup> 53 + $<TARGET_OBJECTS:info-membership> 54 + $<TARGET_OBJECTS:darling-resolver> 55 + SIBLINGS 56 + system_c 57 + system_dyld 58 + system_blocks 59 + system_kernel 60 + system_malloc 61 + system_duct 62 + system_pthread 63 + libdispatch_shared 64 + system_notify 65 + platform 66 + DEPENDENCIES 67 + resolv-darwin 53 68 ) 54 - target_link_libraries(system_info PRIVATE system_c resolv-darwin system_dyld system_blocks libdispatch_shared system_notify platform) 55 - make_fat(system_info) 69 + #target_link_libraries(system_info PRIVATE system_c resolv-darwin system_dyld system_blocks libdispatch_shared system_notify platform) 70 + #make_fat(system_info) 56 71 57 72 install(TARGETS system_info DESTINATION libexec/darling/usr/lib/system) 58 73 install(FILES master.passwd DESTINATION libexec/darling/etc)
+15 -5
src/libm/CMakeLists.txt
··· 6 6 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -ggdb -O0") 7 7 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -DBUILDING_FOR_CARBONCORE_LEGACY -funroll-loops -msse3") # -DBUILDING_FOR_CARBONCORE_LEGACY") 8 8 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DBUILDING_FOR_CARBONCORE_LEGACY") 9 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-flat_namespace -Wl,-undefined,suppress") 9 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 10 10 11 11 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/Intel) 12 12 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel-include) ··· 155 155 make_fat(system_m_extra) 156 156 157 157 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_m.dylib") 158 - add_darling_library(system_m SHARED ${libm_sources} $<TARGET_OBJECTS:system_m_extra>) 159 - set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS 160 - "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias") 158 + add_circular(system_m FAT 159 + SOURCES 160 + ${libm_sources} 161 + OBJECTS 162 + $<TARGET_OBJECTS:system_m_extra> 163 + SIBLINGS 164 + system_c 165 + system_dyld 166 + LINK_FLAGS 167 + "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias" 168 + ) 169 + #set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS 170 + # "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias") 161 171 #target_link_libraries(system_m) 162 - make_fat(system_m) 172 + #make_fat(system_m) 163 173 164 174 install(TARGETS system_m DESTINATION libexec/darling/usr/lib/system) 165 175
+12 -4
src/libmacho/CMakeLists.txt
··· 8 8 add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080) 9 9 10 10 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") 11 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress") 11 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load") 12 12 13 13 include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) 14 14 ··· 29 29 ) 30 30 31 31 set(DYLIB_INSTALL_NAME "/usr/lib/system/libmacho.dylib") 32 - add_darling_library(macho SHARED ${libmacho_sources}) 33 - target_link_libraries(macho system_kernel) 34 - make_fat(macho) 32 + add_circular(macho FAT 33 + SOURCES 34 + ${libmacho_sources} 35 + SIBLINGS 36 + system_kernel 37 + system_dyld 38 + system_c 39 + system_malloc 40 + ) 41 + #target_link_libraries(macho system_kernel) 42 + #make_fat(macho) 35 43 36 44 install(TARGETS macho DESTINATION libexec/darling/usr/lib/system)
+17 -8
src/libmalloc/CMakeLists.txt
··· 2 2 3 3 cmake_minimum_required(VERSION 2.4.0) 4 4 5 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -fblocks -ggdb") 6 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -include ${CMAKE_CURRENT_SOURCE_DIR}/../duct/include/commpage.h -nostdinc") 7 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress") 5 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -fblocks -ggdb") 6 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc") 7 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-bind_at_load") 8 8 9 9 add_definitions(-DTARGET_OS_MAC=1) 10 - add_definitions(-DHAVE_STDINT_H=1) 11 - add_definitions(-D__APPLE__ -D__DYNAMIC__ -DPRIVATE) 10 + add_definitions(-D__APPLE__ -D__DYNAMIC__ -DPRIVATE -DOS_UNFAIR_LOCK_INLINE=1) 12 11 add_definitions("'-DMAGMALLOC_MALLOCERRORBREAK()='") 13 12 14 13 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/malloc) ··· 18 17 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/darwin) 19 18 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel/libsyscall/wrappers/) 20 19 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel/libsyscall) 20 + include_directories(${CMAKE_SOURCE_DIR}/src/external/libpthread/private) 21 21 22 22 set(libmalloc_sources 23 23 src/bitarray.c ··· 35 35 ) 36 36 37 37 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_malloc.dylib") 38 - add_darling_library(system_malloc SHARED ${libmalloc_sources}) 39 - target_link_libraries(system_malloc PRIVATE system_kernel) 40 - make_fat(system_malloc) 38 + add_circular(system_malloc FAT 39 + SOURCES 40 + ${libmalloc_sources} 41 + SIBLINGS 42 + system_kernel 43 + system_c 44 + platform 45 + system_dyld 46 + compiler_rt 47 + ) 48 + #target_link_libraries(system_malloc PRIVATE system_kernel) 49 + #make_fat(system_malloc) 41 50 42 51 install(TARGETS system_malloc DESTINATION libexec/darling/usr/lib/system) 43 52
+17 -3
src/libnotify/CMakeLists.txt
··· 25 25 ) 26 26 27 27 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_notify.dylib") 28 - add_darling_library(system_notify SHARED ${notify_sources}) 29 - target_link_libraries(system_notify system_c system_kernel system_blocks libdispatch_shared launch system_dyld system_malloc system_pthread) 30 - make_fat(system_notify) 28 + add_circular(system_notify FAT 29 + SOURCES 30 + ${notify_sources} 31 + SIBLINGS 32 + system_c 33 + system_kernel 34 + system_blocks 35 + libdispatch_shared 36 + launch 37 + system_dyld 38 + system_malloc 39 + system_pthread 40 + platform 41 + system_asl 42 + ) 43 + #target_link_libraries(system_notify system_c system_kernel system_blocks libdispatch_shared launch system_dyld system_malloc system_pthread) 44 + #make_fat(system_notify) 31 45 32 46 install(TARGETS system_notify DESTINATION libexec/darling/usr/lib/system) 33 47
+2 -1
src/libsystem/CMakeLists.txt
··· 43 43 target_link_libraries(system PRIVATE system_malloc system_c system_kernel keymgr sandbox 44 44 system_m system_info system_notify system_quarantine libdispatch_shared launch compiler_rt 45 45 removefile system_copyfile unwind system_coreservices system_dyld macho CommonCrypto 46 - system_pthread platform) # objc 46 + system_pthread platform system_asl system_duct system_blocks) # objc 47 47 set_target_properties(system PROPERTIES OUTPUT_NAME "System.B") 48 48 set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS 49 49 " -sub_library libsystem_malloc \ ··· 69 69 -sub_library libcommonCrypto \ 70 70 -sub_library libsystem_sandbox \ 71 71 -sub_library libsystem_coreservices \ 72 + -sub_library libsystem_asl \ 72 73 -Wl,-dylib_compatibility_version,1238.0.0") 73 74 74 75 make_fat(system)
+1 -1
src/libsystem_coreservices/CMakeLists.txt
··· 22 22 23 23 set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_coreservices.dylib") 24 24 add_darling_library(system_coreservices SHARED dirhelper.c NSSystemDirectories.c) 25 - target_link_libraries(system_coreservices PRIVATE system_c system_dyld platform system_pthread) 25 + target_link_libraries(system_coreservices PRIVATE system_c system_dyld platform system_pthread system_kernel) 26 26 make_fat(system_coreservices) 27 27 28 28 install(TARGETS system_coreservices DESTINATION libexec/darling/usr/lib/system)
+10 -4
src/libunwind/CMakeLists.txt
··· 35 35 ) 36 36 37 37 set(DYLIB_INSTALL_NAME "/usr/lib/system/libunwind.dylib") 38 - add_darling_library(unwind SHARED ${libunwind_sources}) 39 - target_link_libraries(unwind PRIVATE system_c keymgr) 40 - set_target_properties(unwind PROPERTIES LINKER_LANGUAGE C) 41 - make_fat(unwind) 38 + add_circular(unwind FAT 39 + SOURCES 40 + ${libunwind_sources} 41 + SIBLINGS 42 + system_c 43 + keymgr 44 + ) 45 + #target_link_libraries(unwind PRIVATE system_c keymgr) 46 + #set_target_properties(unwind PROPERTIES LINKER_LANGUAGE C) 47 + #make_fat(unwind) 42 48 43 49 add_library(unwind_static STATIC ${libunwind_sources}) 44 50 set_target_properties(unwind_static PROPERTIES COMPILE_FLAGS "-DNDEBUG=1")