1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include <linux/mm.h>
- #include <linux/random.h>
- #include <linux/limits.h>
- #include <linux/sched.h>
- #include <linux/mman.h>
- #include <linux/compat.h>
- #define MIN_GAP (128*1024*1024)
- #define MAX_GAP (TASK_SIZE/6*5)
- static inline unsigned long mmap_base(struct mm_struct *mm)
- {
- unsigned long gap = rlimit(RLIMIT_STACK);
- unsigned long random_factor = 0;
- if (current->flags & PF_RANDOMIZE)
- random_factor = get_random_int() % (1024*1024);
- if (gap < MIN_GAP)
- gap = MIN_GAP;
- else if (gap > MAX_GAP)
- gap = MAX_GAP;
- return PAGE_ALIGN(TASK_SIZE - gap - random_factor);
- }
- void arch_pick_mmap_layout(struct mm_struct *mm)
- {
- #if !defined(__tilegx__)
- int is_32bit = 1;
- #elif defined(CONFIG_COMPAT)
- int is_32bit = is_compat_task();
- #else
- int is_32bit = 0;
- #endif
- unsigned long random_factor = 0UL;
-
- if (current->flags & PF_RANDOMIZE) {
- if (is_32bit)
- random_factor = get_random_int() % (1<<8);
- else
- random_factor = get_random_int() % (1<<12);
- random_factor <<= PAGE_SHIFT;
- }
-
- if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
- mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
- mm->get_unmapped_area = arch_get_unmapped_area;
- } else {
- mm->mmap_base = mmap_base(mm);
- mm->get_unmapped_area = arch_get_unmapped_area_topdown;
- }
- }
- unsigned long arch_randomize_brk(struct mm_struct *mm)
- {
- return randomize_page(mm->brk, 0x02000000);
- }
|