Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / sparc64 / kernel / binfmt_aout32.c
index ae92b77..c042221 100644 (file)
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
+#include <asm/mmu_context.h>
 
 static int load_aout32_binary(struct linux_binprm *, struct pt_regs * regs);
 static int load_aout32_library(struct file*);
 static int aout32_core_dump(long signr, struct pt_regs * regs, struct file *file);
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 static struct linux_binfmt aout32_format = {
        NULL, THIS_MODULE, load_aout32_binary, load_aout32_library, aout32_core_dump,
        PAGE_SIZE
@@ -50,7 +49,9 @@ static void set_brk(unsigned long start, unsigned long end)
        end = PAGE_ALIGN(end);
        if (end <= start)
                return;
+       down_write(&current->mm->mmap_sem);
        do_brk(start, end - start);
+       up_write(&current->mm->mmap_sem);
 }
 
 /*
@@ -96,26 +97,26 @@ static int aout32_core_dump(long signr, struct pt_regs *regs, struct file *file)
        set_fs(KERNEL_DS);
        has_dumped = 1;
        current->flags |= PF_DUMPCORE;
-               strncpy(dump.u_comm, current->comm, sizeof(current->comm));
+               strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));
        dump.signal = signr;
        dump_thread(regs, &dump);
 
 /* If the size of the dump file exceeds the rlimit, then see what would happen
    if we wrote the stack, but not the data area.  */
        if ((dump.u_dsize+dump.u_ssize) >
-           current->rlim[RLIMIT_CORE].rlim_cur)
+           current->signal->rlim[RLIMIT_CORE].rlim_cur)
                dump.u_dsize = 0;
 
 /* Make sure we have enough room to write the stack and data areas. */
        if ((dump.u_ssize) >
-           current->rlim[RLIMIT_CORE].rlim_cur)
+           current->signal->rlim[RLIMIT_CORE].rlim_cur)
                dump.u_ssize = 0;
 
 /* make sure we actually have a data and stack area to dump */
        set_fs(USER_DS);
-       if (verify_area(VERIFY_READ, (void __user *) START_DATA(dump), dump.u_dsize))
+       if (!access_ok(VERIFY_READ, (void __user *) START_DATA(dump), dump.u_dsize))
                dump.u_dsize = 0;
-       if (verify_area(VERIFY_READ, (void __user *) START_STACK(dump), dump.u_ssize))
+       if (!access_ok(VERIFY_READ, (void __user *) START_STACK(dump), dump.u_ssize))
                dump.u_ssize = 0;
 
        set_fs(KERNEL_DS);
@@ -219,7 +220,7 @@ static int load_aout32_binary(struct linux_binprm * bprm, struct pt_regs * regs)
         * size limits imposed on them by creating programs with large
         * arrays in the data or bss.
         */
-       rlim = current->rlim[RLIMIT_DATA].rlim_cur;
+       rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
        if (rlim >= RLIM_INFINITY)
                rlim = ~0;
        if (ex.a_data + ex.a_bss > rlim)
@@ -239,19 +240,23 @@ static int load_aout32_binary(struct linux_binprm * bprm, struct pt_regs * regs)
                (current->mm->start_data = N_DATADDR(ex));
        current->mm->brk = ex.a_bss +
                (current->mm->start_brk = N_BSSADDR(ex));
+       current->mm->free_area_cache = current->mm->mmap_base;
+       current->mm->cached_hole_size = 0;
 
-       // current->mm->rss = 0;
-       vx_rsspages_sub(current->mm, current->mm->rss);
        current->mm->mmap = NULL;
        compute_creds(bprm);
        current->flags &= ~PF_FORKNOEXEC;
        if (N_MAGIC(ex) == NMAGIC) {
                loff_t pos = fd_offset;
                /* Fuck me plenty... */
+               down_write(&current->mm->mmap_sem);     
                error = do_brk(N_TXTADDR(ex), ex.a_text);
+               up_write(&current->mm->mmap_sem);
                bprm->file->f_op->read(bprm->file, (char __user *)N_TXTADDR(ex),
                          ex.a_text, &pos);
+               down_write(&current->mm->mmap_sem);
                error = do_brk(N_DATADDR(ex), ex.a_data);
+               up_write(&current->mm->mmap_sem);
                bprm->file->f_op->read(bprm->file, (char __user *)N_DATADDR(ex),
                          ex.a_data, &pos);
                goto beyond_if;
@@ -259,8 +264,10 @@ static int load_aout32_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 
        if (N_MAGIC(ex) == OMAGIC) {
                loff_t pos = fd_offset;
+               down_write(&current->mm->mmap_sem);
                do_brk(N_TXTADDR(ex) & PAGE_MASK,
                        ex.a_text+ex.a_data + PAGE_SIZE - 1);
+               up_write(&current->mm->mmap_sem);
                bprm->file->f_op->read(bprm->file, (char __user *)N_TXTADDR(ex),
                          ex.a_text+ex.a_data, &pos);
        } else {
@@ -274,7 +281,9 @@ static int load_aout32_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 
                if (!bprm->file->f_op->mmap) {
                        loff_t pos = fd_offset;
+                       down_write(&current->mm->mmap_sem);
                        do_brk(0, ex.a_text+ex.a_data);
+                       up_write(&current->mm->mmap_sem);
                        bprm->file->f_op->read(bprm->file,
                                  (char __user *)N_TXTADDR(ex),
                                  ex.a_text+ex.a_data, &pos);
@@ -313,7 +322,7 @@ beyond_if:
        orig_thr_flags = current_thread_info()->flags;
        current_thread_info()->flags |= _TIF_32BIT;
 
-       retval = setup_arg_pages(bprm, EXSTACK_DEFAULT);
+       retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
        if (retval < 0) { 
                current_thread_info()->flags = orig_thr_flags;
 
@@ -324,16 +333,8 @@ beyond_if:
 
        current->mm->start_stack =
                (unsigned long) create_aout32_tables((char __user *)bprm->p, bprm);
-       if (!(orig_thr_flags & _TIF_32BIT)) {
-               unsigned long pgd_cache;
-
-               pgd_cache = ((unsigned long)current->mm->pgd[0])<<11UL;
-               __asm__ __volatile__("stxa\t%0, [%1] %2\n\t"
-                                    "membar #Sync"
-                                    : /* no outputs */
-                                    : "r" (pgd_cache),
-                                      "r" (TSB_REG), "i" (ASI_DMMU));
-       }
+       tsb_context_switch(current->mm);
+
        start_thread32(regs, ex.a_entry, current->mm->start_stack);
        if (current->ptrace & PT_PTRACED)
                send_sig(SIGTRAP, current, 0);
@@ -391,7 +392,9 @@ static int load_aout32_library(struct file *file)
        len = PAGE_ALIGN(ex.a_text + ex.a_data);
        bss = ex.a_text + ex.a_data + ex.a_bss;
        if (bss > len) {
+               down_write(&current->mm->mmap_sem);
                error = do_brk(start_addr + len, bss - len);
+               up_write(&current->mm->mmap_sem);
                retval = error;
                if (error != start_addr + len)
                        goto out;