Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * 32-bit compatibility support for ELF format executables and core dumps.
0004  *
0005  * Copyright (C) 2007 Red Hat, Inc.  All rights reserved.
0006  *
0007  * Red Hat Author: Roland McGrath.
0008  *
0009  * This file is used in a 64-bit kernel that wants to support 32-bit ELF.
0010  * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros
0011  * used below, with definitions appropriate for 32-bit ABI compatibility.
0012  *
0013  * We use macros to rename the ABI types and machine-dependent
0014  * functions used in binfmt_elf.c to compat versions.
0015  */
0016 
0017 #include <linux/elfcore-compat.h>
0018 #include <linux/time.h>
0019 
0020 #define ELF_COMPAT  1
0021 
0022 /*
0023  * Rename the basic ELF layout types to refer to the 32-bit class of files.
0024  */
0025 #undef  ELF_CLASS
0026 #define ELF_CLASS   ELFCLASS32
0027 
0028 #undef  elfhdr
0029 #undef  elf_phdr
0030 #undef  elf_shdr
0031 #undef  elf_note
0032 #undef  elf_addr_t
0033 #undef  ELF_GNU_PROPERTY_ALIGN
0034 #define elfhdr      elf32_hdr
0035 #define elf_phdr    elf32_phdr
0036 #define elf_shdr    elf32_shdr
0037 #define elf_note    elf32_note
0038 #define elf_addr_t  Elf32_Addr
0039 #define ELF_GNU_PROPERTY_ALIGN  ELF32_GNU_PROPERTY_ALIGN
0040 
0041 /*
0042  * Some data types as stored in coredump.
0043  */
0044 #define user_long_t     compat_long_t
0045 #define user_siginfo_t      compat_siginfo_t
0046 #define copy_siginfo_to_external    copy_siginfo_to_external32
0047 
0048 /*
0049  * The machine-dependent core note format types are defined in elfcore-compat.h,
0050  * which requires asm/elf.h to define compat_elf_gregset_t et al.
0051  */
0052 #define elf_prstatus    compat_elf_prstatus
0053 #define elf_prstatus_common compat_elf_prstatus_common
0054 #define elf_prpsinfo    compat_elf_prpsinfo
0055 
0056 #undef ns_to_kernel_old_timeval
0057 #define ns_to_kernel_old_timeval ns_to_old_timeval32
0058 
0059 /*
0060  * To use this file, asm/elf.h must define compat_elf_check_arch.
0061  * The other following macros can be defined if the compat versions
0062  * differ from the native ones, or omitted when they match.
0063  */
0064 
0065 #undef  elf_check_arch
0066 #define elf_check_arch  compat_elf_check_arch
0067 
0068 #ifdef  COMPAT_ELF_PLATFORM
0069 #undef  ELF_PLATFORM
0070 #define ELF_PLATFORM        COMPAT_ELF_PLATFORM
0071 #endif
0072 
0073 #ifdef  COMPAT_ELF_HWCAP
0074 #undef  ELF_HWCAP
0075 #define ELF_HWCAP       COMPAT_ELF_HWCAP
0076 #endif
0077 
0078 #ifdef  COMPAT_ELF_HWCAP2
0079 #undef  ELF_HWCAP2
0080 #define ELF_HWCAP2      COMPAT_ELF_HWCAP2
0081 #endif
0082 
0083 #ifdef  COMPAT_ARCH_DLINFO
0084 #undef  ARCH_DLINFO
0085 #define ARCH_DLINFO     COMPAT_ARCH_DLINFO
0086 #endif
0087 
0088 #ifdef  COMPAT_ELF_ET_DYN_BASE
0089 #undef  ELF_ET_DYN_BASE
0090 #define ELF_ET_DYN_BASE     COMPAT_ELF_ET_DYN_BASE
0091 #endif
0092 
0093 #ifdef  COMPAT_ELF_PLAT_INIT
0094 #undef  ELF_PLAT_INIT
0095 #define ELF_PLAT_INIT       COMPAT_ELF_PLAT_INIT
0096 #endif
0097 
0098 #ifdef  COMPAT_SET_PERSONALITY
0099 #undef  SET_PERSONALITY
0100 #define SET_PERSONALITY     COMPAT_SET_PERSONALITY
0101 #endif
0102 
0103 #ifdef  compat_start_thread
0104 #define COMPAT_START_THREAD(ex, regs, new_ip, new_sp)   \
0105     compat_start_thread(regs, new_ip, new_sp)
0106 #endif
0107 
0108 #ifdef  COMPAT_START_THREAD
0109 #undef  START_THREAD
0110 #define START_THREAD        COMPAT_START_THREAD
0111 #endif
0112 
0113 #ifdef compat_arch_setup_additional_pages
0114 #define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \
0115     compat_arch_setup_additional_pages(bprm, interpreter)
0116 #endif
0117 
0118 #ifdef  COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
0119 #undef  ARCH_HAS_SETUP_ADDITIONAL_PAGES
0120 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
0121 #undef  ARCH_SETUP_ADDITIONAL_PAGES
0122 #define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
0123 #endif
0124 
0125 #ifdef  compat_elf_read_implies_exec
0126 #undef  elf_read_implies_exec
0127 #define elf_read_implies_exec compat_elf_read_implies_exec
0128 #endif
0129 
0130 /*
0131  * Rename a few of the symbols that binfmt_elf.c will define.
0132  * These are all local so the names don't really matter, but it
0133  * might make some debugging less confusing not to duplicate them.
0134  */
0135 #define elf_format      compat_elf_format
0136 #define init_elf_binfmt     init_compat_elf_binfmt
0137 #define exit_elf_binfmt     exit_compat_elf_binfmt
0138 #define binfmt_elf_test_cases   compat_binfmt_elf_test_cases
0139 #define binfmt_elf_test_suite   compat_binfmt_elf_test_suite
0140 
0141 /*
0142  * We share all the actual code with the native (64-bit) version.
0143  */
0144 #include "binfmt_elf.c"