From 8f0cd8aa22906c3e678738eeba20fc1a5c399b6c Mon Sep 17 00:00:00 2001 From: Sreeram Ramachandran Date: Tue, 13 May 2014 15:40:26 -0700 Subject: [PATCH] Mark sockets on accept(). (cherry picked from commit 58b1f3f6a30a660ad81637c2b50382c3d279243b) Change-Id: I5d09be413cf720fbed905f96313b007997ada76c --- libc/Android.mk | 1 + libc/SYSCALLS.TXT | 4 ++-- .../syscalls/{accept.S => __accept.S} | 4 ++-- .../syscalls/{accept.S => __accept.S} | 5 +++-- .../syscalls/{accept.S => __accept.S} | 4 ++-- .../syscalls/{accept.S => __accept.S} | 5 +++-- .../syscalls/{accept.S => __accept.S} | 4 ++-- .../syscalls/{accept.S => __accept.S} | 5 +++-- libc/bionic/NetdClient.cpp | 1 + libc/bionic/NetdClientDispatch.cpp | 4 +++- libc/bionic/accept.cpp | 22 +++++++++++++++++++ libc/private/NetdClient.h | 1 + 12 files changed, 45 insertions(+), 15 deletions(-) rename libc/arch-arm/syscalls/{accept.S => __accept.S} (89%) rename libc/arch-arm64/syscalls/{accept.S => __accept.S} (88%) rename libc/arch-mips/syscalls/{accept.S => __accept.S} (89%) rename libc/arch-mips64/syscalls/{accept.S => __accept.S} (87%) rename libc/arch-x86/syscalls/{accept.S => __accept.S} (94%) rename libc/arch-x86_64/syscalls/{accept.S => __accept.S} (85%) create mode 100644 libc/bionic/accept.cpp diff --git a/libc/Android.mk b/libc/Android.mk index ed7d055e7..817c76767 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -98,6 +98,7 @@ libc_common_src_files += \ libc_bionic_src_files := \ bionic/abort.cpp \ + bionic/accept.cpp \ bionic/access.cpp \ bionic/assert.cpp \ bionic/atof.cpp \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index e9fb57522..83feb65c7 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -236,7 +236,7 @@ int socketpair(int, int, int, int*) arm,arm64,mips,mips64,x86_64 int bind(int, struct sockaddr*, int) arm,arm64,mips,mips64,x86_64 int __connect: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 __accept: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 @@ -255,7 +255,7 @@ int socket:socketcall:1(int, int, int) x86 int bind:socketcall:2(int, struct sockaddr*, int) x86 int __connect:socketcall:3(int, struct sockaddr*, socklen_t) x86 int listen:socketcall:4(int, int) x86 -int accept:socketcall:5(int, struct sockaddr*, socklen_t*) x86 +int __accept:socketcall:5(int, struct sockaddr*, socklen_t*) x86 int getsockname:socketcall:6(int, struct sockaddr*, socklen_t*) x86 int getpeername:socketcall:7(int, struct sockaddr*, socklen_t*) x86 int socketpair:socketcall:8(int, int, int, int*) x86 diff --git a/libc/arch-arm/syscalls/accept.S b/libc/arch-arm/syscalls/__accept.S similarity index 89% rename from libc/arch-arm/syscalls/accept.S rename to libc/arch-arm/syscalls/__accept.S index e2a51f5db..bae11bcb7 100644 --- a/libc/arch-arm/syscalls/accept.S +++ b/libc/arch-arm/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) mov ip, r7 ldr r7, =__NR_accept swi #0 @@ -11,4 +11,4 @@ ENTRY(accept) bxls lr neg r0, r0 b __set_errno -END(accept) +END(__accept) diff --git a/libc/arch-arm64/syscalls/accept.S b/libc/arch-arm64/syscalls/__accept.S similarity index 88% rename from libc/arch-arm64/syscalls/accept.S rename to libc/arch-arm64/syscalls/__accept.S index dae6121f2..21b68bc6b 100644 --- a/libc/arch-arm64/syscalls/accept.S +++ b/libc/arch-arm64/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) stp x29, x30, [sp, #-16]! mov x29, sp str x8, [sp, #-16]! @@ -18,4 +18,5 @@ ENTRY(accept) b.hi __set_errno ret -END(accept) +END(__accept) +.hidden __accept diff --git a/libc/arch-mips/syscalls/accept.S b/libc/arch-mips/syscalls/__accept.S similarity index 89% rename from libc/arch-mips/syscalls/accept.S rename to libc/arch-mips/syscalls/__accept.S index 09496abdc..d8141feee 100644 --- a/libc/arch-mips/syscalls/accept.S +++ b/libc/arch-mips/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) .set noreorder .cpload t9 li v0, __NR_accept @@ -16,4 +16,4 @@ ENTRY(accept) j t9 nop .set reorder -END(accept) +END(__accept) diff --git a/libc/arch-mips64/syscalls/accept.S b/libc/arch-mips64/syscalls/__accept.S similarity index 87% rename from libc/arch-mips64/syscalls/accept.S rename to libc/arch-mips64/syscalls/__accept.S index 6c3855698..4404a6862 100644 --- a/libc/arch-mips64/syscalls/accept.S +++ b/libc/arch-mips64/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) .set push .set noreorder li v0, __NR_accept @@ -22,4 +22,5 @@ ENTRY(accept) j t9 move ra, t0 .set pop -END(accept) +END(__accept) +.hidden __accept diff --git a/libc/arch-x86/syscalls/accept.S b/libc/arch-x86/syscalls/__accept.S similarity index 94% rename from libc/arch-x86/syscalls/accept.S rename to libc/arch-x86/syscalls/__accept.S index f7e8a58eb..31cb35001 100644 --- a/libc/arch-x86/syscalls/accept.S +++ b/libc/arch-x86/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) pushl %ebx pushl %ecx .cfi_def_cfa_offset 8 @@ -24,4 +24,4 @@ ENTRY(accept) popl %ecx popl %ebx ret -END(accept) +END(__accept) diff --git a/libc/arch-x86_64/syscalls/accept.S b/libc/arch-x86_64/syscalls/__accept.S similarity index 85% rename from libc/arch-x86_64/syscalls/accept.S rename to libc/arch-x86_64/syscalls/__accept.S index 588fb8231..ff0f5e765 100644 --- a/libc/arch-x86_64/syscalls/accept.S +++ b/libc/arch-x86_64/syscalls/__accept.S @@ -2,7 +2,7 @@ #include -ENTRY(accept) +ENTRY(__accept) movl $__NR_accept, %eax syscall cmpq $-MAX_ERRNO, %rax @@ -13,4 +13,5 @@ ENTRY(accept) orq $-1, %rax 1: ret -END(accept) +END(__accept) +.hidden __accept diff --git a/libc/bionic/NetdClient.cpp b/libc/bionic/NetdClient.cpp index 6826ee8ee..72d90b7bb 100644 --- a/libc/bionic/NetdClient.cpp +++ b/libc/bionic/NetdClient.cpp @@ -40,6 +40,7 @@ static void netdClientInitImpl() { // default implementations of functions that it would've overridden. return; } + netdClientInitFunction(netdClientHandle, "netdClientInitAccept", &__netdClientDispatch.accept); netdClientInitFunction(netdClientHandle, "netdClientInitConnect", &__netdClientDispatch.connect); } diff --git a/libc/bionic/NetdClientDispatch.cpp b/libc/bionic/NetdClientDispatch.cpp index 31728d2fe..adfe16d7f 100644 --- a/libc/bionic/NetdClientDispatch.cpp +++ b/libc/bionic/NetdClientDispatch.cpp @@ -22,8 +22,10 @@ #define __socketcall #endif +extern "C" __socketcall int __accept(int, sockaddr*, socklen_t*); extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t); NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = { - __connect + __accept, + __connect, }; diff --git a/libc/bionic/accept.cpp b/libc/bionic/accept.cpp new file mode 100644 index 000000000..46b4efc65 --- /dev/null +++ b/libc/bionic/accept.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +int accept(int sockfd, sockaddr* addr, socklen_t* addrlen) { + return __netdClientDispatch.accept(sockfd, addr, addrlen); +} diff --git a/libc/private/NetdClient.h b/libc/private/NetdClient.h index 48c05cb9d..b2ce7a664 100644 --- a/libc/private/NetdClient.h +++ b/libc/private/NetdClient.h @@ -20,6 +20,7 @@ #include struct NetdClientDispatch { + int (*accept)(int, sockaddr*, socklen_t*); int (*connect)(int, const sockaddr*, socklen_t); };