1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/* $NetBSD: netbsd32_compat_30.c,v 1.36 2021/01/19 03:20:13 simonb Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.36 2021/01/19 03:20:13 simonb Exp $");
#if defined(_KERNEL_OPT)
#include <opt_ntp.h>
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ktrace.h>
#include <sys/resourcevar.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/namei.h>
#include <sys/statvfs.h>
#include <sys/syscallargs.h>
#include <sys/syscallvar.h>
#include <sys/proc.h>
#include <sys/dirent.h>
#include <sys/kauth.h>
#include <sys/vfs_syscalls.h>
#include <sys/compat_stub.h>
#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_syscall.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
#include <compat/netbsd32/netbsd32_conv.h>
#include <compat/sys/mount.h>
int
compat_30_netbsd32_getdents(struct lwp *l, const struct compat_30_netbsd32_getdents_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(netbsd32_charp) buf;
syscallarg(netbsd32_size_t) count;
} */
file_t *fp;
int error, done;
char *buf;
netbsd32_size_t count;
/* Limit the size on any kernel buffers used by VOP_READDIR */
count = uimin(MAXBSIZE, SCARG(uap, count));
/* fd_getvnode() will use the descriptor for us */
if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
return error;
if ((fp->f_flag & FREAD) == 0) {
error = EBADF;
goto out;
}
if (count == 0)
goto out;
buf = kmem_alloc(count, KM_SLEEP);
error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0);
if (error == 0) {
*retval = netbsd32_to_dirent12(buf, done);
error = copyout(buf, SCARG_P32(uap, buf), *retval);
}
kmem_free(buf, count);
out:
fd_putfile(SCARG(uap, fd));
return error;
}
int
compat_30_netbsd32___stat13(struct lwp *l, const struct compat_30_netbsd32___stat13_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(netbsd32_stat13p_t) ub;
} */
struct netbsd32_stat13 sb32;
struct stat sb;
int error;
const char *path;
path = SCARG_P32(uap, path);
error = do_sys_stat(path, FOLLOW, &sb);
if (error)
return error;
netbsd32_from___stat13(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
return error;
}
int
compat_30_netbsd32___fstat13(struct lwp *l, const struct compat_30_netbsd32___fstat13_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(netbsd32_stat13p_t) sb;
} */
struct netbsd32_stat13 sb32;
struct stat ub;
int error;
error = do_sys_fstat(SCARG(uap, fd), &ub);
if (error == 0) {
netbsd32_from___stat13(&ub, &sb32);
error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
}
return error;
}
int
compat_30_netbsd32___lstat13(struct lwp *l, const struct compat_30_netbsd32___lstat13_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) path;
syscallarg(netbsd32_stat13p_t) ub;
} */
struct netbsd32_stat13 sb32;
struct stat sb;
int error;
const char *path;
path = SCARG_P32(uap, path);
error = do_sys_stat(path, NOFOLLOW, &sb);
if (error)
return error;
netbsd32_from___stat13(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
return error;
}
int
compat_30_netbsd32_fhstat(struct lwp *l, const struct compat_30_netbsd32_fhstat_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_fhandlep_t) fhp;
syscallarg(netbsd32_stat13p_t) sb;
} */
struct stat sb;
struct netbsd32_stat13 sb32;
int error;
struct compat_30_fhandle fh;
struct mount *mp;
struct vnode *vp;
/*
* Must be super user
*/
if ((error = kauth_authorize_system(l->l_cred,
KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
return error;
if ((error = copyin(SCARG_P32(uap, fhp), &fh, sizeof(fh))) != 0)
return error;
if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
return ESTALE;
if (mp->mnt_op->vfs_fhtovp == NULL)
return EOPNOTSUPP;
if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, LK_EXCLUSIVE, &vp)))
return error;
error = vn_stat(vp, &sb);
vput(vp);
if (error)
return error;
netbsd32_from___stat13(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
return error;
}
int
compat_30_netbsd32_fhstatvfs1(struct lwp *l, const struct compat_30_netbsd32_fhstatvfs1_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_fhandlep_t) fhp;
syscallarg(netbsd32_statvfsp_t) buf;
syscallarg(int) flags;
} */
struct statvfs *sbuf;
struct netbsd32_statvfs *s32;
int error;
sbuf = STATVFSBUF_GET();
error = do_fhstatvfs(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, sbuf,
SCARG(uap, flags));
if (error != 0) {
s32 = kmem_alloc(sizeof(*s32), KM_SLEEP);
netbsd32_from_statvfs(sbuf, s32);
error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32);
kmem_free(s32, sizeof(*s32));
}
STATVFSBUF_PUT(sbuf);
return error;
}
int
compat_30_netbsd32_socket(struct lwp *l, const struct compat_30_netbsd32_socket_args *uap, register_t *retval)
{
/* {
syscallarg(int) domain;
syscallarg(int) type;
syscallarg(int) protocol;
} */
struct compat_30_sys_socket_args ua;
NETBSD32TO64_UAP(domain);
NETBSD32TO64_UAP(type);
NETBSD32TO64_UAP(protocol);
return compat_30_sys_socket(l, &ua, retval);
}
int
compat_30_netbsd32_getfh(struct lwp *l, const struct compat_30_netbsd32_getfh_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_charp) fname;
syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
} */
struct compat_30_sys_getfh_args ua;
NETBSD32TOP_UAP(fname, const char);
NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
/* Lucky for us a fhandle_t doesn't change sizes */
return compat_30_sys_getfh(l, &ua, retval);
}
int
compat_30_netbsd32___fhstat30(struct lwp *l, const struct compat_30_netbsd32___fhstat30_args *uap, register_t *retval)
{
/* {
syscallarg(const netbsd32_fhandlep_t) fhp;
syscallarg(netbsd32_statp_t) sb;
} */
struct stat sb;
struct netbsd32_stat50 sb32;
int error;
error = do_fhstat(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
if (error)
return error;
netbsd32_from___stat50(&sb, &sb32);
error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
return error;
}
/*
* Open a file given a file handle.
*
* Check permissions, allocate an open file structure,
* and call the device open routine if any.
*/
int
compat_30_netbsd32_fhopen(struct lwp *l, const struct compat_30_netbsd32_fhopen_args *uap, register_t *retval)
{
/* {
syscallarg(const fhandle_t *) fhp;
syscallarg(int) flags;
} */
struct compat_30_sys_fhopen_args ua;
NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
NETBSD32TO64_UAP(flags);
return compat_30_sys_fhopen(l, &ua, retval);
}
#ifdef NTP
int
compat_30_netbsd32_ntp_gettime(struct lwp *l, const struct compat_30_netbsd32_ntp_gettime_args *uap, register_t *retval)
{
/* {
syscallarg(netbsd32_ntptimevalp_t) ntvp;
} */
struct netbsd32_ntptimeval30 ntv32;
struct ntptimeval ntv;
int error = 0;
if (vec_ntp_gettime == NULL)
return EINVAL;
if (SCARG_P32(uap, ntvp)) {
(*vec_ntp_gettime)(&ntv);
memset(&ntv32, 0, sizeof(ntv32));
ntv32.time.tv_sec = ntv.time.tv_sec;
ntv32.time.tv_usec = ntv.time.tv_nsec / 1000;
ntv32.maxerror = (netbsd32_long)ntv.maxerror;
ntv32.esterror = (netbsd32_long)ntv.esterror;
error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32));
}
if (!error) {
*retval = (*vec_ntp_timestatus)();
}
return error;
}
#endif
static struct syscall_package compat_netbsd32_30_syscalls[] = {
{ NETBSD32_SYS_compat_30_netbsd32_getdents, 0,
(sy_call_t *)compat_30_netbsd32_getdents },
{ NETBSD32_SYS_compat_30_netbsd32___stat13, 0,
(sy_call_t *)compat_30_netbsd32___stat13 },
{ NETBSD32_SYS_compat_30_netbsd32___fstat13, 0,
(sy_call_t *)compat_30_netbsd32___fstat13 },
{ NETBSD32_SYS_compat_30_netbsd32___lstat13, 0,
(sy_call_t *)compat_30_netbsd32___lstat13 },
{ NETBSD32_SYS_compat_30_netbsd32_fhstat, 0,
(sy_call_t *)compat_30_netbsd32_fhstat },
{ NETBSD32_SYS_compat_30_netbsd32_fhstatvfs1, 0,
(sy_call_t *)compat_30_netbsd32_fhstatvfs1 },
{ NETBSD32_SYS_compat_30_netbsd32_socket, 0,
(sy_call_t *)compat_30_netbsd32_socket },
{ NETBSD32_SYS_compat_30_netbsd32_getfh, 0,
(sy_call_t *)compat_30_netbsd32_getfh },
{ NETBSD32_SYS_compat_30_netbsd32___fhstat30, 0,
(sy_call_t *)compat_30_netbsd32___fhstat30 },
{ NETBSD32_SYS_compat_30_netbsd32_fhopen, 0,
(sy_call_t *)compat_30_netbsd32_fhopen },
#ifdef NTP
{ NETBSD32_SYS_compat_30_netbsd32_ntp_gettime, 0,
(sy_call_t *)compat_30_netbsd32_ntp_gettime },
#endif
{ 0, 0, NULL }
};
MODULE(MODULE_CLASS_EXEC, compat_netbsd32_30, "compat_netbsd32_40,compat_30");
static int
compat_netbsd32_30_modcmd(modcmd_t cmd, void *arg)
{
switch (cmd) {
case MODULE_CMD_INIT:
return syscall_establish(&emul_netbsd32,
compat_netbsd32_30_syscalls);
case MODULE_CMD_FINI:
return syscall_disestablish(&emul_netbsd32,
compat_netbsd32_30_syscalls);
default:
return ENOTTY;
}
}
|