1 /* elf-fdpic.c: ELF FDPIC memory layout management
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/sched.h>
15 #include <linux/elf-fdpic.h>
18 /*****************************************************************************/
20 * lay out the userspace VM according to our grand design
23 void elf_fdpic_arch_lay_out_mm(struct elf_fdpic_params
*exec_params
,
24 struct elf_fdpic_params
*interp_params
,
25 unsigned long *start_stack
,
26 unsigned long *start_brk
)
28 *start_stack
= 0x02200000UL
;
30 /* if the only executable is a shared object, assume that it is an interpreter rather than
31 * a true executable, and map it such that "ld.so --list" comes out right
33 if (!(interp_params
->flags
& ELF_FDPIC_FLAG_PRESENT
) &&
34 exec_params
->hdr
.e_type
!= ET_EXEC
36 exec_params
->load_addr
= PAGE_SIZE
;
38 *start_brk
= 0x80000000UL
;
41 exec_params
->load_addr
= 0x02200000UL
;
43 if ((exec_params
->flags
& ELF_FDPIC_FLAG_ARRANGEMENT
) ==
44 ELF_FDPIC_FLAG_INDEPENDENT
46 exec_params
->flags
&= ~ELF_FDPIC_FLAG_ARRANGEMENT
;
47 exec_params
->flags
|= ELF_FDPIC_FLAG_CONSTDISP
;
51 } /* end elf_fdpic_arch_lay_out_mm() */
54 /*****************************************************************************/
56 * place non-fixed mmaps firstly in the bottom part of memory, working up, and then in the top part
57 * of memory, working down
59 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
, unsigned long len
,
60 unsigned long pgoff
, unsigned long flags
)
62 struct vm_area_struct
*vma
;
68 /* handle MAP_FIXED */
69 if (flags
& MAP_FIXED
)
72 /* only honour a hint if we're not going to clobber something doing so */
74 addr
= PAGE_ALIGN(addr
);
75 vma
= find_vma(current
->mm
, addr
);
76 if (TASK_SIZE
- len
>= addr
&&
77 (!vma
|| addr
+ len
<= vma
->vm_start
))
81 /* search between the bottom of user VM and the stack grow area */
83 limit
= (current
->mm
->start_stack
- 0x00200000);
84 if (addr
+ len
<= limit
) {
88 vma
= find_vma(current
->mm
, PAGE_SIZE
);
89 for (; vma
; vma
= vma
->vm_next
) {
92 if (addr
+ len
<= vma
->vm_start
)
99 /* search from just above the WorkRAM area to the top of memory */
100 addr
= PAGE_ALIGN(0x80000000);
101 limit
= TASK_SIZE
- len
;
103 vma
= find_vma(current
->mm
, addr
);
104 for (; vma
; vma
= vma
->vm_next
) {
107 if (addr
+ len
<= vma
->vm_start
)
112 if (!vma
&& addr
<= limit
)
117 printk("[area] l=%lx (ENOMEM) f='%s'\n",
118 len
, filp
? filp
->f_path
.dentry
->d_name
.name
: "");
124 printk("[area] l=%lx ad=%lx f='%s'\n",
125 len
, addr
, filp
? filp
->f_path
.dentry
->d_name
.name
: "");
128 } /* end arch_get_unmapped_area() */