The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4_32/svr4_32_signal.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svr4_32_signal.c,v 1.16 2006/10/16 20:18:55 martin Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas and by Charles M. Hannum.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: svr4_32_signal.c,v 1.16 2006/10/16 20:18:55 martin Exp $");
   41 
   42 #if defined(_KERNEL_OPT)
   43 #include "opt_compat_svr4.h"
   44 #endif
   45 
   46 #include <sys/param.h>
   47 #include <sys/systm.h>
   48 #include <sys/namei.h>
   49 #include <sys/proc.h>
   50 #include <sys/filedesc.h>
   51 #include <sys/ioctl.h>
   52 #include <sys/mount.h>
   53 #include <sys/kernel.h>
   54 #include <sys/signal.h>
   55 #include <sys/signalvar.h>
   56 #include <sys/malloc.h>
   57 #include <sys/wait.h>
   58 
   59 #include <sys/sa.h>
   60 #include <sys/syscallargs.h>
   61 
   62 #include <compat/svr4_32/svr4_32_types.h>
   63 #include <compat/svr4_32/svr4_32_signal.h>
   64 #include <compat/svr4_32/svr4_32_lwp.h>
   65 #include <compat/svr4_32/svr4_32_ucontext.h>
   66 #include <compat/svr4_32/svr4_32_syscallargs.h>
   67 #include <compat/svr4_32/svr4_32_util.h>
   68 #include <compat/svr4_32/svr4_32_ucontext.h>
   69 
   70 #define svr4_sigmask(n)         (1 << (((n) - 1) & 31))
   71 #define svr4_sigword(n)         (((n) - 1) >> 5)
   72 #define svr4_sigemptyset(s)     memset((s), 0, sizeof(*(s)))
   73 #define svr4_sigismember(s, n)  ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n))
   74 #define svr4_sigaddset(s, n)    ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n))
   75 
   76 static inline void svr4_32_sigfillset __P((svr4_32_sigset_t *));
   77 void svr4_32_to_native_sigaction __P((const struct svr4_32_sigaction *,
   78                                 struct sigaction *));
   79 void native_to_svr4_32_sigaction __P((const struct sigaction *,
   80                                 struct svr4_32_sigaction *));
   81 
   82 #ifndef COMPAT_SVR4
   83 const int native_to_svr4_signo[NSIG] = {
   84         0,                      /* 0 */
   85         SVR4_SIGHUP,            /* 1 */
   86         SVR4_SIGINT,            /* 2 */
   87         SVR4_SIGQUIT,           /* 3 */
   88         SVR4_SIGILL,            /* 4 */
   89         SVR4_SIGTRAP,           /* 5 */
   90         SVR4_SIGABRT,           /* 6 */
   91         SVR4_SIGEMT,            /* 7 */
   92         SVR4_SIGFPE,            /* 8 */
   93         SVR4_SIGKILL,           /* 9 */
   94         SVR4_SIGBUS,            /* 10 */
   95         SVR4_SIGSEGV,           /* 11 */
   96         SVR4_SIGSYS,            /* 12 */
   97         SVR4_SIGPIPE,           /* 13 */
   98         SVR4_SIGALRM,           /* 14 */
   99         SVR4_SIGTERM,           /* 15 */
  100         SVR4_SIGURG,            /* 16 */
  101         SVR4_SIGSTOP,           /* 17 */
  102         SVR4_SIGTSTP,           /* 18 */
  103         SVR4_SIGCONT,           /* 19 */
  104         SVR4_SIGCHLD,           /* 20 */
  105         SVR4_SIGTTIN,           /* 21 */
  106         SVR4_SIGTTOU,           /* 22 */
  107         SVR4_SIGIO,             /* 23 */
  108         SVR4_SIGXCPU,           /* 24 */
  109         SVR4_SIGXFSZ,           /* 25 */
  110         SVR4_SIGVTALRM,         /* 26 */
  111         SVR4_SIGPROF,           /* 27 */
  112         SVR4_SIGWINCH,          /* 28 */
  113         0,                      /* 29 SIGINFO */
  114         SVR4_SIGUSR1,           /* 30 */
  115         SVR4_SIGUSR2,           /* 31 */
  116         SVR4_SIGPWR,            /* 32 */
  117         SVR4_SIGRTMIN + 0,      /* 33 */
  118         SVR4_SIGRTMIN + 1,      /* 34 */
  119         SVR4_SIGRTMIN + 2,      /* 35 */
  120         SVR4_SIGRTMIN + 3,      /* 36 */
  121         SVR4_SIGRTMIN + 4,      /* 37 */
  122         SVR4_SIGRTMIN + 5,      /* 38 */
  123         SVR4_SIGRTMIN + 6,      /* 39 */
  124         SVR4_SIGRTMIN + 7,      /* 40 */
  125         SVR4_SIGRTMIN + 8,      /* 41 */
  126         SVR4_SIGRTMIN + 9,      /* 42 */
  127         SVR4_SIGRTMIN + 10,     /* 43 */
  128         SVR4_SIGRTMIN + 11,     /* 44 */
  129         SVR4_SIGRTMIN + 12,     /* 45 */
  130         SVR4_SIGRTMIN + 13,     /* 46 */
  131         SVR4_SIGRTMIN + 14,     /* 47 */
  132         SVR4_SIGRTMIN + 15,     /* 48 */
  133         SVR4_SIGRTMIN + 16,     /* 49 */
  134         SVR4_SIGRTMIN + 17,     /* 50 */
  135         SVR4_SIGRTMIN + 18,     /* 51 */
  136         SVR4_SIGRTMIN + 19,     /* 52 */
  137         SVR4_SIGRTMIN + 20,     /* 53 */
  138         SVR4_SIGRTMIN + 21,     /* 54 */
  139         SVR4_SIGRTMIN + 22,     /* 55 */
  140         SVR4_SIGRTMIN + 23,     /* 56 */
  141         SVR4_SIGRTMIN + 24,     /* 57 */
  142         SVR4_SIGRTMIN + 25,     /* 58 */
  143         SVR4_SIGRTMIN + 26,     /* 59 */
  144         SVR4_SIGRTMIN + 27,     /* 60 */
  145         SVR4_SIGRTMIN + 28,     /* 61 */
  146         SVR4_SIGRTMIN + 29,     /* 62 */
  147         SVR4_SIGRTMIN + 30,     /* 63 */
  148 };
  149 
  150 const int svr4_to_native_signo[SVR4_NSIG] = {
  151         0,                      /* 0 */
  152         SIGHUP,                 /* 1 */
  153         SIGINT,                 /* 2 */
  154         SIGQUIT,                /* 3 */
  155         SIGILL,                 /* 4 */
  156         SIGTRAP,                /* 5 */
  157         SIGABRT,                /* 6 */
  158         SIGEMT,                 /* 7 */
  159         SIGFPE,                 /* 8 */
  160         SIGKILL,                /* 9 */
  161         SIGBUS,                 /* 10 */
  162         SIGSEGV,                /* 11 */
  163         SIGSYS,                 /* 12 */
  164         SIGPIPE,                /* 13 */
  165         SIGALRM,                /* 14 */
  166         SIGTERM,                /* 15 */
  167         SIGUSR1,                /* 16 */
  168         SIGUSR2,                /* 17 */
  169         SIGCHLD,                /* 18 */
  170         SIGPWR,                 /* 19 */
  171         SIGWINCH,               /* 20 */
  172         SIGURG,                 /* 21 */
  173         SIGIO,                  /* 22 */
  174         SIGSTOP,                /* 23 */
  175         SIGTSTP,                /* 24 */
  176         SIGCONT,                /* 25 */
  177         SIGTTIN,                /* 26 */
  178         SIGTTOU,                /* 27 */
  179         SIGVTALRM,              /* 28 */
  180         SIGPROF,                /* 29 */
  181         SIGXCPU,                /* 30 */
  182         SIGXFSZ,                /* 31 */
  183         SIGRTMIN + 0,           /* 32 */
  184         SIGRTMIN + 1,           /* 33 */
  185         SIGRTMIN + 2,           /* 34 */
  186         SIGRTMIN + 3,           /* 35 */
  187         SIGRTMIN + 4,           /* 36 */
  188         SIGRTMIN + 5,           /* 37 */
  189         SIGRTMIN + 6,           /* 38 */
  190         SIGRTMIN + 7,           /* 39 */
  191         SIGRTMIN + 8,           /* 40 */
  192         SIGRTMIN + 9,           /* 41 */
  193         SIGRTMIN + 10,          /* 42 */
  194         SIGRTMIN + 11,          /* 43 */
  195         SIGRTMIN + 12,          /* 44 */
  196         SIGRTMIN + 13,          /* 45 */
  197         SIGRTMIN + 14,          /* 46 */
  198         SIGRTMIN + 15,          /* 47 */
  199         SIGRTMIN + 16,          /* 48 */
  200         SIGRTMIN + 17,          /* 49 */
  201         SIGRTMIN + 18,          /* 50 */
  202         SIGRTMIN + 19,          /* 51 */
  203         SIGRTMIN + 20,          /* 52 */
  204         SIGRTMIN + 21,          /* 53 */
  205         SIGRTMIN + 22,          /* 54 */
  206         SIGRTMIN + 23,          /* 55 */
  207         SIGRTMIN + 24,          /* 56 */
  208         SIGRTMIN + 25,          /* 57 */
  209         SIGRTMIN + 26,          /* 58 */
  210         SIGRTMIN + 27,          /* 59 */
  211         SIGRTMIN + 28,          /* 60 */
  212         SIGRTMIN + 29,          /* 61 */
  213         SIGRTMIN + 30,          /* 62 */
  214         0,                      /* 63 */
  215 };
  216 #endif
  217 
  218 static inline void
  219 svr4_32_sigfillset(s)
  220         svr4_32_sigset_t *s;
  221 {
  222         int i;
  223 
  224         svr4_sigemptyset(s);
  225         for (i = 1; i < SVR4_NSIG; i++)
  226                 if (svr4_to_native_signo[i] != 0)
  227                         svr4_sigaddset(s, i);
  228 }
  229 
  230 void
  231 svr4_32_to_native_sigset(sss, bss)
  232         const svr4_32_sigset_t *sss;
  233         sigset_t *bss;
  234 {
  235         int i, newsig;
  236 
  237         sigemptyset(bss);
  238         for (i = 1; i < SVR4_NSIG; i++) {
  239                 if (svr4_sigismember(sss, i)) {
  240                         newsig = svr4_to_native_signo[i];
  241                         if (newsig)
  242                                 sigaddset(bss, newsig);
  243                 }
  244         }
  245 }
  246 
  247 
  248 void
  249 native_to_svr4_32_sigset(bss, sss)
  250         const sigset_t *bss;
  251         svr4_32_sigset_t *sss;
  252 {
  253         int i, newsig;
  254 
  255         svr4_sigemptyset(sss);
  256         for (i = 1; i < NSIG; i++) {
  257                 if (sigismember(bss, i)) {
  258                         newsig = native_to_svr4_signo[i];
  259                         if (newsig)
  260                                 svr4_sigaddset(sss, newsig);
  261                 }
  262         }
  263 }
  264 
  265 /*
  266  * XXX: Only a subset of the flags is currently implemented.
  267  */
  268 void
  269 svr4_32_to_native_sigaction(ssa, bsa)
  270         const struct svr4_32_sigaction *ssa;
  271         struct sigaction *bsa;
  272 {
  273 
  274         bsa->sa_handler = (sig_t)(u_long) ssa->svr4_32_sa_handler;
  275         svr4_32_to_native_sigset(&ssa->svr4_32_sa_mask, &bsa->sa_mask);
  276         bsa->sa_flags = 0;
  277         if ((ssa->svr4_32_sa_flags & SVR4_SA_ONSTACK) != 0)
  278                 bsa->sa_flags |= SA_ONSTACK;
  279         if ((ssa->svr4_32_sa_flags & SVR4_SA_RESETHAND) != 0)
  280                 bsa->sa_flags |= SA_RESETHAND;
  281         if ((ssa->svr4_32_sa_flags & SVR4_SA_RESTART) != 0)
  282                 bsa->sa_flags |= SA_RESTART;
  283         if ((ssa->svr4_32_sa_flags & SVR4_SA_SIGINFO) != 0) {
  284                 DPRINTF(("svr4_to_native_sigaction: SA_SIGINFO ignored\n"));
  285         }
  286         if ((ssa->svr4_32_sa_flags & SVR4_SA_NODEFER) != 0)
  287                 bsa->sa_flags |= SA_NODEFER;
  288         if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDWAIT) != 0)
  289                 bsa->sa_flags |= SA_NOCLDWAIT;
  290         if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDSTOP) != 0)
  291                 bsa->sa_flags |= SA_NOCLDSTOP;
  292         if ((ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS) != 0) {
  293                 DPRINTF(("svr4_32_to_native_sigaction: extra bits %x ignored\n",
  294                     ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS));
  295         }
  296 }
  297 
  298 void
  299 native_to_svr4_32_sigaction(bsa, ssa)
  300         const struct sigaction *bsa;
  301         struct svr4_32_sigaction *ssa;
  302 {
  303 
  304         ssa->svr4_32_sa_handler = (svr4_32_sig_t)(u_long) bsa->sa_handler;
  305         native_to_svr4_32_sigset(&bsa->sa_mask, &ssa->svr4_32_sa_mask);
  306         ssa->svr4_32_sa_flags = 0;
  307         if ((bsa->sa_flags & SA_ONSTACK) != 0)
  308                 ssa->svr4_32_sa_flags |= SVR4_SA_ONSTACK;
  309         if ((bsa->sa_flags & SA_RESETHAND) != 0)
  310                 ssa->svr4_32_sa_flags |= SVR4_SA_RESETHAND;
  311         if ((bsa->sa_flags & SA_RESTART) != 0)
  312                 ssa->svr4_32_sa_flags |= SVR4_SA_RESTART;
  313         if ((bsa->sa_flags & SA_NODEFER) != 0)
  314                 ssa->svr4_32_sa_flags |= SVR4_SA_NODEFER;
  315         if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
  316                 ssa->svr4_32_sa_flags |= SVR4_SA_NOCLDSTOP;
  317 }
  318 
  319 void
  320 svr4_32_to_native_sigaltstack(sss, bss)
  321         const struct svr4_32_sigaltstack *sss;
  322         struct sigaltstack *bss;
  323 {
  324 
  325         bss->ss_sp = (caddr_t)(u_long)sss->ss_sp;
  326         bss->ss_size = sss->ss_size;
  327         bss->ss_flags = 0;
  328         if ((sss->ss_flags & SVR4_SS_DISABLE) != 0)
  329                 bss->ss_flags |= SS_DISABLE;
  330         if ((sss->ss_flags & SVR4_SS_ONSTACK) != 0)
  331                 bss->ss_flags |= SS_ONSTACK;
  332         if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0)
  333 /*XXX*/         printf("svr4_to_native_sigaltstack: extra bits %x ignored\n",
  334                     sss->ss_flags & ~SVR4_SS_ALLBITS);
  335 }
  336 
  337 void
  338 native_to_svr4_32_sigaltstack(bss, sss)
  339         const struct sigaltstack *bss;
  340         struct svr4_32_sigaltstack *sss;
  341 {
  342 
  343         sss->ss_sp = (u_long)bss->ss_sp;
  344         sss->ss_size = bss->ss_size;
  345         sss->ss_flags = 0;
  346         if ((bss->ss_flags & SS_DISABLE) != 0)
  347                 sss->ss_flags |= SVR4_SS_DISABLE;
  348         if ((bss->ss_flags & SS_ONSTACK) != 0)
  349                 sss->ss_flags |= SVR4_SS_ONSTACK;
  350 }
  351 
  352 int
  353 svr4_32_sys_sigaction(l, v, retval)
  354         struct lwp *l;
  355         void *v;
  356         register_t *retval;
  357 {
  358         struct svr4_32_sys_sigaction_args /* {
  359                 syscallarg(int) signum;
  360                 syscallarg(const struct svr4_32_sigaction *) nsa;
  361                 syscallarg(struct svr4_32_sigaction *) osa;
  362         } */ *uap = v;
  363         struct svr4_32_sigaction nssa, ossa;
  364         struct sigaction nbsa, obsa;
  365         int error;
  366 
  367         if (SCARG(uap, nsa)) {
  368                 error = copyin((caddr_t)(u_long)SCARG(uap, nsa),
  369                                &nssa, sizeof(nssa));
  370                 if (error)
  371                         return (error);
  372                 svr4_32_to_native_sigaction(&nssa, &nbsa);
  373         }
  374         error = sigaction1(l->l_proc,
  375                            svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))],
  376             SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
  377             NULL, 0);
  378         if (error)
  379                 return (error);
  380         if (SCARG(uap, osa)) {
  381                 native_to_svr4_32_sigaction(&obsa, &ossa);
  382                 error = copyout(&ossa, (caddr_t)(u_long)SCARG(uap, osa),
  383                                 sizeof(ossa));
  384                 if (error)
  385                         return (error);
  386         }
  387         return (0);
  388 }
  389 
  390 int
  391 svr4_32_sys_sigaltstack(l, v, retval)
  392         struct lwp *l;
  393         void *v;
  394         register_t *retval;
  395 {
  396         struct svr4_32_sys_sigaltstack_args /* {
  397                 syscallarg(const struct svr4_32_sigaltstack *) nss;
  398                 syscallarg(struct svr4_32_sigaltstack *) oss;
  399         } */ *uap = v;
  400         struct svr4_32_sigaltstack nsss, osss;
  401         struct sigaltstack nbss, obss;
  402         int error;
  403 
  404         if (SCARG(uap, nss)) {
  405                 error = copyin((caddr_t)(u_long)SCARG(uap, nss),
  406                                &nsss, sizeof(nsss));
  407                 if (error)
  408                         return (error);
  409                 svr4_32_to_native_sigaltstack(&nsss, &nbss);
  410         }
  411         error = sigaltstack1(l->l_proc,
  412             SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0);
  413         if (error)
  414                 return (error);
  415         if (SCARG(uap, oss)) {
  416                 native_to_svr4_32_sigaltstack(&obss, &osss);
  417                 error = copyout(&osss, (caddr_t)(u_long)SCARG(uap, oss),
  418                                 sizeof(osss));
  419                 if (error)
  420                         return (error);
  421         }
  422         return (0);
  423 }
  424 
  425 /*
  426  * Stolen from the ibcs2 one
  427  */
  428 int
  429 svr4_32_sys_signal(l, v, retval)
  430         struct lwp *l;
  431         void *v;
  432         register_t *retval;
  433 {
  434         struct svr4_32_sys_signal_args /* {
  435                 syscallarg(int) signum;
  436                 syscallarg(svr4_32_sig_t) handler;
  437         } */ *uap = v;
  438         struct proc *p = l->l_proc;
  439         int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
  440         struct sigaction nbsa, obsa;
  441         sigset_t ss;
  442         int error;
  443 
  444         if (signum <= 0 || signum >= SVR4_NSIG)
  445                 return (EINVAL);
  446 
  447         switch (SVR4_SIGCALL(SCARG(uap, signum))) {
  448         case SVR4_SIGDEFER_MASK:
  449                 if (SCARG(uap, handler) == SVR4_SIG_HOLD)
  450                         goto sighold;
  451                 /* FALLTHROUGH */
  452 
  453         case SVR4_SIGNAL_MASK:
  454                 nbsa.sa_handler = (sig_t)SCARG(uap, handler);
  455                 sigemptyset(&nbsa.sa_mask);
  456                 nbsa.sa_flags = 0;
  457                 error = sigaction1(p, signum, &nbsa, &obsa, NULL, 0);
  458                 if (error)
  459                         return (error);
  460                 *retval = (u_int)(u_long)obsa.sa_handler;
  461                 return (0);
  462 
  463         case SVR4_SIGHOLD_MASK:
  464         sighold:
  465                 sigemptyset(&ss);
  466                 sigaddset(&ss, signum);
  467                 return (sigprocmask1(p, SIG_BLOCK, &ss, 0));
  468 
  469         case SVR4_SIGRELSE_MASK:
  470                 sigemptyset(&ss);
  471                 sigaddset(&ss, signum);
  472                 return (sigprocmask1(p, SIG_UNBLOCK, &ss, 0));
  473 
  474         case SVR4_SIGIGNORE_MASK:
  475                 nbsa.sa_handler = SIG_IGN;
  476                 sigemptyset(&nbsa.sa_mask);
  477                 nbsa.sa_flags = 0;
  478                 return (sigaction1(p, signum, &nbsa, 0, NULL, 0));
  479 
  480         case SVR4_SIGPAUSE_MASK:
  481                 ss = p->p_sigctx.ps_sigmask;
  482                 sigdelset(&ss, signum);
  483                 return (sigsuspend1(p, &ss));
  484 
  485         default:
  486                 return (ENOSYS);
  487         }
  488 }
  489 
  490 int
  491 svr4_32_sys_sigprocmask(l, v, retval)
  492         struct lwp *l;
  493         void *v;
  494         register_t *retval;
  495 {
  496         struct svr4_32_sys_sigprocmask_args /* {
  497                 syscallarg(int) how;
  498                 syscallarg(const svr4_32_sigset_t *) set;
  499                 syscallarg(svr4_32_sigset_t *) oset;
  500         } */ *uap = v;
  501         svr4_32_sigset_t nsss, osss;
  502         sigset_t nbss, obss;
  503         int how;
  504         int error;
  505 
  506         /*
  507          * Initialize how to 0 to avoid a compiler warning.  Note that
  508          * this is safe because of the check in the default: case.
  509          */
  510         how = 0;
  511 
  512         switch (SCARG(uap, how)) {
  513         case SVR4_SIG_BLOCK:
  514                 how = SIG_BLOCK;
  515                 break;
  516         case SVR4_SIG_UNBLOCK:
  517                 how = SIG_UNBLOCK;
  518                 break;
  519         case SVR4_SIG_SETMASK:
  520                 how = SIG_SETMASK;
  521                 break;
  522         default:
  523                 if (SCARG(uap, set))
  524                         return EINVAL;
  525                 break;
  526         }
  527 
  528         if (SCARG(uap, set)) {
  529                 error = copyin((caddr_t)(u_long)SCARG(uap, set),
  530                                &nsss, sizeof(nsss));
  531                 if (error)
  532                         return error;
  533                 svr4_32_to_native_sigset(&nsss, &nbss);
  534         }
  535         error = sigprocmask1(l->l_proc, how,
  536             SCARG(uap, set) ? &nbss : NULL, SCARG(uap, oset) ? &obss : NULL);
  537         if (error)
  538                 return error;
  539         if (SCARG(uap, oset)) {
  540                 native_to_svr4_32_sigset(&obss, &osss);
  541                 error = copyout(&osss, (caddr_t)(u_long)SCARG(uap, oset),
  542                                 sizeof(osss));
  543                 if (error)
  544                         return error;
  545         }
  546         return 0;
  547 }
  548 
  549 int
  550 svr4_32_sys_sigpending(l, v, retval)
  551         struct lwp *l;
  552         void *v;
  553         register_t *retval;
  554 {
  555         struct svr4_32_sys_sigpending_args /* {
  556                 syscallarg(int) what;
  557                 syscallarg(svr4_sigset_t *) set;
  558         } */ *uap = v;
  559         sigset_t bss;
  560         svr4_32_sigset_t sss;
  561 
  562         switch (SCARG(uap, what)) {
  563         case 1: /* sigpending */
  564                 sigpending1(l->l_proc, &bss);
  565                 native_to_svr4_32_sigset(&bss, &sss);
  566                 break;
  567 
  568         case 2: /* sigfillset */
  569                 svr4_32_sigfillset(&sss);
  570                 break;
  571 
  572         default:
  573                 return (EINVAL);
  574         }
  575         return (copyout(&sss, (caddr_t)(u_long)SCARG(uap, set), sizeof(sss)));
  576 }
  577 
  578 int
  579 svr4_32_sys_sigsuspend(l, v, retval)
  580         struct lwp *l;
  581         void *v;
  582         register_t *retval;
  583 {
  584         struct svr4_32_sys_sigsuspend_args /* {
  585                 syscallarg(const svr4_32_sigset_t *) set;
  586         } */ *uap = v;
  587         svr4_32_sigset_t sss;
  588         sigset_t bss;
  589         int error;
  590 
  591         if (SCARG(uap, set)) {
  592                 error = copyin((caddr_t)(u_long)SCARG(uap, set), &sss, sizeof(sss));
  593                 if (error)
  594                         return (error);
  595                 svr4_32_to_native_sigset(&sss, &bss);
  596         }
  597 
  598         return (sigsuspend1(l->l_proc, SCARG(uap, set) ? &bss : 0));
  599 }
  600 
  601 int
  602 svr4_32_sys_pause(l, v, retval)
  603         struct lwp *l;
  604         void *v;
  605         register_t *retval;
  606 {
  607 
  608         return (sigsuspend1(l->l_proc, 0));
  609 }
  610 
  611 int
  612 svr4_32_sys_kill(l, v, retval)
  613         struct lwp *l;
  614         void *v;
  615         register_t *retval;
  616 {
  617         struct svr4_32_sys_kill_args /* {
  618                 syscallarg(int) pid;
  619                 syscallarg(int) signum;
  620         } */ *uap = v;
  621         struct sys_kill_args ka;
  622 
  623         SCARG(&ka, pid) = SCARG(uap, pid);
  624         SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
  625         return sys_kill(l, &ka, retval);
  626 }
  627 
  628 void
  629 svr4_32_getcontext(l, uc, mask)
  630         struct lwp *l;
  631         struct svr4_32_ucontext *uc;
  632         const sigset_t *mask;
  633 {
  634         void *sp;
  635         struct svr4_32_sigaltstack *ss = &uc->uc_stack;
  636 
  637         memset(uc, 0, sizeof(*uc));
  638 
  639         /* get machine context */
  640         sp = svr4_32_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags);
  641 
  642         /* get link */
  643         uc->uc_link = (u_long)l->l_ctxlink;
  644 
  645         /* get stack state. XXX: solaris appears to do this */
  646 #if 0
  647         svr4_32_to_native_sigaltstack(&uc->uc_stack, &p->p_sigacts->ps_sigstk);
  648 #else
  649         ss->ss_sp = (((u_long) sp) & ~(16384 - 1));
  650         ss->ss_size = 16384;
  651         ss->ss_flags = 0;
  652 #endif
  653         /* get signal mask */
  654         native_to_svr4_32_sigset(mask, &uc->uc_sigmask);
  655 
  656         uc->uc_flags |= SVR4_UC_STACK|SVR4_UC_SIGMASK;
  657 }
  658 
  659 
  660 int
  661 svr4_32_setcontext(l, uc)
  662         struct lwp *l;
  663         struct svr4_32_ucontext *uc;
  664 {
  665         int error;
  666         struct proc *p = l->l_proc;
  667 
  668         /* set machine context */
  669         if ((error = svr4_32_setmcontext(l, &uc->uc_mcontext, uc->uc_flags)) != 0)
  670                 return error;
  671 
  672         /* set link */
  673         l->l_ctxlink = (caddr_t)(u_long)uc->uc_link;
  674 
  675         /* set signal stack */
  676         if (uc->uc_flags & SVR4_UC_STACK) {
  677                 svr4_32_to_native_sigaltstack(&uc->uc_stack,
  678                     &p->p_sigctx.ps_sigstk);
  679         }
  680 
  681         /* set signal mask */
  682         if (uc->uc_flags & SVR4_UC_SIGMASK) {
  683                 sigset_t mask;
  684 
  685                 svr4_32_to_native_sigset(&uc->uc_sigmask, &mask);
  686                 (void)sigprocmask1(p, SIG_SETMASK, &mask, 0);
  687         }
  688 
  689         return EJUSTRETURN;
  690 }
  691 
  692 int
  693 svr4_32_sys_context(l, v, retval)
  694         struct lwp *l;
  695         void *v;
  696         register_t *retval;
  697 {
  698         struct svr4_32_sys_context_args /* {
  699                 syscallarg(int) func;
  700                 syscallarg(struct svr4_32_ucontext *) uc;
  701         } */ *uap = v;
  702         struct proc *p = l->l_proc;
  703         struct svr4_32_ucontext uc;
  704         int error;
  705         *retval = 0;
  706 
  707         switch (SCARG(uap, func)) {
  708         case SVR4_GETCONTEXT:
  709                 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc)));
  710                 svr4_32_getcontext(l, &uc, &p->p_sigctx.ps_sigmask);
  711                 return copyout(&uc, (caddr_t)(u_long)SCARG(uap, uc), sizeof(uc));
  712 
  713         case SVR4_SETCONTEXT:
  714                 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc)));
  715                 if (!SCARG(uap, uc))
  716                         exit1(l, W_EXITCODE(0, 0));
  717                 else if ((error = copyin((caddr_t)(u_long)SCARG(uap, uc),
  718                                          &uc, sizeof(uc))) != 0)
  719                         return error;
  720                 else
  721                         return svr4_32_setcontext(l, &uc);
  722 
  723         default:
  724                 DPRINTF(("context(%d, %p)\n", SCARG(uap, func),
  725                     SCARG(uap, uc)));
  726                 return ENOSYS;
  727         }
  728         return 0;
  729 }

Cache object: 920d3775cab88c1a975a5c4f9968e24f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.