]> git.saurik.com Git - apple/libplatform.git/commitdiff
libplatform-220.tar.gz macos-1015 macos-10151 macos-10152 macos-10153 macos-10154 macos-10155 macos-10156 v220 v220.100.1
authorApple <opensource@apple.com>
Fri, 31 Jan 2020 02:16:10 +0000 (02:16 +0000)
committerApple <opensource@apple.com>
Fri, 31 Jan 2020 02:16:10 +0000 (02:16 +0000)
15 files changed:
include/libkern/OSAtomicDeprecated.h
include/os/base.h
include/os/lock.h
private/os/internal/atomic.h
private/os/lock_private.h
src/cachecontrol/arm64/cache.s
src/init.c
src/os/lock.c
src/simple/asl.c
src/simple/string_io.c
src/string/generic/bzero.c
xcodeconfig/atomics.xcconfig
xcodeconfig/libplatform.aliases
xcodeconfig/libplatform.xcconfig
xcodeconfig/os.xcconfig

index aebf48248a72ab01bc78cd56df2731f3fac5c14c..1b0ef91c124bf689e8edbf42d2ea2e869787c66f 100644 (file)
@@ -801,9 +801,9 @@ typedef int64_t OSAtomic_int64_aligned64_t;
 #endif
 
 #if __has_attribute(always_inline)
-#define OSATOMIC_INLINE static __inline
-#else
 #define OSATOMIC_INLINE static __inline __attribute__((__always_inline__))
+#else
+#define OSATOMIC_INLINE static __inline
 #endif
 
 OSATOMIC_INLINE
index 9fa30e42a4f3d0c606ee7fd9973987ce58a9d99c..b187dce78583dd65bbe1703b205ffc9203bbcda2 100644 (file)
 #define OS_OVERLOADABLE
 #endif
 
-#if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
+#if __has_attribute(enum_extensibility)
+#define __OS_ENUM_ATTR __attribute__((enum_extensibility(open)))
+#define __OS_ENUM_ATTR_CLOSED __attribute__((enum_extensibility(closed)))
+#else
+#define __OS_ENUM_ATTR
+#define __OS_ENUM_ATTR_CLOSED
+#endif // __has_attribute(enum_extensibility)
+
+#if __has_attribute(flag_enum)
+/*!
+ * Compile with -Wflag-enum and -Wassign-enum to enforce at definition and
+ * assignment, respectively, i.e. -Wflag-enum prevents you from creating new
+ * enumeration values from illegal values within the enum definition, and
+ * -Wassign-enum prevents you from assigning illegal values to a variable of the
+ * enum type.
+ */
+#define __OS_OPTIONS_ATTR __attribute__((flag_enum))
+#else
+#define __OS_OPTIONS_ATTR
+#endif // __has_attribute(flag_enum)
+
+#if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
+               __has_extension(cxx_strong_enums)
 #define OS_ENUM(_name, _type, ...) \
                typedef enum : _type { __VA_ARGS__ } _name##_t
+#define OS_CLOSED_ENUM(_name, _type, ...) \
+               typedef enum : _type { __VA_ARGS__ } \
+                       __OS_ENUM_ATTR_CLOSED _name##_t
+#define OS_OPTIONS(_name, _type, ...) \
+               typedef enum : _type { __VA_ARGS__ } \
+                       __OS_ENUM_ATTR __OS_OPTIONS_ATTR _name##_t
+#define OS_CLOSED_OPTIONS(_name, _type, ...) \
+               typedef enum : _type { __VA_ARGS__ } \
+                       __OS_ENUM_ATTR_CLOSED __OS_OPTIONS_ATTR _name##_t
 #else
+/*!
+ * There is unfortunately no good way in plain C to have both fixed-type enums
+ * and enforcement for clang's enum_extensibility extensions. The primary goal
+ * of these macros is to allow you to define an enum and specify its width in a
+ * single statement, and for plain C that is accomplished by defining an
+ * anonymous enum and then separately typedef'ing the requested type name to the
+ * requested underlying integer type. So the type emitted actually has no
+ * relationship at all to the enum, and therefore while the compiler could
+ * enforce enum extensibility if you used the enum type, it cannot do so if you
+ * use the "_t" type resulting from this expression.
+ *
+ * But we still define a named enum type and decorate it appropriately for you,
+ * so if you really want the enum extensibility enforcement, you can use the
+ * enum type yourself, i.e. when compiling with a C compiler:
+ *
+ *     OS_CLOSED_ENUM(my_type, uint64_t,
+ *         FOO,
+ *         BAR,
+ *         BAZ,
+ *     );
+ *
+ *     my_type_t mt = 98; // legal
+ *     enum my_type emt = 98; // illegal
+ *
+ * But be aware that the underlying enum type's width is subject only to the C
+ * language's guarantees -- namely that it will be compatible with int, char,
+ * and unsigned char. It is not safe to rely on the size of this type.
+ *
+ * When compiling in ObjC or C++, both of the above assignments are illegal.
+ */
+#define __OS_ENUM_C_FALLBACK(_name, _type, ...) \
+               typedef _type _name##_t; enum _name { __VA_ARGS__ }
+
 #define OS_ENUM(_name, _type, ...) \
-               enum { __VA_ARGS__ }; typedef _type _name##_t
-#endif
+               typedef _type _name##_t; enum { __VA_ARGS__ }
+#define OS_CLOSED_ENUM(_name, _type, ...) \
+               __OS_ENUM_C_FALLBACK(_name, _type, ## __VA_ARGS__) \
+               __OS_ENUM_ATTR_CLOSED
+#define OS_OPTIONS(_name, _type, ...) \
+               __OS_ENUM_C_FALLBACK(_name, _type, ## __VA_ARGS__) \
+               __OS_ENUM_ATTR __OS_OPTIONS_ATTR
+#define OS_CLOSED_OPTIONS(_name, _type, ...) \
+               __OS_ENUM_C_FALLBACK(_name, _type, ## __VA_ARGS__) \
+               __OS_ENUM_ATTR_CLOSED __OS_OPTIONS_ATTR
+#endif // __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
 
 #if __has_feature(attribute_availability_swift)
 // equivalent to __SWIFT_UNAVAILABLE from Availability.h
index d3e760bd3bd0079af6f7f5c03596c7805b5c4481..5c46f28e94697e440ed5c85626b61241624593fe 100644 (file)
@@ -39,8 +39,7 @@ OS_ASSUME_NONNULL_BEGIN
 __BEGIN_DECLS
 
 #define OS_UNFAIR_LOCK_AVAILABILITY \
-               __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) \
-               __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
+               __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
 
 /*!
  * @typedef os_unfair_lock
@@ -55,7 +54,7 @@ __BEGIN_DECLS
  * defined, they contain thread ownership information that the system may use
  * to attempt to resolve priority inversions.
  *
- * This lock must be unlocked from the same thread that locked it, attemps to
+ * This lock must be unlocked from the same thread that locked it, attempts to
  * unlock from a different thread will cause an assertion aborting the process.
  *
  * This lock must not be accessed from multiple processes or threads via shared
index 1d717a66c7284f0ca6dd1d89ec628589069e1fe9..f4fc18a2aa86822dee9fe8eb804805ce30928b32 100644 (file)
@@ -230,22 +230,6 @@ typedef enum _os_atomic_memory_order {
 #define os_atomic_rmw_loop_give_up(expr) \
                os_atomic_rmw_loop_give_up_with_fence(relaxed, expr)
 
-#define os_atomic_tsx_xacq_cmpxchgv(p, e, v, g) \
-               os_atomic_cmpxchgv((p), (e), (v), (g), acquire)
-#define os_atomic_tsx_xrel_store(p, v) \
-               os_atomic_store(p, v, release)
-#define os_atomic_tsx_xacq_cmpxchgv2o(p, f, e, v, g) \
-               os_atomic_tsx_xacq_cmpxchgv(&(p)->f, (e), (v), (g))
-#define os_atomic_tsx_xrel_store2o(p, f, v) \
-               os_atomic_tsx_xrel_store(&(p)->f, (v))
-
-#if defined(__x86_64__) || defined(__i386__)
-#pragma mark -
-#pragma mark x86
-
-
-#endif
-
 
 #endif // __OS_EXPOSE_INTERNALS_INDIRECT__
 
index 755440a9ace35f7e085196813edf6aac6964245a..92abefef13fdc4a4256871cd5fbf2f308f921bec 100644 (file)
@@ -60,7 +60,7 @@ OS_ASSUME_NONNULL_BEGIN
                        OS_LOCK_TYPE_STRUCT(type) * osl_type OS_UNUSED; \
                        uintptr_t _osl_##type##_opaque[size-1] OS_UNUSED; \
                        public: \
-            constexpr OS_LOCK(type)() : \
+                       constexpr OS_LOCK(type)() : \
                                osl_type(&OS_LOCK_TYPE_REF(type)), _osl_##type##_opaque() {} \
                } OS_LOCK(type)
 #define OS_LOCK_INIT(type) {}
@@ -90,8 +90,6 @@ typedef OS_TRANSPARENT_UNION union {
        OS_LOCK_T_MEMBER(nospin);
        OS_LOCK_T_MEMBER(spin);
        OS_LOCK_T_MEMBER(handoff);
-       OS_LOCK_T_MEMBER(eliding);
-       OS_LOCK_T_MEMBER(transactional);
 } os_lock_t;
 
 #endif
@@ -190,58 +188,6 @@ OS_LOCK_DECL(handoff, 2);
 #define OS_LOCK_HANDOFF_INIT OS_LOCK_INIT(handoff)
 
 
-#if !TARGET_OS_IPHONE
-/*!
- * @typedef os_lock_eliding_s
- *
- * @abstract
- * os_lock variant that uses hardware lock elision support if available to allow
- * multiple processors to concurrently execute a critical section as long as
- * they don't perform conflicting operations on each other's data. In case of
- * conflict, the lock reverts to exclusive operation and os_lock_spin_s behavior
- * on contention (at potential extra cost for the aborted attempt at lock-elided
- * concurrent execution). If hardware HLE support is not present, this lock
- * variant behaves like os_lock_spin_s.
- *
- * @discussion
- * IMPORTANT: Use of this lock variant MUST be extensively tested on hardware
- * with HLE support to ensure the data access pattern and length of the critical
- * section allows lock-elided execution to succeed frequently enough to offset
- * the cost of any aborted concurrent execution.
- *
- * Must be initialized with OS_LOCK_ELIDING_INIT
- */
-__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_NA)
-OS_EXPORT OS_LOCK_TYPE_DECL(eliding);
-OS_LOCK_DECL(eliding, 8) OS_ALIGNED(64);
-#define OS_LOCK_ELIDING_INIT OS_LOCK_INIT(eliding)
-
-/*!
- * @typedef os_lock_transactional_s
- *
- * @abstract
- * os_lock variant that uses hardware restricted transactional memory support if
- * available to allow multiple processors to concurrently execute the critical
- * section as a transactional region. If transactional execution aborts, the
- * lock reverts to exclusive operation and os_lock_spin_s behavior on contention
- * (at potential extra cost for the aborted attempt at transactional concurrent
- * execution). If hardware RTM support is not present, this lock variant behaves
- * like os_lock_eliding_s.
- *
- * @discussion
- * IMPORTANT: Use of this lock variant MUST be extensively tested on hardware
- * with RTM support to ensure the data access pattern and length of the critical
- * section allows transactional execution to succeed frequently enough to offset
- * the cost of any aborted transactions.
- *
- * Must be initialized with OS_LOCK_TRANSACTIONAL_INIT
- */
-__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_NA)
-OS_EXPORT OS_LOCK_TYPE_DECL(transactional);
-OS_LOCK_DECL(transactional, 8) OS_ALIGNED(64);
-#define OS_LOCK_TRANSACTIONAL_INIT OS_LOCK_INIT(transactional)
-#endif
-
 __BEGIN_DECLS
 
 /*!
@@ -295,7 +241,7 @@ void os_lock_unlock(os_lock_t lock);
  * contains thread ownership information that the system may use to attempt to
  * resolve priority inversions.
  *
- * This lock must be unlocked from the same thread that locked it, attemps to
+ * This lock must be unlocked from the same thread that locked it, attempts to
  * unlock from a different thread will cause an assertion aborting the process.
  *
  * This lock must not be accessed from multiple processes or threads via shared
@@ -325,14 +271,32 @@ void os_lock_unlock(os_lock_t lock);
  * When this flag is used, the code running under the critical section should
  * be well known and under your control  (Generally it should not call into
  * framework code).
+ *
+ * @const OS_UNFAIR_LOCK_ADAPTIVE_SPIN
+ * This flag allows for the kernel to use adaptive spinning when the holder
+ * of the lock is currently on core. This should only be used for locks
+ * where the protected critical section is always extremely short.
  */
-OS_ENUM(os_unfair_lock_options, uint32_t,
-       OS_UNFAIR_LOCK_NONE
+OS_OPTIONS(os_unfair_lock_options, uint32_t,
+       OS_UNFAIR_LOCK_NONE OS_SWIFT_NAME(None)
                OS_UNFAIR_LOCK_AVAILABILITY = 0x00000000,
-       OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION
+       OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION OS_SWIFT_NAME(DataSynchronization)
                OS_UNFAIR_LOCK_AVAILABILITY = 0x00010000,
+       OS_UNFAIR_LOCK_ADAPTIVE_SPIN OS_SWIFT_NAME(AdaptiveSpin)
+               __API_AVAILABLE(macos(10.15), ios(13.0),
+               tvos(13.0), watchos(6.0), bridgeos(4.0)) = 0x00040000,
 );
 
+#if __swift__
+#define OS_UNFAIR_LOCK_OPTIONS_COMPAT_FOR_SWIFT(name) \
+               static const os_unfair_lock_options_t \
+               name##_FOR_SWIFT OS_SWIFT_NAME(name) = name
+OS_UNFAIR_LOCK_OPTIONS_COMPAT_FOR_SWIFT(OS_UNFAIR_LOCK_NONE);
+OS_UNFAIR_LOCK_OPTIONS_COMPAT_FOR_SWIFT(OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION);
+OS_UNFAIR_LOCK_OPTIONS_COMPAT_FOR_SWIFT(OS_UNFAIR_LOCK_ADAPTIVE_SPIN);
+#undef OS_UNFAIR_LOCK_OPTIONS_COMPAT_FOR_SWIFT
+#endif
+
 /*!
  * @function os_unfair_lock_lock_with_options
  *
@@ -495,6 +459,53 @@ os_unfair_recursive_lock_assert_not_owner(os_unfair_recursive_lock_t lock)
        os_unfair_lock_assert_not_owner(&lock->ourl_lock);
 }
 
+/*!
+ * @function os_unfair_recursive_lock_owned
+ *
+ * @abstract
+ * This function is reserved for the use of people who want to soft-fault
+ * when locking models have been violated.
+ *
+ * @discussion
+ * This is meant for SQLite use to detect existing misuse of the API surface,
+ * and is not meant for anything else than calling os_log_fault() when such
+ * contracts are violated.
+ *
+ * There's little point to use this value for logic as the
+ * os_unfair_recursive_lock is already recursive anyway.
+ */
+__OSX_AVAILABLE(10.15) __IOS_AVAILABLE(13.0)
+__TVOS_AVAILABLE(13.0) __WATCHOS_AVAILABLE(6.0)
+OS_EXPORT OS_NOTHROW OS_NONNULL_ALL
+bool
+os_unfair_recursive_lock_owned(os_unfair_recursive_lock_t lock);
+
+/*!
+ * @function os_unfair_recursive_lock_unlock_forked_child
+ *
+ * @abstract
+ * Function to be used in an atfork child handler to unlock a recursive unfair
+ * lock.
+ *
+ * @discussion
+ * This function helps with handling recursive locks in the presence of fork.
+ *
+ * It is typical to setup atfork handlers that will:
+ * - take the lock in the pre-fork handler,
+ * - drop the lock in the parent handler,
+ * - reset the lock in the forked child.
+ *
+ * However, because a recursive lock may have been held by the current thread
+ * already, reseting needs to act like an unlock.  This function serves for this
+ * purpose.  Unlike os_unfair_recursive_lock_unlock(), this function will fixup
+ * the lock ownership to match the new identity of the thread after fork().
+ */
+__OSX_AVAILABLE(10.15) __IOS_AVAILABLE(13.0)
+__TVOS_AVAILABLE(13.0) __WATCHOS_AVAILABLE(6.0)
+OS_EXPORT OS_NOTHROW OS_NONNULL_ALL
+void
+os_unfair_recursive_lock_unlock_forked_child(os_unfair_recursive_lock_t lock);
+
 #if __has_attribute(cleanup)
 
 /*!
index 000e5816326765676b541e5aab875f26cce52b56..0774e34849efa4259f73f414fd673be583af6969 100644 (file)
@@ -22,6 +22,8 @@
  */
 
 #include <mach/arm/syscall_sw.h>
+#include <mach/arm64/asm.h>
+#include <machine/cpu_capabilities.h>
 
 #define MMU_I_CLINE    6               // cache line size as 1<<MMU_I_CLINE (64)
 
 _sys_icache_invalidate:
        // see InvalidatePoU_IcacheRegion() in xnu/osfmk/arm64/caches_asm.s
        cbz             x1, 2f                                                  // length > 0 ?
-       and             x8, x0, #~((1<<MMU_I_CLINE)-1)  // cacheline align address
-       and             x9, x0, #((1<<MMU_I_CLINE)-1)   // extend length by alignment
-       add             x9, x1, x9
-       sub             x9, x9, #1
-       mov             x10, #-1
-       eor             x9, x10, x9, lsr #MMU_I_CLINE   // compute cacheline counter
+       MOV64   x8, _COMM_PAGE_CPU_CAPABILITIES
+       ldr             w8, [x8]
+       and             x9, x0, #~((1<<MMU_I_CLINE)-1)  // cacheline align address
+       and             x10, x0, #((1<<MMU_I_CLINE)-1)  // extend length by alignment
+       add             x10, x1, x10
+       sub             x10, x10, #1
+       mov             x11, #-1
+       eor             x10, x11, x10, lsr #MMU_I_CLINE // compute cacheline counter
+       dsb             ish
 1:
-       ic              ivau, x8                                                // invalidate icache line
-       add             x8, x8, #1<<MMU_I_CLINE                 // next cacheline address
-       add             x9, x9, #1                                              // decrement cacheline counter
-       cbnz    x9, 1b
+       ic              ivau, x9                                                // invalidate icache line
+       add             x9, x9, #1<<MMU_I_CLINE                 // next cacheline address
+       adds    x10, x10, #1                                    // decrement cacheline counter
+       b.ne    1b
        dsb             ish
+       tbnz    w8, kHasICDSBShift, 2f
        isb
 2:
        ret
@@ -56,19 +62,46 @@ _sys_dcache_flush:
        ret
 
 #if 0
-// Above generated by clang from:
+// Above based on output generated by clang from:
 static void __attribute((used))
 sys_icache_invalidate(uintptr_t start, size_t length)
 {
        if (!length) return;
+       boolean_t hasICDSB = (*(uint32_t*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES) & kHasICDSB;
        uintptr_t addr = start & ~((1 << MMU_I_CLINE) - 1);
        length += start & ((1 << MMU_I_CLINE) - 1);
        size_t count = ((length - 1) >> MMU_I_CLINE) + 1;
+       asm volatile("dsb ish" ::: "memory");
        while (count--) {
                asm("ic ivau, %[addr]" :: [addr] "r" (addr) : "memory");
                addr += (1 << MMU_I_CLINE);
        }
-       asm volatile("dsb ish\n\tisb" ::: "memory");
+       if (hasICDSB) {
+               asm volatile("dsb ish" ::: "memory");
+       } else {
+               asm volatile("dsb ish" ::: "memory");
+               asm volatile("isb" ::: "memory");
+       }
 }
+
+cbz    x1, 0x44
+mov    x8, #0xfffff0000
+movk   x8, #0xc020
+ldr    w8, [x8]
+and    x9, x0, #0xffffffffffffffc0
+and    x10, x0, #0x3f
+add    x10, x1, x10
+sub    x10, x10, #0x1
+mov    x11, #-0x1
+eor    x10, x11, x10, lsr #6
+ic     ivau, x9
+add    x9, x9, #0x40
+adds   x10, x10, #0x1
+b.ne   0x28
+dsb    ish
+tbnz   w8, #0x2, 0x44
+isb
+ret
+
 #endif
 
index 098d54f42c79ef0191af8d0d0fe3989421fa91d9..4705b81c175e1b19fb5251a8bce3738f663a35e6 100644 (file)
@@ -61,7 +61,9 @@ __libplatform_init(void *future_use __unused, const char *envp[],
 #if !TARGET_OS_SIMULATOR
     __pfz_setup(apple);
 #endif
+#if !TARGET_OS_DRIVERKIT
     _simple_asl_init(envp, vars);
+#endif
 
 #if !VARIANT_STATIC
     __libkernel_platform_init(&_platform_string_functions);
index 9230ac85173164caf01d34eef37c1d5cf3d17bcc..6d120be3c6161b678c38489c2f912909775c17bd 100644 (file)
@@ -426,9 +426,13 @@ void _os_unfair_lock_corruption_abort(os_ulock_value_t current);
 
 _Static_assert(OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION ==
                ULF_WAIT_WORKQ_DATA_CONTENTION,
-               "check value for OS_UNFAIR_LOCK_OPTIONS_MASK");
+               "check value for OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION");
+_Static_assert(OS_UNFAIR_LOCK_ADAPTIVE_SPIN ==
+               ULF_WAIT_ADAPTIVE_SPIN,
+               "check value for OS_UNFAIR_LOCK_ADAPTIVE_SPIN");
 #define OS_UNFAIR_LOCK_OPTIONS_MASK \
-               (os_unfair_lock_options_t)(OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION)
+               (os_unfair_lock_options_t)(OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION | \
+                               OS_UNFAIR_LOCK_ADAPTIVE_SPIN)
 #define OS_UNFAIR_LOCK_ALLOW_ANONYMOUS_OWNER 0x01000000u
 
 
@@ -645,6 +649,9 @@ void os_unfair_recursive_lock_unlock(os_unfair_recursive_lock_t lock);
 OS_ATOMIC_EXPORT
 bool os_unfair_recursive_lock_tryunlock4objc(os_unfair_recursive_lock_t lock);
 
+OS_ATOMIC_EXPORT
+void os_unfair_recursive_lock_unlock_forked_child(os_unfair_recursive_lock_t lock);
+
 
 static inline os_lock_owner_t
 _os_unfair_lock_owner(os_unfair_lock_t lock)
@@ -653,6 +660,15 @@ _os_unfair_lock_owner(os_unfair_lock_t lock)
        return OS_ULOCK_OWNER(os_atomic_load(&l->oul_value, relaxed));
 }
 
+
+bool
+os_unfair_recursive_lock_owned(os_unfair_recursive_lock_t lock)
+{
+       return _os_unfair_lock_owner(&lock->ourl_lock) ==
+                       _os_lock_owner_get_self();
+}
+
+
 void
 os_unfair_recursive_lock_lock_with_options(os_unfair_recursive_lock_t lock,
                os_unfair_lock_options_t options)
@@ -733,6 +749,23 @@ os_unfair_recursive_lock_tryunlock4objc(os_unfair_recursive_lock_t lock)
        return false;
 }
 
+void
+os_unfair_recursive_lock_unlock_forked_child(os_unfair_recursive_lock_t lock)
+{
+       _os_unfair_lock_t l = (_os_unfair_lock_t)&lock->ourl_lock;
+
+       if (os_atomic_load(&l->oul_value, relaxed) == OS_LOCK_NO_OWNER) {
+               __LIBPLATFORM_CLIENT_CRASH__(0, "Lock was not held");
+       }
+       if (lock->ourl_count) {
+               os_lock_owner_t self = _os_lock_owner_get_self();
+               lock->ourl_count--;
+               os_atomic_store(&l->oul_value, self, relaxed);
+       } else {
+               os_atomic_store(&l->oul_value, OS_LOCK_NO_OWNER, relaxed);
+       }
+}
+
 
 #pragma mark -
 #pragma mark _os_lock_unfair_t
@@ -1140,31 +1173,3 @@ _os_once(os_once_t *val, void *ctxt, os_function_t func)
        return _os_once_gate_wait(og, ctxt, func, self);
 }
 
-
-#pragma mark -
-#pragma mark os_lock_eliding_t
-
-#if !TARGET_OS_IPHONE
-
-#define _os_lock_eliding_t _os_lock_spin_t
-#define _os_lock_eliding_lock _os_lock_spin_lock
-#define _os_lock_eliding_trylock _os_lock_spin_trylock
-#define _os_lock_eliding_unlock _os_lock_spin_unlock
-OS_LOCK_METHODS_DECL(eliding);
-OS_LOCK_TYPE_INSTANCE(eliding);
-
-#pragma mark -
-#pragma mark os_lock_transactional_t
-
-OS_LOCK_STRUCT_DECL_INTERNAL(transactional,
-       uintptr_t volatile osl_lock;
-);
-
-#define _os_lock_transactional_t _os_lock_eliding_t
-#define _os_lock_transactional_lock _os_lock_eliding_lock
-#define _os_lock_transactional_trylock _os_lock_eliding_trylock
-#define _os_lock_transactional_unlock _os_lock_eliding_unlock
-OS_LOCK_METHODS_DECL(transactional);
-OS_LOCK_TYPE_INSTANCE(transactional);
-
-#endif // !TARGET_OS_IPHONE
index 9aaef411611145fb58fb67f348eb427787859735..4928a6ae8230d58f3fd080417a594a67768568a7 100644 (file)
 #include <platform/string.h>
 #include <platform/compat.h>
 
+#if TARGET_OS_DRIVERKIT
+// DriverKit processes log directly to kernel log
+#include <sys/log_data.h>
+OS_ENUM(os_log_type, uint8_t,
+       OS_LOG_TYPE_DEFAULT = 0x00,
+       OS_LOG_TYPE_INFO    = 0x01,
+       OS_LOG_TYPE_DEBUG   = 0x02,
+);
+#else // !TARGET_OS_DRIVERKIT
+
 #define ASL_LOG_PATH _PATH_LOG
 
 extern ssize_t __sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
@@ -78,35 +88,6 @@ static int _simple_asl_get_fd(void);
  * requires knowledge of the format used by ASL.
  */
 
-static const char *
-_simple_asl_escape_key(unsigned char c)
-{
-       switch(c)
-       {
-               case '\\': return "\\\\";
-               case '[':  return "\\[";
-               case ']':  return "\\]";
-               case '\n': return "\\n";
-               case ' ':  return "\\s";
-       }
-
-       return NULL;
-}
-
-static const char *
-_simple_asl_escape_val(unsigned char c)
-{
-       switch(c)
-       {
-               case '\\': return "\\\\";
-               case '[':  return "\\[";
-               case ']':  return "\\]";
-               case '\n': return "\\n";
-       }
-
-       return NULL;
-}
-
 __attribute__((visibility("hidden")))
 void
 _simple_asl_init(const char *envp[], const struct ProgramVars *vars)
@@ -131,7 +112,7 @@ static int
 _simple_asl_connect(const char *log_path)
 {
        int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
-       if (fd == -1) return;
+       if (fd == -1) return -1;
 
        fcntl(fd, F_SETFD, FD_CLOEXEC);
 
@@ -199,6 +180,36 @@ _simple_asl_get_fd(void)
        return ctx->asl_fd;
 #endif
 }
+#endif // !TARGET_OS_DRIVERKIT
+
+static const char *
+_simple_asl_escape_key(unsigned char c)
+{
+       switch(c)
+       {
+               case '\\': return "\\\\";
+               case '[':  return "\\[";
+               case ']':  return "\\]";
+               case '\n': return "\\n";
+               case ' ':  return "\\s";
+       }
+
+       return NULL;
+}
+
+static const char *
+_simple_asl_escape_val(unsigned char c)
+{
+       switch(c)
+       {
+               case '\\': return "\\\\";
+               case '[':  return "\\[";
+               case ']':  return "\\]";
+               case '\n': return "\\n";
+       }
+
+       return NULL;
+}
 
 _SIMPLE_STRING
 _simple_asl_msg_new(void)
@@ -255,6 +266,7 @@ _simple_asl_msg_set(_SIMPLE_STRING __b, const char *__key, const char *__val)
 void
 _simple_asl_send(_SIMPLE_STRING __b)
 {
+#if !TARGET_OS_DRIVERKIT
        struct timeval tv;
        int asl_fd = _simple_asl_get_fd();
        if (asl_fd < 0) return;
@@ -280,16 +292,21 @@ _simple_asl_send(_SIMPLE_STRING __b)
                cp = _simple_string(__b);
                __sendto(asl_fd, cp, strlen(cp), 0, NULL, 0);
     } while (0);
+#else // TARGET_OS_DRIVERKIT
+       char *cp;
+       cp = _simple_string(__b);
+       log_data_as_kernel(0, OS_LOG_TYPE_DEFAULT, cp, strlen(cp) + 1);
+#endif // TARGET_OS_DRIVERKIT
 }
 
 void
 _simple_asl_log_prog(int level, const char *facility, const char *message, const char *prog)
 {
-       char lstr[2];
-
        _SIMPLE_STRING b = _simple_asl_msg_new();
        if (b == NULL) return;
 
+#if !TARGET_OS_DRIVERKIT
+       char lstr[2];
        if (level < 0) level = 0;
        if (level > 7) level = 7;
        lstr[0] = level + '0';
@@ -300,16 +317,33 @@ _simple_asl_log_prog(int level, const char *facility, const char *message, const
        _simple_asl_msg_set(b, "Facility", facility);
        _simple_asl_msg_set(b, "Message", message);
        _simple_asl_send(b);
+#else // TARGET_OS_DRIVERKIT
+       if (prog) _simple_asl_msg_set(b, "Sender", prog);
+       _simple_asl_msg_set(b, "Facility", facility);
+       _simple_asl_msg_set(b, "Message", message);
+
+       os_log_type_t type = level > ASL_LEVEL_INFO ? OS_LOG_TYPE_DEFAULT :
+                       (level > ASL_LEVEL_DEBUG ? OS_LOG_TYPE_INFO : OS_LOG_TYPE_DEBUG);
+
+       char *cp;
+       cp = _simple_string(b);
+       log_data_as_kernel(0, type, cp, strlen(cp) + 1);
+#endif // TARGET_OS_DRIVERKIT
        _simple_sfree(b);
 }
 
 void
 _simple_asl_log(int level, const char *facility, const char *message)
 {
+#if !TARGET_OS_DRIVERKIT
        _simple_asl_log_prog(level, facility, message,
                        _simple_asl_get_context()->progname);
+#else // TARGET_OS_DRIVERKIT
+       _simple_asl_log_prog(level, facility, message, NULL);
+#endif // TARGET_OS_DRIVERKIT
 }
 
+#if !TARGET_OS_DRIVERKIT
 static struct asl_context *
 _simple_asl_get_context(void)
 {
@@ -325,3 +359,4 @@ _simple_asl_init_context(void *arg)
        ctx->progname = "unknown";
        ctx->asl_fd = -1;
 }
+#endif // !TARGET_OS_DRIVERKIT
index 4bffac6755060e0e3fa720c41e2c4595884dac46..0c8c6375e811c945bcce09b7409a76ca15db76d6 100644 (file)
@@ -187,6 +187,35 @@ dec(BUF *b, _esc_func esc, long long in, int width, int zero)
        put_s(b, esc, cp);
 }
 
+/*
+ * Output the octal string representing the number in "n".  "width" is
+ * the minimum field width, and "zero" is a boolean value, true for zero padding
+ * (otherwise blank padding).
+ */
+static void
+oct(BUF *b, _esc_func esc, unsigned long long n, int width, int zero)
+{
+       char buf[32];
+       char *cp = buf + sizeof(buf);
+       ssize_t pad;
+
+       *--cp = 0;
+       if (n) {
+               while (n) {
+                       *--cp = (n % 8) + '0';
+                       n /= 8;
+               }
+       } else {
+               *--cp = '0';
+       }
+       pad = width - strlen(cp);
+       zero = zero ? '0' : ' ';
+       while (pad-- > 0) {
+               put_c(b, esc, zero);
+       }
+       put_s(b, esc, cp);
+}
+
 /*
  * Output the hex string representing the number in "n".  "width" is the
  * minimum field width, and "zero" is a boolean value, true for zero padding
@@ -334,6 +363,19 @@ __simple_bprintf(BUF *b, _esc_func esc, const char *fmt, va_list ap)
                                lflag++;
                                fmt++;
                                continue;
+                       case 'o':
+                               switch (lflag) {
+                               case 0:
+                                       oct(b, esc, va_arg(ap, int), width, zero);
+                                       break;
+                               case 1:
+                                       oct(b, esc, va_arg(ap, long), width, zero);
+                                       break;
+                               default:
+                                       oct(b, esc, va_arg(ap, long long), width, zero);
+                                       break;
+                               }
+                               break;
                        case 'p':
                                hex(b, esc, (unsigned long)va_arg(ap, void *), width, zero, 0, 1);
                                break;
index 4c070a49b0c6657b9ad9b3f215e1b45e9d4159a4..4559ddea282a60af6c18771da1ce65a26e9cdffc 100644 (file)
 
 #include <platform/string.h>
 
+#if !VARIANT_STATIC
+// to satisfy compiler-generated memset inside libplatform (e.g. makecontext)
+__attribute__((visibility("hidden")))
+void *
+memset(void *b, int c, size_t len)
+{
+       return _platform_memset(b, c, len);
+}
+#endif
+
 #if !_PLATFORM_OPTIMIZED_MEMSET
 
 void *
index e284e51e3096eaab66417f300214ce2cb7c93cae..757ec10d84feca64279e9d4996b86b364e7ddb85 100644 (file)
@@ -8,5 +8,5 @@ OTHER_CFLAGS_debug =
 
 OSATOMIC_PREPROCESSOR_DEFINITIONS = OSATOMIC_USE_INLINED=0 OSATOMIC_DEPRECATED=0
 
-PUBLIC_HEADERS_FOLDER_PATH = /usr/include/libkern
-PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/libkern
+PUBLIC_HEADERS_FOLDER_PATH = $(SDK_INSTALL_HEADERS_ROOT)/usr/include/libkern
+PRIVATE_HEADERS_FOLDER_PATH = $(SDK_INSTALL_HEADERS_ROOT)/usr/local/include/libkern
index 4e8ce3940bf1e395e8235484c659918f71211deb..bba8d5a6fbd27159c4d9db9d6b64cd9f65f0caa3 100644 (file)
@@ -1,3 +1,5 @@
 __platform_bzero ___bzero
+__os_lock_type_spin __os_lock_type_eliding
+__os_lock_type_spin __os_lock_type_transactional
 _os_unfair_lock_lock_with_options _os_unfair_lock_lock_with_options_4Libc
 _os_unfair_lock_unlock _os_unfair_lock_unlock_4Libc
index ce479ba4fe733cacf1fae6b2d8c29ac63db7d78a..048f98b616ca3ef51630786966f5c89e7ab5f046 100644 (file)
@@ -8,9 +8,20 @@ SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator
 BUILD_VARIANTS = normal debug dyld static
 
 EXECUTABLE_PREFIX = lib
-INSTALL_PATH = /usr/lib/system
-PUBLIC_HEADERS_FOLDER_PATH = /usr/include
-PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include
+
+// Pick the right install locations depending on whether building for DriverKit SDK or not
+SDK_INSTALL_VARIANT = $(SDK_INSTALL_VARIANT_$(DRIVERKIT))
+SDK_INSTALL_VARIANT_1 = driverkit
+SDK_INSTALL_VARIANT_ = default
+SDK_INSTALL_ROOT = $(SDK_INSTALL_ROOT_$(SDK_INSTALL_VARIANT))
+SDK_INSTALL_ROOT_driverkit = $(DRIVERKITROOT)
+SDK_INSTALL_HEADERS_ROOT = $(SDK_INSTALL_HEADERS_ROOT_$(SDK_INSTALL_VARIANT))
+SDK_INSTALL_HEADERS_ROOT_driverkit = $(SDK_INSTALL_ROOT)/$(SDK_RUNTIME_HEADERS_PREFIX)
+SDK_RUNTIME_HEADERS_PREFIX = Runtime
+
+INSTALL_PATH = $(SDK_INSTALL_ROOT)/usr/lib/system
+PUBLIC_HEADERS_FOLDER_PATH=$(SDK_INSTALL_HEADERS_ROOT)/usr/include
+PRIVATE_HEADERS_FOLDER_PATH=$(SDK_INSTALL_HEADERS_ROOT)/usr/local/include
 
 USE_HEADERMAP = NO
 SKIP_INSTALL = YES
@@ -19,7 +30,7 @@ INSTALLHDRS_SCRIPT_PHASE = YES
 GCC_OPTIMIZATION_LEVEL = s
 
 // TODO: Remove -fno-stack-protector once it has been moved down (after libproc is moved down)
-OTHER_CFLAGS = -fno-stack-protector -fdollars-in-identifiers -fno-common -fverbose-asm $(COMPILER_CFLAGS) $(PLATFORM_CFLAGS) -isystem $(SYSTEM_FRAMEWORK_HEADERS)
+OTHER_CFLAGS = -fno-stack-protector -fdollars-in-identifiers -fno-common -fverbose-asm $(COMPILER_CFLAGS) $(PLATFORM_CFLAGS)
 OTHER_CFLAGS_normal = -momit-leaf-frame-pointer
 OTHER_CFLAGS_debug = -fno-inline -O0
 
@@ -37,8 +48,9 @@ STRIP_INSTALLED_PRODUCT_static = NO
 STRIP_INSTALLED_PRODUCT_debug = YES
 
 SRCROOT_SEARCH_PATHS = $(SRCROOT)/private $(SRCROOT)/include $(SRCROOT)/internal
-SYSTEM_FRAMEWORK_HEADERS = $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
-HEADER_SEARCH_PATHS = $(SRCROOT_SEARCH_PATHS) $(SDKROOT)/usr/local/include $(SDKROOT)/usr/include $(inherited)
+HEADER_SEARCH_PATHS = $(SRCROOT_SEARCH_PATHS) $(inherited)
+SYSTEM_HEADER_SEARCH_PATHS = $(SDKROOT)/$(SDK_INSTALL_HEADERS_ROOT)/System/Library/Frameworks/System.framework/PrivateHeaders $(SDKROOT)/$(SDK_INSTALL_HEADERS_ROOT)/usr/local/include $(SDKROOT)/$(SDK_INSTALL_HEADERS_ROOT)/usr/include
+SYSTEM_FRAMEWORK_SEARCH_PATHS = $(SDKROOT)/$(SDK_INSTALL_HEADERS_ROOT)/System/Library/Frameworks
 
 DEAD_CODE_STRIPPING = NO
 
@@ -52,8 +64,13 @@ SETJMP_LIBRARIES = $(CONFIGURATION_BUILD_DIR)/libsetjmp_i386_$(CURRENT_VARIANT).
 STRING_LIBRARIES = $(CONFIGURATION_BUILD_DIR)/libstring_i386_$(CURRENT_VARIANT).a $(CONFIGURATION_BUILD_DIR)/libstring_x86_64_$(CURRENT_VARIANT).a $(CONFIGURATION_BUILD_DIR)/libstring_arm_$(CURRENT_VARIANT).a $(CONFIGURATION_BUILD_DIR)/libstring_arm64_$(CURRENT_VARIANT).a $(EXTRA_STRING_LIBRARIES)
 UCONTEXT_LIBRARIES = $(CONFIGURATION_BUILD_DIR)/libucontext_i386_$(CURRENT_VARIANT).a $(CONFIGURATION_BUILD_DIR)/libucontext_x86_64_$(CURRENT_VARIANT).a
 
+IS_ZIPPERED = YES
+
+SIMULATOR_LDFLAGS =
+SIMULATOR_LDFLAGS[sdk=macosx*] = -Wl,-simulator_support
+
 OTHER_LDFLAGS = $(OTHER_LDFLAGS_$(TARGET_NAME)) $(CR_LDFLAGS)
-OTHER_LDFLAGS_libsystem_platform = -all_load $(PLATFORM_LIBRARIES) -umbrella System -L/usr/lib/system -ldyld -lcompiler_rt $(lsystem_kernel) -Wl,-alias_list,$(SRCROOT)/xcodeconfig/libplatform.aliases,$(DIRTY_DATA_LDFLAGS)
+OTHER_LDFLAGS_libsystem_platform = -all_load $(PLATFORM_LIBRARIES) -umbrella System -L$(SDK_INSTALL_ROOT)/usr/lib/system -ldyld $(lcompiler_rt) $(lsystem_kernel) -Wl,-alias_list,$(SRCROOT)/xcodeconfig/libplatform.aliases,$(DIRTY_DATA_LDFLAGS) $(SIMULATOR_LDFLAGS)
 
 OTHER_LIBTOOLFLAGS = $(OTHER_LIBTOOLFLAGS_$(TARGET_NAME))
 OTHER_LIBTOOLFLAGS_libplatform_simple_dyld = $(CONFIGURATION_BUILD_DIR)/libsimple_$(CURRENT_VARIANT).a
@@ -70,4 +87,6 @@ OTHER_LIBTOOLFLAGS_libucontext = $(UCONTEXT_LIBRARIES)
 
 lsystem_kernel = -lsystem_kernel
 lsystem_kernel[sdk=iphonesimulator*] = -lsystem_sim_kernel
+lcompiler_rt = -lcompiler_rt
+lcompiler_rt[sdk=driverkit*] =
 
index 3a940188250ef151059fb09242a7a91f4ec0c50e..fb567009999ce8673d5be249682a585b2251964f 100644 (file)
@@ -22,7 +22,7 @@ OTHER_CFLAGS_debug =
 SRCROOT_SEARCH_PATHS = $(inherited) $(SRCROOT)/src/os/resolver
 OSATOMIC_PREPROCESSOR_DEFINITIONS = OSATOMIC_USE_INLINED=0 OSATOMIC_DEPRECATED=0 OSSPINLOCK_USE_INLINED=0 OSSPINLOCK_DEPRECATED=0
 
-PUBLIC_HEADERS_FOLDER_PATH = /usr/include/os
-PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/os
-OS_INTERNAL_HEADERS_FOLDER_PATH = /usr/local/include/os/internal
+PUBLIC_HEADERS_FOLDER_PATH = $(SDK_INSTALL_HEADERS_ROOT)/usr/include/os
+PRIVATE_HEADERS_FOLDER_PATH = $(SDK_INSTALL_HEADERS_ROOT)/usr/local/include/os
+OS_INTERNAL_HEADERS_FOLDER_PATH = $(SDK_INSTALL_HEADERS_ROOT)/usr/local/include/os/internal