linux32_unistd.c revision 1.41 1 1.41 kamil /* $NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 1.1 manu *
6 1.1 manu * Redistribution and use in source and binary forms, with or without
7 1.1 manu * modification, are permitted provided that the following conditions
8 1.1 manu * are met:
9 1.1 manu * 1. Redistributions of source code must retain the above copyright
10 1.1 manu * notice, this list of conditions and the following disclaimer.
11 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 manu * notice, this list of conditions and the following disclaimer in the
13 1.1 manu * documentation and/or other materials provided with the distribution.
14 1.1 manu * 3. All advertising materials mentioning features or use of this software
15 1.1 manu * must display the following acknowledgement:
16 1.1 manu * This product includes software developed by Emmanuel Dreyfus
17 1.1 manu * 4. The name of the author may not be used to endorse or promote
18 1.1 manu * products derived from this software without specific prior written
19 1.1 manu * permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 1.1 manu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 1.1 manu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 manu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 1.1 manu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 manu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 manu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 manu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 manu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 manu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 manu * POSSIBILITY OF SUCH DAMAGE.
32 1.1 manu */
33 1.1 manu
34 1.1 manu #include <sys/cdefs.h>
35 1.1 manu
36 1.41 kamil __KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $");
37 1.1 manu
38 1.1 manu #include <sys/types.h>
39 1.1 manu #include <sys/param.h>
40 1.1 manu #include <sys/fstypes.h>
41 1.1 manu #include <sys/signal.h>
42 1.1 manu #include <sys/dirent.h>
43 1.1 manu #include <sys/kernel.h>
44 1.1 manu #include <sys/fcntl.h>
45 1.1 manu #include <sys/select.h>
46 1.1 manu #include <sys/proc.h>
47 1.1 manu #include <sys/ucred.h>
48 1.1 manu #include <sys/swap.h>
49 1.26 njoly #include <sys/kauth.h>
50 1.35 christos #include <sys/filedesc.h>
51 1.36 chs #include <sys/vfs_syscalls.h>
52 1.1 manu
53 1.1 manu #include <machine/types.h>
54 1.1 manu
55 1.1 manu #include <sys/syscallargs.h>
56 1.1 manu
57 1.1 manu #include <compat/netbsd32/netbsd32.h>
58 1.1 manu #include <compat/netbsd32/netbsd32_conv.h>
59 1.1 manu
60 1.1 manu #include <compat/linux/common/linux_types.h>
61 1.1 manu #include <compat/linux/common/linux_signal.h>
62 1.1 manu #include <compat/linux/common/linux_machdep.h>
63 1.1 manu #include <compat/linux/common/linux_misc.h>
64 1.1 manu #include <compat/linux/common/linux_oldolduname.h>
65 1.25 ad #include <compat/linux/common/linux_ipc.h>
66 1.25 ad #include <compat/linux/common/linux_sem.h>
67 1.35 christos #include <compat/linux/common/linux_fcntl.h>
68 1.1 manu #include <compat/linux/linux_syscallargs.h>
69 1.1 manu
70 1.1 manu #include <compat/linux32/common/linux32_types.h>
71 1.1 manu #include <compat/linux32/common/linux32_signal.h>
72 1.1 manu #include <compat/linux32/common/linux32_machdep.h>
73 1.36 chs #include <compat/linux32/common/linux32_sched.h>
74 1.1 manu #include <compat/linux32/common/linux32_sysctl.h>
75 1.1 manu #include <compat/linux32/common/linux32_socketcall.h>
76 1.1 manu #include <compat/linux32/linux32_syscallargs.h>
77 1.1 manu
78 1.1 manu static int linux32_select1(struct lwp *, register_t *,
79 1.1 manu int, fd_set *, fd_set *, fd_set *, struct timeval *);
80 1.1 manu
81 1.1 manu int
82 1.17 dsl linux32_sys_brk(struct lwp *l, const struct linux32_sys_brk_args *uap, register_t *retval)
83 1.1 manu {
84 1.17 dsl /* {
85 1.1 manu syscallarg(netbsd32_charp) nsize;
86 1.17 dsl } */
87 1.1 manu struct linux_sys_brk_args ua;
88 1.1 manu
89 1.1 manu NETBSD32TOP_UAP(nsize, char);
90 1.1 manu return linux_sys_brk(l, &ua, retval);
91 1.1 manu }
92 1.1 manu
93 1.1 manu int
94 1.17 dsl linux32_sys_llseek(struct lwp *l, const struct linux32_sys_llseek_args *uap, register_t *retval)
95 1.1 manu {
96 1.17 dsl /* {
97 1.29 njoly syscallarg(int) fd;
98 1.1 manu syscallarg(u_int32_t) ohigh;
99 1.1 manu syscallarg(u_int32_t) olow;
100 1.28 njoly syscallarg(netbsd32_voidp) res;
101 1.29 njoly syscallarg(int) whence;
102 1.17 dsl } */
103 1.1 manu struct linux_sys_llseek_args ua;
104 1.1 manu
105 1.1 manu NETBSD32TO64_UAP(fd);
106 1.1 manu NETBSD32TO64_UAP(ohigh);
107 1.1 manu NETBSD32TO64_UAP(olow);
108 1.28 njoly NETBSD32TOP_UAP(res, void);
109 1.1 manu NETBSD32TO64_UAP(whence);
110 1.1 manu
111 1.1 manu return linux_sys_llseek(l, &ua, retval);
112 1.1 manu }
113 1.1 manu
114 1.1 manu int
115 1.17 dsl linux32_sys_select(struct lwp *l, const struct linux32_sys_select_args *uap, register_t *retval)
116 1.1 manu {
117 1.17 dsl /* {
118 1.1 manu syscallarg(int) nfds;
119 1.1 manu syscallarg(netbsd32_fd_setp_t) readfds;
120 1.1 manu syscallarg(netbsd32_fd_setp_t) writefds;
121 1.1 manu syscallarg(netbsd32_fd_setp_t) exceptfds;
122 1.30 njoly syscallarg(netbsd32_timeval50p_t) timeout;
123 1.17 dsl } */
124 1.1 manu
125 1.1 manu return linux32_select1(l, retval, SCARG(uap, nfds),
126 1.7 dsl SCARG_P32(uap, readfds),
127 1.7 dsl SCARG_P32(uap, writefds),
128 1.7 dsl SCARG_P32(uap, exceptfds),
129 1.7 dsl SCARG_P32(uap, timeout));
130 1.1 manu }
131 1.1 manu
132 1.1 manu int
133 1.17 dsl linux32_sys_oldselect(struct lwp *l, const struct linux32_sys_oldselect_args *uap, register_t *retval)
134 1.1 manu {
135 1.17 dsl /* {
136 1.1 manu syscallarg(linux32_oldselectp_t) lsp;
137 1.17 dsl } */
138 1.1 manu struct linux32_oldselect lsp32;
139 1.1 manu int error;
140 1.1 manu
141 1.7 dsl if ((error = copyin(SCARG_P32(uap, lsp), &lsp32, sizeof(lsp32))) != 0)
142 1.1 manu return error;
143 1.1 manu
144 1.1 manu return linux32_select1(l, retval, lsp32.nfds,
145 1.1 manu NETBSD32PTR64(lsp32.readfds), NETBSD32PTR64(lsp32.writefds),
146 1.1 manu NETBSD32PTR64(lsp32.exceptfds), NETBSD32PTR64(lsp32.timeout));
147 1.1 manu }
148 1.1 manu
149 1.1 manu static int
150 1.31 cegger linux32_select1(struct lwp *l, register_t *retval, int nfds,
151 1.31 cegger fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
152 1.31 cegger struct timeval *timeout)
153 1.1 manu {
154 1.32 christos struct timespec ts0, ts1, uts, *ts = NULL;
155 1.30 njoly struct netbsd32_timeval50 utv32;
156 1.1 manu int error;
157 1.1 manu
158 1.2 skd
159 1.1 manu /*
160 1.1 manu * Store current time for computation of the amount of
161 1.1 manu * time left.
162 1.1 manu */
163 1.1 manu if (timeout) {
164 1.1 manu if ((error = copyin(timeout, &utv32, sizeof(utv32))))
165 1.1 manu return error;
166 1.1 manu
167 1.32 christos uts.tv_sec = utv32.tv_sec;
168 1.41 kamil uts.tv_nsec = (long)((unsigned long)utv32.tv_usec * 1000);
169 1.1 manu
170 1.32 christos if (itimespecfix(&uts)) {
171 1.1 manu /*
172 1.1 manu * The timeval was invalid. Convert it to something
173 1.1 manu * valid that will act as it does under Linux.
174 1.1 manu */
175 1.32 christos uts.tv_sec += uts.tv_nsec / 1000000000;
176 1.32 christos uts.tv_nsec %= 1000000000;
177 1.32 christos if (uts.tv_nsec < 0) {
178 1.32 christos uts.tv_sec -= 1;
179 1.32 christos uts.tv_nsec += 1000000000;
180 1.1 manu }
181 1.32 christos if (uts.tv_sec < 0)
182 1.32 christos timespecclear(&uts);
183 1.1 manu }
184 1.32 christos nanotime(&ts0);
185 1.32 christos ts = &uts;
186 1.32 christos } else
187 1.32 christos timespecclear(&uts); /* XXX GCC4 */
188 1.1 manu
189 1.34 rmind error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL);
190 1.1 manu
191 1.1 manu if (error) {
192 1.1 manu /*
193 1.1 manu * See fs/select.c in the Linux kernel. Without this,
194 1.1 manu * Maelstrom doesn't work.
195 1.1 manu */
196 1.1 manu if (error == ERESTART)
197 1.1 manu error = EINTR;
198 1.1 manu return error;
199 1.1 manu }
200 1.1 manu
201 1.1 manu if (timeout) {
202 1.1 manu if (*retval) {
203 1.1 manu /*
204 1.1 manu * Compute how much time was left of the timeout,
205 1.1 manu * by subtracting the current time and the time
206 1.1 manu * before we started the call, and subtracting
207 1.1 manu * that result from the user-supplied value.
208 1.1 manu */
209 1.32 christos nanotime(&ts1);
210 1.32 christos timespecsub(&ts1, &ts0, &ts1);
211 1.32 christos timespecsub(&uts, &ts1, &uts);
212 1.32 christos if (uts.tv_sec < 0)
213 1.32 christos timespecclear(&uts);
214 1.1 manu } else {
215 1.32 christos timespecclear(&uts);
216 1.1 manu }
217 1.1 manu
218 1.32 christos utv32.tv_sec = uts.tv_sec;
219 1.32 christos utv32.tv_usec = uts.tv_nsec / 1000;
220 1.1 manu
221 1.1 manu if ((error = copyout(&utv32, timeout, sizeof(utv32))))
222 1.1 manu return error;
223 1.1 manu }
224 1.1 manu
225 1.1 manu return 0;
226 1.1 manu }
227 1.1 manu
228 1.40 kamil int
229 1.40 kamil linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap,
230 1.40 kamil register_t *retval)
231 1.1 manu {
232 1.17 dsl /* {
233 1.1 manu syscallarg(netbsd32_intp) fd;
234 1.17 dsl } */
235 1.40 kamil int f[2], error;
236 1.1 manu
237 1.40 kamil if ((error = pipe1(l, f, 0)))
238 1.40 kamil return error;
239 1.1 manu
240 1.40 kamil if ((error = copyout(f, SCARG_P32(uap, fd), sizeof(f))) != 0)
241 1.1 manu return error;
242 1.1 manu retval[0] = 0;
243 1.1 manu return 0;
244 1.1 manu }
245 1.1 manu
246 1.35 christos int
247 1.35 christos linux32_sys_pipe2(struct lwp *l, const struct linux32_sys_pipe2_args *uap,
248 1.35 christos register_t *retval)
249 1.35 christos {
250 1.40 kamil /* {
251 1.40 kamil syscallarg(netbsd32_intp) fd;
252 1.40 kamil } */
253 1.40 kamil int f[2], flags, error;
254 1.35 christos
255 1.39 njoly flags = linux_to_bsd_ioflags(SCARG(uap, flags));
256 1.39 njoly if ((flags & ~(O_CLOEXEC|O_NONBLOCK)) != 0)
257 1.35 christos return EINVAL;
258 1.35 christos
259 1.40 kamil if ((error = pipe1(l, f, flags)))
260 1.35 christos return error;
261 1.35 christos
262 1.40 kamil if ((error = copyout(f, SCARG_P32(uap, fd), sizeof(f))) != 0)
263 1.40 kamil return error;
264 1.40 kamil retval[0] = 0;
265 1.40 kamil return 0;
266 1.35 christos }
267 1.35 christos
268 1.35 christos int
269 1.35 christos linux32_sys_dup3(struct lwp *l, const struct linux32_sys_dup3_args *uap,
270 1.35 christos register_t *retval)
271 1.35 christos {
272 1.35 christos /* {
273 1.35 christos syscallarg(int) from;
274 1.35 christos syscallarg(int) to;
275 1.35 christos syscallarg(int) flags;
276 1.35 christos } */
277 1.38 njoly struct linux_sys_dup3_args ua;
278 1.35 christos
279 1.35 christos NETBSD32TO64_UAP(from);
280 1.35 christos NETBSD32TO64_UAP(to);
281 1.38 njoly NETBSD32TO64_UAP(flags);
282 1.35 christos
283 1.38 njoly return linux_sys_dup3(l, &ua, retval);
284 1.35 christos }
285 1.1 manu
286 1.36 chs
287 1.36 chs int
288 1.36 chs linux32_sys_openat(struct lwp *l, const struct linux32_sys_openat_args *uap, register_t *retval)
289 1.36 chs {
290 1.36 chs /* {
291 1.36 chs syscallarg(int) fd;
292 1.36 chs syscallarg(const netbsd32_charp) path;
293 1.36 chs syscallarg(int) flags;
294 1.36 chs syscallarg(int) mode;
295 1.36 chs } */
296 1.36 chs struct linux_sys_openat_args ua;
297 1.36 chs
298 1.36 chs NETBSD32TO64_UAP(fd);
299 1.36 chs NETBSD32TOP_UAP(path, const char);
300 1.36 chs NETBSD32TO64_UAP(flags);
301 1.36 chs NETBSD32TO64_UAP(mode);
302 1.36 chs
303 1.36 chs return linux_sys_openat(l, &ua, retval);
304 1.36 chs }
305 1.36 chs
306 1.36 chs int
307 1.36 chs linux32_sys_mknodat(struct lwp *l, const struct linux32_sys_mknodat_args *uap, register_t *retval)
308 1.36 chs {
309 1.36 chs /* {
310 1.36 chs syscallarg(int) fd;
311 1.36 chs syscallarg(const netbsd32_charp) path;
312 1.36 chs syscallarg(linux_umode_t) mode;
313 1.36 chs syscallarg(unsigned) dev;
314 1.36 chs } */
315 1.36 chs struct linux_sys_mknodat_args ua;
316 1.36 chs
317 1.36 chs NETBSD32TO64_UAP(fd);
318 1.36 chs NETBSD32TOP_UAP(path, const char);
319 1.36 chs NETBSD32TO64_UAP(mode);
320 1.36 chs NETBSD32TO64_UAP(dev);
321 1.36 chs
322 1.36 chs return linux_sys_mknodat(l, &ua, retval);
323 1.36 chs }
324 1.36 chs
325 1.36 chs int
326 1.36 chs linux32_sys_linkat(struct lwp *l, const struct linux32_sys_linkat_args *uap, register_t *retval)
327 1.36 chs {
328 1.36 chs /* {
329 1.36 chs syscallarg(int) fd1;
330 1.36 chs syscallarg(netbsd32_charp) name1;
331 1.36 chs syscallarg(int) fd2;
332 1.36 chs syscallarg(netbsd32_charp) name2;
333 1.36 chs syscallarg(int) flags;
334 1.36 chs } */
335 1.36 chs int fd1 = SCARG(uap, fd1);
336 1.36 chs const char *name1 = SCARG_P32(uap, name1);
337 1.36 chs int fd2 = SCARG(uap, fd2);
338 1.36 chs const char *name2 = SCARG_P32(uap, name2);
339 1.36 chs int follow;
340 1.36 chs
341 1.36 chs follow = SCARG(uap, flags) & LINUX_AT_SYMLINK_FOLLOW;
342 1.36 chs
343 1.36 chs return do_sys_linkat(l, fd1, name1, fd2, name2, follow, retval);
344 1.36 chs }
345 1.36 chs
346 1.1 manu int
347 1.17 dsl linux32_sys_unlink(struct lwp *l, const struct linux32_sys_unlink_args *uap, register_t *retval)
348 1.1 manu {
349 1.17 dsl /* {
350 1.1 manu syscallarg(const netbsd32_charp) path;
351 1.17 dsl } */
352 1.1 manu struct linux_sys_unlink_args ua;
353 1.1 manu
354 1.1 manu NETBSD32TOP_UAP(path, const char);
355 1.36 chs
356 1.1 manu return linux_sys_unlink(l, &ua, retval);
357 1.1 manu }
358 1.1 manu
359 1.1 manu int
360 1.36 chs linux32_sys_unlinkat(struct lwp *l, const struct linux32_sys_unlinkat_args *uap, register_t *retval)
361 1.36 chs {
362 1.36 chs /* {
363 1.36 chs syscallarg(int) fd;
364 1.36 chs syscallarg(const netbsd32_charp) path;
365 1.36 chs syscallarg(int) flag;
366 1.36 chs } */
367 1.36 chs struct linux_sys_unlinkat_args ua;
368 1.36 chs
369 1.36 chs NETBSD32TO64_UAP(fd);
370 1.36 chs NETBSD32TOP_UAP(path, const char);
371 1.36 chs NETBSD32TO64_UAP(flag);
372 1.36 chs
373 1.36 chs return linux_sys_unlinkat(l, &ua, retval);
374 1.36 chs }
375 1.36 chs
376 1.36 chs int
377 1.36 chs linux32_sys_fchmodat(struct lwp *l, const struct linux32_sys_fchmodat_args *uap, register_t *retval)
378 1.36 chs {
379 1.36 chs /* {
380 1.36 chs syscallarg(int) fd;
381 1.36 chs syscallarg(netbsd_charp) path;
382 1.36 chs syscallarg(linux_umode_t) mode;
383 1.36 chs } */
384 1.36 chs
385 1.36 chs return do_sys_chmodat(l, SCARG(uap, fd), SCARG_P32(uap, path),
386 1.36 chs SCARG(uap, mode), AT_SYMLINK_FOLLOW);
387 1.36 chs }
388 1.36 chs
389 1.36 chs int
390 1.36 chs linux32_sys_fchownat(struct lwp *l, const struct linux32_sys_fchownat_args *uap, register_t *retval)
391 1.36 chs {
392 1.36 chs /* {
393 1.36 chs syscallarg(int) fd;
394 1.36 chs syscallarg(netbsd_charp) path;
395 1.36 chs syscallarg(uid_t) owner;
396 1.36 chs syscallarg(gid_t) group;
397 1.36 chs syscallarg(int) flag;
398 1.36 chs } */
399 1.36 chs int flag;
400 1.36 chs
401 1.36 chs flag = linux_to_bsd_atflags(SCARG(uap, flag));
402 1.36 chs return do_sys_chownat(l, SCARG(uap, fd), SCARG_P32(uap, path),
403 1.36 chs SCARG(uap, owner), SCARG(uap, group), flag);
404 1.36 chs }
405 1.36 chs
406 1.36 chs int
407 1.36 chs linux32_sys_faccessat(struct lwp *l, const struct linux32_sys_faccessat_args *uap, register_t *retval)
408 1.36 chs {
409 1.36 chs /* {
410 1.36 chs syscallarg(int) fd;
411 1.36 chs syscallarg(netbsd_charp) path;
412 1.36 chs syscallarg(int) amode;
413 1.36 chs } */
414 1.36 chs
415 1.36 chs return do_sys_accessat(l, SCARG(uap, fd), SCARG_P32(uap, path),
416 1.36 chs SCARG(uap, amode), AT_SYMLINK_FOLLOW);
417 1.36 chs }
418 1.36 chs
419 1.36 chs int
420 1.36 chs linux32_sys_utimensat(struct lwp *l, const struct linux32_sys_utimensat_args *uap, register_t *retval)
421 1.36 chs {
422 1.36 chs /* {
423 1.36 chs syscallarg(int) fd;
424 1.36 chs syscallarg(const netbsd32_charp) path;
425 1.36 chs syscallarg(const linux32_timespecp_t) times;
426 1.36 chs syscallarg(int) flags;
427 1.36 chs } */
428 1.36 chs int error;
429 1.36 chs struct linux32_timespec lts[2];
430 1.36 chs struct timespec *tsp = NULL, ts[2];
431 1.36 chs
432 1.36 chs if (SCARG_P32(uap, times)) {
433 1.36 chs error = copyin(SCARG_P32(uap, times), <s, sizeof(lts));
434 1.36 chs if (error != 0)
435 1.36 chs return error;
436 1.36 chs linux32_to_native_timespec(&ts[0], <s[0]);
437 1.36 chs linux32_to_native_timespec(&ts[1], <s[1]);
438 1.36 chs tsp = ts;
439 1.36 chs }
440 1.36 chs
441 1.36 chs return linux_do_sys_utimensat(l, SCARG(uap, fd), SCARG_P32(uap, path),
442 1.36 chs tsp, SCARG(uap, flag), retval);
443 1.36 chs }
444 1.36 chs
445 1.36 chs int
446 1.17 dsl linux32_sys_creat(struct lwp *l, const struct linux32_sys_creat_args *uap, register_t *retval)
447 1.1 manu {
448 1.17 dsl /* {
449 1.1 manu syscallarg(const netbsd32_charp) path;
450 1.1 manu syscallarg(int) mode;
451 1.17 dsl } */
452 1.1 manu struct sys_open_args ua;
453 1.1 manu
454 1.1 manu NETBSD32TOP_UAP(path, const char);
455 1.1 manu SCARG(&ua, flags) = O_CREAT | O_TRUNC | O_WRONLY;
456 1.1 manu NETBSD32TO64_UAP(mode);
457 1.1 manu
458 1.1 manu return sys_open(l, &ua, retval);
459 1.1 manu }
460 1.1 manu
461 1.1 manu int
462 1.17 dsl linux32_sys_mknod(struct lwp *l, const struct linux32_sys_mknod_args *uap, register_t *retval)
463 1.1 manu {
464 1.17 dsl /* {
465 1.1 manu syscallarg(const netbsd32_charp) path;
466 1.1 manu syscallarg(int) mode;
467 1.1 manu syscallarg(int) dev;
468 1.17 dsl } */
469 1.1 manu struct linux_sys_mknod_args ua;
470 1.1 manu
471 1.1 manu NETBSD32TOP_UAP(path, const char);
472 1.1 manu NETBSD32TO64_UAP(mode);
473 1.1 manu NETBSD32TO64_UAP(dev);
474 1.1 manu
475 1.1 manu return linux_sys_mknod(l, &ua, retval);
476 1.1 manu }
477 1.1 manu
478 1.1 manu int
479 1.17 dsl linux32_sys_break(struct lwp *l, const struct linux32_sys_break_args *uap, register_t *retval)
480 1.1 manu {
481 1.1 manu #if 0
482 1.17 dsl /* {
483 1.1 manu syscallarg(const netbsd32_charp) nsize;
484 1.17 dsl } */
485 1.1 manu #endif
486 1.1 manu
487 1.1 manu return ENOSYS;
488 1.1 manu }
489 1.1 manu
490 1.1 manu int
491 1.17 dsl linux32_sys_swapon(struct lwp *l, const struct linux32_sys_swapon_args *uap, register_t *retval)
492 1.1 manu {
493 1.17 dsl /* {
494 1.1 manu syscallarg(const netbsd32_charp) name;
495 1.17 dsl } */
496 1.1 manu struct sys_swapctl_args ua;
497 1.1 manu
498 1.1 manu SCARG(&ua, cmd) = SWAP_ON;
499 1.7 dsl SCARG(&ua, arg) = SCARG_P32(uap, name);
500 1.1 manu SCARG(&ua, misc) = 0; /* priority */
501 1.1 manu return (sys_swapctl(l, &ua, retval));
502 1.1 manu }
503 1.1 manu
504 1.1 manu int
505 1.17 dsl linux32_sys_swapoff(struct lwp *l, const struct linux32_sys_swapoff_args *uap, register_t *retval)
506 1.1 manu {
507 1.17 dsl /* {
508 1.1 manu syscallarg(const netbsd32_charp) path;
509 1.17 dsl } */
510 1.1 manu struct sys_swapctl_args ua;
511 1.1 manu
512 1.1 manu SCARG(&ua, cmd) = SWAP_OFF;
513 1.7 dsl SCARG(&ua, arg) = SCARG_P32(uap, path);
514 1.1 manu SCARG(&ua, misc) = 0; /* priority */
515 1.1 manu return (sys_swapctl(l, &ua, retval));
516 1.1 manu }
517 1.1 manu
518 1.1 manu
519 1.1 manu int
520 1.17 dsl linux32_sys_reboot(struct lwp *l, const struct linux32_sys_reboot_args *uap, register_t *retval)
521 1.1 manu {
522 1.17 dsl /* {
523 1.1 manu syscallarg(int) magic1;
524 1.1 manu syscallarg(int) magic2;
525 1.1 manu syscallarg(int) cmd;
526 1.1 manu syscallarg(netbsd32_voidp) arg;
527 1.17 dsl } */
528 1.1 manu struct linux_sys_reboot_args ua;
529 1.1 manu
530 1.1 manu NETBSD32TO64_UAP(magic1);
531 1.1 manu NETBSD32TO64_UAP(magic2);
532 1.1 manu NETBSD32TO64_UAP(cmd);
533 1.1 manu NETBSD32TOP_UAP(arg, void);
534 1.1 manu
535 1.1 manu return linux_sys_reboot(l, &ua, retval);
536 1.1 manu }
537 1.1 manu
538 1.1 manu int
539 1.17 dsl linux32_sys_setresuid(struct lwp *l, const struct linux32_sys_setresuid_args *uap, register_t *retval)
540 1.3 manu {
541 1.17 dsl /* {
542 1.3 manu syscallarg(uid_t) ruid;
543 1.3 manu syscallarg(uid_t) euid;
544 1.3 manu syscallarg(uid_t) suid;
545 1.17 dsl } */
546 1.3 manu struct linux_sys_setresuid_args ua;
547 1.3 manu
548 1.27 njoly NETBSD32TO64_UAP(ruid);
549 1.27 njoly NETBSD32TO64_UAP(euid);
550 1.27 njoly NETBSD32TO64_UAP(suid);
551 1.3 manu
552 1.3 manu return linux_sys_setresuid(l, &ua, retval);
553 1.3 manu }
554 1.3 manu
555 1.3 manu int
556 1.26 njoly linux32_sys_getresuid(struct lwp *l, const struct linux32_sys_getresuid_args *uap, register_t *retval)
557 1.26 njoly {
558 1.26 njoly /* {
559 1.26 njoly syscallarg(linux32_uidp_t) ruid;
560 1.26 njoly syscallarg(linux32_uidp_t) euid;
561 1.26 njoly syscallarg(linux32_uidp_t) suid;
562 1.26 njoly } */
563 1.26 njoly kauth_cred_t pc = l->l_cred;
564 1.26 njoly int error;
565 1.26 njoly uid_t uid;
566 1.26 njoly
567 1.26 njoly uid = kauth_cred_getuid(pc);
568 1.26 njoly if ((error = copyout(&uid, SCARG_P32(uap, ruid), sizeof(uid_t))) != 0)
569 1.26 njoly return error;
570 1.26 njoly
571 1.26 njoly uid = kauth_cred_geteuid(pc);
572 1.26 njoly if ((error = copyout(&uid, SCARG_P32(uap, euid), sizeof(uid_t))) != 0)
573 1.26 njoly return error;
574 1.26 njoly
575 1.26 njoly uid = kauth_cred_getsvuid(pc);
576 1.26 njoly return copyout(&uid, SCARG_P32(uap, suid), sizeof(uid_t));
577 1.26 njoly }
578 1.26 njoly
579 1.26 njoly int
580 1.17 dsl linux32_sys_setresgid(struct lwp *l, const struct linux32_sys_setresgid_args *uap, register_t *retval)
581 1.3 manu {
582 1.17 dsl /* {
583 1.3 manu syscallarg(gid_t) rgid;
584 1.3 manu syscallarg(gid_t) egid;
585 1.3 manu syscallarg(gid_t) sgid;
586 1.17 dsl } */
587 1.3 manu struct linux_sys_setresgid_args ua;
588 1.3 manu
589 1.27 njoly NETBSD32TO64_UAP(rgid);
590 1.27 njoly NETBSD32TO64_UAP(egid);
591 1.27 njoly NETBSD32TO64_UAP(sgid);
592 1.3 manu
593 1.3 manu return linux_sys_setresgid(l, &ua, retval);
594 1.3 manu }
595 1.13 njoly
596 1.13 njoly int
597 1.26 njoly linux32_sys_getresgid(struct lwp *l, const struct linux32_sys_getresgid_args *uap, register_t *retval)
598 1.26 njoly {
599 1.26 njoly /* {
600 1.26 njoly syscallarg(linux32_gidp_t) rgid;
601 1.26 njoly syscallarg(linux32_gidp_t) egid;
602 1.26 njoly syscallarg(linux32_gidp_t) sgid;
603 1.26 njoly } */
604 1.26 njoly kauth_cred_t pc = l->l_cred;
605 1.26 njoly int error;
606 1.26 njoly gid_t gid;
607 1.26 njoly
608 1.26 njoly gid = kauth_cred_getgid(pc);
609 1.26 njoly if ((error = copyout(&gid, SCARG_P32(uap, rgid), sizeof(gid_t))) != 0)
610 1.26 njoly return error;
611 1.26 njoly
612 1.26 njoly gid = kauth_cred_getegid(pc);
613 1.26 njoly if ((error = copyout(&gid, SCARG_P32(uap, egid), sizeof(gid_t))) != 0)
614 1.26 njoly return error;
615 1.26 njoly
616 1.26 njoly gid = kauth_cred_getsvgid(pc);
617 1.26 njoly return copyout(&gid, SCARG_P32(uap, sgid), sizeof(gid_t));
618 1.26 njoly }
619 1.26 njoly
620 1.26 njoly int
621 1.17 dsl linux32_sys_nice(struct lwp *l, const struct linux32_sys_nice_args *uap, register_t *retval)
622 1.13 njoly {
623 1.17 dsl /* {
624 1.13 njoly syscallarg(int) incr;
625 1.17 dsl } */
626 1.24 njoly struct proc *p = l->l_proc;
627 1.22 njoly struct sys_setpriority_args bsa;
628 1.33 njoly int error;
629 1.13 njoly
630 1.13 njoly SCARG(&bsa, which) = PRIO_PROCESS;
631 1.13 njoly SCARG(&bsa, who) = 0;
632 1.24 njoly SCARG(&bsa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
633 1.13 njoly
634 1.33 njoly error = sys_setpriority(l, &bsa, retval);
635 1.33 njoly return (error) ? EPERM : 0;
636 1.13 njoly }
637 1.13 njoly
638 1.13 njoly int
639 1.17 dsl linux32_sys_alarm(struct lwp *l, const struct linux32_sys_alarm_args *uap, register_t *retval)
640 1.13 njoly {
641 1.17 dsl /* {
642 1.13 njoly syscallarg(unsigned int) secs;
643 1.17 dsl } */
644 1.13 njoly struct linux_sys_alarm_args ua;
645 1.13 njoly
646 1.13 njoly NETBSD32TO64_UAP(secs);
647 1.13 njoly
648 1.13 njoly return linux_sys_alarm(l, &ua, retval);
649 1.13 njoly }
650 1.13 njoly
651 1.13 njoly int
652 1.17 dsl linux32_sys_fdatasync(struct lwp *l, const struct linux32_sys_fdatasync_args *uap, register_t *retval)
653 1.13 njoly {
654 1.17 dsl /* {
655 1.13 njoly syscallarg(int) fd;
656 1.17 dsl } */
657 1.13 njoly struct linux_sys_fdatasync_args ua;
658 1.13 njoly
659 1.13 njoly NETBSD32TO64_UAP(fd);
660 1.13 njoly
661 1.13 njoly return linux_sys_fdatasync(l, &ua, retval);
662 1.13 njoly }
663 1.13 njoly
664 1.13 njoly int
665 1.17 dsl linux32_sys_setfsuid(struct lwp *l, const struct linux32_sys_setfsuid_args *uap, register_t *retval)
666 1.13 njoly {
667 1.17 dsl /* {
668 1.13 njoly syscallarg(uid_t) uid;
669 1.17 dsl } */
670 1.13 njoly struct linux_sys_setfsuid_args ua;
671 1.13 njoly
672 1.13 njoly NETBSD32TO64_UAP(uid);
673 1.13 njoly
674 1.13 njoly return linux_sys_setfsuid(l, &ua, retval);
675 1.13 njoly }
676 1.13 njoly
677 1.13 njoly int
678 1.18 njoly linux32_sys_setfsgid(struct lwp *l, const struct linux32_sys_setfsgid_args *uap, register_t *retval)
679 1.18 njoly {
680 1.18 njoly /* {
681 1.18 njoly syscallarg(gid_t) gid;
682 1.18 njoly } */
683 1.18 njoly struct linux_sys_setfsgid_args ua;
684 1.18 njoly
685 1.18 njoly NETBSD32TO64_UAP(gid);
686 1.18 njoly
687 1.18 njoly return linux_sys_setfsgid(l, &ua, retval);
688 1.18 njoly }
689 1.20 dsl
690 1.20 dsl /*
691 1.20 dsl * pread(2).
692 1.20 dsl */
693 1.20 dsl int
694 1.20 dsl linux32_sys_pread(struct lwp *l,
695 1.20 dsl const struct linux32_sys_pread_args *uap, register_t *retval)
696 1.20 dsl {
697 1.20 dsl /* {
698 1.20 dsl syscallarg(int) fd;
699 1.21 njoly syscallarg(netbsd32_voidp) buf;
700 1.20 dsl syscallarg(netbsd32_size_t) nbyte;
701 1.37 njoly syscallarg(netbsd32_off_t) offset;
702 1.20 dsl } */
703 1.20 dsl struct sys_pread_args pra;
704 1.20 dsl
705 1.20 dsl SCARG(&pra, fd) = SCARG(uap, fd);
706 1.21 njoly SCARG(&pra, buf) = SCARG_P32(uap, buf);
707 1.20 dsl SCARG(&pra, nbyte) = SCARG(uap, nbyte);
708 1.37 njoly SCARG(&pra, PAD) = 0;
709 1.20 dsl SCARG(&pra, offset) = SCARG(uap, offset);
710 1.20 dsl
711 1.20 dsl return sys_pread(l, &pra, retval);
712 1.20 dsl }
713 1.20 dsl
714 1.20 dsl /*
715 1.20 dsl * pwrite(2).
716 1.20 dsl */
717 1.20 dsl int
718 1.20 dsl linux32_sys_pwrite(struct lwp *l,
719 1.20 dsl const struct linux32_sys_pwrite_args *uap, register_t *retval)
720 1.20 dsl {
721 1.20 dsl /* {
722 1.20 dsl syscallarg(int) fd;
723 1.21 njoly syscallarg(const netbsd32_voidp) buf;
724 1.20 dsl syscallarg(netbsd32_size_t) nbyte;
725 1.37 njoly syscallarg(netbsd32_off_t) offset;
726 1.20 dsl } */
727 1.20 dsl struct sys_pwrite_args pra;
728 1.20 dsl
729 1.20 dsl SCARG(&pra, fd) = SCARG(uap, fd);
730 1.21 njoly SCARG(&pra, buf) = SCARG_P32(uap, buf);
731 1.20 dsl SCARG(&pra, nbyte) = SCARG(uap, nbyte);
732 1.37 njoly SCARG(&pra, PAD) = 0;
733 1.20 dsl SCARG(&pra, offset) = SCARG(uap, offset);
734 1.20 dsl
735 1.20 dsl return sys_pwrite(l, &pra, retval);
736 1.20 dsl }
737