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/common/kern_sig_43.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: kern_sig_43.c,v 1.32 2008/04/28 20:23:41 martin Exp $  */
    2 
    3 /*-
    4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * 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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: kern_sig_43.c,v 1.32 2008/04/28 20:23:41 martin Exp $");
   34 
   35 #if defined(_KERNEL_OPT)
   36 #include "opt_compat_netbsd.h"
   37 #endif
   38 
   39 #include <sys/param.h>
   40 #include <sys/signalvar.h>
   41 #include <sys/resourcevar.h>
   42 #include <sys/namei.h>
   43 #include <sys/vnode.h>
   44 #include <sys/proc.h>
   45 #include <sys/systm.h>
   46 #include <sys/timeb.h>
   47 #include <sys/times.h>
   48 #include <sys/buf.h>
   49 #include <sys/acct.h>
   50 #include <sys/file.h>
   51 #include <sys/kernel.h>
   52 #include <sys/wait.h>
   53 #include <sys/ktrace.h>
   54 #include <sys/syslog.h>
   55 #include <sys/stat.h>
   56 #include <sys/core.h>
   57 #include <sys/kauth.h>
   58 
   59 #include <sys/mount.h>
   60 #include <sys/syscallargs.h>
   61 
   62 #include <sys/cpu.h>
   63 
   64 #include <sys/user.h>           /* for coredump */
   65 
   66 #include <compat/sys/signal.h>
   67 
   68 void compat_43_sigmask_to_sigset(const int *, sigset_t *);
   69 void compat_43_sigset_to_sigmask(const sigset_t *, int *);
   70 void compat_43_sigvec_to_sigaction(const struct sigvec *, struct sigaction *);
   71 void compat_43_sigaction_to_sigvec(const struct sigaction *, struct sigvec *);
   72 void compat_43_sigstack_to_sigaltstack(const struct sigstack *, struct sigaltstack *);
   73 void compat_43_sigaltstack_to_sigstack(const struct sigaltstack *, struct sigstack *);
   74 
   75 void
   76 compat_43_sigmask_to_sigset(const int *sm, sigset_t *ss)
   77 {
   78 
   79         ss->__bits[0] = *sm;
   80         ss->__bits[1] = 0;
   81         ss->__bits[2] = 0;
   82         ss->__bits[3] = 0;
   83 }
   84 
   85 void
   86 compat_43_sigset_to_sigmask(const sigset_t *ss, int *sm)
   87 {
   88 
   89         *sm = ss->__bits[0];
   90 }
   91 
   92 void
   93 compat_43_sigvec_to_sigaction(const struct sigvec *sv, struct sigaction *sa)
   94 {
   95         sa->sa_handler = sv->sv_handler;
   96         compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
   97         sa->sa_flags = sv->sv_flags ^ SA_RESTART;
   98 }
   99 
  100 void
  101 compat_43_sigaction_to_sigvec(const struct sigaction *sa, struct sigvec *sv)
  102 {
  103         sv->sv_handler = sa->sa_handler;
  104         compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
  105         sv->sv_flags = sa->sa_flags ^ SA_RESTART;
  106 }
  107 
  108 void
  109 compat_43_sigstack_to_sigaltstack(const struct sigstack *ss, struct sigaltstack *sa)
  110 {
  111         sa->ss_sp = ss->ss_sp;
  112         sa->ss_size = SIGSTKSZ; /* Use the recommended size */
  113         sa->ss_flags = 0;
  114         if (ss->ss_onstack)
  115                 sa->ss_flags |= SS_ONSTACK;
  116 }
  117 
  118 void
  119 compat_43_sigaltstack_to_sigstack(const struct sigaltstack *sa, struct sigstack *ss)
  120 {
  121         ss->ss_sp = sa->ss_sp;
  122         if (sa->ss_flags & SS_ONSTACK)
  123                 ss->ss_onstack = 1;
  124         else
  125                 ss->ss_onstack = 0;
  126 }
  127 
  128 int
  129 compat_43_sys_sigblock(struct lwp *l, const struct compat_43_sys_sigblock_args *uap, register_t *retval)
  130 {
  131         /* {
  132                 syscallarg(int) mask;
  133         } */
  134         struct proc *p = l->l_proc;
  135         int nsm, osm;
  136         sigset_t nss, oss;
  137         int error;
  138 
  139         nsm = SCARG(uap, mask);
  140         compat_43_sigmask_to_sigset(&nsm, &nss);
  141         mutex_enter(p->p_lock);
  142         error = sigprocmask1(l, SIG_BLOCK, &nss, &oss);
  143         mutex_exit(p->p_lock);
  144         if (error)
  145                 return (error);
  146         compat_43_sigset_to_sigmask(&oss, &osm);
  147         *retval = osm;
  148         return (0);
  149 }
  150 
  151 int
  152 compat_43_sys_sigsetmask(struct lwp *l, const struct compat_43_sys_sigsetmask_args *uap, register_t *retval)
  153 {
  154         /* {
  155                 syscallarg(int) mask;
  156         } */
  157         struct proc *p = l->l_proc;
  158         int nsm, osm;
  159         sigset_t nss, oss;
  160         int error;
  161 
  162         nsm = SCARG(uap, mask);
  163         compat_43_sigmask_to_sigset(&nsm, &nss);
  164         mutex_enter(p->p_lock);
  165         error = sigprocmask1(l, SIG_SETMASK, &nss, &oss);
  166         mutex_exit(p->p_lock);
  167         if (error)
  168                 return (error);
  169         compat_43_sigset_to_sigmask(&oss, &osm);
  170         *retval = osm;
  171         return (0);
  172 }
  173 
  174 /* ARGSUSED */
  175 int
  176 compat_43_sys_sigstack(struct lwp *l, const struct compat_43_sys_sigstack_args *uap, register_t *retval)
  177 {
  178         /* {
  179                 syscallarg(struct sigstack *) nss;
  180                 syscallarg(struct sigstack *) oss;
  181         } */
  182         struct sigstack nss, oss;
  183         struct sigaltstack nsa, osa;
  184         int error;
  185 
  186         if (SCARG(uap, nss)) {
  187                 error = copyin(SCARG(uap, nss), &nss, sizeof(nss));
  188                 if (error)
  189                         return (error);
  190                 compat_43_sigstack_to_sigaltstack(&nss, &nsa);
  191         }
  192         error = sigaltstack1(l,
  193             SCARG(uap, nss) ? &nsa : 0, SCARG(uap, oss) ? &osa : 0);
  194         if (error)
  195                 return (error);
  196         if (SCARG(uap, oss)) {
  197                 compat_43_sigaltstack_to_sigstack(&osa, &oss);
  198                 error = copyout(&oss, SCARG(uap, oss), sizeof(oss));
  199                 if (error)
  200                         return (error);
  201         }
  202         return (0);
  203 }
  204 
  205 /*
  206  * Generalized interface signal handler, 4.3-compatible.
  207  */
  208 /* ARGSUSED */
  209 int
  210 compat_43_sys_sigvec(struct lwp *l, const struct compat_43_sys_sigvec_args *uap, register_t *retval)
  211 {
  212         /* {
  213                 syscallarg(int) signum;
  214                 syscallarg(const struct sigvec *) nsv;
  215                 syscallarg(struct sigvec *) osv;
  216         } */
  217         struct sigvec nsv, osv;
  218         struct sigaction nsa, osa;
  219         int error;
  220 
  221         if (SCARG(uap, nsv)) {
  222                 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
  223                 if (error)
  224                         return (error);
  225                 compat_43_sigvec_to_sigaction(&nsv, &nsa);
  226         }
  227         error = sigaction1(l, SCARG(uap, signum),
  228             SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
  229             NULL, 0);
  230         if (error)
  231                 return (error);
  232         if (SCARG(uap, osv)) {
  233                 compat_43_sigaction_to_sigvec(&osa, &osv);
  234                 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
  235                 if (error)
  236                         return (error);
  237         }
  238         return (0);
  239 }
  240 
  241 
  242 /* ARGSUSED */
  243 int
  244 compat_43_sys_killpg(struct lwp *l, const struct compat_43_sys_killpg_args *uap, register_t *retval)
  245 {
  246         /* {
  247                 syscallarg(int) pgid;
  248                 syscallarg(int) signum;
  249         } */
  250         ksiginfo_t ksi;
  251         int pgid = SCARG(uap, pgid);
  252 
  253 #ifdef COMPAT_09
  254         pgid &= 0xffff;
  255 #endif
  256 
  257         if ((u_int)SCARG(uap, signum) >= NSIG)
  258                 return (EINVAL);
  259         memset(&ksi, 0, sizeof(ksi));
  260         ksi.ksi_signo = SCARG(uap, signum);
  261         ksi.ksi_code = SI_USER;
  262         ksi.ksi_pid = l->l_proc->p_pid;
  263         ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
  264         return killpg1(l, &ksi, pgid, 0);
  265 }

Cache object: c102cf96647c7496f32b8df314069537


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