mirror of
https://github.com/darlinghq/darling.git
synced 2026-02-15 02:38:57 -06:00
Working new libc and fat build, added machdep calls table and implemented sys_getentropy()
This commit is contained in:
@@ -71,9 +71,14 @@ FUNCTION(add_circular name)
|
||||
endif (CIRCULAR_SOURCES)
|
||||
|
||||
# Then create a shared Darling library, while ignoring all dependencies and using flat namespace
|
||||
add_darling_library("${name}_firstpass" SHARED ${all_objects})# $<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS})
|
||||
add_darling_library("${name}_firstpass" SHARED ${all_objects})
|
||||
set_property(TARGET "${name}_firstpass" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
|
||||
#if (DYLIB_INSTALL_NAME)
|
||||
# set_property(TARGET "${name}_firstpass" PROPERTY FULL_PATH "${DYLIB_INSTALL_NAME}")
|
||||
#endif (DYLIB_INSTALL_NAME)
|
||||
#set_property(GLOBAL APPEND_STRING PROPERTY FIRSTPASS_MAP " -Wl,-dylib_file,${DYLIB_INSTALL_NAME}:$<TARGET_FILE:${name}_firstpass>")
|
||||
|
||||
foreach(dep ${CIRCULAR_STRONG_SIBLINGS})
|
||||
target_link_libraries("${name}_firstpass" PRIVATE "${dep}_firstpass")
|
||||
endforeach(dep)
|
||||
@@ -83,12 +88,18 @@ FUNCTION(add_circular name)
|
||||
endif (CIRCULAR_FAT)
|
||||
|
||||
# Then build the final product while linking against firstpass libraries
|
||||
add_darling_library(${name} SHARED ${all_objects}) #$<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS})
|
||||
set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}")
|
||||
add_darling_library(${name} SHARED ${all_objects})
|
||||
|
||||
#set(dylib_files "")
|
||||
foreach(dep ${CIRCULAR_SIBLINGS})
|
||||
#get_property(full_path TARGET "${name}_firstpass" PROPERTY FULL_PATH)
|
||||
#set(dylib_files "${dylib_files} -Wl,-dylib_file,${full_path}:$<TARGET_FILE:${name}_firstpass>")
|
||||
target_link_libraries("${name}" PRIVATE "${dep}_firstpass")
|
||||
endforeach(dep)
|
||||
|
||||
get_property(dylib_files GLOBAL PROPERTY FIRSTPASS_MAP)
|
||||
set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}")
|
||||
|
||||
target_link_libraries("${name}" PRIVATE ${CIRCULAR_DEPENDENCIES})
|
||||
|
||||
if (CIRCULAR_FAT)
|
||||
|
||||
@@ -3,30 +3,33 @@ FUNCTION(use_ld64 target)
|
||||
LINK_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ld64/src/ \
|
||||
-B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ \
|
||||
-target x86_64-apple-darwin11 \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_c.dylib:${CMAKE_BINARY_DIR}/src/libc/libsystem_c.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_kernel.dylib:${CMAKE_BINARY_DIR}/src/kernel/libsystem_kernel.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libunwind.dylib:${CMAKE_BINARY_DIR}/src/libunwind/libunwind.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_m.dylib:${CMAKE_BINARY_DIR}/src/libm/libsystem_m.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libcompiler_rt.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/builtins/libcompiler_rt.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libdyld.dylib:${CMAKE_BINARY_DIR}/src/dyld-apple/libdyld.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_info.dylib:${CMAKE_BINARY_DIR}/src/libinfo/libsystem_info.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_blocks.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/BlocksRuntime/libsystem_blocks.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_c.dylib:${CMAKE_BINARY_DIR}/src/libc/libsystem_c_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_kernel.dylib:${CMAKE_BINARY_DIR}/src/kernel/libsystem_kernel_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libunwind.dylib:${CMAKE_BINARY_DIR}/src/libunwind/libunwind_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_m.dylib:${CMAKE_BINARY_DIR}/src/libm/libsystem_m_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libcompiler_rt.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/builtins/libcompiler_rt_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libdyld.dylib:${CMAKE_BINARY_DIR}/src/dyld-apple/libsystem_dyld_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_info.dylib:${CMAKE_BINARY_DIR}/src/libinfo/libsystem_info_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_blocks.dylib:${CMAKE_BINARY_DIR}/src/external/compiler-rt/lib/BlocksRuntime/libsystem_blocks_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/libc++abi.dylib:${CMAKE_BINARY_DIR}/src/external/libcxxabi/src/libc++abi.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/liblaunch.dylib:${CMAKE_BINARY_DIR}/src/launchd/liblaunch/liblaunch.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libkeymgr.dylib:${CMAKE_BINARY_DIR}/src/keymgr/libkeymgr.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/liblaunch.dylib:${CMAKE_BINARY_DIR}/src/launchd/liblaunch/liblaunch_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libkeymgr.dylib:${CMAKE_BINARY_DIR}/src/keymgr/libkeymgr_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libquarantine.dylib:${CMAKE_BINARY_DIR}/src/quarantine/libquarantine.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libremovefile.dylib:${CMAKE_BINARY_DIR}/src/libremovefile/libremovefile.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libcopyfile.dylib:${CMAKE_BINARY_DIR}/src/copyfile/libcopyfile.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_coreservices.dylib:${CMAKE_BINARY_DIR}/src/libsystem_coreservices/libsystem_coreservices.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_notify.dylib:${CMAKE_BINARY_DIR}/src/libnotify/libsystem_notify.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libdispatch.dylib:${CMAKE_BINARY_DIR}/src/external/libdispatch/src/libdispatch.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libmacho.dylib:${CMAKE_BINARY_DIR}/src/libmacho/libmacho.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_notify.dylib:${CMAKE_BINARY_DIR}/src/libnotify/libsystem_notify_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libdispatch.dylib:${CMAKE_BINARY_DIR}/src/external/libdispatch/src/liblibdispatch_shared_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libmacho.dylib:${CMAKE_BINARY_DIR}/src/libmacho/libmacho_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_sandbox.dylib:${CMAKE_BINARY_DIR}/src/sandbox/libsystem_sandbox.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_duct.dylib:${CMAKE_BINARY_DIR}/src/duct/src/libsystem_duct.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_pthread.dylib:${CMAKE_BINARY_DIR}/src/external/libpthread/src/libsystem_pthread.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_platform.dylib:${CMAKE_BINARY_DIR}/src/external/libplatform/libsystem_platform.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_duct.dylib:${CMAKE_BINARY_DIR}/src/duct/src/libsystem_duct_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_pthread.dylib:${CMAKE_BINARY_DIR}/src/external/libpthread/src/libsystem_pthread_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_platform.dylib:${CMAKE_BINARY_DIR}/src/external/libplatform/libplatform_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/libcommonCrypto.dylib:${CMAKE_BINARY_DIR}/src/CommonCrypto/libcommonCrypto.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_malloc.dylib:${CMAKE_BINARY_DIR}/src/libmalloc/libsystem_malloc.dylib ")
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_asl.dylib:${CMAKE_BINARY_DIR}/src/external/syslog/libsystem_asl.tproj/libsystem_asl_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/libresolv.9.dylib:${CMAKE_BINARY_DIR}/src/libresolv/libresolv.9.dylib \
|
||||
-W;,-dylib_file,/usr/lib/system/libxpc.dylib:${CMAKE_BINARY_DIR}/src/external/libxpc/libxpc_firstpass.dylib \
|
||||
-Wl,-dylib_file,/usr/lib/system/libsystem_malloc.dylib:${CMAKE_BINARY_DIR}/src/libmalloc/libsystem_malloc_firstpass.dylib ")
|
||||
|
||||
add_dependencies(${target} x86_64-apple-darwin11-ld)
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
#define UNIX_SYSCALL_TRAP \
|
||||
call __darling_bsd_syscall
|
||||
#define MACHDEP_SYSCALL_TRAP \
|
||||
ud2
|
||||
call __darling_machdep_syscall
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,9 +110,9 @@ END(_##trap_name)
|
||||
#ifndef KERNEL
|
||||
|
||||
#define UNIX_SYSCALL_TRAP \
|
||||
syscall
|
||||
call __darling_bsd_syscall
|
||||
#define MACHDEP_SYSCALL_TRAP \
|
||||
syscall
|
||||
call __darling_machdep_syscall
|
||||
|
||||
/*
|
||||
* Macro to generate Mach call stubs in Libc.
|
||||
|
||||
@@ -88,6 +88,7 @@ add_subdirectory(libstdcxx)
|
||||
add_subdirectory(libffi)
|
||||
add_subdirectory(dyld-apple)
|
||||
#add_subdirectory(external/objc4/runtime)
|
||||
add_subdirectory(external/syslog/libsystem_asl.tproj)
|
||||
add_subdirectory(external/libdispatch)
|
||||
add_subdirectory(external/zlib)
|
||||
add_subdirectory(external/bzip2)
|
||||
@@ -129,7 +130,7 @@ add_subdirectory(sandbox)
|
||||
#add_subdirectory(Cocoa)
|
||||
|
||||
add_subdirectory(external/file/file)
|
||||
#add_subdirectory(external/libxpc)
|
||||
add_subdirectory(external/libxpc)
|
||||
add_subdirectory(external/openssl_certificates)
|
||||
|
||||
if (NOT DARLING_NO_EXECUTABLES)
|
||||
|
||||
232
src/duct/include/firehose/firehose_types_private.h
Normal file
232
src/duct/include/firehose/firehose_types_private.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
#ifndef __FIREHOSE_TYPES_PRIVATE__
|
||||
#define __FIREHOSE_TYPES_PRIVATE__
|
||||
|
||||
#include <mach/mach_types.h>
|
||||
#include <mach/std_types.h>
|
||||
#include <os/base.h>
|
||||
|
||||
OS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*!
|
||||
* @enum firehose_activity_flags_t
|
||||
*
|
||||
* @discussion
|
||||
* The lower 8 bits are or-ed in the upper 8 bits of Activity ID and propagated
|
||||
* to children activities
|
||||
*/
|
||||
OS_ENUM(firehose_activity_flags, unsigned long,
|
||||
firehose_activity_flags_default = 0x0000,
|
||||
|
||||
firehose_activity_flags_info_mode = 0x0001,
|
||||
firehose_activity_flags_debug_mode = 0x0002,
|
||||
firehose_activity_flags_stream_live_mode = 0x0004,
|
||||
|
||||
firehose_activity_flags_precise_timestamp = 0x0080,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @typedef firehose_activity_id_t
|
||||
*
|
||||
* @abstract
|
||||
* Opaque activity identifier.
|
||||
*
|
||||
* @discussion
|
||||
* Scalar value type, not reference counted.
|
||||
*/
|
||||
typedef uint64_t firehose_activity_id_t;
|
||||
#define FIREHOSE_ACTIVITY_ID_NULL ((firehose_activity_id_t)0)
|
||||
#define FIREHOSE_ACTIVITY_ID_INVALID ((firehose_activity_id_t)~0ULL)
|
||||
#define FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT 56
|
||||
#define FIREHOSE_ACTIVITY_ID_FLAGS(aid) \
|
||||
((firehose_activity_flags_t)((aid) >> FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT))
|
||||
#define FIREHOSE_ACTIVITY_ID_MERGE_FLAGS(aid, flags) (\
|
||||
((firehose_activity_id_t)(aid)) | \
|
||||
((firehose_activity_id_t)(flags) << FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT))
|
||||
|
||||
/*!
|
||||
* @enum firehose_stream_t
|
||||
*/
|
||||
OS_ENUM(firehose_stream, uint8_t,
|
||||
firehose_stream_persist = 0,
|
||||
firehose_stream_special = 1,
|
||||
firehose_stream_memory = 2,
|
||||
firehose_stream_metadata = 3,
|
||||
firehose_stream_memory_high_traffic = 4,
|
||||
firehose_stream_memory_wifi = 5,
|
||||
firehose_stream_memory_baseband = 6,
|
||||
|
||||
_firehose_stream_max,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_namespace_t
|
||||
*
|
||||
* @abstract
|
||||
* Namespaces of tracepoints.
|
||||
*/
|
||||
OS_ENUM(firehose_tracepoint_namespace, uint8_t,
|
||||
firehose_tracepoint_namespace_activity = 0x02,
|
||||
firehose_tracepoint_namespace_trace = 0x03,
|
||||
firehose_tracepoint_namespace_log = 0x04,
|
||||
firehose_tracepoint_namespace_metadata = 0x05,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_code_t
|
||||
*
|
||||
* @abstract
|
||||
* Codes of tracepoints.
|
||||
*/
|
||||
OS_ENUM(firehose_tracepoint_code, uint32_t,
|
||||
firehose_tracepoint_code_load = 0x01,
|
||||
firehose_tracepoint_code_unload = 0x02,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @typedef firehose_tracepoint_type_t
|
||||
*
|
||||
* @abstract
|
||||
* Type of tracepoints.
|
||||
*/
|
||||
typedef uint8_t firehose_tracepoint_type_t;
|
||||
|
||||
/*!
|
||||
* @typedef firehose_tracepoint_flags_t
|
||||
*
|
||||
* @abstract
|
||||
* Flags for tracepoints.
|
||||
*/
|
||||
OS_ENUM(firehose_tracepoint_flags, uint16_t,
|
||||
_firehose_tracepoint_flags_base_has_current_aid = 0x0001,
|
||||
_firehose_tracepoint_flags_base_main_executable = 0x0002,
|
||||
_firehose_tracepoint_flags_base_shared_cache = 0x0004,
|
||||
_firehose_tracepoint_flags_base_caller_pc = 0x0008,
|
||||
_firehose_tracepoint_flags_base_has_unique_pid = 0x0010,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @typedef firehose_tracepoint_id_t
|
||||
*
|
||||
* @abstract
|
||||
* Opaque tracepoint identifier.
|
||||
*/
|
||||
typedef uint64_t firehose_tracepoint_id_t;
|
||||
|
||||
/*!
|
||||
* @enum _firehose_tracepoint_type_activity_t
|
||||
*
|
||||
* @abstract
|
||||
* Types of Activity tracepoints (namespace activity).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_type_activity, firehose_tracepoint_type_t,
|
||||
_firehose_tracepoint_type_activity_create = 0x01,
|
||||
_firehose_tracepoint_type_activity_swap = 0x02,
|
||||
_firehose_tracepoint_type_activity_useraction = 0x03,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_flags_activity_t
|
||||
*
|
||||
* @abstract
|
||||
* Flags for Activity tracepoints (namespace activity).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_flags_activity, uint16_t,
|
||||
_firehose_tracepoint_flags_activity_user_interface = 0x0100,
|
||||
_firehose_tracepoint_flags_activity_has_other_aid = 0x0200,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_type_trace_t
|
||||
*
|
||||
* @abstract
|
||||
* Types of trace tracepoints (namespace trace).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_type_trace, firehose_tracepoint_type_t,
|
||||
_firehose_tracepoint_type_trace_default = 0x00,
|
||||
_firehose_tracepoint_type_trace_info = 0x01,
|
||||
_firehose_tracepoint_type_trace_debug = 0x02,
|
||||
_firehose_tracepoint_type_trace_error = 0x10,
|
||||
_firehose_tracepoint_type_trace_fault = 0x11,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_type_log_t
|
||||
*
|
||||
* @abstract
|
||||
* Types of Log tracepoints (namespace log).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_type_log, firehose_tracepoint_type_t,
|
||||
_firehose_tracepoint_type_log_default = 0x00,
|
||||
_firehose_tracepoint_type_log_info = 0x01,
|
||||
_firehose_tracepoint_type_log_debug = 0x02,
|
||||
_firehose_tracepoint_type_log_error = 0x10,
|
||||
_firehose_tracepoint_type_log_fault = 0x11,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum firehose_tracepoint_flags_log_t
|
||||
*
|
||||
* @abstract
|
||||
* Flags for Log tracepoints (namespace log).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_flags_log, uint16_t,
|
||||
_firehose_tracepoint_flags_log_has_private_data = 0x0100,
|
||||
_firehose_tracepoint_flags_log_has_subsystem = 0x0200,
|
||||
_firehose_tracepoint_flags_log_has_rules = 0x0400,
|
||||
_firehose_tracepoint_flags_log_has_oversize = 0x0800,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @enum _firehose_tracepoint_type_metadata_t
|
||||
*
|
||||
* @abstract
|
||||
* Types for metadata tracepoints (namespace metadata).
|
||||
*/
|
||||
OS_ENUM(_firehose_tracepoint_type_metadata, firehose_tracepoint_type_t,
|
||||
_firehose_tracepoint_type_metadata_dyld = 0x01,
|
||||
_firehose_tracepoint_type_metadata_subsystem = 0x02,
|
||||
_firehose_tracepoint_type_metadata_kext = 0x03,
|
||||
);
|
||||
|
||||
/* MIG firehose push reply structure */
|
||||
typedef struct firehose_push_reply_s {
|
||||
uint64_t fpr_mem_flushed_pos;
|
||||
uint64_t fpr_io_flushed_pos;
|
||||
} firehose_push_reply_t;
|
||||
|
||||
typedef struct firehose_buffer_map_info_s {
|
||||
mach_vm_address_t fbmi_addr;
|
||||
mach_vm_size_t fbmi_size;
|
||||
} firehose_buffer_map_info_t;
|
||||
|
||||
#define FIREHOSE_PUSH_REPLY_CORRUPTED ((firehose_push_reply_t){ ~0ULL, ~0ULL })
|
||||
|
||||
typedef union firehose_buffer_u *firehose_buffer_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
OS_ASSUME_NONNULL_END
|
||||
|
||||
#endif // __FIREHOSE_TYPES__
|
||||
152
src/duct/include/firehose/tracepoint_private.h
Normal file
152
src/duct/include/firehose/tracepoint_private.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_APACHE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
#ifndef __FIREHOSE_ACTIVITY__
|
||||
#define __FIREHOSE_ACTIVITY__
|
||||
|
||||
#include <machine/cpu_capabilities.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <os/base.h>
|
||||
#if KERNEL
|
||||
#include <atm/atm_internal.h>
|
||||
#endif
|
||||
#include "firehose_types_private.h"
|
||||
|
||||
OS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/*!
|
||||
* @typedef firehose_tracepoint_id_u
|
||||
*
|
||||
* @abstract
|
||||
* Broken down tracepoint identifier.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
firehose_tracepoint_namespace_t _namespace;
|
||||
firehose_tracepoint_type_t _type;
|
||||
firehose_tracepoint_flags_t _flags;
|
||||
uint32_t _code;
|
||||
} ftid;
|
||||
firehose_tracepoint_id_t ftid_value;
|
||||
} firehose_tracepoint_id_u;
|
||||
|
||||
#define FIREHOSE_STAMP_SLOP (1ULL << 36) // ~1minute
|
||||
|
||||
/*!
|
||||
* @typedef firehose_trace_uuid_info_t
|
||||
*
|
||||
* @abstract
|
||||
* Info needed by logd when kexts are loaded or unloaded
|
||||
*
|
||||
*/
|
||||
typedef struct firehose_trace_uuid_info_s {
|
||||
uuid_t ftui_uuid; /* uuid of binary */
|
||||
uint64_t ftui_address; /* load address */
|
||||
uint64_t ftui_size; /* load size */
|
||||
char ftui_path[]; /* full path of binary - Unused in the kernel*/
|
||||
} *firehose_trace_uuid_info_t;
|
||||
|
||||
/*!
|
||||
* @typedef firehose_tracepoint_t
|
||||
*/
|
||||
typedef struct firehose_tracepoint_s {
|
||||
firehose_tracepoint_id_u ft_id;
|
||||
uint64_t ft_thread;
|
||||
union {
|
||||
struct {
|
||||
uint64_t ft_timestamp_delta : 48;
|
||||
uint64_t ft_length : 16;
|
||||
};
|
||||
uint64_t ft_stamp_and_length;
|
||||
};
|
||||
uint8_t ft_data[];
|
||||
} *firehose_tracepoint_t;
|
||||
|
||||
#define FIREHOSE_TRACE_ID_MAKE(ns, type, flags, code) \
|
||||
(((firehose_tracepoint_id_u){ .ftid = { \
|
||||
._namespace = ns, \
|
||||
._type = type, \
|
||||
._flags = flags, \
|
||||
._code = code, \
|
||||
} }).ftid_value)
|
||||
|
||||
#define FIREHOSE_TRACE_ID_SET_NS(tid, ns) \
|
||||
((tid).ftid._namespace = firehose_tracepoint_namespace_##ns)
|
||||
|
||||
#define FIREHOSE_TRACE_ID_SET_TYPE(tid, ns, type) \
|
||||
((tid).ftid._type = _firehose_tracepoint_type_##ns##_##type)
|
||||
|
||||
#define FIREHOSE_TRACE_ID_HAS_FLAG(tid, ns, flag) \
|
||||
((tid).ftid._flags & _firehose_tracepoint_flags_##ns##_##flag)
|
||||
#define FIREHOSE_TRACE_ID_SET_FLAG(tid, ns, flag) \
|
||||
((void)((tid).ftid._flags |= _firehose_tracepoint_flags_##ns##_##flag))
|
||||
#define FIREHOSE_TRACE_ID_CLEAR_FLAG(tid, ns, flag) \
|
||||
((void)((tid).ftid._flags &= ~_firehose_tracepoint_flags_##ns##_##flag))
|
||||
|
||||
#define FIREHOSE_TRACE_ID_SET_CODE(tid, code) \
|
||||
((tid).ftid._code = code)
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#if __has_feature(address_sanitizer)
|
||||
__attribute__((no_sanitize("address")))
|
||||
#endif
|
||||
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
|
||||
__TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
|
||||
OS_ALWAYS_INLINE
|
||||
static inline bool
|
||||
firehose_precise_timestamps_enabled(void)
|
||||
{
|
||||
#if KERNEL
|
||||
return (atm_get_diagnostic_config() & 0x80) == 0;
|
||||
#else
|
||||
return (*((volatile uint32_t *)_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG) & 0x80) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __has_feature(address_sanitizer)
|
||||
__attribute__((no_sanitize("address")))
|
||||
#endif
|
||||
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
|
||||
__TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
|
||||
OS_ALWAYS_INLINE
|
||||
static inline uint64_t
|
||||
firehose_tracepoint_time(firehose_activity_flags_t flags)
|
||||
{
|
||||
if (firehose_precise_timestamps_enabled() ||
|
||||
(flags & firehose_activity_flags_precise_timestamp)) {
|
||||
return mach_continuous_time();
|
||||
} else {
|
||||
return mach_continuous_approximate_time();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KERNEL
|
||||
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
|
||||
__TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
|
||||
void
|
||||
firehose_trace_metadata(firehose_stream_t stream, firehose_tracepoint_id_u ftid,
|
||||
uint64_t stamp, const void* pubdata, size_t publen);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
OS_ASSUME_NONNULL_END
|
||||
|
||||
#endif // __FIREHOSE_FIREHOSE__
|
||||
501
src/duct/include/os/log.h
Normal file
501
src/duct/include/os/log.h
Normal file
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
#ifndef __os_log_h
|
||||
#define __os_log_h
|
||||
|
||||
#include <os/object.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef __has_attribute
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_attribute(not_tail_called)
|
||||
#define OS_LOG_NOTAILCALL __attribute__((not_tail_called))
|
||||
#define OS_LOG_NOTAILCALL_MARKER
|
||||
#else
|
||||
#define OS_LOG_NOTAILCALL
|
||||
#define OS_LOG_NOTAILCALL_MARKER __asm__("")
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern void *__dso_handle;
|
||||
|
||||
OS_ALWAYS_INLINE static inline void _os_log_verify_format_str(__unused const char *msg, ...) __attribute__((format(os_trace, 1, 2)));
|
||||
OS_ALWAYS_INLINE static inline void _os_log_verify_format_str(__unused const char *msg, ...) { /* placeholder */ }
|
||||
|
||||
#if OS_OBJECT_USE_OBJC
|
||||
OS_OBJECT_DECL(os_log);
|
||||
#else
|
||||
typedef struct os_log_s *os_log_t;
|
||||
#endif /* OS_OBJECT_USE_OBJC */
|
||||
|
||||
/*!
|
||||
* @const OS_LOG_DISABLED
|
||||
*
|
||||
* @discussion
|
||||
* Use this to disable a specific log message.
|
||||
*/
|
||||
#define OS_LOG_DISABLED NULL
|
||||
|
||||
/*!
|
||||
* @const OS_LOG_DEFAULT
|
||||
*
|
||||
* @discussion
|
||||
* Use this to log a message in accordance with current system settings.
|
||||
*/
|
||||
#define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default)
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12,__IPHONE_10_0)
|
||||
OS_EXPORT
|
||||
struct os_log_s _os_log_default;
|
||||
|
||||
/*!
|
||||
* @enum os_log_type_t
|
||||
*
|
||||
* @discussion
|
||||
* Supported log message types.
|
||||
*
|
||||
* @constant OS_LOG_TYPE_DEFAULT
|
||||
* Equivalent type for "os_log()" messages, i.e., default messages that are always
|
||||
* captured to memory or disk.
|
||||
*
|
||||
* @constant OS_LOG_TYPE_INFO
|
||||
* Equivalent type for "os_log_info()" messages, i.e., Additional informational messages.
|
||||
*
|
||||
* @constant OS_LOG_TYPE_DEBUG
|
||||
* Equivalent type for "os_log_debug()" messages, i.e., Debug messages.
|
||||
*
|
||||
* @constant OS_LOG_TYPE_ERROR
|
||||
* Equivalent type for "os_log_error()" messages, i.e., local process error messages.
|
||||
*
|
||||
* @constant OS_LOG_TYPE_FAULT
|
||||
* Equivalent type for "os_log_fault()" messages, i.e., a system error that involves
|
||||
* potentially more than one process, usually used by daemons and services.
|
||||
*/
|
||||
OS_ENUM(os_log_type, uint8_t,
|
||||
OS_LOG_TYPE_DEFAULT = 0x00,
|
||||
OS_LOG_TYPE_INFO = 0x01,
|
||||
OS_LOG_TYPE_DEBUG = 0x02,
|
||||
OS_LOG_TYPE_ERROR = 0x10,
|
||||
OS_LOG_TYPE_FAULT = 0x11);
|
||||
|
||||
/*!
|
||||
* @function os_log_create
|
||||
*
|
||||
* @abstract
|
||||
* Creates a log object to be used with other log related functions.
|
||||
*
|
||||
* @discussion
|
||||
* Creates a log object to be used with other log related functions. The
|
||||
* log object serves two purposes: (1) tag related messages by subsystem
|
||||
* and category name for easy filtering, and (2) control logging system
|
||||
* behavior for messages.
|
||||
*
|
||||
* A log object may customize logging system behavior for its messages by
|
||||
* adding a configuration file in /Library/LogPreferences. Most options
|
||||
* accept 3 values: "Default", "Yes" or "No" as strings, where "Default"
|
||||
* signifies follow system behavior for the level of messages.
|
||||
*
|
||||
* For log:
|
||||
*
|
||||
* os_log_create("com.company.mysubsystem", "connections");
|
||||
*
|
||||
* System-provided preferences are located in /System/Library/LogPreferences/<subsystem>.plist
|
||||
*
|
||||
* <dict>
|
||||
*
|
||||
* <!-- Default options applied to message types in each category, which can be overriden. -->
|
||||
* <key>DEFAULT-OPTIONS</key>
|
||||
* <dict>
|
||||
* <key>Enabled</key> <!-- Enabled state follows system defaults -->
|
||||
* <string>Default</string>
|
||||
* <key>Persist</key> <!-- Do not persist to disk, use memory-only buffer if enabled -->
|
||||
* <string>No</string>
|
||||
* <key>TTL</key> <!-- Follow system default behavior if persistence is enabled -->
|
||||
* <string>Default</string> <!-- Can specify in days with "d" or hours "h" (e.g., "4h" = 4 hours) -->
|
||||
* </dict>
|
||||
*
|
||||
* <!-- category named “connections” -->
|
||||
* <key>connections</key>
|
||||
* <dict>
|
||||
*
|
||||
* <!-- Options that control "os_log()" behavior. The "Enabled" option is ignored. -->
|
||||
* <key>Default</key>
|
||||
* <dict>
|
||||
* <key>Persist</key> <!-- Always persist to disk -->
|
||||
* <string>Yes</string>
|
||||
* <key>TTL</key> <!-- Store default messages for maximum 4 days -->
|
||||
* <integer>4d</integer>
|
||||
* </dict>
|
||||
*
|
||||
* <!-- Subdictionary of options that control "os_log_info()" behavior -->
|
||||
* <key>Info</key>
|
||||
* <dict>
|
||||
* <key>Persist</key> <!-- If enabled persist to disk -->
|
||||
* <string>Yes</string>
|
||||
* <key>TTL</key> <!-- Store Info messages for 2 days -->
|
||||
* <string>2d</string>
|
||||
* </dict>
|
||||
*
|
||||
* <!-- Subdictionary of options that control "os_log_debug()" behavior -->
|
||||
* <key>Debug</key>
|
||||
* <dict>
|
||||
* <key>Enabled</key> <!-- Not enabled, must be enabled specifically -->
|
||||
* <string>No</string>
|
||||
* </dict>
|
||||
* </dict>
|
||||
* </dict>
|
||||
*
|
||||
* All other preferences and system-overrides are stored in /Library/LogPreferences/.
|
||||
*
|
||||
* @param subsystem
|
||||
* The identifier of the given subsystem should be in reverse DNS form
|
||||
* (i.e., com.company.mysubsystem). This string must be a constant string,
|
||||
* not dynamically generated.
|
||||
*
|
||||
* @param category
|
||||
* The category within the given subsystem that specifies the settings for
|
||||
* the log object. This string must be a constant string, not dynamically
|
||||
* generated.
|
||||
*
|
||||
* @result
|
||||
* Returns an os_log_t value to be passed to other os_log API calls. This
|
||||
* should be called once at log initialization and rely on system to detect
|
||||
* changes to settings. This object should be released when no longer used
|
||||
* via os_release or -[release] method.
|
||||
*
|
||||
* A value will always be returned to allow for dynamic enablement.
|
||||
*/
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12,__IPHONE_10_0)
|
||||
OS_EXPORT OS_NOTHROW OS_WARN_RESULT OS_OBJECT_RETURNS_RETAINED
|
||||
os_log_t
|
||||
os_log_create(const char *subsystem, const char *category);
|
||||
|
||||
/*!
|
||||
* @function os_log_info_enabled
|
||||
*
|
||||
* @abstract
|
||||
* Returns if development log messages are enabled for a particular log object.
|
||||
*
|
||||
* @discussion
|
||||
* Returns if development log messages are enabled for a particular log object.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @result
|
||||
* Returns ‘true’ if debug log messages are enabled.
|
||||
*/
|
||||
__WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0)
|
||||
OS_EXPORT OS_NOTHROW OS_WARN_RESULT
|
||||
bool
|
||||
os_log_info_enabled(os_log_t log);
|
||||
|
||||
/*!
|
||||
* @function os_log_debug_enabled
|
||||
*
|
||||
* @abstract
|
||||
* Returns if debug log messages are enabled for a particular log object.
|
||||
*
|
||||
* @discussion
|
||||
* Returns if debug log messages are enabled for a particular log object.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @result
|
||||
* Returns ‘true’ if debug log messages are enabled.
|
||||
*/
|
||||
__WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0)
|
||||
OS_EXPORT OS_NOTHROW OS_WARN_RESULT
|
||||
bool
|
||||
os_log_debug_enabled(os_log_t log);
|
||||
|
||||
/*!
|
||||
* @function os_log
|
||||
*
|
||||
* @abstract
|
||||
* Insert a log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* @discussion
|
||||
* Insert a log message into the Unified Logging and Tracing system in
|
||||
* accordance with the preferences specified by the provided log object.
|
||||
* These messages cannot be disabled and therefore always captured either
|
||||
* to memory or disk.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, OS_LOG_TYPE_DEFAULT, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_info
|
||||
*
|
||||
* @abstract
|
||||
* Insert a development log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* @discussion
|
||||
* Insert a log message into the Unified Logging and Tracing system in
|
||||
* accordance with the preferences specified by the provided log object.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_info(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, OS_LOG_TYPE_INFO, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_debug
|
||||
*
|
||||
* @abstract
|
||||
* Insert a debug log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* @discussion
|
||||
* Insert a debug log message into the Unified Logging and Tracing system in
|
||||
* accordance with the preferences specified by the provided log object.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_debug(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, OS_LOG_TYPE_DEBUG, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_error
|
||||
*
|
||||
* @abstract
|
||||
* Insert an error log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* @discussion
|
||||
* Insert an error log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_error(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, OS_LOG_TYPE_ERROR, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_fault
|
||||
*
|
||||
* @abstract
|
||||
* Insert a fault log message into the Unified Logging and Tracing system.
|
||||
*
|
||||
* @discussion
|
||||
* Log a fault message issue into the Unified Logging and Tracing system
|
||||
* signifying a multi-process (i.e., system error) related issue, either
|
||||
* due to interaction via IPC or some other. Faults will gather information
|
||||
* from the entire process chain and record it for later inspection.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_fault(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, OS_LOG_TYPE_FAULT, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_with_type
|
||||
*
|
||||
* @abstract
|
||||
* Log a message using a specific type.
|
||||
*
|
||||
* @discussion
|
||||
* Will log a message with the provided os_log_type_t.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param type
|
||||
* Pass a valid type from os_log_type_t.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_with_type(log, type, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_internal(&__dso_handle, log, type, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_log_sensitive_debug
|
||||
*
|
||||
* @abstract
|
||||
* Insert a debug log message containing sensitive content (i.e., personal
|
||||
* identifying information).
|
||||
*
|
||||
* @discussion
|
||||
* Insert a debug log message containing sensitive content (i.e., personal
|
||||
* identifying information) in accordance with the preferences specified by
|
||||
* the provided log object.
|
||||
*
|
||||
* All strings are considered potentially sensitive, though this call
|
||||
* specifically signifies the message as containing sensitive content.
|
||||
* The message will be stored separately from other messages.
|
||||
*
|
||||
* When an os_activity_id_t is present, the log message will also be scoped by
|
||||
* that identifier. Activities provide granular filtering of log messages
|
||||
* across threads and processes.
|
||||
*
|
||||
* There is a physical cap of 256 bytes per entry for dynamic content,
|
||||
* i.e., %s and %@, that can be written to the persistence store. As such,
|
||||
* all content exceeding the limit will be truncated before written to disk.
|
||||
* Live streams will continue to show the full content.
|
||||
*
|
||||
* @param log
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. This string must be a constant string, not dynamically
|
||||
* generated. Supports all standard printf types and %@ (objects).
|
||||
*/
|
||||
#define os_log_sensitive_debug(log, format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format string must be constant"); \
|
||||
__attribute__((section("__TEXT,__os_log_sens"))) static const char _os_log_fmt[] = format; \
|
||||
_os_log_verify_format_str(format, ##__VA_ARGS__); \
|
||||
_os_log_sensitive(&__dso_handle, log, OS_LOG_TYPE_DEBUG, _os_log_fmt, ##__VA_ARGS__); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function _os_log_internal
|
||||
*
|
||||
* @abstract
|
||||
* Internal function used by macros.
|
||||
*/
|
||||
__WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0)
|
||||
OS_EXPORT OS_NOTHROW
|
||||
void
|
||||
_os_log_internal(void *dso, os_log_t log, os_log_type_t type, const char *message, ...);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __os_log_h */
|
||||
94
src/duct/include/os/log_private.h
Normal file
94
src/duct/include/os/log_private.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
#ifndef __os_log_private_h
|
||||
#define __os_log_private_h
|
||||
|
||||
#include <os/log.h>
|
||||
#include <firehose/tracepoint_private.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*!
|
||||
* @function os_log_with_args
|
||||
*
|
||||
* @abstract
|
||||
* os_log variant that supports va_list args.
|
||||
*
|
||||
* @discussion
|
||||
* os_log variant that supports va_list args. This SPI should only be used
|
||||
* to shim legacy logging systems through os_log.
|
||||
*
|
||||
* @param oslog
|
||||
* Pass OS_LOG_DEFAULT or a log object previously created with os_log_create.
|
||||
*
|
||||
* @param type
|
||||
* Pass one of the following message types.
|
||||
* OS_LOG_TYPE_DEFAULT
|
||||
* OS_LOG_TYPE_DEBUG
|
||||
* OS_LOG_TYPE_INFO
|
||||
* OS_LOG_TYPE_ERROR
|
||||
* OS_LOG_TYPE_FAULT
|
||||
*
|
||||
* @param format
|
||||
* A format string to generate a human-readable log message when the log
|
||||
* line is decoded. Supports all standard printf types in addition to %@
|
||||
* and %m (objects and errno respectively).
|
||||
*
|
||||
* @param args
|
||||
* A va_list containing the values for the format string.
|
||||
*
|
||||
* @param ret_addr
|
||||
* Pass the __builtin_return_address(0) of the function that created the
|
||||
* va_list from variadic arguments. The caller must be the same binary
|
||||
* that generated the message and provided the format string.
|
||||
*/
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
|
||||
OS_EXPORT OS_NOTHROW OS_LOG_NOTAILCALL
|
||||
void
|
||||
os_log_with_args(os_log_t oslog, os_log_type_t type, const char *format, va_list args, void *ret_addr);
|
||||
|
||||
/*!
|
||||
* @enum oslog_stream_link_type_t
|
||||
*/
|
||||
OS_ENUM(oslog_stream_link_type, uint8_t,
|
||||
oslog_stream_link_type_log = 0x0,
|
||||
oslog_stream_link_type_metadata = 0x1,
|
||||
);
|
||||
|
||||
/*!
|
||||
* @typedef oslog_stream_buf_entry_t
|
||||
*/
|
||||
typedef struct oslog_stream_buf_entry_s {
|
||||
STAILQ_ENTRY(oslog_stream_buf_entry_s) buf_entries;
|
||||
uint64_t timestamp;
|
||||
int offset;
|
||||
uint16_t size;
|
||||
oslog_stream_link_type_t type;
|
||||
struct firehose_tracepoint_s metadata[];
|
||||
} *oslog_stream_buf_entry_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // __os_log_private_h
|
||||
893
src/duct/include/os/trace.h
Normal file
893
src/duct/include/os/trace.h
Normal file
@@ -0,0 +1,893 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2015 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
|
||||
#ifndef __OS_TRACE_H__
|
||||
#define __OS_TRACE_H__
|
||||
|
||||
#include <Availability.h>
|
||||
#include <os/base.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#if __has_include(<xpc/xpc.h>)
|
||||
#include <xpc/xpc.h>
|
||||
#else
|
||||
typedef void *xpc_object_t;
|
||||
#endif
|
||||
|
||||
#if !__GNUC__
|
||||
#error "must be GNU C compatible"
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern void *__dso_handle;
|
||||
|
||||
OS_ALWAYS_INLINE
|
||||
static inline void
|
||||
_os_trace_verify_printf(const char *msg, ...) __attribute__((format(printf, 1, 2)))
|
||||
{
|
||||
#pragma unused(msg)
|
||||
}
|
||||
|
||||
#if !defined OS_COUNT_ARGS
|
||||
#define OS_COUNT_ARGS(...) OS_COUNT_ARGS1(, ##__VA_ARGS__, _8, _7, _6, _5, _4, _3, _2, _1, _0)
|
||||
#define OS_COUNT_ARGS1(z, a, b, c, d, e, f, g, h, cnt, ...) cnt
|
||||
#endif
|
||||
|
||||
/* use old macros for anything less than iOS 10 and MacOS 10.12 */
|
||||
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0) \
|
||||
|| (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_3_0) \
|
||||
|| (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED < __TVOS_10_0) \
|
||||
|| (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12)
|
||||
|
||||
#define _os_trace_0(_l, _m, _t) __extension__({ \
|
||||
_os_trace_verify_printf(_l); \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_1(_l, _m, _t, _1) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
_os_trace_verify_printf(_l, _c1); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
uint8_t _s[1]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._cnt = 1, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_2(_l, _m, _t, _1, _2) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
uint8_t _s[2]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._cnt = 2, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_3(_l, _m, _t, _1, _2, _3) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
uint8_t _s[3]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._cnt = 3, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_4(_l, _m, _t, _1, _2, _3, _4) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
uint8_t _s[4]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._cnt = 4, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_5(_l, _m, _t, _1, _2, _3, _4, _5) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_5) _c5 = _5; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
uint8_t _s[5]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._cnt = 5, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_6(_l, _m, _t, _1, _2, _3, _4, _5, _6) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_5) _c5 = _5; \
|
||||
const __typeof__(_6) _c6 = _6; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
__typeof__(_c6) _f6; \
|
||||
uint8_t _s[6]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._f6 = _c6, ._s[5] = sizeof(_c6), \
|
||||
._cnt = 6, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_5) _c5 = _5; \
|
||||
const __typeof__(_6) _c6 = _6; \
|
||||
const __typeof__(_7) _c7 = _7; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
__typeof__(_c6) _f6; \
|
||||
__typeof__(_c7) _f7; \
|
||||
uint8_t _s[7]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._f6 = _c6, ._s[5] = sizeof(_c6), \
|
||||
._f7 = _c7, ._s[6] = sizeof(_c7), \
|
||||
._cnt = 7, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l); \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, NULL, 0, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
_os_trace_verify_printf(_l, _c1); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
uint8_t _s[1]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._cnt = 1, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
uint8_t _s[2]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._cnt = 2, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
uint8_t _s[3]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._cnt = 3, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
uint8_t _s[4]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._cnt = 4, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_4) _c5 = _5; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
uint8_t _s[5]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._cnt = 5, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_5) _c5 = _5; \
|
||||
const __typeof__(_6) _c6 = _6; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
__typeof__(_c6) _f6; \
|
||||
uint8_t _s[6]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._f6 = _c6, ._s[5] = sizeof(_c6), \
|
||||
._cnt = 6, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wpacked\"") \
|
||||
const __typeof__(_1) _c1 = _1; \
|
||||
const __typeof__(_2) _c2 = _2; \
|
||||
const __typeof__(_3) _c3 = _3; \
|
||||
const __typeof__(_4) _c4 = _4; \
|
||||
const __typeof__(_5) _c5 = _5; \
|
||||
const __typeof__(_6) _c6 = _6; \
|
||||
const __typeof__(_7) _c7 = _7; \
|
||||
_os_trace_verify_printf(_l, _c1, _c2, _c3, _c4, _c5, _c6, _c7); \
|
||||
const struct __attribute__((packed)) { \
|
||||
__typeof__(_c1) _f1; \
|
||||
__typeof__(_c2) _f2; \
|
||||
__typeof__(_c3) _f3; \
|
||||
__typeof__(_c4) _f4; \
|
||||
__typeof__(_c5) _f5; \
|
||||
__typeof__(_c6) _f6; \
|
||||
__typeof__(_c7) _f7; \
|
||||
uint8_t _s[7]; \
|
||||
uint8_t _cnt; \
|
||||
} _buf = { \
|
||||
._f1 = _c1, ._s[0] = sizeof(_c1), \
|
||||
._f2 = _c2, ._s[1] = sizeof(_c2), \
|
||||
._f3 = _c3, ._s[2] = sizeof(_c3), \
|
||||
._f4 = _c4, ._s[3] = sizeof(_c4), \
|
||||
._f5 = _c5, ._s[4] = sizeof(_c5), \
|
||||
._f6 = _c6, ._s[5] = sizeof(_c6), \
|
||||
._f7 = _c7, ._s[6] = sizeof(_c7), \
|
||||
._cnt = 7, \
|
||||
}; \
|
||||
_os_trace_with_buffer(&__dso_handle, _m, _t, &_buf, sizeof(_buf), _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#define OS_TRACE_CALL(format, _m, _t, ...) __extension__({ \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") \
|
||||
OS_CONCAT(_os_trace, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, _t, ##__VA_ARGS__); \
|
||||
_Pragma("clang diagnostic pop") \
|
||||
})
|
||||
|
||||
#else
|
||||
|
||||
// Use a new layout in Mac OS 10.12+ and iOS 10.0+
|
||||
#define OS_TRACE_CALL(_l, _m, _t, ...) __extension__({ \
|
||||
uint8_t buf[1024]; \
|
||||
_os_trace_verify_printf(_l, ##__VA_ARGS__); \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, ##__VA_ARGS__); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, NULL); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_1(_l, _m, _t, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, NULL, 0, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_2(_l, _m, _t, _1, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_3(_l, _m, _t, _1, _2, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_4(_l, _m, _t, _1, _2, _3, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2, _3); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_5(_l, _m, _t, _1, _2, _3, _4, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2, _3, _4); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_6(_l, _m, _t, _1, _2, _3, _4, _5, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2, _3, _4, _5); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_7(_l, _m, _t, _1, _2, _3, _4, _5, _6, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#define _os_trace_with_payload_8(_l, _m, _t, _1, _2, _3, _4, _5, _6, _7, _payload) __extension__({ \
|
||||
_os_trace_verify_printf(_l, _1, _2, _3, _4, _5, _6, _7); \
|
||||
uint8_t buf[1024]; \
|
||||
size_t buf_size = _os_trace_encode(buf, sizeof(buf), _m, _1, _2, _3, _4, _5, _6, _7); \
|
||||
_os_trace_internal(&__dso_handle, _t, _m, buf, buf_size, _payload); \
|
||||
__asm__(""); /* avoid tailcall */ \
|
||||
})
|
||||
|
||||
#endif /* if Mac OS >= 10.12 or iPhone OS >= 10.0 */
|
||||
|
||||
/*!
|
||||
*
|
||||
* @abstract
|
||||
* Hashtags in trace messages
|
||||
*
|
||||
* @discussion
|
||||
* Developers are encouraged to include hashtags in log messages, regardless of what API you use.
|
||||
* A hashtag is composed of a hash (#) symbol, followed by at least three non-whitespace characters,
|
||||
* terminated by whitespace or the end of the message. Hashtags may not begin with a number.
|
||||
*
|
||||
* Below is the list of predefined tags:
|
||||
* #System - Message in the context of a system process.
|
||||
* #User - Message in the context of a user process.
|
||||
* #Developer - Message in the context of software development. For example, deprecated APIs and debugging messages.
|
||||
* #Attention - Message that should be investigated by a system administrator, because it may be a sign of a larger issue.
|
||||
* For example, errors from a hard drive controller that typically occur when the drive is about to fail.
|
||||
* #Critical - Message in the context of a critical event or critical failure.
|
||||
* #Error - Message that is a noncritical error.
|
||||
* #Comment - Message that is a comment.
|
||||
* #Marker - Message that marks a change to divide the messages around it into those before and those after the change.
|
||||
* #Clue - Message containing extra key/value pairs with additional information to help reconstruct the context.
|
||||
* #Security - Message related to security concerns.
|
||||
* #Filesystem - Message describing a file system related event.
|
||||
* #Network - Message describing a network-related event.
|
||||
* #Hardware - Message describing a hardware-related event.
|
||||
* #CPU - Message describing CPU related event, e.g., initiating heavy work load
|
||||
* #State - Message describing state changed, e.g., global state, preference, etc.
|
||||
* #Graphics - Message describing significant graphics event
|
||||
* #Disk - Message describing disk activity
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma mark - Other defines
|
||||
|
||||
/*!
|
||||
* @define OS_TRACE_TYPE_RELEASE
|
||||
* Trace messages to be captured on a typical user install. These should be
|
||||
* limited to things which improve diagnosis of a failure/crash/hang. Trace
|
||||
* buffers are generally smaller on a production system.
|
||||
*/
|
||||
#define OS_TRACE_TYPE_RELEASE (1u << 0)
|
||||
|
||||
/*!
|
||||
* @define OS_TRACE_TYPE_DEBUG
|
||||
* Trace messages to be captured while debugger or other development tool is
|
||||
* attached to the originator.
|
||||
*/
|
||||
#define OS_TRACE_TYPE_DEBUG (1u << 1)
|
||||
|
||||
/*!
|
||||
* @define OS_TRACE_TYPE_INFO
|
||||
* Trace messages that are captured when a debugger is attached, system or
|
||||
* Application mode has been increased to include additional information.
|
||||
*/
|
||||
#define OS_TRACE_TYPE_INFO (1u << 2)
|
||||
|
||||
/*!
|
||||
* @define OS_TRACE_TYPE_ERROR
|
||||
* Trace the message as an error and force a collection as a failure may be
|
||||
* imminent.
|
||||
*/
|
||||
#define OS_TRACE_TYPE_ERROR ((1u << 6) | (1u << 0))
|
||||
|
||||
/*!
|
||||
* @define OS_TRACE_TYPE_FAULT
|
||||
* Trace the message as a fatal error which forces a collection and a diagnostic
|
||||
* to be initiated.
|
||||
*/
|
||||
#define OS_TRACE_TYPE_FAULT ((1u << 7) | (1u << 6) | (1u << 0))
|
||||
|
||||
/*!
|
||||
* @typedef os_trace_payload_t
|
||||
* A block that populates an xpc_object_t of type XPC_TYPE_DICTIONARY to represent
|
||||
* complex data. This block will only be invoked under conditions where tools
|
||||
* have attached to the process. The payload can be used to send arbitrary data
|
||||
* via the trace call. Tools may use the data to validate state for integration
|
||||
* tests or provide other introspection services. No assumptions are made about
|
||||
* the format or structure of the data.
|
||||
*/
|
||||
typedef void (^os_trace_payload_t)(xpc_object_t xdict);
|
||||
|
||||
#pragma mark - function declarations
|
||||
|
||||
/*!
|
||||
* @function os_trace
|
||||
*
|
||||
* @abstract
|
||||
* Always inserts a trace message into a buffer pool for later decoding.
|
||||
*
|
||||
* @discussion
|
||||
* Trace message that will be recorded on a typical user install. These should
|
||||
* be limited to things which help diagnose a failure during postmortem
|
||||
* analysis. Trace buffers are generally smaller on a production system.
|
||||
*
|
||||
* @param format
|
||||
* A printf-style format string to generate a human-readable log message when
|
||||
* the trace line is decoded. Only scalar types are supported, attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* os_trace("network event: %ld, last seen: %ld, avg: %g", event_id, last_seen, avg);
|
||||
*/
|
||||
#define os_trace(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
|
||||
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_10_0) \
|
||||
|| (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED >= __WATCHOS_3_0) \
|
||||
|| (defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED >= __TVOS_10_0) \
|
||||
|| (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12)
|
||||
|
||||
/*!
|
||||
* @function os_trace_info
|
||||
*
|
||||
* @abstract
|
||||
* Optionally inserts a trace message containing additional information into a
|
||||
* buffer pool for later decoding.
|
||||
*
|
||||
* @discussion
|
||||
* Trace messages that will be captured when additional information is needed
|
||||
* and are not captured by default. They will only be captured if the
|
||||
* system/process/activity mode has been increased or if a Development tool has
|
||||
* been attached to the process.
|
||||
*
|
||||
* @param format
|
||||
* A printf-style format string that represents a human-readable message when
|
||||
* the trace line is decoded. Only scalar types are supported, attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* os_trace_info("network interface status %ld", status);
|
||||
*/
|
||||
#define os_trace_info(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @function os_trace_debug
|
||||
*
|
||||
* @abstract
|
||||
* Insert debug trace message into a buffer pool for later decoding.
|
||||
*
|
||||
* @discussion
|
||||
* Debug trace message to be recorded while debugger or other development tool is
|
||||
* attached to the originator. This is transported interprocess to help
|
||||
* diagnose the entire call chain including external helpers.
|
||||
*
|
||||
* @param format
|
||||
* A printf-style format string that represents a human-readable message when
|
||||
* the trace line is decoded. Only scalar types are supported, attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* os_trace_debug("network interface status %ld", status);
|
||||
*/
|
||||
#define os_trace_debug(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_trace_info_enabled
|
||||
*
|
||||
* @abstract
|
||||
* Avoid unnecessary work for a trace point by checking if additional information
|
||||
* is enabled.
|
||||
*
|
||||
* @discussion
|
||||
* Avoid unnecessary work for a trace point by checking if additional information
|
||||
* is enabled. Generally trace points should not involve expensive operations, but some
|
||||
* circumstances warrant it. Use this function to avoid doing the work unless
|
||||
* debug level trace messages are requested.
|
||||
*
|
||||
* if (os_trace_info_enabled()) {
|
||||
* os_trace_info("value = %d, average = %d",
|
||||
* [[dict objectForKey: @"myKey"] intValue],
|
||||
* (int) [self getAverage: dict]);
|
||||
* }
|
||||
*
|
||||
* @result
|
||||
* Returns true if development mode is enabled.
|
||||
*/
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
|
||||
OS_EXPORT OS_NOTHROW OS_WARN_RESULT
|
||||
bool
|
||||
os_trace_info_enabled(void);
|
||||
|
||||
/*!
|
||||
* @function os_trace_debug_enabled
|
||||
*
|
||||
* @abstract
|
||||
* Avoid unnecessary work for a trace point by checking if debug level is enabled.
|
||||
*
|
||||
* @discussion
|
||||
* Avoid unnecessary work for a trace point by checking if debug level is enabled.
|
||||
* Generally trace points should not involve expensive operations, but some
|
||||
* circumstances warrant it. Use this function to avoid doing the work unless
|
||||
* debug level trace messages are requested.
|
||||
*
|
||||
* if (os_trace_debug_enabled()) {
|
||||
* os_trace_debug("value = %d, average = %d",
|
||||
* [[dict objectForKey: @"myKey"] intValue],
|
||||
* (int) [self getAverage: dict]);
|
||||
* }
|
||||
*
|
||||
* @result
|
||||
* Returns true if debug mode is enabled.
|
||||
*/
|
||||
__OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0)
|
||||
OS_EXPORT OS_NOTHROW OS_WARN_RESULT
|
||||
bool
|
||||
os_trace_debug_enabled(void);
|
||||
|
||||
/*!
|
||||
* @function os_trace_error
|
||||
*
|
||||
* @abstract
|
||||
* Trace the message as an error and force a collection of the trace buffer as a
|
||||
* failure may be imminent.
|
||||
*
|
||||
* @discussion
|
||||
* Trace the message as an error and force a collection of the trace buffer as a
|
||||
* failure may be imminent.
|
||||
*
|
||||
* @param format
|
||||
* A printf-style format string to generate a human-readable log message when
|
||||
* the trace line is decoded. Only scalar types are supported, attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* os_trace_error("socket %d connection timeout %ld", fd, secs);
|
||||
*/
|
||||
#define os_trace_error(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
/*!
|
||||
* @function os_trace_fault
|
||||
*
|
||||
* @abstract
|
||||
* Trace the message as a fault which forces a collection of the trace buffer
|
||||
* and diagnostic of the activity.
|
||||
*
|
||||
* @discussion
|
||||
* Trace the message as a fault which forces a collection of the trace buffer
|
||||
* and diagnostic of the activity.
|
||||
*
|
||||
* @param format
|
||||
* A printf-style format string to generate a human-readable log message when
|
||||
* the trace line is decoded. Only scalar types are supported, attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* os_trace_fault("failed to lookup uid %d - aborting", uid);
|
||||
*/
|
||||
#define os_trace_fault(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_TRACE_CALL(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#if __has_include(<xpc/xpc.h>)
|
||||
/*!
|
||||
* @function os_trace_with_payload
|
||||
*
|
||||
* @abstract
|
||||
* Add a trace entry containing the provided values and call the block if
|
||||
* appropriate.
|
||||
*
|
||||
* @discussion
|
||||
* Will insert a trace entry into a limited ring buffer for an activity or
|
||||
* process. Trace points are for recording interesting data that would improve
|
||||
* diagnosis of unexpected crashes, failures and hangs. The block will only be
|
||||
* called under the required conditions.
|
||||
*
|
||||
* @param trace_msg
|
||||
* A printf-style format string to generate a human-readable log message when
|
||||
* the trace line is decoded. Only scalar types are supported. Attempts
|
||||
* to pass arbitrary strings will store a pointer that is unresolvable and
|
||||
* will generate an error during decode.
|
||||
*
|
||||
* The final parameter must be a block of type os_trace_payload_t.
|
||||
*
|
||||
* os_trace_with_payload("network event %ld", event, ^(xpc_object_t xdict) {
|
||||
*
|
||||
* // validate the network interface and address where what was expected
|
||||
* xpc_dictionary_set_string(xdict, "network", ifp->ifa_name);
|
||||
* xpc_dictionary_set_string(xdict, "ip_address", _get_address(ifp));
|
||||
* });
|
||||
*/
|
||||
#define os_trace_with_payload(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_RELEASE, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#define os_trace_info_with_payload(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_INFO, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#define os_trace_debug_with_payload(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#define os_trace_error_with_payload(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_ERROR, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#define os_trace_fault_with_payload(format, ...) __extension__({ \
|
||||
_Static_assert(__builtin_constant_p(format), "format must be a constant string"); \
|
||||
__attribute__((section("__TEXT,__os_trace"))) static const char _m[] = format; \
|
||||
OS_CONCAT(_os_trace_with_payload, OS_COUNT_ARGS(__VA_ARGS__))(format, _m, OS_TRACE_TYPE_FAULT, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#endif // __has_include(<xpc/xpc.h>)
|
||||
|
||||
// TODO: change this once we have compiler support
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
|
||||
OS_EXPORT OS_NOTHROW
|
||||
size_t
|
||||
_os_trace_encode(uint8_t *buf, size_t buf_size, const char *format, ...);
|
||||
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0)
|
||||
OS_EXPORT OS_NOTHROW
|
||||
void
|
||||
_os_trace_internal(void *dso, uint8_t type, const char *format, const uint8_t *buf, size_t buf_size, os_trace_payload_t payload);
|
||||
|
||||
/*!
|
||||
* @function _os_trace_with_buffer
|
||||
*
|
||||
* @abstract
|
||||
* Internal function to support pre-encoded buffer.
|
||||
*/
|
||||
__OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.0) __WATCHOS_AVAILABLE(1.0) __TVOS_AVAILABLE(9.0)
|
||||
OS_EXPORT OS_NOTHROW
|
||||
void
|
||||
_os_trace_with_buffer(void *dso, const char *message, uint8_t type, const void *buffer, size_t buffer_size, os_trace_payload_t payload);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // __OS_TRACE_H__
|
||||
@@ -8,16 +8,22 @@ add_definitions(-D__APPLE__ -D__DYNAMIC__ -DPRIVATE)
|
||||
add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load")
|
||||
|
||||
SET(duct_sources
|
||||
commpage.c libnotify.c numcpus.c
|
||||
CRGetCrashLogMessage.c acl.c bootstrap.c dns_sd.c
|
||||
sa_dst_compare.c asl.c)
|
||||
sa_dst_compare.c os_log.c)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_duct.dylib")
|
||||
add_darling_library(system_duct SHARED ${duct_sources})
|
||||
make_fat(system_duct)
|
||||
add_circular(system_duct FAT
|
||||
SOURCES
|
||||
${duct_sources}
|
||||
SIBLINGS
|
||||
system_kernel
|
||||
system_dyld
|
||||
)
|
||||
#make_fat(system_duct)
|
||||
|
||||
set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar")
|
||||
set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib")
|
||||
|
||||
@@ -7,11 +7,3 @@ int acl_size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _simple_asl_msg_set()
|
||||
{
|
||||
}
|
||||
|
||||
void _simple_asl_send()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#include <stddef.h>
|
||||
|
||||
int asl_close()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_get()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_open()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_set_query()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_store_match_timeout()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_new()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_free()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aslresponse_free()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_set()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aslresponse_next()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_store_open_read()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_send()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int asl_store_close()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* _simple_asl_msg_new()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
11
src/duct/src/os_log.c
Normal file
11
src/duct/src/os_log.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int _os_log_default;
|
||||
|
||||
int os_log_shim_legacy_logging_enabled(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_log_shim_with_va_list()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// This function is called from _gai_addr_sort()
|
||||
// No implementation seems to be available.
|
||||
// On macOS, it resides in libsystem_network.dylib, which is not open source.
|
||||
|
||||
int sa_dst_compare()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,8 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/mach-o)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libdyld.dylib")
|
||||
add_darling_library(system_dyld SHARED
|
||||
add_circular(system_dyld FAT
|
||||
SOURCES
|
||||
src/dyldAPIsInLibSystem.cpp
|
||||
src/dyld_stub_binder.S
|
||||
src/dyldLibSystemGlue.c
|
||||
@@ -42,11 +43,16 @@ add_darling_library(system_dyld SHARED
|
||||
src/dyldLock.cpp
|
||||
src/threadLocalVariables.c
|
||||
src/start_glue.S
|
||||
SIBLINGS
|
||||
system_c system_kernel compiler_rt platform
|
||||
DEPENDENCIES
|
||||
launch
|
||||
)
|
||||
set_target_properties(system_dyld PROPERTIES
|
||||
OUTPUT_NAME "dyld"
|
||||
COMPILE_FLAGS "-fno-exceptions -fno-rtti")
|
||||
target_link_libraries(system_dyld PRIVATE system_c system_kernel compiler_rt launch)
|
||||
OUTPUT_NAME "dyld")
|
||||
set_property(TARGET system_dyld_obj APPEND_STRING PROPERTY
|
||||
COMPILE_FLAGS " -fno-exceptions -fno-rtti")
|
||||
#target_link_libraries(system_dyld PRIVATE platform_static32 platform_static64 system_c system_kernel compiler_rt launch)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_SAVED} -nostdlib")
|
||||
|
||||
@@ -74,9 +80,13 @@ add_executable(system_loader
|
||||
use_ld64(system_loader)
|
||||
set_target_properties(system_loader PROPERTIES OUTPUT_NAME "dyld")
|
||||
set_property(TARGET system_loader APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dylinker -Wl,-dead_strip -nostdlib -Wl,-e,__dyld_start")
|
||||
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)
|
||||
target_link_libraries(system_loader libc_static system_blocks_static
|
||||
libc_static32 libc_static64
|
||||
unwind_static system_kernel_static system_m_static cxxabi_static
|
||||
keymgr_static compiler_rt_static32 compiler_rt_static64 system_duct_static
|
||||
platform_static32 platform_static64 pthread_static)
|
||||
|
||||
make_fat(system_dyld)
|
||||
#make_fat(system_dyld)
|
||||
|
||||
install(TARGETS system_dyld DESTINATION libexec/darling/usr/lib/system)
|
||||
install(TARGETS system_loader DESTINATION libexec/darling/usr/lib)
|
||||
|
||||
@@ -20,6 +20,7 @@ set(mldr_sources
|
||||
mldr.c
|
||||
threads.c
|
||||
gdb.c
|
||||
commpage.c
|
||||
)
|
||||
add_executable(mldr ${mldr_sources})
|
||||
target_link_libraries(mldr -lpthread -ldl)
|
||||
|
||||
138
src/dyld/commpage.c
Normal file
138
src/dyld/commpage.c
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "commpage.h"
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <cpuid.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
// Include commpage definitions
|
||||
#define PRIVATE
|
||||
#include "../../kernel-include/i386/cpu_capabilities.h"
|
||||
|
||||
static const char* SIGNATURE32 = "commpage 32-bit";
|
||||
static const char* SIGNATURE64 = "commpage 64-bit";
|
||||
|
||||
static uint64_t get_cpu_caps(void);
|
||||
|
||||
void commpage_setup(bool _64bit)
|
||||
{
|
||||
void* commpage;
|
||||
uint64_t* cpu_caps64;
|
||||
uint32_t* cpu_caps;
|
||||
uint16_t* version;
|
||||
char* signature;
|
||||
uint64_t my_caps;
|
||||
uint8_t *ncpus, *nactivecpus;
|
||||
struct sysinfo si;
|
||||
|
||||
commpage = mmap((void*)(_64bit ? _COMM_PAGE64_BASE_ADDRESS : _COMM_PAGE32_BASE_ADDRESS),
|
||||
_64bit ? _COMM_PAGE64_AREA_LENGTH : _COMM_PAGE32_AREA_LENGTH, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
if (commpage == MAP_FAILED)
|
||||
{
|
||||
fprintf(stderr, "Cannot mmap commpage: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signature = (char*)_COMM_PAGE_SIGNATURE;
|
||||
version = (uint16_t*)_COMM_PAGE_VERSION;
|
||||
cpu_caps64 = (uint64_t*)_COMM_PAGE_CPU_CAPABILITIES64;
|
||||
cpu_caps = (uint32_t*)_COMM_PAGE_CPU_CAPABILITIES;
|
||||
|
||||
strcpy(signature, _64bit ? SIGNATURE64 : SIGNATURE32);
|
||||
*version = _COMM_PAGE_THIS_VERSION;
|
||||
|
||||
ncpus = (uint8_t*)_COMM_PAGE_NCPUS;
|
||||
*ncpus = sysconf(_SC_NPROCESSORS_CONF);
|
||||
|
||||
nactivecpus = (uint8_t*)_COMM_PAGE_ACTIVE_CPUS;
|
||||
*nactivecpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
my_caps = get_cpu_caps();
|
||||
if (*ncpus == 1)
|
||||
my_caps |= kUP;
|
||||
|
||||
*cpu_caps = (uint32_t) my_caps;
|
||||
*cpu_caps64 = my_caps;
|
||||
|
||||
if (sysinfo(&si) == 0)
|
||||
{
|
||||
uint64_t* memsize = (uint64_t*)_COMM_PAGE_MEMORY_SIZE;
|
||||
*memsize = si.totalram * si.mem_unit;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t get_cpu_caps(void)
|
||||
{
|
||||
uint64_t caps = 0;
|
||||
|
||||
{
|
||||
union cpu_flags1 eax;
|
||||
union cpu_flags2 ecx;
|
||||
union cpu_flags3 edx;
|
||||
uint32_t ebx;
|
||||
|
||||
eax.reg = ecx.reg = edx.reg = 0;
|
||||
__cpuid(1, eax.reg, ebx, ecx.reg, edx.reg);
|
||||
|
||||
if (ecx.mmx)
|
||||
caps |= kHasMMX;
|
||||
if (ecx.sse)
|
||||
caps |= kHasSSE;
|
||||
if (ecx.sse2)
|
||||
caps |= kHasSSE2;
|
||||
if (edx.sse3)
|
||||
caps |= kHasSSE3;
|
||||
if (ecx.ia64)
|
||||
caps |= k64Bit;
|
||||
if (edx.ssse3)
|
||||
caps |= kHasSupplementalSSE3;
|
||||
if (edx.sse41)
|
||||
caps |= kHasSSE4_1;
|
||||
if (edx.sse42)
|
||||
caps |= kHasSSE4_2;
|
||||
if (edx.aes)
|
||||
caps |= kHasAES;
|
||||
if (edx.avx)
|
||||
caps |= kHasAVX1_0;
|
||||
if (edx.rdrnd)
|
||||
caps |= kHasRDRAND;
|
||||
if (edx.fma)
|
||||
caps |= kHasFMA;
|
||||
if (edx.f16c)
|
||||
caps |= kHasF16C;
|
||||
}
|
||||
{
|
||||
union cpu_flags4 ebx;
|
||||
union cpu_flags5 ecx;
|
||||
uint32_t edx = 0, eax = 7;
|
||||
|
||||
__cpuid(7, eax, ebx.reg, ecx.reg, edx);
|
||||
|
||||
if (ebx.erms)
|
||||
caps |= kHasENFSTRG;
|
||||
if (ebx.avx2)
|
||||
caps |= kHasAVX2_0;
|
||||
if (ebx.bmi1)
|
||||
caps |= kHasBMI1;
|
||||
if (ebx.bmi2)
|
||||
caps |= kHasBMI2;
|
||||
if (ebx.rtm)
|
||||
caps |= kHasRTM;
|
||||
if (ebx.hle)
|
||||
caps |= kHasHLE;
|
||||
if (ebx.rdseed)
|
||||
caps |= kHasRDSEED;
|
||||
if (ebx.adx)
|
||||
caps |= kHasADX;
|
||||
if (ebx.mpx)
|
||||
caps |= kHasMPX;
|
||||
if (ebx.sgx)
|
||||
caps |= kHasSGX;
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
146
src/dyld/commpage.h
Normal file
146
src/dyld/commpage.h
Normal file
@@ -0,0 +1,146 @@
|
||||
#ifndef _COMMPAGE_H
|
||||
#define _COMMPAGE_H
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void commpage_setup(bool _64bit);
|
||||
|
||||
union cpu_flags1 {
|
||||
struct {
|
||||
uint8_t step: 4;
|
||||
uint8_t model: 4;
|
||||
uint8_t family: 4;
|
||||
uint8_t type: 2;
|
||||
uint8_t pad1: 2;
|
||||
uint8_t emodel: 4;
|
||||
uint8_t efamily: 8;
|
||||
uint8_t pad2: 4;
|
||||
};
|
||||
uint32_t reg;
|
||||
};
|
||||
|
||||
union cpu_flags2 {
|
||||
struct {
|
||||
uint8_t fpu: 1;
|
||||
uint8_t vme: 1;
|
||||
uint8_t de: 1;
|
||||
uint8_t pse: 1;
|
||||
uint8_t tsc: 1;
|
||||
uint8_t msr: 1;
|
||||
uint8_t pae: 1;
|
||||
uint8_t mce: 1;
|
||||
uint8_t cx8: 1;
|
||||
uint8_t apic: 1;
|
||||
uint8_t reserved1: 1;
|
||||
uint8_t sep: 1;
|
||||
uint8_t mtrr: 1;
|
||||
uint8_t pge: 1;
|
||||
uint8_t mca: 1;
|
||||
uint8_t cmov: 1;
|
||||
uint8_t pat: 1;
|
||||
uint8_t pse36: 1;
|
||||
uint8_t psn: 1;
|
||||
uint8_t clfsh: 1;
|
||||
uint8_t reserved2: 1;
|
||||
uint8_t ds: 1;
|
||||
uint8_t acpi: 1;
|
||||
uint8_t mmx: 1;
|
||||
uint8_t fxsr: 1;
|
||||
uint8_t sse: 1;
|
||||
uint8_t sse2: 1;
|
||||
uint8_t ss: 1;
|
||||
uint8_t htt: 1;
|
||||
uint8_t tm: 1;
|
||||
uint8_t ia64: 1;
|
||||
uint8_t pbe: 1;
|
||||
};
|
||||
uint32_t reg;
|
||||
};
|
||||
|
||||
union cpu_flags3 {
|
||||
struct {
|
||||
uint32_t sse3: 1;
|
||||
uint32_t pclmulqdq: 1;
|
||||
uint32_t dtes64: 1;
|
||||
uint32_t monitor: 1;
|
||||
uint32_t dscpl: 1;
|
||||
uint32_t vmx: 1;
|
||||
uint32_t smx: 1;
|
||||
uint32_t est: 1;
|
||||
uint32_t tm2: 1;
|
||||
uint32_t ssse3: 1;
|
||||
uint32_t cntxid: 1;
|
||||
uint32_t sdbg: 1;
|
||||
uint32_t fma: 1;
|
||||
uint32_t cx16: 1;
|
||||
uint32_t xtpr: 1;
|
||||
uint32_t pdcm: 1;
|
||||
uint32_t reserved1: 1;
|
||||
uint32_t pcid: 1;
|
||||
uint32_t dca: 1;
|
||||
uint32_t sse41: 1;
|
||||
uint32_t sse42: 1;
|
||||
uint32_t x2apic: 1;
|
||||
uint32_t movbe: 1;
|
||||
uint32_t popcnt: 1;
|
||||
uint32_t tscdadline: 1;
|
||||
uint32_t aes: 1;
|
||||
uint32_t xsave: 1;
|
||||
uint32_t osxsave: 1;
|
||||
uint32_t avx: 1;
|
||||
uint32_t f16c: 1;
|
||||
uint32_t rdrnd: 1;
|
||||
uint32_t hypervisor: 1;
|
||||
};
|
||||
uint32_t reg;
|
||||
};
|
||||
|
||||
union cpu_flags4 {
|
||||
struct {
|
||||
uint8_t fsgsbase: 1;
|
||||
uint8_t ia32tscadjust: 1;
|
||||
uint8_t sgx: 1;
|
||||
uint8_t bmi1: 1;
|
||||
uint8_t hle: 1;
|
||||
uint8_t avx2: 1;
|
||||
uint8_t reserved1: 1;
|
||||
uint8_t smep: 1;
|
||||
uint8_t bmi2: 1;
|
||||
uint8_t erms: 1;
|
||||
uint8_t invpcid: 1;
|
||||
uint8_t rtm: 1;
|
||||
uint8_t pqm: 1;
|
||||
uint8_t fpucsdsdeprecated: 1;
|
||||
uint8_t mpx: 1;
|
||||
uint8_t pqe: 1;
|
||||
uint8_t avx512f: 1;
|
||||
uint8_t avx512dq: 1;
|
||||
uint8_t rdseed: 1;
|
||||
uint8_t adx: 1;
|
||||
uint8_t smap: 1;
|
||||
uint8_t avx512ifma: 1;
|
||||
uint8_t pcommit: 1;
|
||||
uint8_t clflushopt: 1;
|
||||
uint8_t clwb: 1;
|
||||
uint8_t intelproctrace: 1;
|
||||
uint8_t avx512pf: 1;
|
||||
uint8_t avx512er: 1;
|
||||
uint8_t avx512cd: 1;
|
||||
uint8_t sha: 1;
|
||||
uint8_t avx512bw: 1;
|
||||
uint8_t avx512vl: 1;
|
||||
};
|
||||
uint32_t reg;
|
||||
};
|
||||
|
||||
union cpu_flags5 {
|
||||
struct {
|
||||
uint8_t prefetchwt1: 1;
|
||||
uint8_t avx512vbmi: 1;
|
||||
uint32_t reserved: 30;
|
||||
};
|
||||
uint32_t reg;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2016 Lubos Dolezel
|
||||
Copyright (C) 2017 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -34,6 +34,7 @@ along with Darling. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "elfcalls.h"
|
||||
#include "threads.h"
|
||||
#include "gdb.h"
|
||||
#include "commpage.h"
|
||||
|
||||
#ifndef PAGE_SIZE
|
||||
# define PAGE_SIZE 4096
|
||||
@@ -54,6 +55,7 @@ static void load(const char* path, uint64_t* entryPoint_out, uint64_t* mh_out);
|
||||
static int native_prot(int prot);
|
||||
static void apply_root_path(char* path);
|
||||
static char* elfcalls_make(void);
|
||||
static char* apple0_make(const char* filepath);
|
||||
|
||||
int main(int argc, char** argv, char** envp)
|
||||
{
|
||||
@@ -106,7 +108,7 @@ int main(int argc, char** argv, char** envp)
|
||||
# error Unsupported platform!
|
||||
#endif
|
||||
|
||||
apple[0] = filename;
|
||||
apple[0] = apple0_make(filename);
|
||||
apple[1] = elfcalls_make();
|
||||
apple[2] = NULL;
|
||||
|
||||
@@ -157,11 +159,16 @@ void load(const char* path, uint64_t* entryPoint_out, uint64_t* mh_out)
|
||||
|
||||
if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64)
|
||||
{
|
||||
if (mh_out)
|
||||
commpage_setup(true);
|
||||
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
load64(fd, entryPoint_out, mh_out);
|
||||
}
|
||||
else if (magic == FAT_MAGIC || magic == FAT_CIGAM)
|
||||
{
|
||||
if (mh_out)
|
||||
commpage_setup(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -412,3 +419,15 @@ static char* elfcalls_make(void)
|
||||
return param;
|
||||
}
|
||||
|
||||
char* apple0_make(const char* filepath)
|
||||
{
|
||||
const char prefix[] = "executable_path=";
|
||||
char* apple0;
|
||||
|
||||
apple0 = (char*) malloc(strlen(filepath) + sizeof(prefix));
|
||||
strcpy(apple0, prefix);
|
||||
strcat(apple0, filepath);
|
||||
|
||||
return apple0;
|
||||
}
|
||||
|
||||
|
||||
2
src/external/adv_cmds
vendored
2
src/external/adv_cmds
vendored
Submodule src/external/adv_cmds updated: 314c032e06...5b31c03ffa
2
src/external/apr
vendored
2
src/external/apr
vendored
Submodule src/external/apr updated: 31906a4bd5...155633ab5d
2
src/external/bzip2
vendored
2
src/external/bzip2
vendored
Submodule src/external/bzip2 updated: 91fd441c8a...7c278751da
2
src/external/compiler-rt
vendored
2
src/external/compiler-rt
vendored
Submodule src/external/compiler-rt updated: 2e6b25e8e4...756b73078c
2
src/external/curl
vendored
2
src/external/curl
vendored
Submodule src/external/curl updated: 154ef8c7fc...fc8bd94193
2
src/external/expat
vendored
2
src/external/expat
vendored
Submodule src/external/expat updated: d387e37b3e...0f4976638b
2
src/external/icu
vendored
2
src/external/icu
vendored
Submodule src/external/icu updated: e658d4e2de...6fb99f4bf3
2
src/external/libarchive
vendored
2
src/external/libarchive
vendored
Submodule src/external/libarchive updated: 0f1f6f8ad9...26813aaf71
2
src/external/libdispatch
vendored
2
src/external/libdispatch
vendored
Submodule src/external/libdispatch updated: e5b75ab5d2...44f8109459
2
src/external/liblzma
vendored
2
src/external/liblzma
vendored
Submodule src/external/liblzma updated: 79edeee1ab...c3b70a3388
2
src/external/libplatform
vendored
2
src/external/libplatform
vendored
Submodule src/external/libplatform updated: 680dbc2ca2...ed5c609e0a
2
src/external/libpthread
vendored
2
src/external/libpthread
vendored
Submodule src/external/libpthread updated: 6e8bea3aba...e6dded6c6e
2
src/external/libxml2
vendored
2
src/external/libxml2
vendored
Submodule src/external/libxml2 updated: 7f67d58106...ddddc8c71a
2
src/external/libxpc
vendored
2
src/external/libxpc
vendored
Submodule src/external/libxpc updated: f9d2655335...ee160b8de0
2
src/external/libxslt
vendored
2
src/external/libxslt
vendored
Submodule src/external/libxslt updated: 4115c2e370...a70b4c7efc
2
src/external/openpam
vendored
2
src/external/openpam
vendored
Submodule src/external/openpam updated: 735329f3e6...69041c3253
2
src/external/openssl
vendored
2
src/external/openssl
vendored
Submodule src/external/openssl updated: b3fcc9b36e...35bf52db96
2
src/external/pcre
vendored
2
src/external/pcre
vendored
Submodule src/external/pcre updated: 56c183f8e3...d8b176c85e
2
src/external/shell_cmds
vendored
2
src/external/shell_cmds
vendored
Submodule src/external/shell_cmds updated: d6ba60bb6c...77a1df6923
2
src/external/sqlite
vendored
2
src/external/sqlite
vendored
Submodule src/external/sqlite updated: 8fc2e7be46...70c0cb6e52
2
src/external/syslog
vendored
2
src/external/syslog
vendored
Submodule src/external/syslog updated: 8e7f76186d...4613412d8a
2
src/external/zlib
vendored
2
src/external/zlib
vendored
Submodule src/external/zlib updated: 2b46e68475...cf7fabfce1
@@ -21,9 +21,15 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -fblocks -ggdb")
|
||||
# -> dyld places stubs -> stubs go into dyld_stub_binder at first use
|
||||
# -> there is a temporary loss of 16-byte stack alignment in __darling_bsd_syscall
|
||||
# -> dyld_stub_binder checks for this and bails out with a SIGSEGV
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc -Wl,-bind_at_load -Wl,-undefined,suppress -Wl,-flat_namespace")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc -Wl,-bind_at_load")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib")
|
||||
|
||||
#set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_c.dylib")
|
||||
#add_darling_library(fakelibc SHARED fakelibc.c)
|
||||
#make_fat(fakelibc)
|
||||
#set(DYLIB_INSTALL_NAME "/usr/lib/system/libdyld.dylib")
|
||||
#add_darling_library(fakedyld SHARED fakedyld.c)
|
||||
#make_fat(fakedyld)
|
||||
|
||||
add_definitions(-DTARGET_OS_MAC=1)
|
||||
add_definitions(-DHAVE_STDINT_H=1)
|
||||
@@ -33,22 +39,26 @@ add_subdirectory(libsyscall)
|
||||
add_subdirectory(mach_server/client)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_kernel.dylib")
|
||||
add_darling_library(system_kernel SHARED
|
||||
$<TARGET_OBJECTS:libsyscall>
|
||||
$<TARGET_OBJECTS:libsyscall_dynamic>
|
||||
#$<TARGET_OBJECTS:kqueue>
|
||||
$<TARGET_OBJECTS:emulation>
|
||||
${extra_objs}
|
||||
$<TARGET_OBJECTS:mach_server_client>)
|
||||
target_link_libraries(system_kernel system_duct)
|
||||
add_circular(system_kernel FAT
|
||||
OBJECTS
|
||||
$<TARGET_OBJECTS:libsyscall>
|
||||
$<TARGET_OBJECTS:libsyscall_dynamic>
|
||||
#$<TARGET_OBJECTS:kqueue>
|
||||
$<TARGET_OBJECTS:emulation>
|
||||
$<TARGET_OBJECTS:mach_server_client>
|
||||
SIBLINGS
|
||||
system_c
|
||||
compiler_rt
|
||||
system_dyld
|
||||
)
|
||||
#target_link_libraries(system_kernel system_duct platform_static32 platform_static64)
|
||||
make_fat(system_kernel)
|
||||
|
||||
add_library(system_kernel_static STATIC
|
||||
$<TARGET_OBJECTS:libsyscall>
|
||||
$<TARGET_OBJECTS:libsyscall_static>
|
||||
#$<TARGET_OBJECTS:libsyscall_static>
|
||||
#$<TARGET_OBJECTS:kqueue>
|
||||
$<TARGET_OBJECTS:emulation_dyld>
|
||||
${extra_objs}
|
||||
$<TARGET_OBJECTS:mach_server_client_dyld>)
|
||||
|
||||
install(TARGETS system_kernel DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
@@ -13,6 +13,7 @@ add_definitions(-DBSDTHREAD_WRAP_LINUX_PTHREAD
|
||||
-DEMULATED_RELEASE="12.0.0"
|
||||
-DEMULATED_VERSION="Darwin Kernel Version 12.0.0")
|
||||
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/dyld)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
@@ -22,8 +23,10 @@ set(emulation_sources
|
||||
syscalls.c
|
||||
simple.c
|
||||
errno.c
|
||||
tls.c
|
||||
readline.c
|
||||
machdep/machdeps.c
|
||||
machdep/machdep-table.S
|
||||
machdep/tls.c
|
||||
unistd/write.c
|
||||
unistd/read.c
|
||||
unistd/pread.c
|
||||
@@ -97,6 +100,7 @@ set(emulation_sources
|
||||
signal/sigprocmask.c
|
||||
signal/sig_restorer.S
|
||||
signal/sigsuspend.c
|
||||
misc/getentropy.c
|
||||
misc/syscall.c
|
||||
misc/shared_region_check_np.c
|
||||
misc/ioctl.c
|
||||
|
||||
@@ -11,6 +11,12 @@ long __unknown_syscall(int nr, ...)
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
long __unknown_syscall_machdep(int nr, ...)
|
||||
{
|
||||
__simple_printf("Unimplemented machdep trap (%d)\n", nr);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int __linux_syscall(int nr, long a1, long a2, long a3, long a4, long a5, long a6)
|
||||
{
|
||||
return linux_syscall(a1, a2, a3, a4, a5, a6, nr);
|
||||
|
||||
69
src/kernel/emulation/linux/machdep/machdep-table.S
Normal file
69
src/kernel/emulation/linux/machdep/machdep-table.S
Normal file
@@ -0,0 +1,69 @@
|
||||
.text
|
||||
.globl __darling_machdep_syscall
|
||||
.private_extern __darling_machdep_syscall
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
__darling_machdep_syscall:
|
||||
movq ___machdep_syscall_table@GOTPCREL(%rip), %r10
|
||||
andq $0xff, %rax
|
||||
movq (%r10,%rax,8), %r10
|
||||
test %r10, %r10
|
||||
jz .no_sys
|
||||
# Re-push possible 7th and 8th arg
|
||||
movq 24(%rsp), %r11
|
||||
pushq %r11
|
||||
movq 24(%rsp), %r11
|
||||
pushq %r11
|
||||
call *%r10
|
||||
addq $16, %rsp
|
||||
ret
|
||||
.no_sys:
|
||||
movq %rax, %rdi
|
||||
call ___unknown_syscall_machdep
|
||||
ret
|
||||
|
||||
#elif defined(__i386__)
|
||||
|
||||
#define copy_arg(off) \
|
||||
movl 8+off(%esp), %ecx ;\
|
||||
movl %ecx, -24+off(%esp)
|
||||
|
||||
__darling_machdep_syscall:
|
||||
calll .L0$pb
|
||||
.L0$pb:
|
||||
popl %ecx
|
||||
.Ltmp0:
|
||||
movl L___machdep_syscall_table$non_lazy_ptr-.L0$pb(%ecx), %ecx
|
||||
andl $0xffff, %eax // Because there is some extra stuff in upper bytes we don't need
|
||||
movl (%ecx,%eax,4), %eax
|
||||
test %eax, %eax
|
||||
jz .no_sys
|
||||
// Copy arguments
|
||||
copy_arg(0)
|
||||
copy_arg(4)
|
||||
copy_arg(8)
|
||||
copy_arg(12)
|
||||
copy_arg(16)
|
||||
copy_arg(20)
|
||||
subl $24, %esp
|
||||
call *%eax
|
||||
addl $24, %esp
|
||||
ret
|
||||
.no_sys:
|
||||
pushl %ecx
|
||||
call ___unknown_syscall_machdep
|
||||
addl $4, %esp
|
||||
ret
|
||||
|
||||
.section __IMPORT,__pointers,non_lazy_symbol_pointers
|
||||
L___machdep_syscall_table$non_lazy_ptr:
|
||||
.indirect_symbol ___machdep_syscall_table
|
||||
.long 0
|
||||
|
||||
.subsections_via_symbols
|
||||
|
||||
#else
|
||||
# error Missing assembly
|
||||
#endif
|
||||
|
||||
7
src/kernel/emulation/linux/machdep/machdeps.c
Normal file
7
src/kernel/emulation/linux/machdep/machdeps.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "machdeps.h"
|
||||
#include "tls.h"
|
||||
|
||||
void* __machdep_syscall_table[10] = {
|
||||
[3] = sys_thread_set_tsd_base,
|
||||
};
|
||||
|
||||
7
src/kernel/emulation/linux/machdep/machdeps.h
Normal file
7
src/kernel/emulation/linux/machdep/machdeps.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _MACHDEPS_H
|
||||
#define _MACHDEPS_H
|
||||
|
||||
extern void* __machdep_syscall_table[10];
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define ARCH_SET_GS 0x1001
|
||||
|
||||
void __pthread_set_self(void* ptr)
|
||||
void sys_thread_set_tsd_base(void* ptr, int unk)
|
||||
{
|
||||
#ifdef __x86_64__
|
||||
LINUX_SYSCALL(__NR_arch_prctl, ARCH_SET_GS, ptr);
|
||||
@@ -2,7 +2,7 @@
|
||||
#define LINUX_TLS_H
|
||||
#include "base.h"
|
||||
|
||||
VISIBLE void __pthread_set_self(void* ptr);
|
||||
void sys_thread_set_tsd_base(void* ptr, int unk);
|
||||
|
||||
#endif
|
||||
|
||||
18
src/kernel/emulation/linux/misc/getentropy.c
Normal file
18
src/kernel/emulation/linux/misc/getentropy.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "getentropy.h"
|
||||
#include "../base.h"
|
||||
#include "../errno.h"
|
||||
#include <linux-syscalls/linux.h>
|
||||
|
||||
#define LINUX_GRND_RANDOM 2
|
||||
|
||||
long sys_getentropy(void* buf, unsigned long size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = LINUX_SYSCALL(__NR_getrandom, buf, size, LINUX_GRND_RANDOM);
|
||||
if (ret < 0)
|
||||
ret = errno_linux_to_bsd(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
7
src/kernel/emulation/linux/misc/getentropy.h
Normal file
7
src/kernel/emulation/linux/misc/getentropy.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef LINUX_GETENTROPY_H
|
||||
#define LINUX_GETENTROPY_H
|
||||
|
||||
long sys_getentropy(void* buf, unsigned long size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -319,3 +319,17 @@ static long sysctl_name_to_oid(const char* name, int* oid_name,
|
||||
__simple_printf("Unknown sysctl: %s\n", name);
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
long sys_sysctlbyname(const char* name, unsigned long namelen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen)
|
||||
{
|
||||
long rv;
|
||||
int oid[4];
|
||||
unsigned long oid_len = 4;
|
||||
|
||||
rv = sysctl_name_to_oid(name, oid, &oid_len);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
return sys_sysctl(oid, oid_len, old, oldlen, _new, newlen);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LINUX_SYSCTL_H
|
||||
|
||||
long sys_sysctl(int* name, unsigned int nlen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen);
|
||||
long sys_sysctlbyname(const char* name, unsigned long namelen, void* old, unsigned long* oldlen, void* _new, unsigned long newlen);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
extern int strcmp(const char *s1, const char *s2);
|
||||
extern char *strcat(char *dest, const char *src);
|
||||
extern char *strcpy(char *dest, const char *src);
|
||||
extern void* memchr(const void* s, int c, __SIZE_TYPE__ n);
|
||||
extern char* strchr(const char* s, int c);
|
||||
extern int strncmp(const char *s1, const char *s2, __SIZE_TYPE__ n);
|
||||
extern __SIZE_TYPE__ strlen(const char *s);
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <stddef.h>
|
||||
#include "unistd/read.h"
|
||||
|
||||
extern void *memchr(const void *s, int c, __SIZE_TYPE__ n);
|
||||
extern void *memmove(void *dest, const void *src, __SIZE_TYPE__ n);
|
||||
extern char* memchr(char* buf, int c, __SIZE_TYPE__ n);
|
||||
|
||||
const char* _readline(int fd, struct rdline_buffer* buf)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <linux-syscalls/linux.h>
|
||||
|
||||
void __simple_vsprintf(char* buf, const char* format, va_list vl);
|
||||
extern char* memchr(char* buf, int c, __SIZE_TYPE__ n);
|
||||
|
||||
int __simple_strlen(const char* text)
|
||||
{
|
||||
@@ -190,7 +191,6 @@ unsigned long long __simple_atoi16(const char* str, const char** endp)
|
||||
|
||||
extern void *memmove(void *dest, const void *src, __SIZE_TYPE__ n);
|
||||
extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
|
||||
extern void *memchr(const void *s, int c, __SIZE_TYPE__ n);
|
||||
extern long sys_read(int fd, void* buf, __SIZE_TYPE__ n);
|
||||
|
||||
#ifndef min
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
#include "process/wait4.h"
|
||||
#include "process/waitid.h"
|
||||
#include "process/execve.h"
|
||||
#include "misc/getentropy.h"
|
||||
#include "misc/getlogin.h"
|
||||
#include "misc/shared_region_check_np.h"
|
||||
#include "ioctl/ioctl.h"
|
||||
@@ -278,6 +279,7 @@ void* __bsd_syscall_table[600] = {
|
||||
[240] = sys_listxattr,
|
||||
[241] = sys_flistxattr,
|
||||
[244] = sys_posix_spawn,
|
||||
[274] = sys_sysctlbyname,
|
||||
[282] = sys_chmod_extended,
|
||||
[283] = sys_fchmod_extended,
|
||||
[294] = sys_shared_region_check_np,
|
||||
@@ -330,5 +332,6 @@ void* __bsd_syscall_table[600] = {
|
||||
[415] = sys_pwrite_nocancel,
|
||||
[417] = sys_poll_nocancel,
|
||||
[423] = sys_semwait_signal_nocancel,
|
||||
[500] = sys_getentropy,
|
||||
};
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ set(syscall_sources
|
||||
wrappers/clonefile.c
|
||||
wrappers/coalition.c
|
||||
wrappers/__commpage_gettimeofday.c
|
||||
wrappers/__commpage_gettimeofday_asm.S
|
||||
wrappers/__get_cpu_capabilities.S
|
||||
wrappers/csr.c
|
||||
wrappers/fs_snapshot.c
|
||||
wrappers/gethostuuid.c
|
||||
@@ -617,9 +619,9 @@ add_library(libsyscall_dynamic OBJECT ${syscall_dynamic_sources})
|
||||
make_fat(libsyscall)
|
||||
make_fat(libsyscall_dynamic)
|
||||
|
||||
add_library(libsyscall_static OBJECT wrappers/_libc_funcptr.c)
|
||||
set_target_properties(libsyscall_static PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD")
|
||||
make_fat(libsyscall_static)
|
||||
#add_library(libsyscall_static OBJECT wrappers/_libc_funcptr.c)
|
||||
#set_target_properties(libsyscall_static PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD")
|
||||
#make_fat(libsyscall_static)
|
||||
|
||||
# For i386
|
||||
#add_library(libsyscall_legacy_extra OBJECT wrappers/legacy/select.c)
|
||||
|
||||
@@ -34,6 +34,7 @@ struct _os_alloc_once_s {
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
// XXX: I had to add an initializer here. Without it, the symbol wasn't being exported
|
||||
__attribute__((visibility("default")))
|
||||
extern struct _os_alloc_once_s _os_alloc_once_table[];
|
||||
struct _os_alloc_once_s _os_alloc_once_table[OS_ALLOC_ONCE_KEY_MAX];
|
||||
struct _os_alloc_once_s _os_alloc_once_table[OS_ALLOC_ONCE_KEY_MAX] = { {0,0} };
|
||||
|
||||
@@ -97,7 +97,7 @@ __libkernel_voucher_init(_libkernel_voucher_functions_t fns)
|
||||
_libkernel_voucher_functions = fns;
|
||||
return KERN_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
boolean_t
|
||||
voucher_mach_msg_set(mach_msg_header_t *msg)
|
||||
{
|
||||
@@ -131,4 +131,4 @@ voucher_mach_msg_revert(voucher_mach_msg_state_t state)
|
||||
return _libkernel_voucher_functions->voucher_mach_msg_revert(state);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -554,4 +554,18 @@ kern_return_t bsdthread_terminate_trap(
|
||||
return ioctl(driver_fd, NR_bsdthread_terminate_trap, &args);
|
||||
}
|
||||
|
||||
typedef struct voucher_mach_msg_state_s *voucher_mach_msg_state_t;
|
||||
|
||||
boolean_t voucher_mach_msg_set(mach_msg_header_t *msg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void voucher_mach_msg_revert(voucher_mach_msg_state_t state)
|
||||
{
|
||||
}
|
||||
|
||||
voucher_mach_msg_state_t voucher_mach_msg_adopt(mach_msg_header_t *msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,19 @@ set(keymgr_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libkeymgr.dylib")
|
||||
add_darling_library(keymgr SHARED ${keymgr_sources})
|
||||
target_link_libraries(keymgr PRIVATE system_c system_dyld system_malloc system_pthread)
|
||||
make_fat(keymgr)
|
||||
add_circular(keymgr FAT
|
||||
SOURCES
|
||||
${keymgr_sources}
|
||||
SIBLINGS
|
||||
system_c
|
||||
system_dyld
|
||||
system_malloc
|
||||
system_pthread
|
||||
platform
|
||||
system_kernel
|
||||
)
|
||||
#target_link_libraries(keymgr PRIVATE system_c system_dyld system_malloc system_pthread)
|
||||
#make_fat(keymgr)
|
||||
|
||||
set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar")
|
||||
set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib")
|
||||
|
||||
@@ -31,9 +31,15 @@ set(launch_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/liblaunch.dylib")
|
||||
add_darling_library(launch SHARED ${launch_sources})
|
||||
target_link_libraries(launch PRIVATE system_c system_kernel)
|
||||
make_fat(launch)
|
||||
add_circular(launch FAT
|
||||
SOURCES
|
||||
${launch_sources}
|
||||
SIBLINGS
|
||||
system_c
|
||||
system_kernel
|
||||
)
|
||||
#target_link_libraries(launch PRIVATE system_c system_kernel)
|
||||
#make_fat(launch)
|
||||
|
||||
install(TARGETS launch DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ add_definitions(
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -fPIC -w ")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${CMAKE_CURRENT_SOURCE_DIR}/weak_reference.h")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") # development flags
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load")
|
||||
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/fbsdcompat")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/darwin")
|
||||
@@ -127,7 +127,7 @@ make_fat(
|
||||
#)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_c.dylib")
|
||||
add_darling_library(system_c SHARED
|
||||
add_circular(system_c FAT OBJECTS
|
||||
$<TARGET_OBJECTS:libc-db>
|
||||
$<TARGET_OBJECTS:libc-compat>
|
||||
$<TARGET_OBJECTS:libc-compat_cancelable>
|
||||
@@ -144,6 +144,7 @@ add_darling_library(system_c SHARED
|
||||
$<TARGET_OBJECTS:libc-util>
|
||||
$<TARGET_OBJECTS:libc-string>
|
||||
$<TARGET_OBJECTS:libc-string-x86_64>
|
||||
$<TARGET_OBJECTS:libc-string-i386>
|
||||
$<TARGET_OBJECTS:libc-stdtime>
|
||||
$<TARGET_OBJECTS:libc-sys>
|
||||
$<TARGET_OBJECTS:libc-sys_noinode64>
|
||||
@@ -173,10 +174,30 @@ add_darling_library(system_c SHARED
|
||||
$<TARGET_OBJECTS:libc-regex_legacy>
|
||||
$<TARGET_OBJECTS:libc-locale_legacy>
|
||||
$<TARGET_OBJECTS:libc-net_legacy>
|
||||
STRONG_SIBLINGS
|
||||
platform
|
||||
SIBLINGS
|
||||
system_kernel
|
||||
compiler_rt
|
||||
system_dyld
|
||||
system_malloc
|
||||
system_pthread
|
||||
system_blocks
|
||||
system_m
|
||||
platform
|
||||
launch
|
||||
system_notify
|
||||
libdispatch_shared
|
||||
system_info
|
||||
macho
|
||||
system_duct
|
||||
system_asl
|
||||
LINK_FLAGS
|
||||
"-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/xcodescripts/alias.list"
|
||||
)
|
||||
target_link_libraries(system_c system_kernel system_m macho system_malloc platform)
|
||||
make_fat(system_c)
|
||||
set_property(TARGET system_c APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/xcodescripts/alias.list")
|
||||
#target_link_libraries(system_c system_kernel system_m macho system_malloc platform system_blocks system_pthread compiler_rt)
|
||||
#make_fat(system_c)
|
||||
#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")
|
||||
|
||||
install(TARGETS system_c DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
@@ -190,7 +211,8 @@ add_library(libc_static STATIC
|
||||
$<TARGET_OBJECTS:libc-locale>
|
||||
$<TARGET_OBJECTS:libc-stdio>
|
||||
$<TARGET_OBJECTS:libc-stdtime>
|
||||
$<TARGET_OBJECTS:libc-gdtoa>
|
||||
$<TARGET_OBJECTS:libc-string>
|
||||
$<TARGET_OBJECTS:libc-gdtoa_dyld>
|
||||
$<TARGET_OBJECTS:libc-secure>
|
||||
$<TARGET_OBJECTS:libc-os>
|
||||
$<TARGET_OBJECTS:libc-stdio_extsn>
|
||||
@@ -198,3 +220,8 @@ add_library(libc_static STATIC
|
||||
add_dependencies(libc_static ranlib x86_64-apple-darwin11-ar)
|
||||
set_target_properties(libc_static PROPERTIES COMPILE_FLAGS "-ffunction-sections")
|
||||
|
||||
add_library(libc_static64 STATIC $<TARGET_OBJECTS:libc-x86_64>)
|
||||
add_dependencies(libc_static64 ranlib x86_64-apple-darwin11-ar)
|
||||
add_library(libc_static32 STATIC $<TARGET_OBJECTS:libc-i386>)
|
||||
add_dependencies(libc_static32 ranlib x86_64-apple-darwin11-ar)
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ set(gdtoa_sources ${gdtoa_sources}
|
||||
#SET_SOURCE_FILES_PROPERTIES(FreeBSD/gdtoa-strtof.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_STRTOF -DLIBC_ALIAS_STRTOF_L")
|
||||
|
||||
add_library(libc-gdtoa OBJECT ${gdtoa_sources})
|
||||
add_library(libc-gdtoa_dyld OBJECT ${gdtoa_sources})
|
||||
set_target_properties(libc-gdtoa_dyld PROPERTIES COMPILE_FLAGS "-DVARIANT_DYLD")
|
||||
make_fat(libc-gdtoa_dyld)
|
||||
|
||||
# Legacy variant
|
||||
set(gdtoa-legacy_sources
|
||||
|
||||
@@ -87,6 +87,7 @@ Balloc
|
||||
#ifdef GDTOA_TSD
|
||||
Bigint **freelist;
|
||||
|
||||
#ifndef VARIANT_DYLD
|
||||
if (gdtoa_tsd_key == (pthread_key_t)-1) {
|
||||
pthread_mutex_lock(&gdtoa_tsd_lock);
|
||||
if (gdtoa_tsd_key == (pthread_key_t)-1) {
|
||||
@@ -95,6 +96,7 @@ Balloc
|
||||
}
|
||||
pthread_mutex_unlock(&gdtoa_tsd_lock);
|
||||
}
|
||||
#endif
|
||||
if ((freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key)) == NULL) {
|
||||
freelist = (Bigint **)MALLOC((Kmax+1) * sizeof(Bigint *));
|
||||
bzero(freelist, (Kmax+1) * sizeof(Bigint *));
|
||||
|
||||
@@ -187,7 +187,7 @@ set(gen-legacy_sources FreeBSD/clock.c FreeBSD/closedir.c FreeBSD/fnmatch.c
|
||||
FreeBSD/seekdir.c FreeBSD/setmode.c FreeBSD/sleep.c FreeBSD/telldir.c
|
||||
FreeBSD/ttyname.c FreeBSD/usleep.c FreeBSD/wait.c FreeBSD/waitpid.c
|
||||
FreeBSD/timezone.c FreeBSD/termios.c FreeBSD/nice.c
|
||||
confstr.c crypt.c nftw.c FreeBSD/opendir.c)
|
||||
confstr.c crypt.c nftw.c FreeBSD/opendir.c nanosleep.c)
|
||||
|
||||
add_library(libc-gen_legacy OBJECT ${gen-legacy_sources})
|
||||
SET_TARGET_PROPERTIES(libc-gen_legacy PROPERTIES COMPILE_FLAGS
|
||||
@@ -222,7 +222,7 @@ SET_TARGET_PROPERTIES(libc-gen_pre1050 PROPERTIES COMPILE_FLAGS "-DBUILDING_VARI
|
||||
|
||||
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
|
||||
FreeBSD/readdir.c FreeBSD/scandir.c FreeBSD/sysctl.c FreeBSD/sysctlbyname.c FreeBSD/telldir.c FreeBSD/usleep.c FreeBSD/sysconf.c
|
||||
FreeBSD/isatty.c FreeBSD/termios.c FreeBSD/getprogname.c errlst.c)
|
||||
FreeBSD/isatty.c FreeBSD/termios.c FreeBSD/getprogname.c FreeBSD/vis.c FreeBSD/err.c FreeBSD/usleep.c errlst.c)
|
||||
|
||||
SET_TARGET_PROPERTIES(libc-gen_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN -U__DARWIN_NON_CANCELABLE")
|
||||
SET_TARGET_PROPERTIES(libc-gen_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_DARWINEXTSN -D__DARWIN_NON_CANCELABLE=1 -D__DARWIN_UNIX03=1")
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_C99_SOURCE -D_FORTIFY_SOURCE=0 -
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa/FreeBSD")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa")
|
||||
|
||||
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/dyld-apple/include)
|
||||
|
||||
set(secure_sources
|
||||
chk_fail.c
|
||||
memcpy_chk.c
|
||||
@@ -24,6 +26,7 @@ set(secure_sources
|
||||
strncpy_chk.c
|
||||
vsnprintf_chk.c
|
||||
vsprintf_chk.c
|
||||
secure.c
|
||||
)
|
||||
|
||||
#SET_SOURCE_FILES_PROPERTIES(FreeBSD/snprintf.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS}")
|
||||
|
||||
@@ -27,4 +27,42 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <TargetConditionals.h>
|
||||
#include <mach-o/dyld_priv.h>
|
||||
#include "secure.h"
|
||||
|
||||
extern void __abort(void) __dead2;
|
||||
|
||||
void
|
||||
__attribute__ ((noreturn))
|
||||
__chk_fail (void)
|
||||
{
|
||||
//const char message[] = "[%d] detected buffer overflow";
|
||||
|
||||
//syslog(LOG_CRIT, message, getpid());
|
||||
|
||||
const char message[] = "detected buffer overflow";
|
||||
write(2, message, sizeof(message)-1);
|
||||
|
||||
__abort();
|
||||
}
|
||||
|
||||
static void __chk_assert_no_overlap_callback(const struct mach_header* mh, intptr_t vmaddr_slide)
|
||||
{
|
||||
if (__chk_assert_no_overlap)
|
||||
{
|
||||
if (dyld_get_sdk_version(mh) < DYLD_MACOSX_VERSION_10_9)
|
||||
__chk_assert_no_overlap = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__chk_init (void)
|
||||
{
|
||||
if (dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_9)
|
||||
{
|
||||
_dyld_register_func_for_add_image(&__chk_assert_no_overlap_callback);
|
||||
__chk_assert_no_overlap = 1;
|
||||
}
|
||||
else
|
||||
__chk_assert_no_overlap = 0;
|
||||
}
|
||||
|
||||
35
src/libc/secure/secure.c
Normal file
35
src/libc/secure/secure.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdint.h>
|
||||
#include "secure.h"
|
||||
#include <syslog.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__attribute__ ((visibility ("hidden")))
|
||||
uint32_t __chk_assert_no_overlap = 1;
|
||||
|
||||
extern void __abort(void) __dead2;
|
||||
extern void __chk_fail (void) __attribute__((__noreturn__));
|
||||
|
||||
void __chk_fail_overflow (void) __attribute__((__noreturn__))
|
||||
{
|
||||
__chk_fail();
|
||||
}
|
||||
|
||||
void __chk_fail_overlap (void) __attribute__((__noreturn__))
|
||||
{
|
||||
//const char message[] = "[%d] detected illegal buffer overlap";
|
||||
|
||||
//syslog(LOG_CRIT, message, getpid());
|
||||
const char message[] = "detected illegal buffer overlap";
|
||||
write(2, message, sizeof(message)-1);
|
||||
|
||||
__abort();
|
||||
}
|
||||
|
||||
void __chk_overlap (const void *a, size_t an, const void *b, size_t bn)
|
||||
{
|
||||
if (((uintptr_t)a) <= ((uintptr_t)b)+bn && ((uintptr_t)b) <= ((uintptr_t)a)+an)
|
||||
__chk_fail_overlap();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${CMAKE_CURRENT_SOURCE_DIR}/../fbsd
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa/FreeBSD")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../gdtoa")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/FreeBSD")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set(stdio_sources
|
||||
xprintf_all_in_one.c
|
||||
@@ -54,8 +55,8 @@ set(stdio_sources
|
||||
FreeBSD/fwrite.c
|
||||
FreeBSD/fwscanf.c
|
||||
FreeBSD/getc.c
|
||||
FreeBSD/getchar.c
|
||||
FreeBSD/getdelim.c
|
||||
FreeBSD/getchar.c
|
||||
FreeBSD/getline.c
|
||||
FreeBSD/gets.c
|
||||
FreeBSD/getw.c
|
||||
@@ -110,6 +111,15 @@ set(stdio_sources
|
||||
FreeBSD/wprintf.c
|
||||
FreeBSD/wscanf.c
|
||||
FreeBSD/wsetup.c
|
||||
FreeBSD/xprintf.c
|
||||
FreeBSD/xprintf_errno.c
|
||||
FreeBSD/xprintf_float.c
|
||||
FreeBSD/xprintf_hexdump.c
|
||||
FreeBSD/xprintf_int.c
|
||||
FreeBSD/xprintf_quote.c
|
||||
FreeBSD/xprintf_str.c
|
||||
FreeBSD/xprintf_time.c
|
||||
FreeBSD/xprintf_vis.c
|
||||
)
|
||||
|
||||
set_source_files_properties(FreeBSD/fopen.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_FOPEN")
|
||||
|
||||
@@ -104,6 +104,6 @@ add_library(libc-stdlib_extsn OBJECT ${stdlib-extsn_sources})
|
||||
SET_TARGET_PROPERTIES(libc-stdlib_extsn PROPERTIES COMPILE_DEFINITIONS "BUILDING_VARIANT;VARIANT_DARWINEXTSN")
|
||||
|
||||
# DYLD variant
|
||||
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)
|
||||
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)
|
||||
SET_TARGET_PROPERTIES(libc-stdlib_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN")
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ set(string_x86_64_sources
|
||||
strlcpy.c
|
||||
)
|
||||
|
||||
# i386 only, vice versa
|
||||
set(string_i386_sources
|
||||
FreeBSD/strnlen.c)
|
||||
|
||||
set(string_sources ${string_sources}
|
||||
FreeBSD/index.c
|
||||
FreeBSD/memmem.c
|
||||
@@ -87,6 +91,9 @@ add_library(libc-string OBJECT ${string_sources})
|
||||
add_library(libc-string-x86_64 OBJECT ${string_x86_64_sources})
|
||||
set_target_properties(libc-string-x86_64 PROPERTIES COMPILE_FLAGS "-arch x86_64")
|
||||
|
||||
add_library(libc-string-i386 OBJECT ${string_i386_sources})
|
||||
set_target_properties(libc-string-i386 PROPERTIES COMPILE_FLAGS "-arch i386")
|
||||
|
||||
# Legacy variant
|
||||
set(string-legacy_sources
|
||||
FreeBSD/strerror.c)
|
||||
|
||||
@@ -48,6 +48,6 @@ set(sys-noinode64_sources statx_np.c)
|
||||
add_library(libc-sys_noinode64 OBJECT ${sys-noinode64_sources})
|
||||
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")
|
||||
|
||||
add_library(libc-sys_dyld OBJECT gettimeofday.c crt_externs.c)
|
||||
add_library(libc-sys_dyld OBJECT gettimeofday.c crt_externs.c sigaction.c)
|
||||
SET_TARGET_PROPERTIES(libc-sys_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN")
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ set(edit_SRCS
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/libedit.3.dylib")
|
||||
add_darling_library(edit SHARED ${edit_SRCS})
|
||||
make_fat(edit)
|
||||
set_target_properties(edit PROPERTIES OUTPUT_NAME "edit.3")
|
||||
target_link_libraries(edit PRIVATE system ncurses)
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ if(COMMAND cmake_policy)
|
||||
endif(COMMAND cmake_policy)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-sub_library,libcompiler_rt")
|
||||
|
||||
set(libgcc_sources
|
||||
dummy.c
|
||||
)
|
||||
|
||||
add_darling_library(gcc_s SHARED ${libgcc_sources})
|
||||
target_link_libraries(gcc_s PRIVATE compiler_rt -sub_library libcompiler_rt)
|
||||
target_link_libraries(gcc_s PRIVATE compiler_rt)
|
||||
set_target_properties(gcc_s PROPERTIES OUTPUT_NAME "gcc_s.1")
|
||||
|
||||
InstallSymlink("libgcc_s.1.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libgcc_s.dylib")
|
||||
|
||||
@@ -42,17 +42,32 @@ make_fat(info-dns
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_info.dylib")
|
||||
add_darling_library(system_info SHARED $<TARGET_OBJECTS:info-util>
|
||||
$<TARGET_OBJECTS:info-dns>
|
||||
$<TARGET_OBJECTS:info-gen>
|
||||
$<TARGET_OBJECTS:info-nis>
|
||||
$<TARGET_OBJECTS:info-rpc>
|
||||
$<TARGET_OBJECTS:info-lookup>
|
||||
$<TARGET_OBJECTS:info-membership>
|
||||
$<TARGET_OBJECTS:darling-resolver>
|
||||
add_circular(system_info FAT
|
||||
OBJECTS
|
||||
$<TARGET_OBJECTS:info-util>
|
||||
$<TARGET_OBJECTS:info-dns>
|
||||
$<TARGET_OBJECTS:info-gen>
|
||||
$<TARGET_OBJECTS:info-nis>
|
||||
$<TARGET_OBJECTS:info-rpc>
|
||||
$<TARGET_OBJECTS:info-lookup>
|
||||
$<TARGET_OBJECTS:info-membership>
|
||||
$<TARGET_OBJECTS:darling-resolver>
|
||||
SIBLINGS
|
||||
system_c
|
||||
system_dyld
|
||||
system_blocks
|
||||
system_kernel
|
||||
system_malloc
|
||||
system_duct
|
||||
system_pthread
|
||||
libdispatch_shared
|
||||
system_notify
|
||||
platform
|
||||
DEPENDENCIES
|
||||
resolv-darwin
|
||||
)
|
||||
target_link_libraries(system_info PRIVATE system_c resolv-darwin system_dyld system_blocks libdispatch_shared system_notify platform)
|
||||
make_fat(system_info)
|
||||
#target_link_libraries(system_info PRIVATE system_c resolv-darwin system_dyld system_blocks libdispatch_shared system_notify platform)
|
||||
#make_fat(system_info)
|
||||
|
||||
install(TARGETS system_info DESTINATION libexec/darling/usr/lib/system)
|
||||
install(FILES master.passwd DESTINATION libexec/darling/etc)
|
||||
|
||||
@@ -6,7 +6,7 @@ enable_language(C ASM)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -ggdb -O0")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -DBUILDING_FOR_CARBONCORE_LEGACY -funroll-loops -msse3") # -DBUILDING_FOR_CARBONCORE_LEGACY")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DBUILDING_FOR_CARBONCORE_LEGACY")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/Intel)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel-include)
|
||||
@@ -155,11 +155,21 @@ set_target_properties(system_m_extra PROPERTIES COMPILE_FLAGS "-UBUILDING_FOR_CA
|
||||
make_fat(system_m_extra)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_m.dylib")
|
||||
add_darling_library(system_m SHARED ${libm_sources} $<TARGET_OBJECTS:system_m_extra>)
|
||||
set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS
|
||||
"-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias")
|
||||
add_circular(system_m FAT
|
||||
SOURCES
|
||||
${libm_sources}
|
||||
OBJECTS
|
||||
$<TARGET_OBJECTS:system_m_extra>
|
||||
SIBLINGS
|
||||
system_c
|
||||
system_dyld
|
||||
LINK_FLAGS
|
||||
"-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias"
|
||||
)
|
||||
#set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS
|
||||
# "-Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libm_Intel.a.alias -Wl,-alias_list,${CMAKE_CURRENT_SOURCE_DIR}/Exports/libmathCommonIntel.alias")
|
||||
#target_link_libraries(system_m)
|
||||
make_fat(system_m)
|
||||
#make_fat(system_m)
|
||||
|
||||
install(TARGETS system_m DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ add_definitions(-D__APPLE__ -D__DYNAMIC__)
|
||||
add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load")
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin)
|
||||
|
||||
@@ -29,8 +29,16 @@ SET(libmacho_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libmacho.dylib")
|
||||
add_darling_library(macho SHARED ${libmacho_sources})
|
||||
target_link_libraries(macho system_kernel)
|
||||
make_fat(macho)
|
||||
add_circular(macho FAT
|
||||
SOURCES
|
||||
${libmacho_sources}
|
||||
SIBLINGS
|
||||
system_kernel
|
||||
system_dyld
|
||||
system_c
|
||||
system_malloc
|
||||
)
|
||||
#target_link_libraries(macho system_kernel)
|
||||
#make_fat(macho)
|
||||
|
||||
install(TARGETS macho DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
@@ -2,13 +2,12 @@ project(darling-libsystem_malloc)
|
||||
|
||||
cmake_minimum_required(VERSION 2.4.0)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -fblocks -ggdb")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -include ${CMAKE_CURRENT_SOURCE_DIR}/../duct/include/commpage.h -nostdinc")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -fblocks -ggdb")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w -nostdinc")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-bind_at_load")
|
||||
|
||||
add_definitions(-DTARGET_OS_MAC=1)
|
||||
add_definitions(-DHAVE_STDINT_H=1)
|
||||
add_definitions(-D__APPLE__ -D__DYNAMIC__ -DPRIVATE)
|
||||
add_definitions(-D__APPLE__ -D__DYNAMIC__ -DPRIVATE -DOS_UNFAIR_LOCK_INLINE=1)
|
||||
add_definitions("'-DMAGMALLOC_MALLOCERRORBREAK()='")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/malloc)
|
||||
@@ -18,6 +17,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/gen)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/darwin)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel/libsyscall/wrappers/)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../kernel/libsyscall)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/external/libpthread/private)
|
||||
|
||||
set(libmalloc_sources
|
||||
src/bitarray.c
|
||||
@@ -35,9 +35,18 @@ set(libmalloc_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_malloc.dylib")
|
||||
add_darling_library(system_malloc SHARED ${libmalloc_sources})
|
||||
target_link_libraries(system_malloc PRIVATE system_kernel)
|
||||
make_fat(system_malloc)
|
||||
add_circular(system_malloc FAT
|
||||
SOURCES
|
||||
${libmalloc_sources}
|
||||
SIBLINGS
|
||||
system_kernel
|
||||
system_c
|
||||
platform
|
||||
system_dyld
|
||||
compiler_rt
|
||||
)
|
||||
#target_link_libraries(system_malloc PRIVATE system_kernel)
|
||||
#make_fat(system_malloc)
|
||||
|
||||
install(TARGETS system_malloc DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
|
||||
@@ -25,9 +25,23 @@ set(notify_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_notify.dylib")
|
||||
add_darling_library(system_notify SHARED ${notify_sources})
|
||||
target_link_libraries(system_notify system_c system_kernel system_blocks libdispatch_shared launch system_dyld system_malloc system_pthread)
|
||||
make_fat(system_notify)
|
||||
add_circular(system_notify FAT
|
||||
SOURCES
|
||||
${notify_sources}
|
||||
SIBLINGS
|
||||
system_c
|
||||
system_kernel
|
||||
system_blocks
|
||||
libdispatch_shared
|
||||
launch
|
||||
system_dyld
|
||||
system_malloc
|
||||
system_pthread
|
||||
platform
|
||||
system_asl
|
||||
)
|
||||
#target_link_libraries(system_notify system_c system_kernel system_blocks libdispatch_shared launch system_dyld system_malloc system_pthread)
|
||||
#make_fat(system_notify)
|
||||
|
||||
install(TARGETS system_notify DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ add_darling_library(system SHARED ${libsystem_sources})
|
||||
target_link_libraries(system PRIVATE system_malloc system_c system_kernel keymgr sandbox
|
||||
system_m system_info system_notify system_quarantine libdispatch_shared launch compiler_rt
|
||||
removefile system_copyfile unwind system_coreservices system_dyld macho CommonCrypto
|
||||
system_pthread platform) # objc
|
||||
system_pthread platform system_asl system_duct system_blocks) # objc
|
||||
set_target_properties(system PROPERTIES OUTPUT_NAME "System.B")
|
||||
set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS
|
||||
" -sub_library libsystem_malloc \
|
||||
@@ -69,6 +69,7 @@ set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS
|
||||
-sub_library libcommonCrypto \
|
||||
-sub_library libsystem_sandbox \
|
||||
-sub_library libsystem_coreservices \
|
||||
-sub_library libsystem_asl \
|
||||
-Wl,-dylib_compatibility_version,1238.0.0")
|
||||
|
||||
make_fat(system)
|
||||
|
||||
@@ -22,7 +22,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_coreservices.dylib")
|
||||
add_darling_library(system_coreservices SHARED dirhelper.c NSSystemDirectories.c)
|
||||
target_link_libraries(system_coreservices PRIVATE system_c system_dyld platform system_pthread)
|
||||
target_link_libraries(system_coreservices PRIVATE system_c system_dyld platform system_pthread system_kernel)
|
||||
make_fat(system_coreservices)
|
||||
|
||||
install(TARGETS system_coreservices DESTINATION libexec/darling/usr/lib/system)
|
||||
|
||||
@@ -35,10 +35,16 @@ set(libunwind_sources
|
||||
)
|
||||
|
||||
set(DYLIB_INSTALL_NAME "/usr/lib/system/libunwind.dylib")
|
||||
add_darling_library(unwind SHARED ${libunwind_sources})
|
||||
target_link_libraries(unwind PRIVATE system_c keymgr)
|
||||
set_target_properties(unwind PROPERTIES LINKER_LANGUAGE C)
|
||||
make_fat(unwind)
|
||||
add_circular(unwind FAT
|
||||
SOURCES
|
||||
${libunwind_sources}
|
||||
SIBLINGS
|
||||
system_c
|
||||
keymgr
|
||||
)
|
||||
#target_link_libraries(unwind PRIVATE system_c keymgr)
|
||||
#set_target_properties(unwind PROPERTIES LINKER_LANGUAGE C)
|
||||
#make_fat(unwind)
|
||||
|
||||
add_library(unwind_static STATIC ${libunwind_sources})
|
||||
set_target_properties(unwind_static PROPERTIES COMPILE_FLAGS "-DNDEBUG=1")
|
||||
|
||||
Reference in New Issue
Block a user