Annotation of sys/compat/vax1k/vax1k_subr.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: vax1k_subr.c,v 1.3 2005/11/06 22:21:33 miod Exp $ */
2: /* $NetBSD: vax1k_subr.c,v 1.2 1999/03/24 05:51:20 mrg Exp $ */
3:
4: /*
5: * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by Christopher G. Demetriou.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: #include <sys/param.h>
35: #include <sys/systm.h>
36: #include <sys/proc.h>
37: #include <sys/malloc.h>
38: #include <sys/vnode.h>
39: #include <sys/filedesc.h>
40: #include <sys/exec.h>
41: #include <sys/mman.h>
42:
43: #include <compat/vax1k/vax1k_exec.h>
44:
45: #include <uvm/uvm_extern.h>
46:
47: /*
48: * vax1k_map_readvn():
49: * handle vmcmd which specifies that a vnode should be read from.
50: * This is used to be able to read in and execute vax1k binaries
51: * even if the page size is bigger. (cannot mmap).
52: */
53: int
54: vax1k_map_readvn(p, cmd)
55: struct proc *p;
56: struct exec_vmcmd *cmd;
57: {
58: vaddr_t oaddr;
59: int error;
60:
61: if (cmd->ev_len == 0)
62: return (0);
63:
64: oaddr = cmd->ev_addr;
65: cmd->ev_addr = trunc_page(cmd->ev_addr); /* required by uvm_map */
66: error = uvm_map(&p->p_vmspace->vm_map, &cmd->ev_addr,
67: round_page(cmd->ev_len + (oaddr - cmd->ev_addr)),
68: NULL, UVM_UNKNOWN_OFFSET, 0,
69: UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
70: UVM_ADV_NORMAL,
71: UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
72:
73: if (error)
74: return error;
75:
76: error = vn_rdwr(UIO_READ, cmd->ev_vp, (caddr_t)oaddr,
77: cmd->ev_len, cmd->ev_offset, UIO_USERSPACE, IO_UNIT,
78: p->p_ucred, NULL, p);
79: if (error)
80: return error;
81:
82: if (cmd->ev_prot != (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)) {
83: /*
84: * we had to map in the area at PROT_ALL so that vn_rdwr()
85: * could write to it. however, the caller seems to want
86: * it mapped read-only, so now we are going to have to call
87: * uvm_map_protect() to fix up the protection. ICK.
88: */
89: return(uvm_map_protect(&p->p_vmspace->vm_map,
90: trunc_page(cmd->ev_addr),
91: round_page(cmd->ev_addr + cmd->ev_len),
92: cmd->ev_prot, FALSE));
93: }
94:
95: return (0);
96: }
CVSweb