Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.30.12.1
      1  1.30.12.1  wrstuden /*	$NetBSD: netbsd32_compat_12.c,v 1.30.12.1 2008/05/10 23:48:57 wrstuden 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.30.12.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_12.c,v 1.30.12.1 2008/05/10 23:48:57 wrstuden 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.30.12.1  wrstuden #include <sys/sa.h>
     46        1.1       mrg #include <sys/syscallargs.h>
     47        1.1       mrg 
     48       1.19  christos #include <compat/sys/stat.h>
     49       1.19  christos 
     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.28       dsl static void netbsd32_stat12_to_netbsd32(struct stat12 *,
     54       1.28       dsl 		struct netbsd32_stat12 *);
     55        1.1       mrg 
     56        1.1       mrg /* for use with {,fl}stat() */
     57        1.1       mrg static void
     58       1.29       dsl netbsd32_stat12_to_netbsd32(struct stat12 *sp12, struct netbsd32_stat12 *sp32)
     59        1.1       mrg {
     60        1.1       mrg 
     61        1.1       mrg 	sp32->st_dev = sp12->st_dev;
     62        1.1       mrg 	sp32->st_ino = sp12->st_ino;
     63        1.1       mrg 	sp32->st_mode = sp12->st_mode;
     64        1.1       mrg 	sp32->st_nlink = sp12->st_nlink;
     65        1.1       mrg 	sp32->st_uid = sp12->st_uid;
     66        1.1       mrg 	sp32->st_gid = sp12->st_gid;
     67        1.1       mrg 	sp32->st_rdev = sp12->st_rdev;
     68        1.1       mrg 	if (sp12->st_size < (quad_t)1 << 32)
     69        1.1       mrg 		sp32->st_size = sp12->st_size;
     70        1.1       mrg 	else
     71        1.1       mrg 		sp32->st_size = -2;
     72        1.1       mrg 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     73        1.1       mrg 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     74        1.1       mrg 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     75        1.1       mrg 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     76        1.1       mrg 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     77        1.1       mrg 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     78        1.1       mrg 	sp32->st_blocks = sp12->st_blocks;
     79        1.1       mrg 	sp32->st_blksize = sp12->st_blksize;
     80        1.1       mrg 	sp32->st_flags = sp12->st_flags;
     81        1.1       mrg 	sp32->st_gen = sp12->st_gen;
     82        1.3       eeh }
     83        1.3       eeh 
     84        1.3       eeh int
     85       1.30       dsl compat_12_netbsd32_reboot(struct lwp *l, const struct compat_12_netbsd32_reboot_args *uap, register_t *retval)
     86        1.3       eeh {
     87       1.30       dsl 	/* {
     88        1.3       eeh 		syscallarg(int) opt;
     89       1.30       dsl 	} */
     90        1.3       eeh 	struct compat_12_sys_reboot_args ua;
     91        1.3       eeh 
     92        1.5       mrg 	NETBSD32TO64_UAP(opt);
     93       1.16   thorpej 	return (compat_12_sys_reboot(l, &ua, retval));
     94        1.1       mrg }
     95        1.1       mrg 
     96        1.1       mrg int
     97       1.30       dsl compat_12_netbsd32_msync(struct lwp *l, const struct compat_12_netbsd32_msync_args *uap, register_t *retval)
     98        1.1       mrg {
     99       1.30       dsl 	/* {
    100       1.23  christos 		syscallarg(netbsd32_caddr_t) addr;
    101        1.4       mrg 		syscallarg(netbsd32_size_t) len;
    102       1.30       dsl 	} */
    103        1.1       mrg 	struct sys___msync13_args ua;
    104        1.1       mrg 
    105       1.24       dsl 	NETBSD32TOP_UAP(addr, void *);
    106        1.5       mrg 	NETBSD32TOX_UAP(len, size_t);
    107        1.1       mrg 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    108       1.16   thorpej 	return (sys___msync13(l, &ua, retval));
    109        1.1       mrg }
    110        1.1       mrg 
    111        1.1       mrg int
    112       1.30       dsl compat_12_netbsd32_oswapon(struct lwp *l, const struct compat_12_netbsd32_oswapon_args *uap, register_t *retval)
    113        1.1       mrg {
    114       1.30       dsl 	/* {
    115        1.4       mrg 		syscallarg(const netbsd32_charp) name;
    116       1.30       dsl 	} */
    117        1.1       mrg 	struct sys_swapctl_args ua;
    118        1.1       mrg 
    119        1.1       mrg 	SCARG(&ua, cmd) = SWAP_ON;
    120       1.25       dsl 	SCARG(&ua, arg) = SCARG_P32(uap, name);
    121        1.1       mrg 	SCARG(&ua, misc) = 0;	/* priority */
    122       1.16   thorpej 	return (sys_swapctl(l, &ua, retval));
    123        1.1       mrg }
    124        1.1       mrg 
    125        1.1       mrg int
    126       1.30       dsl compat_12_netbsd32_stat12(struct lwp *l, const struct compat_12_netbsd32_stat12_args *uap, register_t *retval)
    127        1.1       mrg {
    128       1.30       dsl 	/* {
    129        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    130        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    131       1.30       dsl 	} */
    132       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    133        1.1       mrg 	struct stat12 sb12;
    134        1.1       mrg 	struct stat12 *sp12 = &sb12;
    135        1.1       mrg 	struct compat_12_sys_stat_args ua;
    136        1.1       mrg 	int rv;
    137        1.1       mrg 
    138        1.5       mrg 	NETBSD32TOP_UAP(path, const char);
    139        1.1       mrg 	SCARG(&ua, ub) = &sb12;
    140        1.1       mrg 
    141       1.16   thorpej 	rv = compat_12_sys_stat(l, &ua, retval);
    142       1.10       mrg 	if (rv)
    143       1.10       mrg 		return (rv);
    144        1.1       mrg 
    145       1.25       dsl 	sp32 = SCARG_P32(uap, ub);
    146       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    147        1.1       mrg 
    148       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    149        1.1       mrg }
    150        1.1       mrg 
    151        1.1       mrg int
    152       1.30       dsl compat_12_netbsd32_fstat12(struct lwp *l, const struct compat_12_netbsd32_fstat12_args *uap, register_t *retval)
    153        1.1       mrg {
    154       1.30       dsl 	/* {
    155        1.1       mrg 		syscallarg(int) fd;
    156        1.4       mrg 		syscallarg(netbsd32_stat12p_t) sb;
    157       1.30       dsl 	} */
    158       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    159        1.1       mrg 	struct stat12 sb12;
    160        1.1       mrg 	struct stat12 *sp12 = &sb12;
    161        1.1       mrg 	struct compat_12_sys_fstat_args ua;
    162        1.1       mrg 	int rv;
    163        1.1       mrg 
    164        1.5       mrg 	NETBSD32TO64_UAP(fd);
    165        1.1       mrg 	SCARG(&ua, sb) = &sb12;
    166       1.16   thorpej 	rv = compat_12_sys_fstat(l, &ua, retval);
    167       1.10       mrg 	if (rv)
    168       1.10       mrg 		return (rv);
    169        1.1       mrg 
    170       1.25       dsl 	sp32 = SCARG_P32(uap, sb);
    171       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    172        1.1       mrg 
    173       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    174        1.1       mrg }
    175        1.1       mrg 
    176        1.1       mrg int
    177       1.30       dsl compat_12_netbsd32_lstat12(struct lwp *l, const struct compat_12_netbsd32_lstat12_args *uap, register_t *retval)
    178        1.1       mrg {
    179       1.30       dsl 	/* {
    180        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    181        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    182       1.30       dsl 	} */
    183       1.10       mrg 	struct netbsd32_stat12 *sp32, sb32;
    184        1.1       mrg 	struct stat12 sb12;
    185        1.1       mrg 	struct stat12 *sp12 = &sb12;
    186        1.1       mrg 	struct compat_12_sys_lstat_args ua;
    187        1.1       mrg 	int rv;
    188        1.1       mrg 
    189        1.5       mrg 	NETBSD32TOP_UAP(path, const char);
    190        1.1       mrg 	SCARG(&ua, ub) = &sb12;
    191        1.1       mrg 
    192       1.16   thorpej 	rv = compat_12_sys_lstat(l, &ua, retval);
    193       1.10       mrg 	if (rv)
    194       1.10       mrg 		return (rv);
    195        1.1       mrg 
    196       1.25       dsl 	sp32 = SCARG_P32(uap, ub);
    197       1.10       mrg 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
    198        1.1       mrg 
    199       1.10       mrg 	return (copyout(&sb32, sp32, sizeof sb32));
    200        1.1       mrg }
    201        1.1       mrg 
    202        1.1       mrg int
    203       1.30       dsl compat_12_netbsd32_getdirentries(struct lwp *l, const struct compat_12_netbsd32_getdirentries_args *uap, register_t *retval)
    204        1.1       mrg {
    205       1.30       dsl 	/* {
    206        1.1       mrg 		syscallarg(int) fd;
    207        1.4       mrg 		syscallarg(netbsd32_charp) buf;
    208        1.1       mrg 		syscallarg(u_int) count;
    209        1.4       mrg 		syscallarg(netbsd32_longp) basep;
    210       1.30       dsl 	} */
    211        1.1       mrg 	struct compat_12_sys_getdirentries_args ua;
    212        1.1       mrg 
    213        1.5       mrg 	NETBSD32TO64_UAP(fd);
    214        1.5       mrg 	NETBSD32TOP_UAP(buf, char);
    215        1.5       mrg 	NETBSD32TO64_UAP(count);
    216        1.5       mrg 	NETBSD32TOP_UAP(basep, long);
    217        1.1       mrg 
    218       1.16   thorpej 	return (compat_12_sys_getdirentries(l, &ua, retval));
    219        1.1       mrg }
    220