netbsd32_compat_12.c revision 1.19
1/*	$NetBSD: netbsd32_compat_12.c,v 1.19 2005/09/13 03:23:09 christos 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.19 2005/09/13 03:23:09 christos 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
53static void netbsd32_stat12_to_netbsd32 __P((struct stat12 *,
54		struct netbsd32_stat12 *));
55
56/* for use with {,fl}stat() */
57static void
58netbsd32_stat12_to_netbsd32(sp12, sp32)
59	struct stat12 *sp12;
60	struct netbsd32_stat12 *sp32;
61{
62
63	sp32->st_dev = sp12->st_dev;
64	sp32->st_ino = sp12->st_ino;
65	sp32->st_mode = sp12->st_mode;
66	sp32->st_nlink = sp12->st_nlink;
67	sp32->st_uid = sp12->st_uid;
68	sp32->st_gid = sp12->st_gid;
69	sp32->st_rdev = sp12->st_rdev;
70	if (sp12->st_size < (quad_t)1 << 32)
71		sp32->st_size = sp12->st_size;
72	else
73		sp32->st_size = -2;
74	sp32->st_atimespec.tv_sec = sp12->st_atimespec.tv_sec;
75	sp32->st_atimespec.tv_nsec = sp12->st_atimespec.tv_nsec;
76	sp32->st_mtimespec.tv_sec = sp12->st_mtimespec.tv_sec;
77	sp32->st_mtimespec.tv_nsec = sp12->st_mtimespec.tv_nsec;
78	sp32->st_ctimespec.tv_sec = sp12->st_ctimespec.tv_sec;
79	sp32->st_ctimespec.tv_nsec = sp12->st_ctimespec.tv_nsec;
80	sp32->st_blocks = sp12->st_blocks;
81	sp32->st_blksize = sp12->st_blksize;
82	sp32->st_flags = sp12->st_flags;
83	sp32->st_gen = sp12->st_gen;
84}
85
86int
87compat_12_netbsd32_reboot(l, v, retval)
88	struct lwp *l;
89	void *v;
90	register_t *retval;
91{
92	struct compat_12_netbsd32_reboot_args /* {
93		syscallarg(int) opt;
94	} */ *uap = v;
95	struct compat_12_sys_reboot_args ua;
96
97	NETBSD32TO64_UAP(opt);
98	return (compat_12_sys_reboot(l, &ua, retval));
99}
100
101int
102compat_12_netbsd32_msync(l, v, retval)
103	struct lwp *l;
104	void *v;
105	register_t *retval;
106{
107	struct compat_12_netbsd32_msync_args /* {
108		syscallarg(netbsd32_caddr_t) addr;
109		syscallarg(netbsd32_size_t) len;
110	} */ *uap = v;
111	struct sys___msync13_args ua;
112
113	NETBSD32TOX64_UAP(addr, caddr_t);
114	NETBSD32TOX_UAP(len, size_t);
115	SCARG(&ua, flags) = MS_SYNC | MS_INVALIDATE;
116	return (sys___msync13(l, &ua, retval));
117}
118
119int
120compat_12_netbsd32_oswapon(l, v, retval)
121	struct lwp *l;
122	void *v;
123	register_t *retval;
124{
125	struct compat_12_netbsd32_oswapon_args /* {
126		syscallarg(const netbsd32_charp) name;
127	} */ *uap = v;
128	struct sys_swapctl_args ua;
129
130	SCARG(&ua, cmd) = SWAP_ON;
131	SCARG(&ua, arg) = (void *)NETBSD32PTR64(SCARG(uap, name));
132	SCARG(&ua, misc) = 0;	/* priority */
133	return (sys_swapctl(l, &ua, retval));
134}
135
136int
137compat_12_netbsd32_stat12(l, v, retval)
138	struct lwp *l;
139	void *v;
140	register_t *retval;
141{
142	struct proc *p = l->l_proc;
143	struct compat_12_netbsd32_stat12_args /* {
144		syscallarg(const netbsd32_charp) path;
145		syscallarg(netbsd32_stat12p_t) ub;
146	} */ *uap = v;
147	struct netbsd32_stat12 *sp32, sb32;
148	struct stat12 sb12;
149	struct stat12 *sp12 = &sb12;
150	struct compat_12_sys_stat_args ua;
151	caddr_t sg;
152	int rv;
153
154	NETBSD32TOP_UAP(path, const char);
155	SCARG(&ua, ub) = &sb12;
156	sg = stackgap_init(p, 0);
157	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
158
159	rv = compat_12_sys_stat(l, &ua, retval);
160	if (rv)
161		return (rv);
162
163	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
164	netbsd32_stat12_to_netbsd32(sp12, &sb32);
165
166	return (copyout(&sb32, sp32, sizeof sb32));
167}
168
169int
170compat_12_netbsd32_fstat12(l, v, retval)
171	struct lwp *l;
172	void *v;
173	register_t *retval;
174{
175	struct compat_12_netbsd32_fstat12_args /* {
176		syscallarg(int) fd;
177		syscallarg(netbsd32_stat12p_t) sb;
178	} */ *uap = v;
179	struct netbsd32_stat12 *sp32, sb32;
180	struct stat12 sb12;
181	struct stat12 *sp12 = &sb12;
182	struct compat_12_sys_fstat_args ua;
183	int rv;
184
185	NETBSD32TO64_UAP(fd);
186	SCARG(&ua, sb) = &sb12;
187	rv = compat_12_sys_fstat(l, &ua, retval);
188	if (rv)
189		return (rv);
190
191	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, sb));
192	netbsd32_stat12_to_netbsd32(sp12, &sb32);
193
194	return (copyout(&sb32, sp32, sizeof sb32));
195}
196
197int
198compat_12_netbsd32_lstat12(l, v, retval)
199	struct lwp *l;
200	void *v;
201	register_t *retval;
202{
203	struct proc *p = l->l_proc;
204	struct compat_12_netbsd32_lstat12_args /* {
205		syscallarg(const netbsd32_charp) path;
206		syscallarg(netbsd32_stat12p_t) ub;
207	} */ *uap = v;
208	struct netbsd32_stat12 *sp32, sb32;
209	struct stat12 sb12;
210	struct stat12 *sp12 = &sb12;
211	struct compat_12_sys_lstat_args ua;
212	caddr_t sg;
213	int rv;
214
215	NETBSD32TOP_UAP(path, const char);
216	SCARG(&ua, ub) = &sb12;
217	sg = stackgap_init(p, 0);
218	CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
219
220	rv = compat_12_sys_lstat(l, &ua, retval);
221	if (rv)
222		return (rv);
223
224	sp32 = (struct netbsd32_stat12 *)NETBSD32PTR64(SCARG(uap, ub));
225	netbsd32_stat12_to_netbsd32(sp12, &sb32);
226
227	return (copyout(&sb32, sp32, sizeof sb32));
228}
229
230int
231compat_12_netbsd32_getdirentries(l, v, retval)
232	struct lwp *l;
233	void *v;
234	register_t *retval;
235{
236	struct compat_12_netbsd32_getdirentries_args /* {
237		syscallarg(int) fd;
238		syscallarg(netbsd32_charp) buf;
239		syscallarg(u_int) count;
240		syscallarg(netbsd32_longp) basep;
241	} */ *uap = v;
242	struct compat_12_sys_getdirentries_args ua;
243
244	NETBSD32TO64_UAP(fd);
245	NETBSD32TOP_UAP(buf, char);
246	NETBSD32TO64_UAP(count);
247	NETBSD32TOP_UAP(basep, long);
248
249	return (compat_12_sys_getdirentries(l, &ua, retval));
250}
251