From 1f5af926fa626734981d6b4dcc0ab54e520032a9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 15 Oct 2013 18:01:56 -0700 Subject: [PATCH] Fix sigsuspend to use rt_sigsuspend on all platforms. Change-Id: I981c1a66d35480d4457a0a08a1b042dac94daa5b --- libc/Android.mk | 2 +- libc/SYSCALLS.TXT | 14 +++--- libc/arch-arm/syscalls.mk | 4 +- .../{__sigsuspend.S => __rt_sigsuspend.S} | 6 +-- libc/arch-mips/syscalls.mk | 4 +- .../{__sigsuspend.S => __rt_sigsuspend.S} | 10 ++--- libc/arch-x86/syscalls.mk | 4 +- .../{__sigsuspend.S => __rt_sigsuspend.S} | 13 +++--- libc/arch-x86_64/syscalls.mk | 2 +- libc/arch-x86_64/x86_64.mk | 1 - libc/bionic/signalfd.cpp | 2 +- libc/bionic/sigsuspend.c | 43 ------------------- .../sigsuspend.c => bionic/sigsuspend.cpp} | 11 +++-- libc/bionic/sigwait.cpp | 2 +- tests/signal_test.cpp | 33 ++++++++++++++ 15 files changed, 69 insertions(+), 82 deletions(-) rename libc/arch-arm/syscalls/{__sigsuspend.S => __rt_sigsuspend.S} (76%) rename libc/arch-mips/syscalls/{__sigsuspend.S => __rt_sigsuspend.S} (66%) rename libc/arch-x86/syscalls/{__sigsuspend.S => __rt_sigsuspend.S} (65%) delete mode 100644 libc/bionic/sigsuspend.c rename libc/{arch-x86_64/bionic/sigsuspend.c => bionic/sigsuspend.cpp} (82%) diff --git a/libc/Android.mk b/libc/Android.mk index b9db2017b..88be78dc2 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -184,7 +184,6 @@ libc_common_src_files += \ bionic/fstatfs.c \ bionic/__get_tls.cpp \ bionic/lseek64.c \ - bionic/sigsuspend.c \ bionic/statfs.c \ endif @@ -248,6 +247,7 @@ libc_bionic_src_files := \ bionic/setlocale.cpp \ bionic/signalfd.cpp \ bionic/sigprocmask.cpp \ + bionic/sigsuspend.cpp \ bionic/sigwait.cpp \ bionic/statvfs.cpp \ bionic/strerror.cpp \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index cea187818..0d1e808b3 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -233,14 +233,12 @@ int timerfd_gettime(int, struct itimerspec*) all # signals int sigaction(int, const struct sigaction*, struct sigaction*) arm,x86,mips -int __sigsuspend:sigsuspend(int unused1, int unused2, unsigned mask) arm,x86 -int __sigsuspend:sigsuspend(const sigset_t* mask) mips -int __rt_sigsuspend:rt_sigsuspend(const sigset_t *unewset, size_t sigset_size) x86_64 -int __rt_sigaction:rt_sigaction(int sig, const struct sigaction* act, struct sigaction* oact, size_t sigsetsize) all -int __rt_sigprocmask:rt_sigprocmask(int how, const sigset_t* set, sigset_t* oset, size_t sigsetsize) all -int __rt_sigtimedwait:rt_sigtimedwait(const sigset_t* set, struct siginfo_t* info, struct timespec_t* timeout, size_t sigset_size) all int sigpending(sigset_t*) arm,x86,mips -int signalfd4(int fd, const sigset_t* mask, size_t sizemask, int flags) all +int __rt_sigaction:rt_sigaction(int, const struct sigaction*, struct sigaction*, size_t) all +int __rt_sigprocmask:rt_sigprocmask(int, const sigset_t*, sigset_t*, size_t) all +int __rt_sigsuspend:rt_sigsuspend(const sigset_t*, size_t) all +int __rt_sigtimedwait:rt_sigtimedwait(const sigset_t*, struct siginfo_t*, struct timespec_t*, size_t) all +int signalfd4(int, const sigset_t*, size_t, int) all # sockets int socket(int, int, int) arm,mips,x86_64 @@ -296,7 +294,7 @@ int ioprio_get(int which, int who) all # other int uname(struct utsname*) all mode_t umask(mode_t) all -int __reboot:reboot(int, int, int, void*) all +int __reboot:reboot(int, int, int, void*) all int __syslog:syslog(int, char*, int) all int init_module(void*, unsigned long, const char*) all int delete_module(const char*, unsigned int) all diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index 3a66c1b91..dc7e3dfdb 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -152,11 +152,11 @@ syscall_src += arch-arm/syscalls/timerfd_create.S syscall_src += arch-arm/syscalls/timerfd_settime.S syscall_src += arch-arm/syscalls/timerfd_gettime.S syscall_src += arch-arm/syscalls/sigaction.S -syscall_src += arch-arm/syscalls/__sigsuspend.S +syscall_src += arch-arm/syscalls/sigpending.S syscall_src += arch-arm/syscalls/__rt_sigaction.S syscall_src += arch-arm/syscalls/__rt_sigprocmask.S +syscall_src += arch-arm/syscalls/__rt_sigsuspend.S syscall_src += arch-arm/syscalls/__rt_sigtimedwait.S -syscall_src += arch-arm/syscalls/sigpending.S syscall_src += arch-arm/syscalls/signalfd4.S syscall_src += arch-arm/syscalls/socket.S syscall_src += arch-arm/syscalls/socketpair.S diff --git a/libc/arch-arm/syscalls/__sigsuspend.S b/libc/arch-arm/syscalls/__rt_sigsuspend.S similarity index 76% rename from libc/arch-arm/syscalls/__sigsuspend.S rename to libc/arch-arm/syscalls/__rt_sigsuspend.S index dc519d281..2e63e8995 100644 --- a/libc/arch-arm/syscalls/__sigsuspend.S +++ b/libc/arch-arm/syscalls/__rt_sigsuspend.S @@ -3,13 +3,13 @@ #include #include -ENTRY(__sigsuspend) +ENTRY(__rt_sigsuspend) mov ip, r7 - ldr r7, =__NR_sigsuspend + ldr r7, =__NR_rt_sigsuspend swi #0 mov r7, ip cmn r0, #(MAX_ERRNO + 1) bxls lr neg r0, r0 b __set_errno -END(__sigsuspend) +END(__rt_sigsuspend) diff --git a/libc/arch-mips/syscalls.mk b/libc/arch-mips/syscalls.mk index 740f91c49..2704200ea 100644 --- a/libc/arch-mips/syscalls.mk +++ b/libc/arch-mips/syscalls.mk @@ -155,11 +155,11 @@ syscall_src += arch-mips/syscalls/timerfd_create.S syscall_src += arch-mips/syscalls/timerfd_settime.S syscall_src += arch-mips/syscalls/timerfd_gettime.S syscall_src += arch-mips/syscalls/sigaction.S -syscall_src += arch-mips/syscalls/__sigsuspend.S +syscall_src += arch-mips/syscalls/sigpending.S syscall_src += arch-mips/syscalls/__rt_sigaction.S syscall_src += arch-mips/syscalls/__rt_sigprocmask.S +syscall_src += arch-mips/syscalls/__rt_sigsuspend.S syscall_src += arch-mips/syscalls/__rt_sigtimedwait.S -syscall_src += arch-mips/syscalls/sigpending.S syscall_src += arch-mips/syscalls/signalfd4.S syscall_src += arch-mips/syscalls/socket.S syscall_src += arch-mips/syscalls/socketpair.S diff --git a/libc/arch-mips/syscalls/__sigsuspend.S b/libc/arch-mips/syscalls/__rt_sigsuspend.S similarity index 66% rename from libc/arch-mips/syscalls/__sigsuspend.S rename to libc/arch-mips/syscalls/__rt_sigsuspend.S index 2b6f6d7ed..a1a3fcea7 100644 --- a/libc/arch-mips/syscalls/__sigsuspend.S +++ b/libc/arch-mips/syscalls/__rt_sigsuspend.S @@ -1,14 +1,14 @@ /* autogenerated by gensyscalls.py */ #include .text - .globl __sigsuspend + .globl __rt_sigsuspend .align 4 - .ent __sigsuspend + .ent __rt_sigsuspend -__sigsuspend: +__rt_sigsuspend: .set noreorder .cpload $t9 - li $v0, __NR_sigsuspend + li $v0, __NR_rt_sigsuspend syscall bnez $a3, 1f move $a0, $v0 @@ -19,4 +19,4 @@ __sigsuspend: j $t9 nop .set reorder - .end __sigsuspend + .end __rt_sigsuspend diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index a704905bf..10970a6f5 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -156,11 +156,11 @@ syscall_src += arch-x86/syscalls/timerfd_create.S syscall_src += arch-x86/syscalls/timerfd_settime.S syscall_src += arch-x86/syscalls/timerfd_gettime.S syscall_src += arch-x86/syscalls/sigaction.S -syscall_src += arch-x86/syscalls/__sigsuspend.S +syscall_src += arch-x86/syscalls/sigpending.S syscall_src += arch-x86/syscalls/__rt_sigaction.S syscall_src += arch-x86/syscalls/__rt_sigprocmask.S +syscall_src += arch-x86/syscalls/__rt_sigsuspend.S syscall_src += arch-x86/syscalls/__rt_sigtimedwait.S -syscall_src += arch-x86/syscalls/sigpending.S syscall_src += arch-x86/syscalls/signalfd4.S syscall_src += arch-x86/syscalls/socket.S syscall_src += arch-x86/syscalls/bind.S diff --git a/libc/arch-x86/syscalls/__sigsuspend.S b/libc/arch-x86/syscalls/__rt_sigsuspend.S similarity index 65% rename from libc/arch-x86/syscalls/__sigsuspend.S rename to libc/arch-x86/syscalls/__rt_sigsuspend.S index 6a5c6aacb..32b213470 100644 --- a/libc/arch-x86/syscalls/__sigsuspend.S +++ b/libc/arch-x86/syscalls/__rt_sigsuspend.S @@ -3,14 +3,12 @@ #include #include -ENTRY(__sigsuspend) +ENTRY(__rt_sigsuspend) pushl %ebx pushl %ecx - pushl %edx - mov 16(%esp), %ebx - mov 20(%esp), %ecx - mov 24(%esp), %edx - movl $__NR_sigsuspend, %eax + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_rt_sigsuspend, %eax int $0x80 cmpl $-MAX_ERRNO, %eax jb 1f @@ -20,8 +18,7 @@ ENTRY(__sigsuspend) addl $4, %esp orl $-1, %eax 1: - popl %edx popl %ecx popl %ebx ret -END(__sigsuspend) +END(__rt_sigsuspend) diff --git a/libc/arch-x86_64/syscalls.mk b/libc/arch-x86_64/syscalls.mk index 51c3646cb..6b72ca0b1 100644 --- a/libc/arch-x86_64/syscalls.mk +++ b/libc/arch-x86_64/syscalls.mk @@ -149,9 +149,9 @@ syscall_src += arch-x86_64/syscalls/utimensat.S syscall_src += arch-x86_64/syscalls/timerfd_create.S syscall_src += arch-x86_64/syscalls/timerfd_settime.S syscall_src += arch-x86_64/syscalls/timerfd_gettime.S -syscall_src += arch-x86_64/syscalls/__rt_sigsuspend.S syscall_src += arch-x86_64/syscalls/__rt_sigaction.S syscall_src += arch-x86_64/syscalls/__rt_sigprocmask.S +syscall_src += arch-x86_64/syscalls/__rt_sigsuspend.S syscall_src += arch-x86_64/syscalls/__rt_sigtimedwait.S syscall_src += arch-x86_64/syscalls/signalfd4.S syscall_src += arch-x86_64/syscalls/socket.S diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk index f293b2dbd..13442c7cc 100644 --- a/libc/arch-x86_64/x86_64.mk +++ b/libc/arch-x86_64/x86_64.mk @@ -9,7 +9,6 @@ _LIBC_ARCH_COMMON_SRC_FILES := \ arch-x86_64/bionic/__set_tls.c \ arch-x86_64/bionic/sigaction.c \ arch-x86_64/bionic/sigsetjmp.S \ - arch-x86_64/bionic/sigsuspend.c \ arch-x86_64/bionic/syscall.S \ _LIBC_ARCH_STATIC_SRC_FILES := \ diff --git a/libc/bionic/signalfd.cpp b/libc/bionic/signalfd.cpp index b7e647412..36ef81db0 100644 --- a/libc/bionic/signalfd.cpp +++ b/libc/bionic/signalfd.cpp @@ -28,7 +28,7 @@ #include -#include +#include "private/kernel_sigset_t.h" extern "C" int signalfd4(int fd, kernel_sigset_t* mask, size_t sizemask, int flags); diff --git a/libc/bionic/sigsuspend.c b/libc/bionic/sigsuspend.c deleted file mode 100644 index fd0863167..000000000 --- a/libc/bionic/sigsuspend.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include -#ifdef __mips__ -extern int __sigsuspend(const sigset_t *); -#else -extern int __sigsuspend(int, int, unsigned int); -#endif - -int sigsuspend(const sigset_t *_mask) -{ -#ifdef __mips__ - return __sigsuspend(_mask); -#else - unsigned int mask = (unsigned int)*_mask; - return __sigsuspend(0, 0, mask); -#endif -} diff --git a/libc/arch-x86_64/bionic/sigsuspend.c b/libc/bionic/sigsuspend.cpp similarity index 82% rename from libc/arch-x86_64/bionic/sigsuspend.c rename to libc/bionic/sigsuspend.cpp index 40bfaeaea..fb846b83e 100644 --- a/libc/arch-x86_64/bionic/sigsuspend.c +++ b/libc/bionic/sigsuspend.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,8 +28,11 @@ #include -extern int __rt_sigsuspend(const sigset_t*, size_t); +#include "private/kernel_sigset_t.h" -int sigsuspend(const sigset_t* set) { - return __rt_sigsuspend(set, sizeof(sigset_t)); +extern "C" int __rt_sigsuspend(const kernel_sigset_t*, size_t); + +int sigsuspend(const sigset_t* bionic_set) { + kernel_sigset_t set(bionic_set); + return __rt_sigsuspend(&set, sizeof(set)); } diff --git a/libc/bionic/sigwait.cpp b/libc/bionic/sigwait.cpp index 1546fd6e9..873a36808 100644 --- a/libc/bionic/sigwait.cpp +++ b/libc/bionic/sigwait.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include "private/kernel_sigset_t.h" extern "C" int __rt_sigtimedwait(const sigset_t* uthese, siginfo_t* uinfo, const struct timespec* uts, size_t sigsetsize); diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp index e41dc1cb5..70e9017cd 100644 --- a/tests/signal_test.cpp +++ b/tests/signal_test.cpp @@ -153,3 +153,36 @@ TEST(signal, sigwait) { ASSERT_EQ(0, errno); ASSERT_EQ(SIGALRM, received_signal); } + +static int gSigSuspendTestHelperCallCount = 0; + +static void SigSuspendTestHelper(int) { + ++gSigSuspendTestHelperCallCount; +} + +TEST(signal, sigsuspend) { + ScopedSignalHandler ssh(SIGALRM, SigSuspendTestHelper); + + // Block SIGALRM. + sigset_t just_SIGALRM; + sigemptyset(&just_SIGALRM); + sigaddset(&just_SIGALRM, SIGALRM); + sigset_t original_set; + ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); + + // Raise SIGALRM and check our signal handler wasn't called. + raise(SIGALRM); + ASSERT_EQ(0, gSigSuspendTestHelperCallCount); + + // Use sigsuspend to block everything except SIGALRM... + sigset_t not_SIGALRM; + sigfillset(¬_SIGALRM); + sigdelset(¬_SIGALRM, SIGALRM); + ASSERT_EQ(-1, sigsuspend(¬_SIGALRM)); + ASSERT_EQ(EINTR, errno); + // ...and check that we now receive our pending SIGALRM. + ASSERT_EQ(1, gSigSuspendTestHelperCallCount); + + // Restore the original set. + assert(0 == sigprocmask(SIG_SETMASK, &original_set, NULL)); +}