Home | History | Annotate | Line # | Download | only in netbsd32
      1 /*	$NetBSD: netbsd32_compat_90.c,v 1.2 2023/07/29 13:57:28 pgoyette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software developed for The NetBSD Foundation
      8  * by Christos Zoulas.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_90.c,v 1.2 2023/07/29 13:57:28 pgoyette Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/kmem.h>
     37 #include <sys/module.h>
     38 #include <sys/filedesc.h>
     39 #include <sys/statvfs.h>
     40 #include <sys/vfs_syscalls.h>
     41 #include <sys/syscallvar.h>
     42 
     43 #include <compat/netbsd32/netbsd32.h>
     44 #include <compat/netbsd32/netbsd32_syscall.h>
     45 #include <compat/netbsd32/netbsd32_syscallargs.h>
     46 #include <compat/netbsd32/netbsd32_conv.h>
     47 
     48 static int
     49 netbsd32_copyout_statvfs90(const void *kp, void *up, size_t len)
     50 {
     51 	struct netbsd32_statvfs90 *sbuf_32;
     52 	int error;
     53 
     54 	sbuf_32 = kmem_alloc(sizeof(*sbuf_32), KM_SLEEP);
     55 	netbsd32_from_statvfs90(kp, sbuf_32);
     56 	error = copyout(sbuf_32, up, sizeof(*sbuf_32));
     57 	kmem_free(sbuf_32, sizeof(*sbuf_32));
     58 
     59 	return error;
     60 }
     61 
     62 int
     63 compat_90_netbsd32_getvfsstat(struct lwp *l,
     64     const struct compat_90_netbsd32_getvfsstat_args *uap, register_t *retval)
     65 {
     66 	/* {
     67 		syscallarg(netbsd32_statvfs90p_t) buf;
     68 		syscallarg(netbsd32_size_t) bufsize;
     69 		syscallarg(int) flags;
     70 	} */
     71 
     72 	return do_sys_getvfsstat(l, SCARG_P32(uap, buf), SCARG(uap, bufsize),
     73 	    SCARG(uap, flags), netbsd32_copyout_statvfs90,
     74 	    sizeof(struct netbsd32_statvfs90), retval);
     75 }
     76 
     77 int
     78 compat_90_netbsd32_statvfs1(struct lwp *l,
     79     const struct compat_90_netbsd32_statvfs1_args *uap, register_t *retval)
     80 {
     81 	/* {
     82 		syscallarg(const netbsd32_charp) path;
     83 		syscallarg(netbsd32_statvfs90p_t) buf;
     84 		syscallarg(int) flags;
     85 	} */
     86 	struct statvfs *sb;
     87 	int error;
     88 
     89 	sb = STATVFSBUF_GET();
     90 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), SCARG(uap, flags), sb);
     91 	if (error == 0)
     92 		error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf),
     93 		    sizeof(struct netbsd32_statvfs90));
     94 	STATVFSBUF_PUT(sb);
     95 	return error;
     96 }
     97 
     98 int
     99 compat_90_netbsd32_fstatvfs1(struct lwp *l,
    100     const struct compat_90_netbsd32_fstatvfs1_args *uap, register_t *retval)
    101 {
    102 	/* {
    103 		syscallarg(int) fd;
    104 		syscallarg(netbsd32_statvfs90p_t) buf;
    105 		syscallarg(int) flags;
    106 	} */
    107 	struct statvfs *sb;
    108 	int error;
    109 
    110 	sb = STATVFSBUF_GET();
    111 	error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
    112 	if (error == 0)
    113 		error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf), 0);
    114 	STATVFSBUF_PUT(sb);
    115 	return error;
    116 }
    117 
    118 
    119 int
    120 compat_90_netbsd32_fhstatvfs1(struct lwp *l,
    121     const struct compat_90_netbsd32_fhstatvfs1_args *uap, register_t *retval)
    122 {
    123 	/* {
    124 		syscallarg(const netbsd32_pointer_t) fhp;
    125 		syscallarg(netbsd32_size_t) fh_size;
    126 		syscallarg(netbsd32_statvfs90p_t) buf;
    127 		syscallarg(int) flags;
    128 	} */
    129 	struct statvfs *sb;
    130 	int error;
    131 
    132 	sb = STATVFSBUF_GET();
    133 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), sb,
    134 	    SCARG(uap, flags));
    135 
    136 	if (error == 0)
    137 		error = netbsd32_copyout_statvfs90(sb, SCARG_P32(uap, buf), 0);
    138 	STATVFSBUF_PUT(sb);
    139 
    140 	return error;
    141 }
    142 
    143 static struct syscall_package compat_netbsd32_90_syscalls[] = {
    144 	{ NETBSD32_SYS_compat_90_netbsd32_getvfsstat, 0,
    145 	    (sy_call_t *)compat_90_netbsd32_getvfsstat },
    146 	{ NETBSD32_SYS_compat_90_netbsd32_statvfs1, 0,
    147 	    (sy_call_t *)compat_90_netbsd32_statvfs1 },
    148 	{ NETBSD32_SYS_compat_90_netbsd32_fstatvfs1, 0,
    149 	    (sy_call_t *)compat_90_netbsd32_fstatvfs1 },
    150 	{ NETBSD32_SYS_compat_90_netbsd32_fhstatvfs1, 0,
    151 	    (sy_call_t *)compat_90_netbsd32_fhstatvfs1 },
    152 	{ 0, 0, NULL }
    153 };
    154 
    155 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_90, "compat_netbsd32_100,compat_90");
    156 
    157 
    158 static int
    159 compat_netbsd32_90_modcmd(modcmd_t cmd, void *arg)
    160 {
    161 
    162 	switch (cmd) {
    163 	case MODULE_CMD_INIT:
    164 		return syscall_establish(&emul_netbsd32,
    165 		    compat_netbsd32_90_syscalls);
    166 
    167 	case MODULE_CMD_FINI:
    168 		return syscall_disestablish(&emul_netbsd32,
    169 		    compat_netbsd32_90_syscalls);
    170 
    171 	default:
    172 		return ENOTTY;
    173 	}
    174 }
    175