Home | History | Annotate | Line # | Download | only in freebsd
freebsd_misc.c revision 1.10
      1 /*	$NetBSD: freebsd_misc.c,v 1.10 2000/12/17 16:11:38 jdolecek 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/proc.h>
     46 #include <sys/mount.h>
     47 #include <sys/signal.h>
     48 #include <sys/signalvar.h>
     49 #include <sys/malloc.h>
     50 #ifdef KTRACE
     51 #include <sys/ktrace.h>
     52 #endif
     53 
     54 #include <sys/syscallargs.h>
     55 
     56 #include <compat/freebsd/freebsd_syscallargs.h>
     57 #include <compat/common/compat_util.h>
     58 #include <compat/freebsd/freebsd_rtprio.h>
     59 #include <compat/freebsd/freebsd_timex.h>
     60 #include <compat/freebsd/freebsd_signal.h>
     61 
     62 void    ktrinitheader(struct ktr_header *, struct proc *, int);
     63 int	ktrwrite(struct proc *, struct ktr_header *);
     64 
     65 int
     66 freebsd_sys_msync(p, v, retval)
     67 	struct proc *p;
     68 	void *v;
     69 	register_t *retval;
     70 {
     71 	struct freebsd_sys_msync_args /* {
     72 		syscallarg(caddr_t) addr;
     73 		syscallarg(size_t) len;
     74 		syscallarg(int) flags;
     75 	} */ *uap = v;
     76 	struct sys___msync13_args bma;
     77 
     78 	/*
     79 	 * FreeBSD-2.0-RELEASE's msync(2) is compatible with NetBSD's.
     80 	 * FreeBSD-2.0.5-RELEASE's msync(2) has addtional argument `flags',
     81 	 * but syscall number is not changed. :-<
     82 	 */
     83 	SCARG(&bma, addr) = SCARG(uap, addr);
     84 	SCARG(&bma, len) = SCARG(uap, len);
     85 	SCARG(&bma, flags) = SCARG(uap, flags);
     86 	return sys___msync13(p, &bma, retval);
     87 }
     88 
     89 /* just a place holder */
     90 
     91 int
     92 freebsd_sys_rtprio(p, v, retval)
     93 	struct proc *p;
     94 	void *v;
     95 	register_t *retval;
     96 {
     97 #ifdef notyet
     98 	struct freebsd_sys_rtprio_args /* {
     99 		syscallarg(int) function;
    100 		syscallarg(pid_t) pid;
    101 		syscallarg(struct freebsd_rtprio *) rtp;
    102 	} */ *uap = v;
    103 #endif
    104 
    105 	return ENOSYS;	/* XXX */
    106 }
    107 
    108 #ifdef NTP
    109 int
    110 freebsd_ntp_adjtime(p, v, retval)
    111 	struct proc *p;
    112 	void *v;
    113 	register_t *retval;
    114 {
    115 #ifdef notyet
    116 	struct freebsd_ntp_adjtime_args /* {
    117 		syscallarg(struct freebsd_timex *) tp;
    118 	} */ *uap = v;
    119 #endif
    120 
    121 	return ENOSYS;	/* XXX */
    122 }
    123 #endif
    124 
    125 int
    126 freebsd_sys_sigaction4(p, v, retval)
    127 	struct proc *p;
    128 	void *v;
    129 	register_t *retval;
    130 {
    131 	struct freebsd_sys_sigaction4_args /* {
    132 		syscallarg(int) signum;
    133 		syscallarg(const struct freebsd_sigaction4 *) nsa;
    134 		syscallarg(struct freebsd_sigaction4 *) osa;
    135 	} */ *uap = v;
    136 	struct freebsd_sigaction4 nesa, oesa;
    137 	struct sigaction nbsa, obsa;
    138 	int error;
    139 
    140 	if (SCARG(uap, nsa)) {
    141 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    142 		if (error)
    143 			return (error);
    144 		nbsa.sa_handler = nesa.sa_handler;
    145 		nbsa.sa_mask    = nesa.sa_mask;
    146 		nbsa.sa_flags   = nesa.sa_flags;
    147 	}
    148 	error = sigaction1(p, SCARG(uap, signum),
    149 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0);
    150 	if (error)
    151 		return (error);
    152 	if (SCARG(uap, osa)) {
    153 		oesa.sa_handler = obsa.sa_handler;
    154 		oesa.sa_mask    = obsa.sa_mask;
    155 		oesa.sa_flags   = obsa.sa_flags;
    156 		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
    157 		if (error)
    158 			return (error);
    159 	}
    160 	return (0);
    161 }
    162 
    163 int
    164 freebsd_sys_utrace(p, v, retval)
    165 	struct proc *p;
    166 	void *v;
    167 	register_t *retval;
    168 {
    169 	struct freebsd_sys_utrace_args /* {
    170 		syscallarg(void *) addr;
    171 		syscallarg(size_t) len;
    172 	} */ *uap = v;
    173 #ifdef KTRACE
    174 	struct ktr_header kth;
    175 	register caddr_t cp;
    176 	int error = 0;
    177 
    178 	if (!KTRPOINT(p, KTR_USER))
    179 		return (0);
    180 	p->p_traceflag |= KTRFAC_ACTIVE;
    181 	ktrinitheader(&kth, p, KTR_USER);
    182 	cp = (caddr_t) malloc(SCARG(uap, len), M_TEMP, M_WAITOK);
    183 	if ((error = copyin(SCARG(uap, addr), cp, SCARG(uap, len))) == 0) {
    184 		kth.ktr_buf = cp;
    185 		kth.ktr_len = SCARG(uap, len);
    186 		error = ktrwrite(p, &kth);
    187 	}
    188 	free(cp, M_TEMP);
    189 	p->p_traceflag &= ~KTRFAC_ACTIVE;
    190 
    191 	return (error);
    192 #else
    193 	return ENOSYS;
    194 #endif
    195 }
    196