patch-2.6.6-vs1.9.0
[linux-2.6.git] / arch / s390 / kernel / compat_exec.c
1 /*
2  * Support for 32-bit Linux for S390 ELF binaries.
3  *
4  * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
5  * Author(s): Gerhard Tonn (ton@de.ibm.com)
6  *
7  * Separated from binfmt_elf32.c to reduce exports for module enablement.
8  *
9  */
10
11 #include <linux/config.h>
12 #include <linux/slab.h>
13 #include <linux/file.h>
14 #include <linux/mman.h>
15 #include <linux/a.out.h>
16 #include <linux/stat.h>
17 #include <linux/fcntl.h>
18 #include <linux/smp_lock.h>
19 #include <linux/init.h>
20 #include <linux/pagemap.h>
21 #include <linux/mm.h>
22 #include <linux/highmem.h>
23 #include <linux/spinlock.h>
24 #include <linux/binfmts.h>
25 #include <linux/module.h>
26 #include <linux/security.h>
27
28 #include <asm/uaccess.h>
29 #include <asm/pgalloc.h>
30 #include <asm/mmu_context.h>
31
32 #ifdef CONFIG_KMOD
33 #include <linux/kmod.h>
34 #endif
35
36
37 #undef STACK_TOP
38 #define STACK_TOP TASK31_SIZE
39
40 int setup_arg_pages32(struct linux_binprm *bprm, int executable_stack)
41 {
42         unsigned long stack_base, grow;
43         struct vm_area_struct *mpnt;
44         struct mm_struct *mm = current->mm;
45         int i;
46
47         stack_base = STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE;
48         mm->arg_start = bprm->p + stack_base;
49
50         bprm->p += stack_base;
51         if (bprm->loader)
52                 bprm->loader += stack_base;
53         bprm->exec += stack_base;
54
55         mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
56         if (!mpnt) 
57                 return -ENOMEM; 
58         
59         grow = (STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
60                 >> PAGE_SHIFT;
61         if (security_vm_enough_memory(grow) ||
62                 !vx_vmpages_avail(mm, grow)) {
63                 kmem_cache_free(vm_area_cachep, mpnt);
64                 return -ENOMEM;
65         }
66
67         down_write(&mm->mmap_sem);
68         {
69                 mpnt->vm_mm = mm;
70                 mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
71                 mpnt->vm_end = STACK_TOP;
72                 /* executable stack setting would be applied here */
73                 mpnt->vm_page_prot = PAGE_COPY;
74                 mpnt->vm_flags = VM_STACK_FLAGS;
75                 mpnt->vm_ops = NULL;
76                 mpnt->vm_pgoff = 0;
77                 mpnt->vm_file = NULL;
78                 INIT_LIST_HEAD(&mpnt->shared);
79                 mpnt->vm_private_data = (void *) 0;
80                 insert_vm_struct(mm, mpnt);
81                 // mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
82                 vx_vmpages_sub(mm, mm->total_vm -
83                         ((mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT));
84         } 
85
86         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
87                 struct page *page = bprm->page[i];
88                 if (page) {
89                         bprm->page[i] = NULL;
90                         put_dirty_page(current,page,stack_base,PAGE_COPY);
91                 }
92                 stack_base += PAGE_SIZE;
93         }
94         up_write(&mm->mmap_sem);
95         
96         return 0;
97 }
98
99 EXPORT_SYMBOL(setup_arg_pages32);