compat_binfmt_elf.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * 32-bit compatibility support for ELF format executables and core dumps.
  4. *
  5. * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
  6. *
  7. * Red Hat Author: Roland McGrath.
  8. *
  9. * This file is used in a 64-bit kernel that wants to support 32-bit ELF.
  10. * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros
  11. * used below, with definitions appropriate for 32-bit ABI compatibility.
  12. *
  13. * We use macros to rename the ABI types and machine-dependent
  14. * functions used in binfmt_elf.c to compat versions.
  15. */
  16. #include <linux/elfcore-compat.h>
  17. #include <linux/time.h>
  18. #define ELF_COMPAT 1
  19. /*
  20. * Rename the basic ELF layout types to refer to the 32-bit class of files.
  21. */
  22. #undef ELF_CLASS
  23. #define ELF_CLASS ELFCLASS32
  24. #undef elfhdr
  25. #undef elf_phdr
  26. #undef elf_shdr
  27. #undef elf_note
  28. #undef elf_addr_t
  29. #undef ELF_GNU_PROPERTY_ALIGN
  30. #define elfhdr elf32_hdr
  31. #define elf_phdr elf32_phdr
  32. #define elf_shdr elf32_shdr
  33. #define elf_note elf32_note
  34. #define elf_addr_t Elf32_Addr
  35. #define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN
  36. /*
  37. * Some data types as stored in coredump.
  38. */
  39. #define user_long_t compat_long_t
  40. #define user_siginfo_t compat_siginfo_t
  41. #define copy_siginfo_to_external copy_siginfo_to_external32
  42. /*
  43. * The machine-dependent core note format types are defined in elfcore-compat.h,
  44. * which requires asm/elf.h to define compat_elf_gregset_t et al.
  45. */
  46. #define elf_prstatus compat_elf_prstatus
  47. #define elf_prstatus_common compat_elf_prstatus_common
  48. #define elf_prpsinfo compat_elf_prpsinfo
  49. #undef ns_to_kernel_old_timeval
  50. #define ns_to_kernel_old_timeval ns_to_old_timeval32
  51. /*
  52. * To use this file, asm/elf.h must define compat_elf_check_arch.
  53. * The other following macros can be defined if the compat versions
  54. * differ from the native ones, or omitted when they match.
  55. */
  56. #undef elf_check_arch
  57. #define elf_check_arch compat_elf_check_arch
  58. #ifdef COMPAT_ELF_PLATFORM
  59. #undef ELF_PLATFORM
  60. #define ELF_PLATFORM COMPAT_ELF_PLATFORM
  61. #endif
  62. #ifdef COMPAT_ELF_HWCAP
  63. #undef ELF_HWCAP
  64. #define ELF_HWCAP COMPAT_ELF_HWCAP
  65. #endif
  66. #ifdef COMPAT_ELF_HWCAP2
  67. #undef ELF_HWCAP2
  68. #define ELF_HWCAP2 COMPAT_ELF_HWCAP2
  69. #endif
  70. #ifdef COMPAT_ARCH_DLINFO
  71. #undef ARCH_DLINFO
  72. #define ARCH_DLINFO COMPAT_ARCH_DLINFO
  73. #endif
  74. #ifdef COMPAT_ELF_ET_DYN_BASE
  75. #undef ELF_ET_DYN_BASE
  76. #define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
  77. #endif
  78. #ifdef COMPAT_ELF_PLAT_INIT
  79. #undef ELF_PLAT_INIT
  80. #define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT
  81. #endif
  82. #ifdef COMPAT_SET_PERSONALITY
  83. #undef SET_PERSONALITY
  84. #define SET_PERSONALITY COMPAT_SET_PERSONALITY
  85. #endif
  86. #ifdef compat_start_thread
  87. #define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \
  88. compat_start_thread(regs, new_ip, new_sp)
  89. #endif
  90. #ifdef COMPAT_START_THREAD
  91. #undef START_THREAD
  92. #define START_THREAD COMPAT_START_THREAD
  93. #endif
  94. #ifdef compat_arch_setup_additional_pages
  95. #define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \
  96. compat_arch_setup_additional_pages(bprm, interpreter)
  97. #endif
  98. #ifdef COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
  99. #undef ARCH_HAS_SETUP_ADDITIONAL_PAGES
  100. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
  101. #undef ARCH_SETUP_ADDITIONAL_PAGES
  102. #define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
  103. #endif
  104. #ifdef compat_elf_read_implies_exec
  105. #undef elf_read_implies_exec
  106. #define elf_read_implies_exec compat_elf_read_implies_exec
  107. #endif
  108. /*
  109. * Rename a few of the symbols that binfmt_elf.c will define.
  110. * These are all local so the names don't really matter, but it
  111. * might make some debugging less confusing not to duplicate them.
  112. */
  113. #define elf_format compat_elf_format
  114. #define init_elf_binfmt init_compat_elf_binfmt
  115. #define exit_elf_binfmt exit_compat_elf_binfmt
  116. #define binfmt_elf_test_cases compat_binfmt_elf_test_cases
  117. #define binfmt_elf_test_suite compat_binfmt_elf_test_suite
  118. /*
  119. * We share all the actual code with the native (64-bit) version.
  120. */
  121. #include "binfmt_elf.c"