netbsd32_compat_12.c revision 1.11
1/* $NetBSD: netbsd32_compat_12.c,v 1.11 2001/05/30 11:37:28 mrg 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_OPT) 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 47static void netbsd32_stat12_to_netbsd32 __P((struct stat12 *, 48 struct netbsd32_stat12 *)); 49 50/* for use with {,fl}stat() */ 51static void 52netbsd32_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 80int 81compat_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 95int 96compat_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 113int 114compat_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 130int 131compat_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, sb32; 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 if (rv) 154 return (rv); 155 156 sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub); 157 netbsd32_stat12_to_netbsd32(sp12, &sb32); 158 159 return (copyout(&sb32, sp32, sizeof sb32)); 160} 161 162int 163compat_12_netbsd32_fstat12(p, v, retval) 164 struct proc *p; 165 void *v; 166 register_t *retval; 167{ 168 struct compat_12_netbsd32_fstat12_args /* { 169 syscallarg(int) fd; 170 syscallarg(netbsd32_stat12p_t) sb; 171 } */ *uap = v; 172 struct netbsd32_stat12 *sp32, sb32; 173 struct stat12 sb12; 174 struct stat12 *sp12 = &sb12; 175 struct compat_12_sys_fstat_args ua; 176 int rv; 177 178 NETBSD32TO64_UAP(fd); 179 SCARG(&ua, sb) = &sb12; 180 rv = compat_12_sys_fstat(p, &ua, retval); 181 if (rv) 182 return (rv); 183 184 sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, sb); 185 netbsd32_stat12_to_netbsd32(sp12, &sb32); 186 187 return (copyout(&sb32, sp32, sizeof sb32)); 188} 189 190int 191compat_12_netbsd32_lstat12(p, v, retval) 192 struct proc *p; 193 void *v; 194 register_t *retval; 195{ 196 struct compat_12_netbsd32_lstat12_args /* { 197 syscallarg(const netbsd32_charp) path; 198 syscallarg(netbsd32_stat12p_t) ub; 199 } */ *uap = v; 200 struct netbsd32_stat12 *sp32, sb32; 201 struct stat12 sb12; 202 struct stat12 *sp12 = &sb12; 203 struct compat_12_sys_lstat_args ua; 204 caddr_t sg; 205 int rv; 206 207 NETBSD32TOP_UAP(path, const char); 208 SCARG(&ua, ub) = &sb12; 209 sg = stackgap_init(p->p_emul); 210 CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path)); 211 212 rv = compat_12_sys_lstat(p, &ua, retval); 213 if (rv) 214 return (rv); 215 216 sp32 = (struct netbsd32_stat12 *)(u_long)SCARG(uap, ub); 217 netbsd32_stat12_to_netbsd32(sp12, &sb32); 218 219 return (copyout(&sb32, sp32, sizeof sb32)); 220} 221 222int 223compat_12_netbsd32_getdirentries(p, v, retval) 224 struct proc *p; 225 void *v; 226 register_t *retval; 227{ 228 struct compat_12_netbsd32_getdirentries_args /* { 229 syscallarg(int) fd; 230 syscallarg(netbsd32_charp) buf; 231 syscallarg(u_int) count; 232 syscallarg(netbsd32_longp) basep; 233 } */ *uap = v; 234 struct compat_12_sys_getdirentries_args ua; 235 236 NETBSD32TO64_UAP(fd); 237 NETBSD32TOP_UAP(buf, char); 238 NETBSD32TO64_UAP(count); 239 NETBSD32TOP_UAP(basep, long); 240 241 return (compat_12_sys_getdirentries(p, &ua, retval)); 242} 243