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