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/darwin/darwin_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: darwin_signal.c,v 1.30 2008/07/02 19:49:58 rmind Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Emmanuel Dreyfus.
    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: darwin_signal.c,v 1.30 2008/07/02 19:49:58 rmind Exp $");
   34 
   35 #include <sys/types.h>
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/mount.h>
   39 #include <sys/proc.h>
   40 #include <sys/signal.h>
   41 #include <sys/syscallargs.h>
   42 
   43 #include <compat/sys/signal.h>
   44 #include <compat/sys/signalvar.h>
   45 
   46 #include <compat/common/compat_util.h>
   47 
   48 #include <compat/mach/mach_types.h>
   49 #include <compat/mach/mach_vm.h>
   50 #include <compat/mach/mach_port.h>
   51 #include <compat/mach/mach_exception.h>
   52 
   53 #include <compat/darwin/darwin_audit.h>
   54 #include <compat/darwin/darwin_exec.h>
   55 #include <compat/darwin/darwin_signal.h>
   56 #include <compat/darwin/darwin_syscallargs.h>
   57 
   58 int
   59 darwin_sys_sigaction(struct lwp *l, const struct darwin_sys_sigaction_args *uap, register_t *retval)
   60 {
   61         /* {
   62                 syscallarg(int) signum;
   63                 syscallarg(struct darwin___sigaction *) nsa;
   64                 syscallarg(struct sigaction13 *) osa;
   65         } */
   66         struct darwin___sigaction dsa;
   67         struct sigaction nsa, osa;
   68         struct sigaction13 sa13;
   69         int error;
   70 
   71         if ((error = copyin(SCARG(uap, nsa), &dsa, sizeof(dsa))) != 0)
   72                 return error;
   73 
   74         nsa.sa_handler = dsa.darwin_sa_handler.__sa_handler;
   75         native_sigset13_to_sigset(&dsa.darwin_sa_mask, &nsa.sa_mask);
   76         if (dsa.darwin_sa_flags & ~DARWIN_SA_ALLBITS) {
   77                 DPRINTF(("darwin_sys_sigaction: ignoring bits (flags = %x)\n",
   78                     dsa.darwin_sa_flags));
   79         }
   80         nsa.sa_flags = dsa.darwin_sa_flags & DARWIN_SA_ALLBITS;
   81 
   82         error = sigaction1(l, SCARG(uap, signum), &nsa, &osa,
   83             dsa.darwin_sa_tramp, 1);
   84         if (error != 0)
   85                 return error;
   86 
   87         if (SCARG(uap, osa) == NULL)
   88                 return 0;
   89 
   90         /* XXX: The returned structure has a different type to that supplied */
   91         sa13.osa_handler = osa.sa_handler;
   92         sa13.osa_mask = osa.sa_mask.__bits[0];
   93         native_sigset_to_sigset13(&osa.sa_mask, &sa13.osa_mask);
   94         sa13.osa_flags = osa.sa_flags;
   95 
   96         return copyout(&sa13, SCARG(uap, osa), sizeof(sa13));
   97 }
   98 
   99 void
  100 darwin_trapsignal(struct lwp *l, struct ksiginfo *ksi)
  101 {
  102         if (mach_trapsignal1(l, ksi) != 0)
  103                 trapsignal(l, ksi);
  104 
  105         return;
  106 }
  107 
  108 int
  109 darwin_tracesig(struct proc *p, int signo)
  110 {
  111         struct darwin_emuldata *ded;
  112         struct lwp *l;
  113         int code[2];
  114         int error;
  115 
  116         /*
  117          * If the process does not have softsignals,
  118          * we are done, normal signal delivery should
  119          * occur.
  120          */
  121         ded = (struct darwin_emuldata *)p->p_emuldata;
  122         if ((ded->ded_flags & DARWIN_DED_SIGEXC) == 0)
  123                 return 0;
  124 
  125         code[0] = MACH_SOFT_SIGNAL;
  126         code[1] = signo;
  127         l = LIST_FIRST(&p->p_lwps);
  128         KASSERT(l != NULL);
  129         error = mach_exception(l, MACH_EXC_SOFTWARE, code);
  130 
  131         /* Inhibit normal signal delivery */
  132         return EINVAL;
  133 }
  134 
  135 int
  136 darwin_sys_sigprocmask(struct lwp *l, const struct darwin_sys_sigprocmask_args *uap, register_t *retval)
  137 {
  138         /* {
  139                 syscallarg(int) how;
  140                 syscallarg(sigset13_t *) set;
  141                 syscallarg(sigset13_t *) oset;
  142         } */
  143         int error;
  144         sigset13_t kdset;
  145         sigset_t kbset, kboset;
  146 
  147         if (SCARG(uap, set) != NULL) {
  148                 error = copyin(SCARG(uap, set), &kdset, sizeof(kdset));
  149                 if (error != 0)
  150                         return error;
  151                 native_sigset13_to_sigset(&kdset, &kbset);
  152                 error = sigprocmask1(l, SCARG(uap, how), &kbset, &kboset);
  153         } else
  154                 error = sigprocmask1(l, SCARG(uap, how), NULL, &kboset);
  155 
  156         if (SCARG(uap, oset) == NULL || error != 0)
  157                 return error;
  158 
  159         native_sigset_to_sigset13(&kboset, &kdset);
  160         return copyout(&kdset, SCARG(uap, oset), sizeof(kdset));
  161 }
  162 
  163 void
  164 native_to_darwin_siginfo(const struct ksiginfo *ksi, struct darwin___siginfo *dsi)
  165 {
  166         dsi->darwin_si_signo = ksi->ksi_signo;
  167         dsi->darwin_si_errno = ksi->ksi_errno;
  168         dsi->darwin_si_code = ksi->ksi_code;
  169         dsi->darwin_si_pid = ksi->ksi_pid;
  170         dsi->darwin_si_uid = ksi->ksi_uid;
  171         dsi->darwin_si_status = ksi->ksi_status;
  172         dsi->darwin_si_addr = ksi->ksi_addr;
  173         (void)memcpy(&dsi->darwin_si_value,
  174             &ksi->ksi_value, sizeof(dsi->darwin_si_value));
  175         dsi->darwin_si_band = ksi->ksi_band;
  176 
  177         return;
  178 }

Cache object: 77f5e85e60bb10a178ffbb790fad1272


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