yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* POSIX.1 sigaction call for Linux/SPARC. |
| 2 | Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx), 1997. |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library; if not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307 USA. |
| 20 | |
| 21 | Ported to uClibc from glibc: 090520: |
| 22 | Jan Buchholz, KIP, Uni Heidelberg <jan.buchholz@kip.uni-heidelberg.de> |
| 23 | Austin Foxley, Ceton Corporation <austinf@cetoncorp.com> |
| 24 | */ |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #include <signal.h> |
| 28 | #include <string.h> |
| 29 | #include <sys/syscall.h> |
| 30 | #include <bits/kernel_sigaction.h> |
| 31 | |
| 32 | |
| 33 | _syscall5(int, rt_sigaction, int, a, int, b, int, c, int, d, int, e) |
| 34 | static void __rt_sigreturn_stub(void); |
| 35 | static void __sigreturn_stub(void); |
| 36 | |
| 37 | int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact) |
| 38 | { |
| 39 | int ret; |
| 40 | struct sigaction kact, koact; |
| 41 | unsigned long stub = 0; |
| 42 | |
| 43 | if (act) { |
| 44 | kact.sa_handler = act->sa_handler; |
| 45 | memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t)); |
| 46 | if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0) |
| 47 | stub = (unsigned long) &__rt_sigreturn_stub; |
| 48 | else |
| 49 | stub = (unsigned long) &__sigreturn_stub; |
| 50 | stub -= 8; |
| 51 | kact.sa_restorer = NULL; |
| 52 | } |
| 53 | |
| 54 | /* XXX The size argument hopefully will have to be changed to the |
| 55 | * real size of the user-level sigset_t. */ |
| 56 | ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0, |
| 57 | oact ? &koact : 0, stub, _NSIG / 8); |
| 58 | |
| 59 | if (oact && ret >= 0) { |
| 60 | oact->sa_handler = koact.sa_handler; |
| 61 | memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t)); |
| 62 | oact->sa_flags = koact.sa_flags; |
| 63 | oact->sa_restorer = koact.sa_restorer; |
| 64 | } |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | #ifndef LIBC_SIGACTION |
| 70 | # ifndef __UCLIBC_HAS_THREADS__ |
| 71 | strong_alias(__libc_sigaction,sigaction) |
| 72 | libc_hidden_def(sigaction) |
| 73 | # else |
| 74 | weak_alias(__libc_sigaction,sigaction) |
| 75 | libc_hidden_weak(sigaction) |
| 76 | # endif |
| 77 | #endif |
| 78 | |
| 79 | |
| 80 | static void |
| 81 | __rt_sigreturn_stub(void) |
| 82 | { |
| 83 | __asm__( |
| 84 | "mov %0, %%g1\n\t" |
| 85 | "ta 0x10\n\t" |
| 86 | : /* no outputs */ |
| 87 | : "i" (__NR_rt_sigreturn) |
| 88 | ); |
| 89 | } |
| 90 | static void |
| 91 | __sigreturn_stub(void) |
| 92 | { |
| 93 | __asm__( |
| 94 | "mov %0, %%g1\n\t" |
| 95 | "ta 0x10\n\t" |
| 96 | : /* no outputs */ |
| 97 | : "i" (__NR_sigreturn) |
| 98 | ); |
| 99 | } |