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