Some laptops return other values for working toucpads. Allow test_aux_port to
[dragonfly.git] / sys / emulation / 43bsd / 43bsd_signal.c
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  *
40  * $DragonFly: src/sys/emulation/43bsd/43bsd_signal.c,v 1.1 2003/10/24 14:10:45 daver Exp $
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>
58
59 #define ONSIG   32              /* NSIG for osig* syscalls.  XXX. */
60
61 #define SIG2OSIG(sig, osig)     osig = (sig).__bits[0]
62 #define OSIG2SIG(osig, sig)     SIGEMPTYSET(sig); (sig).__bits[0] = osig
63
64 #define SIGSETLO(set1, set2)    ((set1).__bits[0] = (set2).__bits[0])
65
66 /*
67  * These syscalls are unncessary because it is next to impossible to
68  * find 4.3BSD binaries built for i386.  The current libc has routines
69  * which fake the 4.3BSD family of signal syscalls, so anything built
70  * from source won't be using these.
71  *
72  * This file is provided for educational purposes only.  The osigvec()
73  * syscall is probably broken because the current signal code uses
74  * a different signal trampoline.
75  */
76
77 int
78 osigvec(struct osigvec_args *uap)
79 {
80         struct sigvec vec;
81         struct sigaction nsa, osa;
82         struct sigaction *nsap, *osap;
83         int error;
84
85         if (uap->signum <= 0 || uap->signum >= ONSIG)
86                 return (EINVAL);
87         nsap = (uap->nsv != NULL) ? &nsa : NULL;
88         osap = (uap->osv != NULL) ? &osa : NULL;
89         if (nsap) {
90                 error = copyin(uap->nsv, &vec, sizeof(vec));
91                 if (error)
92                         return (error);
93                 nsap->sa_handler = vec.sv_handler;
94                 OSIG2SIG(vec.sv_mask, nsap->sa_mask);
95                 nsap->sa_flags = vec.sv_flags;
96                 nsap->sa_flags ^= SA_RESTART;   /* opposite of SV_INTERRUPT */
97         }
98
99         error = kern_sigaction(uap->signum, nsap, osap);
100
101         if (osap && !error) {
102                 vec.sv_handler = osap->sa_handler;
103                 SIG2OSIG(osap->sa_mask, vec.sv_mask);
104                 vec.sv_flags = osap->sa_flags;
105                 vec.sv_flags &= ~SA_NOCLDWAIT;
106                 vec.sv_flags ^= SA_RESTART;
107                 error = copyout(&vec, uap->osv, sizeof(vec));
108         }
109         return (error);
110 }
111
112 int
113 osigblock(struct osigblock_args *uap)
114 {
115         struct proc *p = curproc;
116         sigset_t set;
117
118         OSIG2SIG(uap->mask, set);
119         SIG_CANTMASK(set);
120         (void) splhigh();
121         SIG2OSIG(p->p_sigmask, uap->sysmsg_result);
122         SIGSETOR(p->p_sigmask, set);
123         (void) spl0();
124         return (0);
125 }
126
127 int
128 osigsetmask(struct osigsetmask_args *uap)
129 {
130         struct proc *p = curproc;
131         sigset_t set;
132
133         OSIG2SIG(uap->mask, set);
134         SIG_CANTMASK(set);
135         (void) splhigh();
136         SIG2OSIG(p->p_sigmask, uap->sysmsg_result);
137         SIGSETLO(p->p_sigmask, set);
138         (void) spl0();
139         return (0);
140 }
141
142 int
143 osigstack(struct osigstack_args *uap)
144 {
145         struct proc *p = curproc;
146         struct sigstack ss;
147         int error = 0;
148
149         ss.ss_sp = p->p_sigstk.ss_sp;
150         ss.ss_onstack = p->p_sigstk.ss_flags & SS_ONSTACK;
151         if (uap->oss && (error = copyout(&ss, uap->oss,
152             sizeof(struct sigstack))))
153                 return (error);
154         if (uap->nss && (error = copyin(uap->nss, &ss, sizeof(ss))) == 0) {
155                 p->p_sigstk.ss_sp = ss.ss_sp;
156                 p->p_sigstk.ss_size = 0;
157                 p->p_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK;
158                 p->p_flag |= P_ALTSTACK;
159         }
160         return (error);
161 }
162
163 int
164 okillpg(struct okillpg_args *uap)
165 {
166         int error;
167
168         error = kern_kill(uap->signum, -uap->pgid);
169
170         return (error);
171 }