aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/ia32/ia32_aout.c20
-rw-r--r--fs/binfmt_aout.c20
-rw-r--r--fs/binfmt_elf.c15
-rw-r--r--include/linux/mm.h3
-rw-r--r--mm/mmap.c16
-rw-r--r--mm/nommu.c2
6 files changed, 31 insertions, 45 deletions
diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index d511d951a052..b6817ee9033f 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -119,9 +119,7 @@ static void set_brk(unsigned long start, unsigned long end)
119 end = PAGE_ALIGN(end); 119 end = PAGE_ALIGN(end);
120 if (end <= start) 120 if (end <= start)
121 return; 121 return;
122 down_write(&current->mm->mmap_sem); 122 vm_brk(start, end - start);
123 do_brk(start, end - start);
124 up_write(&current->mm->mmap_sem);
125} 123}
126 124
127#ifdef CORE_DUMP 125#ifdef CORE_DUMP
@@ -332,9 +330,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
332 pos = 32; 330 pos = 32;
333 map_size = ex.a_text+ex.a_data; 331 map_size = ex.a_text+ex.a_data;
334 332
335 down_write(&current->mm->mmap_sem); 333 error = vm_brk(text_addr & PAGE_MASK, map_size);
336 error = do_brk(text_addr & PAGE_MASK, map_size);
337 up_write(&current->mm->mmap_sem);
338 334
339 if (error != (text_addr & PAGE_MASK)) { 335 if (error != (text_addr & PAGE_MASK)) {
340 send_sig(SIGKILL, current, 0); 336 send_sig(SIGKILL, current, 0);
@@ -373,9 +369,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
373 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) { 369 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
374 loff_t pos = fd_offset; 370 loff_t pos = fd_offset;
375 371
376 down_write(&current->mm->mmap_sem); 372 vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
377 do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
378 up_write(&current->mm->mmap_sem);
379 bprm->file->f_op->read(bprm->file, 373 bprm->file->f_op->read(bprm->file,
380 (char __user *)N_TXTADDR(ex), 374 (char __user *)N_TXTADDR(ex),
381 ex.a_text+ex.a_data, &pos); 375 ex.a_text+ex.a_data, &pos);
@@ -476,9 +470,7 @@ static int load_aout_library(struct file *file)
476 error_time = jiffies; 470 error_time = jiffies;
477 } 471 }
478#endif 472#endif
479 down_write(&current->mm->mmap_sem); 473 vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
480 do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
481 up_write(&current->mm->mmap_sem);
482 474
483 file->f_op->read(file, (char __user *)start_addr, 475 file->f_op->read(file, (char __user *)start_addr,
484 ex.a_text + ex.a_data, &pos); 476 ex.a_text + ex.a_data, &pos);
@@ -503,9 +495,7 @@ static int load_aout_library(struct file *file)
503 len = PAGE_ALIGN(ex.a_text + ex.a_data); 495 len = PAGE_ALIGN(ex.a_text + ex.a_data);
504 bss = ex.a_text + ex.a_data + ex.a_bss; 496 bss = ex.a_text + ex.a_data + ex.a_bss;
505 if (bss > len) { 497 if (bss > len) {
506 down_write(&current->mm->mmap_sem); 498 error = vm_brk(start_addr + len, bss - len);
507 error = do_brk(start_addr + len, bss - len);
508 up_write(&current->mm->mmap_sem);
509 retval = error; 499 retval = error;
510 if (error != start_addr + len) 500 if (error != start_addr + len)
511 goto out; 501 goto out;
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 2eb12f13593d..88527492b917 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -50,9 +50,7 @@ static int set_brk(unsigned long start, unsigned long end)
50 end = PAGE_ALIGN(end); 50 end = PAGE_ALIGN(end);
51 if (end > start) { 51 if (end > start) {
52 unsigned long addr; 52 unsigned long addr;
53 down_write(&current->mm->mmap_sem); 53 addr = vm_brk(start, end - start);
54 addr = do_brk(start, end - start);
55 up_write(&current->mm->mmap_sem);
56 if (BAD_ADDR(addr)) 54 if (BAD_ADDR(addr))
57 return addr; 55 return addr;
58 } 56 }
@@ -280,9 +278,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
280 pos = 32; 278 pos = 32;
281 map_size = ex.a_text+ex.a_data; 279 map_size = ex.a_text+ex.a_data;
282#endif 280#endif
283 down_write(&current->mm->mmap_sem); 281 error = vm_brk(text_addr & PAGE_MASK, map_size);
284 error = do_brk(text_addr & PAGE_MASK, map_size);
285 up_write(&current->mm->mmap_sem);
286 if (error != (text_addr & PAGE_MASK)) { 282 if (error != (text_addr & PAGE_MASK)) {
287 send_sig(SIGKILL, current, 0); 283 send_sig(SIGKILL, current, 0);
288 return error; 284 return error;
@@ -313,9 +309,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
313 309
314 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { 310 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
315 loff_t pos = fd_offset; 311 loff_t pos = fd_offset;
316 down_write(&current->mm->mmap_sem); 312 vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
317 do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
318 up_write(&current->mm->mmap_sem);
319 bprm->file->f_op->read(bprm->file, 313 bprm->file->f_op->read(bprm->file,
320 (char __user *)N_TXTADDR(ex), 314 (char __user *)N_TXTADDR(ex),
321 ex.a_text+ex.a_data, &pos); 315 ex.a_text+ex.a_data, &pos);
@@ -412,9 +406,7 @@ static int load_aout_library(struct file *file)
412 "N_TXTOFF is not page aligned. Please convert library: %s\n", 406 "N_TXTOFF is not page aligned. Please convert library: %s\n",
413 file->f_path.dentry->d_name.name); 407 file->f_path.dentry->d_name.name);
414 } 408 }
415 down_write(&current->mm->mmap_sem); 409 vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
416 do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
417 up_write(&current->mm->mmap_sem);
418 410
419 file->f_op->read(file, (char __user *)start_addr, 411 file->f_op->read(file, (char __user *)start_addr,
420 ex.a_text + ex.a_data, &pos); 412 ex.a_text + ex.a_data, &pos);
@@ -438,9 +430,7 @@ static int load_aout_library(struct file *file)
438 len = PAGE_ALIGN(ex.a_text + ex.a_data); 430 len = PAGE_ALIGN(ex.a_text + ex.a_data);
439 bss = ex.a_text + ex.a_data + ex.a_bss; 431 bss = ex.a_text + ex.a_data + ex.a_bss;
440 if (bss > len) { 432 if (bss > len) {
441 down_write(&current->mm->mmap_sem); 433 error = vm_brk(start_addr + len, bss - len);
442 error = do_brk(start_addr + len, bss - len);
443 up_write(&current->mm->mmap_sem);
444 retval = error; 434 retval = error;
445 if (error != start_addr + len) 435 if (error != start_addr + len)
446 goto out; 436 goto out;
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 48ffb3dc610a..0708a0bf0ba9 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -82,9 +82,7 @@ static int set_brk(unsigned long start, unsigned long end)
82 end = ELF_PAGEALIGN(end); 82 end = ELF_PAGEALIGN(end);
83 if (end > start) { 83 if (end > start) {
84 unsigned long addr; 84 unsigned long addr;
85 down_write(&current->mm->mmap_sem); 85 addr = vm_brk(start, end - start);
86 addr = do_brk(start, end - start);
87 up_write(&current->mm->mmap_sem);
88 if (BAD_ADDR(addr)) 86 if (BAD_ADDR(addr))
89 return addr; 87 return addr;
90 } 88 }
@@ -514,9 +512,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
514 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1); 512 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
515 513
516 /* Map the last of the bss segment */ 514 /* Map the last of the bss segment */
517 down_write(&current->mm->mmap_sem); 515 error = vm_brk(elf_bss, last_bss - elf_bss);
518 error = do_brk(elf_bss, last_bss - elf_bss);
519 up_write(&current->mm->mmap_sem);
520 if (BAD_ADDR(error)) 516 if (BAD_ADDR(error))
521 goto out_close; 517 goto out_close;
522 } 518 }
@@ -1072,11 +1068,8 @@ static int load_elf_library(struct file *file)
1072 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr + 1068 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
1073 ELF_MIN_ALIGN - 1); 1069 ELF_MIN_ALIGN - 1);
1074 bss = eppnt->p_memsz + eppnt->p_vaddr; 1070 bss = eppnt->p_memsz + eppnt->p_vaddr;
1075 if (bss > len) { 1071 if (bss > len)
1076 down_write(&current->mm->mmap_sem); 1072 vm_brk(len, bss - len);
1077 do_brk(len, bss - len);
1078 up_write(&current->mm->mmap_sem);
1079 }
1080 error = 0; 1073 error = 0;
1081 1074
1082out_free_ph: 1075out_free_ph:
diff --git a/include/linux/mm.h b/include/linux/mm.h
index d8738a464b94..bfee4ad6680b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1415,7 +1415,8 @@ out:
1415 1415
1416extern int do_munmap(struct mm_struct *, unsigned long, size_t); 1416extern int do_munmap(struct mm_struct *, unsigned long, size_t);
1417 1417
1418extern unsigned long do_brk(unsigned long, unsigned long); 1418/* These take the mm semaphore themselves */
1419extern unsigned long vm_brk(unsigned long, unsigned long);
1419 1420
1420/* truncate.c */ 1421/* truncate.c */
1421extern void truncate_inode_pages(struct address_space *, loff_t); 1422extern void truncate_inode_pages(struct address_space *, loff_t);
diff --git a/mm/mmap.c b/mm/mmap.c
index a7bf6a31c9f6..df51891c8646 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -240,6 +240,8 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
240 return next; 240 return next;
241} 241}
242 242
243static unsigned long do_brk(unsigned long addr, unsigned long len);
244
243SYSCALL_DEFINE1(brk, unsigned long, brk) 245SYSCALL_DEFINE1(brk, unsigned long, brk)
244{ 246{
245 unsigned long rlim, retval; 247 unsigned long rlim, retval;
@@ -2136,7 +2138,7 @@ static inline void verify_mm_writelocked(struct mm_struct *mm)
2136 * anonymous maps. eventually we may be able to do some 2138 * anonymous maps. eventually we may be able to do some
2137 * brk-specific accounting here. 2139 * brk-specific accounting here.
2138 */ 2140 */
2139unsigned long do_brk(unsigned long addr, unsigned long len) 2141static unsigned long do_brk(unsigned long addr, unsigned long len)
2140{ 2142{
2141 struct mm_struct * mm = current->mm; 2143 struct mm_struct * mm = current->mm;
2142 struct vm_area_struct * vma, * prev; 2144 struct vm_area_struct * vma, * prev;
@@ -2232,7 +2234,17 @@ out:
2232 return addr; 2234 return addr;
2233} 2235}
2234 2236
2235EXPORT_SYMBOL(do_brk); 2237unsigned long vm_brk(unsigned long addr, unsigned long len)
2238{
2239 struct mm_struct *mm = current->mm;
2240 unsigned long ret;
2241
2242 down_write(&mm->mmap_sem);
2243 ret = do_brk(addr, len);
2244 up_write(&mm->mmap_sem);
2245 return ret;
2246}
2247EXPORT_SYMBOL(vm_brk);
2236 2248
2237/* Release all mmaps. */ 2249/* Release all mmaps. */
2238void exit_mmap(struct mm_struct *mm) 2250void exit_mmap(struct mm_struct *mm)
diff --git a/mm/nommu.c b/mm/nommu.c
index f59e170fceb4..634193324a6b 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1744,7 +1744,7 @@ void exit_mmap(struct mm_struct *mm)
1744 kleave(""); 1744 kleave("");
1745} 1745}
1746 1746
1747unsigned long do_brk(unsigned long addr, unsigned long len) 1747unsigned long vm_brk(unsigned long addr, unsigned long len)
1748{ 1748{
1749 return -ENOMEM; 1749 return -ENOMEM;
1750} 1750}