Add accept4() syscall

Add accept4() using SYSCALLS.TXT and gensyscall

Change-Id: I6f19f29144186d15d46423e10f2cc4b4223719c6
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 8d4b258..e597b2f 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -238,6 +238,7 @@
 int           connect(int, struct sockaddr*, socklen_t)   arm,arm64,mips,mips64,x86_64
 int           listen(int, int)                   arm,arm64,mips,mips64,x86_64
 int           accept(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
+int           accept4(int, struct sockaddr*, socklen_t*, int)  arm,arm64,mips,mips64,x86_64
 int           getsockname(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
 int           getpeername(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
 int           sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  arm,arm64,mips,mips64,x86_64
@@ -266,6 +267,7 @@
 int           getsockopt:socketcall:15(int, int, int, void*, socklen_t*)    x86
 int           sendmsg:socketcall:16(int, const struct msghdr*, unsigned int)  x86
 int           recvmsg:socketcall:17(int, struct msghdr*, unsigned int)   x86
+int           accept4:socketcall:18(int, struct sockaddr*, socklen_t*, int)  x86
 int           recvmmsg:socketcall:19(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   x86
 int           sendmmsg:socketcall:20(int, struct mmsghdr*, unsigned int, int)   x86
 
diff --git a/libc/arch-arm/syscalls/accept4.S b/libc/arch-arm/syscalls/accept4.S
new file mode 100644
index 0000000..6d14e79
--- /dev/null
+++ b/libc/arch-arm/syscalls/accept4.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    mov     ip, r7
+    ldr     r7, =__NR_accept4
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno
+END(accept4)
diff --git a/libc/arch-arm64/syscalls/accept4.S b/libc/arch-arm64/syscalls/accept4.S
new file mode 100644
index 0000000..3c9227f
--- /dev/null
+++ b/libc/arch-arm64/syscalls/accept4.S
@@ -0,0 +1,21 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    stp     x29, x30, [sp, #-16]!
+    mov     x29,  sp
+    str     x8,       [sp, #-16]!
+
+    mov     x8, __NR_accept4
+    svc     #0
+
+    ldr     x8,       [sp], #16
+    ldp     x29, x30, [sp], #16
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(accept4)
diff --git a/libc/arch-mips/syscalls/accept4.S b/libc/arch-mips/syscalls/accept4.S
new file mode 100644
index 0000000..ea1dc60
--- /dev/null
+++ b/libc/arch-mips/syscalls/accept4.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_accept4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno
+    j t9
+    nop
+    .set reorder
+END(accept4)
diff --git a/libc/arch-mips64/syscalls/accept4.S b/libc/arch-mips64/syscalls/accept4.S
new file mode 100644
index 0000000..8b5cadb
--- /dev/null
+++ b/libc/arch-mips64/syscalls/accept4.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    .set push
+    .set noreorder
+    li v0, __NR_accept4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(accept4)
diff --git a/libc/arch-x86/syscalls/accept4.S b/libc/arch-x86/syscalls/accept4.S
new file mode 100644
index 0000000..dc3c1f5
--- /dev/null
+++ b/libc/arch-x86/syscalls/accept4.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    pushl   %ebx
+    pushl   %ecx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    .cfi_rel_offset ecx, 4
+    mov     $18, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno
+    addl    $4, %esp
+    orl     $-1, %eax
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(accept4)
diff --git a/libc/arch-x86_64/syscalls/accept4.S b/libc/arch-x86_64/syscalls/accept4.S
new file mode 100644
index 0000000..d66d952
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/accept4.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(accept4)
+    movq    %rcx, %r10
+    movl    $__NR_accept4, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno
+    orq     $-1, %rax
+1:
+    ret
+END(accept4)
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 62a5300..0cddcd9 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -302,6 +302,7 @@
 __socketcall int shutdown(int, int);
 __socketcall int socket(int, int, int);
 __socketcall int socketpair(int, int, int, int*);
+__socketcall int accept4(int, struct sockaddr*, socklen_t*, int);
 
 extern ssize_t send(int, const void*, size_t, int);
 extern ssize_t recv(int, void*, size_t, int);
diff --git a/libc/include/sys/socketcalls.h b/libc/include/sys/socketcalls.h
index c74f463..09c079f 100644
--- a/libc/include/sys/socketcalls.h
+++ b/libc/include/sys/socketcalls.h
@@ -47,5 +47,6 @@
 #define SYS_GETSOCKOPT  15              /* sys_getsockopt(2)            */
 #define SYS_SENDMSG     16              /* sys_sendmsg(2)               */
 #define SYS_RECVMSG     17              /* sys_recvmsg(2)               */
+#define SYS_ACCEPT4     18              /* sys_accept4(2)               */
 
 #endif /* _SYS_SOCKETCALLS_H_ */