Home | History | Annotate | Line # | Download | only in freebsd
freebsd_misc.c revision 1.12.2.1
      1 /*	$NetBSD: freebsd_misc.c,v 1.12.2.1 2001/03/05 22:49:20 nathanw 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 #if defined(_KERNEL) && !defined(_LKM)
     39 #include "opt_ntp.h"
     40 #include "opt_ktrace.h"
     41 #endif
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/lwp.h>
     46 #include <sys/proc.h>
     47 #include <sys/mount.h>
     48 #include <sys/signal.h>
     49 #include <sys/signalvar.h>
     50 #include <sys/malloc.h>
     51 #ifdef KTRACE
     52 #include <sys/ktrace.h>
     53 #endif
     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 
     63 int
     64 freebsd_sys_msync(l, v, retval)
     65 	struct lwp *l;
     66 	void *v;
     67 	register_t *retval;
     68 {
     69 	struct freebsd_sys_msync_args /* {
     70 		syscallarg(caddr_t) addr;
     71 		syscallarg(size_t) len;
     72 		syscallarg(int) flags;
     73 	} */ *uap = v;
     74 	struct sys___msync13_args bma;
     75 
     76 	/*
     77 	 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
     78 	 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
     79 	 * but syscall number is not changed. :-<
     80 	 */
     81 	SCARG(&bma, addr) = SCARG(uap, addr);
     82 	SCARG(&bma, len) = SCARG(uap, len);
     83 	SCARG(&bma, flags) = SCARG(uap, flags);
     84 	return sys___msync13(l, &bma, retval);
     85 }
     86 
     87 /* just a place holder */
     88 
     89 int
     90 freebsd_sys_rtprio(l, v, retval)
     91 	struct lwp *l;
     92 	void *v;
     93 	register_t *retval;
     94 {
     95 #ifdef notyet
     96 	struct freebsd_sys_rtprio_args /* {
     97 		syscallarg(int) function;
     98 		syscallarg(pid_t) pid;
     99 		syscallarg(struct freebsd_rtprio *) rtp;
    100 	} */ *uap = v;
    101 #endif
    102 
    103 	return ENOSYS;	/* XXX */
    104 }
    105 
    106 #ifdef NTP
    107 int
    108 freebsd_ntp_adjtime(l, v, retval)
    109 	struct lwp *l;
    110 	void *v;
    111 	register_t *retval;
    112 {
    113 #ifdef notyet
    114 	struct freebsd_ntp_adjtime_args /* {
    115 		syscallarg(struct freebsd_timex *) tp;
    116 	} */ *uap = v;
    117 #endif
    118 
    119 	return ENOSYS;	/* XXX */
    120 }
    121 #endif
    122 
    123 int
    124 freebsd_sys_sigaction4(l, v, retval)
    125 	struct lwp *l;
    126 	void *v;
    127 	register_t *retval;
    128 {
    129 	struct freebsd_sys_sigaction4_args /* {
    130 		syscallarg(int) signum;
    131 		syscallarg(const struct freebsd_sigaction4 *) nsa;
    132 		syscallarg(struct freebsd_sigaction4 *) osa;
    133 	} */ *uap = v;
    134 	struct proc *p = l->l_proc;
    135 	struct freebsd_sigaction4 nesa, oesa;
    136 	struct sigaction nbsa, obsa;
    137 	int error;
    138 
    139 	if (SCARG(uap, nsa)) {
    140 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    141 		if (error)
    142 			return (error);
    143 		nbsa.sa_handler = nesa.sa_handler;
    144 		nbsa.sa_mask    = nesa.sa_mask;
    145 		nbsa.sa_flags   = nesa.sa_flags;
    146 	}
    147 	error = sigaction1(p, SCARG(uap, signum),
    148 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0);
    149 	if (error)
    150 		return (error);
    151 	if (SCARG(uap, osa)) {
    152 		oesa.sa_handler = obsa.sa_handler;
    153 		oesa.sa_mask    = obsa.sa_mask;
    154 		oesa.sa_flags   = obsa.sa_flags;
    155 		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
    156 		if (error)
    157 			return (error);
    158 	}
    159 	return (0);
    160 }
    161 
    162 int
    163 freebsd_sys_utrace(l, v, retval)
    164 	struct lwp *l;
    165 	void *v;
    166 	register_t *retval;
    167 {
    168 #ifdef KTRACE
    169 	struct freebsd_sys_utrace_args /* {
    170 		syscallarg(void *) addr;
    171 		syscallarg(size_t) len;
    172 	} */ *uap = v;
    173 	struct proc *p = l->l_proc;
    174 
    175 	if (KTRPOINT(p, KTR_USER))
    176 		ktruser(p, "FreeBSD utrace", SCARG(uap, addr), SCARG(uap, len),
    177 			0);
    178 
    179 	return (0);
    180 #else
    181 	return (ENOSYS);
    182 #endif
    183 }
    184