| Commit | Line | Data |
|---|---|---|
| 65957d54 DRJ |
1 | /* |
| 2 | * 43BSD_SIGNAL.C - 4.3BSD compatibility signal syscalls | |
| 3 | * | |
| 4 | * Copyright (c) 1989, 1993 | |
| 5 | * The Regents of the University of California. All rights reserved. | |
| 6 | * (c) UNIX System Laboratories, Inc. | |
| 7 | * All or some portions of this file are derived from material licensed | |
| 8 | * to the University of California by American Telephone and Telegraph | |
| 9 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
| 10 | * the permission of UNIX System Laboratories, Inc. | |
| 11 | * | |
| 12 | * Redistribution and use in source and binary forms, with or without | |
| 13 | * modification, are permitted provided that the following conditions | |
| 14 | * are met: | |
| 15 | * 1. Redistributions of source code must retain the above copyright | |
| 16 | * notice, this list of conditions and the following disclaimer. | |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 18 | * notice, this list of conditions and the following disclaimer in the | |
| 19 | * documentation and/or other materials provided with the distribution. | |
| 20 | * 3. All advertising materials mentioning features or use of this software | |
| 21 | * must display the following acknowledgement: | |
| 22 | * This product includes software developed by the University of | |
| 23 | * California, Berkeley and its contributors. | |
| 24 | * 4. Neither the name of the University nor the names of its contributors | |
| 25 | * may be used to endorse or promote products derived from this software | |
| 26 | * without specific prior written permission. | |
| 27 | * | |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
| 29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
| 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 38 | * SUCH DAMAGE. | |
| 39 | * | |
| f9366a82 | 40 | * $DragonFly: src/sys/emulation/43bsd/43bsd_signal.c,v 1.5 2007/03/12 21:07:42 corecode Exp $ |
| 65957d54 DRJ |
41 | * from: DragonFly kern/kern_sig.c,v 1.22 |
| 42 | * | |
| 43 | * These syscalls used to live in kern/kern_sig.c. They are modified | |
| 44 | * to use the new split syscalls. | |
| 45 | */ | |
| 46 | ||
| 47 | #include "opt_compat.h" | |
| 48 | ||
| 49 | #include <sys/param.h> | |
| 50 | #include <sys/systm.h> | |
| 51 | #include <sys/sysproto.h> | |
| 52 | #include <sys/conf.h> | |
| 53 | #include <sys/kernel.h> | |
| 54 | #include <sys/kern_syscall.h> | |
| 55 | #include <sys/proc.h> | |
| 56 | #include <sys/signal.h> | |
| 57 | #include <sys/signalvar.h> | |
| 684a93c4 | 58 | |
| 9ec81f83 | 59 | #include <sys/thread2.h> |
| 65957d54 DRJ |
60 | |
| 61 | #define ONSIG 32 /* NSIG for osig* syscalls. XXX. */ | |
| 62 | ||
| 63 | #define SIG2OSIG(sig, osig) osig = (sig).__bits[0] | |
| 64 | #define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig | |
| 65 | ||
| 66 | #define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) | |
| 67 | ||
| 68 | /* | |
| 69 | * These syscalls are unncessary because it is next to impossible to | |
| 70 | * find 4.3BSD binaries built for i386. The current libc has routines | |
| 71 | * which fake the 4.3BSD family of signal syscalls, so anything built | |
| 72 | * from source won't be using these. | |
| 73 | * | |
| 74 | * This file is provided for educational purposes only. The osigvec() | |
| 75 | * syscall is probably broken because the current signal code uses | |
| 76 | * a different signal trampoline. | |
| 3919ced0 MD |
77 | * |
| 78 | * MPALMOSTSAFE | |
| 65957d54 | 79 | */ |
| 65957d54 | 80 | int |
| 753fd850 | 81 | sys_osigvec(struct osigvec_args *uap) |
| 65957d54 DRJ |
82 | { |
| 83 | struct sigvec vec; | |
| 84 | struct sigaction nsa, osa; | |
| 85 | struct sigaction *nsap, *osap; | |
| 86 | int error; | |
| 87 | ||
| 88 | if (uap->signum <= 0 || uap->signum >= ONSIG) | |
| 89 | return (EINVAL); | |
| 90 | nsap = (uap->nsv != NULL) ? &nsa : NULL; | |
| 91 | osap = (uap->osv != NULL) ? &osa : NULL; | |
| 92 | if (nsap) { | |
| 93 | error = copyin(uap->nsv, &vec, sizeof(vec)); | |
| 94 | if (error) | |
| 95 | return (error); | |
| 96 | nsap->sa_handler = vec.sv_handler; | |
| 97 | OSIG2SIG(vec.sv_mask, nsap->sa_mask); | |
| 98 | nsap->sa_flags = vec.sv_flags; | |
| 99 | nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */ | |
| 100 | } | |
| 101 | ||
| 102 | error = kern_sigaction(uap->signum, nsap, osap); | |
| 103 | ||
| 104 | if (osap && !error) { | |
| 105 | vec.sv_handler = osap->sa_handler; | |
| 106 | SIG2OSIG(osap->sa_mask, vec.sv_mask); | |
| 107 | vec.sv_flags = osap->sa_flags; | |
| 108 | vec.sv_flags &= ~SA_NOCLDWAIT; | |
| 109 | vec.sv_flags ^= SA_RESTART; | |
| 110 | error = copyout(&vec, uap->osv, sizeof(vec)); | |
| 111 | } | |
| 112 | return (error); | |
| 113 | } | |
| 114 | ||
| 3919ced0 MD |
115 | /* |
| 116 | * MPSAFE | |
| 117 | */ | |
| 65957d54 | 118 | int |
| 753fd850 | 119 | sys_osigblock(struct osigblock_args *uap) |
| 65957d54 | 120 | { |
| 08f2f1bb | 121 | struct lwp *lp = curthread->td_lwp; |
| 65957d54 DRJ |
122 | sigset_t set; |
| 123 | ||
| 124 | OSIG2SIG(uap->mask, set); | |
| 125 | SIG_CANTMASK(set); | |
| 9ec81f83 | 126 | crit_enter(); |
| e54488bb | 127 | SIG2OSIG(lp->lwp_sigmask, uap->sysmsg_iresult); |
| 08f2f1bb | 128 | SIGSETOR(lp->lwp_sigmask, set); |
| 9ec81f83 | 129 | crit_exit(); |
| 65957d54 DRJ |
130 | return (0); |
| 131 | } | |
| 132 | ||
| 3919ced0 MD |
133 | /* |
| 134 | * MPSAFE | |
| 135 | */ | |
| 65957d54 | 136 | int |
| 753fd850 | 137 | sys_osigsetmask(struct osigsetmask_args *uap) |
| 65957d54 | 138 | { |
| 08f2f1bb | 139 | struct lwp *lp = curthread->td_lwp; |
| 65957d54 DRJ |
140 | sigset_t set; |
| 141 | ||
| 142 | OSIG2SIG(uap->mask, set); | |
| 143 | SIG_CANTMASK(set); | |
| 9ec81f83 | 144 | crit_enter(); |
| e54488bb | 145 | SIG2OSIG(lp->lwp_sigmask, uap->sysmsg_iresult); |
| 08f2f1bb | 146 | SIGSETLO(lp->lwp_sigmask, set); |
| 9ec81f83 | 147 | crit_exit(); |
| 65957d54 DRJ |
148 | return (0); |
| 149 | } | |
| 150 | ||
| 3919ced0 MD |
151 | /* |
| 152 | * MPSAFE | |
| 153 | */ | |
| 65957d54 | 154 | int |
| 753fd850 | 155 | sys_osigstack(struct osigstack_args *uap) |
| 65957d54 | 156 | { |
| 08f2f1bb | 157 | struct lwp *lp = curthread->td_lwp; |
| 65957d54 DRJ |
158 | struct sigstack ss; |
| 159 | int error = 0; | |
| 160 | ||
| 08f2f1bb SS |
161 | ss.ss_sp = lp->lwp_sigstk.ss_sp; |
| 162 | ss.ss_onstack = lp->lwp_sigstk.ss_flags & SS_ONSTACK; | |
| 65957d54 | 163 | if (uap->oss && (error = copyout(&ss, uap->oss, |
| 3919ced0 | 164 | sizeof(struct sigstack)))) { |
| 65957d54 | 165 | return (error); |
| 3919ced0 | 166 | } |
| 65957d54 | 167 | if (uap->nss && (error = copyin(uap->nss, &ss, sizeof(ss))) == 0) { |
| 08f2f1bb SS |
168 | lp->lwp_sigstk.ss_sp = ss.ss_sp; |
| 169 | lp->lwp_sigstk.ss_size = 0; | |
| 170 | lp->lwp_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK; | |
| 4643740a | 171 | lp->lwp_flags |= LWP_ALTSTACK; |
| 65957d54 DRJ |
172 | } |
| 173 | return (error); | |
| 174 | } | |
| 175 | ||
| 176 | int | |
| 753fd850 | 177 | sys_okillpg(struct okillpg_args *uap) |
| 65957d54 DRJ |
178 | { |
| 179 | int error; | |
| 180 | ||
| f9366a82 | 181 | error = kern_kill(uap->signum, -uap->pgid, -1); |
| 65957d54 DRJ |
182 | |
| 183 | return (error); | |
| 184 | } |