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