From eeada54edb21b0ca513011606c15f809db4fcdf4 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Wed, 25 Jan 2017 16:11:01 +0100 Subject: [PATCH] More progress on libc upgrade+fat build, now at the point of linking libSystem --- cmake/use_ld64.cmake | 2 + compiler-include/stdatomic.h | 2 +- platform-include/i386/atomic.h | 66 +++ platform-include/i386/smp.h | 35 ++ platform-include/machine/atomic.h | 51 +++ platform-include/sys/spawn_internal.h | 419 ++++++++++++++++++ src/CMakeLists.txt | 1 + src/CommonCrypto/CMakeLists.txt | 7 +- src/copyfile/CMakeLists.txt | 9 +- src/duct/include/commpage.h | 71 --- src/duct/src/CMakeLists.txt | 2 +- src/duct/src/commpage.c | 9 +- src/dyld-apple/CMakeLists.txt | 2 + src/external/compiler-rt | 2 +- src/external/libdispatch | 2 +- src/external/libkqueue | 2 +- src/external/libplatform | 2 +- src/external/libpthread | 2 +- src/kernel/libsyscall/CMakeLists.txt | 3 + src/kernel/libsyscall/bsdsyscalls/___getpid.S | 5 + src/kernel/libsyscall/os/tsd.h | 45 +- src/keymgr/CMakeLists.txt | 4 +- src/launchd/liblaunch/CMakeLists.txt | 1 + src/libc/CMakeLists.txt | 6 +- src/libc/derived/i386/libc-features.h | 2 +- src/libc/derived/x86_64/libc-features.h | 2 +- src/libc/string/CMakeLists.txt | 13 +- src/libinfo/CMakeLists.txt | 17 +- src/libnotify/CMakeLists.txt | 5 +- src/libremovefile/CMakeLists.txt | 8 +- src/libresolv/CMakeLists.txt | 10 +- src/libsystem/CMakeLists.txt | 8 +- src/libsystem_coreservices/CMakeLists.txt | 6 +- src/libunwind/CMakeLists.txt | 8 +- src/libunwind/System | 1 - src/libunwind/System/pthread_machdep.h | 1 + src/quarantine/CMakeLists.txt | 2 + src/sandbox/CMakeLists.txt | 4 + 38 files changed, 726 insertions(+), 111 deletions(-) create mode 100644 platform-include/i386/atomic.h create mode 100644 platform-include/i386/smp.h create mode 100644 platform-include/machine/atomic.h create mode 100644 platform-include/sys/spawn_internal.h delete mode 120000 src/libunwind/System create mode 120000 src/libunwind/System/pthread_machdep.h diff --git a/cmake/use_ld64.cmake b/cmake/use_ld64.cmake index 1400c049c..a4ad37b1c 100644 --- a/cmake/use_ld64.cmake +++ b/cmake/use_ld64.cmake @@ -23,6 +23,8 @@ FUNCTION(use_ld64 target) -Wl,-dylib_file,/usr/lib/system/libmacho.dylib:${CMAKE_BINARY_DIR}/src/libmacho/libmacho.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/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 ") diff --git a/compiler-include/stdatomic.h b/compiler-include/stdatomic.h index e03798766..d1537027a 100644 --- a/compiler-include/stdatomic.h +++ b/compiler-include/stdatomic.h @@ -27,7 +27,7 @@ /* If we're hosted, fall back to the system's stdatomic.h. FreeBSD, for * example, already has a Clang-compatible stdatomic.h header. */ -#if __STDC_HOSTED__ && __has_include_next() +#if __STDC_HOSTED__ && __has_include_next() && 0 # include_next #else diff --git a/platform-include/i386/atomic.h b/platform-include/i386/atomic.h new file mode 100644 index 000000000..22ca1fd50 --- /dev/null +++ b/platform-include/i386/atomic.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#ifndef _I386_ATOMIC_H_ +#define _I386_ATOMIC_H_ + +#include + +#if __SMP__ + +#define memory_order_consume_smp memory_order_consume +#define memory_order_acquire_smp memory_order_acquire +#define memory_order_release_smp memory_order_release +#define memory_order_acq_rel_smp memory_order_acq_rel +#define memory_order_seq_cst_smp memory_order_seq_cst + +#else + +#define memory_order_consume_smp memory_order_relaxed +#define memory_order_acquire_smp memory_order_relaxed +#define memory_order_release_smp memory_order_relaxed +#define memory_order_acq_rel_smp memory_order_relaxed +#define memory_order_seq_cst_smp memory_order_relaxed + +#endif + +#ifdef ATOMIC_PRIVATE + +static boolean_t +atomic_compare_exchange(uintptr_t *target, uintptr_t oldval, uintptr_t newval, + enum memory_order ord, boolean_t wait) +{ + (void)wait; + return __c11_atomic_compare_exchange_strong((_Atomic uintptr_t *)target, &oldval, newval, ord, memory_order_relaxed); +} + +#endif // ATOMIC_PRIVATE + + +#endif // _I386_ATOMIC_H_ + diff --git a/platform-include/i386/smp.h b/platform-include/i386/smp.h new file mode 100644 index 000000000..e98af290e --- /dev/null +++ b/platform-include/i386/smp.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#ifndef _I386_SMP_H_ +#define _I386_SMP_H_ + +/* x86_64 kernels are always built SMP, even if only 1 CPU is active */ +#define __SMP__ 1 + +#endif /* _I386_SMP_H_ */ diff --git a/platform-include/machine/atomic.h b/platform-include/machine/atomic.h new file mode 100644 index 000000000..d594ad9d7 --- /dev/null +++ b/platform-include/machine/atomic.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#ifndef _MACHINE_ATOMIC_H +#define _MACHINE_ATOMIC_H +#include + +#if 0 +/* This should be in stdatomic.h once supported by compiler */ +enum memory_order { + memory_order_relaxed, + memory_order_consume, + memory_order_acquire, + memory_order_release, + memory_order_acq_rel, + memory_order_seq_cst +}; +#endif + +#if defined (__x86_64__) || defined (__i386__) +#include "i386/atomic.h" +#else +#error architecture not supported +#endif + +#endif /* _MACHINE_ATOMIC_H */ diff --git a/platform-include/sys/spawn_internal.h b/platform-include/sys/spawn_internal.h new file mode 100644 index 000000000..9985b3cfc --- /dev/null +++ b/platform-include/sys/spawn_internal.h @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + + +/* + * [SPN] Support for _POSIX_SPAWN + * + * This file contains internal data structures which are externally represented + * as opaque void pointers to prevent introspection. This permits us to + * change the underlying implementation of the code to maintain it or to + * support new features, as needed, without the consumer needing to recompile + * their code because of structure size changes or data reorganization. + */ + +#ifndef _SYS_SPAWN_INTERNAL_H_ +#define _SYS_SPAWN_INTERNAL_H_ + +#include /* __offsetof(), __darwin_size_t */ +#include +#include /* PATH_MAX */ +#include +#include +#include +#include +#include /* COALITION_NUM_TYPES */ + +/* + * Allowable posix_spawn() port action types + */ +typedef enum { + PSPA_SPECIAL = 0, + PSPA_EXCEPTION = 1, + PSPA_AU_SESSION = 2, + PSPA_IMP_WATCHPORTS = 3, +} pspa_t; + +/* + * Internal representation of one port to be set on posix_spawn(). + * Currently this is limited to setting special and exception ports, + * but could be extended to other inheritable port types. + */ +typedef struct _ps_port_action { + pspa_t port_type; + exception_mask_t mask; + mach_port_name_t new_port; + exception_behavior_t behavior; + thread_state_flavor_t flavor; + int which; +} _ps_port_action_t; + +/* + * A collection of port actions to take on the newly spawned process. + */ +typedef struct _posix_spawn_port_actions { + int pspa_alloc; + int pspa_count; + _ps_port_action_t pspa_actions[]; +} *_posix_spawn_port_actions_t; + +/* + * Returns size in bytes of a _posix_spawn_port_actions holding x elements. + */ +#define PS_PORT_ACTIONS_SIZE(x) \ + __offsetof(struct _posix_spawn_port_actions, pspa_actions[(x)]) + +#define NBINPREFS 4 + +/* + * Mapping of opaque data pointer to a MAC policy (specified by name). + */ +typedef struct _ps_mac_policy_extension { + char policyname[128]; + union { + uint64_t data; + void *datap; /* pointer in kernel memory */ + }; + uint64_t datalen; +} _ps_mac_policy_extension_t; + +/* + * A collection of extra data passed to MAC policies for the newly spawned process. + */ +typedef struct _posix_spawn_mac_policy_extensions { + int psmx_alloc; + int psmx_count; + _ps_mac_policy_extension_t psmx_extensions[]; +} *_posix_spawn_mac_policy_extensions_t; + +/* + * Returns size in bytes of a _posix_spawn_mac_policy_extensions holding x elements. + */ +#define PS_MAC_EXTENSIONS_SIZE(x) \ + __offsetof(struct _posix_spawn_mac_policy_extensions, psmx_extensions[(x)]) + +#define PS_MAC_EXTENSIONS_INIT_COUNT 2 + +/* + * Coalition posix spawn attributes + */ +struct _posix_spawn_coalition_info { + struct { + uint64_t psci_id; + uint32_t psci_role; + uint32_t psci_reserved1; + uint64_t psci_reserved2; + } psci_info[COALITION_NUM_TYPES]; +}; + +/* + * Persona attributes + */ +struct _posix_spawn_persona_info { + uid_t pspi_id; /* persona ID (unix UID) */ + uint32_t pspi_flags; /* spawn persona flags */ + uid_t pspi_uid; /* alternate posix/unix UID */ + gid_t pspi_gid; /* alternate posix/unix GID */ + uint32_t pspi_ngroups; /* alternate advisory groups */ + gid_t pspi_groups[NGROUPS]; + uid_t pspi_gmuid; /* group membership UID */ +}; + +#define POSIX_SPAWN_PERSONA_FLAGS_NONE 0x0 +#define POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE 0x1 +#define POSIX_SPAWN_PERSONA_FLAGS_VERIFY 0x2 + +#define POSIX_SPAWN_PERSONA_ALL_FLAGS \ + (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE \ + | POSIX_SPAWN_PERSONA_FLAGS_VERIFY \ + ) + +#define POSIX_SPAWN_PERSONA_UID 0x00010000 +#define POSIX_SPAWN_PERSONA_GID 0x00020000 +#define POSIX_SPAWN_PERSONA_GROUPS 0x00040000 + + +/* + * A posix_spawnattr structure contains all of the attribute elements that + * can be set, as well as any metadata whose validity is signalled by the + * presence of a bit in the flags field. All fields are initialized to the + * appropriate default values by posix_spawnattr_init(). + */ + +typedef struct _posix_spawnattr { + short psa_flags; /* spawn attribute flags */ + short flags_padding; /* get the flags to be int aligned */ + sigset_t psa_sigdefault; /* signal set to default */ + sigset_t psa_sigmask; /* signal set to mask */ + pid_t psa_pgroup; /* pgroup to spawn into */ + cpu_type_t psa_binprefs[NBINPREFS]; /* cpu affinity prefs*/ + int psa_pcontrol; /* process control bits on resource starvation */ + int psa_apptype; /* app type and process spec behav */ + uint64_t psa_cpumonitor_percent; /* CPU usage monitor percentage */ + uint64_t psa_cpumonitor_interval; /* CPU usage monitor interval, in seconds */ + uint64_t psa_reserved; + + short psa_jetsam_flags; /* jetsam flags */ + short short_padding; /* Padding for alignment issues */ + int psa_priority; /* jetsam relative importance */ + int psa_memlimit_active; /* jetsam memory limit (in MB) when process is active */ + int psa_memlimit_inactive; /* jetsam memory limit (in MB) when process is inactive */ + + uint64_t psa_qos_clamp; /* QoS Clamp to set on the new process */ + uint64_t psa_darwin_role; /* PRIO_DARWIN_ROLE to set on the new process */ + + /* + * NOTE: Extensions array pointers must stay at the end so that + * everything above this point stays the same size on different bitnesses + * see + */ + _posix_spawn_port_actions_t psa_ports; /* special/exception ports */ + _posix_spawn_mac_policy_extensions_t psa_mac_extensions; /* MAC policy-specific extensions. */ + struct _posix_spawn_coalition_info *psa_coalition_info; /* coalition info */ + struct _posix_spawn_persona_info *psa_persona_info; /* spawn new process into given persona */ +} *_posix_spawnattr_t; + +/* + * Jetsam flags eg: psa_jetsam_flags + */ +#define POSIX_SPAWN_JETSAM_SET 0x8000 + +#define POSIX_SPAWN_JETSAM_USE_EFFECTIVE_PRIORITY 0x01 +#define POSIX_SPAWN_JETSAM_HIWATER_BACKGROUND 0x02 /* to be deprecated */ +#define POSIX_SPAWN_JETSAM_MEMLIMIT_FATAL 0x04 /* to be deprecated */ + +/* + * Additional flags available for use with + * the posix_spawnattr_setjetsam_ext() call + */ +#define POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL 0x04 /* if set, limit is fatal when the process is active */ +#define POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL 0x08 /* if set, limit is fatal when the process is inactive */ + +/* + * Deprecated posix_spawn psa_flags values + * + * POSIX_SPAWN_OSX_TALAPP_START 0x0400 + * POSIX_SPAWN_IOS_RESV1_APP_START 0x0400 + * POSIX_SPAWN_IOS_APPLE_DAEMON_START 0x0800 + * POSIX_SPAWN_IOS_APP_START 0x1000 + * POSIX_SPAWN_OSX_WIDGET_START 0x0800 + * POSIX_SPAWN_OSX_DBCLIENT_START 0x0800 + * POSIX_SPAWN_OSX_RESVAPP_START 0x1000 + */ + +/* + * Deprecated posix_spawn psa_apptype values + * + * POSIX_SPAWN_PROCESS_TYPE_APPLEDAEMON 0x00000001 + * POSIX_SPAWN_PROCESS_TYPE_UIAPP 0x00000002 + * POSIX_SPAWN_PROCESS_TYPE_ADAPTIVE 0x00000004 + * POSIX_SPAWN_PROCESS_TYPE_TAL 0x00000001 + * POSIX_SPAWN_PROCESS_TYPE_WIDGET 0x00000002 + * POSIX_SPAWN_PROCESS_TYPE_DELAYIDLESLEEP 0x10000000 + * + * POSIX_SPAWN_PROCESS_FLAG_IMPORTANCE_DONOR 0x00000010 + * POSIX_SPAWN_PROCESS_FLAG_ADAPTIVE 0x00000020 + * POSIX_SPAWN_PROCESS_FLAG_START_BACKGROUND 0x00000040 + * POSIX_SPAWN_PROCESS_FLAG_START_LIGHT_THROTTLE 0x00000080 + */ + +/* + * posix_spawn psa_apptype process type settings. + * when POSIX_SPAWN_PROC_TYPE is set, old psa_apptype bits are ignored + */ + +#define POSIX_SPAWN_PROCESS_TYPE_NORMAL 0x00000000 +#define POSIX_SPAWN_PROCESS_TYPE_DEFAULT POSIX_SPAWN_PROCESS_TYPE_NORMAL + +#define POSIX_SPAWN_PROC_TYPE_MASK 0x00000F00 + +#define POSIX_SPAWN_PROC_TYPE_APP_DEFAULT 0x00000100 +#define POSIX_SPAWN_PROC_TYPE_APP_TAL 0x00000200 + +#define POSIX_SPAWN_PROC_TYPE_DAEMON_STANDARD 0x00000300 +#define POSIX_SPAWN_PROC_TYPE_DAEMON_INTERACTIVE 0x00000400 +#define POSIX_SPAWN_PROC_TYPE_DAEMON_BACKGROUND 0x00000500 +#define POSIX_SPAWN_PROC_TYPE_DAEMON_ADAPTIVE 0x00000600 + +#define POSIX_SPAWN_PROC_CLAMP_NONE 0x00000000 +#define POSIX_SPAWN_PROC_CLAMP_UTILITY 0x00000001 +#define POSIX_SPAWN_PROC_CLAMP_BACKGROUND 0x00000002 +#define POSIX_SPAWN_PROC_CLAMP_MAINTENANCE 0x00000003 +#define POSIX_SPAWN_PROC_CLAMP_LAST 0x00000004 + +/* Setting to indicate no change to darwin role */ +#define POSIX_SPAWN_DARWIN_ROLE_NONE 0x00000000 +/* Other possible values are specified by PRIO_DARWIN_ROLE in sys/resource.h */ + +/* + * Allowable posix_spawn() file actions + */ +typedef enum { + PSFA_OPEN = 0, + PSFA_CLOSE = 1, + PSFA_DUP2 = 2, + PSFA_INHERIT = 3 +} psfa_t; + + +/* + * A posix_spawn() file action record for a single action + * + * Notes: We carry around the full open arguments for both the open + * and the close to permit the use of a single array of action + * elements to be associated with a file actions object. + * + * A possible future optimization would be to break this into + * a variable sized vector list to save space (i.e. a separate + * string area, allocation of least amount of path buffer per + * open action, etc.). + * + * XXX: Currently overloading psfao_oflag for PSFA_DUP2 + */ +typedef struct _psfa_action { + psfa_t psfaa_type; /* file action type */ + int psfaa_filedes; /* fd to operate on */ + struct _psfaa_open { + int psfao_oflag; /* open flags to use */ + mode_t psfao_mode; /* mode for open */ + char psfao_path[PATH_MAX]; /* path to open */ + } psfaa_openargs; +} _psfa_action_t; + + +/* + * Internal representation of posix_spawn() file actions structure + * + * Notes: This is implemented as a structure followed by an array of + * file action records. The psfa_act_alloc value is the number + * of elements allocated in this array, and the psfa_act_count is + * the number of elements currently in use (to permit some form + * of preallocation, e.g. a power of 2 growth for reallocation, + * etc.). + * + * A possible future optimization would keep a size value and + * a structure base reference pointer to permit copyin to the + * kernel directly as a single blob, without damaging relative + * internal pointer math. It's probably better that this be a + * long long rather than a true pointer, to make it invariant + * for 32 vs. 64 bt programming SPIs. + */ +typedef struct _posix_spawn_file_actions { + int psfa_act_alloc; /* available actions space */ + int psfa_act_count; /* count of defined actions */ + _psfa_action_t psfa_act_acts[]; /* actions array (uses c99) */ +} *_posix_spawn_file_actions_t; + +/* + * Calculate the size of a structure, given the number of elements that it is + * capable of containing. + */ +#define PSF_ACTIONS_SIZE(x) \ + __offsetof(struct _posix_spawn_file_actions, psfa_act_acts[(x)]) + +/* + * Initial count of actions in a struct _posix_spawn_file_actions after it is + * first allocated; this should be non-zero, since we expect that one would not + * have been allocated unless there was an intent to use it. + */ +#define PSF_ACTIONS_INIT_COUNT 2 + +/* + * Structure defining the true third argument to the posix_spawn() system call + * entry point; we wrap it and pass a descriptor so that we can know the + * copyin size ahead of time, and deal with copying in variant lists of things + * as single monolithic units, instead of many individual elements. This is a + * performance optimization. + */ +struct _posix_spawn_args_desc { + __darwin_size_t attr_size; /* size of attributes block */ + _posix_spawnattr_t attrp; /* pointer to block */ + __darwin_size_t file_actions_size; /* size of file actions block */ + _posix_spawn_file_actions_t + file_actions; /* pointer to block */ + __darwin_size_t port_actions_size; /* size of port actions block */ + _posix_spawn_port_actions_t + port_actions; /* pointer to port block */ + __darwin_size_t mac_extensions_size; + _posix_spawn_mac_policy_extensions_t + mac_extensions; /* pointer to policy-specific + * attributes */ + __darwin_size_t coal_info_size; + struct _posix_spawn_coalition_info *coal_info; /* pointer to coalition info */ + + __darwin_size_t persona_info_size; + struct _posix_spawn_persona_info *persona_info; +}; + +#ifdef KERNEL +#include +#ifdef __APPLE_API_PRIVATE + +#if __DARWIN_ALIGN_NATURAL +#pragma options align=natural +#endif + +struct user32__posix_spawn_args_desc { + uint32_t attr_size; /* size of attributes block */ + uint32_t attrp; /* pointer to block */ + uint32_t file_actions_size; /* size of file actions block */ + uint32_t file_actions; /* pointer to block */ + uint32_t port_actions_size; /* size of port actions block */ + uint32_t port_actions; /* pointer to block */ + uint32_t mac_extensions_size; + uint32_t mac_extensions; + uint32_t coal_info_size; + uint32_t coal_info; + uint32_t persona_info_size; + uint32_t persona_info; +}; + +struct user__posix_spawn_args_desc { + user_size_t attr_size; /* size of attributes block */ + user_addr_t attrp; /* pointer to block */ + user_size_t file_actions_size; /* size of file actions block */ + user_addr_t file_actions; /* pointer to block */ + user_size_t port_actions_size; /* size of port actions block */ + user_addr_t port_actions; /* pointer to block */ + user_size_t mac_extensions_size; /* size of MAC-specific attrs. */ + user_addr_t mac_extensions; /* pointer to block */ + user_size_t coal_info_size; + user_addr_t coal_info; + user_size_t persona_info_size; + user_addr_t persona_info; +}; + + +#if __DARWIN_ALIGN_NATURAL +#pragma options align=reset +#endif + +#endif /* __APPLE_API_PRIVATE */ +#endif /* KERNEL */ + +#endif /* _SYS_SPAWN_INTERNAL_H_ */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a49872233..c8a1351c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/duct/include") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/external/libplatform/include") add_subdirectory(external/libplatform) +add_subdirectory(external/libpthread) add_subdirectory(kernel) add_subdirectory(libc) diff --git a/src/CommonCrypto/CMakeLists.txt b/src/CommonCrypto/CMakeLists.txt index 9b1c539bd..97a69674a 100644 --- a/src/CommonCrypto/CMakeLists.txt +++ b/src/CommonCrypto/CMakeLists.txt @@ -22,7 +22,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/CommonCrypto) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/ccUtilities) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/CommonCryptoSPI) -include_directories(${DARLING_TOP_DIRECTORY}/src/external/libdispatch) +include_directories(${CMAKE_SOURCE_DIR}/src/external/libdispatch) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/stdtime/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) set(cc_SRCS Source/Digest/md2_dgst.c diff --git a/src/copyfile/CMakeLists.txt b/src/copyfile/CMakeLists.txt index 414bdef3d..5591f548b 100644 --- a/src/copyfile/CMakeLists.txt +++ b/src/copyfile/CMakeLists.txt @@ -5,9 +5,11 @@ cmake_minimum_required(VERSION 2.4.0) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -fblocks") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") -include_directories(${DARLING_TOP_DIRECTORY}/platform-include) -include_directories(${DARLING_TOP_DIRECTORY}/src/libinfo/membership.subproj/) -include_directories(${DARLING_TOP_DIRECTORY}/src/external/libdispatch) +include_directories(${CMAKE_SOURCE_DIR}/platform-include) +include_directories(${CMAKE_SOURCE_DIR}/src/libinfo/membership.subproj/) +include_directories(${CMAKE_SOURCE_DIR}/src/external/libdispatch) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(-DTARGET_OS_MAC=1) @@ -29,5 +31,6 @@ set(DYLIB_INSTALL_NAME "/usr/lib/system/libcopyfile.dylib") add_darling_library(system_copyfile SHARED ${copyfile_sources}) set_target_properties(system_copyfile PROPERTIES OUTPUT_NAME "copyfile") target_link_libraries(system_copyfile PRIVATE system_kernel system_c system_blocks system_info system_dyld system_malloc) +make_fat(system_copyfile) install(TARGETS system_copyfile DESTINATION libexec/darling/usr/lib/system) diff --git a/src/duct/include/commpage.h b/src/duct/include/commpage.h index 4de8dc71f..e69de29bb 100644 --- a/src/duct/include/commpage.h +++ b/src/duct/include/commpage.h @@ -1,71 +0,0 @@ -#ifndef COMMPAGE_H -#define COMMPAGE_H - -#ifndef __ASSEMBLER__ -#include - -extern uint8_t __commpage[]; -#endif - -//#ifndef __ASSEMBLER__ -//#define _COMM_PAGE_BASE_ADDRESS (__commpage) -//#else -//#define _COMM_PAGE_BASE_ADDRESS ___commpage@GOTPCREL(%rip) -//#endif -#define _COMM_PAGE_AREA_LENGTH ( 1 * 4096 ) /* reserved length of entire comm area */ - -#ifdef __x86_64__ -#define _COMM_PAGE_BASE_ADDRESS ( 0x7fffffe00000 ) /* base address of allocated memory */ -#else -#define _COMM_PAGE_BASE_ADDRESS ( 0xaaaa0000 ) /* base address of allocated memory */ -#endif - -#define _COMM_PAGE_START_ADDRESS ( _COMM_PAGE_BASE_ADDRESS ) /* address traditional commpage code starts on */ -#define _COMM_PAGE_AREA_USED ( 1 * 4096 ) /* this is the amt actually allocated */ -#define _COMM_PAGE_SIGS_OFFSET 0x8000 /* offset to routine signatures */ - - -#define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first few bytes are a signature */ -#define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */ -#define _COMM_PAGE_THIS_VERSION 12 /* version of the commarea format */ - -#define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities */ -#define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs (hw.logicalcpu at boot time) */ -#define _COMM_PAGE_UNUSED0 (_COMM_PAGE_START_ADDRESS+0x024) /* 2 unused bytes, reserved for future expansion of cpu_capabilities */ -#define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */ - -#define _COMM_PAGE_SCHED_GEN (_COMM_PAGE_START_ADDRESS+0x028) /* uint32_t scheduler generation number (count of pre-emptions) */ -#define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x02c) /* uint32_t copy of vm_memory_pressure */ -#define _COMM_PAGE_SPIN_COUNT (_COMM_PAGE_START_ADDRESS+0x030) /* uint32_t max spin count for mutex's */ - -#define _COMM_PAGE_ACTIVE_CPUS (_COMM_PAGE_START_ADDRESS+0x034) /* uint8_t number of active CPUs (hw.activecpu) */ -#define _COMM_PAGE_PHYSICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x035) /* uint8_t number of physical CPUs (hw.physicalcpu_max) */ -#define _COMM_PAGE_LOGICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x036) /* uint8_t number of logical CPUs (hw.logicalcpu_max) */ -#define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x037) /* 1 unused bytes */ -#define _COMM_PAGE_MEMORY_SIZE (_COMM_PAGE_START_ADDRESS+0x038) /* uint64_t max memory size */ - -#define _COMM_PAGE_CPUFAMILY (_COMM_PAGE_START_ADDRESS+0x040) /* uint32_t hw.cpufamily, x86*/ -#define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x044) /* [0x44,0x50) unused */ - -#define _COMM_PAGE_TIME_DATA_START (_COMM_PAGE_START_ADDRESS+0x050) /* base of offsets below (_NT_SCALE etc) */ -#define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */ -#define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */ -#define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */ -#define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */ -#define _COMM_PAGE_NT_GENERATION (_COMM_PAGE_START_ADDRESS+0x068) /* used by nanotime() */ -#define _COMM_PAGE_GTOD_GENERATION (_COMM_PAGE_START_ADDRESS+0x06c) /* used by gettimeofday() */ -#define _COMM_PAGE_GTOD_NS_BASE (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */ -#define _COMM_PAGE_GTOD_SEC_BASE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */ - -#define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x080) -#define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x088) - -#define _COMM_TEXT_PFZ_ENQUEUE_OFFSET (_COMM_PAGE_START_ADDRESS+0xc00) -#define _COMM_TEXT_PFZ_DEQUEUE_OFFSET (_COMM_PAGE_START_ADDRESS+0xc80) -#define _COMM_TEXT_PFZ_MUTEX_LOCK_OFFSET (_COMM_PAGE_START_ADDRESS+0xd00) - -#define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0xfff) /* end of common page */ - -#define _COMM_PAGE_TEXT_START (_COMM_PAGE_START_ADDRESS+0x1000) - -#endif diff --git a/src/duct/src/CMakeLists.txt b/src/duct/src/CMakeLists.txt index b4e1b0b3f..2d4515ccf 100644 --- a/src/duct/src/CMakeLists.txt +++ b/src/duct/src/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.4.0) add_definitions(-DTARGET_OS_MAC=1) add_definitions(-DHAVE_STDINT_H=1) -add_definitions(-D__APPLE__ -D__DYNAMIC__) +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") diff --git a/src/duct/src/commpage.c b/src/duct/src/commpage.c index 1cd8aedd7..86ae3b8e4 100644 --- a/src/duct/src/commpage.c +++ b/src/duct/src/commpage.c @@ -1,11 +1,12 @@ -#include +#include #include +#include //uint8_t __commpage[_COMM_PAGE_AREA_LENGTH]; void _darling_initialize_commpage(void) { - mmap(_COMM_PAGE_BASE_ADDRESS, _COMM_PAGE_AREA_LENGTH, PROT_READ|PROT_WRITE, + mmap(_COMM_PAGE_START_ADDRESS, _COMM_PAGE_AREA_LENGTH, PROT_READ|PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); *((uint8_t*)_COMM_PAGE_NCPUS) = 1; @@ -13,9 +14,9 @@ void _darling_initialize_commpage(void) *((uint64_t*) _COMM_PAGE_MEMORY_SIZE) = 1024LL*1024LL*1024LL; } -int _get_cpu_capabilities(void) +/*int _get_cpu_capabilities(void) { const uint16_t* p = (uint16_t*) _COMM_PAGE_CPU_CAPABILITIES; return *p; -} +}*/ diff --git a/src/dyld-apple/CMakeLists.txt b/src/dyld-apple/CMakeLists.txt index 421f161b6..b0e75ba80 100644 --- a/src/dyld-apple/CMakeLists.txt +++ b/src/dyld-apple/CMakeLists.txt @@ -75,5 +75,7 @@ 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_static system_duct_static) +make_fat(system_dyld) + install(TARGETS system_dyld DESTINATION libexec/darling/usr/lib/system) install(TARGETS system_loader DESTINATION libexec/darling/usr/lib) diff --git a/src/external/compiler-rt b/src/external/compiler-rt index 52df90364..d790b0e8f 160000 --- a/src/external/compiler-rt +++ b/src/external/compiler-rt @@ -1 +1 @@ -Subproject commit 52df9036437799ba0483363888681e7777cfe606 +Subproject commit d790b0e8f6f016a396396df22e7bad68e930eb8a diff --git a/src/external/libdispatch b/src/external/libdispatch index 8e4debde5..e5b75ab5d 160000 --- a/src/external/libdispatch +++ b/src/external/libdispatch @@ -1 +1 @@ -Subproject commit 8e4debde5a09f097d944eb585b06a769cbd92ace +Subproject commit e5b75ab5d241c61d0056d2426d598e5054e173db diff --git a/src/external/libkqueue b/src/external/libkqueue index 645e2b36c..7dbf79587 160000 --- a/src/external/libkqueue +++ b/src/external/libkqueue @@ -1 +1 @@ -Subproject commit 645e2b36c05083438725948e2edc658c20d32721 +Subproject commit 7dbf79587a5726b42c2902c0b515a005f58b58e1 diff --git a/src/external/libplatform b/src/external/libplatform index bfa1fbeeb..9d42f6943 160000 --- a/src/external/libplatform +++ b/src/external/libplatform @@ -1 +1 @@ -Subproject commit bfa1fbeeb829177f2f80b345031e83ba0d6ae7df +Subproject commit 9d42f6943076b2def435aa9eb371a6f44698ec2b diff --git a/src/external/libpthread b/src/external/libpthread index 8922dd3c4..6e8bea3ab 160000 --- a/src/external/libpthread +++ b/src/external/libpthread @@ -1 +1 @@ -Subproject commit 8922dd3c4fa8d4ae43957f005641e1661a781934 +Subproject commit 6e8bea3abac71cb21eb76ca60ce20b35d3767791 diff --git a/src/kernel/libsyscall/CMakeLists.txt b/src/kernel/libsyscall/CMakeLists.txt index cf33a981f..391bb1c0b 100644 --- a/src/kernel/libsyscall/CMakeLists.txt +++ b/src/kernel/libsyscall/CMakeLists.txt @@ -14,6 +14,7 @@ include_directories("${CMAKE_SOURCE_DIR}/src/dyld") # for elfcalls.h include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libc/include") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../duct/include") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/wrappers/libproc") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/wrappers/spawn") include_directories("${CMAKE_CURRENT_BINARY_DIR}") add_definitions(-DPRIVATE=1 -D__DARWIN_C_LEVEL=20150101) add_definitions('-D__XNU_PRIVATE_EXTERN=') @@ -132,6 +133,8 @@ set(syscall_sources wrappers/unix03/mmap.c wrappers/unix03/munmap.c wrappers/unix03/setrlimit.c + + wrappers/spawn/posix_spawn.c ${syscall_legacy_sources} diff --git a/src/kernel/libsyscall/bsdsyscalls/___getpid.S b/src/kernel/libsyscall/bsdsyscalls/___getpid.S index 78de0824c..57574be36 100644 --- a/src/kernel/libsyscall/bsdsyscalls/___getpid.S +++ b/src/kernel/libsyscall/bsdsyscalls/___getpid.S @@ -102,3 +102,8 @@ LEAF(___getpid, 0) #else #error Unsupported architecture #endif + +#if defined(__x86_64__) || defined(__i386__) + .globl _getpid + _getpid = ___getpid +#endif diff --git a/src/kernel/libsyscall/os/tsd.h b/src/kernel/libsyscall/os/tsd.h index 57f853b3e..3e3955867 100644 --- a/src/kernel/libsyscall/os/tsd.h +++ b/src/kernel/libsyscall/os/tsd.h @@ -1,4 +1,3 @@ -// Modified by Lubos Dolezel for Darling; gs->fs /* * Copyright (c) 2012 Apple Inc. All rights reserved. * @@ -50,6 +49,17 @@ _os_cpu_number(void) return 0; } +#if defined(__i386__) || defined(__x86_64__) + +#if defined(__has_attribute) +#if __has_attribute(address_space) +#define OS_GS_RELATIVE __attribute__((address_space(256))) +#endif +#endif + +#ifdef OS_GS_RELATIVE +#define _os_tsd_get_base() ((void * OS_GS_RELATIVE *)0) +#else __attribute__((always_inline)) static __inline__ void* _os_tsd_get_direct(unsigned long slot) @@ -57,27 +67,48 @@ _os_tsd_get_direct(unsigned long slot) void *ret; #if defined(__i386__) __asm__("mov %%fs:%1, %0" : "=r" (ret) : "m" (*(void **)(slot * sizeof(void *)))); -#elif defined(__x86_64__) +#else __asm__("mov %%gs:%1, %0" : "=r" (ret) : "m" (*(void **)(slot * sizeof(void *)))); #endif - - return ret; } __attribute__((always_inline)) static __inline__ int -_os_tsd_set_direct(unsigned long slot, void* val) +_os_tsd_set_direct(unsigned long slot, void *val) { #if defined(__i386__) && defined(__PIC__) __asm__("movl %1, %%fs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "rn" (val)); #elif defined(__i386__) && !defined(__PIC__) - __asm__("movl %1, %%fs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "ri" (val)); -#elif defined(__x86_64__) + __asm__("movl %1, %%gs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "ri" (val)); +#else __asm__("movq %1, %%gs:%0" : "=m" (*(void **)(slot * sizeof(void *))) : "rn" (val)); +#endif + return 0; +} +#endif + +#else +#error _os_tsd_get_base not implemented on this architecture #endif +#ifdef _os_tsd_get_base +__attribute__((always_inline)) +static __inline__ void* +_os_tsd_get_direct(unsigned long slot) +{ + return _os_tsd_get_base()[slot]; +} + +__attribute__((always_inline)) +static __inline__ int +_os_tsd_set_direct(unsigned long slot, void *val) +{ + _os_tsd_get_base()[slot] = val; return 0; } +#endif + +extern void _thread_set_tsd_base(void *tsd_base); #endif diff --git a/src/keymgr/CMakeLists.txt b/src/keymgr/CMakeLists.txt index f93b50c5c..a375aa7f8 100644 --- a/src/keymgr/CMakeLists.txt +++ b/src/keymgr/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") include_directories(${CMAKE_SOURCE_DIR}/libc/fbsdcompat) include_directories(${CMAKE_SOURCE_DIR}/kernel/libsyscall/wrappers) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) add_definitions(-DTARGET_OS_MAC=1) add_definitions(-DHAVE_STDINT_H=1) @@ -18,7 +19,8 @@ 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) +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") diff --git a/src/launchd/liblaunch/CMakeLists.txt b/src/launchd/liblaunch/CMakeLists.txt index e84201ac1..df94b9ff6 100644 --- a/src/launchd/liblaunch/CMakeLists.txt +++ b/src/launchd/liblaunch/CMakeLists.txt @@ -33,6 +33,7 @@ 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) install(TARGETS launch DESTINATION libexec/darling/usr/lib/system) diff --git a/src/libc/CMakeLists.txt b/src/libc/CMakeLists.txt index 3d22780f4..d2fc455a5 100644 --- a/src/libc/CMakeLists.txt +++ b/src/libc/CMakeLists.txt @@ -143,6 +143,7 @@ add_darling_library(system_c SHARED $ $ $ + $ $ $ $ @@ -173,8 +174,9 @@ add_darling_library(system_c SHARED $ $ ) -target_link_libraries(system_c system_kernel system_m macho system_malloc) +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") install(TARGETS system_c DESTINATION libexec/darling/usr/lib/system) @@ -185,8 +187,6 @@ add_library(libc_static STATIC $ $ $ - $ - $ $ $ $ diff --git a/src/libc/derived/i386/libc-features.h b/src/libc/derived/i386/libc-features.h index 16da94569..c8ba61541 100644 --- a/src/libc/derived/i386/libc-features.h +++ b/src/libc/derived/i386/libc-features.h @@ -20,7 +20,7 @@ # error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1 #endif /* __DARWIN_ONLY_64_BIT_INO_T */ #define __APPLE_PR3417676_HACK__ 1 -#define PLOCKSTAT 1 +/* #define PLOCKSTAT 0 */ #define NOTIFY_TZ 1 /* #undef LIBC_NO_LIBCRASHREPORTERCLIENT */ /* #undef FEATURE_SMALL_STDIOBUF */ diff --git a/src/libc/derived/x86_64/libc-features.h b/src/libc/derived/x86_64/libc-features.h index 5a4135c53..e509b534e 100644 --- a/src/libc/derived/x86_64/libc-features.h +++ b/src/libc/derived/x86_64/libc-features.h @@ -20,7 +20,7 @@ # error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1 #endif /* __DARWIN_ONLY_64_BIT_INO_T */ #define __APPLE_PR3417676_HACK__ 1 -#define PLOCKSTAT 1 +/* #define PLOCKSTAT 0 */ #define NOTIFY_TZ 1 /* #undef LIBC_NO_LIBCRASHREPORTERCLIENT */ /* #undef FEATURE_SMALL_STDIOBUF */ diff --git a/src/libc/string/CMakeLists.txt b/src/libc/string/CMakeLists.txt index f64c42922..fbce27ebf 100644 --- a/src/libc/string/CMakeLists.txt +++ b/src/libc/string/CMakeLists.txt @@ -13,12 +13,16 @@ set(string_sources stpncpy.c strcat.c #strcpy.c - #strlcat.c - #strlcpy.c strncat.c #strncpy.c ) +# x86_64 only, i386 has its own assembly impl +set(string_x86_64_sources + strlcat.c + strlcpy.c +) + set(string_sources ${string_sources} FreeBSD/index.c FreeBSD/memmem.c @@ -80,6 +84,8 @@ set(string_sources ${string_sources} SET_SOURCE_FILES_PROPERTIES(FreeBSD/strerror.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_STRERROR") 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") # Legacy variant set(string-legacy_sources @@ -89,6 +95,7 @@ SET_TARGET_PROPERTIES(libc-string_legacy PROPERTIES COMPILE_DEFINITIONS "BUILDIN # DYLD variant add_library(libc-string_dyld OBJECT strcat.c strcpy.c FreeBSD/strdup.c strlcat.c strlcpy.c FreeBSD/strnlen.c FreeBSD/strrchr.c FreeBSD/strstr.c FreeBSD/strtok.c - FreeBSD/wcscpy.c FreeBSD/wcslen.c FreeBSD/wcsncmp.c FreeBSD/wcsncpy.c FreeBSD/strerror.c) + FreeBSD/wcscpy.c FreeBSD/wcslen.c FreeBSD/wcsncmp.c FreeBSD/wcsncpy.c FreeBSD/strerror.c + strlcat.c strlcpy.c strncat.c strncpy.c) SET_TARGET_PROPERTIES(libc-string_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libinfo/CMakeLists.txt b/src/libinfo/CMakeLists.txt index 2287de723..ade113417 100644 --- a/src/libinfo/CMakeLists.txt +++ b/src/libinfo/CMakeLists.txt @@ -18,6 +18,11 @@ add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w -ggdb") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) +include_directories(${CMAKE_SOURCE_DIR}/src/libmalloc/include) +include_directories(${CMAKE_SOURCE_DIR}/src/external/syslog/libsystem_asl.tproj/include) + add_subdirectory(gen.subproj) add_subdirectory(util.subproj) add_subdirectory(dns.subproj) @@ -27,6 +32,15 @@ add_subdirectory(lookup.subproj) add_subdirectory(membership.subproj) add_subdirectory(darling-resolver) +make_fat(info-dns + info-gen + info-nis + info-rpc + info-lookup + info-membership + darling-resolver +) + set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_info.dylib") add_darling_library(system_info SHARED $ $ @@ -37,7 +51,8 @@ add_darling_library(system_info SHARED $ $ $ ) -target_link_libraries(system_info PRIVATE system_c resolv-darwin system_dyld system_blocks libdispatch_shared system_notify) +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) diff --git a/src/libnotify/CMakeLists.txt b/src/libnotify/CMakeLists.txt index c218a6cfd..f65feae9b 100644 --- a/src/libnotify/CMakeLists.txt +++ b/src/libnotify/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories(${DARLING_TOP_DIRECTORY}/src/launchd/liblaunch) include_directories(${DARLING_TOP_DIRECTORY}/src/libc/gen) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks -nostdinc -include ${DARLING_TOP_DIRECTORY}/kernel-include/sys/fileport.h") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") @@ -24,7 +26,8 @@ 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) +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) diff --git a/src/libremovefile/CMakeLists.txt b/src/libremovefile/CMakeLists.txt index e2e70c2a2..8c6ada515 100644 --- a/src/libremovefile/CMakeLists.txt +++ b/src/libremovefile/CMakeLists.txt @@ -5,6 +5,11 @@ cmake_minimum_required(VERSION 2.4.0) include_directories(${DARLING_TOP_DIRECTORY}/platform-include) include_directories(${DARLING_TOP_DIRECTORY}/src/libc/gen) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/stdtime/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks -nostdinc") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") @@ -19,7 +24,8 @@ set(removefile_sources set(DYLIB_INSTALL_NAME "/usr/lib/system/libremovefile.dylib") add_darling_library(removefile SHARED ${removefile_sources}) -target_link_libraries(removefile system_c system_kernel system_dyld system_malloc) +target_link_libraries(removefile system_c system_kernel system_dyld system_malloc compiler_rt) +make_fat(removefile) install(TARGETS removefile DESTINATION libexec/darling/usr/lib/system) diff --git a/src/libresolv/CMakeLists.txt b/src/libresolv/CMakeLists.txt index dfff6f9ed..ef08f495d 100644 --- a/src/libresolv/CMakeLists.txt +++ b/src/libresolv/CMakeLists.txt @@ -4,8 +4,13 @@ cmake_minimum_required(VERSION 2.4.0) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../external/libdispatch/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../external/libdispatch/private) -include_directories(${DARLING_TOP_DIRECTORY}/platform-include) -include_directories(${DARLING_TOP_DIRECTORY}/src/libinfo/lookup.subproj/) +include_directories(${CMAKE_SOURCE_DIR}/platform-include) +include_directories(${CMAKE_SOURCE_DIR}/src/libinfo/lookup.subproj/) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/stdtime/FreeBSD) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dnsinfo) @@ -57,6 +62,7 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(DYLIB_INSTALL_NAME "/usr/lib/libresolv.9.dylib") add_darling_library(resolv-darwin SHARED ${resolv_sources}) set_target_properties(resolv-darwin PROPERTIES OUTPUT_NAME "resolv.9") +make_fat(resolv-darwin) #target_link_libraries(resolv-darwin PRIVATE system) install(TARGETS resolv-darwin DESTINATION libexec/darling/usr/lib) diff --git a/src/libsystem/CMakeLists.txt b/src/libsystem/CMakeLists.txt index e7a9c53fa..d303bb3dc 100644 --- a/src/libsystem/CMakeLists.txt +++ b/src/libsystem/CMakeLists.txt @@ -11,6 +11,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -ggdb") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load") include_directories(${DARLING_TOP_DIRECTORY}/src/libc/fbsdcompat) +include_directories(${DARLING_TOP_DIRECTORY}/src/libc/darwin) include_directories(${DARLING_TOP_DIRECTORY}/src/kernel/libsyscall/wrappers) add_definitions(-DTARGET_OS_MAC=1) @@ -38,7 +39,8 @@ set(DYLIB_INSTALL_NAME "/usr/lib/libSystem.B.dylib") 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) # objc + removefile system_copyfile unwind system_coreservices system_dyld macho CommonCrypto + system_pthread platform) # objc set_target_properties(system PROPERTIES OUTPUT_NAME "System.B") set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS " -sub_library libsystem_malloc \ @@ -51,6 +53,8 @@ set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS -sub_library libquarantine \ -sub_library libsystem_blocks \ -sub_library libsystem_duct \ + -sub_library libsystem_pthread \ + -sub_library libsystem_platform \ -sub_library libdispatch \ -sub_library liblaunch \ -sub_library libremovefile \ @@ -64,6 +68,8 @@ set_property(TARGET system APPEND_STRING PROPERTY LINK_FLAGS -sub_library libsystem_coreservices \ -Wl,-dylib_compatibility_version,1238.0.0") +make_fat(system) + install(TARGETS system DESTINATION libexec/darling/usr/lib) InstallSymlink("libSystem.B.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libSystem.dylib") diff --git a/src/libsystem_coreservices/CMakeLists.txt b/src/libsystem_coreservices/CMakeLists.txt index bf098a28a..a1eb6f636 100644 --- a/src/libsystem_coreservices/CMakeLists.txt +++ b/src/libsystem_coreservices/CMakeLists.txt @@ -17,8 +17,12 @@ 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") +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) +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) +target_link_libraries(system_coreservices PRIVATE system_c system_dyld platform system_pthread) +make_fat(system_coreservices) install(TARGETS system_coreservices DESTINATION libexec/darling/usr/lib/system) diff --git a/src/libunwind/CMakeLists.txt b/src/libunwind/CMakeLists.txt index fba8a561d..3e6471cd7 100644 --- a/src/libunwind/CMakeLists.txt +++ b/src/libunwind/CMakeLists.txt @@ -19,7 +19,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/locale) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/locale/FreeBSD) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/stdtime/FreeBSD) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libc/pthreads) -include_directories(${DARLING_TOP_DIRECTORY}/platform-include) +include_directories(${CMAKE_SOURCE_DIR}/platform-include) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) +include_directories(${CMAKE_SOURCE_DIR}/src/external/libpthread/private) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall) set(libunwind_sources src/libuwind.cxx @@ -34,8 +38,10 @@ 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_library(unwind_static STATIC ${libunwind_sources}) set_target_properties(unwind_static PROPERTIES COMPILE_FLAGS "-DNDEBUG=1") +make_fat(unwind_static) install(TARGETS unwind DESTINATION libexec/darling/usr/lib/system) diff --git a/src/libunwind/System b/src/libunwind/System deleted file mode 120000 index 99c64080a..000000000 --- a/src/libunwind/System +++ /dev/null @@ -1 +0,0 @@ -../libc/pthreads/ \ No newline at end of file diff --git a/src/libunwind/System/pthread_machdep.h b/src/libunwind/System/pthread_machdep.h new file mode 120000 index 000000000..91e489385 --- /dev/null +++ b/src/libunwind/System/pthread_machdep.h @@ -0,0 +1 @@ +../../external/libpthread/private/private.h \ No newline at end of file diff --git a/src/quarantine/CMakeLists.txt b/src/quarantine/CMakeLists.txt index f76f25edc..3d3b79419 100644 --- a/src/quarantine/CMakeLists.txt +++ b/src/quarantine/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.4.0) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w -ggdb") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) set(DYLIB_INSTALL_NAME "/usr/lib/system/libquarantine.dylib") add_darling_library(system_quarantine SHARED @@ -11,6 +12,7 @@ add_darling_library(system_quarantine SHARED ) set_target_properties(system_quarantine PROPERTIES OUTPUT_NAME "quarantine") target_link_libraries(system_quarantine PRIVATE system_c system_dyld system_malloc) +make_fat(system_quarantine) install(TARGETS system_quarantine DESTINATION libexec/darling/usr/lib/system) diff --git a/src/sandbox/CMakeLists.txt b/src/sandbox/CMakeLists.txt index a6cd5456a..411afb608 100644 --- a/src/sandbox/CMakeLists.txt +++ b/src/sandbox/CMakeLists.txt @@ -11,6 +11,9 @@ add_definitions(-DTARGET_OS_MAC=1) add_definitions(-D__APPLE__ -D__DYNAMIC__) add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080) +include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) +include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") @@ -22,5 +25,6 @@ set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_sandbox.dylib") add_darling_library(sandbox SHARED sandbox.c) target_link_libraries(sandbox PRIVATE system_c system_kernel system_dyld system_malloc) set_target_properties(sandbox PROPERTIES OUTPUT_NAME "system_sandbox") +make_fat(sandbox) install(TARGETS sandbox DESTINATION libexec/darling/usr/lib/system) -- 2.51.2