Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / arch / frv / mm / elf-fdpic.c
1 /* elf-fdpic.c: ELF FDPIC memory layout management
2  *
3  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/fs.h>
15 #include <linux/elf-fdpic.h>
16
17 /*****************************************************************************/
18 /*
19  * lay out the userspace VM according to our grand design
20  */
21 #ifdef CONFIG_MMU
22 void elf_fdpic_arch_lay_out_mm(struct elf_fdpic_params *exec_params,
23                                struct elf_fdpic_params *interp_params,
24                                unsigned long *start_stack,
25                                unsigned long *start_brk)
26 {
27         *start_stack = 0x02200000UL;
28
29         /* if the only executable is a shared object, assume that it is an interpreter rather than
30          * a true executable, and map it such that "ld.so --list" comes out right
31          */
32         if (!(interp_params->flags & ELF_FDPIC_FLAG_PRESENT) &&
33             exec_params->hdr.e_type != ET_EXEC
34             ) {
35                 exec_params->load_addr = PAGE_SIZE;
36
37                 *start_brk = 0x80000000UL;
38         }
39         else {
40                 exec_params->load_addr = 0x02200000UL;
41
42                 if ((exec_params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) ==
43                     ELF_FDPIC_FLAG_INDEPENDENT
44                     ) {
45                         exec_params->flags &= ~ELF_FDPIC_FLAG_ARRANGEMENT;
46                         exec_params->flags |= ELF_FDPIC_FLAG_CONSTDISP;
47                 }
48         }
49
50 } /* end elf_fdpic_arch_lay_out_mm() */
51 #endif
52
53 /*****************************************************************************/
54 /*
55  * place non-fixed mmaps firstly in the bottom part of memory, working up, and then in the top part
56  * of memory, working down
57  */
58 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
59                                      unsigned long pgoff, unsigned long flags)
60 {
61         struct vm_area_struct *vma;
62         unsigned long limit;
63
64         if (len > TASK_SIZE)
65                 return -ENOMEM;
66
67         /* handle MAP_FIXED */
68         if (flags & MAP_FIXED)
69                 return addr;
70
71         /* only honour a hint if we're not going to clobber something doing so */
72         if (addr) {
73                 addr = PAGE_ALIGN(addr);
74                 vma = find_vma(current->mm, addr);
75                 if (TASK_SIZE - len >= addr &&
76                     (!vma || addr + len <= vma->vm_start))
77                         goto success;
78         }
79
80         /* search between the bottom of user VM and the stack grow area */
81         addr = PAGE_SIZE;
82         limit = (current->mm->start_stack - 0x00200000);
83         if (addr + len <= limit) {
84                 limit -= len;
85
86                 if (addr <= limit) {
87                         vma = find_vma(current->mm, PAGE_SIZE);
88                         for (; vma; vma = vma->vm_next) {
89                                 if (addr > limit)
90                                         break;
91                                 if (addr + len <= vma->vm_start)
92                                         goto success;
93                                 addr = vma->vm_end;
94                         }
95                 }
96         }
97
98         /* search from just above the WorkRAM area to the top of memory */
99         addr = PAGE_ALIGN(0x80000000);
100         limit = TASK_SIZE - len;
101         if (addr <= limit) {
102                 vma = find_vma(current->mm, addr);
103                 for (; vma; vma = vma->vm_next) {
104                         if (addr > limit)
105                                 break;
106                         if (addr + len <= vma->vm_start)
107                                 goto success;
108                         addr = vma->vm_end;
109                 }
110
111                 if (!vma && addr <= limit)
112                         goto success;
113         }
114
115 #if 0
116         printk("[area] l=%lx (ENOMEM) f='%s'\n",
117                len, filp ? filp->f_path.dentry->d_name.name : "");
118 #endif
119         return -ENOMEM;
120
121  success:
122 #if 0
123         printk("[area] l=%lx ad=%lx f='%s'\n",
124                len, addr, filp ? filp->f_path.dentry->d_name.name : "");
125 #endif
126         return addr;
127 } /* end arch_get_unmapped_area() */