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