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
diff --git a/libc/arch-arm/bionic/futex_arm.S b/libc/arch-arm/bionic/futex_arm.S
index 0aba278..89a1e96 100644
--- a/libc/arch-arm/bionic/futex_arm.S
+++ b/libc/arch-arm/bionic/futex_arm.S
@@ -28,42 +28,11 @@
 
 #include <private/bionic_asm.h>
 
-#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 00d24a4..9d7465a 100644
--- a/libc/arch-arm64/bionic/futex_arm64.S
+++ b/libc/arch-arm64/bionic/futex_arm64.S
@@ -28,11 +28,8 @@
 
 #include <private/bionic_asm.h>
 
-#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 @@
   .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 7626a7c..5a09f32 100644
--- a/libc/arch-mips/bionic/futex_mips.S
+++ b/libc/arch-mips/bionic/futex_mips.S
@@ -28,74 +28,8 @@
 
 #include <private/bionic_asm.h>
 
-#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 81f2f22..60c218c 100644
--- a/libc/arch-mips64/bionic/futex_mips.S
+++ b/libc/arch-mips64/bionic/futex_mips.S
@@ -28,9 +28,6 @@
 
 #include <private/bionic_asm.h>
 
-#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 @@
 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 @@
 #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 8dd2ad0..94647ca 100644
--- a/libc/arch-x86/bionic/futex_x86.S
+++ b/libc/arch-x86/bionic/futex_x86.S
@@ -1,49 +1,7 @@
 #include <private/bionic_asm.h>
 
-#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 25cdf1b..c248439 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 <private/bionic_asm.h>
 
-#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 baa95d9..8c5d9c7 100644
--- a/libc/bionic/pthread_internals.cpp
+++ b/libc/bionic/pthread_internals.cpp
@@ -88,11 +88,3 @@
   }
   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 97e1a03..7618586 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -51,9 +51,8 @@
 #include <sys/_system_properties.h>
 #include <sys/system_properties.h>
 
-#include <sys/atomics.h>
-
 #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 b4c2494..6aeaa0c 100644
--- a/libc/bionic/system_properties_compat.c
+++ b/libc/bionic/system_properties_compat.c
@@ -35,7 +35,8 @@
  */
 
 #include <string.h>
-#include <sys/atomics.h>
+
+#include "private/bionic_futex.h"
 
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #include <sys/_system_properties.h>
@@ -67,7 +68,7 @@
 
 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 @@
     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_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 143bc4b..dfb5d5e 100644
--- a/libc/include/sys/atomics.h
+++ b/libc/include/sys/atomics.h
@@ -75,10 +75,6 @@
   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 d01b859..11699ce 100644
--- a/libc/private/bionic_futex.h
+++ b/libc/private/bionic_futex.h
@@ -30,20 +30,30 @@
 
 #include <linux/futex.h>
 #include <sys/cdefs.h>
+#include <stdbool.h>
+#include <stddef.h>
 
 __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