netbsd32_compat_12.c revision 1.30.12.1 1 /* $NetBSD: netbsd32_compat_12.c,v 1.30.12.1 2008/05/10 23:48:57 wrstuden Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001 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 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_12.c,v 1.30.12.1 2008/05/10 23:48:57 wrstuden Exp $");
33
34 #if defined(_KERNEL_OPT)
35 #include "opt_compat_netbsd.h"
36 #endif
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/mount.h>
41 #include <sys/mman.h>
42 #include <sys/proc.h>
43 #include <sys/stat.h>
44 #include <sys/swap.h>
45 #include <sys/sa.h>
46 #include <sys/syscallargs.h>
47
48 #include <compat/sys/stat.h>
49
50 #include <compat/netbsd32/netbsd32.h>
51 #include <compat/netbsd32/netbsd32_syscallargs.h>
52
53 static void netbsd32_stat12_to_netbsd32(struct stat12 *,
54 struct netbsd32_stat12 *);
55
56 /* for use with {,fl}stat() */
57 static void
58 netbsd32_stat12_to_netbsd32(struct stat12 *sp12, struct netbsd32_stat12 *sp32)
59 {
60
61 sp32->st_dev = sp12->st_dev;
62 sp32->st_ino = sp12->st_ino;
63 sp32->st_mode = sp12->st_mode;
64 sp32->st_nlink = sp12->st_nlink;
65 sp32->st_uid = sp12->st_uid;
66 sp32->st_gid = sp12->st_gid;
67 sp32->st_rdev = sp12->st_rdev;
68 if (sp12->st_size < (quad_t)1 << 32)
69 sp32->st_size = sp12->st_size;
70 else
71 sp32->st_size = -2;
72 sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
73 sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
74 sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
75 sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
76 sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
77 sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
78 sp32->st_blocks = sp12->st_blocks;
79 sp32->st_blksize = sp12->st_blksize;
80 sp32->st_flags = sp12->st_flags;
81 sp32->st_gen = sp12->st_gen;
82 }
83
84 int
85 compat_12_netbsd32_reboot(struct lwp *l, const struct compat_12_netbsd32_reboot_args *uap, register_t *retval)
86 {
87 /* {
88 syscallarg(int) opt;
89 } */
90 struct compat_12_sys_reboot_args ua;
91
92 NETBSD32TO64_UAP(opt);
93 return (compat_12_sys_reboot(l, &ua, retval));
94 }
95
96 int
97 compat_12_netbsd32_msync(struct lwp *l, const struct compat_12_netbsd32_msync_args *uap, register_t *retval)
98 {
99 /* {
100 syscallarg(netbsd32_caddr_t) addr;
101 syscallarg(netbsd32_size_t) len;
102 } */
103 struct sys___msync13_args ua;
104
105 NETBSD32TOP_UAP(addr, void *);
106 NETBSD32TOX_UAP(len, size_t);
107 SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
108 return (sys___msync13(l, &ua, retval));
109 }
110
111 int
112 compat_12_netbsd32_oswapon(struct lwp *l, const struct compat_12_netbsd32_oswapon_args *uap, register_t *retval)
113 {
114 /* {
115 syscallarg(const netbsd32_charp) name;
116 } */
117 struct sys_swapctl_args ua;
118
119 SCARG(&ua, cmd) = SWAP_ON;
120 SCARG(&ua, arg) = SCARG_P32(uap, name);
121 SCARG(&ua, misc) = 0; /* priority */
122 return (sys_swapctl(l, &ua, retval));
123 }
124
125 int
126 compat_12_netbsd32_stat12(struct lwp *l, const struct compat_12_netbsd32_stat12_args *uap, register_t *retval)
127 {
128 /* {
129 syscallarg(const netbsd32_charp) path;
130 syscallarg(netbsd32_stat12p_t) ub;
131 } */
132 struct netbsd32_stat12 *sp32, sb32;
133 struct stat12 sb12;
134 struct stat12 *sp12 = &sb12;
135 struct compat_12_sys_stat_args ua;
136 int rv;
137
138 NETBSD32TOP_UAP(path, const char);
139 SCARG(&ua, ub) = &sb12;
140
141 rv = compat_12_sys_stat(l, &ua, retval);
142 if (rv)
143 return (rv);
144
145 sp32 = SCARG_P32(uap, ub);
146 netbsd32_stat12_to_netbsd32(sp12, &sb32);
147
148 return (copyout(&sb32, sp32, sizeof sb32));
149 }
150
151 int
152 compat_12_netbsd32_fstat12(struct lwp *l, const struct compat_12_netbsd32_fstat12_args *uap, register_t *retval)
153 {
154 /* {
155 syscallarg(int) fd;
156 syscallarg(netbsd32_stat12p_t) sb;
157 } */
158 struct netbsd32_stat12 *sp32, sb32;
159 struct stat12 sb12;
160 struct stat12 *sp12 = &sb12;
161 struct compat_12_sys_fstat_args ua;
162 int rv;
163
164 NETBSD32TO64_UAP(fd);
165 SCARG(&ua, sb) = &sb12;
166 rv = compat_12_sys_fstat(l, &ua, retval);
167 if (rv)
168 return (rv);
169
170 sp32 = SCARG_P32(uap, sb);
171 netbsd32_stat12_to_netbsd32(sp12, &sb32);
172
173 return (copyout(&sb32, sp32, sizeof sb32));
174 }
175
176 int
177 compat_12_netbsd32_lstat12(struct lwp *l, const struct compat_12_netbsd32_lstat12_args *uap, register_t *retval)
178 {
179 /* {
180 syscallarg(const netbsd32_charp) path;
181 syscallarg(netbsd32_stat12p_t) ub;
182 } */
183 struct netbsd32_stat12 *sp32, sb32;
184 struct stat12 sb12;
185 struct stat12 *sp12 = &sb12;
186 struct compat_12_sys_lstat_args ua;
187 int rv;
188
189 NETBSD32TOP_UAP(path, const char);
190 SCARG(&ua, ub) = &sb12;
191
192 rv = compat_12_sys_lstat(l, &ua, retval);
193 if (rv)
194 return (rv);
195
196 sp32 = SCARG_P32(uap, ub);
197 netbsd32_stat12_to_netbsd32(sp12, &sb32);
198
199 return (copyout(&sb32, sp32, sizeof sb32));
200 }
201
202 int
203 compat_12_netbsd32_getdirentries(struct lwp *l, const struct compat_12_netbsd32_getdirentries_args *uap, register_t *retval)
204 {
205 /* {
206 syscallarg(int) fd;
207 syscallarg(netbsd32_charp) buf;
208 syscallarg(u_int) count;
209 syscallarg(netbsd32_longp) basep;
210 } */
211 struct compat_12_sys_getdirentries_args ua;
212
213 NETBSD32TO64_UAP(fd);
214 NETBSD32TOP_UAP(buf, char);
215 NETBSD32TO64_UAP(count);
216 NETBSD32TOP_UAP(basep, long);
217
218 return (compat_12_sys_getdirentries(l, &ua, retval));
219 }
220