Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_12.c revision 1.33.36.6
      1  1.33.36.6  pgoyette /*	$NetBSD: netbsd32_compat_12.c,v 1.33.36.6 2018/09/11 05:00:42 pgoyette 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  *
     16        1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17        1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18        1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19        1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20        1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21        1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22        1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23        1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24        1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1       mrg  * SUCH DAMAGE.
     27        1.1       mrg  */
     28       1.13     lukem 
     29       1.13     lukem #include <sys/cdefs.h>
     30  1.33.36.6  pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_12.c,v 1.33.36.6 2018/09/11 05:00:42 pgoyette Exp $");
     31        1.9      fvdl 
     32       1.11       mrg #if defined(_KERNEL_OPT)
     33        1.9      fvdl #include "opt_compat_netbsd.h"
     34        1.9      fvdl #endif
     35        1.1       mrg 
     36        1.1       mrg #include <sys/param.h>
     37        1.1       mrg #include <sys/systm.h>
     38  1.33.36.1  pgoyette #include <sys/module.h>
     39       1.33       chs #include <sys/filedesc.h>
     40        1.1       mrg #include <sys/mount.h>
     41        1.1       mrg #include <sys/mman.h>
     42       1.33       chs #include <sys/namei.h>
     43        1.1       mrg #include <sys/proc.h>
     44        1.1       mrg #include <sys/stat.h>
     45        1.2       mrg #include <sys/swap.h>
     46       1.33       chs #include <sys/vfs_syscalls.h>
     47       1.33       chs 
     48        1.1       mrg #include <sys/syscallargs.h>
     49  1.33.36.3  pgoyette #include <sys/syscallvar.h>
     50        1.1       mrg 
     51       1.19  christos #include <compat/sys/stat.h>
     52       1.19  christos 
     53        1.4       mrg #include <compat/netbsd32/netbsd32.h>
     54  1.33.36.4  pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
     55        1.4       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     56        1.1       mrg 
     57  1.33.36.6  pgoyette extern struct emul emul_netbsd32;
     58  1.33.36.6  pgoyette 
     59       1.28       dsl static void netbsd32_stat12_to_netbsd32(struct stat12 *,
     60       1.28       dsl 		struct netbsd32_stat12 *);
     61        1.1       mrg 
     62        1.1       mrg /* for use with {,fl}stat() */
     63        1.1       mrg static void
     64       1.29       dsl netbsd32_stat12_to_netbsd32(struct stat12 *sp12, struct netbsd32_stat12 *sp32)
     65        1.1       mrg {
     66        1.1       mrg 
     67        1.1       mrg 	sp32->st_dev = sp12->st_dev;
     68        1.1       mrg 	sp32->st_ino = sp12->st_ino;
     69        1.1       mrg 	sp32->st_mode = sp12->st_mode;
     70        1.1       mrg 	sp32->st_nlink = sp12->st_nlink;
     71        1.1       mrg 	sp32->st_uid = sp12->st_uid;
     72        1.1       mrg 	sp32->st_gid = sp12->st_gid;
     73        1.1       mrg 	sp32->st_rdev = sp12->st_rdev;
     74        1.1       mrg 	if (sp12->st_size < (quad_t)1 << 32)
     75        1.1       mrg 		sp32->st_size = sp12->st_size;
     76        1.1       mrg 	else
     77        1.1       mrg 		sp32->st_size = -2;
     78        1.1       mrg 	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
     79        1.1       mrg 	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
     80        1.1       mrg 	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
     81        1.1       mrg 	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
     82        1.1       mrg 	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
     83        1.1       mrg 	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
     84        1.1       mrg 	sp32->st_blocks = sp12->st_blocks;
     85        1.1       mrg 	sp32->st_blksize = sp12->st_blksize;
     86        1.1       mrg 	sp32->st_flags = sp12->st_flags;
     87        1.1       mrg 	sp32->st_gen = sp12->st_gen;
     88        1.3       eeh }
     89        1.3       eeh 
     90        1.3       eeh int
     91       1.30       dsl compat_12_netbsd32_reboot(struct lwp *l, const struct compat_12_netbsd32_reboot_args *uap, register_t *retval)
     92        1.3       eeh {
     93       1.30       dsl 	/* {
     94        1.3       eeh 		syscallarg(int) opt;
     95       1.30       dsl 	} */
     96        1.3       eeh 	struct compat_12_sys_reboot_args ua;
     97        1.3       eeh 
     98        1.5       mrg 	NETBSD32TO64_UAP(opt);
     99       1.16   thorpej 	return (compat_12_sys_reboot(l, &ua, retval));
    100        1.1       mrg }
    101        1.1       mrg 
    102        1.1       mrg int
    103       1.30       dsl compat_12_netbsd32_msync(struct lwp *l, const struct compat_12_netbsd32_msync_args *uap, register_t *retval)
    104        1.1       mrg {
    105       1.30       dsl 	/* {
    106       1.32     njoly 		syscallarg(netbsd32_voidp) addr;
    107        1.4       mrg 		syscallarg(netbsd32_size_t) len;
    108       1.30       dsl 	} */
    109        1.1       mrg 	struct sys___msync13_args ua;
    110        1.1       mrg 
    111       1.24       dsl 	NETBSD32TOP_UAP(addr, void *);
    112        1.5       mrg 	NETBSD32TOX_UAP(len, size_t);
    113        1.1       mrg 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
    114       1.16   thorpej 	return (sys___msync13(l, &ua, retval));
    115        1.1       mrg }
    116        1.1       mrg 
    117        1.1       mrg int
    118       1.30       dsl compat_12_netbsd32_oswapon(struct lwp *l, const struct compat_12_netbsd32_oswapon_args *uap, register_t *retval)
    119        1.1       mrg {
    120       1.30       dsl 	/* {
    121        1.4       mrg 		syscallarg(const netbsd32_charp) name;
    122       1.30       dsl 	} */
    123        1.1       mrg 	struct sys_swapctl_args ua;
    124        1.1       mrg 
    125        1.1       mrg 	SCARG(&ua, cmd) = SWAP_ON;
    126       1.25       dsl 	SCARG(&ua, arg) = SCARG_P32(uap, name);
    127        1.1       mrg 	SCARG(&ua, misc) = 0;	/* priority */
    128       1.16   thorpej 	return (sys_swapctl(l, &ua, retval));
    129        1.1       mrg }
    130        1.1       mrg 
    131        1.1       mrg int
    132       1.30       dsl compat_12_netbsd32_stat12(struct lwp *l, const struct compat_12_netbsd32_stat12_args *uap, register_t *retval)
    133        1.1       mrg {
    134       1.30       dsl 	/* {
    135        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    136        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    137       1.30       dsl 	} */
    138       1.33       chs 	struct netbsd32_stat12 sb32;
    139        1.1       mrg 	struct stat12 sb12;
    140       1.33       chs 	struct stat sb;
    141       1.33       chs 	int error;
    142        1.1       mrg 
    143       1.33       chs 	error = do_sys_stat(SCARG_P32(uap, path), FOLLOW, &sb);
    144       1.33       chs 	if (error)
    145       1.33       chs 		return (error);
    146        1.1       mrg 
    147       1.33       chs 	compat_12_stat_conv(&sb, &sb12);
    148       1.33       chs 	netbsd32_stat12_to_netbsd32(&sb12, &sb32);
    149        1.1       mrg 
    150       1.33       chs 	return (copyout(&sb32, SCARG_P32(uap, ub), sizeof sb32));
    151        1.1       mrg }
    152        1.1       mrg 
    153        1.1       mrg int
    154       1.30       dsl compat_12_netbsd32_fstat12(struct lwp *l, const struct compat_12_netbsd32_fstat12_args *uap, register_t *retval)
    155        1.1       mrg {
    156       1.30       dsl 	/* {
    157        1.1       mrg 		syscallarg(int) fd;
    158        1.4       mrg 		syscallarg(netbsd32_stat12p_t) sb;
    159       1.30       dsl 	} */
    160       1.33       chs 	struct netbsd32_stat12 sb32;
    161        1.1       mrg 	struct stat12 sb12;
    162       1.33       chs 	struct stat sb;
    163       1.33       chs 	int error;
    164        1.1       mrg 
    165       1.33       chs 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    166       1.33       chs 	if (error)
    167       1.33       chs 		return (error);
    168        1.1       mrg 
    169       1.33       chs 	compat_12_stat_conv(&sb, &sb12);
    170       1.33       chs 	netbsd32_stat12_to_netbsd32(&sb12, &sb32);
    171        1.1       mrg 
    172       1.33       chs 	return (copyout(&sb32, SCARG_P32(uap, sb), sizeof sb32));
    173        1.1       mrg }
    174        1.1       mrg 
    175        1.1       mrg int
    176       1.30       dsl compat_12_netbsd32_lstat12(struct lwp *l, const struct compat_12_netbsd32_lstat12_args *uap, register_t *retval)
    177        1.1       mrg {
    178       1.30       dsl 	/* {
    179        1.4       mrg 		syscallarg(const netbsd32_charp) path;
    180        1.4       mrg 		syscallarg(netbsd32_stat12p_t) ub;
    181       1.30       dsl 	} */
    182       1.33       chs 	struct netbsd32_stat12 sb32;
    183        1.1       mrg 	struct stat12 sb12;
    184       1.33       chs 	struct stat sb;
    185       1.33       chs 	int error;
    186        1.1       mrg 
    187       1.33       chs 	error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &sb);
    188       1.33       chs 	if (error)
    189       1.33       chs 		return (error);
    190        1.1       mrg 
    191       1.33       chs 	compat_12_stat_conv(&sb, &sb12);
    192       1.33       chs 	netbsd32_stat12_to_netbsd32(&sb12, &sb32);
    193        1.1       mrg 
    194       1.33       chs 	return (copyout(&sb32, SCARG_P32(uap, ub), sizeof sb32));
    195        1.1       mrg }
    196        1.1       mrg 
    197        1.1       mrg int
    198       1.30       dsl compat_12_netbsd32_getdirentries(struct lwp *l, const struct compat_12_netbsd32_getdirentries_args *uap, register_t *retval)
    199        1.1       mrg {
    200       1.30       dsl 	/* {
    201        1.1       mrg 		syscallarg(int) fd;
    202        1.4       mrg 		syscallarg(netbsd32_charp) buf;
    203        1.1       mrg 		syscallarg(u_int) count;
    204        1.4       mrg 		syscallarg(netbsd32_longp) basep;
    205       1.30       dsl 	} */
    206        1.1       mrg 	struct compat_12_sys_getdirentries_args ua;
    207        1.1       mrg 
    208        1.5       mrg 	NETBSD32TO64_UAP(fd);
    209        1.5       mrg 	NETBSD32TOP_UAP(buf, char);
    210        1.5       mrg 	NETBSD32TO64_UAP(count);
    211        1.5       mrg 	NETBSD32TOP_UAP(basep, long);
    212        1.1       mrg 
    213       1.16   thorpej 	return (compat_12_sys_getdirentries(l, &ua, retval));
    214        1.1       mrg }
    215  1.33.36.1  pgoyette 
    216  1.33.36.2  pgoyette static struct syscall_package compat_netbsd32_12_syscalls[] = {
    217  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_reboot, 0,
    218  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_reboot },
    219  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_msync, 0,
    220  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_msync },
    221  1.33.36.5  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_oswapon, 0,
    222  1.33.36.5  pgoyette 	    (sy_call_t *)compat_12_netbsd32_oswapon },
    223  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_stat12, 0,
    224  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_stat12 },
    225  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_fstat12, 0,
    226  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_fstat12 },
    227  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_lstat12, 0,
    228  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_lstat12 },
    229  1.33.36.4  pgoyette 	{ NETBSD32_SYS_compat_12_netbsd32_getdirentries, 0,
    230  1.33.36.2  pgoyette 	    (sy_call_t *)compat_12_netbsd32_getdirentries },
    231  1.33.36.2  pgoyette 	{ 0, 0, NULL }
    232  1.33.36.1  pgoyette };
    233  1.33.36.1  pgoyette 
    234  1.33.36.1  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_12, "compat_netbsd32,compat_12");
    235  1.33.36.1  pgoyette 
    236  1.33.36.1  pgoyette static int
    237  1.33.36.1  pgoyette compat_netbsd32_12_modcmd(modcmd_t cmd, void *arg)
    238  1.33.36.1  pgoyette {
    239  1.33.36.1  pgoyette 
    240  1.33.36.1  pgoyette 	switch (cmd) {
    241  1.33.36.1  pgoyette 	case MODULE_CMD_INIT:
    242  1.33.36.5  pgoyette 		return syscall_establish(&emul_netbsd32,
    243  1.33.36.5  pgoyette 		    compat_netbsd32_12_syscalls);
    244  1.33.36.1  pgoyette 
    245  1.33.36.1  pgoyette 	case MODULE_CMD_FINI:
    246  1.33.36.5  pgoyette 		return syscall_disestablish(&emul_netbsd32,
    247  1.33.36.5  pgoyette 		    compat_netbsd32_12_syscalls);
    248  1.33.36.1  pgoyette 
    249  1.33.36.1  pgoyette 	default:
    250  1.33.36.1  pgoyette 		return ENOTTY;
    251  1.33.36.1  pgoyette 	}
    252  1.33.36.1  pgoyette }
    253