Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.4
      1 /*	$NetBSD: netbsd32_compat_12.c,v 1.4 1999/03/25 16:22:49 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 Matthew R. Green
      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. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/mount.h>
     34 #include <sys/mman.h>
     35 #include <sys/proc.h>
     36 #include <sys/stat.h>
     37 #include <sys/swap.h>
     38 #include <sys/syscallargs.h>
     39 
     40 #include <compat/netbsd32/netbsd32.h>
     41 #include <compat/netbsd32/netbsd32_syscallargs.h>
     42 
     43 
     44 /* for use with {,fl}stat() */
     45 static void
     46 compat_netbsd32_stat12_to_netbsd32(sp12, sp32)
     47 	struct stat12 *sp12;
     48 	struct netbsd32_stat12 *sp32;
     49 {
     50 
     51 	sp32->st_dev = sp12->st_dev;
     52 	sp32->st_ino = sp12->st_ino;
     53 	sp32->st_mode = sp12->st_mode;
     54 	sp32->st_nlink = sp12->st_nlink;
     55 	sp32->st_uid = sp12->st_uid;
     56 	sp32->st_gid = sp12->st_gid;
     57 	sp32->st_rdev = sp12->st_rdev;
     58 	if (sp12->st_size < (quad_t)1 << 32)
     59 		sp32->st_size = sp12->st_size;
     60 	else
     61 		sp32->st_size = -2;
     62 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     63 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     64 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     65 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     66 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     67 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     68 	sp32->st_blocks = sp12->st_blocks;
     69 	sp32->st_blksize = sp12->st_blksize;
     70 	sp32->st_flags = sp12->st_flags;
     71 	sp32->st_gen = sp12->st_gen;
     72 }
     73 
     74 int
     75 compat_12_compat_netbsd32_reboot(p, v, retval)
     76 	struct proc *p;
     77 	void *v;
     78 	register_t *retval;
     79 {
     80 	struct compat_12_compat_netbsd32_reboot_args /* {
     81 		syscallarg(int) opt;
     82 	} */ *uap = v;
     83 	struct compat_12_sys_reboot_args ua;
     84 
     85 	SPARC32TO64_UAP(opt);
     86 	return (compat_12_sys_reboot(p, &ua, retval));
     87 }
     88 
     89 int
     90 compat_12_compat_netbsd32_msync(p, v, retval)
     91 	struct proc *p;
     92 	void *v;
     93 	register_t *retval;
     94 {
     95 	struct compat_12_compat_netbsd32_msync_args /* {
     96 		syscallarg(netbsd32_caddr_t) addr;
     97 		syscallarg(netbsd32_size_t) len;
     98 	} */ *uap = v;
     99 	struct sys___msync13_args ua;
    100 
    101 	SPARC32TOX64_UAP(addr, caddr_t);
    102 	SPARC32TOX_UAP(len, size_t);
    103 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    104 	return (sys___msync13(p, &ua, retval));
    105 }
    106 
    107 int
    108 compat_12_compat_netbsd32_oswapon(p, v, retval)
    109 	struct proc *p;
    110 	void *v;
    111 	register_t *retval;
    112 {
    113 	struct compat_12_compat_netbsd32_oswapon_args /* {
    114 		syscallarg(const netbsd32_charp) name;
    115 	} */ *uap = v;
    116 	struct sys_swapctl_args ua;
    117 
    118 	SCARG(&ua, cmd) = SWAP_ON;
    119 	SCARG(&ua, arg) = (void *)(u_long)SCARG(uap, name);
    120 	SCARG(&ua, misc) = 0;	/* priority */
    121 	return (sys_swapctl(p, &ua, retval));
    122 }
    123 
    124 int
    125 compat_12_compat_netbsd32_stat12(p, v, retval)
    126 	struct proc *p;
    127 	void *v;
    128 	register_t *retval;
    129 {
    130 	struct compat_12_compat_netbsd32_stat12_args /* {
    131 		syscallarg(const netbsd32_charp) path;
    132 		syscallarg(netbsd32_stat12p_t) ub;
    133 	} */ *uap = v;
    134 	struct netbsd32_stat12 *sp32;
    135 	struct stat12 sb12;
    136 	struct stat12 *sp12 = &sb12;
    137 	struct compat_12_sys_stat_args ua;
    138 	caddr_t sg;
    139 	int rv;
    140 
    141 	SPARC32TOP_UAP(path, const char);
    142 	SCARG(&ua, ub) = &sb12;
    143 	sg = stackgap_init(p->p_emul);
    144 	SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    145 
    146 	rv = compat_12_sys_stat(p, &ua, retval);
    147 
    148 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub);
    149 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    150 
    151 	return (rv);
    152 }
    153 
    154 int
    155 compat_12_compat_netbsd32_fstat12(p, v, retval)
    156 	struct proc *p;
    157 	void *v;
    158 	register_t *retval;
    159 {
    160 	struct compat_12_compat_netbsd32_fstat12_args /* {
    161 		syscallarg(int) fd;
    162 		syscallarg(netbsd32_stat12p_t) sb;
    163 	} */ *uap = v;
    164 	struct netbsd32_stat12 *sp32;
    165 	struct stat12 sb12;
    166 	struct stat12 *sp12 = &sb12;
    167 	struct compat_12_sys_fstat_args ua;
    168 	int rv;
    169 
    170 	SPARC32TO64_UAP(fd);
    171 	SCARG(&ua, sb) = &sb12;
    172 	rv = compat_12_sys_fstat(p, &ua, retval);
    173 
    174 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, sb);
    175 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    176 
    177 	return (rv);
    178 }
    179 
    180 int
    181 compat_12_compat_netbsd32_lstat12(p, v, retval)
    182 	struct proc *p;
    183 	void *v;
    184 	register_t *retval;
    185 {
    186 	struct compat_12_compat_netbsd32_lstat12_args /* {
    187 		syscallarg(const netbsd32_charp) path;
    188 		syscallarg(netbsd32_stat12p_t) ub;
    189 	} */ *uap = v;
    190 	struct netbsd32_stat12 *sp32;
    191 	struct stat12 sb12;
    192 	struct stat12 *sp12 = &sb12;
    193 	struct compat_12_sys_lstat_args ua;
    194 	caddr_t sg;
    195 	int rv;
    196 
    197 	SPARC32TOP_UAP(path, const char);
    198 	SCARG(&ua, ub) = &sb12;
    199 	sg = stackgap_init(p->p_emul);
    200 	SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    201 
    202 	rv = compat_12_sys_lstat(p, &ua, retval);
    203 
    204 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub);
    205 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    206 
    207 	return (rv);
    208 }
    209 
    210 int
    211 compat_12_compat_netbsd32_getdirentries(p, v, retval)
    212 	struct proc *p;
    213 	void *v;
    214 	register_t *retval;
    215 {
    216 	struct compat_12_compat_netbsd32_getdirentries_args /* {
    217 		syscallarg(int) fd;
    218 		syscallarg(netbsd32_charp) buf;
    219 		syscallarg(u_int) count;
    220 		syscallarg(netbsd32_longp) basep;
    221 	} */ *uap = v;
    222 	struct compat_12_sys_getdirentries_args ua;
    223 
    224 	SPARC32TO64_UAP(fd);
    225 	SPARC32TOP_UAP(buf, char);
    226 	SPARC32TO64_UAP(count);
    227 	SPARC32TOP_UAP(basep, long);
    228 
    229 	return (compat_12_sys_getdirentries(p, &ua, retval));
    230 }
    231