Home | History | Annotate | Line # | Download | only in freebsd
freebsd_misc.c revision 1.29.10.1
      1 /*	$NetBSD: freebsd_misc.c,v 1.29.10.1 2007/09/03 10:19:57 skrll 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.29.10.1 2007/09/03 10:19:57 skrll 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/syscallargs.h>
     56 
     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>
     63 
     64 int
     65 freebsd_sys_msync(l, v, retval)
     66 	struct lwp *l;
     67 	void *v;
     68 	register_t *retval;
     69 {
     70 	struct freebsd_sys_msync_args /* {
     71 		syscallarg(void *) addr;
     72 		syscallarg(size_t) len;
     73 		syscallarg(int) flags;
     74 	} */ *uap = v;
     75 	struct sys___msync13_args bma;
     76 
     77 	/*
     78 	 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
     79 	 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
     80 	 * but syscall number is not changed. :-<
     81 	 */
     82 	SCARG(&bma, addr) = SCARG(uap, addr);
     83 	SCARG(&bma, len) = SCARG(uap, len);
     84 	SCARG(&bma, flags) = SCARG(uap, flags);
     85 	return sys___msync13(l, &bma, retval);
     86 }
     87 
     88 int
     89 freebsd_sys_mmap(l, v, retval)
     90 	struct lwp *l;
     91 	void *v;
     92 	register_t *retval;
     93 {
     94 	struct freebsd_sys_mmap_args /* {
     95 		syscallarg(void *) addr;
     96 		syscallarg(size_t) len;
     97 		syscallarg(int) prot;
     98 		syscallarg(int) flags;
     99 		syscallarg(int) fd;
    100 		syscallarg(long) pad;
    101 		syscallarg(off_t) pos;
    102 	} */ *uap = v;
    103 	struct sys_mmap_args bma;
    104 	int flags, prot, fd;
    105 	off_t pos;
    106 
    107 	prot = SCARG(uap, prot);
    108 	flags = SCARG(uap, flags);
    109 	fd = SCARG(uap, fd);
    110 	pos = SCARG(uap, pos);
    111 
    112 	/*
    113 	 * If using MAP_STACK on FreeBSD:
    114 	 *
    115 	 * + fd has to be -1
    116 	 * + prot must have read and write
    117 	 * + MAP_STACK implies MAP_ANON
    118 	 * + MAP_STACK implies offset of 0
    119 	 */
    120 	if (flags & FREEBSD_MAP_STACK) {
    121 		if ((fd != -1)
    122 		    ||((prot & (PROT_READ|PROT_WRITE))!=(PROT_READ|PROT_WRITE)))
    123 			return (EINVAL);
    124 
    125 		flags |= (MAP_ANON | MAP_FIXED);
    126 		flags &= ~FREEBSD_MAP_STACK;
    127 
    128 		pos = 0;
    129 	}
    130 
    131 	SCARG(&bma, addr) = SCARG(uap, addr);
    132 	SCARG(&bma, len) = SCARG(uap, len);
    133 	SCARG(&bma, prot) = prot;
    134 	SCARG(&bma, flags) = flags;
    135 	SCARG(&bma, fd) = fd;
    136 	SCARG(&bma, pos) = pos;
    137 
    138 	return sys_mmap(l, &bma, retval);
    139 }
    140 
    141 /* just a place holder */
    142 
    143 int
    144 freebsd_sys_rtprio(struct lwp *l, void *v,
    145     register_t *retval)
    146 {
    147 #ifdef notyet
    148 	struct freebsd_sys_rtprio_args /* {
    149 		syscallarg(int) function;
    150 		syscallarg(pid_t) pid;
    151 		syscallarg(struct freebsd_rtprio *) rtp;
    152 	} */ *uap = v;
    153 #endif
    154 
    155 	return ENOSYS;	/* XXX */
    156 }
    157 
    158 #ifdef NTP
    159 int
    160 freebsd_ntp_adjtime(struct lwp *l, void *v,
    161     register_t *retval)
    162 {
    163 #ifdef notyet
    164 	struct freebsd_ntp_adjtime_args /* {
    165 		syscallarg(struct freebsd_timex *) tp;
    166 	} */ *uap = v;
    167 #endif
    168 
    169 	return ENOSYS;	/* XXX */
    170 }
    171 #endif
    172 
    173 int
    174 freebsd_sys_sigaction4(struct lwp *l, void *v, register_t *retval)
    175 {
    176 	struct freebsd_sys_sigaction4_args /* {
    177 		syscallarg(int) signum;
    178 		syscallarg(const struct freebsd_sigaction4 *) nsa;
    179 		syscallarg(struct freebsd_sigaction4 *) osa;
    180 	} */ *uap = v;
    181 	struct freebsd_sigaction4 nesa, oesa;
    182 	struct sigaction nbsa, obsa;
    183 	int error;
    184 
    185 	if (SCARG(uap, nsa)) {
    186 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    187 		if (error)
    188 			return (error);
    189 		nbsa.sa_handler = nesa.freebsd_sa_handler;
    190 		nbsa.sa_mask    = nesa.freebsd_sa_mask;
    191 		nbsa.sa_flags   = nesa.freebsd_sa_flags;
    192 	}
    193 	error = sigaction1(l, SCARG(uap, signum),
    194 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
    195 	    NULL, 0);
    196 	if (error)
    197 		return (error);
    198 	if (SCARG(uap, osa)) {
    199 		oesa.freebsd_sa_handler = obsa.sa_handler;
    200 		oesa.freebsd_sa_mask    = obsa.sa_mask;
    201 		oesa.freebsd_sa_flags   = obsa.sa_flags;
    202 		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
    203 		if (error)
    204 			return (error);
    205 	}
    206 	return (0);
    207 }
    208 
    209 int
    210 freebsd_sys_utrace(struct lwp *l, void *v, register_t *retval)
    211 {
    212 	struct freebsd_sys_utrace_args /* {
    213 		syscallarg(void *) addr;
    214 		syscallarg(size_t) len;
    215 	} */ *uap = v;
    216 
    217 	return ktruser("FreeBSD utrace", SCARG(uap, addr), SCARG(uap, len),
    218 	    0);
    219 }
    220