elf.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define ELF32_GNU_PROPERTY_ALIGN 4
  22. #define ELF64_GNU_PROPERTY_ALIGN 8
  23. #if ELF_CLASS == ELFCLASS32
  24. extern Elf32_Dyn _DYNAMIC [];
  25. #define elfhdr elf32_hdr
  26. #define elf_phdr elf32_phdr
  27. #define elf_shdr elf32_shdr
  28. #define elf_note elf32_note
  29. #define elf_addr_t Elf32_Off
  30. #define Elf_Half Elf32_Half
  31. #define Elf_Word Elf32_Word
  32. #define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN
  33. #else
  34. extern Elf64_Dyn _DYNAMIC [];
  35. #define elfhdr elf64_hdr
  36. #define elf_phdr elf64_phdr
  37. #define elf_shdr elf64_shdr
  38. #define elf_note elf64_note
  39. #define elf_addr_t Elf64_Off
  40. #define Elf_Half Elf64_Half
  41. #define Elf_Word Elf64_Word
  42. #define ELF_GNU_PROPERTY_ALIGN ELF64_GNU_PROPERTY_ALIGN
  43. #endif
  44. /* Optional callbacks to write extra ELF notes. */
  45. struct file;
  46. struct coredump_params;
  47. #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
  48. static inline int elf_coredump_extra_notes_size(void) { return 0; }
  49. static inline int elf_coredump_extra_notes_write(struct coredump_params *cprm) { return 0; }
  50. #else
  51. extern int elf_coredump_extra_notes_size(void);
  52. extern int elf_coredump_extra_notes_write(struct coredump_params *cprm);
  53. #endif
  54. /*
  55. * NT_GNU_PROPERTY_TYPE_0 header:
  56. * Keep this internal until/unless there is an agreed UAPI definition.
  57. * pr_type values (GNU_PROPERTY_*) are public and defined in the UAPI header.
  58. */
  59. struct gnu_property {
  60. u32 pr_type;
  61. u32 pr_datasz;
  62. };
  63. struct arch_elf_state;
  64. #ifndef CONFIG_ARCH_USE_GNU_PROPERTY
  65. static inline int arch_parse_elf_property(u32 type, const void *data,
  66. size_t datasz, bool compat,
  67. struct arch_elf_state *arch)
  68. {
  69. return 0;
  70. }
  71. #else
  72. extern int arch_parse_elf_property(u32 type, const void *data, size_t datasz,
  73. bool compat, struct arch_elf_state *arch);
  74. #endif
  75. #ifdef CONFIG_ARCH_HAVE_ELF_PROT
  76. int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state,
  77. bool has_interp, bool is_interp);
  78. #else
  79. static inline int arch_elf_adjust_prot(int prot,
  80. const struct arch_elf_state *state,
  81. bool has_interp, bool is_interp)
  82. {
  83. return prot;
  84. }
  85. #endif
  86. #endif /* _LINUX_ELF_H */