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