From 5eccb9646dd94438911706d3ebf52775caa7f41e Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 20 Dec 2013 16:58:06 -0800 Subject: [PATCH] Fix aarch64 futex assembly routines. Also make the other architectures more similar to one another, use NULL instead of 0 in calling code, and remove an unused #define. Change-Id: I52b874afb6a351c802f201a0625e484df6d093bb --- libc/arch-aarch64/bionic/futex_aarch64.S | 109 ++++++++++--------------------- libc/arch-arm/bionic/futex_arm.S | 11 ++-- libc/arch-mips/bionic/futex_mips.S | 20 ++---- libc/arch-x86/bionic/futex_x86.S | 11 ++-- libc/arch-x86_64/bionic/futex_x86_64.S | 14 ++-- libc/bionic/system_properties.c | 8 +-- libc/bionic/system_properties_compat.c | 2 +- libc/private/bionic_futex.h | 1 - 8 files changed, 59 insertions(+), 117 deletions(-) diff --git a/libc/arch-aarch64/bionic/futex_aarch64.S b/libc/arch-aarch64/bionic/futex_aarch64.S index bf7959b17..e3ac30938 100644 --- a/libc/arch-aarch64/bionic/futex_aarch64.S +++ b/libc/arch-aarch64/bionic/futex_aarch64.S @@ -31,97 +31,56 @@ #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -/* - * Syscall interface for fast userspace locks - * - * int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout); - * int __futex_wake(volatile void *ftx, int count); - * int __futex_syscall3(volatile void *ftx, int op, int val); - * int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout); - */ - +// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) ENTRY(__futex_syscall4) - /* create AArch64 PCS frame pointer */ - stp x29, x30, [sp, #-16]! - mov x29, sp - - /* store x8 */ - str x8, [sp, #-16]! - - /* syscall No. in x8 */ - mov x8, __NR_futex - svc #0 - - /* restore x8 */ - ldr x8, [sp], #16 - ldp x29, x30, [sp], #16 + stp x29, x30, [sp, #-16]! + mov x29, sp - /* check if syscall returned successfully */ - cmn x0, #(MAX_ERRNO + 1) - cneg x0, x0, hi - b.hi __set_errno + str x8, [sp, #-16]! + mov x8, __NR_futex + svc #0 + ldr x8, [sp], #16 - ret + ldp x29, x30, [sp], #16 + ret END(__futex_syscall4) +// int __futex_syscall3(volatile void* ftx, int op, int count) ENTRY(__futex_syscall3) - /* __futex_syscall4 but with fewer arguments */ - b __futex_syscall4 + b __futex_syscall4 END(__futex_syscall3) +// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) ENTRY(__futex_wait) - /* create AArch64 PCS frame pointer */ - stp x29, x30, [sp, #-16]! - mov x29, sp + stp x29, x30, [sp, #-16]! + mov x29, sp - /* store x8 */ - str x8, [sp, #-16]! + mov x3, x2 + mov x2, x1 + mov x1, #FUTEX_WAIT - /* arange arguments as expected in the kernel side */ - mov x3, x2 - mov w2, w1 - mov w1, #FUTEX_WAIT + str x8, [sp, #-16]! + mov x8, __NR_futex + svc #0 + ldr x8, [sp], #16 - /* syscall No. in X8 */ - mov x8, __NR_futex - svc #0 - - /* restore x8 */ - ldr x8, [sp], #16 - ldp x29, x30, [sp], #16 - - /* check if syscall returned successfully */ - cmn x0, #(MAX_ERRNO + 1) - cneg x0, x0, hi - b.hi __set_errno - - ret + ldp x29, x30, [sp], #16 + ret END(__futex_wait) +// int __futex_wake(volatile void* ftx, int count) ENTRY(__futex_wake) - /* create AArch64 PCS frame pointer */ - stp x29, x30, [sp, #-16]! - mov x29, sp - - /* store x8 */ - str x8, [sp, #-16]! - - /* arange arguments as expected in the kernel side */ - mov w2, w1 - mov w1, #FUTEX_WAIT - - /* syscall No. in X8 */ - mov x8, __NR_futex - svc #0 + stp x29, x30, [sp, #-16]! + mov x29, sp - /* restore x8 */ - ldr x8, [sp], #16 - ldp x29, x30, [sp], #16 + mov x2, x1 + mov x1, #FUTEX_WAKE - /* check if syscall returned successfully */ - cmn x0, #(MAX_ERRNO + 1) - cneg x0, x0, hi - b.hi __set_errno + str x8, [sp, #-16]! + mov x8, __NR_futex + svc #0 + ldr x8, [sp], #16 - ret + ldp x29, x30, [sp], #16 + ret END(__futex_wake) diff --git a/libc/arch-arm/bionic/futex_arm.S b/libc/arch-arm/bionic/futex_arm.S index 4131cdb1f..0aba27818 100644 --- a/libc/arch-arm/bionic/futex_arm.S +++ b/libc/arch-arm/bionic/futex_arm.S @@ -26,13 +26,12 @@ * SUCH DAMAGE. */ -#include -#include +#include #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -// __futex_syscall3(*ftx, op, val) +// int __futex_syscall3(volatile void* ftx, int op, int count) ENTRY(__futex_syscall3) mov ip, r7 ldr r7, =__NR_futex @@ -41,12 +40,12 @@ ENTRY(__futex_syscall3) bx lr END(__futex_syscall3) -// __futex_syscall4(*ftx, op, val, *timespec) +// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) ENTRY(__futex_syscall4) b __futex_syscall3 END(__futex_syscall4) -// __futex_wait(*ftx, val, *timespec) +// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) ENTRY(__futex_wait) mov ip, r7 mov r3, r2 @@ -58,7 +57,7 @@ ENTRY(__futex_wait) bx lr END(__futex_wait) -// __futex_wake(*ftx, counter) +// int __futex_wake(volatile void* ftx, int count) ENTRY(__futex_wake) mov ip, r7 mov r2, r1 diff --git a/libc/arch-mips/bionic/futex_mips.S b/libc/arch-mips/bionic/futex_mips.S index 2a953caf0..5247b79e1 100644 --- a/libc/arch-mips/bionic/futex_mips.S +++ b/libc/arch-mips/bionic/futex_mips.S @@ -26,15 +26,12 @@ * SUCH DAMAGE. */ -#include +#include #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -/* - * __futex_wait(*ftx, val, *timespec) - * futex_syscall(*ftx, op, val, *timespec, *addr2, val3) - */ +// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) .type __futex_wait, @function .global __futex_wait .align 4 @@ -59,10 +56,7 @@ __futex_wait: j $ra .end __futex_wait -/* - * int __futex_wake(volatile void *ftx, int count) - * int futex_syscall(*ftx, op, val, *timespec, *addr2, val3) - */ +// int __futex_wake(volatile void* ftx, int count) .type __futex_wake, @function .globl __futex_wake .align 4 @@ -87,9 +81,7 @@ __futex_wake: j $ra .end __futex_wake -/* __futex_syscall3(*ftx, op, val) - * futex_syscall(*ftx, op, val, *timespec, *addr2, val3) - */ +// int __futex_syscall3(volatile void* ftx, int op, int count) .type __futex_syscall3, @function .global __futex_syscall3 .align 4 @@ -114,9 +106,7 @@ __futex_syscall3: j $ra .end __futex_syscall3 -/* __futex_syscall4(*ftx, op, val) - * futex_syscall(*ftx, op, val, *timespec, *addr2, val3) - */ +// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) .type __futex_syscall4, @function .global __futex_syscall4 .align 4 diff --git a/libc/arch-x86/bionic/futex_x86.S b/libc/arch-x86/bionic/futex_x86.S index fa3375858..8dd2ad018 100644 --- a/libc/arch-x86/bionic/futex_x86.S +++ b/libc/arch-x86/bionic/futex_x86.S @@ -1,10 +1,9 @@ -#include -#include +#include #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -// int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout) +// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) ENTRY(__futex_wait) pushl %ebx pushl %esi @@ -19,7 +18,7 @@ ENTRY(__futex_wait) ret END(__futex_wait) -// int __futex_wake(volatile void *ftx, int count) +// int __futex_wake(volatile void* ftx, int count) ENTRY(__futex_wake) pushl %ebx mov 8(%esp), %ebx /* ftx */ @@ -31,7 +30,7 @@ ENTRY(__futex_wake) ret END(__futex_wake) -// int __futex_syscall3(volatile void *ftx, int op, int count) +// int __futex_syscall3(volatile void* ftx, int op, int count) ENTRY(__futex_syscall3) pushl %ebx movl 8(%esp), %ebx /* ftx */ @@ -43,7 +42,7 @@ ENTRY(__futex_syscall3) ret END(__futex_syscall3) -// int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout) +// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) ENTRY(__futex_syscall4) pushl %ebx pushl %esi diff --git a/libc/arch-x86_64/bionic/futex_x86_64.S b/libc/arch-x86_64/bionic/futex_x86_64.S index 48a437e76..f85d583bd 100644 --- a/libc/arch-x86_64/bionic/futex_x86_64.S +++ b/libc/arch-x86_64/bionic/futex_x86_64.S @@ -26,15 +26,12 @@ * SUCH DAMAGE. */ -#include -#include +#include #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -/* - * int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout) - */ +// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) ENTRY(__futex_wait) mov %rdx, %r10 /* timeout */ mov %esi, %edx /* val */ @@ -44,8 +41,7 @@ ENTRY(__futex_wait) ret END(__futex_wait) -/* int __futex_wake(volatile void *ftx, int count) */ - +// int __futex_wake(volatile void* ftx, int count) ENTRY(__futex_wake) mov %esi, %edx mov $FUTEX_WAKE, %esi @@ -54,14 +50,14 @@ ENTRY(__futex_wake) ret END(__futex_wake) -/* int __futex_syscall3(volatile void *ftx, int op, int count) */ +// int __futex_syscall3(volatile void* ftx, int op, int count) ENTRY(__futex_syscall3) mov $__NR_futex, %eax syscall ret END(__futex_syscall3) -/* int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout) */ +// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) ENTRY(__futex_syscall4) mov %rcx, %r10 /* timeout */ mov $__NR_futex, %eax diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c index 9fdb6f5e2..825894f75 100644 --- a/libc/bionic/system_properties.c +++ b/libc/bionic/system_properties.c @@ -454,7 +454,7 @@ int __system_property_read(const prop_info *pi, char *name, char *value) for(;;) { serial = pi->serial; while(SERIAL_DIRTY(serial)) { - __futex_wait((volatile void *)&pi->serial, serial, 0); + __futex_wait((volatile void *)&pi->serial, serial, NULL); serial = pi->serial; } len = SERIAL_VALUE_LEN(serial); @@ -572,12 +572,12 @@ int __system_property_wait(const prop_info *pi) prop_area *pa = __system_property_area__; n = pa->serial; do { - __futex_wait(&pa->serial, n, 0); + __futex_wait(&pa->serial, n, NULL); } while(n == pa->serial); } else { n = pi->serial; do { - __futex_wait((volatile void *)&pi->serial, n, 0); + __futex_wait((volatile void *)&pi->serial, n, NULL); } while(n == pi->serial); } return 0; @@ -635,7 +635,7 @@ unsigned int __system_property_wait_any(unsigned int serial) prop_area *pa = __system_property_area__; do { - __futex_wait(&pa->serial, serial, 0); + __futex_wait(&pa->serial, serial, NULL); } while(pa->serial == serial); return pa->serial; diff --git a/libc/bionic/system_properties_compat.c b/libc/bionic/system_properties_compat.c index 0326f053a..b4c249465 100644 --- a/libc/bionic/system_properties_compat.c +++ b/libc/bionic/system_properties_compat.c @@ -101,7 +101,7 @@ int __system_property_read_compat(const prop_info *_pi, char *name, char *value) for(;;) { serial = pi->serial; while(SERIAL_DIRTY(serial)) { - __futex_wait((volatile void *)&pi->serial, serial, 0); + __futex_wait((volatile void *)&pi->serial, serial, NULL); serial = pi->serial; } len = SERIAL_VALUE_LEN(serial); diff --git a/libc/private/bionic_futex.h b/libc/private/bionic_futex.h index 5602af76e..bfc3520f7 100644 --- a/libc/private/bionic_futex.h +++ b/libc/private/bionic_futex.h @@ -28,7 +28,6 @@ #ifndef _BIONIC_FUTEX_H #define _BIONIC_FUTEX_H -#include /* needed for __user in non-uapi futex.h */ #include #include -- 2.11.0