mmap.c 893 B

123456789101112131415161718192021222324252627282930
  1. /* Copyright 2005 Andi Kleen, SuSE Labs.
  2. * Licensed under GPL, v.2
  3. */
  4. #include <linux/config.h>
  5. #include <linux/mm.h>
  6. #include <linux/sched.h>
  7. #include <linux/random.h>
  8. #include <asm/ia32.h>
  9. /* Notebook: move the mmap code from sys_x86_64.c over here. */
  10. void arch_pick_mmap_layout(struct mm_struct *mm)
  11. {
  12. #ifdef CONFIG_IA32_EMULATION
  13. if (current_thread_info()->flags & _TIF_IA32)
  14. return ia32_pick_mmap_layout(mm);
  15. #endif
  16. mm->mmap_base = TASK_UNMAPPED_BASE;
  17. if (current->flags & PF_RANDOMIZE) {
  18. /* Add 28bit randomness which is about 40bits of address space
  19. because mmap base has to be page aligned.
  20. or ~1/128 of the total user VM
  21. (total user address space is 47bits) */
  22. unsigned rnd = get_random_int() & 0xfffffff;
  23. mm->mmap_base += ((unsigned long)rnd) << PAGE_SHIFT;
  24. }
  25. mm->get_unmapped_area = arch_get_unmapped_area;
  26. mm->unmap_area = arch_unmap_area;
  27. }