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