Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.4
      1  1.4  mrg /*	$NetBSD: netbsd32_compat_12.c,v 1.4 1999/03/25 16:22:49 mrg Exp $	*/
      2  1.1  mrg 
      3  1.1  mrg /*
      4  1.1  mrg  * Copyright (c) 1998 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.1  mrg 
     31  1.1  mrg #include <sys/param.h>
     32  1.1  mrg #include <sys/systm.h>
     33  1.1  mrg #include <sys/mount.h>
     34  1.1  mrg #include <sys/mman.h>
     35  1.1  mrg #include <sys/proc.h>
     36  1.1  mrg #include <sys/stat.h>
     37  1.2  mrg #include <sys/swap.h>
     38  1.1  mrg #include <sys/syscallargs.h>
     39  1.1  mrg 
     40  1.4  mrg #include <compat/netbsd32/netbsd32.h>
     41  1.4  mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     42  1.1  mrg 
     43  1.1  mrg 
     44  1.1  mrg /* for use with {,fl}stat() */
     45  1.1  mrg static void
     46  1.4  mrg compat_netbsd32_stat12_to_netbsd32(sp12, sp32)
     47  1.1  mrg 	struct stat12 *sp12;
     48  1.4  mrg 	struct netbsd32_stat12 *sp32;
     49  1.1  mrg {
     50  1.1  mrg 
     51  1.1  mrg 	sp32->st_dev = sp12->st_dev;
     52  1.1  mrg 	sp32->st_ino = sp12->st_ino;
     53  1.1  mrg 	sp32->st_mode = sp12->st_mode;
     54  1.1  mrg 	sp32->st_nlink = sp12->st_nlink;
     55  1.1  mrg 	sp32->st_uid = sp12->st_uid;
     56  1.1  mrg 	sp32->st_gid = sp12->st_gid;
     57  1.1  mrg 	sp32->st_rdev = sp12->st_rdev;
     58  1.1  mrg 	if (sp12->st_size < (quad_t)1 << 32)
     59  1.1  mrg 		sp32->st_size = sp12->st_size;
     60  1.1  mrg 	else
     61  1.1  mrg 		sp32->st_size = -2;
     62  1.1  mrg 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     63  1.1  mrg 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     64  1.1  mrg 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     65  1.1  mrg 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     66  1.1  mrg 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     67  1.1  mrg 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     68  1.1  mrg 	sp32->st_blocks = sp12->st_blocks;
     69  1.1  mrg 	sp32->st_blksize = sp12->st_blksize;
     70  1.1  mrg 	sp32->st_flags = sp12->st_flags;
     71  1.1  mrg 	sp32->st_gen = sp12->st_gen;
     72  1.3  eeh }
     73  1.3  eeh 
     74  1.3  eeh int
     75  1.4  mrg compat_12_compat_netbsd32_reboot(p, v, retval)
     76  1.3  eeh 	struct proc *p;
     77  1.3  eeh 	void *v;
     78  1.3  eeh 	register_t *retval;
     79  1.3  eeh {
     80  1.4  mrg 	struct compat_12_compat_netbsd32_reboot_args /* {
     81  1.3  eeh 		syscallarg(int) opt;
     82  1.3  eeh 	} */ *uap = v;
     83  1.3  eeh 	struct compat_12_sys_reboot_args ua;
     84  1.3  eeh 
     85  1.3  eeh 	SPARC32TO64_UAP(opt);
     86  1.3  eeh 	return (compat_12_sys_reboot(p, &ua, retval));
     87  1.1  mrg }
     88  1.1  mrg 
     89  1.1  mrg int
     90  1.4  mrg compat_12_compat_netbsd32_msync(p, v, retval)
     91  1.1  mrg 	struct proc *p;
     92  1.1  mrg 	void *v;
     93  1.1  mrg 	register_t *retval;
     94  1.1  mrg {
     95  1.4  mrg 	struct compat_12_compat_netbsd32_msync_args /* {
     96  1.4  mrg 		syscallarg(netbsd32_caddr_t) addr;
     97  1.4  mrg 		syscallarg(netbsd32_size_t) len;
     98  1.1  mrg 	} */ *uap = v;
     99  1.1  mrg 	struct sys___msync13_args ua;
    100  1.1  mrg 
    101  1.1  mrg 	SPARC32TOX64_UAP(addr, caddr_t);
    102  1.1  mrg 	SPARC32TOX_UAP(len, size_t);
    103  1.1  mrg 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    104  1.1  mrg 	return (sys___msync13(p, &ua, retval));
    105  1.1  mrg }
    106  1.1  mrg 
    107  1.1  mrg int
    108  1.4  mrg compat_12_compat_netbsd32_oswapon(p, v, retval)
    109  1.1  mrg 	struct proc *p;
    110  1.1  mrg 	void *v;
    111  1.1  mrg 	register_t *retval;
    112  1.1  mrg {
    113  1.4  mrg 	struct compat_12_compat_netbsd32_oswapon_args /* {
    114  1.4  mrg 		syscallarg(const netbsd32_charp) name;
    115  1.1  mrg 	} */ *uap = v;
    116  1.1  mrg 	struct sys_swapctl_args ua;
    117  1.1  mrg 
    118  1.1  mrg 	SCARG(&ua, cmd) = SWAP_ON;
    119  1.1  mrg 	SCARG(&ua, arg) = (void *)(u_long)SCARG(uap, name);
    120  1.1  mrg 	SCARG(&ua, misc) = 0;	/* priority */
    121  1.1  mrg 	return (sys_swapctl(p, &ua, retval));
    122  1.1  mrg }
    123  1.1  mrg 
    124  1.1  mrg int
    125  1.4  mrg compat_12_compat_netbsd32_stat12(p, v, retval)
    126  1.1  mrg 	struct proc *p;
    127  1.1  mrg 	void *v;
    128  1.1  mrg 	register_t *retval;
    129  1.1  mrg {
    130  1.4  mrg 	struct compat_12_compat_netbsd32_stat12_args /* {
    131  1.4  mrg 		syscallarg(const netbsd32_charp) path;
    132  1.4  mrg 		syscallarg(netbsd32_stat12p_t) ub;
    133  1.1  mrg 	} */ *uap = v;
    134  1.4  mrg 	struct netbsd32_stat12 *sp32;
    135  1.1  mrg 	struct stat12 sb12;
    136  1.1  mrg 	struct stat12 *sp12 = &sb12;
    137  1.1  mrg 	struct compat_12_sys_stat_args ua;
    138  1.1  mrg 	caddr_t sg;
    139  1.1  mrg 	int rv;
    140  1.1  mrg 
    141  1.1  mrg 	SPARC32TOP_UAP(path, const char);
    142  1.1  mrg 	SCARG(&ua, ub) = &sb12;
    143  1.1  mrg 	sg = stackgap_init(p->p_emul);
    144  1.1  mrg 	SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    145  1.1  mrg 
    146  1.1  mrg 	rv = compat_12_sys_stat(p, &ua, retval);
    147  1.1  mrg 
    148  1.4  mrg 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub);
    149  1.4  mrg 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    150  1.1  mrg 
    151  1.1  mrg 	return (rv);
    152  1.1  mrg }
    153  1.1  mrg 
    154  1.1  mrg int
    155  1.4  mrg compat_12_compat_netbsd32_fstat12(p, v, retval)
    156  1.1  mrg 	struct proc *p;
    157  1.1  mrg 	void *v;
    158  1.1  mrg 	register_t *retval;
    159  1.1  mrg {
    160  1.4  mrg 	struct compat_12_compat_netbsd32_fstat12_args /* {
    161  1.1  mrg 		syscallarg(int) fd;
    162  1.4  mrg 		syscallarg(netbsd32_stat12p_t) sb;
    163  1.1  mrg 	} */ *uap = v;
    164  1.4  mrg 	struct netbsd32_stat12 *sp32;
    165  1.1  mrg 	struct stat12 sb12;
    166  1.1  mrg 	struct stat12 *sp12 = &sb12;
    167  1.1  mrg 	struct compat_12_sys_fstat_args ua;
    168  1.1  mrg 	int rv;
    169  1.1  mrg 
    170  1.1  mrg 	SPARC32TO64_UAP(fd);
    171  1.1  mrg 	SCARG(&ua, sb) = &sb12;
    172  1.1  mrg 	rv = compat_12_sys_fstat(p, &ua, retval);
    173  1.1  mrg 
    174  1.4  mrg 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, sb);
    175  1.4  mrg 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    176  1.1  mrg 
    177  1.1  mrg 	return (rv);
    178  1.1  mrg }
    179  1.1  mrg 
    180  1.1  mrg int
    181  1.4  mrg compat_12_compat_netbsd32_lstat12(p, v, retval)
    182  1.1  mrg 	struct proc *p;
    183  1.1  mrg 	void *v;
    184  1.1  mrg 	register_t *retval;
    185  1.1  mrg {
    186  1.4  mrg 	struct compat_12_compat_netbsd32_lstat12_args /* {
    187  1.4  mrg 		syscallarg(const netbsd32_charp) path;
    188  1.4  mrg 		syscallarg(netbsd32_stat12p_t) ub;
    189  1.1  mrg 	} */ *uap = v;
    190  1.4  mrg 	struct netbsd32_stat12 *sp32;
    191  1.1  mrg 	struct stat12 sb12;
    192  1.1  mrg 	struct stat12 *sp12 = &sb12;
    193  1.1  mrg 	struct compat_12_sys_lstat_args ua;
    194  1.1  mrg 	caddr_t sg;
    195  1.1  mrg 	int rv;
    196  1.1  mrg 
    197  1.1  mrg 	SPARC32TOP_UAP(path, const char);
    198  1.1  mrg 	SCARG(&ua, ub) = &sb12;
    199  1.1  mrg 	sg = stackgap_init(p->p_emul);
    200  1.1  mrg 	SPARC32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
    201  1.1  mrg 
    202  1.1  mrg 	rv = compat_12_sys_lstat(p, &ua, retval);
    203  1.1  mrg 
    204  1.4  mrg 	sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub);
    205  1.4  mrg 	compat_netbsd32_stat12_to_netbsd32(sp12, sp32);
    206  1.1  mrg 
    207  1.1  mrg 	return (rv);
    208  1.1  mrg }
    209  1.1  mrg 
    210  1.1  mrg int
    211  1.4  mrg compat_12_compat_netbsd32_getdirentries(p, v, retval)
    212  1.1  mrg 	struct proc *p;
    213  1.1  mrg 	void *v;
    214  1.1  mrg 	register_t *retval;
    215  1.1  mrg {
    216  1.4  mrg 	struct compat_12_compat_netbsd32_getdirentries_args /* {
    217  1.1  mrg 		syscallarg(int) fd;
    218  1.4  mrg 		syscallarg(netbsd32_charp) buf;
    219  1.1  mrg 		syscallarg(u_int) count;
    220  1.4  mrg 		syscallarg(netbsd32_longp) basep;
    221  1.1  mrg 	} */ *uap = v;
    222  1.1  mrg 	struct compat_12_sys_getdirentries_args ua;
    223  1.1  mrg 
    224  1.1  mrg 	SPARC32TO64_UAP(fd);
    225  1.1  mrg 	SPARC32TOP_UAP(buf, char);
    226  1.1  mrg 	SPARC32TO64_UAP(count);
    227  1.1  mrg 	SPARC32TOP_UAP(basep, long);
    228  1.1  mrg 
    229  1.1  mrg 	return (compat_12_sys_getdirentries(p, &ua, retval));
    230  1.1  mrg }
    231