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