From 8f2a30a92ab6981cccbc1a9e17b738f7542ae33f Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 26 Mar 2014 15:50:01 +0200 Subject: [PATCH] Add accept4() syscall Add accept4() using SYSCALLS.TXT and gensyscall Change-Id: I6f19f29144186d15d46423e10f2cc4b4223719c6 --- libc/SYSCALLS.TXT | 2 ++ libc/arch-arm/syscalls/accept4.S | 14 ++++++++++++++ libc/arch-arm64/syscalls/accept4.S | 21 +++++++++++++++++++++ libc/arch-mips/syscalls/accept4.S | 19 +++++++++++++++++++ libc/arch-mips64/syscalls/accept4.S | 25 +++++++++++++++++++++++++ libc/arch-x86/syscalls/accept4.S | 27 +++++++++++++++++++++++++++ libc/arch-x86_64/syscalls/accept4.S | 17 +++++++++++++++++ libc/include/sys/socket.h | 1 + libc/include/sys/socketcalls.h | 1 + 9 files changed, 127 insertions(+) create mode 100644 libc/arch-arm/syscalls/accept4.S create mode 100644 libc/arch-arm64/syscalls/accept4.S create mode 100644 libc/arch-mips/syscalls/accept4.S create mode 100644 libc/arch-mips64/syscalls/accept4.S create mode 100644 libc/arch-x86/syscalls/accept4.S create mode 100644 libc/arch-x86_64/syscalls/accept4.S diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 8d4b258f6..e597b2f52 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -238,6 +238,7 @@ int bind(int, struct sockaddr*, int) arm,arm64,mips,mips64,x86_64 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 setsockopt:socketcall:14(int, int, int, const void*, socklen_t) x 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 000000000..6d14e7947 --- /dev/null +++ b/libc/arch-arm/syscalls/accept4.S @@ -0,0 +1,14 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 000000000..3c9227f6d --- /dev/null +++ b/libc/arch-arm64/syscalls/accept4.S @@ -0,0 +1,21 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 000000000..ea1dc6005 --- /dev/null +++ b/libc/arch-mips/syscalls/accept4.S @@ -0,0 +1,19 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 000000000..8b5cadb16 --- /dev/null +++ b/libc/arch-mips64/syscalls/accept4.S @@ -0,0 +1,25 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 000000000..dc3c1f5c5 --- /dev/null +++ b/libc/arch-x86/syscalls/accept4.S @@ -0,0 +1,27 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 000000000..d66d9529e --- /dev/null +++ b/libc/arch-x86_64/syscalls/accept4.S @@ -0,0 +1,17 @@ +/* Generated by gensyscalls.py. Do not edit. */ + +#include + +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 62a5300ce..0cddcd97a 100644 --- a/libc/include/sys/socket.h +++ b/libc/include/sys/socket.h @@ -302,6 +302,7 @@ __socketcall int setsockopt(int, int, int, const void*, socklen_t); __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 c74f463e8..09c079f66 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_ */