Back to index

glibc  2.9
sigaction.c
Go to the documentation of this file.
00001 /* POSIX.1 sigaction call for Linux/SPARC.
00002    Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx), 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <string.h>
00022 #include <syscall.h>
00023 #include <sys/signal.h>
00024 #include <errno.h>
00025 #include <kernel_sigaction.h>
00026 #include <sysdep.h>
00027 
00028 static void __rt_sigreturn_stub (void);
00029 static void __sigreturn_stub (void);
00030 
00031 /* The variable is shared between all wrappers around signal handling
00032    functions which have RT equivalents.  */
00033 int __libc_missing_rt_sigs;
00034 
00035 int
00036 __libc_sigaction (int sig, __const struct sigaction *act,
00037                 struct sigaction *oact)
00038 {
00039   struct old_kernel_sigaction k_sigact, k_osigact;
00040   int ret;
00041 
00042 #ifdef __NR_rt_sigaction
00043   /* First try the RT signals.  */
00044   if (!__libc_missing_rt_sigs)
00045     {
00046       struct kernel_sigaction kact, koact;
00047       unsigned long stub = 0;
00048       int saved_errno = errno;
00049 
00050       if (act)
00051        {
00052          kact.k_sa_handler = act->sa_handler;
00053          memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
00054          if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
00055            stub = (unsigned long) &__rt_sigreturn_stub;
00056          else
00057            stub = (unsigned long) &__sigreturn_stub;
00058          stub -= 8;
00059          kact.sa_restorer = NULL;
00060        }
00061 
00062       /* XXX The size argument hopefully will have to be changed to the
00063         real size of the user-level sigset_t.  */
00064       ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0,
00065                          oact ? &koact : 0, stub, _NSIG / 8);
00066 
00067       if (ret >= 0 || errno != ENOSYS)
00068        {
00069          if (oact && ret >= 0)
00070            {
00071              oact->sa_handler = koact.k_sa_handler;
00072              memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
00073              oact->sa_flags = koact.sa_flags;
00074              oact->sa_restorer = koact.sa_restorer;
00075            }
00076          return ret;
00077        }
00078 
00079       __set_errno (saved_errno);
00080       __libc_missing_rt_sigs = 1;
00081     }
00082 #endif
00083 
00084   /* Magic to tell the kernel we are using "new-style" signals, in that
00085      the signal table is not kept in userspace.  Not the same as the
00086      really-new-style rt signals.  */
00087   sig = -sig;
00088 
00089   if (act)
00090     {
00091       k_sigact.k_sa_handler = act->sa_handler;
00092       k_sigact.sa_mask = act->sa_mask.__val[0];
00093       k_sigact.sa_flags = act->sa_flags;
00094       k_sigact.sa_restorer = NULL;
00095     }
00096 
00097   {
00098     register int r_syscallnr __asm__("%g1") = __NR_sigaction;
00099     register int r_sig __asm__("%o0") = sig;
00100     register struct old_kernel_sigaction *r_act __asm__("%o1");
00101     register struct old_kernel_sigaction *r_oact __asm__("%o2");
00102 
00103     r_act = act ? &k_sigact : NULL;
00104     r_oact = oact ? &k_osigact : NULL;
00105 
00106     __asm__ __volatile__("t 0x10\n\t"
00107                       "bcc 1f\n\t"
00108                       " nop\n\t"
00109                       "sub %%g0,%%o0,%%o0\n"
00110                       "1:"
00111                       : "=r"(r_sig)
00112                       : "r"(r_syscallnr), "r"(r_act), "r"(r_oact),
00113                         "0"(r_sig));
00114 
00115     ret = r_sig;
00116   }
00117 
00118   if (ret >= 0)
00119     {
00120       if (oact)
00121        {
00122          oact->sa_handler = k_osigact.k_sa_handler;
00123          oact->sa_mask.__val[0] = k_osigact.sa_mask;
00124          oact->sa_flags = k_osigact.sa_flags;
00125          oact->sa_restorer = NULL;
00126        }
00127       return ret;
00128     }
00129 
00130   __set_errno (-ret);
00131   return -1;
00132 }
00133 libc_hidden_def (__libc_sigaction)
00134 
00135 #ifdef WRAPPER_INCLUDE
00136 # include WRAPPER_INCLUDE
00137 #endif
00138 
00139 #ifndef LIBC_SIGACTION
00140 weak_alias (__libc_sigaction, __sigaction);
00141 libc_hidden_weak (__sigaction)
00142 weak_alias (__libc_sigaction, sigaction);
00143 #endif
00144 
00145 static void
00146 __rt_sigreturn_stub (void)
00147 {
00148   __asm__ ("mov %0, %%g1\n\t"
00149           "ta 0x10\n\t"
00150           : /* no outputs */
00151           : "i" (__NR_rt_sigreturn));
00152 }
00153 
00154 static void
00155 __sigreturn_stub (void)
00156 {
00157   __asm__ ("mov %0, %%g1\n\t"
00158           "ta 0x10\n\t"
00159           : /* no outputs */
00160           : "i" (__NR_sigreturn));
00161 }