2 * (C) Copyright 2002 Linus Torvalds
3 * Portions based on the vdso-randomization code from exec-shield:
4 * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
6 * This file contains the needed initializations to support sysenter.
9 #include <linux/init.h>
10 #include <linux/smp.h>
11 #include <linux/thread_info.h>
12 #include <linux/sched.h>
13 #include <linux/gfp.h>
14 #include <linux/string.h>
15 #include <linux/elf.h>
17 #include <linux/err.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
21 #include <asm/cpufeature.h>
23 #include <asm/pgtable.h>
24 #include <asm/unistd.h>
26 #include <asm/tlbflush.h>
28 #include <asm/proto.h>
29 #include <asm/fixmap.h>
33 #ifdef CONFIG_COMPAT_VDSO
34 #define VDSO_DEFAULT 0
36 #define VDSO_DEFAULT 1
40 #define arch_setup_additional_pages syscall32_setup_pages
44 * Should the kernel map a VDSO page into processes and pass its
45 * address down to glibc upon exec()?
47 unsigned int __read_mostly vdso32_enabled
= VDSO_DEFAULT
;
49 static int __init
vdso32_setup(char *s
)
51 vdso32_enabled
= simple_strtoul(s
, NULL
, 0);
53 if (vdso32_enabled
> 1)
54 pr_warn("vdso32 values other than 0 and 1 are no longer allowed; vdso disabled\n");
60 * For consistency, the argument vdso32=[012] affects the 32-bit vDSO
61 * behavior on both 64-bit and 32-bit kernels.
62 * On 32-bit kernels, vdso=[012] means the same thing.
64 __setup("vdso32=", vdso32_setup
);
67 __setup_param("vdso=", vdso_setup
, vdso32_setup
, 0);
70 static struct page
**vdso32_pages
;
71 static unsigned vdso32_size
;
75 #define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SYSENTER32))
76 #define vdso32_syscall() (boot_cpu_has(X86_FEATURE_SYSCALL32))
78 #else /* CONFIG_X86_32 */
80 #define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP))
81 #define vdso32_syscall() (0)
83 #endif /* CONFIG_X86_64 */
85 int __init
sysenter_setup(void)
87 char *vdso32_start
, *vdso32_end
;
91 if (vdso32_syscall()) {
92 vdso32_start
= vdso32_syscall_start
;
93 vdso32_end
= vdso32_syscall_end
;
94 vdso32_pages
= vdso32_syscall_pages
;
97 if (vdso32_sysenter()) {
98 vdso32_start
= vdso32_sysenter_start
;
99 vdso32_end
= vdso32_sysenter_end
;
100 vdso32_pages
= vdso32_sysenter_pages
;
102 vdso32_start
= vdso32_int80_start
;
103 vdso32_end
= vdso32_int80_end
;
104 vdso32_pages
= vdso32_int80_pages
;
107 npages
= ((vdso32_end
- vdso32_start
) + PAGE_SIZE
- 1) / PAGE_SIZE
;
108 vdso32_size
= npages
<< PAGE_SHIFT
;
109 for (i
= 0; i
< npages
; i
++)
110 vdso32_pages
[i
] = virt_to_page(vdso32_start
+ i
*PAGE_SIZE
);
112 patch_vdso32(vdso32_start
, vdso32_size
);
117 /* Setup a VMA at program startup for the vsyscall page */
118 int arch_setup_additional_pages(struct linux_binprm
*bprm
, int uses_interp
)
120 struct mm_struct
*mm
= current
->mm
;
123 struct vm_area_struct
*vma
;
125 #ifdef CONFIG_X86_X32_ABI
126 if (test_thread_flag(TIF_X32
))
127 return x32_setup_additional_pages(bprm
, uses_interp
);
130 if (vdso32_enabled
!= 1) /* Other values all mean "disabled" */
133 down_write(&mm
->mmap_sem
);
135 addr
= get_unmapped_area(NULL
, 0, vdso32_size
+ VDSO_OFFSET(VDSO_PREV_PAGES
), 0, 0);
136 if (IS_ERR_VALUE(addr
)) {
141 addr
+= VDSO_OFFSET(VDSO_PREV_PAGES
);
143 current
->mm
->context
.vdso
= (void *)addr
;
146 * MAYWRITE to allow gdb to COW and set breakpoints
148 ret
= install_special_mapping(mm
,
152 VM_MAYREAD
|VM_MAYWRITE
|VM_MAYEXEC
,
158 vma
= _install_special_mapping(mm
,
159 addr
- VDSO_OFFSET(VDSO_PREV_PAGES
),
160 VDSO_OFFSET(VDSO_PREV_PAGES
),
169 ret
= remap_pfn_range(vma
,
170 addr
- VDSO_OFFSET(VDSO_VVAR_PAGE
),
171 __pa_symbol(&__vvar_page
) >> PAGE_SHIFT
,
178 #ifdef CONFIG_HPET_TIMER
180 ret
= io_remap_pfn_range(vma
,
181 addr
- VDSO_OFFSET(VDSO_HPET_PAGE
),
182 hpet_address
>> PAGE_SHIFT
,
184 pgprot_noncached(PAGE_READONLY
));
191 current_thread_info()->sysenter_return
=
192 VDSO32_SYMBOL(addr
, SYSENTER_RETURN
);
196 current
->mm
->context
.vdso
= NULL
;
198 up_write(&mm
->mmap_sem
);
205 subsys_initcall(sysenter_setup
);
208 /* Register vsyscall32 into the ABI table */
209 #include <linux/sysctl.h>
211 static struct ctl_table abi_table2
[] = {
213 .procname
= "vsyscall32",
214 .data
= &vdso32_enabled
,
215 .maxlen
= sizeof(int),
217 .proc_handler
= proc_dointvec
222 static struct ctl_table abi_root_table2
[] = {
231 static __init
int ia32_binfmt_init(void)
233 register_sysctl_table(abi_root_table2
);
236 __initcall(ia32_binfmt_init
);
239 #else /* CONFIG_X86_32 */
241 const char *arch_vma_name(struct vm_area_struct
*vma
)
243 if (vma
->vm_mm
&& vma
->vm_start
== (long)vma
->vm_mm
->context
.vdso
)
248 struct vm_area_struct
*get_gate_vma(struct mm_struct
*mm
)
253 int in_gate_area(struct mm_struct
*mm
, unsigned long addr
)
258 int in_gate_area_no_mm(unsigned long addr
)
263 #endif /* CONFIG_X86_64 */