2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1988 University of Utah.
27 * Copyright (c) 1991, 1993
28 * The Regents of the University of California. All rights reserved.
30 * This code is derived from software contributed to Berkeley by
31 * the Systems Programming Group of the University of Utah Computer
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
64 * @(#)vm_mmap.c 8.10 (Berkeley) 2/19/95
68 * Mapped file (mmap) interface to VM
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/filedesc.h>
75 #include <sys/resourcevar.h>
77 #include <sys/vnode.h>
81 #include <sys/vadvise.h>
82 #include <sys/trace.h>
88 #include <mach/mach_types.h>
90 #include <kern/cpu_number.h>
92 #include <vm/vm_map.h>
93 #include <vm/vm_kern.h>
94 #include <vm/vm_pager.h>
96 #include <mach/vm_sync.h>
97 #include <mach/vm_behavior.h>
98 #include <mach/vm_inherit.h>
99 #include <mach/vm_statistics.h>
109 struct sbrk_args
*uap
;
112 /* Not yet implemented */
124 struct sstk_args
*uap
;
127 /* Not yet implemented */
134 ogetpagesize(p
, uap
, retval
)
143 #endif /* COMPAT_43 */
154 osmmap(curp
, uap
, retval
)
156 register struct osmmap_args
*uap
;
165 #ifdef DOUBLE_ALIGN_PARAMS
171 if ((uap
->share
== MAP_SHARED
)|| (uap
->share
== MAP_PRIVATE
)) {
172 newargs
.addr
= uap
->addr
;
173 newargs
.len
= (size_t)uap
->len
;
174 newargs
.prot
= uap
->prot
;
175 newargs
.flags
= uap
->share
;
176 newargs
.fd
= uap
->fd
;
177 newargs
.pos
= (off_t
)uap
->pos
;
178 return(mmap(curp
,&newargs
, retval
));
189 #ifdef DOUBLE_ALIGN_PARAMS
197 struct mmap_args
*uap
;
201 * Map in special device (must be SHARED) or file
204 register struct vnode
*vp
;
209 kern_return_t result
;
210 vm_offset_t user_addr
;
213 vm_object_offset_t file_pos
;
214 boolean_t find_space
, docow
;
220 user_addr
= (vm_offset_t
)uap
->addr
;
221 user_size
= (vm_size_t
) uap
->len
;
222 prot
= (uap
->prot
& VM_PROT_ALL
);
226 * The vm code does not have prototypes & compiler doesn't do the'
227 * the right thing when you cast 64bit value and pass it in function
228 * call. So here it is.
230 file_pos
= (vm_object_offset_t
)uap
->pos
;
233 /* make sure mapping fits into numeric range etc */
234 if ((file_pos
+ user_size
> (vm_object_offset_t
)-PAGE_SIZE_64
) ||
235 ((ssize_t
) uap
->len
< 0 )||
236 ((flags
& MAP_ANON
) && uap
->fd
!= -1))
240 * Align the file position to a page boundary,
241 * and save its page offset component.
243 pageoff
= ((vm_offset_t
)file_pos
& PAGE_MASK
);
244 file_pos
-= (vm_object_offset_t
)pageoff
;
247 /* Adjust size for rounding (on both ends). */
248 user_size
+= pageoff
; /* low end... */
249 user_size
= (vm_size_t
) round_page(user_size
); /* hi end */
253 * Check for illegal addresses. Watch out for address wrap... Note
254 * that VM_*_ADDRESS are not constants due to casts (argh).
256 if (flags
& MAP_FIXED
) {
258 * The specified address must have the same remainder
259 * as the file offset taken modulo PAGE_SIZE, so it
260 * should be aligned after adjustment by pageoff.
262 user_addr
-= pageoff
;
263 if (user_addr
& PAGE_MASK
)
265 /* Address range must be all in user VM space. */
266 if (VM_MAX_ADDRESS
> 0 && (user_addr
+ user_size
> VM_MAX_ADDRESS
))
268 if (VM_MIN_ADDRESS
> 0 && user_addr
< VM_MIN_ADDRESS
)
270 if (user_addr
+ user_size
< user_addr
)
274 /* DO not have apis to get this info, need to wait till then*/
276 * XXX for non-fixed mappings where no hint is provided or
277 * the hint would fall in the potential heap space,
278 * place it after the end of the largest possible heap.
280 * There should really be a pmap call to determine a reasonable
283 else if (addr
< round_page(p
->p_vmspace
->vm_daddr
+ MAXDSIZ
))
284 addr
= round_page(p
->p_vmspace
->vm_daddr
+ MAXDSIZ
);
289 if (flags
& MAP_ANON
) {
291 * Mapping blank space is trivial.
294 maxprot
= VM_PROT_ALL
;
299 * Mapping file, get fp for validation. Obtain vnode and make
300 * sure it is of appropriate type.
302 err
= fdgetf(p
, uap
->fd
, &fp
);
305 if(fp
->f_type
== DTYPE_PSXSHM
) {
306 uap
->addr
= user_addr
;
307 uap
->len
= user_size
;
311 return(pshm_mmap(p
, uap
, retval
, fp
, pageoff
));
314 if (fp
->f_type
!= DTYPE_VNODE
)
316 vp
= (struct vnode
*)fp
->f_data
;
318 if (vp
->v_type
!= VREG
&& vp
->v_type
!= VCHR
)
321 * XXX hack to handle use of /dev/zero to map anon memory (ala
324 if (vp
->v_type
== VCHR
|| vp
->v_type
== VSTR
) {
328 * Ensure that file and memory protections are
329 * compatible. Note that we only worry about
330 * writability if mapping is shared; in this case,
331 * current and max prot are dictated by the open file.
332 * XXX use the vnode instead? Problem is: what
333 * credentials do we use for determination? What if
334 * proc does a setuid?
336 maxprot
= VM_PROT_EXECUTE
; /* ??? */
337 if (fp
->f_flag
& FREAD
)
338 maxprot
|= VM_PROT_READ
;
339 else if (prot
& PROT_READ
)
342 * If we are sharing potential changes (either via
343 * MAP_SHARED or via the implicit sharing of character
344 * device mappings), and we are trying to get write
345 * permission although we opened it without asking
349 if ((flags
& MAP_SHARED
) != 0) {
350 if ((fp
->f_flag
& FWRITE
) != 0) {
357 (IMMUTABLE
|APPEND
)) == 0)
358 maxprot
|= VM_PROT_WRITE
;
359 else if (prot
& PROT_WRITE
)
361 } else if ((prot
& PROT_WRITE
) != 0)
364 maxprot
|= VM_PROT_WRITE
;
374 * We bend a little - round the start and end addresses
375 * to the nearest page boundary.
377 user_size
= round_page(user_size
);
379 if (file_pos
& PAGE_MASK_64
)
382 user_map
= current_map();
384 if ((flags
& MAP_FIXED
) == 0) {
386 user_addr
= round_page(user_addr
);
388 if (user_addr
!= trunc_page(user_addr
))
391 (void) vm_deallocate(user_map
, user_addr
, user_size
);
396 * Lookup/allocate object.
398 if (flags
& MAP_ANON
) {
400 * Unnamed anonymous regions always start at 0.
406 if (handle
== NULL
) {
410 #if defined(VM_PROT_READ_IS_EXEC)
411 if (prot
& VM_PROT_READ
)
412 prot
|= VM_PROT_EXECUTE
;
414 if (maxprot
& VM_PROT_READ
)
415 maxprot
|= VM_PROT_EXECUTE
;
418 result
= vm_allocate(user_map
, &user_addr
, user_size
, find_space
);
419 if (result
!= KERN_SUCCESS
)
423 UBCINFOCHECK("mmap", vp
);
424 pager
= ubc_getpager(vp
);
431 * FIXME: if we're writing the file we need a way to
432 * ensure that someone doesn't replace our R/W creds
433 * with ones that only work for read.
438 if ((flags
& (MAP_ANON
|MAP_SHARED
)) == 0) {
444 #if defined(VM_PROT_READ_IS_EXEC)
445 if (prot
& VM_PROT_READ
)
446 prot
|= VM_PROT_EXECUTE
;
448 if (maxprot
& VM_PROT_READ
)
449 maxprot
|= VM_PROT_EXECUTE
;
453 result
= vm_map_64(user_map
, &user_addr
, user_size
,
454 0, find_space
, pager
, file_pos
, docow
,
458 if (result
!= KERN_SUCCESS
)
464 if (flags
& (MAP_SHARED
|MAP_INHERIT
)) {
465 result
= vm_inherit(user_map
, user_addr
, user_size
,
467 if (result
!= KERN_SUCCESS
) {
468 (void) vm_deallocate(user_map
, user_addr
, user_size
);
477 *fdflags(p
, uap
->fd
) |= UF_MAPPED
;
478 *retval
= (register_t
)(user_addr
+ pageoff
);
480 case KERN_INVALID_ADDRESS
:
483 case KERN_PROTECTION_FAILURE
:
497 msync(p
, uap
, retval
)
499 struct msync_args
*uap
;
503 vm_size_t size
, pageoff
;
507 vm_sync_t sync_flags
=0;
509 addr
= (vm_offset_t
) uap
->addr
;
510 pageoff
= (addr
& PAGE_MASK
);
513 size
= (vm_size_t
) round_page(size
);
516 if (addr
+ size
< addr
)
519 user_map
= current_map();
521 if ((flags
& (MS_ASYNC
|MS_INVALIDATE
)) == (MS_ASYNC
|MS_INVALIDATE
))
526 * We cannot support this properly without maintaining
527 * list all mmaps done. Cannot use vm_map_entry as they could be
528 * split or coalesced by indepenedant actions. So instead of
529 * inaccurate results, lets just return error as invalid size
535 if (flags
& MS_KILLPAGES
)
536 sync_flags
|= VM_SYNC_KILLPAGES
;
537 if (flags
& MS_DEACTIVATE
)
538 sync_flags
|= VM_SYNC_DEACTIVATE
;
539 if (flags
& MS_INVALIDATE
)
540 sync_flags
|= VM_SYNC_INVALIDATE
;
542 if ( !(flags
& (MS_KILLPAGES
| MS_DEACTIVATE
))) {
543 if (flags
& MS_ASYNC
)
544 sync_flags
|= VM_SYNC_ASYNCHRONOUS
;
546 sync_flags
|= VM_SYNC_SYNCHRONOUS
;
548 rv
= vm_msync(user_map
, addr
, size
, sync_flags
);
553 case KERN_INVALID_ADDRESS
:
554 return (EINVAL
); /* Sun returns ENOMEM? */
568 /* Not yet implemented */
576 munmap(p
, uap
, retval
)
578 struct munmap_args
*uap
;
582 vm_offset_t user_addr
;
583 vm_size_t user_size
, pageoff
;
584 kern_return_t result
;
586 user_addr
= (vm_offset_t
) uap
->addr
;
587 user_size
= (vm_size_t
) uap
->len
;
589 pageoff
= (user_addr
& PAGE_MASK
);
591 user_addr
-= pageoff
;
592 user_size
+= pageoff
;
593 user_size
= round_page(user_size
);
594 if (user_addr
+ user_size
< user_addr
)
600 /* Address range must be all in user VM space. */
601 if (VM_MAX_ADDRESS
> 0 && (user_addr
+ user_size
> VM_MAX_ADDRESS
))
603 if (VM_MIN_ADDRESS
> 0 && user_addr
< VM_MIN_ADDRESS
)
607 result
= vm_deallocate(current_map(), user_addr
, user_size
);
608 if (result
!= KERN_SUCCESS
) {
620 * XXX should vm_deallocate any regions mapped to this file
622 *fdflags(p
, fd
) &= ~UF_MAPPED
;
625 struct mprotect_args
{
631 mprotect(p
, uap
, retval
)
633 struct mprotect_args
*uap
;
636 register vm_prot_t prot
;
637 vm_offset_t user_addr
;
638 vm_size_t user_size
, pageoff
;
639 kern_return_t result
;
642 user_addr
= (vm_offset_t
) uap
->addr
;
643 user_size
= (vm_size_t
) uap
->len
;
644 prot
= (vm_prot_t
)(uap
->prot
& VM_PROT_ALL
);
648 #if defined(VM_PROT_READ_IS_EXEC)
649 if (prot
& VM_PROT_READ
)
650 prot
|= VM_PROT_EXECUTE
;
654 pageoff
= (user_addr
& PAGE_MASK
);
655 user_addr
-= pageoff
;
656 user_size
+= pageoff
;
657 user_size
= round_page(user_size
);
658 if (user_addr
+ user_size
< user_addr
)
661 user_map
= current_map();
663 result
= vm_map_protect(user_map
, user_addr
, user_addr
+user_size
, prot
,
668 case KERN_PROTECTION_FAILURE
:
675 struct minherit_args
{
682 minherit(p
, uap
, retval
)
684 struct minherit_args
*uap
;
688 vm_size_t size
, pageoff
;
689 register vm_inherit_t inherit
;
691 kern_return_t result
;
693 addr
= (vm_offset_t
)uap
->addr
;
695 inherit
= uap
->inherit
;
697 pageoff
= (addr
& PAGE_MASK
);
700 size
= (vm_size_t
) round_page(size
);
701 if (addr
+ size
< addr
)
704 user_map
= current_map();
705 result
= vm_inherit(user_map
, addr
, size
,
710 case KERN_PROTECTION_FAILURE
:
716 struct madvise_args
{
723 madvise(p
, uap
, retval
)
725 struct madvise_args
*uap
;
729 vm_offset_t start
, end
;
730 vm_behavior_t new_behavior
;
731 kern_return_t result
;
734 * Check for illegal addresses. Watch out for address wrap... Note
735 * that VM_*_ADDRESS are not constants due to casts (argh).
737 if (VM_MAX_ADDRESS
> 0 &&
738 ((vm_offset_t
) uap
->addr
+ uap
->len
) > VM_MAX_ADDRESS
)
740 if (VM_MIN_ADDRESS
> 0 && uap
->addr
< VM_MIN_ADDRESS
)
743 if (((vm_offset_t
) uap
->addr
+ uap
->len
) < (vm_offset_t
) uap
->addr
)
747 * Since this routine is only advisory, we default to conservative
750 start
= trunc_page((vm_offset_t
) uap
->addr
);
751 end
= round_page((vm_offset_t
) uap
->addr
+ uap
->len
);
753 user_map
= current_map();
755 switch (uap
->behav
) {
757 new_behavior
= VM_BEHAVIOR_RANDOM
;
759 case MADV_SEQUENTIAL
:
760 new_behavior
= VM_BEHAVIOR_SEQUENTIAL
;
763 new_behavior
= VM_BEHAVIOR_DEFAULT
;
766 new_behavior
= VM_BEHAVIOR_WILLNEED
;
769 new_behavior
= VM_BEHAVIOR_DONTNEED
;
775 result
= vm_behavior_set(user_map
, start
, end
, new_behavior
);
779 case KERN_INVALID_ADDRESS
:
786 struct mincore_args
{
793 mincore(p
, uap
, retval
)
795 struct mincore_args
*uap
;
798 vm_offset_t addr
, first_addr
;
803 int vecindex
, lastvecindex
;
812 * Make sure that the addresses presented are valid for user
815 first_addr
= addr
= trunc_page((vm_offset_t
) uap
->addr
);
816 end
= addr
+ (vm_size_t
)round_page(uap
->len
);
818 if (VM_MAX_ADDRESS
> 0 && end
> VM_MAX_ADDRESS
)
824 * Address of byte vector
831 * Do this on a map entry basis so that if the pages are not
832 * in the current processes address space, we can easily look
833 * up the pages elsewhere.
836 for(addr
; addr
< end
; addr
+= PAGE_SIZE
) {
838 ret
= vm_map_page_query(map
, addr
, &pqueryinfo
, &numref
);
839 if (ret
!= KERN_SUCCESS
)
842 if (pqueryinfo
& VM_PAGE_QUERY_PAGE_PRESENT
)
843 mincoreinfo
|= MINCORE_INCORE
;
844 if (pqueryinfo
& VM_PAGE_QUERY_PAGE_REF
)
845 mincoreinfo
|= MINCORE_REFERENCED
;
846 if (pqueryinfo
& VM_PAGE_QUERY_PAGE_DIRTY
)
847 mincoreinfo
|= MINCORE_MODIFIED
;
851 * calculate index into user supplied byte vector
853 vecindex
= (addr
- first_addr
)>> PAGE_SHIFT
;
856 * If we have skipped map entries, we need to make sure that
857 * the byte vector is zeroed for those skipped entries.
859 while((lastvecindex
+ 1) < vecindex
) {
860 error
= subyte( vec
+ lastvecindex
, 0);
868 * Pass the page information to the user
870 error
= subyte( vec
+ vecindex
, mincoreinfo
);
874 lastvecindex
= vecindex
;
879 * Zero the last entries in the byte vector.
881 vecindex
= (end
- first_addr
) >> PAGE_SHIFT
;
882 while((lastvecindex
+ 1) < vecindex
) {
883 error
= subyte( vec
+ lastvecindex
, 0);
899 mlock(p
, uap
, retval
)
901 struct mlock_args
*uap
;
906 vm_size_t size
, pageoff
;
908 kern_return_t result
;
910 addr
= (vm_offset_t
) uap
->addr
;
913 pageoff
= (addr
& PAGE_MASK
);
916 size
= (vm_size_t
) round_page(size
);
918 /* disable wrap around */
919 if (addr
+ size
< addr
)
922 /* Hmm.. What am I going to do with this? */
923 if (atop(size
) + cnt
.v_wire_count
> vm_page_max_wired
)
925 #ifdef pmap_wired_count
926 if (size
+ ptoa(pmap_wired_count(vm_map_pmap(&p
->p_vmspace
->vm_map
))) >
927 p
->p_rlimit
[RLIMIT_MEMLOCK
].rlim_cur
)
930 error
= suser(p
->p_ucred
, &p
->p_acflag
);
936 user_map
= current_map();
939 result
= vm_map_wire(user_map
, addr
, (vm_offset_t
)(addr
+size
), VM_PROT_NONE
, TRUE
);
940 return (result
== KERN_SUCCESS
? 0 : ENOMEM
);
943 struct munlock_args
{
948 munlock(p
, uap
, retval
)
950 struct munlock_args
*uap
;
954 vm_size_t size
, pageoff
;
957 kern_return_t result
;
959 addr
= (vm_offset_t
) uap
->addr
;
962 pageoff
= (addr
& PAGE_MASK
);
965 size
= (vm_size_t
) round_page(size
);
967 /* disable wrap around */
968 if (addr
+ size
< addr
)
972 /* Hmm.. What am I going to do with this? */
973 #ifndef pmap_wired_count
974 error
= suser(p
->p_ucred
, &p
->p_acflag
);
980 user_map
= current_map();
983 result
= vm_wire(host_priv_self(), user_map
, addr
, size
, VM_PROT_NONE
);
984 return (result
== KERN_SUCCESS
? 0 : ENOMEM
);
988 struct mlockall_args
{
995 struct mlockall_args
*uap
;
1000 struct munlockall_args
{
1007 struct munlockall_args
*uap
;
1014 struct obreak_args
{
1017 obreak(p
, uap
, retval
)
1019 struct obreak_args
*uap
;
1022 /* Not implemented, obsolete */
1037 int print_map_addr
=0;
1040 /* CDY need to fix interface to allow user to map above 32 bits */
1041 kern_return_t
map_fd(
1045 boolean_t findspace
,
1049 boolean_t funnel_state
;
1051 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1053 ret
= map_fd_funneled( fd
, (vm_object_offset_t
)offset
,
1054 va
, findspace
, size
);
1056 (void) thread_funnel_set(kernel_flock
, FALSE
);
1061 kern_return_t
map_fd_funneled(
1063 vm_object_offset_t offset
,
1065 boolean_t findspace
,
1068 kern_return_t result
;
1072 vm_offset_t map_addr
=0;
1077 struct proc
*p
=(struct proc
*)current_proc();
1079 extern int print_map_addr
;
1083 * Find the inode; verify that it's a regular file.
1086 err
= fdgetf(p
, fd
, &fp
);
1090 if (fp
->f_type
!= DTYPE_VNODE
)
1091 return(KERN_INVALID_ARGUMENT
);
1093 if (!(fp
->f_flag
& FREAD
))
1094 return (KERN_PROTECTION_FAILURE
);
1096 vp
= (struct vnode
*)fp
->f_data
;
1098 if (vp
->v_type
!= VREG
)
1099 return (KERN_INVALID_ARGUMENT
);
1101 if (offset
& PAGE_MASK_64
) {
1102 printf("map_fd: file offset not page aligned(%d : %s)\n",p
->p_pid
, p
->p_comm
);
1103 return (KERN_INVALID_ARGUMENT
);
1105 map_size
= round_page(size
);
1108 * Allow user to map in a zero length file.
1111 return (KERN_SUCCESS
);
1115 UBCINFOCHECK("map_fd_funneled", vp
);
1116 pager
= (void *) ubc_getpager(vp
);
1118 return (KERN_FAILURE
);
1121 my_map
= current_map();
1125 &map_addr
, map_size
, (vm_offset_t
)0, TRUE
,
1126 pager
, offset
, TRUE
,
1127 VM_PROT_DEFAULT
, VM_PROT_ALL
,
1128 VM_INHERIT_DEFAULT
);
1129 if (result
!= KERN_SUCCESS
)
1134 vm_offset_t dst_addr
;
1137 if (copyin(va
, &dst_addr
, sizeof (dst_addr
)) ||
1138 trunc_page(dst_addr
) != dst_addr
) {
1139 (void) vm_map_remove(
1141 map_addr
, map_addr
+ map_size
,
1143 return (KERN_INVALID_ADDRESS
);
1146 result
= vm_map_copyin(
1148 map_addr
, map_size
, TRUE
,
1150 if (result
!= KERN_SUCCESS
) {
1152 (void) vm_map_remove(
1154 map_addr
, map_addr
+ map_size
,
1159 result
= vm_map_copy_overwrite(
1161 dst_addr
, tmp
, FALSE
);
1162 if (result
!= KERN_SUCCESS
) {
1163 vm_map_copy_discard(tmp
);
1167 if (copyout(&map_addr
, va
, sizeof (map_addr
))) {
1168 (void) vm_map_remove(
1170 map_addr
, map_addr
+ map_size
,
1172 return (KERN_INVALID_ADDRESS
);
1176 ubc_setcred(vp
, current_proc());
1179 return (KERN_SUCCESS
);