Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_ELF_H |
| 3 | #define _LINUX_ELF_H |
| 4 | |
Dave Martin | db751e3 | 2020-03-16 16:50:43 +0000 | [diff] [blame] | 5 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/elf.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 7 | #include <uapi/linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
David Howells | 267aed9 | 2011-12-12 13:54:36 +0000 | [diff] [blame] | 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 |
Al Viro | e72837e | 2013-02-17 17:47:04 -0500 | [diff] [blame] | 15 | #ifndef SET_PERSONALITY |
| 16 | #define SET_PERSONALITY(ex) \ |
| 17 | set_personality(PER_LINUX | (current->personality & (~PER_MASK))) |
| 18 | #endif |
David Howells | 267aed9 | 2011-12-12 13:54:36 +0000 | [diff] [blame] | 19 | |
Paul Burton | 774c105 | 2014-09-11 08:30:16 +0100 | [diff] [blame] | 20 | #ifndef SET_PERSONALITY2 |
| 21 | #define SET_PERSONALITY2(ex, state) \ |
| 22 | SET_PERSONALITY(ex) |
| 23 | #endif |
| 24 | |
Dave Martin | 00e19ce | 2020-03-16 16:50:44 +0000 | [diff] [blame] | 25 | #define ELF32_GNU_PROPERTY_ALIGN 4 |
| 26 | #define ELF64_GNU_PROPERTY_ALIGN 8 |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #if ELF_CLASS == ELFCLASS32 |
| 29 | |
| 30 | extern Elf32_Dyn _DYNAMIC []; |
| 31 | #define elfhdr elf32_hdr |
| 32 | #define elf_phdr elf32_phdr |
Daisuke HATAYAMA | 8d9032b | 2010-03-05 13:44:10 -0800 | [diff] [blame] | 33 | #define elf_shdr elf32_shdr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define elf_note elf32_note |
Magnus Damm | 386d9a7 | 2006-12-06 20:37:53 -0800 | [diff] [blame] | 35 | #define elf_addr_t Elf32_Off |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 36 | #define Elf_Half Elf32_Half |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 37 | #define Elf_Word Elf32_Word |
Dave Martin | 00e19ce | 2020-03-16 16:50:44 +0000 | [diff] [blame] | 38 | #define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #else |
| 41 | |
| 42 | extern Elf64_Dyn _DYNAMIC []; |
| 43 | #define elfhdr elf64_hdr |
| 44 | #define elf_phdr elf64_phdr |
Daisuke HATAYAMA | 8d9032b | 2010-03-05 13:44:10 -0800 | [diff] [blame] | 45 | #define elf_shdr elf64_shdr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define elf_note elf64_note |
Magnus Damm | 386d9a7 | 2006-12-06 20:37:53 -0800 | [diff] [blame] | 47 | #define elf_addr_t Elf64_Off |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 48 | #define Elf_Half Elf64_Half |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 49 | #define Elf_Word Elf64_Word |
Dave Martin | 00e19ce | 2020-03-16 16:50:44 +0000 | [diff] [blame] | 50 | #define ELF_GNU_PROPERTY_ALIGN ELF64_GNU_PROPERTY_ALIGN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #endif |
| 53 | |
Michael Ellerman | e550149 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 54 | /* Optional callbacks to write extra ELF notes. */ |
David Howells | 267aed9 | 2011-12-12 13:54:36 +0000 | [diff] [blame] | 55 | struct file; |
Al Viro | cdc3d56 | 2013-10-05 22:24:29 -0400 | [diff] [blame] | 56 | struct coredump_params; |
David Howells | 267aed9 | 2011-12-12 13:54:36 +0000 | [diff] [blame] | 57 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 58 | #ifndef ARCH_HAVE_EXTRA_ELF_NOTES |
Michael Ellerman | e550149 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 59 | static inline int elf_coredump_extra_notes_size(void) { return 0; } |
Al Viro | cdc3d56 | 2013-10-05 22:24:29 -0400 | [diff] [blame] | 60 | static inline int elf_coredump_extra_notes_write(struct coredump_params *cprm) { return 0; } |
Michael Ellerman | e550149 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 61 | #else |
| 62 | extern int elf_coredump_extra_notes_size(void); |
Al Viro | cdc3d56 | 2013-10-05 22:24:29 -0400 | [diff] [blame] | 63 | extern int elf_coredump_extra_notes_write(struct coredump_params *cprm); |
Michael Ellerman | e550149 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 64 | #endif |
Dave Martin | db751e3 | 2020-03-16 16:50:43 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | * NT_GNU_PROPERTY_TYPE_0 header: |
| 68 | * Keep this internal until/unless there is an agreed UAPI definition. |
| 69 | * pr_type values (GNU_PROPERTY_*) are public and defined in the UAPI header. |
| 70 | */ |
| 71 | struct gnu_property { |
| 72 | u32 pr_type; |
| 73 | u32 pr_datasz; |
| 74 | }; |
| 75 | |
Dave Martin | 00e19ce | 2020-03-16 16:50:44 +0000 | [diff] [blame] | 76 | struct arch_elf_state; |
| 77 | |
| 78 | #ifndef CONFIG_ARCH_USE_GNU_PROPERTY |
| 79 | static inline int arch_parse_elf_property(u32 type, const void *data, |
| 80 | size_t datasz, bool compat, |
| 81 | struct arch_elf_state *arch) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | #else |
| 86 | extern int arch_parse_elf_property(u32 type, const void *data, size_t datasz, |
| 87 | bool compat, struct arch_elf_state *arch); |
| 88 | #endif |
| 89 | |
Dave Martin | fe0f676 | 2020-03-16 16:50:46 +0000 | [diff] [blame] | 90 | #ifdef CONFIG_ARCH_HAVE_ELF_PROT |
| 91 | int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state, |
| 92 | bool has_interp, bool is_interp); |
| 93 | #else |
| 94 | static inline int arch_elf_adjust_prot(int prot, |
| 95 | const struct arch_elf_state *state, |
| 96 | bool has_interp, bool is_interp) |
| 97 | { |
| 98 | return prot; |
| 99 | } |
| 100 | #endif |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #endif /* _LINUX_ELF_H */ |