freebsd_misc.c revision 1.32.12.1 1 /* $NetBSD: freebsd_misc.c,v 1.32.12.1 2008/05/10 23:48:49 wrstuden 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 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: freebsd_misc.c,v 1.32.12.1 2008/05/10 23:48:49 wrstuden Exp $");
40
41 #if defined(_KERNEL_OPT)
42 #include "opt_ntp.h"
43 #endif
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/proc.h>
48 #include <sys/mount.h>
49 #include <sys/signal.h>
50 #include <sys/signalvar.h>
51 #include <sys/malloc.h>
52 #include <sys/mman.h>
53 #include <sys/ktrace.h>
54
55 #include <sys/sa.h>
56 #include <sys/syscallargs.h>
57
58 #include <compat/freebsd/freebsd_syscallargs.h>
59 #include <compat/common/compat_util.h>
60 #include <compat/freebsd/freebsd_rtprio.h>
61 #include <compat/freebsd/freebsd_timex.h>
62 #include <compat/freebsd/freebsd_signal.h>
63 #include <compat/freebsd/freebsd_mman.h>
64
65 int
66 freebsd_sys_msync(struct lwp *l, const struct freebsd_sys_msync_args *uap, register_t *retval)
67 {
68 /* {
69 syscallarg(void *) addr;
70 syscallarg(size_t) len;
71 syscallarg(int) flags;
72 } */
73 struct sys___msync13_args bma;
74
75 /*
76 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
77 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
78 * but syscall number is not changed. :-<
79 */
80 SCARG(&bma, addr) = SCARG(uap, addr);
81 SCARG(&bma, len) = SCARG(uap, len);
82 SCARG(&bma, flags) = SCARG(uap, flags);
83 return sys___msync13(l, &bma, retval);
84 }
85
86 int
87 freebsd_sys_mmap(struct lwp *l, const struct freebsd_sys_mmap_args *uap, register_t *retval)
88 {
89 /* {
90 syscallarg(void *) addr;
91 syscallarg(size_t) len;
92 syscallarg(int) prot;
93 syscallarg(int) flags;
94 syscallarg(int) fd;
95 syscallarg(long) pad;
96 syscallarg(off_t) pos;
97 } */
98 struct sys_mmap_args bma;
99 int flags, prot, fd;
100 off_t pos;
101
102 prot = SCARG(uap, prot);
103 flags = SCARG(uap, flags);
104 fd = SCARG(uap, fd);
105 pos = SCARG(uap, pos);
106
107 /*
108 * If using MAP_STACK on FreeBSD:
109 *
110 * + fd has to be -1
111 * + prot must have read and write
112 * + MAP_STACK implies MAP_ANON
113 * + MAP_STACK implies offset of 0
114 */
115 if (flags & FREEBSD_MAP_STACK) {
116 if ((fd != -1)
117 ||((prot & (PROT_READ|PROT_WRITE))!=(PROT_READ|PROT_WRITE)))
118 return (EINVAL);
119
120 flags |= (MAP_ANON | MAP_FIXED);
121 flags &= ~FREEBSD_MAP_STACK;
122
123 pos = 0;
124 }
125
126 SCARG(&bma, addr) = SCARG(uap, addr);
127 SCARG(&bma, len) = SCARG(uap, len);
128 SCARG(&bma, prot) = prot;
129 SCARG(&bma, flags) = flags;
130 SCARG(&bma, fd) = fd;
131 SCARG(&bma, pos) = pos;
132
133 return sys_mmap(l, &bma, retval);
134 }
135
136 /* just a place holder */
137
138 int
139 freebsd_sys_rtprio(struct lwp *l, const struct freebsd_sys_rtprio_args *uap, register_t *retval)
140 {
141 /* {
142 syscallarg(int) function;
143 syscallarg(pid_t) pid;
144 syscallarg(struct freebsd_rtprio *) rtp;
145 } */
146
147 return ENOSYS; /* XXX */
148 }
149
150 #ifdef NTP
151 int
152 freebsd_ntp_adjtime(struct lwp *l, const struct freebsd_ntp_adjtime_args *uap, register_t *retval)
153 {
154 /* {
155 syscallarg(struct freebsd_timex *) tp;
156 } */
157
158 return ENOSYS; /* XXX */
159 }
160 #endif
161
162 int
163 freebsd_sys_sigaction4(struct lwp *l, const struct freebsd_sys_sigaction4_args *uap, register_t *retval)
164 {
165 /* {
166 syscallarg(int) signum;
167 syscallarg(const struct freebsd_sigaction4 *) nsa;
168 syscallarg(struct freebsd_sigaction4 *) osa;
169 } */
170 struct freebsd_sigaction4 nesa, oesa;
171 struct sigaction nbsa, obsa;
172 int error;
173
174 if (SCARG(uap, nsa)) {
175 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
176 if (error)
177 return (error);
178 nbsa.sa_handler = nesa.freebsd_sa_handler;
179 nbsa.sa_mask = nesa.freebsd_sa_mask;
180 nbsa.sa_flags = nesa.freebsd_sa_flags;
181 }
182 error = sigaction1(l, SCARG(uap, signum),
183 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
184 NULL, 0);
185 if (error)
186 return (error);
187 if (SCARG(uap, osa)) {
188 oesa.freebsd_sa_handler = obsa.sa_handler;
189 oesa.freebsd_sa_mask = obsa.sa_mask;
190 oesa.freebsd_sa_flags = obsa.sa_flags;
191 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
192 if (error)
193 return (error);
194 }
195 return (0);
196 }
197
198 int
199 freebsd_sys_utrace(struct lwp *l, const struct freebsd_sys_utrace_args *uap, register_t *retval)
200 {
201 /* {
202 syscallarg(void *) addr;
203 syscallarg(size_t) len;
204 } */
205
206 return ktruser("FreeBSD utrace", SCARG(uap, addr), SCARG(uap, len),
207 0);
208 }
209