compat_binfmt_elf.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * 32-bit compatibility support for ELF format executables and core dumps.
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
  5. *
  6. * This copyrighted material is made available to anyone wishing to use,
  7. * modify, copy, or redistribute it subject to the terms and conditions
  8. * of the GNU General Public License v.2.
  9. *
  10. * Red Hat Author: Roland McGrath.
  11. *
  12. * This file is used in a 64-bit kernel that wants to support 32-bit ELF.
  13. * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros
  14. * used below, with definitions appropriate for 32-bit ABI compatibility.
  15. *
  16. * We use macros to rename the ABI types and machine-dependent
  17. * functions used in binfmt_elf.c to compat versions.
  18. */
  19. #include <linux/elfcore-compat.h>
  20. #include <linux/time.h>
  21. /*
  22. * Rename the basic ELF layout types to refer to the 32-bit class of files.
  23. */
  24. #undef ELF_CLASS
  25. #define ELF_CLASS ELFCLASS32
  26. #undef elfhdr
  27. #undef elf_phdr
  28. #undef elf_shdr
  29. #undef elf_note
  30. #undef elf_addr_t
  31. #define elfhdr elf32_hdr
  32. #define elf_phdr elf32_phdr
  33. #define elf_shdr elf32_shdr
  34. #define elf_note elf32_note
  35. #define elf_addr_t Elf32_Addr
  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_user copy_siginfo_to_user32
  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_prpsinfo compat_elf_prpsinfo
  48. /*
  49. * Compat version of cputime_to_compat_timeval, perhaps this
  50. * should be an inline in <linux/compat.h>.
  51. */
  52. static void cputime_to_compat_timeval(const cputime_t cputime,
  53. struct compat_timeval *value)
  54. {
  55. struct timeval tv;
  56. cputime_to_timeval(cputime, &tv);
  57. value->tv_sec = tv.tv_sec;
  58. value->tv_usec = tv.tv_usec;
  59. }
  60. #undef cputime_to_timeval
  61. #define cputime_to_timeval cputime_to_compat_timeval
  62. /*
  63. * To use this file, asm/elf.h must define compat_elf_check_arch.
  64. * The other following macros can be defined if the compat versions
  65. * differ from the native ones, or omitted when they match.
  66. */
  67. #undef ELF_ARCH
  68. #undef elf_check_arch
  69. #define elf_check_arch compat_elf_check_arch
  70. #ifdef COMPAT_ELF_PLATFORM
  71. #undef ELF_PLATFORM
  72. #define ELF_PLATFORM COMPAT_ELF_PLATFORM
  73. #endif
  74. #ifdef COMPAT_ELF_HWCAP
  75. #undef ELF_HWCAP
  76. #define ELF_HWCAP COMPAT_ELF_HWCAP
  77. #endif
  78. #ifdef COMPAT_ELF_HWCAP2
  79. #undef ELF_HWCAP2
  80. #define ELF_HWCAP2 COMPAT_ELF_HWCAP2
  81. #endif
  82. #ifdef COMPAT_ARCH_DLINFO
  83. #undef ARCH_DLINFO
  84. #define ARCH_DLINFO COMPAT_ARCH_DLINFO
  85. #endif
  86. #ifdef COMPAT_ELF_ET_DYN_BASE
  87. #undef ELF_ET_DYN_BASE
  88. #define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
  89. #endif
  90. #ifdef COMPAT_ELF_EXEC_PAGESIZE
  91. #undef ELF_EXEC_PAGESIZE
  92. #define ELF_EXEC_PAGESIZE COMPAT_ELF_EXEC_PAGESIZE
  93. #endif
  94. #ifdef COMPAT_ELF_PLAT_INIT
  95. #undef ELF_PLAT_INIT
  96. #define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT
  97. #endif
  98. #ifdef COMPAT_SET_PERSONALITY
  99. #undef SET_PERSONALITY
  100. #define SET_PERSONALITY COMPAT_SET_PERSONALITY
  101. #endif
  102. #ifdef compat_start_thread
  103. #undef start_thread
  104. #define start_thread compat_start_thread
  105. #endif
  106. #ifdef compat_arch_setup_additional_pages
  107. #undef ARCH_HAS_SETUP_ADDITIONAL_PAGES
  108. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
  109. #undef arch_setup_additional_pages
  110. #define arch_setup_additional_pages compat_arch_setup_additional_pages
  111. #endif
  112. /*
  113. * Rename a few of the symbols that binfmt_elf.c will define.
  114. * These are all local so the names don't really matter, but it
  115. * might make some debugging less confusing not to duplicate them.
  116. */
  117. #define elf_format compat_elf_format
  118. #define init_elf_binfmt init_compat_elf_binfmt
  119. #define exit_elf_binfmt exit_compat_elf_binfmt
  120. /*
  121. * We share all the actual code with the native (64-bit) version.
  122. */
  123. #include "binfmt_elf.c"