signal: Add __libc_sigaction

The generic implementation basically handle the system agnostic logic
(filtering out the invalid signals) while the __libc_sigaction is
the function with implements the system and architecture bits.

Checked on x86_64-linux-gnu and i686-linux-gnu.
This commit is contained in:
Adhemerval Zanella 2021-03-15 15:23:40 -03:00
parent d5ddd583da
commit a894053318
14 changed files with 48 additions and 23 deletions

View File

@ -225,6 +225,7 @@ libpthread-routines = \
sem_unlink \ sem_unlink \
sem_wait \ sem_wait \
sigaction \ sigaction \
libc_sigaction \
tpp \ tpp \
unwind \ unwind \
unwind-forcedunwind \ unwind-forcedunwind \

View File

@ -35,7 +35,7 @@ headers := signal.h sys/signal.h \
bits/sigstksz.h bits/sigstksz.h
routines := signal raise killpg \ routines := signal raise killpg \
sigaction sigprocmask kill \ sigaction libc_sigaction sigprocmask kill \
sigpending sigsuspend sigwait \ sigpending sigsuspend sigwait \
sigblock sigsetmask sigpause sigvec \ sigblock sigsetmask sigpause sigvec \
sigstack sigaltstack sigintr \ sigstack sigaltstack sigintr \

32
signal/libc_sigaction.c Normal file
View File

@ -0,0 +1,32 @@
/* Internal sigaction definitions.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <signal.h>
/* If ACT is not NULL, change the action for SIG to *ACT.
If OACT is not NULL, put the old action for SIG in *OACT. */
int
__libc_sigaction (int sig, const struct sigaction *act,
struct sigaction *oact)
{
__set_errno (ENOSYS);
return -1;
}
stub_warning (libc_sigaction)
libc_hidden_def (__libc_sigaction)

View File

@ -17,7 +17,7 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <internal-signals.h>
/* If ACT is not NULL, change the action for SIG to *ACT. /* If ACT is not NULL, change the action for SIG to *ACT.
If OACT is not NULL, put the old action for SIG in *OACT. */ If OACT is not NULL, put the old action for SIG in *OACT. */
@ -30,10 +30,7 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
return -1; return -1;
} }
__set_errno (ENOSYS); return __libc_sigaction (sig, act, oact);
return -1;
} }
libc_hidden_def (__sigaction) libc_hidden_def (__sigaction)
stub_warning (sigaction)
weak_alias (__sigaction, sigaction) weak_alias (__sigaction, sigaction)

View File

@ -24,16 +24,15 @@
/* If ACT is not NULL, change the action for SIG to *ACT. /* If ACT is not NULL, change the action for SIG to *ACT.
If OACT is not NULL, put the old action for SIG in *OACT. */ If OACT is not NULL, put the old action for SIG in *OACT. */
int int
__sigaction (int sig, const struct sigaction *act, struct sigaction *oact) __libc_sigaction (int sig, const struct sigaction *act,
struct sigaction *oact)
{ {
struct hurd_sigstate *ss; struct hurd_sigstate *ss;
struct sigaction a, old; struct sigaction a, old;
sigset_t pending; sigset_t pending;
if (sig <= 0 || sig >= NSIG if (act != NULL && act->sa_handler != SIG_DFL
|| (act != NULL && act->sa_handler != SIG_DFL && ((__sigmask (sig) & _SIG_CANT_MASK) || act->sa_handler == SIG_ERR))
&& ((__sigmask (sig) & _SIG_CANT_MASK)
|| act->sa_handler == SIG_ERR)))
{ {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -87,5 +86,4 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
return 0; return 0;
} }
libc_hidden_def (__sigaction) libc_hidden_def (__libc_sigaction)
weak_alias (__sigaction, sigaction)

View File

@ -74,7 +74,6 @@ setsid - setsid i: __setsid setsid
setsockopt - setsockopt i:iiibn setsockopt __setsockopt setsockopt - setsockopt i:iiibn setsockopt __setsockopt
setuid - setuid i:i __setuid setuid setuid - setuid i:i __setuid setuid
shutdown - shutdown i:ii shutdown shutdown - shutdown i:ii shutdown
sigaction - sigaction i:ipp __sigaction sigaction
sigsuspend - sigsuspend Ci:p sigsuspend sigsuspend - sigsuspend Ci:p sigsuspend
socket - socket i:iii __socket socket socket - socket i:iii __socket socket
socketpair - socketpair i:iiif socketpair socketpair - socketpair i:iiif socketpair

View File

@ -27,4 +27,4 @@
#define RESET_SA_RESTORER(act, kact) \ #define RESET_SA_RESTORER(act, kact) \
(act)->sa_restorer = (kact)->sa_restorer; (act)->sa_restorer = (kact)->sa_restorer;
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>

View File

@ -28,4 +28,4 @@ extern void __default_rt_sa_restorer (void);
#define RESET_SA_RESTORER(act, kact) #define RESET_SA_RESTORER(act, kact)
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>

View File

@ -36,4 +36,4 @@ extern void __default_rt_sa_restorer (void);
#define RESET_SA_RESTORER(act, kact) \ #define RESET_SA_RESTORER(act, kact) \
(act)->sa_restorer = (kact)->sa_restorer; (act)->sa_restorer = (kact)->sa_restorer;
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>

View File

@ -39,7 +39,7 @@ extern void restore (void) asm ("__restore") attribute_hidden;
#define RESET_SA_RESTORER(act, kact) \ #define RESET_SA_RESTORER(act, kact) \
(act)->sa_restorer = (kact)->sa_restorer (act)->sa_restorer = (kact)->sa_restorer
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>
/* NOTE: Please think twice before making any changes to the bits of /* NOTE: Please think twice before making any changes to the bits of
code below. GDB needs some intimate knowledge about it to code below. GDB needs some intimate knowledge about it to

View File

@ -70,5 +70,3 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
return result; return result;
} }
libc_hidden_def (__libc_sigaction) libc_hidden_def (__libc_sigaction)
#include <nptl/sigaction.c>

View File

@ -34,4 +34,4 @@ void __sigreturn_stub (void);
: 0, \ : 0, \
(sigsetsize) (sigsetsize)
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>

View File

@ -29,4 +29,4 @@ void __rt_sigreturn_stub (void);
(((unsigned long) &__rt_sigreturn_stub) - 8), \ (((unsigned long) &__rt_sigreturn_stub) - 8), \
(sigsetsize) (sigsetsize)
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>

View File

@ -30,7 +30,7 @@ extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
#include <kernel_sigaction.h> #include <kernel_sigaction.h>
#include <sysdeps/unix/sysv/linux/sigaction.c> #include <sysdeps/unix/sysv/linux/libc_sigaction.c>
/* NOTE: Please think twice before making any changes to the bits of /* NOTE: Please think twice before making any changes to the bits of
code below. GDB needs some intimate knowledge about it to code below. GDB needs some intimate knowledge about it to