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.13 2005/02/26 23:10:21 perry 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.13 2005/02/26 23:10:21 perry 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         if ((ssa->svr4_32_sa_flags & SVR4_SA_NODEFER) != 0)
  286                 bsa->sa_flags |= SA_NODEFER;
  287         if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDWAIT) != 0)
  288                 bsa->sa_flags |= SA_NOCLDWAIT;
  289         if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDSTOP) != 0)
  290                 bsa->sa_flags |= SA_NOCLDSTOP;
  291         if ((ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS) != 0)
  292                 DPRINTF(("svr4_32_to_native_sigaction: extra bits %x ignored\n",
  293                     ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS));
  294 }
  295 
  296 void
  297 native_to_svr4_32_sigaction(bsa, ssa)
  298         const struct sigaction *bsa;
  299         struct svr4_32_sigaction *ssa;
  300 {
  301 
  302         ssa->svr4_32_sa_handler = (svr4_32_sig_t)(u_long) bsa->sa_handler;
  303         native_to_svr4_32_sigset(&bsa->sa_mask, &ssa->svr4_32_sa_mask);
  304         ssa->svr4_32_sa_flags = 0;
  305         if ((bsa->sa_flags & SA_ONSTACK) != 0)
  306                 ssa->svr4_32_sa_flags |= SVR4_SA_ONSTACK;
  307         if ((bsa->sa_flags & SA_RESETHAND) != 0)
  308                 ssa->svr4_32_sa_flags |= SVR4_SA_RESETHAND;
  309         if ((bsa->sa_flags & SA_RESTART) != 0)
  310                 ssa->svr4_32_sa_flags |= SVR4_SA_RESTART;
  311         if ((bsa->sa_flags & SA_NODEFER) != 0)
  312                 ssa->svr4_32_sa_flags |= SVR4_SA_NODEFER;
  313         if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
  314                 ssa->svr4_32_sa_flags |= SVR4_SA_NOCLDSTOP;
  315 }
  316 
  317 void
  318 svr4_32_to_native_sigaltstack(sss, bss)
  319         const struct svr4_32_sigaltstack *sss;
  320         struct sigaltstack *bss;
  321 {
  322 
  323         bss->ss_sp = (caddr_t)(u_long)sss->ss_sp;
  324         bss->ss_size = sss->ss_size;
  325         bss->ss_flags = 0;
  326         if ((sss->ss_flags & SVR4_SS_DISABLE) != 0)
  327                 bss->ss_flags |= SS_DISABLE;
  328         if ((sss->ss_flags & SVR4_SS_ONSTACK) != 0)
  329                 bss->ss_flags |= SS_ONSTACK;
  330         if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0)
  331 /*XXX*/         printf("svr4_to_native_sigaltstack: extra bits %x ignored\n",
  332                     sss->ss_flags & ~SVR4_SS_ALLBITS);
  333 }
  334 
  335 void
  336 native_to_svr4_32_sigaltstack(bss, sss)
  337         const struct sigaltstack *bss;
  338         struct svr4_32_sigaltstack *sss;
  339 {
  340 
  341         sss->ss_sp = (u_long)bss->ss_sp;
  342         sss->ss_size = bss->ss_size;
  343         sss->ss_flags = 0;
  344         if ((bss->ss_flags & SS_DISABLE) != 0)
  345                 sss->ss_flags |= SVR4_SS_DISABLE;
  346         if ((bss->ss_flags & SS_ONSTACK) != 0)
  347                 sss->ss_flags |= SVR4_SS_ONSTACK;
  348 }
  349 
  350 int
  351 svr4_32_sys_sigaction(l, v, retval)
  352         struct lwp *l;
  353         void *v;
  354         register_t *retval;
  355 {
  356         struct svr4_32_sys_sigaction_args /* {
  357                 syscallarg(int) signum;
  358                 syscallarg(const struct svr4_32_sigaction *) nsa;
  359                 syscallarg(struct svr4_32_sigaction *) osa;
  360         } */ *uap = v;
  361         struct svr4_32_sigaction nssa, ossa;
  362         struct sigaction nbsa, obsa;
  363         int error;
  364 
  365         if (SCARG(uap, nsa)) {
  366                 error = copyin((caddr_t)(u_long)SCARG(uap, nsa),
  367                                &nssa, sizeof(nssa));
  368                 if (error)
  369                         return (error);
  370                 svr4_32_to_native_sigaction(&nssa, &nbsa);
  371         }
  372         error = sigaction1(l->l_proc,
  373                            svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))],
  374             SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
  375             NULL, 0);
  376         if (error)
  377                 return (error);
  378         if (SCARG(uap, osa)) {
  379                 native_to_svr4_32_sigaction(&obsa, &ossa);
  380                 error = copyout(&ossa, (caddr_t)(u_long)SCARG(uap, osa),
  381                                 sizeof(ossa));
  382                 if (error)
  383                         return (error);
  384         }
  385         return (0);
  386 }
  387 
  388 int
  389 svr4_32_sys_sigaltstack(l, v, retval)
  390         struct lwp *l;
  391         void *v;
  392         register_t *retval;
  393 {
  394         struct svr4_32_sys_sigaltstack_args /* {
  395                 syscallarg(const struct svr4_32_sigaltstack *) nss;
  396                 syscallarg(struct svr4_32_sigaltstack *) oss;
  397         } */ *uap = v;
  398         struct svr4_32_sigaltstack nsss, osss;
  399         struct sigaltstack nbss, obss;
  400         int error;
  401 
  402         if (SCARG(uap, nss)) {
  403                 error = copyin((caddr_t)(u_long)SCARG(uap, nss),
  404                                &nsss, sizeof(nsss));
  405                 if (error)
  406                         return (error);
  407                 svr4_32_to_native_sigaltstack(&nsss, &nbss);
  408         }
  409         error = sigaltstack1(l->l_proc,
  410             SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0);
  411         if (error)
  412                 return (error);
  413         if (SCARG(uap, oss)) {
  414                 native_to_svr4_32_sigaltstack(&obss, &osss);
  415                 error = copyout(&osss, (caddr_t)(u_long)SCARG(uap, oss),
  416                                 sizeof(osss));
  417                 if (error)
  418                         return (error);
  419         }
  420         return (0);
  421 }
  422 
  423 /*
  424  * Stolen from the ibcs2 one
  425  */
  426 int
  427 svr4_32_sys_signal(l, v, retval)
  428         struct lwp *l;
  429         void *v;
  430         register_t *retval;
  431 {
  432         struct svr4_32_sys_signal_args /* {
  433                 syscallarg(int) signum;
  434                 syscallarg(svr4_32_sig_t) handler;
  435         } */ *uap = v;
  436         struct proc *p = l->l_proc;
  437         int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
  438         struct sigaction nbsa, obsa;
  439         sigset_t ss;
  440         int error;
  441 
  442         if (signum <= 0 || signum >= SVR4_NSIG)
  443                 return (EINVAL);
  444 
  445         switch (SVR4_SIGCALL(SCARG(uap, signum))) {
  446         case SVR4_SIGDEFER_MASK:
  447                 if (SCARG(uap, handler) == SVR4_SIG_HOLD)
  448                         goto sighold;
  449                 /* FALLTHROUGH */
  450 
  451         case SVR4_SIGNAL_MASK:
  452                 nbsa.sa_handler = (sig_t)SCARG(uap, handler);
  453                 sigemptyset(&nbsa.sa_mask);
  454                 nbsa.sa_flags = 0;
  455                 error = sigaction1(p, signum, &nbsa, &obsa, NULL, 0);
  456                 if (error)
  457                         return (error);
  458                 *retval = (u_int)(u_long)obsa.sa_handler;
  459                 return (0);
  460 
  461         case SVR4_SIGHOLD_MASK:
  462         sighold:
  463                 sigemptyset(&ss);
  464                 sigaddset(&ss, signum);
  465                 return (sigprocmask1(p, SIG_BLOCK, &ss, 0));
  466 
  467         case SVR4_SIGRELSE_MASK:
  468                 sigemptyset(&ss);
  469                 sigaddset(&ss, signum);
  470                 return (sigprocmask1(p, SIG_UNBLOCK, &ss, 0));
  471 
  472         case SVR4_SIGIGNORE_MASK:
  473                 nbsa.sa_handler = SIG_IGN;
  474                 sigemptyset(&nbsa.sa_mask);
  475                 nbsa.sa_flags = 0;
  476                 return (sigaction1(p, signum, &nbsa, 0, NULL, 0));
  477 
  478         case SVR4_SIGPAUSE_MASK:
  479                 ss = p->p_sigctx.ps_sigmask;
  480                 sigdelset(&ss, signum);
  481                 return (sigsuspend1(p, &ss));
  482 
  483         default:
  484                 return (ENOSYS);
  485         }
  486 }
  487 
  488 int
  489 svr4_32_sys_sigprocmask(l, v, retval)
  490         struct lwp *l;
  491         void *v;
  492         register_t *retval;
  493 {
  494         struct svr4_32_sys_sigprocmask_args /* {
  495                 syscallarg(int) how;
  496                 syscallarg(const svr4_32_sigset_t *) set;
  497                 syscallarg(svr4_32_sigset_t *) oset;
  498         } */ *uap = v;
  499         svr4_32_sigset_t nsss, osss;
  500         sigset_t nbss, obss;
  501         int how;
  502         int error;
  503 
  504         /*
  505          * Initialize how to 0 to avoid a compiler warning.  Note that
  506          * this is safe because of the check in the default: case.
  507          */
  508         how = 0;
  509 
  510         switch (SCARG(uap, how)) {
  511         case SVR4_SIG_BLOCK:
  512                 how = SIG_BLOCK;
  513                 break;
  514         case SVR4_SIG_UNBLOCK:
  515                 how = SIG_UNBLOCK;
  516                 break;
  517         case SVR4_SIG_SETMASK:
  518                 how = SIG_SETMASK;
  519                 break;
  520         default:
  521                 if (SCARG(uap, set))
  522                         return EINVAL;
  523                 break;
  524         }
  525 
  526         if (SCARG(uap, set)) {
  527                 error = copyin((caddr_t)(u_long)SCARG(uap, set),
  528                                &nsss, sizeof(nsss));
  529                 if (error)
  530                         return error;
  531                 svr4_32_to_native_sigset(&nsss, &nbss);
  532         }
  533         error = sigprocmask1(l->l_proc, how,
  534             SCARG(uap, set) ? &nbss : NULL, SCARG(uap, oset) ? &obss : NULL);
  535         if (error)
  536                 return error;
  537         if (SCARG(uap, oset)) {
  538                 native_to_svr4_32_sigset(&obss, &osss);
  539                 error = copyout(&osss, (caddr_t)(u_long)SCARG(uap, oset),
  540                                 sizeof(osss));
  541                 if (error)
  542                         return error;
  543         }
  544         return 0;
  545 }
  546 
  547 int
  548 svr4_32_sys_sigpending(l, v, retval)
  549         struct lwp *l;
  550         void *v;
  551         register_t *retval;
  552 {
  553         struct svr4_32_sys_sigpending_args /* {
  554                 syscallarg(int) what;
  555                 syscallarg(svr4_sigset_t *) set;
  556         } */ *uap = v;
  557         sigset_t bss;
  558         svr4_32_sigset_t sss;
  559 
  560         switch (SCARG(uap, what)) {
  561         case 1: /* sigpending */
  562                 sigpending1(l->l_proc, &bss);
  563                 native_to_svr4_32_sigset(&bss, &sss);
  564                 break;
  565 
  566         case 2: /* sigfillset */
  567                 svr4_32_sigfillset(&sss);
  568                 break;
  569 
  570         default:
  571                 return (EINVAL);
  572         }
  573         return (copyout(&sss, (caddr_t)(u_long)SCARG(uap, set), sizeof(sss)));
  574 }
  575 
  576 int
  577 svr4_32_sys_sigsuspend(l, v, retval)
  578         struct lwp *l;
  579         void *v;
  580         register_t *retval;
  581 {
  582         struct svr4_32_sys_sigsuspend_args /* {
  583                 syscallarg(const svr4_32_sigset_t *) set;
  584         } */ *uap = v;
  585         svr4_32_sigset_t sss;
  586         sigset_t bss;
  587         int error;
  588 
  589         if (SCARG(uap, set)) {
  590                 error = copyin((caddr_t)(u_long)SCARG(uap, set), &sss, sizeof(sss));
  591                 if (error)
  592                         return (error);
  593                 svr4_32_to_native_sigset(&sss, &bss);
  594         }
  595 
  596         return (sigsuspend1(l->l_proc, SCARG(uap, set) ? &bss : 0));
  597 }
  598 
  599 int
  600 svr4_32_sys_pause(l, v, retval)
  601         struct lwp *l;
  602         void *v;
  603         register_t *retval;
  604 {
  605 
  606         return (sigsuspend1(l->l_proc, 0));
  607 }
  608 
  609 int
  610 svr4_32_sys_kill(l, v, retval)
  611         struct lwp *l;
  612         void *v;
  613         register_t *retval;
  614 {
  615         struct svr4_32_sys_kill_args /* {
  616                 syscallarg(int) pid;
  617                 syscallarg(int) signum;
  618         } */ *uap = v;
  619         struct sys_kill_args ka;
  620 
  621         SCARG(&ka, pid) = SCARG(uap, pid);
  622         SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
  623         return sys_kill(l, &ka, retval);
  624 }
  625 
  626 void
  627 svr4_32_getcontext(l, uc, mask)
  628         struct lwp *l;
  629         struct svr4_32_ucontext *uc;
  630         const sigset_t *mask;
  631 {
  632         void *sp;
  633         struct svr4_32_sigaltstack *ss = &uc->uc_stack;
  634 
  635         memset(uc, 0, sizeof(*uc));
  636 
  637         /* get machine context */
  638         sp = svr4_32_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags);
  639 
  640         /* get link */
  641         uc->uc_link = (u_long)l->l_ctxlink;
  642 
  643         /* get stack state. XXX: solaris appears to do this */
  644 #if 0
  645         svr4_32_to_native_sigaltstack(&uc->uc_stack, &p->p_sigacts->ps_sigstk);
  646 #else
  647         ss->ss_sp = (((u_long) sp) & ~(16384 - 1));
  648         ss->ss_size = 16384;
  649         ss->ss_flags = 0;
  650 #endif
  651         /* get signal mask */
  652         native_to_svr4_32_sigset(mask, &uc->uc_sigmask);
  653 
  654         uc->uc_flags |= SVR4_UC_STACK|SVR4_UC_SIGMASK;
  655 }
  656 
  657 
  658 int
  659 svr4_32_setcontext(l, uc)
  660         struct lwp *l;
  661         struct svr4_32_ucontext *uc;
  662 {
  663         int error;
  664         struct proc *p = l->l_proc;
  665 
  666         /* set machine context */
  667         if ((error = svr4_32_setmcontext(l, &uc->uc_mcontext, uc->uc_flags)) != 0)
  668                 return error;
  669 
  670         /* set link */
  671         l->l_ctxlink = (caddr_t)(u_long)uc->uc_link;
  672 
  673         /* set signal stack */
  674         if (uc->uc_flags & SVR4_UC_STACK) {
  675                 svr4_32_to_native_sigaltstack(&uc->uc_stack,
  676                     &p->p_sigctx.ps_sigstk);
  677         }
  678 
  679         /* set signal mask */
  680         if (uc->uc_flags & SVR4_UC_SIGMASK) {
  681                 sigset_t mask;
  682 
  683                 svr4_32_to_native_sigset(&uc->uc_sigmask, &mask);
  684                 (void)sigprocmask1(p, SIG_SETMASK, &mask, 0);
  685         }
  686 
  687         return EJUSTRETURN;
  688 }
  689 
  690 int
  691 svr4_32_sys_context(l, v, retval)
  692         struct lwp *l;
  693         void *v;
  694         register_t *retval;
  695 {
  696         struct svr4_32_sys_context_args /* {
  697                 syscallarg(int) func;
  698                 syscallarg(struct svr4_32_ucontext *) uc;
  699         } */ *uap = v;
  700         struct proc *p = l->l_proc;
  701         struct svr4_32_ucontext uc;
  702         int error;
  703         *retval = 0;
  704 
  705         switch (SCARG(uap, func)) {
  706         case SVR4_GETCONTEXT:
  707                 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc)));
  708                 svr4_32_getcontext(l, &uc, &p->p_sigctx.ps_sigmask);
  709                 return copyout(&uc, (caddr_t)(u_long)SCARG(uap, uc), sizeof(uc));
  710 
  711         case SVR4_SETCONTEXT:
  712                 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc)));
  713                 if (!SCARG(uap, uc))
  714                         exit1(l, W_EXITCODE(0, 0));
  715                 else if ((error = copyin((caddr_t)(u_long)SCARG(uap, uc),
  716                                          &uc, sizeof(uc))) != 0)
  717                         return error;
  718                 else
  719                         return svr4_32_setcontext(l, &uc);
  720 
  721         default:
  722                 DPRINTF(("context(%d, %p)\n", SCARG(uap, func),
  723                     SCARG(uap, uc)));
  724                 return ENOSYS;
  725         }
  726         return 0;
  727 }

Cache object: ab922d0fb4d260c38be5eedfdf5adda2


[ 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.