diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2003-04-14 04:53:52 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2003-04-14 04:53:52 +0000 |
commit | 901c826a09497ead7016206abf7b50656baff91e (patch) | |
tree | 2721a7366483b12d83c3a02b75f402e9e3fd0860 /sys/uvm/uvm_mmap.c | |
parent | bcf4f93c865e19f6d796c4f4095be600cd2b319e (diff) |
There are two related changes.
The first one is an mquery(2) syscall. It's for asking the VM system
about where to map things. It will be used by ld.so, read the man page
for details.
The second change is related and is a centralization of uvm_map hint
that all callers of uvm_map calculated. This will allow us to adjust
this hint on architectures that have segments for non-exec mappings.
deraadt@ drahn@ ok.
Diffstat (limited to 'sys/uvm/uvm_mmap.c')
-rw-r--r-- | sys/uvm/uvm_mmap.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c index 0e09b0096f2..0a68cc18275 100644 --- a/sys/uvm/uvm_mmap.c +++ b/sys/uvm/uvm_mmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_mmap.c,v 1.39 2003/04/07 14:47:08 mpech Exp $ */ +/* $OpenBSD: uvm_mmap.c,v 1.40 2003/04/14 04:53:51 art Exp $ */ /* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */ /* @@ -117,6 +117,68 @@ sys_sstk(p, v, retval) } /* + * sys_mquery: provide mapping hints to applications that do fixed mappings + * + * flags: 0 or MAP_FIXED (MAP_FIXED - means that we insist on this addr and + * don't care about PMAP_PREFER or such) + * addr: hint where we'd like to place the mapping. + * size: size of the mapping + * fd: fd of the file we want to map + * off: offset within the file + */ + +/* ARGSUSED */ +int +sys_mquery(struct proc *p, void *v, register_t *retval) +{ + struct sys_mquery_args /* { + syscallarg(int) flags; + syscallarg(void **) addr; + syscallarg(size_t) size; + syscallarg(int) fd; + syscallarg(off_t) off; + } */ *uap = v; + struct file *fp; + struct uvm_object *uobj; + voff_t uoff; + int error; + vaddr_t vaddr; + int flags = 0; + vm_prot_t prot = SCARG(uap, flags) & VM_PROT_ALL; + + if (SCARG(uap, flags) & MAP_FIXED) + flags |= UVM_FLAG_FIXED; + + if ((error = copyin(SCARG(uap, addr), &vaddr, sizeof(void *))) != 0) + return (error); + + if (SCARG(uap, fd) >= 0) { + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + uobj = &((struct vnode *)fp->f_data)->v_uvm.u_obj; + uoff = SCARG(uap, off); + } else { + fp = NULL; + uobj = NULL; + uoff = 0; + } + + if (vaddr == 0) + vaddr = uvm_map_hint(p, prot); + + if (uvm_map_findspace(&p->p_vmspace->vm_map, vaddr, SCARG(uap, size), + &vaddr, uobj, uoff, 0, flags) == NULL) { + error = ENOMEM; + } else { + error = copyout(&vaddr, SCARG(uap, addr), sizeof(void *)); + } + + if (fp != NULL) + FRELE(fp); + return (error); +} + +/* * sys_mincore: determine if pages are in core or not. */ @@ -350,10 +412,8 @@ sys_mmap(p, v, retval) * we will refine our guess later (e.g. to account for VAC, etc) */ - if (addr < round_page((vaddr_t)p->p_vmspace->vm_daddr + - MAXDSIZ)) - addr = round_page((vaddr_t)p->p_vmspace->vm_daddr + - MAXDSIZ); + if (addr < uvm_map_hint(p, prot)) + addr = uvm_map_hint(p, prot); } /* |