Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.15
      1 /*	$NetBSD: netbsd32_compat_12.c,v 1.15 2002/10/23 13:16:41 scw Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 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/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_12.c,v 1.15 2002/10/23 13:16:41 scw Exp $");
     33 
     34 #if defined(_KERNEL_OPT)
     35 #include "opt_compat_netbsd.h"
     36 #endif
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/mount.h>
     41 #include <sys/mman.h>
     42 #include <sys/proc.h>
     43 #include <sys/stat.h>
     44 #include <sys/swap.h>
     45 #include <sys/syscallargs.h>
     46 
     47 #include <compat/netbsd32/netbsd32.h>
     48 #include <compat/netbsd32/netbsd32_syscallargs.h>
     49 
     50 static void netbsd32_stat12_to_netbsd32 __P((struct stat12 *,
     51 		struct netbsd32_stat12 *));
     52 
     53 /* for use with {,fl}stat() */
     54 static void
     55 netbsd32_stat12_to_netbsd32(sp12, sp32)
     56 	struct stat12 *sp12;
     57 	struct netbsd32_stat12 *sp32;
     58 {
     59 
     60 	sp32->st_dev = sp12->st_dev;
     61 	sp32->st_ino = sp12->st_ino;
     62 	sp32->st_mode = sp12->st_mode;
     63 	sp32->st_nlink = sp12->st_nlink;
     64 	sp32->st_uid = sp12->st_uid;
     65 	sp32->st_gid = sp12->st_gid;
     66 	sp32->st_rdev = sp12->st_rdev;
     67 	if (sp12->st_size < (quad_t)1 << 32)
     68 		sp32->st_size = sp12->st_size;
     69 	else
     70 		sp32->st_size = -2;
     71 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     72 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     73 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     74 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     75 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     76 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     77 	sp32->st_blocks = sp12->st_blocks;
     78 	sp32->st_blksize = sp12->st_blksize;
     79 	sp32->st_flags = sp12->st_flags;
     80 	sp32->st_gen = sp12->st_gen;
     81 }
     82 
     83 int
     84 compat_12_netbsd32_reboot(p, v, retval)
     85 	struct proc *p;
     86 	void *v;
     87 	register_t *retval;
     88 {
     89 	struct compat_12_netbsd32_reboot_args /* {
     90 		syscallarg(int) opt;
     91 	} */ *uap = v;
     92 	struct compat_12_sys_reboot_args ua;
     93 
     94 	NETBSD32TO64_UAP(opt);
     95 	return (compat_12_sys_reboot(p, &ua, retval));
     96 }
     97 
     98 int
     99 compat_12_netbsd32_msync(p, v, retval)
    100 	struct proc *p;
    101 	void *v;
    102 	register_t *retval;
    103 {
    104 	struct compat_12_netbsd32_msync_args /* {
    105 		syscallarg(netbsd32_caddr_t) addr;
    106 		syscallarg(netbsd32_size_t) len;
    107 	} */ *uap = v;
    108 	struct sys___msync13_args ua;
    109 
    110 	NETBSD32TOX64_UAP(addr, caddr_t);
    111 	NETBSD32TOX_UAP(len, size_t);
    112 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    113 	return (sys___msync13(p, &ua, retval));
    114 }
    115 
    116 int
    117 compat_12_netbsd32_oswapon(p, v, retval)
    118 	struct proc *p;
    119 	void *v;
    120 	register_t *retval;
    121 {
    122 	struct compat_12_netbsd32_oswapon_args /* {
    123 		syscallarg(const netbsd32_charp) name;
    124 	} */ *uap = v;
    125 	struct sys_swapctl_args ua;
    126 
    127 	SCARG(&ua, cmd) = SWAP_ON;
    128 	SCARG(&ua, arg) = (void *)NETBSD32PTR64(SCARG(uap, name));
    129 	SCARG(&ua, misc) = 0;	/* priority */
    130 	return (sys_swapctl(p, &ua, retval));
    131 }
    132 
    133 int
    134 compat_12_netbsd32_stat12(p, v, retval)
    135 	struct proc *p;
    136 	void *v;
    137 	register_t *retval;
    138 {
    139 	struct compat_12_netbsd32_stat12_args /* {
    140 		syscallarg(const netbsd32_charp) path;
    141 		syscallarg(netbsd32_stat12p_t) ub;
    142 	} */ *uap = v;
    143 	struct netbsd32_stat12 *sp32, sb32;
    144 	struct stat12 sb12;
    145 	struct stat12 *sp12 = &sb12;
    146 	struct compat_12_sys_stat_args ua;
    147 	caddr_t sg;
    148 	int rv;
    149 
    150 	NETBSD32TOP_UAP(path, const char);
    151 	SCARG(&ua, ub) = &sb12;
    152 	sg = stackgap_init(p, 0);
    153 	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    154 
    155 	rv = compat_12_sys_stat(p, &ua, retval);
    156 	if (rv)
    157 		return (rv);
    158 
    159 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
    160 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    161 
    162 	return (copyout(&sb32, sp32, sizeof sb32));
    163 }
    164 
    165 int
    166 compat_12_netbsd32_fstat12(p, v, retval)
    167 	struct proc *p;
    168 	void *v;
    169 	register_t *retval;
    170 {
    171 	struct compat_12_netbsd32_fstat12_args /* {
    172 		syscallarg(int) fd;
    173 		syscallarg(netbsd32_stat12p_t) sb;
    174 	} */ *uap = v;
    175 	struct netbsd32_stat12 *sp32, sb32;
    176 	struct stat12 sb12;
    177 	struct stat12 *sp12 = &sb12;
    178 	struct compat_12_sys_fstat_args ua;
    179 	int rv;
    180 
    181 	NETBSD32TO64_UAP(fd);
    182 	SCARG(&ua, sb) = &sb12;
    183 	rv = compat_12_sys_fstat(p, &ua, retval);
    184 	if (rv)
    185 		return (rv);
    186 
    187 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, sb));
    188 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    189 
    190 	return (copyout(&sb32, sp32, sizeof sb32));
    191 }
    192 
    193 int
    194 compat_12_netbsd32_lstat12(p, v, retval)
    195 	struct proc *p;
    196 	void *v;
    197 	register_t *retval;
    198 {
    199 	struct compat_12_netbsd32_lstat12_args /* {
    200 		syscallarg(const netbsd32_charp) path;
    201 		syscallarg(netbsd32_stat12p_t) ub;
    202 	} */ *uap = v;
    203 	struct netbsd32_stat12 *sp32, sb32;
    204 	struct stat12 sb12;
    205 	struct stat12 *sp12 = &sb12;
    206 	struct compat_12_sys_lstat_args ua;
    207 	caddr_t sg;
    208 	int rv;
    209 
    210 	NETBSD32TOP_UAP(path, const char);
    211 	SCARG(&ua, ub) = &sb12;
    212 	sg = stackgap_init(p, 0);
    213 	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    214 
    215 	rv = compat_12_sys_lstat(p, &ua, retval);
    216 	if (rv)
    217 		return (rv);
    218 
    219 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
    220 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    221 
    222 	return (copyout(&sb32, sp32, sizeof sb32));
    223 }
    224 
    225 int
    226 compat_12_netbsd32_getdirentries(p, v, retval)
    227 	struct proc *p;
    228 	void *v;
    229 	register_t *retval;
    230 {
    231 	struct compat_12_netbsd32_getdirentries_args /* {
    232 		syscallarg(int) fd;
    233 		syscallarg(netbsd32_charp) buf;
    234 		syscallarg(u_int) count;
    235 		syscallarg(netbsd32_longp) basep;
    236 	} */ *uap = v;
    237 	struct compat_12_sys_getdirentries_args ua;
    238 
    239 	NETBSD32TO64_UAP(fd);
    240 	NETBSD32TOP_UAP(buf, char);
    241 	NETBSD32TO64_UAP(count);
    242 	NETBSD32TOP_UAP(basep, long);
    243 
    244 	return (compat_12_sys_getdirentries(p, &ua, retval));
    245 }
    246