/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*13* Taken from the i386 architecture and simplified.14*/1516#include <linux/mm.h>17#include <linux/random.h>18#include <linux/limits.h>19#include <linux/sched.h>20#include <linux/mman.h>21#include <linux/compat.h>2223/*24* Top of mmap area (just below the process stack).25*26* Leave an at least ~128 MB hole.27*/28#define MIN_GAP (128*1024*1024)29#define MAX_GAP (TASK_SIZE/6*5)3031static inline unsigned long mmap_base(struct mm_struct *mm)32{33unsigned long gap = rlimit(RLIMIT_STACK);34unsigned long random_factor = 0;3536if (current->flags & PF_RANDOMIZE)37random_factor = get_random_int() % (1024*1024);3839if (gap < MIN_GAP)40gap = MIN_GAP;41else if (gap > MAX_GAP)42gap = MAX_GAP;4344return PAGE_ALIGN(TASK_SIZE - gap - random_factor);45}4647/*48* This function, called very early during the creation of a new49* process VM image, sets up which VM layout function to use:50*/51void arch_pick_mmap_layout(struct mm_struct *mm)52{53#if !defined(__tilegx__)54int is_32bit = 1;55#elif defined(CONFIG_COMPAT)56int is_32bit = is_compat_task();57#else58int is_32bit = 0;59#endif6061/*62* Use standard layout if the expected stack growth is unlimited63* or we are running native 64 bits.64*/65if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {66mm->mmap_base = TASK_UNMAPPED_BASE;67mm->get_unmapped_area = arch_get_unmapped_area;68mm->unmap_area = arch_unmap_area;69} else {70mm->mmap_base = mmap_base(mm);71mm->get_unmapped_area = arch_get_unmapped_area_topdown;72mm->unmap_area = arch_unmap_area_topdown;73}74}757677