am 9fb53dd4: Merge "Make SIGRTMIN hide the real-time signals we use internally."

* commit '9fb53dd4dbaa7633c234d9da8417827fa3d3c32f':
  Make SIGRTMIN hide the real-time signals we use internally.
This commit is contained in:
Elliott Hughes 2014-04-30 18:32:28 +00:00 committed by Android Git Automerger
commit 4a41581af5
12 changed files with 111 additions and 14 deletions

View file

@ -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 \

View file

@ -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 <signal.h>
int __libc_current_sigrtmax(void) {
return __SIGRTMAX;
}

View file

@ -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 <signal.h>
// POSIX timers use __SIGRTMIN + 0.
// libbacktrace uses __SIGRTMIN + 1.
// libcore uses __SIGRTMIN + 2.
int __libc_current_sigrtmin(void) {
return __SIGRTMIN + 3;
}

View file

@ -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;

View file

@ -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. */

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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 */

View file

@ -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 */

View file

@ -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);
}

View file

@ -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.