xref: /linux-6.15/include/linux/elf.h (revision bc3d7bf6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_ELF_H
3 #define _LINUX_ELF_H
4 
5 #include <linux/types.h>
6 #include <asm/elf.h>
7 #include <uapi/linux/elf.h>
8 
9 #ifndef elf_read_implies_exec
10   /* Executables for which elf_read_implies_exec() returns TRUE will
11      have the READ_IMPLIES_EXEC personality flag set automatically.
12      Override in asm/elf.h as needed.  */
13 # define elf_read_implies_exec(ex, have_pt_gnu_stack)	0
14 #endif
15 #ifndef SET_PERSONALITY
16 #define SET_PERSONALITY(ex) \
17 	set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
18 #endif
19 
20 #ifndef SET_PERSONALITY2
21 #define SET_PERSONALITY2(ex, state) \
22 	SET_PERSONALITY(ex)
23 #endif
24 
25 #ifndef START_THREAD
26 #define START_THREAD(elf_ex, regs, elf_entry, start_stack)	\
27 	start_thread(regs, elf_entry, start_stack)
28 #endif
29 
30 #define ELF32_GNU_PROPERTY_ALIGN	4
31 #define ELF64_GNU_PROPERTY_ALIGN	8
32 
33 #if ELF_CLASS == ELFCLASS32
34 
35 extern Elf32_Dyn _DYNAMIC [];
36 #define elfhdr		elf32_hdr
37 #define elf_phdr	elf32_phdr
38 #define elf_shdr	elf32_shdr
39 #define elf_note	elf32_note
40 #define elf_addr_t	Elf32_Off
41 #define Elf_Half	Elf32_Half
42 #define Elf_Word	Elf32_Word
43 #define ELF_GNU_PROPERTY_ALIGN	ELF32_GNU_PROPERTY_ALIGN
44 
45 #else
46 
47 extern Elf64_Dyn _DYNAMIC [];
48 #define elfhdr		elf64_hdr
49 #define elf_phdr	elf64_phdr
50 #define elf_shdr	elf64_shdr
51 #define elf_note	elf64_note
52 #define elf_addr_t	Elf64_Off
53 #define Elf_Half	Elf64_Half
54 #define Elf_Word	Elf64_Word
55 #define ELF_GNU_PROPERTY_ALIGN	ELF64_GNU_PROPERTY_ALIGN
56 
57 #endif
58 
59 /* Optional callbacks to write extra ELF notes. */
60 struct file;
61 struct coredump_params;
62 
63 #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
64 static inline int elf_coredump_extra_notes_size(void) { return 0; }
65 static inline int elf_coredump_extra_notes_write(struct coredump_params *cprm) { return 0; }
66 #else
67 extern int elf_coredump_extra_notes_size(void);
68 extern int elf_coredump_extra_notes_write(struct coredump_params *cprm);
69 #endif
70 
71 /*
72  * NT_GNU_PROPERTY_TYPE_0 header:
73  * Keep this internal until/unless there is an agreed UAPI definition.
74  * pr_type values (GNU_PROPERTY_*) are public and defined in the UAPI header.
75  */
76 struct gnu_property {
77 	u32 pr_type;
78 	u32 pr_datasz;
79 };
80 
81 struct arch_elf_state;
82 
83 #ifndef CONFIG_ARCH_USE_GNU_PROPERTY
84 static inline int arch_parse_elf_property(u32 type, const void *data,
85 					  size_t datasz, bool compat,
86 					  struct arch_elf_state *arch)
87 {
88 	return 0;
89 }
90 #else
91 extern int arch_parse_elf_property(u32 type, const void *data, size_t datasz,
92 				   bool compat, struct arch_elf_state *arch);
93 #endif
94 
95 #ifdef CONFIG_ARCH_HAVE_ELF_PROT
96 int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state,
97 			 bool has_interp, bool is_interp);
98 #else
99 static inline int arch_elf_adjust_prot(int prot,
100 				       const struct arch_elf_state *state,
101 				       bool has_interp, bool is_interp)
102 {
103 	return prot;
104 }
105 #endif
106 
107 #endif /* _LINUX_ELF_H */
108