Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.18.18.1
      1  1.18.18.1      yamt /*	$NetBSD: netbsd32_compat_12.c,v 1.18.18.1 2006/06/21 14:59:35 yamt Exp $	*/
      2        1.1       mrg 
      3        1.1       mrg /*
      4       1.12       mrg  * Copyright (c) 1998, 2001 Matthew R. Green
      5        1.1       mrg  * All rights reserved.
      6        1.1       mrg  *
      7        1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8        1.1       mrg  * modification, are permitted provided that the following conditions
      9        1.1       mrg  * are met:
     10        1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11        1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12        1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15        1.1       mrg  * 3. The name of the author may not be used to endorse or promote products
     16        1.1       mrg  *    derived from this software without specific prior written permission.
     17        1.1       mrg  *
     18        1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19        1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20        1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21        1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22        1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23        1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24        1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25        1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26        1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27        1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28        1.1       mrg  * SUCH DAMAGE.
     29        1.1       mrg  */
     30       1.13     lukem 
     31       1.13     lukem #include <sys/cdefs.h>
     32  1.18.18.1      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_12.c,v 1.18.18.1 2006/06/21 14:59:35 yamt Exp $");
     33        1.9      fvdl 
     34       1.11       mrg #if defined(_KERNEL_OPT)
     35        1.9      fvdl #include "opt_compat_netbsd.h"
     36        1.9      fvdl #endif
     37        1.1       mrg 
     38        1.1       mrg #include <sys/param.h>
     39        1.1       mrg #include <sys/systm.h>
     40        1.1       mrg #include <sys/mount.h>
     41        1.1       mrg #include <sys/mman.h>
     42        1.1       mrg #include <sys/proc.h>
     43        1.1       mrg #include <sys/stat.h>
     44        1.2       mrg #include <sys/swap.h>
     45       1.16   thorpej #include <sys/sa.h>
     46        1.1       mrg #include <sys/syscallargs.h>
     47        1.1       mrg 
     48  1.18.18.1      yamt #include <compat/sys/stat.h>
     49  1.18.18.1      yamt 
     50        1.4       mrg #include <compat/netbsd32/netbsd32.h>
     51        1.4       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     52        1.1       mrg 
     53        1.8  jdolecek static void netbsd32_stat12_to_netbsd32 __P((struct stat12 *,
     54        1.8  jdolecek 		struct netbsd32_stat12 *));
     55        1.1       mrg 
     56        1.1       mrg /* for use with {,fl}stat() */
     57        1.1       mrg static void
     58        1.6       eeh netbsd32_stat12_to_netbsd32(sp12, sp32)
     59        1.1       mrg 	struct stat12 *sp12;
     60        1.4       mrg 	struct netbsd32_stat12 *sp32;
     61        1.1       mrg {
     62        1.1       mrg 
     63        1.1       mrg 	sp32->st_dev = sp12->st_dev;
     64        1.1       mrg 	sp32->st_ino = sp12->st_ino;
     65        1.1       mrg 	sp32->st_mode = sp12->st_mode;
     66        1.1       mrg 	sp32->st_nlink = sp12->st_nlink;
     67        1.1       mrg 	sp32->st_uid = sp12->st_uid;
     68        1.1       mrg 	sp32->st_gid = sp12->st_gid;
     69        1.1       mrg 	sp32->st_rdev = sp12->st_rdev;
     70        1.1       mrg 	if (sp12->st_size < (quad_t)1 << 32)
     71        1.1       mrg 		sp32->st_size = sp12->st_size;
     72        1.1       mrg 	else
     73        1.1       mrg 		sp32->st_size = -2;
     74        1.1       mrg 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     75        1.1       mrg 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     76        1.1       mrg 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     77        1.1       mrg 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     78        1.1       mrg 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     79        1.1       mrg 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     80        1.1       mrg 	sp32->st_blocks = sp12->st_blocks;
     81        1.1       mrg 	sp32->st_blksize = sp12->st_blksize;
     82        1.1       mrg 	sp32->st_flags = sp12->st_flags;
     83        1.1       mrg 	sp32->st_gen = sp12->st_gen;
     84        1.3       eeh }
     85        1.3       eeh 
     86        1.3       eeh int
     87       1.16   thorpej compat_12_netbsd32_reboot(l, v, retval)
     88       1.16   thorpej 	struct lwp *l;
     89        1.3       eeh 	void *v;
     90        1.3       eeh 	register_t *retval;
     91        1.3       eeh {
     92        1.6       eeh 	struct compat_12_netbsd32_reboot_args /* {
     93        1.3       eeh 		syscallarg(int) opt;
     94        1.3       eeh 	} */ *uap = v;
     95        1.3       eeh 	struct compat_12_sys_reboot_args ua;
     96        1.3       eeh 
     97        1.5       mrg 	NETBSD32TO64_UAP(opt);
     98       1.16   thorpej 	return (compat_12_sys_reboot(l, &ua, retval));
     99        1.1       mrg }
    100        1.1       mrg 
    101        1.1       mrg int
    102       1.16   thorpej compat_12_netbsd32_msync(l, v, retval)
    103       1.16   thorpej 	struct lwp *l;
    104        1.1       mrg 	void *v;
    105        1.1       mrg 	register_t *retval;
    106        1.1       mrg {
    107        1.6       eeh 	struct compat_12_netbsd32_msync_args /* {
    108        1.4       mrg 		syscallarg(netbsd32_caddr_t) addr;
    109        1.4       mrg 		syscallarg(netbsd32_size_t) len;
    110        1.1       mrg 	} */ *uap = v;
    111        1.1       mrg 	struct sys___msync13_args ua;
    112        1.1       mrg 
    113        1.5       mrg 	NETBSD32TOX64_UAP(addr, caddr_t);
    114        1.5       mrg 	NETBSD32TOX_UAP(len, size_t);
    115        1.1       mrg 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    116       1.16   thorpej 	return (sys___msync13(l, &ua, retval));
    117        1.1       mrg }
    118        1.1       mrg 
    119        1.1       mrg int
    120       1.16   thorpej compat_12_netbsd32_oswapon(l, v, retval)
    121       1.16   thorpej 	struct lwp *l;
    122        1.1       mrg 	void *v;
    123        1.1       mrg 	register_t *retval;
    124        1.1       mrg {
    125        1.6       eeh 	struct compat_12_netbsd32_oswapon_args /* {
    126        1.4       mrg 		syscallarg(const netbsd32_charp) name;
    127        1.1       mrg 	} */ *uap = v;
    128        1.1       mrg 	struct sys_swapctl_args ua;
    129        1.1       mrg 
    130        1.1       mrg 	SCARG(&ua, cmd) = SWAP_ON;
    131       1.15       scw 	SCARG(&ua, arg) = (void *)NETBSD32PTR64(SCARG(uap, name));
    132        1.1       mrg 	SCARG(&ua, misc) = 0;	/* priority */
    133       1.16   thorpej 	return (sys_swapctl(l, &ua, retval));
    134        1.1       mrg }
    135        1.1       mrg 
    136        1.1       mrg int
    137       1.16   thorpej compat_12_netbsd32_stat12(l, v, retval)
    138       1.16   thorpej 	struct lwp *l;
    139        1.1       mrg 	void *v;
    140        1.1       mrg 	register_t *retval;
    141        1.1       mrg {
    142       1.16   thorpej 	struct proc *p = l->l_proc;
    143        1.6       eeh 	struct compat_12_netbsd32_stat12_args /* {
    144        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    145        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    146        1.1       mrg 	} */ *uap = v;
    147       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    148        1.1       mrg 	struct stat12 sb12;
    149        1.1       mrg 	struct stat12 *sp12 = &sb12;
    150        1.1       mrg 	struct compat_12_sys_stat_args ua;
    151        1.1       mrg 	caddr_t sg;
    152        1.1       mrg 	int rv;
    153        1.1       mrg 
    154        1.5       mrg 	NETBSD32TOP_UAP(path, const char);
    155        1.1       mrg 	SCARG(&ua, ub) = &sb12;
    156       1.14  christos 	sg = stackgap_init(p, 0);
    157  1.18.18.1      yamt 	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
    158        1.1       mrg 
    159       1.16   thorpej 	rv = compat_12_sys_stat(l, &ua, retval);
    160       1.10       mrg 	if (rv)
    161       1.10       mrg 		return (rv);
    162        1.1       mrg 
    163       1.15       scw 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
    164       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    165        1.1       mrg 
    166       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    167        1.1       mrg }
    168        1.1       mrg 
    169        1.1       mrg int
    170       1.16   thorpej compat_12_netbsd32_fstat12(l, v, retval)
    171       1.16   thorpej 	struct lwp *l;
    172        1.1       mrg 	void *v;
    173        1.1       mrg 	register_t *retval;
    174        1.1       mrg {
    175        1.6       eeh 	struct compat_12_netbsd32_fstat12_args /* {
    176        1.1       mrg 		syscallarg(int) fd;
    177        1.4       mrg 		syscallarg(netbsd32_stat12p_t) sb;
    178        1.1       mrg 	} */ *uap = v;
    179       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    180        1.1       mrg 	struct stat12 sb12;
    181        1.1       mrg 	struct stat12 *sp12 = &sb12;
    182        1.1       mrg 	struct compat_12_sys_fstat_args ua;
    183        1.1       mrg 	int rv;
    184        1.1       mrg 
    185        1.5       mrg 	NETBSD32TO64_UAP(fd);
    186        1.1       mrg 	SCARG(&ua, sb) = &sb12;
    187       1.16   thorpej 	rv = compat_12_sys_fstat(l, &ua, retval);
    188       1.10       mrg 	if (rv)
    189       1.10       mrg 		return (rv);
    190        1.1       mrg 
    191       1.15       scw 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, sb));
    192       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    193        1.1       mrg 
    194       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    195        1.1       mrg }
    196        1.1       mrg 
    197        1.1       mrg int
    198       1.16   thorpej compat_12_netbsd32_lstat12(l, v, retval)
    199       1.16   thorpej 	struct lwp *l;
    200        1.1       mrg 	void *v;
    201        1.1       mrg 	register_t *retval;
    202        1.1       mrg {
    203       1.16   thorpej 	struct proc *p = l->l_proc;
    204        1.6       eeh 	struct compat_12_netbsd32_lstat12_args /* {
    205        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    206        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    207        1.1       mrg 	} */ *uap = v;
    208       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    209        1.1       mrg 	struct stat12 sb12;
    210        1.1       mrg 	struct stat12 *sp12 = &sb12;
    211        1.1       mrg 	struct compat_12_sys_lstat_args ua;
    212        1.1       mrg 	caddr_t sg;
    213        1.1       mrg 	int rv;
    214        1.1       mrg 
    215        1.5       mrg 	NETBSD32TOP_UAP(path, const char);
    216        1.1       mrg 	SCARG(&ua, ub) = &sb12;
    217       1.14  christos 	sg = stackgap_init(p, 0);
    218  1.18.18.1      yamt 	CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
    219        1.1       mrg 
    220       1.16   thorpej 	rv = compat_12_sys_lstat(l, &ua, retval);
    221       1.10       mrg 	if (rv)
    222       1.10       mrg 		return (rv);
    223        1.1       mrg 
    224       1.15       scw 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
    225       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    226        1.1       mrg 
    227       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    228        1.1       mrg }
    229        1.1       mrg 
    230        1.1       mrg int
    231       1.16   thorpej compat_12_netbsd32_getdirentries(l, v, retval)
    232       1.16   thorpej 	struct lwp *l;
    233        1.1       mrg 	void *v;
    234        1.1       mrg 	register_t *retval;
    235        1.1       mrg {
    236        1.6       eeh 	struct compat_12_netbsd32_getdirentries_args /* {
    237        1.1       mrg 		syscallarg(int) fd;
    238        1.4       mrg 		syscallarg(netbsd32_charp) buf;
    239        1.1       mrg 		syscallarg(u_int) count;
    240        1.4       mrg 		syscallarg(netbsd32_longp) basep;
    241        1.1       mrg 	} */ *uap = v;
    242        1.1       mrg 	struct compat_12_sys_getdirentries_args ua;
    243        1.1       mrg 
    244        1.5       mrg 	NETBSD32TO64_UAP(fd);
    245        1.5       mrg 	NETBSD32TOP_UAP(buf, char);
    246        1.5       mrg 	NETBSD32TO64_UAP(count);
    247        1.5       mrg 	NETBSD32TOP_UAP(basep, long);
    248        1.1       mrg 
    249       1.16   thorpej 	return (compat_12_sys_getdirentries(l, &ua, retval));
    250        1.1       mrg }
    251