From d5ed63a6a8290de88802172ce178656fbafe70c6 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 21 May 2014 18:27:40 -0700 Subject: [PATCH] Hide most of the private futex functions. Also hide part of the system properties compatibility code, since we needed to touch that to keep it building. I'll remove __futex_syscall4 and futex in a later patch. Bug: 11156955 Change-Id: Ibbf42414c5bb07fb9f1c4a169922844778e4eeae --- libc/arch-arm/bionic/futex_arm.S | 43 ++------------ libc/arch-arm64/bionic/futex_arm64.S | 53 +---------------- libc/arch-mips/bionic/futex_mips.S | 68 +-------------------- libc/arch-mips64/bionic/futex_mips.S | 82 +------------------------- libc/arch-x86/bionic/futex_x86.S | 44 +------------- libc/arch-x86_64/bionic/futex_x86_64.S | 31 +--------- libc/bionic/pthread_internals.cpp | 8 --- libc/bionic/system_properties.cpp | 3 +- libc/bionic/system_properties_compat.c | 9 +-- libc/include/sys/atomics.h | 4 -- libc/private/bionic_futex.h | 28 ++++++--- 11 files changed, 36 insertions(+), 337 deletions(-) diff --git a/libc/arch-arm/bionic/futex_arm.S b/libc/arch-arm/bionic/futex_arm.S index 0aba27818..89a1e9689 100644 --- a/libc/arch-arm/bionic/futex_arm.S +++ b/libc/arch-arm/bionic/futex_arm.S @@ -28,42 +28,11 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - -// int __futex_syscall3(volatile void* ftx, int op, int count) -ENTRY(__futex_syscall3) - mov ip, r7 - ldr r7, =__NR_futex - swi #0 - mov r7, ip - bx lr -END(__futex_syscall3) - // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) -ENTRY(__futex_syscall4) - b __futex_syscall3 +ENTRY_PRIVATE(__futex_syscall4) + mov ip, r7 + ldr r7, =__NR_futex + swi #0 + mov r7, ip + bx lr END(__futex_syscall4) - -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -ENTRY(__futex_wait) - mov ip, r7 - mov r3, r2 - mov r2, r1 - mov r1, #FUTEX_WAIT - ldr r7, =__NR_futex - swi #0 - mov r7, ip - bx lr -END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -ENTRY(__futex_wake) - mov ip, r7 - mov r2, r1 - mov r1, #FUTEX_WAKE - ldr r7, =__NR_futex - swi #0 - mov r7, ip - bx lr -END(__futex_wake) diff --git a/libc/arch-arm64/bionic/futex_arm64.S b/libc/arch-arm64/bionic/futex_arm64.S index 00d24a49c..9d7465ae4 100644 --- a/libc/arch-arm64/bionic/futex_arm64.S +++ b/libc/arch-arm64/bionic/futex_arm64.S @@ -28,11 +28,8 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) -ENTRY(__futex_syscall4) +ENTRY_PRIVATE(__futex_syscall4) stp x29, x30, [sp, #-16]! .cfi_def_cfa_offset 16 .cfi_rel_offset x29, 0 @@ -48,51 +45,3 @@ ENTRY(__futex_syscall4) .cfi_restore x30 ret END(__futex_syscall4) - -// int __futex_syscall3(volatile void* ftx, int op, int count) -ENTRY(__futex_syscall3) - b __futex_syscall4 -END(__futex_syscall3) - -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -ENTRY_PRIVATE(__futex_wait) - stp x29, x30, [sp, #-16]! - .cfi_def_cfa_offset 16 - .cfi_rel_offset x29, 0 - .cfi_rel_offset x30, 8 - mov x29, sp - - mov x3, x2 - mov x2, x1 - mov x1, #FUTEX_WAIT - - mov x8, __NR_futex - svc #0 - - ldp x29, x30, [sp], #16 - .cfi_def_cfa_offset 0 - .cfi_restore x29 - .cfi_restore x30 - ret -END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -ENTRY_PRIVATE(__futex_wake) - stp x29, x30, [sp, #-16]! - .cfi_def_cfa_offset 16 - .cfi_rel_offset x29, 0 - .cfi_rel_offset x30, 8 - mov x29, sp - - mov x2, x1 - mov x1, #FUTEX_WAKE - - mov x8, __NR_futex - svc #0 - - ldp x29, x30, [sp], #16 - .cfi_def_cfa_offset 0 - .cfi_restore x29 - .cfi_restore x30 - ret -END(__futex_wake) diff --git a/libc/arch-mips/bionic/futex_mips.S b/libc/arch-mips/bionic/futex_mips.S index 7626a7ca1..5a09f325d 100644 --- a/libc/arch-mips/bionic/futex_mips.S +++ b/libc/arch-mips/bionic/futex_mips.S @@ -28,74 +28,8 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -ENTRY(__futex_wait) - subu sp,4*6 - sw $0,20(sp) /* val3 */ - sw $0,16(sp) /* addr2 */ - move a3,a2 /* timespec */ - move a2,a1 /* val */ - li a1,FUTEX_WAIT /* op */ -# move a0,a0 /* ftx */ - li v0,__NR_futex - syscall - .set noreorder - bnez a3, 1f /* Check for error */ - neg v0 /* Negate error number if it's valid */ - move v0,$0 /* Otherwise return 0 */ -1: - .set reorder - addu sp,4*6 - j ra -END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -ENTRY(__futex_wake) - subu sp,4*6 - sw $0,20(sp) /* val3 */ - sw $0,16(sp) /* addr2 */ - move a3,$0 /* timespec */ - move a2,a1 /* val */ - li a1,FUTEX_WAKE /* op */ -# move a0,a0 /* ftx */ - li v0,__NR_futex - syscall - .set noreorder - bnez a3, 1f /* Check for error */ - neg v0 /* Negate error number if it's valid */ - move v0,$0 /* Otherwise return 0 */ -1: - .set reorder - addu sp,4*6 - j ra -END(__futex_wake) - -// int __futex_syscall3(volatile void* ftx, int op, int count) -ENTRY(__futex_syscall3) - subu sp,4*6 - sw $0,20(sp) /* val3 */ - sw $0,16(sp) /* addr2 */ - move a3,$0 /* timespec */ -# move a2,a2 /* val */ -# li a1,a1 /* op */ -# move a0,a0 /* ftx */ - li v0,__NR_futex - syscall - .set noreorder - bnez a3, 1f /* Check for error */ - neg v0 /* Negate error number if it's valid */ - move v0,$0 /* Otherwise return 0 */ -1: - .set reorder - addu sp,4*6 - j ra -END(__futex_syscall3) - // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) -ENTRY(__futex_syscall4) +ENTRY_PRIVATE(__futex_syscall4) subu sp,4*6 sw $0,20(sp) /* val3 */ sw $0,16(sp) /* addr2 */ diff --git a/libc/arch-mips64/bionic/futex_mips.S b/libc/arch-mips64/bionic/futex_mips.S index 81f2f228d..60c218c26 100644 --- a/libc/arch-mips64/bionic/futex_mips.S +++ b/libc/arch-mips64/bionic/futex_mips.S @@ -28,9 +28,6 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) FRAMESZ = MKFSIZ(NARGSAVE+2,0) FRAME_A4 = 4*REGSZ @@ -39,84 +36,6 @@ FRAME_A5 = 5*REGSZ FRAMESZ = 0 #endif -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -LEAF(__futex_wait, FRAMESZ) -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_SUBU sp, FRAMESZ - REG_S $0,FRAME_A5(sp) /* val3 */ - REG_S $0,FRAME_A4(sp) /* addr2 */ -#else - move a5,$0 /* val3 */ - move a4,$0 /* addr2 */ -#endif - move a3,a2 /* timespec */ - move a2,a1 /* val */ - LI a1,FUTEX_WAIT /* op */ -# move a0,a0 /* ftx */ - LI v0,__NR_futex - syscall - neg v0 /* Negate errno */ - bnez a3,1f /* Check for error */ - move v0,$0 /* Return 0 if no error */ -1: -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_ADDU sp,FRAMESZ -#endif - j ra - END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -LEAF(__futex_wake,FRAMESZ) -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_SUBU sp, FRAMESZ - REG_S $0,FRAME_A5(sp) /* val3 */ - REG_S $0,FRAME_A4(sp) /* addr2 */ -#else - move a5,$0 /* val3 */ - move a4,$0 /* addr2 */ -#endif - move a3,$0 /* timespec */ - move a2,a1 /* val */ - LI a1,FUTEX_WAKE /* op */ -# move a0,a0 /* ftx */ - LI v0,__NR_futex - syscall - neg v0 /* Negate errno */ - bnez a3,1f /* Check for error */ - move v0,$0 /* Return 0 if no error */ -1: -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_ADDU sp,FRAMESZ -#endif - j ra - END(__futex_wake) - -// int __futex_syscall3(volatile void* ftx, int op, int count) -LEAF(__futex_syscall3,FRAMESZ) -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_SUBU sp, FRAMESZ - REG_S $0,FRAME_A5(sp) /* val3 */ - REG_S $0,FRAME_A4(sp) /* addr2 */ -#else - move a5,$0 /* val3 */ - move a4,$0 /* addr2 */ -#endif - move a3,$0 /* timespec */ -# move a2,a2 /* val */ -# move a1,a1 /* op */ -# move a0,a0 /* ftx */ - LI v0,__NR_futex - syscall - neg v0 /* Negate errno */ - bnez a3,1f /* Check for error */ - move v0,$0 /* Return 0 if no error */ -1: -#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) - PTR_ADDU sp,FRAMESZ -#endif - j ra - END(__futex_syscall3) - // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) LEAF(__futex_syscall4,FRAMESZ) #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) @@ -142,3 +61,4 @@ LEAF(__futex_syscall4,FRAMESZ) #endif j ra END(__futex_syscall4) +.hidden __futex_syscall4 diff --git a/libc/arch-x86/bionic/futex_x86.S b/libc/arch-x86/bionic/futex_x86.S index 8dd2ad018..94647cabd 100644 --- a/libc/arch-x86/bionic/futex_x86.S +++ b/libc/arch-x86/bionic/futex_x86.S @@ -1,49 +1,7 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -ENTRY(__futex_wait) - pushl %ebx - pushl %esi - mov 12(%esp), %ebx /* ftx */ - movl $FUTEX_WAIT, %ecx - mov 16(%esp), %edx /* val */ - mov 20(%esp), %esi /* timeout */ - movl $__NR_futex, %eax - int $0x80 - popl %esi - popl %ebx - ret -END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -ENTRY(__futex_wake) - pushl %ebx - mov 8(%esp), %ebx /* ftx */ - movl $FUTEX_WAKE, %ecx - mov 12(%esp), %edx /* count */ - movl $__NR_futex, %eax - int $0x80 - popl %ebx - ret -END(__futex_wake) - -// int __futex_syscall3(volatile void* ftx, int op, int count) -ENTRY(__futex_syscall3) - pushl %ebx - movl 8(%esp), %ebx /* ftx */ - movl 12(%esp), %ecx /* op */ - movl 16(%esp), %edx /* value */ - movl $__NR_futex, %eax - int $0x80 - popl %ebx - ret -END(__futex_syscall3) - // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout) -ENTRY(__futex_syscall4) +ENTRY_PRIVATE(__futex_syscall4) pushl %ebx pushl %esi movl 12(%esp), %ebx /* ftx */ diff --git a/libc/arch-x86_64/bionic/futex_x86_64.S b/libc/arch-x86_64/bionic/futex_x86_64.S index 25cdf1bb5..c24843930 100644 --- a/libc/arch-x86_64/bionic/futex_x86_64.S +++ b/libc/arch-x86_64/bionic/futex_x86_64.S @@ -28,37 +28,8 @@ #include -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 - -// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout) -ENTRY_PRIVATE(__futex_wait) - mov %rdx, %r10 /* timeout */ - mov %esi, %edx /* val */ - mov $FUTEX_WAIT, %esi /* op */ - mov $__NR_futex, %eax - syscall - ret -END(__futex_wait) - -// int __futex_wake(volatile void* ftx, int count) -ENTRY_PRIVATE(__futex_wake) - mov %esi, %edx - mov $FUTEX_WAKE, %esi - mov $__NR_futex, %eax - syscall - ret -END(__futex_wake) - -// 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) -ENTRY(__futex_syscall4) +ENTRY_PRIVATE(__futex_syscall4) mov %rcx, %r10 /* timeout */ mov $__NR_futex, %eax syscall diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp index baa95d902..8c5d9c7e9 100644 --- a/libc/bionic/pthread_internals.cpp +++ b/libc/bionic/pthread_internals.cpp @@ -88,11 +88,3 @@ int __timespec_from_absolute(timespec* ts, const timespec* abstime, clockid_t cl } return 0; } - -int __futex_wake_ex(volatile void* ftx, int pshared, int val) { - return __futex_syscall3(ftx, pshared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, val); -} - -int __futex_wait_ex(volatile void* ftx, int pshared, int val, const timespec* timeout) { - return __futex_syscall4(ftx, pshared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, val, timeout); -} diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp index 97e1a03f4..761858617 100644 --- a/libc/bionic/system_properties.cpp +++ b/libc/bionic/system_properties.cpp @@ -51,9 +51,8 @@ #include #include -#include - #include "private/bionic_atomic_inline.h" +#include "private/bionic_futex.h" #include "private/bionic_macros.h" #define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) diff --git a/libc/bionic/system_properties_compat.c b/libc/bionic/system_properties_compat.c index b4c249465..6aeaa0c37 100644 --- a/libc/bionic/system_properties_compat.c +++ b/libc/bionic/system_properties_compat.c @@ -35,7 +35,8 @@ */ #include -#include + +#include "private/bionic_futex.h" #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include @@ -67,7 +68,7 @@ typedef struct prop_info_compat prop_info_compat; extern prop_area *__system_property_area__; -const prop_info *__system_property_find_compat(const char *name) +__LIBC_HIDDEN__ const prop_info *__system_property_find_compat(const char *name) { prop_area_compat *pa = (prop_area_compat *)__system_property_area__; unsigned count = pa->count; @@ -93,7 +94,7 @@ const prop_info *__system_property_find_compat(const char *name) return 0; } -int __system_property_read_compat(const prop_info *_pi, char *name, char *value) +__LIBC_HIDDEN__ int __system_property_read_compat(const prop_info *_pi, char *name, char *value) { unsigned serial, len; const prop_info_compat *pi = (const prop_info_compat *)_pi; @@ -115,7 +116,7 @@ int __system_property_read_compat(const prop_info *_pi, char *name, char *value) } } -int __system_property_foreach_compat( +__LIBC_HIDDEN__ int __system_property_foreach_compat( void (*propfn)(const prop_info *pi, void *cookie), void *cookie) { diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h index 143bc4bc2..dfb5d5e5d 100644 --- a/libc/include/sys/atomics.h +++ b/libc/include/sys/atomics.h @@ -75,10 +75,6 @@ __atomic_inc(volatile int *ptr) return __sync_fetch_and_add (ptr, 1); } - -int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout); -int __futex_wake(volatile void *ftx, int count); - __END_DECLS #endif /* _SYS_ATOMICS_H */ diff --git a/libc/private/bionic_futex.h b/libc/private/bionic_futex.h index d01b8596d..11699cea6 100644 --- a/libc/private/bionic_futex.h +++ b/libc/private/bionic_futex.h @@ -30,20 +30,30 @@ #include #include +#include +#include __BEGIN_DECLS -extern int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout); -extern int __futex_wake(volatile void *ftx, int count); +struct timespec; -extern int __futex_syscall3(volatile void *ftx, int op, int val); -extern int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout); +extern int __futex_syscall4(volatile void* ftx, int op, int value, const struct timespec* timeout); -/* Like __futex_wait/wake, but take an additional 'pshared' argument. - * when non-0, this will use normal futexes. Otherwise, private futexes. - */ -__LIBC_HIDDEN__ int __futex_wake_ex(volatile void* ftx, int pshared, int val); -__LIBC_HIDDEN__ int __futex_wait_ex(volatile void* ftx, int pshared, int val, const struct timespec* timeout); +static inline int __futex_wake(volatile void* ftx, int count) { + return __futex_syscall4(ftx, FUTEX_WAKE, count, NULL); +} + +static inline int __futex_wake_ex(volatile void* ftx, bool shared, int count) { + return __futex_syscall4(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, NULL); +} + +static inline int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) { + return __futex_syscall4(ftx, FUTEX_WAIT, value, timeout); +} + +static inline int __futex_wait_ex(volatile void* ftx, bool shared, int value, const struct timespec* timeout) { + return __futex_syscall4(ftx, shared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, value, timeout); +} __END_DECLS