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 / x86_64 / ia32 / ia32_binfmt.c
index 7ac15ab..e5a4cef 100644 (file)
@@ -46,7 +46,7 @@ struct elf_phdr;
 
 #define IA32_EMULATOR 1
 
-#define ELF_ET_DYN_BASE                (TASK_UNMAPPED_32 + 0x1000000)
+#define ELF_ET_DYN_BASE                (TASK_UNMAPPED_BASE + 0x1000000)
 
 #undef ELF_ARCH
 #define ELF_ARCH EM_386
@@ -58,7 +58,7 @@ struct elf_phdr;
 
 #define USE_ELF_CORE_DUMP 1
 
-/* Overwrite elfcore.h */ 
+/* Override elfcore.h */ 
 #define _LINUX_ELFCORE_H 1
 typedef unsigned int elf_greg_t;
 
@@ -182,6 +182,7 @@ struct elf_prpsinfo
 #define user user32
 
 #define __ASM_X86_64_ELF_H 1
+#define elf_read_implies_exec(ex, have_pt_gnu_stack)   (!(have_pt_gnu_stack))
 //#include <asm/ia32.h>
 #include <linux/elf.h>
 
@@ -196,8 +197,7 @@ static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *re
 
 static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
 {      
-       struct pt_regs *pp = (struct pt_regs *)(t->thread.rsp0);
-       --pp;
+       struct pt_regs *pp = task_pt_regs(t);
        ELF_CORE_COPY_REGS((*elfregs), pp);
        /* fix wrong segments */ 
        (*elfregs)[7] = t->thread.ds; 
@@ -213,11 +213,10 @@ elf_core_copy_task_fpregs(struct task_struct *tsk, struct pt_regs *regs, elf_fpr
        struct _fpstate_ia32 *fpstate = (void*)fpu; 
        mm_segment_t oldfs = get_fs();
 
-       if (!tsk->used_math) 
+       if (!tsk_used_math(tsk))
                return 0;
        if (!regs)
-               regs = (struct pt_regs *)tsk->thread.rsp0;
-       --regs;
+               regs = task_pt_regs(tsk);
        if (tsk == current)
                unlazy_fpu(tsk);
        set_fs(KERNEL_DS); 
@@ -233,8 +232,8 @@ elf_core_copy_task_fpregs(struct task_struct *tsk, struct pt_regs *regs, elf_fpr
 static inline int 
 elf_core_copy_task_xfpregs(struct task_struct *t, elf_fpxregset_t *xfpu)
 {
-       struct pt_regs *regs = ((struct pt_regs *)(t->thread.rsp0))-1; 
-       if (!t->used_math) 
+       struct pt_regs *regs = task_pt_regs(t);
+       if (!tsk_used_math(t))
                return 0;
        if (t == current)
                unlazy_fpu(t); 
@@ -272,8 +271,9 @@ do {                                                        \
 #define load_elf_binary load_elf32_binary
 
 #define ELF_PLAT_INIT(r, load_addr)    elf32_init(r)
-#define setup_arg_pages(bprm, exec_stack)      ia32_setup_arg_pages(bprm, exec_stack)
-int ia32_setup_arg_pages(struct linux_binprm *bprm, int executable_stack);
+#define setup_arg_pages(bprm, stack_top, exec_stack) \
+       ia32_setup_arg_pages(bprm, stack_top, exec_stack)
+int ia32_setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_top, int executable_stack);
 
 #undef start_thread
 #define start_thread(regs,new_rip,new_rsp) do { \
@@ -289,8 +289,6 @@ int ia32_setup_arg_pages(struct linux_binprm *bprm, int executable_stack);
 } while(0) 
 
 
-#define elf_map elf32_map
-
 #include <linux/module.h>
 
 MODULE_DESCRIPTION("Binary format loader for compatibility with IA32 ELF binaries."); 
@@ -303,6 +301,10 @@ MODULE_AUTHOR("Eric Youngdale, Andi Kleen");
 
 static void elf32_init(struct pt_regs *);
 
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
+#define arch_setup_additional_pages syscall32_setup_pages
+extern int syscall32_setup_pages(struct linux_binprm *, int exstack, unsigned long start_code, unsigned long interp_map_address);
+
 #include "../../../fs/binfmt_elf.c" 
 
 static void elf32_init(struct pt_regs *regs)
@@ -325,14 +327,15 @@ static void elf32_init(struct pt_regs *regs)
        me->thread.es = __USER_DS;
 }
 
-int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
+int ia32_setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_top,
+                        int executable_stack)
 {
-       unsigned long stack_base, grow;
+       unsigned long stack_base;
        struct vm_area_struct *mpnt;
        struct mm_struct *mm = current->mm;
-       int i;
+       int i, ret;
 
-       stack_base = IA32_STACK_TOP - MAX_ARG_PAGES * PAGE_SIZE;
+       stack_base = stack_top - MAX_ARG_PAGES * PAGE_SIZE;
        mm->arg_start = bprm->p + stack_base;
 
        bprm->p += stack_base;
@@ -343,14 +346,6 @@ int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
        mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
        if (!mpnt) 
                return -ENOMEM; 
-       
-       grow = (IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
-               >> PAGE_SHIFT;
-       if (security_vm_enough_memory(grow) ||
-               !vx_vmpages_avail(mm, grow)) {
-               kmem_cache_free(vm_area_cachep, mpnt);
-               return -ENOMEM;
-       }
 
        memset(mpnt, 0, sizeof(*mpnt));
 
@@ -358,19 +353,22 @@ int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
        {
                mpnt->vm_mm = mm;
                mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
-               mpnt->vm_end = IA32_STACK_TOP;
+               mpnt->vm_end = stack_top;
                if (executable_stack == EXSTACK_ENABLE_X)
-                       mpnt->vm_flags = vm_stack_flags32 |  VM_EXEC;
+                       mpnt->vm_flags = VM_STACK_FLAGS |  VM_EXEC;
                else if (executable_stack == EXSTACK_DISABLE_X)
-                       mpnt->vm_flags = vm_stack_flags32 & ~VM_EXEC;
+                       mpnt->vm_flags = VM_STACK_FLAGS & ~VM_EXEC;
                else
-                       mpnt->vm_flags = vm_stack_flags32;
+                       mpnt->vm_flags = VM_STACK_FLAGS;
                mpnt->vm_page_prot = (mpnt->vm_flags & VM_EXEC) ? 
                        PAGE_COPY_EXEC : PAGE_COPY;
-               insert_vm_struct(mm, mpnt);
-               // mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
-               vx_vmpages_sub(mm, mm->total_vm -
-                       ((mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT));
+               if ((ret = insert_vm_struct(mm, mpnt))) {
+                       up_write(&mm->mmap_sem);
+                       kmem_cache_free(vm_area_cachep, mpnt);
+                       return ret;
+               }
+               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
+               mm->stack_vm = mm->total_vm;
        } 
 
        for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
@@ -385,24 +383,7 @@ int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
        
        return 0;
 }
-
-static unsigned long
-elf32_map (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
-{
-       unsigned long map_addr;
-       struct task_struct *me = current; 
-
-       if (prot & PROT_READ) 
-               prot |= vm_force_exec32;
-
-       down_write(&me->mm->mmap_sem);
-       map_addr = do_mmap(filep, ELF_PAGESTART(addr),
-                          eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, 
-                          type,
-                          eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
-       up_write(&me->mm->mmap_sem);
-       return(map_addr);
-}
+EXPORT_SYMBOL(ia32_setup_arg_pages);
 
 #ifdef CONFIG_SYSCTL
 /* Register vsyscall32 into the ABI table */