elf.h 3.0 KB

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