freebsd_misc.c revision 1.11 1 /* $NetBSD: freebsd_misc.c,v 1.11 2000/12/18 08:53:39 jdolecek Exp $ */
2
3 /*
4 * Copyright (c) 1995 Frank van der Linden
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Frank van der Linden
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * FreeBSD compatibility module. Try to deal with various FreeBSD system calls.
36 */
37
38 #if defined(_KERNEL) && !defined(_LKM)
39 #include "opt_ntp.h"
40 #include "opt_ktrace.h"
41 #endif
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/proc.h>
46 #include <sys/mount.h>
47 #include <sys/signal.h>
48 #include <sys/signalvar.h>
49 #include <sys/malloc.h>
50 #ifdef KTRACE
51 #include <sys/ktrace.h>
52 #endif
53
54 #include <sys/syscallargs.h>
55
56 #include <compat/freebsd/freebsd_syscallargs.h>
57 #include <compat/common/compat_util.h>
58 #include <compat/freebsd/freebsd_rtprio.h>
59 #include <compat/freebsd/freebsd_timex.h>
60 #include <compat/freebsd/freebsd_signal.h>
61
62 #ifdef KTRACE
63 void ktrinitheader(struct ktr_header *, struct proc *, int);
64 int ktrwrite(struct proc *, struct ktr_header *);
65 #endif
66
67 int
68 freebsd_sys_msync(p, v, retval)
69 struct proc *p;
70 void *v;
71 register_t *retval;
72 {
73 struct freebsd_sys_msync_args /* {
74 syscallarg(caddr_t) addr;
75 syscallarg(size_t) len;
76 syscallarg(int) flags;
77 } */ *uap = v;
78 struct sys___msync13_args bma;
79
80 /*
81 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
82 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
83 * but syscall number is not changed. :-<
84 */
85 SCARG(&bma, addr) = SCARG(uap, addr);
86 SCARG(&bma, len) = SCARG(uap, len);
87 SCARG(&bma, flags) = SCARG(uap, flags);
88 return sys___msync13(p, &bma, retval);
89 }
90
91 /* just a place holder */
92
93 int
94 freebsd_sys_rtprio(p, v, retval)
95 struct proc *p;
96 void *v;
97 register_t *retval;
98 {
99 #ifdef notyet
100 struct freebsd_sys_rtprio_args /* {
101 syscallarg(int) function;
102 syscallarg(pid_t) pid;
103 syscallarg(struct freebsd_rtprio *) rtp;
104 } */ *uap = v;
105 #endif
106
107 return ENOSYS; /* XXX */
108 }
109
110 #ifdef NTP
111 int
112 freebsd_ntp_adjtime(p, v, retval)
113 struct proc *p;
114 void *v;
115 register_t *retval;
116 {
117 #ifdef notyet
118 struct freebsd_ntp_adjtime_args /* {
119 syscallarg(struct freebsd_timex *) tp;
120 } */ *uap = v;
121 #endif
122
123 return ENOSYS; /* XXX */
124 }
125 #endif
126
127 int
128 freebsd_sys_sigaction4(p, v, retval)
129 struct proc *p;
130 void *v;
131 register_t *retval;
132 {
133 struct freebsd_sys_sigaction4_args /* {
134 syscallarg(int) signum;
135 syscallarg(const struct freebsd_sigaction4 *) nsa;
136 syscallarg(struct freebsd_sigaction4 *) osa;
137 } */ *uap = v;
138 struct freebsd_sigaction4 nesa, oesa;
139 struct sigaction nbsa, obsa;
140 int error;
141
142 if (SCARG(uap, nsa)) {
143 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
144 if (error)
145 return (error);
146 nbsa.sa_handler = nesa.sa_handler;
147 nbsa.sa_mask = nesa.sa_mask;
148 nbsa.sa_flags = nesa.sa_flags;
149 }
150 error = sigaction1(p, SCARG(uap, signum),
151 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0);
152 if (error)
153 return (error);
154 if (SCARG(uap, osa)) {
155 oesa.sa_handler = obsa.sa_handler;
156 oesa.sa_mask = obsa.sa_mask;
157 oesa.sa_flags = obsa.sa_flags;
158 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
159 if (error)
160 return (error);
161 }
162 return (0);
163 }
164
165 int
166 freebsd_sys_utrace(p, v, retval)
167 struct proc *p;
168 void *v;
169 register_t *retval;
170 {
171 #ifdef KTRACE
172 struct freebsd_sys_utrace_args /* {
173 syscallarg(void *) addr;
174 syscallarg(size_t) len;
175 } */ *uap = v;
176 struct ktr_header kth;
177 register caddr_t cp;
178 int error = 0;
179
180 if (!KTRPOINT(p, KTR_USER))
181 return (0);
182 p->p_traceflag |= KTRFAC_ACTIVE;
183 ktrinitheader(&kth, p, KTR_USER);
184 cp = (caddr_t) malloc(SCARG(uap, len), M_TEMP, M_WAITOK);
185 if ((error = copyin(SCARG(uap, addr), cp, SCARG(uap, len))) == 0) {
186 kth.ktr_buf = cp;
187 kth.ktr_len = SCARG(uap, len);
188 error = ktrwrite(p, &kth);
189 }
190 free(cp, M_TEMP);
191 p->p_traceflag &= ~KTRFAC_ACTIVE;
192
193 return (error);
194 #else
195 return ENOSYS;
196 #endif
197 }
198