2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
40 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94
41 * $FreeBSD: src/sys/vm/vm_mmap.c,v 1.108.2.6 2002/07/02 20:06:19 dillon Exp $
45 * Mapped file (mmap) interface to VM
48 #include "opt_compat.h"
50 #include <sys/param.h>
51 #include <sys/kernel.h>
52 #include <sys/systm.h>
53 #include <sys/sysproto.h>
54 #include <sys/filedesc.h>
56 #include <sys/resource.h>
57 #include <sys/resourcevar.h>
58 #include <sys/vnode.h>
59 #include <sys/fcntl.h>
64 #include <sys/vmmeter.h>
65 #include <sys/sysctl.h>
68 #include <vm/vm_param.h>
71 #include <vm/vm_map.h>
72 #include <vm/vm_object.h>
73 #include <vm/vm_page.h>
74 #include <vm/vm_pager.h>
75 #include <vm/vm_pageout.h>
76 #include <vm/vm_extern.h>
77 #include <vm/vm_page.h>
78 #include <vm/vm_kern.h>
80 #ifndef _SYS_SYSPROTO_H_
86 static int max_proc_mmap;
87 SYSCTL_INT(_vm, OID_AUTO, max_proc_mmap, CTLFLAG_RW, &max_proc_mmap, 0, "");
90 * Set the maximum number of vm_map_entry structures per process. Roughly
91 * speaking vm_map_entry structures are tiny, so allowing them to eat 1/100
92 * of our KVM malloc space still results in generous limits. We want a
93 * default that is good enough to prevent the kernel running out of resources
94 * if attacked from compromised user account but generous enough such that
95 * multi-threaded processes are not unduly inconvenienced.
98 static void vmmapentry_rsrc_init __P((void *));
99 SYSINIT(vmmersrc, SI_SUB_KVM_RSRC, SI_ORDER_FIRST, vmmapentry_rsrc_init, NULL)
102 vmmapentry_rsrc_init(dummy)
105 max_proc_mmap = vm_kmem_size / sizeof(struct vm_map_entry);
106 max_proc_mmap /= 100;
113 struct sbrk_args *uap;
116 /* Not yet implemented */
120 #ifndef _SYS_SYSPROTO_H_
130 struct sstk_args *uap;
133 /* Not yet implemented */
137 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
138 #ifndef _SYS_SYSPROTO_H_
139 struct getpagesize_args {
148 struct getpagesize_args *uap;
151 p->p_retval[0] = PAGE_SIZE;
154 #endif /* COMPAT_43 || COMPAT_SUNOS */
158 * Memory Map (mmap) system call. Note that the file offset
159 * and address are allowed to be NOT page aligned, though if
160 * the MAP_FIXED flag it set, both must have the same remainder
161 * modulo the PAGE_SIZE (POSIX 1003.1b). If the address is not
162 * page-aligned, the actual mapping starts at trunc_page(addr)
163 * and the return value is adjusted up by the page offset.
165 * Generally speaking, only character devices which are themselves
166 * memory-based, such as a video framebuffer, can be mmap'd. Otherwise
167 * there would be no cache coherency between a descriptor and a VM mapping
168 * both to the same character device.
170 * Block devices can be mmap'd no matter what they represent. Cache coherency
171 * is maintained as long as you do not write directly to the underlying
174 #ifndef _SYS_SYSPROTO_H_
189 register struct mmap_args *uap;
191 register struct filedesc *fdp = p->p_fd;
192 register struct file *fp = NULL;
195 vm_size_t size, pageoff;
196 vm_prot_t prot, maxprot;
199 int disablexworkaround;
201 struct vmspace *vms = p->p_vmspace;
204 addr = (vm_offset_t) uap->addr;
206 prot = uap->prot & VM_PROT_ALL;
210 /* make sure mapping fits into numeric range etc */
211 if ((ssize_t) uap->len < 0 ||
212 ((flags & MAP_ANON) && uap->fd != -1))
215 if (flags & MAP_STACK) {
216 if ((uap->fd != -1) ||
217 ((prot & (PROT_READ | PROT_WRITE)) != (PROT_READ | PROT_WRITE)))
224 * Align the file position to a page boundary,
225 * and save its page offset component.
227 pageoff = (pos & PAGE_MASK);
230 /* Adjust size for rounding (on both ends). */
231 size += pageoff; /* low end... */
232 size = (vm_size_t) round_page(size); /* hi end */
235 * Check for illegal addresses. Watch out for address wrap... Note
236 * that VM_*_ADDRESS are not constants due to casts (argh).
238 if (flags & MAP_FIXED) {
240 * The specified address must have the same remainder
241 * as the file offset taken modulo PAGE_SIZE, so it
242 * should be aligned after adjustment by pageoff.
245 if (addr & PAGE_MASK)
247 /* Address range must be all in user VM space. */
248 if (VM_MAXUSER_ADDRESS > 0 && addr + size > VM_MAXUSER_ADDRESS)
251 if (VM_MIN_ADDRESS > 0 && addr < VM_MIN_ADDRESS)
254 if (addr + size < addr)
258 * XXX for non-fixed mappings where no hint is provided or
259 * the hint would fall in the potential heap space,
260 * place it after the end of the largest possible heap.
262 * There should really be a pmap call to determine a reasonable
265 else if (addr == 0 ||
266 (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
267 addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz)))
268 addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz);
270 if (flags & MAP_ANON) {
272 * Mapping blank space is trivial.
275 maxprot = VM_PROT_ALL;
279 * Mapping file, get fp for validation. Obtain vnode and make
280 * sure it is of appropriate type.
282 if (((unsigned) uap->fd) >= fdp->fd_nfiles ||
283 (fp = fdp->fd_ofiles[uap->fd]) == NULL)
285 if (fp->f_type != DTYPE_VNODE)
288 * POSIX shared-memory objects are defined to have
289 * kernel persistence, and are not defined to support
290 * read(2)/write(2) -- or even open(2). Thus, we can
291 * use MAP_ASYNC to trade on-disk coherence for speed.
292 * The shm_open(3) library routine turns on the FPOSIXSHM
293 * flag to request this behavior.
295 if (fp->f_flag & FPOSIXSHM)
297 vp = (struct vnode *) fp->f_data;
298 if (vp->v_type != VREG && vp->v_type != VCHR)
300 if (vp->v_type == VREG) {
302 * Get the proper underlying object
304 if (VOP_GETVOBJECT(vp, &obj) != 0)
306 vp = (struct vnode*)obj->handle;
310 * don't let the descriptor disappear on us if we block
315 * XXX hack to handle use of /dev/zero to map anon memory (ala
318 if (vp->v_type == VCHR && iszerodev(vp->v_rdev)) {
320 maxprot = VM_PROT_ALL;
325 * cdevs does not provide private mappings of any kind.
328 * However, for XIG X server to continue to work,
329 * we should allow the superuser to do it anyway.
330 * We only allow it at securelevel < 1.
331 * (Because the XIG X server writes directly to video
332 * memory via /dev/mem, it should never work at any
334 * XXX this will have to go
336 if (securelevel >= 1)
337 disablexworkaround = 1;
339 disablexworkaround = suser(p);
340 if (vp->v_type == VCHR && disablexworkaround &&
341 (flags & (MAP_PRIVATE|MAP_COPY))) {
346 * Ensure that file and memory protections are
347 * compatible. Note that we only worry about
348 * writability if mapping is shared; in this case,
349 * current and max prot are dictated by the open file.
350 * XXX use the vnode instead? Problem is: what
351 * credentials do we use for determination? What if
352 * proc does a setuid?
354 maxprot = VM_PROT_EXECUTE; /* ??? */
355 if (fp->f_flag & FREAD) {
356 maxprot |= VM_PROT_READ;
357 } else if (prot & PROT_READ) {
362 * If we are sharing potential changes (either via
363 * MAP_SHARED or via the implicit sharing of character
364 * device mappings), and we are trying to get write
365 * permission although we opened it without asking
366 * for it, bail out. Check for superuser, only if
367 * we're at securelevel < 1, to allow the XIG X server
368 * to continue to work.
371 if ((flags & MAP_SHARED) != 0 ||
372 (vp->v_type == VCHR && disablexworkaround)) {
373 if ((fp->f_flag & FWRITE) != 0) {
381 (IMMUTABLE|APPEND)) == 0) {
382 maxprot |= VM_PROT_WRITE;
383 } else if (prot & PROT_WRITE) {
387 } else if ((prot & PROT_WRITE) != 0) {
392 maxprot |= VM_PROT_WRITE;
399 * Do not allow more then a certain number of vm_map_entry structures
400 * per process. Scale with the number of rforks sharing the map
401 * to make the limit reasonable for threads.
404 vms->vm_map.nentries >= max_proc_mmap * vms->vm_refcnt) {
409 error = vm_mmap(&vms->vm_map, &addr, size, prot, maxprot,
412 p->p_retval[0] = (register_t) (addr + pageoff);
420 #ifndef _SYS_SYSPROTO_H_
433 register struct ommap_args *uap;
435 struct mmap_args nargs;
436 static const char cvtbsdprot[8] = {
440 PROT_EXEC | PROT_WRITE,
442 PROT_EXEC | PROT_READ,
443 PROT_WRITE | PROT_READ,
444 PROT_EXEC | PROT_WRITE | PROT_READ,
447 #define OMAP_ANON 0x0002
448 #define OMAP_COPY 0x0020
449 #define OMAP_SHARED 0x0010
450 #define OMAP_FIXED 0x0100
451 #define OMAP_INHERIT 0x0800
453 nargs.addr = uap->addr;
454 nargs.len = uap->len;
455 nargs.prot = cvtbsdprot[uap->prot & 0x7];
457 if (uap->flags & OMAP_ANON)
458 nargs.flags |= MAP_ANON;
459 if (uap->flags & OMAP_COPY)
460 nargs.flags |= MAP_COPY;
461 if (uap->flags & OMAP_SHARED)
462 nargs.flags |= MAP_SHARED;
464 nargs.flags |= MAP_PRIVATE;
465 if (uap->flags & OMAP_FIXED)
466 nargs.flags |= MAP_FIXED;
467 if (uap->flags & OMAP_INHERIT)
468 nargs.flags |= MAP_INHERIT;
470 nargs.pos = uap->pos;
471 return (mmap(p, &nargs));
473 #endif /* COMPAT_43 */
476 #ifndef _SYS_SYSPROTO_H_
486 struct msync_args *uap;
489 vm_size_t size, pageoff;
494 addr = (vm_offset_t) uap->addr;
498 pageoff = (addr & PAGE_MASK);
501 size = (vm_size_t) round_page(size);
502 if (addr + size < addr)
505 if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE))
508 map = &p->p_vmspace->vm_map;
511 * XXX Gak! If size is zero we are supposed to sync "all modified
512 * pages with the region containing addr". Unfortunately, we don't
513 * really keep track of individual mmaps so we approximate by flushing
514 * the range of the map entry containing addr. This can be incorrect
515 * if the region splits or is coalesced with a neighbor.
518 vm_map_entry_t entry;
520 vm_map_lock_read(map);
521 rv = vm_map_lookup_entry(map, addr, &entry);
522 vm_map_unlock_read(map);
526 size = entry->end - entry->start;
530 * Clean the pages and interpret the return value.
532 rv = vm_map_clean(map, addr, addr + size, (flags & MS_ASYNC) == 0,
533 (flags & MS_INVALIDATE) != 0);
538 case KERN_INVALID_ADDRESS:
539 return (EINVAL); /* Sun returns ENOMEM? */
549 #ifndef _SYS_SYSPROTO_H_
557 register struct proc *p;
558 register struct munmap_args *uap;
561 vm_size_t size, pageoff;
564 addr = (vm_offset_t) uap->addr;
567 pageoff = (addr & PAGE_MASK);
570 size = (vm_size_t) round_page(size);
571 if (addr + size < addr)
578 * Check for illegal addresses. Watch out for address wrap... Note
579 * that VM_*_ADDRESS are not constants due to casts (argh).
581 if (VM_MAXUSER_ADDRESS > 0 && addr + size > VM_MAXUSER_ADDRESS)
584 if (VM_MIN_ADDRESS > 0 && addr < VM_MIN_ADDRESS)
587 map = &p->p_vmspace->vm_map;
589 * Make sure entire range is allocated.
591 if (!vm_map_check_protection(map, addr, addr + size, VM_PROT_NONE))
593 /* returns nothing but KERN_SUCCESS anyway */
594 (void) vm_map_remove(map, addr, addr + size);
605 * XXX should unmap any regions mapped to this file
607 p->p_fd->fd_ofileflags[fd] &= ~UF_MAPPED;
611 #ifndef _SYS_SYSPROTO_H_
612 struct mprotect_args {
621 struct mprotect_args *uap;
624 vm_size_t size, pageoff;
625 register vm_prot_t prot;
627 addr = (vm_offset_t) uap->addr;
629 prot = uap->prot & VM_PROT_ALL;
630 #if defined(VM_PROT_READ_IS_EXEC)
631 if (prot & VM_PROT_READ)
632 prot |= VM_PROT_EXECUTE;
635 pageoff = (addr & PAGE_MASK);
638 size = (vm_size_t) round_page(size);
639 if (addr + size < addr)
642 switch (vm_map_protect(&p->p_vmspace->vm_map, addr, addr + size, prot,
646 case KERN_PROTECTION_FAILURE:
652 #ifndef _SYS_SYSPROTO_H_
653 struct minherit_args {
662 struct minherit_args *uap;
665 vm_size_t size, pageoff;
666 register vm_inherit_t inherit;
668 addr = (vm_offset_t)uap->addr;
670 inherit = uap->inherit;
672 pageoff = (addr & PAGE_MASK);
675 size = (vm_size_t) round_page(size);
676 if (addr + size < addr)
679 switch (vm_map_inherit(&p->p_vmspace->vm_map, addr, addr+size,
683 case KERN_PROTECTION_FAILURE:
689 #ifndef _SYS_SYSPROTO_H_
690 struct madvise_args {
701 struct madvise_args *uap;
703 vm_offset_t start, end;
706 * Check for illegal behavior
708 if (uap->behav < 0 || uap->behav > MADV_CORE)
711 * Check for illegal addresses. Watch out for address wrap... Note
712 * that VM_*_ADDRESS are not constants due to casts (argh).
714 if (VM_MAXUSER_ADDRESS > 0 &&
715 ((vm_offset_t) uap->addr + uap->len) > VM_MAXUSER_ADDRESS)
718 if (VM_MIN_ADDRESS > 0 && uap->addr < VM_MIN_ADDRESS)
721 if (((vm_offset_t) uap->addr + uap->len) < (vm_offset_t) uap->addr)
725 * Since this routine is only advisory, we default to conservative
728 start = trunc_page((vm_offset_t) uap->addr);
729 end = round_page((vm_offset_t) uap->addr + uap->len);
731 if (vm_map_madvise(&p->p_vmspace->vm_map, start, end, uap->behav))
736 #ifndef _SYS_SYSPROTO_H_
737 struct mincore_args {
748 struct mincore_args *uap;
750 vm_offset_t addr, first_addr;
751 vm_offset_t end, cend;
756 int vecindex, lastvecindex;
757 register vm_map_entry_t current;
758 vm_map_entry_t entry;
760 unsigned int timestamp;
763 * Make sure that the addresses presented are valid for user
766 first_addr = addr = trunc_page((vm_offset_t) uap->addr);
767 end = addr + (vm_size_t)round_page(uap->len);
768 if (VM_MAXUSER_ADDRESS > 0 && end > VM_MAXUSER_ADDRESS)
774 * Address of byte vector
778 map = &p->p_vmspace->vm_map;
779 pmap = vmspace_pmap(p->p_vmspace);
781 vm_map_lock_read(map);
783 timestamp = map->timestamp;
785 if (!vm_map_lookup_entry(map, addr, &entry))
789 * Do this on a map entry basis so that if the pages are not
790 * in the current processes address space, we can easily look
791 * up the pages elsewhere.
795 (current != &map->header) && (current->start < end);
796 current = current->next) {
799 * ignore submaps (for now) or null objects
801 if ((current->eflags & MAP_ENTRY_IS_SUB_MAP) ||
802 current->object.vm_object == NULL)
806 * limit this scan to the current map entry and the
807 * limits for the mincore call
809 if (addr < current->start)
810 addr = current->start;
816 * scan this entry one page at a time
820 * Check pmap first, it is likely faster, also
821 * it can provide info as to whether we are the
822 * one referencing or modifying the page.
824 mincoreinfo = pmap_mincore(pmap, addr);
830 * calculate the page index into the object
832 offset = current->offset + (addr - current->start);
833 pindex = OFF_TO_IDX(offset);
834 m = vm_page_lookup(current->object.vm_object,
837 * if the page is resident, then gather information about
841 mincoreinfo = MINCORE_INCORE;
844 mincoreinfo |= MINCORE_MODIFIED_OTHER;
845 if ((m->flags & PG_REFERENCED) ||
846 pmap_ts_referenced(m)) {
847 vm_page_flag_set(m, PG_REFERENCED);
848 mincoreinfo |= MINCORE_REFERENCED_OTHER;
854 * subyte may page fault. In case it needs to modify
855 * the map, we release the lock.
857 vm_map_unlock_read(map);
860 * calculate index into user supplied byte vector
862 vecindex = OFF_TO_IDX(addr - first_addr);
865 * If we have skipped map entries, we need to make sure that
866 * the byte vector is zeroed for those skipped entries.
868 while((lastvecindex + 1) < vecindex) {
869 error = subyte( vec + lastvecindex, 0);
877 * Pass the page information to the user
879 error = subyte( vec + vecindex, mincoreinfo);
885 * If the map has changed, due to the subyte, the previous
886 * output may be invalid.
888 vm_map_lock_read(map);
889 if (timestamp != map->timestamp)
892 lastvecindex = vecindex;
898 * subyte may page fault. In case it needs to modify
899 * the map, we release the lock.
901 vm_map_unlock_read(map);
904 * Zero the last entries in the byte vector.
906 vecindex = OFF_TO_IDX(end - first_addr);
907 while((lastvecindex + 1) < vecindex) {
908 error = subyte( vec + lastvecindex, 0);
916 * If the map has changed, due to the subyte, the previous
917 * output may be invalid.
919 vm_map_lock_read(map);
920 if (timestamp != map->timestamp)
922 vm_map_unlock_read(map);
927 #ifndef _SYS_SYSPROTO_H_
936 struct mlock_args *uap;
939 vm_size_t size, pageoff;
942 addr = (vm_offset_t) uap->addr;
945 pageoff = (addr & PAGE_MASK);
948 size = (vm_size_t) round_page(size);
950 /* disable wrap around */
951 if (addr + size < addr)
954 if (atop(size) + cnt.v_wire_count > vm_page_max_wired)
957 #ifdef pmap_wired_count
958 if (size + ptoa(pmap_wired_count(vm_map_pmap(&p->p_vmspace->vm_map))) >
959 p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur)
967 error = vm_map_user_pageable(&p->p_vmspace->vm_map, addr, addr + size, FALSE);
968 return (error == KERN_SUCCESS ? 0 : ENOMEM);
971 #ifndef _SYS_SYSPROTO_H_
972 struct mlockall_args {
980 struct mlockall_args *uap;
985 #ifndef _SYS_SYSPROTO_H_
986 struct mlockall_args {
994 struct munlockall_args *uap;
999 #ifndef _SYS_SYSPROTO_H_
1000 struct munlock_args {
1008 struct munlock_args *uap;
1011 vm_size_t size, pageoff;
1014 addr = (vm_offset_t) uap->addr;
1017 pageoff = (addr & PAGE_MASK);
1020 size = (vm_size_t) round_page(size);
1022 /* disable wrap around */
1023 if (addr + size < addr)
1026 #ifndef pmap_wired_count
1032 error = vm_map_user_pageable(&p->p_vmspace->vm_map, addr, addr + size, TRUE);
1033 return (error == KERN_SUCCESS ? 0 : ENOMEM);
1037 * Internal version of mmap.
1038 * Currently used by mmap, exec, and sys5 shared memory.
1039 * Handle is either a vnode pointer or NULL for MAP_ANON.
1042 vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
1043 vm_prot_t maxprot, int flags,
1049 struct vnode *vp = NULL;
1051 int rv = KERN_SUCCESS;
1052 vm_ooffset_t objsize;
1054 struct proc *p = curproc;
1059 objsize = size = round_page(size);
1061 if (p->p_vmspace->vm_map.size + size >
1062 p->p_rlimit[RLIMIT_VMEM].rlim_cur) {
1067 * We currently can only deal with page aligned file offsets.
1068 * The check is here rather than in the syscall because the
1069 * kernel calls this function internally for other mmaping
1070 * operations (such as in exec) and non-aligned offsets will
1071 * cause pmap inconsistencies...so we want to be sure to
1072 * disallow this in all cases.
1074 if (foff & PAGE_MASK)
1077 if ((flags & MAP_FIXED) == 0) {
1079 *addr = round_page(*addr);
1081 if (*addr != trunc_page(*addr))
1084 (void) vm_map_remove(map, *addr, *addr + size);
1088 * Lookup/allocate object.
1090 if (flags & MAP_ANON) {
1091 type = OBJT_DEFAULT;
1093 * Unnamed anonymous regions always start at 0.
1098 vp = (struct vnode *) handle;
1099 if (vp->v_type == VCHR) {
1101 handle = (void *)(intptr_t)vp->v_rdev;
1106 error = VOP_GETATTR(vp, &vat, p->p_ucred, p);
1109 objsize = round_page(vat.va_size);
1112 * if it is a regular file without any references
1113 * we do not need to sync it.
1115 if (vp->v_type == VREG && vat.va_nlink == 0) {
1116 flags |= MAP_NOSYNC;
1121 if (handle == NULL) {
1125 object = vm_pager_allocate(type,
1126 handle, objsize, prot, foff);
1128 return (type == OBJT_DEVICE ? EINVAL : ENOMEM);
1129 docow = MAP_PREFAULT_PARTIAL;
1133 * Force device mappings to be shared.
1135 if (type == OBJT_DEVICE || type == OBJT_PHYS) {
1136 flags &= ~(MAP_PRIVATE|MAP_COPY);
1137 flags |= MAP_SHARED;
1140 if ((flags & (MAP_ANON|MAP_SHARED)) == 0)
1141 docow |= MAP_COPY_ON_WRITE;
1142 if (flags & MAP_NOSYNC)
1143 docow |= MAP_DISABLE_SYNCER;
1144 if (flags & MAP_NOCORE)
1145 docow |= MAP_DISABLE_COREDUMP;
1147 #if defined(VM_PROT_READ_IS_EXEC)
1148 if (prot & VM_PROT_READ)
1149 prot |= VM_PROT_EXECUTE;
1151 if (maxprot & VM_PROT_READ)
1152 maxprot |= VM_PROT_EXECUTE;
1156 *addr = pmap_addr_hint(object, *addr, size);
1159 if (flags & MAP_STACK)
1160 rv = vm_map_stack (map, *addr, size, prot,
1163 rv = vm_map_find(map, object, foff, addr, size, fitit,
1164 prot, maxprot, docow);
1166 if (rv != KERN_SUCCESS) {
1168 * Lose the object reference. Will destroy the
1169 * object if it's an unnamed anonymous mapping
1170 * or named anonymous without other references.
1172 vm_object_deallocate(object);
1177 * Shared memory is also shared with children.
1179 if (flags & (MAP_SHARED|MAP_INHERIT)) {
1180 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE);
1181 if (rv != KERN_SUCCESS) {
1182 (void) vm_map_remove(map, *addr, *addr + size);
1190 case KERN_INVALID_ADDRESS:
1193 case KERN_PROTECTION_FAILURE: