Home | History | Annotate | Line # | Download | only in freebsd
freebsd_misc.c revision 1.31.4.1
      1 /*	$NetBSD: freebsd_misc.c,v 1.31.4.1 2008/01/02 21:51:52 bouyer 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.31.4.1 2008/01/02 21:51:52 bouyer 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(struct lwp *l, const struct freebsd_sys_msync_args *uap, register_t *retval)
     66 {
     67 	/* {
     68 		syscallarg(void *) addr;
     69 		syscallarg(size_t) len;
     70 		syscallarg(int) flags;
     71 	} */
     72 	struct sys___msync13_args bma;
     73 
     74 	/*
     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. :-<
     78 	 */
     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);
     83 }
     84 
     85 int
     86 freebsd_sys_mmap(struct lwp *l, const struct freebsd_sys_mmap_args *uap, register_t *retval)
     87 {
     88 	/* {
     89 		syscallarg(void *) addr;
     90 		syscallarg(size_t) len;
     91 		syscallarg(int) prot;
     92 		syscallarg(int) flags;
     93 		syscallarg(int) fd;
     94 		syscallarg(long) pad;
     95 		syscallarg(off_t) pos;
     96 	} */
     97 	struct sys_mmap_args bma;
     98 	int flags, prot, fd;
     99 	off_t pos;
    100 
    101 	prot = SCARG(uap, prot);
    102 	flags = SCARG(uap, flags);
    103 	fd = SCARG(uap, fd);
    104 	pos = SCARG(uap, pos);
    105 
    106 	/*
    107 	 * If using MAP_STACK on FreeBSD:
    108 	 *
    109 	 * + fd has to be -1
    110 	 * + prot must have read and write
    111 	 * + MAP_STACK implies MAP_ANON
    112 	 * + MAP_STACK implies offset of 0
    113 	 */
    114 	if (flags & FREEBSD_MAP_STACK) {
    115 		if ((fd != -1)
    116 		    ||((prot & (PROT_READ|PROT_WRITE))!=(PROT_READ|PROT_WRITE)))
    117 			return (EINVAL);
    118 
    119 		flags |= (MAP_ANON | MAP_FIXED);
    120 		flags &= ~FREEBSD_MAP_STACK;
    121 
    122 		pos = 0;
    123 	}
    124 
    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;
    131 
    132 	return sys_mmap(l, &bma, retval);
    133 }
    134 
    135 /* just a place holder */
    136 
    137 int
    138 freebsd_sys_rtprio(struct lwp *l, const struct freebsd_sys_rtprio_args *uap, register_t *retval)
    139 {
    140 	/* {
    141 		syscallarg(int) function;
    142 		syscallarg(pid_t) pid;
    143 		syscallarg(struct freebsd_rtprio *) rtp;
    144 	} */
    145 
    146 	return ENOSYS;	/* XXX */
    147 }
    148 
    149 #ifdef NTP
    150 int
    151 freebsd_ntp_adjtime(struct lwp *l, const struct freebsd_ntp_adjtime_args *uap, register_t *retval)
    152 {
    153 	/* {
    154 		syscallarg(struct freebsd_timex *) tp;
    155 	} */
    156 
    157 	return ENOSYS;	/* XXX */
    158 }
    159 #endif
    160 
    161 int
    162 freebsd_sys_sigaction4(struct lwp *l, const struct freebsd_sys_sigaction4_args *uap, register_t *retval)
    163 {
    164 	/* {
    165 		syscallarg(int) signum;
    166 		syscallarg(const struct freebsd_sigaction4 *) nsa;
    167 		syscallarg(struct freebsd_sigaction4 *) osa;
    168 	} */
    169 	struct freebsd_sigaction4 nesa, oesa;
    170 	struct sigaction nbsa, obsa;
    171 	int error;
    172 
    173 	if (SCARG(uap, nsa)) {
    174 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    175 		if (error)
    176 			return (error);
    177 		nbsa.sa_handler = nesa.freebsd_sa_handler;
    178 		nbsa.sa_mask    = nesa.freebsd_sa_mask;
    179 		nbsa.sa_flags   = nesa.freebsd_sa_flags;
    180 	}
    181 	error = sigaction1(l, SCARG(uap, signum),
    182 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
    183 	    NULL, 0);
    184 	if (error)
    185 		return (error);
    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));
    191 		if (error)
    192 			return (error);
    193 	}
    194 	return (0);
    195 }
    196 
    197 int
    198 freebsd_sys_utrace(struct lwp *l, const struct freebsd_sys_utrace_args *uap, register_t *retval)
    199 {
    200 	/* {
    201 		syscallarg(void *) addr;
    202 		syscallarg(size_t) len;
    203 	} */
    204 
    205 	return ktruser("FreeBSD utrace", SCARG(uap, addr), SCARG(uap, len),
    206 	    0);
    207 }
    208