aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mmap.c
diff options
context:
space:
mode:
authorTony Luck <tony.luck@intel.com>2005-05-17 18:53:14 -0400
committerTony Luck <tony.luck@intel.com>2005-05-17 18:53:14 -0400
commit325a479c4c110db278ef3361460a48c4093252cc (patch)
treebcfbf4d0647d9442045639a5c19da59d55190e81 /mm/mmap.c
parentebcc80c1b6629a445f7471cc1ddb48faf8a84e70 (diff)
parent7f9eaedf894dbaa08c157832e9a6c9c03ffed1ed (diff)
Merge with temp tree to get David's gdb inferior calls patch
Diffstat (limited to 'mm/mmap.c')
-rw-r--r--mm/mmap.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index 6ea204cc751e..01f9793591f6 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -937,9 +937,10 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
937 /* mlock MCL_FUTURE? */ 937 /* mlock MCL_FUTURE? */
938 if (vm_flags & VM_LOCKED) { 938 if (vm_flags & VM_LOCKED) {
939 unsigned long locked, lock_limit; 939 unsigned long locked, lock_limit;
940 locked = mm->locked_vm << PAGE_SHIFT; 940 locked = len >> PAGE_SHIFT;
941 locked += mm->locked_vm;
941 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; 942 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
942 locked += len; 943 lock_limit >>= PAGE_SHIFT;
943 if (locked > lock_limit && !capable(CAP_IPC_LOCK)) 944 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
944 return -EAGAIN; 945 return -EAGAIN;
945 } 946 }
@@ -1009,8 +1010,7 @@ munmap_back:
1009 } 1010 }
1010 1011
1011 /* Check against address space limit. */ 1012 /* Check against address space limit. */
1012 if ((mm->total_vm << PAGE_SHIFT) + len 1013 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
1013 > current->signal->rlim[RLIMIT_AS].rlim_cur)
1014 return -ENOMEM; 1014 return -ENOMEM;
1015 1015
1016 if (accountable && (!(flags & MAP_NORESERVE) || 1016 if (accountable && (!(flags & MAP_NORESERVE) ||
@@ -1421,7 +1421,7 @@ static int acct_stack_growth(struct vm_area_struct * vma, unsigned long size, un
1421 struct rlimit *rlim = current->signal->rlim; 1421 struct rlimit *rlim = current->signal->rlim;
1422 1422
1423 /* address space limit tests */ 1423 /* address space limit tests */
1424 if (mm->total_vm + grow > rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT) 1424 if (!may_expand_vm(mm, grow))
1425 return -ENOMEM; 1425 return -ENOMEM;
1426 1426
1427 /* Stack limit test */ 1427 /* Stack limit test */
@@ -1823,9 +1823,10 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
1823 */ 1823 */
1824 if (mm->def_flags & VM_LOCKED) { 1824 if (mm->def_flags & VM_LOCKED) {
1825 unsigned long locked, lock_limit; 1825 unsigned long locked, lock_limit;
1826 locked = mm->locked_vm << PAGE_SHIFT; 1826 locked = len >> PAGE_SHIFT;
1827 locked += mm->locked_vm;
1827 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; 1828 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
1828 locked += len; 1829 lock_limit >>= PAGE_SHIFT;
1829 if (locked > lock_limit && !capable(CAP_IPC_LOCK)) 1830 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
1830 return -EAGAIN; 1831 return -EAGAIN;
1831 } 1832 }
@@ -1848,8 +1849,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
1848 } 1849 }
1849 1850
1850 /* Check against address space limits *after* clearing old maps... */ 1851 /* Check against address space limits *after* clearing old maps... */
1851 if ((mm->total_vm << PAGE_SHIFT) + len 1852 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
1852 > current->signal->rlim[RLIMIT_AS].rlim_cur)
1853 return -ENOMEM; 1853 return -ENOMEM;
1854 1854
1855 if (mm->map_count > sysctl_max_map_count) 1855 if (mm->map_count > sysctl_max_map_count)
@@ -2019,3 +2019,19 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
2019 } 2019 }
2020 return new_vma; 2020 return new_vma;
2021} 2021}
2022
2023/*
2024 * Return true if the calling process may expand its vm space by the passed
2025 * number of pages
2026 */
2027int may_expand_vm(struct mm_struct *mm, unsigned long npages)
2028{
2029 unsigned long cur = mm->total_vm; /* pages */
2030 unsigned long lim;
2031
2032 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
2033
2034 if (cur + npages > lim)
2035 return 0;
2036 return 1;
2037}