From 0990d4fda898ada86e557f872f5cb7d16b138e3c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 30 Apr 2014 09:45:40 -0700 Subject: [PATCH] Make SIGRTMIN hide the real-time signals we use internally. __SIGRTMIN will continue to tell the truth. This matches glibc's behavior (as evidenced by the fact that we don't need a special case in the strsignal test now). Change-Id: I1abe1681d516577afa8cd39c837ef12467f68dd2 --- libc/Android.mk | 2 ++ libc/bionic/__libc_current_sigrtmax.cpp | 33 ++++++++++++++++++++++ libc/bionic/__libc_current_sigrtmin.cpp | 37 +++++++++++++++++++++++++ libc/bionic/posix_timers.cpp | 2 +- libc/include/signal.h | 6 ++++ libc/kernel/tools/defaults.py | 3 ++ libc/kernel/uapi/asm-arm/asm/signal.h | 4 +-- libc/kernel/uapi/asm-generic/signal.h | 4 +-- libc/kernel/uapi/asm-mips/asm/signal.h | 4 +-- libc/kernel/uapi/asm-x86/asm/signal.h | 4 +-- tests/signal_test.cpp | 18 ++++++++++++ tests/string_test.cpp | 8 ++---- 12 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 libc/bionic/__libc_current_sigrtmax.cpp create mode 100644 libc/bionic/__libc_current_sigrtmin.cpp diff --git a/libc/Android.mk b/libc/Android.mk index 0b70e07b2..a0eb6122b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -129,6 +129,8 @@ libc_bionic_src_files := \ bionic/inotify_init.cpp \ bionic/lchown.cpp \ bionic/lfs64_support.cpp \ + bionic/__libc_current_sigrtmax.cpp \ + bionic/__libc_current_sigrtmin.cpp \ bionic/libc_init_common.cpp \ bionic/libc_logging.cpp \ bionic/libgen.cpp \ diff --git a/libc/bionic/__libc_current_sigrtmax.cpp b/libc/bionic/__libc_current_sigrtmax.cpp new file mode 100644 index 000000000..27fcb351b --- /dev/null +++ b/libc/bionic/__libc_current_sigrtmax.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014 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 + +int __libc_current_sigrtmax(void) { + return __SIGRTMAX; +} diff --git a/libc/bionic/__libc_current_sigrtmin.cpp b/libc/bionic/__libc_current_sigrtmin.cpp new file mode 100644 index 000000000..16b037d1e --- /dev/null +++ b/libc/bionic/__libc_current_sigrtmin.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 + +// POSIX timers use __SIGRTMIN + 0. +// libbacktrace uses __SIGRTMIN + 1. +// libcore uses __SIGRTMIN + 2. + +int __libc_current_sigrtmin(void) { + return __SIGRTMIN + 3; +} diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp index 59933ec78..312bf9e59 100644 --- a/libc/bionic/posix_timers.cpp +++ b/libc/bionic/posix_timers.cpp @@ -52,7 +52,7 @@ extern "C" int __timer_settime(__kernel_timer_t, int, const itimerspec*, itimers // end up with one of our POSIX timer threads handling it (meaning that the intended recipient // doesn't). glibc uses SIGRTMIN for its POSIX timer implementation, so in the absence of any // reason to use anything else, we use that too. -static const int TIMER_SIGNAL = SIGRTMIN; +static const int TIMER_SIGNAL = (__SIGRTMIN + 0); struct PosixTimer { __kernel_timer_t kernel_timer_id; diff --git a/libc/include/signal.h b/libc/include/signal.h index 267f3e6be..45c1cdad7 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -60,6 +60,12 @@ typedef int sig_atomic_t; #define _NSIG (_KERNEL__NSIG + 1) #define NSIG _NSIG +/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */ +#define SIGRTMIN (__libc_current_sigrtmin()) +#define SIGRTMAX (__libc_current_sigrtmax()) +extern int __libc_current_sigrtmin(void); +extern int __libc_current_sigrtmax(void); + extern const char* const sys_siglist[]; extern const char* const sys_signame[]; /* BSD compatibility. */ diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py index b4d823e1d..8c41cc625 100644 --- a/libc/kernel/tools/defaults.py +++ b/libc/kernel/tools/defaults.py @@ -63,6 +63,9 @@ kernel_token_replacements = { # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside. "_NSIG": "_KERNEL__NSIG", "NSIG": "_KERNEL_NSIG", + # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few. + "SIGRTMIN": "__SIGRTMIN", + "SIGRTMAX": "__SIGRTMAX", } # this is the set of known static inline functions that we want to keep diff --git a/libc/kernel/uapi/asm-arm/asm/signal.h b/libc/kernel/uapi/asm-arm/asm/signal.h index 512e22a25..fd39aaa9a 100644 --- a/libc/kernel/uapi/asm-arm/asm/signal.h +++ b/libc/kernel/uapi/asm-arm/asm/signal.h @@ -66,8 +66,8 @@ typedef unsigned long sigset_t; #define SIGSYS 31 #define SIGUNUSED 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ -#define SIGRTMIN 32 -#define SIGRTMAX _KERNEL__NSIG +#define __SIGRTMIN 32 +#define __SIGRTMAX _KERNEL__NSIG #define SIGSWI 32 #define SA_NOCLDSTOP 0x00000001 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/libc/kernel/uapi/asm-generic/signal.h b/libc/kernel/uapi/asm-generic/signal.h index fe7d9a097..a16622a34 100644 --- a/libc/kernel/uapi/asm-generic/signal.h +++ b/libc/kernel/uapi/asm-generic/signal.h @@ -66,9 +66,9 @@ #define SIGSYS 31 #define SIGUNUSED 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ -#define SIGRTMIN 32 +#define __SIGRTMIN 32 #ifndef SIGRTMAX -#define SIGRTMAX _KERNEL__NSIG +#define __SIGRTMAX _KERNEL__NSIG #endif /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define SA_NOCLDSTOP 0x00000001 diff --git a/libc/kernel/uapi/asm-mips/asm/signal.h b/libc/kernel/uapi/asm-mips/asm/signal.h index 53f501513..b774a66f3 100644 --- a/libc/kernel/uapi/asm-mips/asm/signal.h +++ b/libc/kernel/uapi/asm-mips/asm/signal.h @@ -71,8 +71,8 @@ typedef unsigned long old_sigset_t; #define SIGXCPU 30 #define SIGXFSZ 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ -#define SIGRTMIN 32 -#define SIGRTMAX _KERNEL__NSIG +#define __SIGRTMIN 32 +#define __SIGRTMAX _KERNEL__NSIG #define SA_ONSTACK 0x08000000 #define SA_RESETHAND 0x80000000 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/libc/kernel/uapi/asm-x86/asm/signal.h b/libc/kernel/uapi/asm-x86/asm/signal.h index 6f5b4354d..308c7a934 100644 --- a/libc/kernel/uapi/asm-x86/asm/signal.h +++ b/libc/kernel/uapi/asm-x86/asm/signal.h @@ -71,8 +71,8 @@ typedef unsigned long sigset_t; #define SIGSYS 31 #define SIGUNUSED 31 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ -#define SIGRTMIN 32 -#define SIGRTMAX _KERNEL__NSIG +#define __SIGRTMIN 32 +#define __SIGRTMAX _KERNEL__NSIG #define SA_NOCLDSTOP 0x00000001u #define SA_NOCLDWAIT 0x00000002u /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp index 6d55bef24..af9896409 100644 --- a/tests/signal_test.cpp +++ b/tests/signal_test.cpp @@ -252,3 +252,21 @@ TEST(signal, sys_siglist) { ASSERT_TRUE(sys_siglist[0] == NULL); ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]); } + +TEST(signal, limits) { + // This comes from the kernel. + ASSERT_EQ(32, __SIGRTMIN); + + // We reserve a non-zero number at the bottom for ourselves. + ASSERT_GT(SIGRTMIN, __SIGRTMIN); + + // MIPS has more signals than everyone else. +#if defined(__mips__) + ASSERT_EQ(128, __SIGRTMAX); +#else + ASSERT_EQ(64, __SIGRTMAX); +#endif + + // We don't currently reserve any at the top. + ASSERT_EQ(SIGRTMAX, __SIGRTMAX); +} diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 14b284e2d..5ccc63d3a 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -100,11 +100,9 @@ TEST(string, strsignal) { ASSERT_STREQ("Hangup", strsignal(1)); // A real-time signal. -#ifdef __GLIBC__ // glibc reserves real-time signals for internal use, and doesn't count those. - ASSERT_STREQ("Real-time signal 14", strsignal(48)); -#else - ASSERT_STREQ("Real-time signal 16", strsignal(48)); -#endif + ASSERT_STREQ("Real-time signal 14", strsignal(SIGRTMIN + 14)); + // One of the signals the C library keeps to itself. + ASSERT_STREQ("Unknown signal 32", strsignal(__SIGRTMIN)); // Errors. ASSERT_STREQ("Unknown signal -1", strsignal(-1)); // Too small.