xref: /linux/arch/x86/include/asm/elf.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21965aae3SH. Peter Anvin #ifndef _ASM_X86_ELF_H
31965aae3SH. Peter Anvin #define _ASM_X86_ELF_H
4bb898558SAl Viro 
5bb898558SAl Viro /*
6bb898558SAl Viro  * ELF register definitions..
7bb898558SAl Viro  */
8dfb09f9bSBorislav Petkov #include <linux/thread_info.h>
9bb898558SAl Viro 
105ae2702dSNikolay Borisov #include <asm/ia32.h>
11bb898558SAl Viro #include <asm/ptrace.h>
12bb898558SAl Viro #include <asm/user.h>
13bb898558SAl Viro #include <asm/auxvec.h>
14824eea38SChang S. Bae #include <asm/fsgsbase.h>
15bb898558SAl Viro 
16bb898558SAl Viro typedef unsigned long elf_greg_t;
17bb898558SAl Viro 
18bb898558SAl Viro #define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t))
19bb898558SAl Viro typedef elf_greg_t elf_gregset_t[ELF_NGREG];
20bb898558SAl Viro 
21bb898558SAl Viro typedef struct user_i387_struct elf_fpregset_t;
22bb898558SAl Viro 
23bb898558SAl Viro #ifdef __i386__
24bb898558SAl Viro 
25bb898558SAl Viro #define R_386_NONE	0
26bb898558SAl Viro #define R_386_32	1
27bb898558SAl Viro #define R_386_PC32	2
28bb898558SAl Viro #define R_386_GOT32	3
29bb898558SAl Viro #define R_386_PLT32	4
30bb898558SAl Viro #define R_386_COPY	5
31bb898558SAl Viro #define R_386_GLOB_DAT	6
32bb898558SAl Viro #define R_386_JMP_SLOT	7
33bb898558SAl Viro #define R_386_RELATIVE	8
34bb898558SAl Viro #define R_386_GOTOFF	9
35bb898558SAl Viro #define R_386_GOTPC	10
36bb898558SAl Viro #define R_386_NUM	11
37bb898558SAl Viro 
38bb898558SAl Viro /*
39bb898558SAl Viro  * These are used to set parameters in the core dumps.
40bb898558SAl Viro  */
41bb898558SAl Viro #define ELF_CLASS	ELFCLASS32
42bb898558SAl Viro #define ELF_DATA	ELFDATA2LSB
43bb898558SAl Viro #define ELF_ARCH	EM_386
44bb898558SAl Viro 
45bb898558SAl Viro #else
46bb898558SAl Viro 
47bb898558SAl Viro /* x86-64 relocation types */
48bb898558SAl Viro #define R_X86_64_NONE		0	/* No reloc */
49bb898558SAl Viro #define R_X86_64_64		1	/* Direct 64 bit  */
50bb898558SAl Viro #define R_X86_64_PC32		2	/* PC relative 32 bit signed */
51bb898558SAl Viro #define R_X86_64_GOT32		3	/* 32 bit GOT entry */
52bb898558SAl Viro #define R_X86_64_PLT32		4	/* 32 bit PLT address */
53bb898558SAl Viro #define R_X86_64_COPY		5	/* Copy symbol at runtime */
54bb898558SAl Viro #define R_X86_64_GLOB_DAT	6	/* Create GOT entry */
55bb898558SAl Viro #define R_X86_64_JUMP_SLOT	7	/* Create PLT entry */
56bb898558SAl Viro #define R_X86_64_RELATIVE	8	/* Adjust by program base */
57bb898558SAl Viro #define R_X86_64_GOTPCREL	9	/* 32 bit signed pc relative
58bb898558SAl Viro 					   offset to GOT */
59bb898558SAl Viro #define R_X86_64_32		10	/* Direct 32 bit zero extended */
60bb898558SAl Viro #define R_X86_64_32S		11	/* Direct 32 bit sign extended */
61bb898558SAl Viro #define R_X86_64_16		12	/* Direct 16 bit zero extended */
62bb898558SAl Viro #define R_X86_64_PC16		13	/* 16 bit sign extended pc relative */
63bb898558SAl Viro #define R_X86_64_8		14	/* Direct 8 bit sign extended  */
64bb898558SAl Viro #define R_X86_64_PC8		15	/* 8 bit sign extended pc relative */
65b40a142bSArd Biesheuvel #define R_X86_64_PC64		24	/* Place relative 64-bit signed */
66bb898558SAl Viro 
67bb898558SAl Viro /*
68bb898558SAl Viro  * These are used to set parameters in the core dumps.
69bb898558SAl Viro  */
70bb898558SAl Viro #define ELF_CLASS	ELFCLASS64
71bb898558SAl Viro #define ELF_DATA	ELFDATA2LSB
72bb898558SAl Viro #define ELF_ARCH	EM_X86_64
73bb898558SAl Viro 
74bb898558SAl Viro #endif
75bb898558SAl Viro 
76bb898558SAl Viro #include <asm/vdso.h>
77bb898558SAl Viro 
783d7ee969SAndy Lutomirski #ifdef CONFIG_X86_64
793d7ee969SAndy Lutomirski extern unsigned int vdso64_enabled;
803d7ee969SAndy Lutomirski #endif
81ab8b82eeSBrian Gerst #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
823d7ee969SAndy Lutomirski extern unsigned int vdso32_enabled;
833d7ee969SAndy Lutomirski #endif
84bb898558SAl Viro 
85bb898558SAl Viro /*
86bb898558SAl Viro  * This is used to ensure we don't load something for the wrong architecture.
87bb898558SAl Viro  */
88bb898558SAl Viro #define elf_check_arch_ia32(x) \
89bb898558SAl Viro 	(((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
90bb898558SAl Viro 
91bb898558SAl Viro #include <asm/processor.h>
92bb898558SAl Viro 
93bb898558SAl Viro #ifdef CONFIG_X86_32
94bb898558SAl Viro #include <asm/desc.h>
95bb898558SAl Viro 
96bb898558SAl Viro #define elf_check_arch(x)	elf_check_arch_ia32(x)
97bb898558SAl Viro 
98bb898558SAl Viro /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
99bb898558SAl Viro    contains a pointer to a function which might be registered using `atexit'.
100bb898558SAl Viro    This provides a mean for the dynamic linker to call DT_FINI functions for
101bb898558SAl Viro    shared libraries that have been loaded before the code runs.
102bb898558SAl Viro 
103bb898558SAl Viro    A value of 0 tells we have no such handler.
104bb898558SAl Viro 
105bb898558SAl Viro    We might as well make sure everything else is cleared too (except for %esp),
106bb898558SAl Viro    just to make things more deterministic.
107bb898558SAl Viro  */
108bb898558SAl Viro #define ELF_PLAT_INIT(_r, load_addr)		\
109bb898558SAl Viro 	do {					\
110bb898558SAl Viro 	_r->bx = 0; _r->cx = 0; _r->dx = 0;	\
111bb898558SAl Viro 	_r->si = 0; _r->di = 0; _r->bp = 0;	\
112bb898558SAl Viro 	_r->ax = 0;				\
113bb898558SAl Viro } while (0)
114bb898558SAl Viro 
115bb898558SAl Viro /*
116bb898558SAl Viro  * regs is struct pt_regs, pr_reg is elf_gregset_t (which is
117bb898558SAl Viro  * now struct_user_regs, they are different)
118bb898558SAl Viro  */
119bb898558SAl Viro 
120f5d9283eSBrian Gerst #define ELF_CORE_COPY_REGS(pr_reg, regs)	\
121bb898558SAl Viro do {						\
122bb898558SAl Viro 	pr_reg[0] = regs->bx;			\
123bb898558SAl Viro 	pr_reg[1] = regs->cx;			\
124bb898558SAl Viro 	pr_reg[2] = regs->dx;			\
125bb898558SAl Viro 	pr_reg[3] = regs->si;			\
126bb898558SAl Viro 	pr_reg[4] = regs->di;			\
127bb898558SAl Viro 	pr_reg[5] = regs->bp;			\
128bb898558SAl Viro 	pr_reg[6] = regs->ax;			\
12999504819SAndy Lutomirski 	pr_reg[7] = regs->ds;			\
13099504819SAndy Lutomirski 	pr_reg[8] = regs->es;			\
13199504819SAndy Lutomirski 	pr_reg[9] = regs->fs;			\
132f5d9283eSBrian Gerst 	savesegment(gs, pr_reg[10]);		\
133bb898558SAl Viro 	pr_reg[11] = regs->orig_ax;		\
134bb898558SAl Viro 	pr_reg[12] = regs->ip;			\
13599504819SAndy Lutomirski 	pr_reg[13] = regs->cs;			\
136bb898558SAl Viro 	pr_reg[14] = regs->flags;		\
137bb898558SAl Viro 	pr_reg[15] = regs->sp;			\
13899504819SAndy Lutomirski 	pr_reg[16] = regs->ss;			\
139bb898558SAl Viro } while (0);
140bb898558SAl Viro 
141bb898558SAl Viro #define ELF_PLATFORM	(utsname()->machine)
142bb898558SAl Viro #define set_personality_64bit()	do { } while (0)
143bb898558SAl Viro 
144bb898558SAl Viro #else /* CONFIG_X86_32 */
145bb898558SAl Viro 
146bb898558SAl Viro /*
147bb898558SAl Viro  * This is used to ensure we don't load something for the wrong architecture.
148bb898558SAl Viro  */
149bb898558SAl Viro #define elf_check_arch(x)			\
150bb898558SAl Viro 	((x)->e_machine == EM_X86_64)
151bb898558SAl Viro 
152d1a797f3SH. Peter Anvin #define compat_elf_check_arch(x)					\
153*f789383fSBorislav Petkov (AMD) 	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
1540e6d3112SBen Hutchings 	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
155d1a797f3SH. Peter Anvin 
elf_common_init(struct thread_struct * t,struct pt_regs * regs,const u16 ds)156bb898558SAl Viro static inline void elf_common_init(struct thread_struct *t,
157bb898558SAl Viro 				   struct pt_regs *regs, const u16 ds)
158bb898558SAl Viro {
1597bcdea4dSAndy Lutomirski 	/* ax gets execve's return value. */
1607bcdea4dSAndy Lutomirski 	/*regs->ax = */ regs->bx = regs->cx = regs->dx = 0;
1617bcdea4dSAndy Lutomirski 	regs->si = regs->di = regs->bp = 0;
162bb898558SAl Viro 	regs->r8 = regs->r9 = regs->r10 = regs->r11 = 0;
1637bcdea4dSAndy Lutomirski 	regs->r12 = regs->r13 = regs->r14 = regs->r15 = 0;
164296f781aSAndy Lutomirski 	t->fsbase = t->gsbase = 0;
165bb898558SAl Viro 	t->fsindex = t->gsindex = 0;
166bb898558SAl Viro 	t->ds = t->es = ds;
167bb898558SAl Viro }
168bb898558SAl Viro 
169bb898558SAl Viro #define ELF_PLAT_INIT(_r, load_addr)			\
17011557b24SOleg Nesterov 	elf_common_init(&current->thread, _r, 0)
171bb898558SAl Viro 
172bb898558SAl Viro #define	COMPAT_ELF_PLAT_INIT(regs, load_addr)		\
173bb898558SAl Viro 	elf_common_init(&current->thread, regs, __USER_DS)
174bb898558SAl Viro 
1752424b146SGabriel Krisman Bertazi void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp, bool x32);
1762424b146SGabriel Krisman Bertazi #define COMPAT_START_THREAD(ex, regs, new_ip, new_sp)	\
1772424b146SGabriel Krisman Bertazi 	compat_start_thread(regs, new_ip, new_sp, ex->e_machine == EM_X86_64)
178bb898558SAl Viro 
179d1a797f3SH. Peter Anvin void set_personality_ia32(bool);
180d1a797f3SH. Peter Anvin #define COMPAT_SET_PERSONALITY(ex)			\
181d1a797f3SH. Peter Anvin 	set_personality_ia32((ex).e_machine == EM_X86_64)
182bb898558SAl Viro 
183bb898558SAl Viro #define COMPAT_ELF_PLATFORM			("i686")
184bb898558SAl Viro 
185bb898558SAl Viro /*
186bb898558SAl Viro  * regs is struct pt_regs, pr_reg is elf_gregset_t (which is
187bb898558SAl Viro  * now struct_user_regs, they are different). Assumes current is the process
188bb898558SAl Viro  * getting dumped.
189bb898558SAl Viro  */
190bb898558SAl Viro 
191bb898558SAl Viro #define ELF_CORE_COPY_REGS(pr_reg, regs)			\
192bb898558SAl Viro do {								\
193bb898558SAl Viro 	unsigned v;						\
194bb898558SAl Viro 	(pr_reg)[0] = (regs)->r15;				\
195bb898558SAl Viro 	(pr_reg)[1] = (regs)->r14;				\
196bb898558SAl Viro 	(pr_reg)[2] = (regs)->r13;				\
197bb898558SAl Viro 	(pr_reg)[3] = (regs)->r12;				\
198bb898558SAl Viro 	(pr_reg)[4] = (regs)->bp;				\
199bb898558SAl Viro 	(pr_reg)[5] = (regs)->bx;				\
200bb898558SAl Viro 	(pr_reg)[6] = (regs)->r11;				\
201bb898558SAl Viro 	(pr_reg)[7] = (regs)->r10;				\
202bb898558SAl Viro 	(pr_reg)[8] = (regs)->r9;				\
203bb898558SAl Viro 	(pr_reg)[9] = (regs)->r8;				\
204bb898558SAl Viro 	(pr_reg)[10] = (regs)->ax;				\
205bb898558SAl Viro 	(pr_reg)[11] = (regs)->cx;				\
206bb898558SAl Viro 	(pr_reg)[12] = (regs)->dx;				\
207bb898558SAl Viro 	(pr_reg)[13] = (regs)->si;				\
208bb898558SAl Viro 	(pr_reg)[14] = (regs)->di;				\
209bb898558SAl Viro 	(pr_reg)[15] = (regs)->orig_ax;				\
210bb898558SAl Viro 	(pr_reg)[16] = (regs)->ip;				\
211bb898558SAl Viro 	(pr_reg)[17] = (regs)->cs;				\
212bb898558SAl Viro 	(pr_reg)[18] = (regs)->flags;				\
213bb898558SAl Viro 	(pr_reg)[19] = (regs)->sp;				\
214bb898558SAl Viro 	(pr_reg)[20] = (regs)->ss;				\
215824eea38SChang S. Bae 	(pr_reg)[21] = x86_fsbase_read_cpu();			\
216824eea38SChang S. Bae 	(pr_reg)[22] = x86_gsbase_read_cpu_inactive();		\
217bb898558SAl Viro 	asm("movl %%ds,%0" : "=r" (v)); (pr_reg)[23] = v;	\
218bb898558SAl Viro 	asm("movl %%es,%0" : "=r" (v)); (pr_reg)[24] = v;	\
219bb898558SAl Viro 	asm("movl %%fs,%0" : "=r" (v)); (pr_reg)[25] = v;	\
220bb898558SAl Viro 	asm("movl %%gs,%0" : "=r" (v)); (pr_reg)[26] = v;	\
221bb898558SAl Viro } while (0);
222bb898558SAl Viro 
223bb898558SAl Viro /* I'm not sure if we can use '-' here */
224bb898558SAl Viro #define ELF_PLATFORM       ("x86_64")
225bb898558SAl Viro extern void set_personality_64bit(void);
226bb898558SAl Viro extern int force_personality32;
227bb898558SAl Viro 
228bb898558SAl Viro #endif /* !CONFIG_X86_32 */
229bb898558SAl Viro 
230bb898558SAl Viro #define CORE_DUMP_USE_REGSET
231bb898558SAl Viro #define ELF_EXEC_PAGESIZE	4096
232bb898558SAl Viro 
233eab09532SKees Cook /*
234eab09532SKees Cook  * This is the base location for PIE (ET_DYN with INTERP) loads. On
235c715b72cSKees Cook  * 64-bit, this is above 4GB to leave the entire 32-bit address
236eab09532SKees Cook  * space open for things that want to use the area for 32-bit pointers.
237eab09532SKees Cook  */
238eab09532SKees Cook #define ELF_ET_DYN_BASE		(mmap_is_ia32() ? 0x000400000UL : \
239be739f4bSKirill A. Shutemov 						  (DEFAULT_MAP_WINDOW / 3 * 2))
240bb898558SAl Viro 
241bb898558SAl Viro /* This yields a mask that user programs can use to figure out what
242bb898558SAl Viro    instruction set this CPU supports.  This could be done in user space,
243bb898558SAl Viro    but it's not easy, and we've already done it here.  */
244bb898558SAl Viro 
24516aaa537SHuaitong Han #define ELF_HWCAP		(boot_cpu_data.x86_capability[CPUID_1_EDX])
246bb898558SAl Viro 
2470274f955SGrzegorz Andrejczuk extern u32 elf_hwcap2;
2480274f955SGrzegorz Andrejczuk 
2490274f955SGrzegorz Andrejczuk /*
2500274f955SGrzegorz Andrejczuk  * HWCAP2 supplies mask with kernel enabled CPU features, so that
2510274f955SGrzegorz Andrejczuk  * the application can discover that it can safely use them.
2520274f955SGrzegorz Andrejczuk  * The bits are defined in uapi/asm/hwcap2.h.
2530274f955SGrzegorz Andrejczuk  */
2540274f955SGrzegorz Andrejczuk #define ELF_HWCAP2		(elf_hwcap2)
2550274f955SGrzegorz Andrejczuk 
256bb898558SAl Viro /* This yields a string that ld.so will use to load implementation
257bb898558SAl Viro    specific libraries for optimization.  This is more specific in
258bb898558SAl Viro    intent than poking at uname or /proc/cpuinfo.
259bb898558SAl Viro 
260bb898558SAl Viro    For the moment, we have only optimizations for the Intel generations,
261bb898558SAl Viro    but that could change... */
262bb898558SAl Viro 
263bb898558SAl Viro #define SET_PERSONALITY(ex) set_personality_64bit()
264bb898558SAl Viro 
265bb898558SAl Viro /*
266bb898558SAl Viro  * An executable for which elf_read_implies_exec() returns TRUE will
267bb898558SAl Viro  * have the READ_IMPLIES_EXEC personality flag set automatically.
2689d9e435fSKees Cook  *
2699d9e435fSKees Cook  * The decision process for determining the results are:
2709d9e435fSKees Cook  *
271c681df88SIngo Molnar  *                 CPU: | lacks NX*  | has NX, ia32     | has NX, x86_64 |
272c681df88SIngo Molnar  * ELF:                 |            |                  |                |
2739d9e435fSKees Cook  * ---------------------|------------|------------------|----------------|
274c681df88SIngo Molnar  * missing PT_GNU_STACK | exec-all   | exec-all         | exec-none      |
275c681df88SIngo Molnar  * PT_GNU_STACK == RWX  | exec-stack | exec-stack       | exec-stack     |
276c681df88SIngo Molnar  * PT_GNU_STACK == RW   | exec-none  | exec-none        | exec-none      |
2779d9e435fSKees Cook  *
2789d9e435fSKees Cook  *  exec-all  : all PROT_READ user mappings are executable, except when
2799d9e435fSKees Cook  *              backed by files on a noexec-filesystem.
2809d9e435fSKees Cook  *  exec-none : only PROT_EXEC user mappings are executable.
28112230611SKees Cook  *  exec-stack: only the stack and PROT_EXEC user mappings are executable.
2829d9e435fSKees Cook  *
2839d9e435fSKees Cook  *  *this column has no architectural effect: NX markings are ignored by
2849d9e435fSKees Cook  *   hardware, but may have behavioral effects when "wants X" collides with
2859d9e435fSKees Cook  *   "cannot be X" constraints in memory permission flags, as in
2869d9e435fSKees Cook  *   https://lkml.kernel.org/r/20190418055759.GA3155@mellanox.com
2879d9e435fSKees Cook  *
288bb898558SAl Viro  */
289bb898558SAl Viro #define elf_read_implies_exec(ex, executable_stack)	\
2909fccc5c0SKees Cook 	(mmap_is_ia32() && executable_stack == EXSTACK_DEFAULT)
291bb898558SAl Viro 
292bb898558SAl Viro struct task_struct;
293bb898558SAl Viro 
2943d7ee969SAndy Lutomirski #define	ARCH_DLINFO_IA32						\
295bb898558SAl Viro do {									\
2966fdc6dd9SThomas Gleixner 	if (VDSO_CURRENT_BASE) {					\
297bb898558SAl Viro 		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);			\
298bb898558SAl Viro 		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE);	\
299bb898558SAl Viro 	}								\
3001c33bb05SChang S. Bae 	NEW_AUX_ENT(AT_MINSIGSTKSZ, get_sigframe_size());		\
301bb898558SAl Viro } while (0)
302bb898558SAl Viro 
3038f3e474fSDmitry Safonov /*
3048f3e474fSDmitry Safonov  * True on X86_32 or when emulating IA32 on X86_64
3058f3e474fSDmitry Safonov  */
mmap_is_ia32(void)3068f3e474fSDmitry Safonov static inline int mmap_is_ia32(void)
3078f3e474fSDmitry Safonov {
3088f3e474fSDmitry Safonov 	return IS_ENABLED(CONFIG_X86_32) ||
3098f3e474fSDmitry Safonov 	       (IS_ENABLED(CONFIG_COMPAT) &&
3108f3e474fSDmitry Safonov 		test_thread_flag(TIF_ADDR32));
3118f3e474fSDmitry Safonov }
3128f3e474fSDmitry Safonov 
313e8f01a8dSKirill A. Shutemov extern unsigned long task_size_32bit(void);
314b569bab7SKirill A. Shutemov extern unsigned long task_size_64bit(int full_addr_space);
315e13b73ddSDmitry Safonov extern unsigned long get_mmap_base(int is_legacy);
3161e0f25dbSKirill A. Shutemov extern bool mmap_address_hint_valid(unsigned long addr, unsigned long len);
3171c33bb05SChang S. Bae extern unsigned long get_sigframe_size(void);
3181b028f78SDmitry Safonov 
319bb898558SAl Viro #ifdef CONFIG_X86_32
320bb898558SAl Viro 
3218f3e474fSDmitry Safonov #define __STACK_RND_MASK(is32bit) (0x7ff)
32280938332SMichal Hocko #define STACK_RND_MASK (0x7ff)
32380938332SMichal Hocko 
3243d7ee969SAndy Lutomirski #define ARCH_DLINFO		ARCH_DLINFO_IA32
325bb898558SAl Viro 
326bb898558SAl Viro /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
327bb898558SAl Viro 
328bb898558SAl Viro #else /* CONFIG_X86_32 */
329bb898558SAl Viro 
330bb898558SAl Viro /* 1GB for 64bit, 8MB for 32bit */
3318f3e474fSDmitry Safonov #define __STACK_RND_MASK(is32bit) ((is32bit) ? 0x7ff : 0x3fffff)
3328f3e474fSDmitry Safonov #define STACK_RND_MASK __STACK_RND_MASK(mmap_is_ia32())
333bb898558SAl Viro 
334bb898558SAl Viro #define ARCH_DLINFO							\
335bb898558SAl Viro do {									\
3363d7ee969SAndy Lutomirski 	if (vdso64_enabled)						\
337bb898558SAl Viro 		NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
3386f121e54SAndy Lutomirski 			    (unsigned long __force)current->mm->context.vdso); \
3391c33bb05SChang S. Bae 	NEW_AUX_ENT(AT_MINSIGSTKSZ, get_sigframe_size());		\
340bb898558SAl Viro } while (0)
341bb898558SAl Viro 
3423d7ee969SAndy Lutomirski /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
343d1a797f3SH. Peter Anvin #define ARCH_DLINFO_X32							\
344d1a797f3SH. Peter Anvin do {									\
3453d7ee969SAndy Lutomirski 	if (vdso64_enabled)						\
346d1a797f3SH. Peter Anvin 		NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
3476f121e54SAndy Lutomirski 			    (unsigned long __force)current->mm->context.vdso); \
3481c33bb05SChang S. Bae 	NEW_AUX_ENT(AT_MINSIGSTKSZ, get_sigframe_size());		\
349d1a797f3SH. Peter Anvin } while (0)
350d1a797f3SH. Peter Anvin 
351bb898558SAl Viro #define AT_SYSINFO		32
352bb898558SAl Viro 
353d1a797f3SH. Peter Anvin #define COMPAT_ARCH_DLINFO						\
3542656af0dSGabriel Krisman Bertazi if (exec->e_machine == EM_X86_64)					\
355d1a797f3SH. Peter Anvin 	ARCH_DLINFO_X32;						\
35685f2ada7SAl Viro else if (IS_ENABLED(CONFIG_IA32_EMULATION))				\
3573d7ee969SAndy Lutomirski 	ARCH_DLINFO_IA32
358bb898558SAl Viro 
359bb898558SAl Viro #define COMPAT_ELF_ET_DYN_BASE	(TASK_UNMAPPED_BASE + 0x1000000)
360bb898558SAl Viro 
361bb898558SAl Viro #endif /* !CONFIG_X86_32 */
362bb898558SAl Viro 
363bb898558SAl Viro #define VDSO_CURRENT_BASE	((unsigned long)current->mm->context.vdso)
364bb898558SAl Viro 
365bb898558SAl Viro #define VDSO_ENTRY							\
3666f121e54SAndy Lutomirski 	((unsigned long)current->mm->context.vdso +			\
3670a6d1fa0SAndy Lutomirski 	 vdso_image_32.sym___kernel_vsyscall)
368bb898558SAl Viro 
369bb898558SAl Viro struct linux_binprm;
370bb898558SAl Viro 
371bb898558SAl Viro #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
372bb898558SAl Viro extern int arch_setup_additional_pages(struct linux_binprm *bprm,
373fc5243d9SMartin Schwidefsky 				       int uses_interp);
37418d0a6fdSAndy Lutomirski extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
3753316ec8cSGabriel Krisman Bertazi 					      int uses_interp, bool x32);
3763316ec8cSGabriel Krisman Bertazi #define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter)	\
3773316ec8cSGabriel Krisman Bertazi 	compat_arch_setup_additional_pages(bprm, interpreter,		\
3783316ec8cSGabriel Krisman Bertazi 					   (ex->e_machine == EM_X86_64))
379bb898558SAl Viro 
380c5c87812SGabriel Krisman Bertazi extern bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs);
381c5c87812SGabriel Krisman Bertazi 
382f9902472SMichel Lespinasse /* Do not change the values. See get_align_mask() */
383dfb09f9bSBorislav Petkov enum align_flags {
384dfb09f9bSBorislav Petkov 	ALIGN_VA_32	= BIT(0),
385dfb09f9bSBorislav Petkov 	ALIGN_VA_64	= BIT(1),
386dfb09f9bSBorislav Petkov };
387dfb09f9bSBorislav Petkov 
388dfb09f9bSBorislav Petkov struct va_alignment {
389dfb09f9bSBorislav Petkov 	int flags;
390dfb09f9bSBorislav Petkov 	unsigned long mask;
3914e26d11fSHector Marco-Gisbert 	unsigned long bits;
392dfb09f9bSBorislav Petkov } ____cacheline_aligned;
393dfb09f9bSBorislav Petkov 
394dfb09f9bSBorislav Petkov extern struct va_alignment va_align;
3951965aae3SH. Peter Anvin #endif /* _ASM_X86_ELF_H */
396