[SPARC64]: of_device_register() error checking fix
[powerpc.git] / arch / sparc64 / kernel / sys_sparc.c
index 61dffb9..51c056d 100644 (file)
@@ -6,7 +6,6 @@
  * platform.
  */
 
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/syscalls.h>
 #include <linux/ipc.h>
 #include <linux/personality.h>
+#include <linux/random.h>
 
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 #include <asm/utrap.h>
 #include <asm/perfctr.h>
+#include <asm/a.out.h>
 
 /* #define DEBUG_UNIMP_SYSCALL */
 
@@ -130,7 +131,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
        }
 
        if (test_thread_flag(TIF_32BIT))
-               task_size = 0xf0000000UL;
+               task_size = STACK_TOP32;
        if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
                return -ENOMEM;
 
@@ -203,7 +204,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
 {
        struct vm_area_struct *vma;
        struct mm_struct *mm = current->mm;
-       unsigned long task_size = 0xf0000000UL;
+       unsigned long task_size = STACK_TOP32;
        unsigned long addr = addr0;
        int do_color_align;
 
@@ -357,6 +358,17 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
 /* Essentially the same as PowerPC... */
 void arch_pick_mmap_layout(struct mm_struct *mm)
 {
+       unsigned long random_factor = 0UL;
+
+       if (current->flags & PF_RANDOMIZE) {
+               random_factor = get_random_int();
+               if (test_thread_flag(TIF_32BIT))
+                       random_factor &= ((1 * 1024 * 1024) - 1);
+               else
+                       random_factor = ((random_factor << PAGE_SHIFT) &
+                                        0xffffffffUL);
+       }
+
        /*
         * Fall back to the standard layout if the personality
         * bit is set, or if the expected stack growth is unlimited:
@@ -365,12 +377,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
            (current->personality & ADDR_COMPAT_LAYOUT) ||
            current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
            sysctl_legacy_va_layout) {
-               mm->mmap_base = TASK_UNMAPPED_BASE;
+               mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
                mm->get_unmapped_area = arch_get_unmapped_area;
                mm->unmap_area = arch_unmap_area;
        } else {
                /* We know it's 32-bit */
-               unsigned long task_size = 0xf0000000UL;
+               unsigned long task_size = STACK_TOP32;
                unsigned long gap;
 
                gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
@@ -379,7 +391,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
                if (gap > (task_size / 6 * 5))
                        gap = (task_size / 6 * 5);
 
-               mm->mmap_base = task_size - (gap & PAGE_MASK);
+               mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
                mm->get_unmapped_area = arch_get_unmapped_area_topdown;
                mm->unmap_area = arch_unmap_area_topdown;
        }
@@ -388,7 +400,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
 asmlinkage unsigned long sparc_brk(unsigned long brk)
 {
        /* People could try to be nasty and use ta 0x6d in 32bit programs */
-       if (test_thread_flag(TIF_32BIT) && brk >= 0xf0000000UL)
+       if (test_thread_flag(TIF_32BIT) && brk >= STACK_TOP32)
                return current->mm->brk;
 
        if (unlikely(straddles_64bit_va_hole(current->mm->brk, brk)))
@@ -554,10 +566,10 @@ asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
        retval = -EINVAL;
 
        if (test_thread_flag(TIF_32BIT)) {
-               if (len >= 0xf0000000UL)
+               if (len >= STACK_TOP32)
                        goto out_putf;
 
-               if ((flags & MAP_FIXED) && addr > 0xf0000000UL - len)
+               if ((flags & MAP_FIXED) && addr > STACK_TOP32 - len)
                        goto out_putf;
        } else {
                if (len >= VA_EXCLUDE_START)