]> git.saurik.com Git - apple/libpthread.git/commitdiff
libpthread-416.100.3.tar.gz macos-10154 macos-10155 macos-10156 v416.100.3
authorApple <opensource@apple.com>
Fri, 1 May 2020 18:18:24 +0000 (18:18 +0000)
committerApple <opensource@apple.com>
Fri, 1 May 2020 18:18:24 +0000 (18:18 +0000)
src/pthread_asm.s
src/pthread_mutex.c
tests/stack.c

index 244957a86209a8deca3904c593bfb2f97e9c5144..2a02f0949f3e1deac1004db4768e900b2d7e7539 100644 (file)
@@ -279,7 +279,7 @@ _thread_start:
        .globl _thread_chkstk_darwin
 _thread_chkstk_darwin:
        .globl ____chkstk_darwin
        .globl _thread_chkstk_darwin
 _thread_chkstk_darwin:
        .globl ____chkstk_darwin
-____chkstk_darwin: // %w9 == alloca size
+____chkstk_darwin: // %w9/x9 == alloca size
        stp     x10, x11, [sp, #-16]
 
        // validate that the frame pointer is on our stack (no alt stack)
        stp     x10, x11, [sp, #-16]
 
        // validate that the frame pointer is on our stack (no alt stack)
@@ -288,6 +288,7 @@ ____chkstk_darwin: // %w9 == alloca size
 
        // (%sp - pthread_self()->stackaddr) > 0 ?
 #if defined(__ARM64_ARCH_8_32__)
 
        // (%sp - pthread_self()->stackaddr) > 0 ?
 #if defined(__ARM64_ARCH_8_32__)
+       ubfx    x9, x9, #0, #32
        ldur    w11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
 #else
        ldur    x11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
        ldur    w11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
 #else
        ldur    x11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
@@ -305,8 +306,8 @@ ____chkstk_darwin: // %w9 == alloca size
        cmp     x10, x11
        b.ls    Lprobe
 
        cmp     x10, x11
        b.ls    Lprobe
 
-       // %sp - (uintptr_t)%w9 < pthread_self()->stackbottom ?
-       subs    x10, x10, w9, uxtw
+       // %sp - (uintptr_t)%x9 < pthread_self()->stackbottom ?
+       subs    x10, x10, x9
        b.lo    Lcrash
        cmp     x10, x11
        b.lo    Lcrash
        b.lo    Lcrash
        cmp     x10, x11
        b.lo    Lcrash
@@ -326,13 +327,13 @@ Lcrash:
 
 Lprobe:
        mov     x10, sp
 
 Lprobe:
        mov     x10, sp
-       cmp     w9, #0x1000
+       cmp     x9, #0x1000
        b.lo    Lend
 Lloop:
        sub     x10, x10, #0x1000
        ldr     x11, [x10]
        b.lo    Lend
 Lloop:
        sub     x10, x10, #0x1000
        ldr     x11, [x10]
-       sub     w9, w9, #0x1000
-       cmp     w9, #0x1000
+       sub     x9, x9, #0x1000
+       cmp     x9, #0x1000
        b.hi    Lloop
 Lend:
        sub     x10, x10, x9
        b.hi    Lloop
 Lend:
        sub     x10, x10, x9
index e1e5c2e042f9714b2174d55195d7c41b6328fa75..ad86eebf456f4bfa3dc24faac9c05f38eb185ed3 100644 (file)
@@ -1444,7 +1444,7 @@ _pthread_mutex_firstfit_lock(pthread_mutex_t *omutex, bool trylock)
        mutex_seq oldseq, newseq;
        mutex_seq_load(seqaddr, &oldseq);
 
        mutex_seq oldseq, newseq;
        mutex_seq_load(seqaddr, &oldseq);
 
-       if (os_unlikely(oldseq.lgenval & PTH_RWL_EBIT)) {
+       if (os_unlikely(!trylock && (oldseq.lgenval & PTH_RWL_EBIT))) {
                return _pthread_mutex_firstfit_lock_slow(mutex, trylock);
        }
 
                return _pthread_mutex_firstfit_lock_slow(mutex, trylock);
        }
 
@@ -1454,9 +1454,16 @@ _pthread_mutex_firstfit_lock(pthread_mutex_t *omutex, bool trylock)
                gotlock = is_rwl_ebit_clear(oldseq.lgenval);
 
                if (trylock && !gotlock) {
                gotlock = is_rwl_ebit_clear(oldseq.lgenval);
 
                if (trylock && !gotlock) {
+#if __LP64__
+                       // The sequence load is atomic, so we can bail here without writing
+                       // it and avoid some unnecessary coherence traffic - rdar://57259033
+                       os_atomic_thread_fence(acquire);
+                       return EBUSY;
+#else
                        // A trylock on a held lock will fail immediately. But since
                        // we did not load the sequence words atomically, perform a
                        // no-op CAS64 to ensure that nobody has unlocked concurrently.
                        // A trylock on a held lock will fail immediately. But since
                        // we did not load the sequence words atomically, perform a
                        // no-op CAS64 to ensure that nobody has unlocked concurrently.
+#endif
                } else if (os_likely(gotlock)) {
                        // In first-fit, getting the lock simply adds the E-bit
                        newseq.lgenval |= PTH_RWL_EBIT;
                } else if (os_likely(gotlock)) {
                        // In first-fit, getting the lock simply adds the E-bit
                        newseq.lgenval |= PTH_RWL_EBIT;
index f9458adc2722484ead2c2771c18b7c9a9a294ff4..f7d7fd0007df77e7819eb17fd295bdb8a7d674f3 100644 (file)
@@ -50,7 +50,11 @@ T_DECL(chkstk, "chkstk",
        };
        T_ASSERT_POSIX_SUCCESS(sigaction(SIGSEGV, &sa, NULL), "sigaction");
 
        };
        T_ASSERT_POSIX_SUCCESS(sigaction(SIGSEGV, &sa, NULL), "sigaction");
 
-       call_chkstk(1 << 24);
+#if __LP64__
+       call_chkstk(1ul << 32);
+#else
+       call_chkstk(1ul << 24);
+#endif
        T_FAIL("should have crashed");
 #endif
 }
        T_FAIL("should have crashed");
 #endif
 }