1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-12-24 17:51:17 +03:00

Refactor internal-signals.h

The main drive is to optimize the internal usage and required size
when sigset_t is embedded in other data structures.  On Linux, the
current supported signal set requires up to 8 bytes (16 on mips),
was lower than the user defined sigset_t (128 bytes).

A new internal type internal_sigset_t is added, along with the
functions to operate on it similar to the ones for sigset_t.  The
internal-signals.h is also refactored to remove unused functions

Besides small stack usage on some functions (posix_spawn, abort)
it lower the struct pthread by about 120 bytes (112 on mips).

Checked on x86_64-linux-gnu.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
This commit is contained in:
Adhemerval Zanella
2022-04-21 09:41:59 -03:00
parent c22d2021a9
commit a1bdd81664
18 changed files with 184 additions and 98 deletions

View File

@@ -19,10 +19,11 @@
#ifndef __INTERNAL_SIGNALS_H
# define __INTERNAL_SIGNALS_H
#include <internal-sigset.h>
#include <limits.h>
#include <signal.h>
#include <sigsetops.h>
#include <stdbool.h>
#include <limits.h>
#include <stddef.h>
#include <sysdep.h>
@@ -47,67 +48,63 @@
/* Return is sig is used internally. */
static inline bool
__is_internal_signal (int sig)
is_internal_signal (int sig)
{
return (sig == SIGCANCEL) || (sig == SIGSETXID);
}
/* Remove internal glibc signal from the mask. */
static inline void
__clear_internal_signals (sigset_t *set)
clear_internal_signals (sigset_t *set)
{
__sigdelset (set, SIGCANCEL);
__sigdelset (set, SIGSETXID);
}
static const sigset_t sigall_set = {
.__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 }
static const internal_sigset_t sigall_set = {
.__val = {[0 ... __NSIG_WORDS-1 ] = -1 }
};
static const sigset_t sigtimer_set = {
.__val = { [0] = __sigmask (SIGTIMER),
[1 ... _SIGSET_NWORDS-1] = 0 }
};
/* Obtain and change blocked signals, including internal glibc ones. */
static inline int
internal_sigprocmask (int how, const internal_sigset_t *set,
internal_sigset_t *oldset)
{
return INTERNAL_SYSCALL_CALL (rt_sigprocmask, how, set, oldset,
__NSIG_BYTES);
}
/* Block all signals, including internal glibc ones. */
static inline void
__libc_signal_block_all (sigset_t *set)
internal_signal_block_all (internal_sigset_t *oset)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigall_set, set,
__NSIG_BYTES);
}
/* Block all application signals (excluding internal glibc ones). */
static inline void
__libc_signal_block_app (sigset_t *set)
{
sigset_t allset = sigall_set;
__clear_internal_signals (&allset);
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &allset, set,
__NSIG_BYTES);
}
/* Block only SIGTIMER and return the previous set on SET. */
static inline void
__libc_signal_block_sigtimer (sigset_t *set)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigtimer_set, set,
__NSIG_BYTES);
}
/* Unblock only SIGTIMER and return the previous set on SET. */
static inline void
__libc_signal_unblock_sigtimer (sigset_t *set)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_UNBLOCK, &sigtimer_set, set,
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigall_set, oset,
__NSIG_BYTES);
}
/* Restore current process signal mask. */
static inline void
__libc_signal_restore_set (const sigset_t *set)
internal_signal_restore_set (const internal_sigset_t *set)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_SETMASK, set, NULL,
__NSIG_BYTES);
}
/* It is used on timer_create code directly on sigwaitinfo call, so it can not
use the internal_sigset_t definitions. */
static const sigset_t sigtimer_set = {
.__val = { [0] = __sigmask (SIGTIMER),
[1 ... _SIGSET_NWORDS-1] = 0
}
};
/* Unblock only SIGTIMER. */
static inline void
signal_unblock_sigtimer (void)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_UNBLOCK, &sigtimer_set, NULL,
__NSIG_BYTES);
}
#endif