Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / darwin / darwin_signal.c
blobd9533b048c293917273dee8f72f01c4c575d125d
1 /* $NetBSD: darwin_signal.c,v 1.28.8.2 2008/11/01 21:22:25 christos Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.28.8.2 2008/11/01 21:22:25 christos Exp $");
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>
43 #include <compat/sys/signal.h>
44 #include <compat/sys/signalvar.h>
46 #include <compat/common/compat_util.h>
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>
53 #include <compat/darwin/darwin_types.h>
54 #include <compat/darwin/darwin_audit.h>
55 #include <compat/darwin/darwin_exec.h>
56 #include <compat/darwin/darwin_signal.h>
57 #include <compat/darwin/darwin_syscallargs.h>
59 int
60 darwin_sys_sigaction(struct lwp *l, const struct darwin_sys_sigaction_args *uap, register_t *retval)
62 /* {
63 syscallarg(int) signum;
64 syscallarg(struct darwin___sigaction *) nsa;
65 syscallarg(struct sigaction13 *) osa;
66 } */
67 struct darwin___sigaction dsa;
68 struct sigaction nsa, osa;
69 struct sigaction13 sa13;
70 int error;
72 if ((error = copyin(SCARG(uap, nsa), &dsa, sizeof(dsa))) != 0)
73 return error;
75 nsa.sa_handler = dsa.darwin_sa_handler.__sa_handler;
76 native_sigset13_to_sigset(&dsa.darwin_sa_mask, &nsa.sa_mask);
77 if (dsa.darwin_sa_flags & ~DARWIN_SA_ALLBITS) {
78 DPRINTF(("darwin_sys_sigaction: ignoring bits (flags = %x)\n",
79 dsa.darwin_sa_flags));
81 nsa.sa_flags = dsa.darwin_sa_flags & DARWIN_SA_ALLBITS;
83 error = sigaction1(l, SCARG(uap, signum), &nsa, &osa,
84 dsa.darwin_sa_tramp, 1);
85 if (error != 0)
86 return error;
88 if (SCARG(uap, osa) == NULL)
89 return 0;
91 /* XXX: The returned structure has a different type to that supplied */
92 sa13.osa_handler = osa.sa_handler;
93 sa13.osa_mask = osa.sa_mask.__bits[0];
94 native_sigset_to_sigset13(&osa.sa_mask, &sa13.osa_mask);
95 sa13.osa_flags = osa.sa_flags;
97 return copyout(&sa13, SCARG(uap, osa), sizeof(sa13));
100 void
101 darwin_trapsignal(struct lwp *l, struct ksiginfo *ksi)
103 if (mach_trapsignal1(l, ksi) != 0)
104 trapsignal(l, ksi);
106 return;
110 darwin_tracesig(struct proc *p, int signo)
112 struct darwin_emuldata *ded;
113 struct lwp *l;
114 int code[2];
115 int error;
118 * If the process does not have softsignals,
119 * we are done, normal signal delivery should
120 * occur.
122 ded = (struct darwin_emuldata *)p->p_emuldata;
123 if ((ded->ded_flags & DARWIN_DED_SIGEXC) == 0)
124 return 0;
126 code[0] = MACH_SOFT_SIGNAL;
127 code[1] = signo;
128 l = LIST_FIRST(&p->p_lwps);
129 KASSERT(l != NULL);
130 error = mach_exception(l, MACH_EXC_SOFTWARE, code);
132 /* Inhibit normal signal delivery */
133 return EINVAL;
137 darwin_sys_sigprocmask(struct lwp *l, const struct darwin_sys_sigprocmask_args *uap, register_t *retval)
139 /* {
140 syscallarg(int) how;
141 syscallarg(sigset13_t *) set;
142 syscallarg(sigset13_t *) oset;
143 } */
144 int error;
145 sigset13_t kdset;
146 sigset_t kbset, kboset;
148 if (SCARG(uap, set) != NULL) {
149 error = copyin(SCARG(uap, set), &kdset, sizeof(kdset));
150 if (error != 0)
151 return error;
152 native_sigset13_to_sigset(&kdset, &kbset);
153 error = sigprocmask1(l, SCARG(uap, how), &kbset, &kboset);
154 } else
155 error = sigprocmask1(l, SCARG(uap, how), NULL, &kboset);
157 if (SCARG(uap, oset) == NULL || error != 0)
158 return error;
160 native_sigset_to_sigset13(&kboset, &kdset);
161 return copyout(&kdset, SCARG(uap, oset), sizeof(kdset));
164 void
165 native_to_darwin_siginfo(const struct ksiginfo *ksi, struct darwin___siginfo *dsi)
167 dsi->darwin_si_signo = ksi->ksi_signo;
168 dsi->darwin_si_errno = ksi->ksi_errno;
169 dsi->darwin_si_code = ksi->ksi_code;
170 dsi->darwin_si_pid = ksi->ksi_pid;
171 dsi->darwin_si_uid = ksi->ksi_uid;
172 dsi->darwin_si_status = ksi->ksi_status;
173 dsi->darwin_si_addr = ksi->ksi_addr;
174 (void)memcpy(&dsi->darwin_si_value,
175 &ksi->ksi_value, sizeof(dsi->darwin_si_value));
176 dsi->darwin_si_band = ksi->ksi_band;
178 return;