1 /* $NetBSD: freebsd_misc.c,v 1.31 2007/12/08 18:35:58 dsl Exp $ */
4 * Copyright (c) 1995 Frank van der Linden
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
35 * FreeBSD compatibility module. Try to deal with various FreeBSD system calls.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: freebsd_misc.c,v 1.31 2007/12/08 18:35:58 dsl Exp $");
41 #if defined(_KERNEL_OPT)
45 #include <sys/param.h>
46 #include <sys/systm.h>
48 #include <sys/mount.h>
49 #include <sys/signal.h>
50 #include <sys/signalvar.h>
51 #include <sys/malloc.h>
53 #include <sys/ktrace.h>
55 #include <sys/syscallargs.h>
57 #include <compat/freebsd/freebsd_syscallargs.h>
58 #include <compat/common/compat_util.h>
59 #include <compat/freebsd/freebsd_rtprio.h>
60 #include <compat/freebsd/freebsd_timex.h>
61 #include <compat/freebsd/freebsd_signal.h>
62 #include <compat/freebsd/freebsd_mman.h>
65 freebsd_sys_msync(struct lwp
*l
, const struct freebsd_sys_msync_args
*uap
, register_t
*retval
)
68 syscallarg(void *) addr;
69 syscallarg(size_t) len;
70 syscallarg(int) flags;
72 struct sys___msync13_args bma
;
75 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
76 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
77 * but syscall number is not changed. :-<
79 SCARG(&bma
, addr
) = SCARG(uap
, addr
);
80 SCARG(&bma
, len
) = SCARG(uap
, len
);
81 SCARG(&bma
, flags
) = SCARG(uap
, flags
);
82 return sys___msync13(l
, &bma
, retval
);
86 freebsd_sys_mmap(struct lwp
*l
, const struct freebsd_sys_mmap_args
*uap
, register_t
*retval
)
89 syscallarg(void *) addr;
90 syscallarg(size_t) len;
92 syscallarg(int) flags;
95 syscallarg(off_t) pos;
97 struct sys_mmap_args bma
;
101 prot
= SCARG(uap
, prot
);
102 flags
= SCARG(uap
, flags
);
104 pos
= SCARG(uap
, pos
);
107 * If using MAP_STACK on FreeBSD:
110 * + prot must have read and write
111 * + MAP_STACK implies MAP_ANON
112 * + MAP_STACK implies offset of 0
114 if (flags
& FREEBSD_MAP_STACK
) {
116 ||((prot
& (PROT_READ
|PROT_WRITE
))!=(PROT_READ
|PROT_WRITE
)))
119 flags
|= (MAP_ANON
| MAP_FIXED
);
120 flags
&= ~FREEBSD_MAP_STACK
;
125 SCARG(&bma
, addr
) = SCARG(uap
, addr
);
126 SCARG(&bma
, len
) = SCARG(uap
, len
);
127 SCARG(&bma
, prot
) = prot
;
128 SCARG(&bma
, flags
) = flags
;
129 SCARG(&bma
, fd
) = fd
;
130 SCARG(&bma
, pos
) = pos
;
132 return sys_mmap(l
, &bma
, retval
);
135 /* just a place holder */
138 freebsd_sys_rtprio(struct lwp
*l
, const struct freebsd_sys_rtprio_args
*uap
, register_t
*retval
)
141 syscallarg(int) function;
142 syscallarg(pid_t) pid;
143 syscallarg(struct freebsd_rtprio *) rtp;
146 return ENOSYS
; /* XXX */
151 freebsd_ntp_adjtime(struct lwp
*l
, const struct freebsd_ntp_adjtime_args
*uap
, register_t
*retval
)
154 syscallarg(struct freebsd_timex *) tp;
157 return ENOSYS
; /* XXX */
162 freebsd_sys_sigaction4(struct lwp
*l
, const struct freebsd_sys_sigaction4_args
*uap
, register_t
*retval
)
165 syscallarg(int) signum;
166 syscallarg(const struct freebsd_sigaction4 *) nsa;
167 syscallarg(struct freebsd_sigaction4 *) osa;
169 struct freebsd_sigaction4 nesa
, oesa
;
170 struct sigaction nbsa
, obsa
;
173 if (SCARG(uap
, nsa
)) {
174 error
= copyin(SCARG(uap
, nsa
), &nesa
, sizeof(nesa
));
177 nbsa
.sa_handler
= nesa
.freebsd_sa_handler
;
178 nbsa
.sa_mask
= nesa
.freebsd_sa_mask
;
179 nbsa
.sa_flags
= nesa
.freebsd_sa_flags
;
181 error
= sigaction1(l
, SCARG(uap
, signum
),
182 SCARG(uap
, nsa
) ? &nbsa
: 0, SCARG(uap
, osa
) ? &obsa
: 0,
186 if (SCARG(uap
, osa
)) {
187 oesa
.freebsd_sa_handler
= obsa
.sa_handler
;
188 oesa
.freebsd_sa_mask
= obsa
.sa_mask
;
189 oesa
.freebsd_sa_flags
= obsa
.sa_flags
;
190 error
= copyout(&oesa
, SCARG(uap
, osa
), sizeof(oesa
));
198 freebsd_sys_utrace(struct lwp
*l
, const struct freebsd_sys_utrace_args
*uap
, register_t
*retval
)
201 syscallarg(void *) addr;
202 syscallarg(size_t) len;
205 return ktruser("FreeBSD utrace", SCARG(uap
, addr
), SCARG(uap
, len
),