2 * linux/arch/s390/mm/mmap.c
4 * flexible mmap layout support
6 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Started by Ingo Molnar <mingo@elte.hu>
27 #include <linux/personality.h>
29 #include <linux/module.h>
30 #include <asm/pgalloc.h>
31 #include <asm/compat.h>
33 static unsigned long stack_maxrandom_size(void)
35 if (!(current->flags & PF_RANDOMIZE))
37 if (current->personality & ADDR_NO_RANDOMIZE)
39 return STACK_RND_MASK << PAGE_SHIFT;
43 * Top of mmap area (just below the process stack).
45 * Leave at least a ~32 MB hole.
47 #define MIN_GAP (32*1024*1024)
48 #define MAX_GAP (STACK_TOP/6*5)
50 static inline unsigned long mmap_base(void)
52 unsigned long gap = rlimit(RLIMIT_STACK);
56 else if (gap > MAX_GAP)
59 return STACK_TOP - stack_maxrandom_size() - (gap & PAGE_MASK);
62 static inline int mmap_is_legacy(void)
66 * Force standard allocation for 64 bit programs.
68 if (!is_compat_task())
71 return sysctl_legacy_va_layout ||
72 (current->personality & ADDR_COMPAT_LAYOUT) ||
73 rlimit(RLIMIT_STACK) == RLIM_INFINITY;
79 * This function, called very early during the creation of a new
80 * process VM image, sets up which VM layout function to use:
82 void arch_pick_mmap_layout(struct mm_struct *mm)
85 * Fall back to the standard layout if the personality
86 * bit is set, or if the expected stack growth is unlimited:
88 if (mmap_is_legacy()) {
89 mm->mmap_base = TASK_UNMAPPED_BASE;
90 mm->get_unmapped_area = arch_get_unmapped_area;
91 mm->unmap_area = arch_unmap_area;
93 mm->mmap_base = mmap_base();
94 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
95 mm->unmap_area = arch_unmap_area_topdown;
98 EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);
102 int s390_mmap_check(unsigned long addr, unsigned long len)
104 if (!is_compat_task() &&
105 len >= TASK_SIZE && TASK_SIZE < (1UL << 53))
106 return crst_table_upgrade(current->mm, 1UL << 53);
111 s390_get_unmapped_area(struct file *filp, unsigned long addr,
112 unsigned long len, unsigned long pgoff, unsigned long flags)
114 struct mm_struct *mm = current->mm;
118 area = arch_get_unmapped_area(filp, addr, len, pgoff, flags);
119 if (!(area & ~PAGE_MASK))
121 if (area == -ENOMEM && !is_compat_task() && TASK_SIZE < (1UL << 53)) {
122 /* Upgrade the page table to 4 levels and retry. */
123 rc = crst_table_upgrade(mm, 1UL << 53);
125 return (unsigned long) rc;
126 area = arch_get_unmapped_area(filp, addr, len, pgoff, flags);
132 s390_get_unmapped_area_topdown(struct file *filp, const unsigned long addr,
133 const unsigned long len, const unsigned long pgoff,
134 const unsigned long flags)
136 struct mm_struct *mm = current->mm;
140 area = arch_get_unmapped_area_topdown(filp, addr, len, pgoff, flags);
141 if (!(area & ~PAGE_MASK))
143 if (area == -ENOMEM && !is_compat_task() && TASK_SIZE < (1UL << 53)) {
144 /* Upgrade the page table to 4 levels and retry. */
145 rc = crst_table_upgrade(mm, 1UL << 53);
147 return (unsigned long) rc;
148 area = arch_get_unmapped_area_topdown(filp, addr, len,
154 * This function, called very early during the creation of a new
155 * process VM image, sets up which VM layout function to use:
157 void arch_pick_mmap_layout(struct mm_struct *mm)
160 * Fall back to the standard layout if the personality
161 * bit is set, or if the expected stack growth is unlimited:
163 if (mmap_is_legacy()) {
164 mm->mmap_base = TASK_UNMAPPED_BASE;
165 mm->get_unmapped_area = s390_get_unmapped_area;
166 mm->unmap_area = arch_unmap_area;
168 mm->mmap_base = mmap_base();
169 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
170 mm->unmap_area = arch_unmap_area_topdown;
173 EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);