xref: /netbsd-src/sys/compat/linux32/common/linux32_misc.c (revision 2f5e5e735694c180714bb1b7faa48b23eb56b861)
1*2f5e5e73Sryo /*	$NetBSD: linux32_misc.c,v 1.34 2021/11/25 03:08:04 ryo Exp $	*/
2f771d34aSnjoly 
3f771d34aSnjoly /*-
4f771d34aSnjoly  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
5f771d34aSnjoly  * All rights reserved.
6f771d34aSnjoly  *
7f771d34aSnjoly  * This code is derived from software contributed to The NetBSD Foundation
8f771d34aSnjoly  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9f771d34aSnjoly  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center;
10f771d34aSnjoly  * by Edgar Fu\ss, Mathematisches Institut der Uni Bonn.
11f771d34aSnjoly  *
12f771d34aSnjoly  * Redistribution and use in source and binary forms, with or without
13f771d34aSnjoly  * modification, are permitted provided that the following conditions
14f771d34aSnjoly  * are met:
15f771d34aSnjoly  * 1. Redistributions of source code must retain the above copyright
16f771d34aSnjoly  *    notice, this list of conditions and the following disclaimer.
17f771d34aSnjoly  * 2. Redistributions in binary form must reproduce the above copyright
18f771d34aSnjoly  *    notice, this list of conditions and the following disclaimer in the
19f771d34aSnjoly  *    documentation and/or other materials provided with the distribution.
20f771d34aSnjoly  *
21f771d34aSnjoly  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22f771d34aSnjoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23f771d34aSnjoly  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24f771d34aSnjoly  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25f771d34aSnjoly  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26f771d34aSnjoly  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27f771d34aSnjoly  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28f771d34aSnjoly  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29f771d34aSnjoly  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30f771d34aSnjoly  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31f771d34aSnjoly  * POSSIBILITY OF SUCH DAMAGE.
32f771d34aSnjoly  */
33f771d34aSnjoly 
34f771d34aSnjoly #include <sys/cdefs.h>
35*2f5e5e73Sryo __KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.34 2021/11/25 03:08:04 ryo Exp $");
36f771d34aSnjoly 
37f771d34aSnjoly #include <sys/param.h>
38f771d34aSnjoly #include <sys/proc.h>
39f771d34aSnjoly #include <sys/time.h>
40f771d34aSnjoly #include <sys/types.h>
41906b9af2Sdsl #include <sys/fstypes.h>
42906b9af2Sdsl #include <sys/vfs_syscalls.h>
435f09cf30Schristos #include <sys/ptrace.h>
441eff3fc2Snjoly #include <sys/syscall.h>
45f43d462aSnjoly #include <sys/poll.h>
46276ef223Sthorpej #include <sys/futex.h>
47f771d34aSnjoly 
48f771d34aSnjoly #include <compat/netbsd32/netbsd32.h>
49f771d34aSnjoly #include <compat/netbsd32/netbsd32_syscallargs.h>
50f771d34aSnjoly 
5129a841b3Schs #include <compat/linux/common/linux_types.h>
5229a841b3Schs 
53f771d34aSnjoly #include <compat/linux32/common/linux32_types.h>
54*2f5e5e73Sryo #include <compat/linux32/common/linux32_machdep.h>
55f771d34aSnjoly #include <compat/linux32/common/linux32_signal.h>
5630d1f33eSchristos #include <compat/linux32/common/linux32_sched.h>
57f771d34aSnjoly #include <compat/linux32/linux32_syscallargs.h>
58f771d34aSnjoly 
595f09cf30Schristos #include <compat/linux/common/linux_ptrace.h>
6033fa5ccbSchs #include <compat/linux/common/linux_emuldata.h>
61f771d34aSnjoly #include <compat/linux/common/linux_signal.h>
62f771d34aSnjoly #include <compat/linux/common/linux_misc.h>
63f771d34aSnjoly #include <compat/linux/common/linux_statfs.h>
6492ce8c6aSad #include <compat/linux/common/linux_ipc.h>
6592ce8c6aSad #include <compat/linux/common/linux_sem.h>
66f771d34aSnjoly #include <compat/linux/linux_syscallargs.h>
67f771d34aSnjoly 
68f771d34aSnjoly extern const struct linux_mnttypes linux_fstypes[];
69f771d34aSnjoly extern const int linux_fstypes_cnt;
70f771d34aSnjoly 
71f771d34aSnjoly /*
72f771d34aSnjoly  * Implement the fs stat functions. Straightforward.
73f771d34aSnjoly  */
74f771d34aSnjoly int
linux32_sys_statfs(struct lwp * l,const struct linux32_sys_statfs_args * uap,register_t * retval)757e2790cfSdsl linux32_sys_statfs(struct lwp *l, const struct linux32_sys_statfs_args *uap, register_t *retval)
76f771d34aSnjoly {
777e2790cfSdsl 	/* {
78f771d34aSnjoly 		syscallarg(const netbsd32_charp char) path;
79f771d34aSnjoly 		syscallarg(linux32_statfsp) sp;
807e2790cfSdsl 	} */
81906b9af2Sdsl 	struct statvfs *sb;
82f771d34aSnjoly 	struct linux_statfs ltmp;
83f771d34aSnjoly 	int error;
84f771d34aSnjoly 
85906b9af2Sdsl 	sb = STATVFSBUF_GET();
86906b9af2Sdsl 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb);
87906b9af2Sdsl 	if (error == 0) {
88906b9af2Sdsl 		bsd_to_linux_statfs(sb, &ltmp);
89f771d34aSnjoly 		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
90906b9af2Sdsl 	}
91906b9af2Sdsl 
92906b9af2Sdsl 	STATVFSBUF_PUT(sb);
93f771d34aSnjoly 	return error;
94f771d34aSnjoly }
959cbea944Snjoly 
96ca080002Snjoly int
linux32_sys_fstatfs(struct lwp * l,const struct linux32_sys_fstatfs_args * uap,register_t * retval)97ca080002Snjoly linux32_sys_fstatfs(struct lwp *l, const struct linux32_sys_fstatfs_args *uap, register_t *retval)
98ca080002Snjoly {
99ca080002Snjoly 	/* {
100ca080002Snjoly 		syscallarg(int) fd;
101ca080002Snjoly 		syscallarg(linux32_statfsp) sp;
102ca080002Snjoly 	} */
103ca080002Snjoly 	struct statvfs *sb;
104ca080002Snjoly 	struct linux_statfs ltmp;
105ca080002Snjoly 	int error;
106ca080002Snjoly 
107ca080002Snjoly 	sb = STATVFSBUF_GET();
108ca080002Snjoly 	error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
109ca080002Snjoly 	if (error == 0) {
110ca080002Snjoly 		bsd_to_linux_statfs(sb, &ltmp);
111ca080002Snjoly 		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
112ca080002Snjoly 	}
113ca080002Snjoly 	STATVFSBUF_PUT(sb);
114ca080002Snjoly 
115ca080002Snjoly 	return error;
116ca080002Snjoly }
117ca080002Snjoly 
118fc7a1961Schs int
linux32_sys_statfs64(struct lwp * l,const struct linux32_sys_statfs64_args * uap,register_t * retval)119fc7a1961Schs linux32_sys_statfs64(struct lwp *l, const struct linux32_sys_statfs64_args *uap, register_t *retval)
120fc7a1961Schs {
121fc7a1961Schs 	/* {
122fc7a1961Schs 		syscallarg(const netbsd32_charp char) path;
123fc7a1961Schs 		syscallarg(linux32_statfs64p) sp;
124fc7a1961Schs 	} */
125fc7a1961Schs 	struct statvfs *sb;
126fc7a1961Schs 	struct linux_statfs64 ltmp;
127fc7a1961Schs 	int error;
128fc7a1961Schs 
129fc7a1961Schs 	sb = STATVFSBUF_GET();
130fc7a1961Schs 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb);
131fc7a1961Schs 	if (error == 0) {
132fc7a1961Schs 		bsd_to_linux_statfs64(sb, &ltmp);
133fc7a1961Schs 		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
134fc7a1961Schs 	}
135fc7a1961Schs 
136fc7a1961Schs 	STATVFSBUF_PUT(sb);
137fc7a1961Schs 	return error;
138fc7a1961Schs }
139fc7a1961Schs 
140fc7a1961Schs int
linux32_sys_fstatfs64(struct lwp * l,const struct linux32_sys_fstatfs64_args * uap,register_t * retval)141fc7a1961Schs linux32_sys_fstatfs64(struct lwp *l, const struct linux32_sys_fstatfs64_args *uap, register_t *retval)
142fc7a1961Schs {
143fc7a1961Schs 	/* {
144fc7a1961Schs 		syscallarg(int) fd;
145fc7a1961Schs 		syscallarg(linux32_statfs64p) sp;
146fc7a1961Schs 	} */
147fc7a1961Schs 	struct statvfs *sb;
148fc7a1961Schs 	struct linux_statfs64 ltmp;
149fc7a1961Schs 	int error;
150fc7a1961Schs 
151fc7a1961Schs 	sb = STATVFSBUF_GET();
152fc7a1961Schs 	error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
153fc7a1961Schs 	if (error == 0) {
154fc7a1961Schs 		bsd_to_linux_statfs64(sb, &ltmp);
155fc7a1961Schs 		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
156fc7a1961Schs 	}
157fc7a1961Schs 	STATVFSBUF_PUT(sb);
158fc7a1961Schs 
159fc7a1961Schs 	return error;
160fc7a1961Schs }
161fc7a1961Schs 
1625f09cf30Schristos extern const int linux_ptrace_request_map[];
1639cbea944Snjoly 
1645f09cf30Schristos int
linux32_sys_ptrace(struct lwp * l,const struct linux32_sys_ptrace_args * uap,register_t * retval)1655f09cf30Schristos linux32_sys_ptrace(struct lwp *l, const struct linux32_sys_ptrace_args *uap, register_t *retval)
1665f09cf30Schristos {
1675f09cf30Schristos 	/* {
1685f09cf30Schristos 		i386, m68k, powerpc: T=int
169*2f5e5e73Sryo 		aarch64, alpha, amd64: T=long
1705f09cf30Schristos 		syscallarg(T) request;
1715f09cf30Schristos 		syscallarg(T) pid;
1725f09cf30Schristos 		syscallarg(T) addr;
1735f09cf30Schristos 		syscallarg(T) data;
1745f09cf30Schristos 	} */
1755f09cf30Schristos 	const int *ptr;
1765f09cf30Schristos 	int request;
1775f09cf30Schristos 	int error;
1785f09cf30Schristos 
1795f09cf30Schristos 	ptr = linux_ptrace_request_map;
1805f09cf30Schristos 	request = SCARG(uap, request);
1815f09cf30Schristos 	while (*ptr != -1)
1825f09cf30Schristos 		if (*ptr++ == request) {
1839cbea944Snjoly 			struct sys_ptrace_args pta;
1845f09cf30Schristos 
1855f09cf30Schristos 			SCARG(&pta, req) = *ptr;
1865f09cf30Schristos 			SCARG(&pta, pid) = SCARG(uap, pid);
1879cbea944Snjoly 			SCARG(&pta, addr) = NETBSD32IPTR64(SCARG(uap, addr));
1885f09cf30Schristos 			SCARG(&pta, data) = SCARG(uap, data);
1895f09cf30Schristos 
1905f09cf30Schristos 			/*
1915f09cf30Schristos 			 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually
1925f09cf30Schristos 			 * to continue where the process left off previously.
1935f09cf30Schristos 			 * The same thing is achieved by addr == (void *) 1
1945f09cf30Schristos 			 * on NetBSD, so rewrite 'addr' appropriately.
1955f09cf30Schristos 			 */
1965f09cf30Schristos 			if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0)
1975f09cf30Schristos 				SCARG(&pta, addr) = (void *) 1;
1985f09cf30Schristos 
1990efea177Sad 			error = sysent[SYS_ptrace].sy_call(l, &pta, retval);
2005f09cf30Schristos 			if (error)
2015f09cf30Schristos 				return error;
2025f09cf30Schristos 			switch (request) {
2035f09cf30Schristos 			case LINUX_PTRACE_PEEKTEXT:
2045f09cf30Schristos 			case LINUX_PTRACE_PEEKDATA:
2055f09cf30Schristos 				error = copyout (retval,
2069cbea944Snjoly 				    NETBSD32IPTR64(SCARG(uap, data)),
2075f09cf30Schristos 				    sizeof *retval);
2085f09cf30Schristos 				*retval = SCARG(uap, data);
2095f09cf30Schristos 				break;
2105f09cf30Schristos 			default:
2115f09cf30Schristos 				break;
2125f09cf30Schristos 			}
2135f09cf30Schristos 			return error;
2145f09cf30Schristos 		}
2155f09cf30Schristos 		else
2165f09cf30Schristos 			ptr++;
2175f09cf30Schristos 
2189cbea944Snjoly 	return EIO;
2195f09cf30Schristos }
220b22c955aSnjoly 
221b22c955aSnjoly int
linux32_sys_personality(struct lwp * l,const struct linux32_sys_personality_args * uap,register_t * retval)222b22c955aSnjoly linux32_sys_personality(struct lwp *l, const struct linux32_sys_personality_args *uap, register_t *retval)
223b22c955aSnjoly {
224b22c955aSnjoly 	/* {
225675b20daSnjoly 		syscallarg(netbsd32_u_long) per;
226b22c955aSnjoly 	} */
22768429401Schs 	struct linux_sys_personality_args ua;
228b22c955aSnjoly 
22968429401Schs 	NETBSD32TOX_UAP(per, long);
23068429401Schs 	return linux_sys_personality(l, &ua, retval);
231b22c955aSnjoly }
23233fa5ccbSchs 
23333fa5ccbSchs int
linux32_sys_futex(struct lwp * l,const struct linux32_sys_futex_args * uap,register_t * retval)23433fa5ccbSchs linux32_sys_futex(struct lwp *l,
23533fa5ccbSchs     const struct linux32_sys_futex_args *uap, register_t *retval)
23633fa5ccbSchs {
23733fa5ccbSchs 	/* {
23833fa5ccbSchs 		syscallarg(linux32_intp_t) uaddr;
23933fa5ccbSchs 		syscallarg(int) op;
24033fa5ccbSchs 		syscallarg(int) val;
24133fa5ccbSchs 		syscallarg(linux32_timespecp_t) timeout;
24233fa5ccbSchs 		syscallarg(linux32_intp_t) uaddr2;
24333fa5ccbSchs 		syscallarg(int) val3;
24433fa5ccbSchs 	} */
24533fa5ccbSchs 	struct linux32_timespec lts;
246276ef223Sthorpej 	struct timespec ts, *tsp = NULL;
247276ef223Sthorpej 	int val2 = 0;
24833fa5ccbSchs 	int error;
24933fa5ccbSchs 
250276ef223Sthorpej 	/*
251276ef223Sthorpej 	 * Linux overlays the "timeout" field and the "val2" field.
252d69d0e70Sthorpej 	 * "timeout" is only valid for FUTEX_WAIT and FUTEX_WAIT_BITSET
253d69d0e70Sthorpej 	 * on Linux.
254276ef223Sthorpej 	 */
255d69d0e70Sthorpej 	const int op = (SCARG(uap, op) & FUTEX_CMD_MASK);
256d69d0e70Sthorpej 	if ((op == FUTEX_WAIT || op == FUTEX_WAIT_BITSET) &&
25733fa5ccbSchs 	    SCARG_P32(uap, timeout) != NULL) {
258276ef223Sthorpej 		if ((error = copyin(SCARG_P32(uap, timeout),
25933fa5ccbSchs 		    &lts, sizeof(lts))) != 0) {
26033fa5ccbSchs 			return error;
26133fa5ccbSchs 		}
26233fa5ccbSchs 		linux32_to_native_timespec(&ts, &lts);
263276ef223Sthorpej 		tsp = &ts;
264276ef223Sthorpej 	} else {
265276ef223Sthorpej 		val2 = (int)(uintptr_t)SCARG_P32(uap, timeout);
26633fa5ccbSchs 	}
26733fa5ccbSchs 
2686430fcd5Sthorpej 	return linux_do_futex(SCARG_P32(uap, uaddr), SCARG(uap, op),
269276ef223Sthorpej 	    SCARG(uap, val), tsp, SCARG_P32(uap, uaddr2), val2,
270276ef223Sthorpej 	    SCARG(uap, val3), retval);
27133fa5ccbSchs }
272fc7a1961Schs 
273fc7a1961Schs int
linux32_sys_truncate64(struct lwp * l,const struct linux32_sys_truncate64_args * uap,register_t * retval)274fc7a1961Schs linux32_sys_truncate64(struct lwp *l, const struct linux32_sys_truncate64_args *uap, register_t *retval)
275fc7a1961Schs {
276fc7a1961Schs 	/* {
277fc7a1961Schs 		syscallarg(netbsd32_charp) path;
278fc7a1961Schs 		syscallarg(off_t) length;
279fc7a1961Schs 	} */
280fc7a1961Schs 	struct sys_truncate_args ua;
281fc7a1961Schs 
282fc7a1961Schs 	/* Linux doesn't have the 'pad' pseudo-parameter */
283fc7a1961Schs 	NETBSD32TOP_UAP(path, const char *);
284fc7a1961Schs 	SCARG(&ua, PAD) = 0;
285fc7a1961Schs 	SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo);
286fc7a1961Schs 	return sys_truncate(l, &ua, retval);
287fc7a1961Schs }
288fc7a1961Schs 
289fc7a1961Schs int
linux32_sys_ftruncate64(struct lwp * l,const struct linux32_sys_ftruncate64_args * uap,register_t * retval)290fc7a1961Schs linux32_sys_ftruncate64(struct lwp *l, const struct linux32_sys_ftruncate64_args *uap, register_t *retval)
291fc7a1961Schs {
292fc7a1961Schs 	/* {
293fc7a1961Schs 		syscallarg(unsigned int) fd;
294fc7a1961Schs 		syscallarg(off_t) length;
295fc7a1961Schs 	} */
296fc7a1961Schs 	struct sys_ftruncate_args ua;
297fc7a1961Schs 
298fc7a1961Schs 	/* Linux doesn't have the 'pad' pseudo-parameter */
299fc7a1961Schs 	NETBSD32TO64_UAP(fd);
300fc7a1961Schs 	SCARG(&ua, PAD) = 0;
301fc7a1961Schs 	SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo);
302fc7a1961Schs 	return sys_ftruncate(l, &ua, retval);
303fc7a1961Schs }
304fc7a1961Schs 
305fc7a1961Schs int
linux32_sys_setdomainname(struct lwp * l,const struct linux32_sys_setdomainname_args * uap,register_t * retval)306fc7a1961Schs linux32_sys_setdomainname(struct lwp *l, const struct linux32_sys_setdomainname_args *uap, register_t *retval)
307fc7a1961Schs {
308fc7a1961Schs 	/* {
309fc7a1961Schs 		syscallarg(netbsd32_charp) domainname;
310fc7a1961Schs 		syscallarg(int) len;
311fc7a1961Schs 	} */
312fc7a1961Schs 	struct linux_sys_setdomainname_args ua;
313fc7a1961Schs 
314fc7a1961Schs 	NETBSD32TOP_UAP(domainname, char);
315fc7a1961Schs 	NETBSD32TO64_UAP(len);
316fc7a1961Schs 	return linux_sys_setdomainname(l, &ua, retval);
317fc7a1961Schs }
318f43d462aSnjoly 
319f43d462aSnjoly int
linux32_sys_ppoll(struct lwp * l,const struct linux32_sys_ppoll_args * uap,register_t * retval)320f43d462aSnjoly linux32_sys_ppoll(struct lwp *l, const struct linux32_sys_ppoll_args *uap,
321f43d462aSnjoly     register_t *retval)
322f43d462aSnjoly {
323f43d462aSnjoly 	/* {
324f43d462aSnjoly 		syscallarg(netbsd32_pollfdp_t) fds;
325f43d462aSnjoly 		syscallarg(u_int) nfds;
326f43d462aSnjoly 		syscallarg(linux32_timespecp_t) timeout;
327f43d462aSnjoly 		syscallarg(linux32_sigsetp_t) sigset;
328f43d462aSnjoly 	} */
329f43d462aSnjoly 	struct linux32_timespec lts0, *lts;
330f43d462aSnjoly 	struct timespec ts0, *ts = NULL;
331f43d462aSnjoly 	linux32_sigset_t lsigmask0, *lsigmask;
332f43d462aSnjoly 	sigset_t sigmask0, *sigmask = NULL;
333f43d462aSnjoly 	int error;
334f43d462aSnjoly 
335f43d462aSnjoly 	lts = SCARG_P32(uap, timeout);
336f43d462aSnjoly 	if (lts) {
337f43d462aSnjoly 		if ((error = copyin(lts, &lts0, sizeof(lts0))) != 0)
338f43d462aSnjoly 			return error;
339f43d462aSnjoly 		linux32_to_native_timespec(&ts0, &lts0);
340f43d462aSnjoly 		ts = &ts0;
341f43d462aSnjoly 	}
342f43d462aSnjoly 
343f43d462aSnjoly 	lsigmask = SCARG_P32(uap, sigset);
344f43d462aSnjoly 	if (lsigmask) {
345f43d462aSnjoly 		if ((error = copyin(lsigmask, &lsigmask0, sizeof(lsigmask0))))
346f43d462aSnjoly 			return error;
347f43d462aSnjoly 		linux32_to_native_sigset(&sigmask0, &lsigmask0);
348f43d462aSnjoly 		sigmask = &sigmask0;
349f43d462aSnjoly 	}
350f43d462aSnjoly 
351f43d462aSnjoly 	return pollcommon(retval, SCARG_P32(uap, fds), SCARG(uap, nfds),
352f43d462aSnjoly 	    ts, sigmask);
353f43d462aSnjoly }
3544d055d8aSthorpej 
3554d055d8aSthorpej int
linux32_sys_eventfd(struct lwp * l,const struct linux32_sys_eventfd_args * uap,register_t * retval)3564d055d8aSthorpej linux32_sys_eventfd(struct lwp *l, const struct linux32_sys_eventfd_args *uap,
3574d055d8aSthorpej     register_t *retval)
3584d055d8aSthorpej {
3594d055d8aSthorpej 	/* {
3604d055d8aSthorpej 		syscallarg(unsigned int) initval;
3614d055d8aSthorpej 	} */
3624d055d8aSthorpej 	struct linux_sys_eventfd_args ua;
3634d055d8aSthorpej 
3644d055d8aSthorpej 	NETBSD32TO64_UAP(initval);
3654d055d8aSthorpej 
3664d055d8aSthorpej 	return linux_sys_eventfd(l, &ua, retval);
3674d055d8aSthorpej }
3684d055d8aSthorpej 
3694d055d8aSthorpej int
linux32_sys_eventfd2(struct lwp * l,const struct linux32_sys_eventfd2_args * uap,register_t * retval)3704d055d8aSthorpej linux32_sys_eventfd2(struct lwp *l, const struct linux32_sys_eventfd2_args *uap,
3714d055d8aSthorpej     register_t *retval)
3724d055d8aSthorpej {
3734d055d8aSthorpej 	/* {
3744d055d8aSthorpej 		syscallarg(unsigned int) initval;
3754d055d8aSthorpej 		syscallarg(int) flags;
3764d055d8aSthorpej 	} */
3774d055d8aSthorpej 	struct linux_sys_eventfd2_args ua;
3784d055d8aSthorpej 
3794d055d8aSthorpej 	NETBSD32TO64_UAP(initval);
3804d055d8aSthorpej 	NETBSD32TO64_UAP(flags);
3814d055d8aSthorpej 
3824d055d8aSthorpej 	return linux_sys_eventfd2(l, &ua, retval);
3834d055d8aSthorpej }
3844d7b9c05Sthorpej 
3854d7b9c05Sthorpej static inline off_t
linux32_hilo_to_off_t(unsigned long hi,unsigned long lo)3864d7b9c05Sthorpej linux32_hilo_to_off_t(unsigned long hi, unsigned long lo)
3874d7b9c05Sthorpej {
3884d7b9c05Sthorpej 	return (((off_t)hi) << 32) | lo;
3894d7b9c05Sthorpej }
3904d7b9c05Sthorpej 
3914d7b9c05Sthorpej int
linux32_sys_preadv(struct lwp * l,const struct linux32_sys_preadv_args * uap,register_t * retval)3924d7b9c05Sthorpej linux32_sys_preadv(struct lwp *l, const struct linux32_sys_preadv_args *uap,
3934d7b9c05Sthorpej     register_t *retval)
3944d7b9c05Sthorpej {
3954d7b9c05Sthorpej 	/* {
3964d7b9c05Sthorpej 		syscallarg(int) fd;
3974d7b9c05Sthorpej 		syscallarg(const netbsd32_iovecp_t) iovp;
3984d7b9c05Sthorpej 		syscallarg(int) iovcnt;
3994d7b9c05Sthorpej 		syscallarg(netbsd32_u_long) off_lo;
4004d7b9c05Sthorpej 		syscallarg(netbsd32_u_long) off_hi;
4014d7b9c05Sthorpej 	} */
4024d7b9c05Sthorpej 	struct netbsd32_preadv_args ua;
4034d7b9c05Sthorpej 
4044d7b9c05Sthorpej 	SCARG(&ua, fd) = SCARG(uap, fd);
4054d7b9c05Sthorpej 	SCARG(&ua, iovp) = SCARG(uap, iovp);
4064d7b9c05Sthorpej 	SCARG(&ua, iovcnt) = SCARG(uap, iovcnt);
4074d7b9c05Sthorpej 	SCARG(&ua, PAD) = 0;
4084d7b9c05Sthorpej 	SCARG(&ua, offset) = linux32_hilo_to_off_t(SCARG(uap, off_hi),
4094d7b9c05Sthorpej 						   SCARG(uap, off_lo));
4104d7b9c05Sthorpej 	return netbsd32_preadv(l, &ua, retval);
4114d7b9c05Sthorpej }
4124d7b9c05Sthorpej 
4134d7b9c05Sthorpej int
linux32_sys_pwritev(struct lwp * l,const struct linux32_sys_pwritev_args * uap,register_t * retval)4144d7b9c05Sthorpej linux32_sys_pwritev(struct lwp *l, const struct linux32_sys_pwritev_args *uap,
4154d7b9c05Sthorpej     register_t *retval)
4164d7b9c05Sthorpej {
4174d7b9c05Sthorpej 	/* {
4184d7b9c05Sthorpej 		syscallarg(int) fd;
4194d7b9c05Sthorpej 		syscallarg(const netbsd32_iovecp_t) iovp;
4204d7b9c05Sthorpej 		syscallarg(int) iovcnt;
4214d7b9c05Sthorpej 		syscallarg(netbsd32_u_long) off_lo;
4224d7b9c05Sthorpej 		syscallarg(netbsd32_u_long) off_hi;
4234d7b9c05Sthorpej 	} */
4244d7b9c05Sthorpej 	struct netbsd32_pwritev_args ua;
4254d7b9c05Sthorpej 
4264d7b9c05Sthorpej 	SCARG(&ua, fd) = SCARG(uap, fd);
4274d7b9c05Sthorpej 	SCARG(&ua, iovp) = SCARG(uap, iovp);
4284d7b9c05Sthorpej 	SCARG(&ua, iovcnt) = SCARG(uap, iovcnt);
4294d7b9c05Sthorpej 	SCARG(&ua, PAD) = 0;
4304d7b9c05Sthorpej 	SCARG(&ua, offset) = linux32_hilo_to_off_t(SCARG(uap, off_hi),
4314d7b9c05Sthorpej 						   SCARG(uap, off_lo));
4324d7b9c05Sthorpej 	return netbsd32_pwritev(l, &ua, retval);
4334d7b9c05Sthorpej }
434