vm_mmap.c (91406) | vm_mmap.c (92029) |
---|---|
1/* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. --- 24 unchanged lines hidden (view full) --- 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 36 * SUCH DAMAGE. 37 * 38 * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$ 39 * 40 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 | 1/* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. --- 24 unchanged lines hidden (view full) --- 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 36 * SUCH DAMAGE. 37 * 38 * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$ 39 * 40 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 |
41 * $FreeBSD: head/sys/vm/vm_mmap.c 91406 2002-02-27 18:32:23Z jhb $ | 41 * $FreeBSD: head/sys/vm/vm_mmap.c 92029 2002-03-10 21:52:48Z eivind $ |
42 */ 43 44/* 45 * Mapped file (mmap) interface to VM 46 */ 47 48#include "opt_compat.h" 49 --- 38 unchanged lines hidden (view full) --- 88/* 89 * Set the maximum number of vm_map_entry structures per process. Roughly 90 * speaking vm_map_entry structures are tiny, so allowing them to eat 1/100 91 * of our KVM malloc space still results in generous limits. We want a 92 * default that is good enough to prevent the kernel running out of resources 93 * if attacked from compromised user account but generous enough such that 94 * multi-threaded processes are not unduly inconvenienced. 95 */ | 42 */ 43 44/* 45 * Mapped file (mmap) interface to VM 46 */ 47 48#include "opt_compat.h" 49 --- 38 unchanged lines hidden (view full) --- 88/* 89 * Set the maximum number of vm_map_entry structures per process. Roughly 90 * speaking vm_map_entry structures are tiny, so allowing them to eat 1/100 91 * of our KVM malloc space still results in generous limits. We want a 92 * default that is good enough to prevent the kernel running out of resources 93 * if attacked from compromised user account but generous enough such that 94 * multi-threaded processes are not unduly inconvenienced. 95 */ |
96 | |
97static void vmmapentry_rsrc_init __P((void *)); 98SYSINIT(vmmersrc, SI_SUB_KVM_RSRC, SI_ORDER_FIRST, vmmapentry_rsrc_init, NULL) 99 100static void 101vmmapentry_rsrc_init(dummy) 102 void *dummy; 103{ 104 max_proc_mmap = vm_kmem_size / sizeof(struct vm_map_entry); --- 270 unchanged lines hidden (view full) --- 375 * If we are sharing potential changes (either via 376 * MAP_SHARED or via the implicit sharing of character 377 * device mappings), and we are trying to get write 378 * permission although we opened it without asking 379 * for it, bail out. Check for superuser, only if 380 * we're at securelevel < 1, to allow the XIG X server 381 * to continue to work. 382 */ | 96static void vmmapentry_rsrc_init __P((void *)); 97SYSINIT(vmmersrc, SI_SUB_KVM_RSRC, SI_ORDER_FIRST, vmmapentry_rsrc_init, NULL) 98 99static void 100vmmapentry_rsrc_init(dummy) 101 void *dummy; 102{ 103 max_proc_mmap = vm_kmem_size / sizeof(struct vm_map_entry); --- 270 unchanged lines hidden (view full) --- 374 * If we are sharing potential changes (either via 375 * MAP_SHARED or via the implicit sharing of character 376 * device mappings), and we are trying to get write 377 * permission although we opened it without asking 378 * for it, bail out. Check for superuser, only if 379 * we're at securelevel < 1, to allow the XIG X server 380 * to continue to work. 381 */ |
383 | |
384 if ((flags & MAP_SHARED) != 0 || 385 (vp->v_type == VCHR && disablexworkaround)) { 386 if ((fp->f_flag & FWRITE) != 0) { 387 struct vattr va; 388 if ((error = 389 VOP_GETATTR(vp, &va, 390 td->td_ucred, td))) { 391 goto done; --- 120 unchanged lines hidden (view full) --- 512 size = uap->len; 513 flags = uap->flags; 514 515 pageoff = (addr & PAGE_MASK); 516 addr -= pageoff; 517 size += pageoff; 518 size = (vm_size_t) round_page(size); 519 if (addr + size < addr) | 382 if ((flags & MAP_SHARED) != 0 || 383 (vp->v_type == VCHR && disablexworkaround)) { 384 if ((fp->f_flag & FWRITE) != 0) { 385 struct vattr va; 386 if ((error = 387 VOP_GETATTR(vp, &va, 388 td->td_ucred, td))) { 389 goto done; --- 120 unchanged lines hidden (view full) --- 510 size = uap->len; 511 flags = uap->flags; 512 513 pageoff = (addr & PAGE_MASK); 514 addr -= pageoff; 515 size += pageoff; 516 size = (vm_size_t) round_page(size); 517 if (addr + size < addr) |
520 return(EINVAL); | 518 return (EINVAL); |
521 522 if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE)) 523 return (EINVAL); 524 525 mtx_lock(&Giant); 526 527 map = &td->td_proc->p_vmspace->vm_map; 528 --- 24 unchanged lines hidden (view full) --- 553 rv = vm_map_clean(map, addr, addr + size, (flags & MS_ASYNC) == 0, 554 (flags & MS_INVALIDATE) != 0); 555 556done2: 557 mtx_unlock(&Giant); 558 559 switch (rv) { 560 case KERN_SUCCESS: | 519 520 if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE)) 521 return (EINVAL); 522 523 mtx_lock(&Giant); 524 525 map = &td->td_proc->p_vmspace->vm_map; 526 --- 24 unchanged lines hidden (view full) --- 551 rv = vm_map_clean(map, addr, addr + size, (flags & MS_ASYNC) == 0, 552 (flags & MS_INVALIDATE) != 0); 553 554done2: 555 mtx_unlock(&Giant); 556 557 switch (rv) { 558 case KERN_SUCCESS: |
561 return(0); | 559 return (0); |
562 case KERN_INVALID_ADDRESS: 563 return (EINVAL); /* Sun returns ENOMEM? */ 564 case KERN_FAILURE: 565 return (EIO); 566 default: 567 return (EINVAL); 568 } 569} --- 19 unchanged lines hidden (view full) --- 589 addr = (vm_offset_t) uap->addr; 590 size = uap->len; 591 592 pageoff = (addr & PAGE_MASK); 593 addr -= pageoff; 594 size += pageoff; 595 size = (vm_size_t) round_page(size); 596 if (addr + size < addr) | 560 case KERN_INVALID_ADDRESS: 561 return (EINVAL); /* Sun returns ENOMEM? */ 562 case KERN_FAILURE: 563 return (EIO); 564 default: 565 return (EINVAL); 566 } 567} --- 19 unchanged lines hidden (view full) --- 587 addr = (vm_offset_t) uap->addr; 588 size = uap->len; 589 590 pageoff = (addr & PAGE_MASK); 591 addr -= pageoff; 592 size += pageoff; 593 size = (vm_size_t) round_page(size); 594 if (addr + size < addr) |
597 return(EINVAL); | 595 return (EINVAL); |
598 599 if (size == 0) 600 return (0); 601 602 /* 603 * Check for illegal addresses. Watch out for address wrap... Note 604 * that VM_*_ADDRESS are not constants due to casts (argh). 605 */ --- 61 unchanged lines hidden (view full) --- 667 prot |= VM_PROT_EXECUTE; 668#endif 669 670 pageoff = (addr & PAGE_MASK); 671 addr -= pageoff; 672 size += pageoff; 673 size = (vm_size_t) round_page(size); 674 if (addr + size < addr) | 596 597 if (size == 0) 598 return (0); 599 600 /* 601 * Check for illegal addresses. Watch out for address wrap... Note 602 * that VM_*_ADDRESS are not constants due to casts (argh). 603 */ --- 61 unchanged lines hidden (view full) --- 665 prot |= VM_PROT_EXECUTE; 666#endif 667 668 pageoff = (addr & PAGE_MASK); 669 addr -= pageoff; 670 size += pageoff; 671 size = (vm_size_t) round_page(size); 672 if (addr + size < addr) |
675 return(EINVAL); | 673 return (EINVAL); |
676 677 mtx_lock(&Giant); 678 ret = vm_map_protect(&td->td_proc->p_vmspace->vm_map, addr, 679 addr + size, prot, FALSE); 680 mtx_unlock(&Giant); 681 switch (ret) { 682 case KERN_SUCCESS: 683 return (0); --- 27 unchanged lines hidden (view full) --- 711 size = uap->len; 712 inherit = uap->inherit; 713 714 pageoff = (addr & PAGE_MASK); 715 addr -= pageoff; 716 size += pageoff; 717 size = (vm_size_t) round_page(size); 718 if (addr + size < addr) | 674 675 mtx_lock(&Giant); 676 ret = vm_map_protect(&td->td_proc->p_vmspace->vm_map, addr, 677 addr + size, prot, FALSE); 678 mtx_unlock(&Giant); 679 switch (ret) { 680 case KERN_SUCCESS: 681 return (0); --- 27 unchanged lines hidden (view full) --- 709 size = uap->len; 710 inherit = uap->inherit; 711 712 pageoff = (addr & PAGE_MASK); 713 addr -= pageoff; 714 size += pageoff; 715 size = (vm_size_t) round_page(size); 716 if (addr + size < addr) |
719 return(EINVAL); | 717 return (EINVAL); |
720 721 mtx_lock(&Giant); 722 ret = vm_map_inherit(&td->td_proc->p_vmspace->vm_map, addr, addr+size, 723 inherit); 724 mtx_unlock(&Giant); 725 726 switch (ret) { 727 case KERN_SUCCESS: --- 188 unchanged lines hidden (view full) --- 916 */ 917 vecindex = OFF_TO_IDX(addr - first_addr); 918 919 /* 920 * If we have skipped map entries, we need to make sure that 921 * the byte vector is zeroed for those skipped entries. 922 */ 923 while ((lastvecindex + 1) < vecindex) { | 718 719 mtx_lock(&Giant); 720 ret = vm_map_inherit(&td->td_proc->p_vmspace->vm_map, addr, addr+size, 721 inherit); 722 mtx_unlock(&Giant); 723 724 switch (ret) { 725 case KERN_SUCCESS: --- 188 unchanged lines hidden (view full) --- 914 */ 915 vecindex = OFF_TO_IDX(addr - first_addr); 916 917 /* 918 * If we have skipped map entries, we need to make sure that 919 * the byte vector is zeroed for those skipped entries. 920 */ 921 while ((lastvecindex + 1) < vecindex) { |
924 error = subyte( vec + lastvecindex, 0); | 922 error = subyte(vec + lastvecindex, 0); |
925 if (error) { 926 error = EFAULT; 927 goto done2; 928 } 929 ++lastvecindex; 930 } 931 932 /* 933 * Pass the page information to the user 934 */ | 923 if (error) { 924 error = EFAULT; 925 goto done2; 926 } 927 ++lastvecindex; 928 } 929 930 /* 931 * Pass the page information to the user 932 */ |
935 error = subyte( vec + vecindex, mincoreinfo); | 933 error = subyte(vec + vecindex, mincoreinfo); |
936 if (error) { 937 error = EFAULT; 938 goto done2; 939 } 940 941 /* 942 * If the map has changed, due to the subyte, the previous 943 * output may be invalid. --- 13 unchanged lines hidden (view full) --- 957 */ 958 vm_map_unlock_read(map); 959 960 /* 961 * Zero the last entries in the byte vector. 962 */ 963 vecindex = OFF_TO_IDX(end - first_addr); 964 while ((lastvecindex + 1) < vecindex) { | 934 if (error) { 935 error = EFAULT; 936 goto done2; 937 } 938 939 /* 940 * If the map has changed, due to the subyte, the previous 941 * output may be invalid. --- 13 unchanged lines hidden (view full) --- 955 */ 956 vm_map_unlock_read(map); 957 958 /* 959 * Zero the last entries in the byte vector. 960 */ 961 vecindex = OFF_TO_IDX(end - first_addr); 962 while ((lastvecindex + 1) < vecindex) { |
965 error = subyte( vec + lastvecindex, 0); | 963 error = subyte(vec + lastvecindex, 0); |
966 if (error) { 967 error = EFAULT; 968 goto done2; 969 } 970 ++lastvecindex; 971 } 972 973 /* --- 304 unchanged lines hidden --- | 964 if (error) { 965 error = EFAULT; 966 goto done2; 967 } 968 ++lastvecindex; 969 } 970 971 /* --- 304 unchanged lines hidden --- |