aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/mm/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390/mm/mmap.c')
-rw-r--r--arch/s390/mm/mmap.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index 869efbaed3ea..c9a9f7f18188 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -27,17 +27,44 @@
27#include <linux/personality.h> 27#include <linux/personality.h>
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/random.h>
30#include <asm/pgalloc.h> 31#include <asm/pgalloc.h>
31#include <asm/compat.h> 32#include <asm/compat.h>
32 33
34static unsigned long stack_maxrandom_size(void)
35{
36 if (!(current->flags & PF_RANDOMIZE))
37 return 0;
38 if (current->personality & ADDR_NO_RANDOMIZE)
39 return 0;
40 return STACK_RND_MASK << PAGE_SHIFT;
41}
42
33/* 43/*
34 * Top of mmap area (just below the process stack). 44 * Top of mmap area (just below the process stack).
35 * 45 *
36 * Leave an at least ~128 MB hole. 46 * Leave at least a ~32 MB hole.
37 */ 47 */
38#define MIN_GAP (128*1024*1024) 48#define MIN_GAP (32*1024*1024)
39#define MAX_GAP (STACK_TOP/6*5) 49#define MAX_GAP (STACK_TOP/6*5)
40 50
51static inline int mmap_is_legacy(void)
52{
53 if (current->personality & ADDR_COMPAT_LAYOUT)
54 return 1;
55 if (rlimit(RLIMIT_STACK) == RLIM_INFINITY)
56 return 1;
57 return sysctl_legacy_va_layout;
58}
59
60static unsigned long mmap_rnd(void)
61{
62 if (!(current->flags & PF_RANDOMIZE))
63 return 0;
64 /* 8MB randomization for mmap_base */
65 return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
66}
67
41static inline unsigned long mmap_base(void) 68static inline unsigned long mmap_base(void)
42{ 69{
43 unsigned long gap = rlimit(RLIMIT_STACK); 70 unsigned long gap = rlimit(RLIMIT_STACK);
@@ -46,22 +73,8 @@ static inline unsigned long mmap_base(void)
46 gap = MIN_GAP; 73 gap = MIN_GAP;
47 else if (gap > MAX_GAP) 74 else if (gap > MAX_GAP)
48 gap = MAX_GAP; 75 gap = MAX_GAP;
49 76 gap &= PAGE_MASK;
50 return STACK_TOP - (gap & PAGE_MASK); 77 return STACK_TOP - stack_maxrandom_size() - mmap_rnd() - gap;
51}
52
53static inline int mmap_is_legacy(void)
54{
55#ifdef CONFIG_64BIT
56 /*
57 * Force standard allocation for 64 bit programs.
58 */
59 if (!is_compat_task())
60 return 1;
61#endif
62 return sysctl_legacy_va_layout ||
63 (current->personality & ADDR_COMPAT_LAYOUT) ||
64 rlimit(RLIMIT_STACK) == RLIM_INFINITY;
65} 78}
66 79
67#ifndef CONFIG_64BIT 80#ifndef CONFIG_64BIT