xref: /netbsd-src/sys/compat/netbsd32/netbsd32_compat_12.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: netbsd32_compat_12.c,v 1.18 2003/06/29 22:29:36 fvdl 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.18 2003/06/29 22:29:36 fvdl 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/netbsd32/netbsd32.h>
49 #include <compat/netbsd32/netbsd32_syscallargs.h>
50 
51 static void netbsd32_stat12_to_netbsd32 __P((struct stat12 *,
52 		struct netbsd32_stat12 *));
53 
54 /* for use with {,fl}stat() */
55 static void
56 netbsd32_stat12_to_netbsd32(sp12, sp32)
57 	struct stat12 *sp12;
58 	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(l, v, retval)
86 	struct lwp *l;
87 	void *v;
88 	register_t *retval;
89 {
90 	struct compat_12_netbsd32_reboot_args /* {
91 		syscallarg(int) opt;
92 	} */ *uap = v;
93 	struct compat_12_sys_reboot_args ua;
94 
95 	NETBSD32TO64_UAP(opt);
96 	return (compat_12_sys_reboot(l, &ua, retval));
97 }
98 
99 int
100 compat_12_netbsd32_msync(l, v, retval)
101 	struct lwp *l;
102 	void *v;
103 	register_t *retval;
104 {
105 	struct compat_12_netbsd32_msync_args /* {
106 		syscallarg(netbsd32_caddr_t) addr;
107 		syscallarg(netbsd32_size_t) len;
108 	} */ *uap = v;
109 	struct sys___msync13_args ua;
110 
111 	NETBSD32TOX64_UAP(addr, caddr_t);
112 	NETBSD32TOX_UAP(len, size_t);
113 	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
114 	return (sys___msync13(l, &ua, retval));
115 }
116 
117 int
118 compat_12_netbsd32_oswapon(l, v, retval)
119 	struct lwp *l;
120 	void *v;
121 	register_t *retval;
122 {
123 	struct compat_12_netbsd32_oswapon_args /* {
124 		syscallarg(const netbsd32_charp) name;
125 	} */ *uap = v;
126 	struct sys_swapctl_args ua;
127 
128 	SCARG(&ua, cmd) = SWAP_ON;
129 	SCARG(&ua, arg) = (void *)NETBSD32PTR64(SCARG(uap, name));
130 	SCARG(&ua, misc) = 0;	/* priority */
131 	return (sys_swapctl(l, &ua, retval));
132 }
133 
134 int
135 compat_12_netbsd32_stat12(l, v, retval)
136 	struct lwp *l;
137 	void *v;
138 	register_t *retval;
139 {
140 	struct proc *p = l->l_proc;
141 	struct compat_12_netbsd32_stat12_args /* {
142 		syscallarg(const netbsd32_charp) path;
143 		syscallarg(netbsd32_stat12p_t) ub;
144 	} */ *uap = v;
145 	struct netbsd32_stat12 *sp32, sb32;
146 	struct stat12 sb12;
147 	struct stat12 *sp12 = &sb12;
148 	struct compat_12_sys_stat_args ua;
149 	caddr_t sg;
150 	int rv;
151 
152 	NETBSD32TOP_UAP(path, const char);
153 	SCARG(&ua, ub) = &sb12;
154 	sg = stackgap_init(p, 0);
155 	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
156 
157 	rv = compat_12_sys_stat(l, &ua, retval);
158 	if (rv)
159 		return (rv);
160 
161 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
162 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
163 
164 	return (copyout(&sb32, sp32, sizeof sb32));
165 }
166 
167 int
168 compat_12_netbsd32_fstat12(l, v, retval)
169 	struct lwp *l;
170 	void *v;
171 	register_t *retval;
172 {
173 	struct compat_12_netbsd32_fstat12_args /* {
174 		syscallarg(int) fd;
175 		syscallarg(netbsd32_stat12p_t) sb;
176 	} */ *uap = v;
177 	struct netbsd32_stat12 *sp32, sb32;
178 	struct stat12 sb12;
179 	struct stat12 *sp12 = &sb12;
180 	struct compat_12_sys_fstat_args ua;
181 	int rv;
182 
183 	NETBSD32TO64_UAP(fd);
184 	SCARG(&ua, sb) = &sb12;
185 	rv = compat_12_sys_fstat(l, &ua, retval);
186 	if (rv)
187 		return (rv);
188 
189 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, sb));
190 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
191 
192 	return (copyout(&sb32, sp32, sizeof sb32));
193 }
194 
195 int
196 compat_12_netbsd32_lstat12(l, v, retval)
197 	struct lwp *l;
198 	void *v;
199 	register_t *retval;
200 {
201 	struct proc *p = l->l_proc;
202 	struct compat_12_netbsd32_lstat12_args /* {
203 		syscallarg(const netbsd32_charp) path;
204 		syscallarg(netbsd32_stat12p_t) ub;
205 	} */ *uap = v;
206 	struct netbsd32_stat12 *sp32, sb32;
207 	struct stat12 sb12;
208 	struct stat12 *sp12 = &sb12;
209 	struct compat_12_sys_lstat_args ua;
210 	caddr_t sg;
211 	int rv;
212 
213 	NETBSD32TOP_UAP(path, const char);
214 	SCARG(&ua, ub) = &sb12;
215 	sg = stackgap_init(p, 0);
216 	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
217 
218 	rv = compat_12_sys_lstat(l, &ua, retval);
219 	if (rv)
220 		return (rv);
221 
222 	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
223 	netbsd32_stat12_to_netbsd32(sp12, &sb32);
224 
225 	return (copyout(&sb32, sp32, sizeof sb32));
226 }
227 
228 int
229 compat_12_netbsd32_getdirentries(l, v, retval)
230 	struct lwp *l;
231 	void *v;
232 	register_t *retval;
233 {
234 	struct compat_12_netbsd32_getdirentries_args /* {
235 		syscallarg(int) fd;
236 		syscallarg(netbsd32_charp) buf;
237 		syscallarg(u_int) count;
238 		syscallarg(netbsd32_longp) basep;
239 	} */ *uap = v;
240 	struct compat_12_sys_getdirentries_args ua;
241 
242 	NETBSD32TO64_UAP(fd);
243 	NETBSD32TOP_UAP(buf, char);
244 	NETBSD32TO64_UAP(count);
245 	NETBSD32TOP_UAP(basep, long);
246 
247 	return (compat_12_sys_getdirentries(l, &ua, retval));
248 }
249