netbsd32_vm.c revision 1.3 1 1.3 simonb /* $NetBSD: netbsd32_vm.c,v 1.3 2021/01/19 01:47:58 simonb Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg *
28 1.1 mrg * from: NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp
29 1.1 mrg */
30 1.1 mrg
31 1.1 mrg #include <sys/cdefs.h>
32 1.3 simonb __KERNEL_RCSID(0, "$NetBSD: netbsd32_vm.c,v 1.3 2021/01/19 01:47:58 simonb Exp $");
33 1.1 mrg
34 1.1 mrg #include <sys/param.h>
35 1.1 mrg #include <sys/systm.h>
36 1.1 mrg #include <sys/mman.h>
37 1.1 mrg #include <sys/filedesc.h>
38 1.1 mrg #include <sys/vfs_syscalls.h>
39 1.1 mrg
40 1.1 mrg #include <compat/sys/mman.h>
41 1.1 mrg #include <compat/netbsd32/netbsd32.h>
42 1.1 mrg #include <compat/netbsd32/netbsd32_syscall.h>
43 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
44 1.1 mrg #include <compat/netbsd32/netbsd32_conv.h>
45 1.1 mrg
46 1.1 mrg
47 1.1 mrg int
48 1.1 mrg netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
49 1.1 mrg {
50 1.1 mrg /* {
51 1.1 mrg syscallarg(netbsd32_voidp) addr;
52 1.1 mrg syscallarg(netbsd32_size_t) len;
53 1.1 mrg syscallarg(int) prot;
54 1.1 mrg syscallarg(int) flags;
55 1.1 mrg syscallarg(int) fd;
56 1.1 mrg syscallarg(netbsd32_long) PAD;
57 1.1 mrg syscallarg(netbsd32_off_t) pos;
58 1.1 mrg } */
59 1.1 mrg struct sys_mmap_args ua;
60 1.1 mrg int error;
61 1.1 mrg
62 1.1 mrg NETBSD32TOP_UAP(addr, void);
63 1.1 mrg NETBSD32TOX_UAP(len, size_t);
64 1.1 mrg NETBSD32TO64_UAP(prot);
65 1.1 mrg NETBSD32TO64_UAP(flags);
66 1.1 mrg #ifdef __x86_64__
67 1.1 mrg /*
68 1.1 mrg * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least
69 1.1 mrg * and ld.so did not turn it on!
70 1.1 mrg */
71 1.1 mrg if (SCARG(&ua, flags) & COMPAT_MAP_COPY) {
72 1.1 mrg SCARG(&ua, flags) = MAP_PRIVATE
73 1.1 mrg | (SCARG(&ua, flags) & ~COMPAT_MAP_COPY);
74 1.1 mrg SCARG(&ua, prot) |= PROT_EXEC;
75 1.1 mrg }
76 1.1 mrg #endif
77 1.1 mrg NETBSD32TO64_UAP(fd);
78 1.1 mrg NETBSD32TOX_UAP(PAD, long);
79 1.1 mrg NETBSD32TOX_UAP(pos, off_t);
80 1.1 mrg #ifdef DEBUG_MMAP
81 1.1 mrg printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, "
82 1.1 mrg "fd=%ld, pos=0x%lx);\n",
83 1.1 mrg (long)SCARG(&ua, addr), (long)SCARG(&ua, len),
84 1.1 mrg (long)SCARG(&ua, prot), (long)SCARG(&ua, flags),
85 1.1 mrg (long)SCARG(&ua, fd), (long)SCARG(&ua, pos));
86 1.1 mrg #endif
87 1.1 mrg
88 1.1 mrg error = sys_mmap(l, &ua, retval);
89 1.3 simonb #ifdef DEBUG_MMAP
90 1.3 simonb printf("mmap error = %d *retval = %#"PRIxREGISTER"\n", error, *retval);
91 1.3 simonb #endif
92 1.2 mrg if (error == 0 && (u_long)*retval > (u_long)UINT_MAX) {
93 1.2 mrg const char *name = curlwp->l_name;
94 1.2 mrg
95 1.2 mrg if (name == NULL)
96 1.2 mrg name = curproc->p_comm;
97 1.2 mrg printf("netbsd32_mmap(%s:%u:%u): retval out of range: 0x%lx\n",
98 1.2 mrg name, curproc->p_pid, curlwp->l_lid, (u_long)*retval);
99 1.1 mrg /* Should try to recover and return an error here. */
100 1.1 mrg }
101 1.1 mrg return error;
102 1.1 mrg }
103