145 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*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_* macros11 * used below, with definitions appropriate for 32-bit ABI compatibility.12 *13 * We use macros to rename the ABI types and machine-dependent14 * functions used in binfmt_elf.c to compat versions.15 */16 17#include <linux/elfcore-compat.h>18#include <linux/time.h>19 20#define ELF_COMPAT 121 22/*23 * Rename the basic ELF layout types to refer to the 32-bit class of files.24 */25#undef ELF_CLASS26#define ELF_CLASS ELFCLASS3227 28#undef elfhdr29#undef elf_phdr30#undef elf_shdr31#undef elf_note32#undef elf_addr_t33#undef ELF_GNU_PROPERTY_ALIGN34#define elfhdr elf32_hdr35#define elf_phdr elf32_phdr36#define elf_shdr elf32_shdr37#define elf_note elf32_note38#define elf_addr_t Elf32_Addr39#define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN40 41/*42 * Some data types as stored in coredump.43 */44#define user_long_t compat_long_t45#define user_siginfo_t compat_siginfo_t46#define copy_siginfo_to_external copy_siginfo_to_external3247 48/*49 * The machine-dependent core note format types are defined in elfcore-compat.h,50 * which requires asm/elf.h to define compat_elf_gregset_t et al.51 */52#define elf_prstatus compat_elf_prstatus53#define elf_prstatus_common compat_elf_prstatus_common54#define elf_prpsinfo compat_elf_prpsinfo55 56#undef ns_to_kernel_old_timeval57#define ns_to_kernel_old_timeval ns_to_old_timeval3258 59/*60 * To use this file, asm/elf.h must define compat_elf_check_arch.61 * The other following macros can be defined if the compat versions62 * differ from the native ones, or omitted when they match.63 */64 65#undef elf_check_arch66#define elf_check_arch compat_elf_check_arch67 68#ifdef COMPAT_ELF_PLATFORM69#undef ELF_PLATFORM70#define ELF_PLATFORM COMPAT_ELF_PLATFORM71#endif72 73#ifdef COMPAT_ELF_HWCAP74#undef ELF_HWCAP75#define ELF_HWCAP COMPAT_ELF_HWCAP76#endif77 78#ifdef COMPAT_ELF_HWCAP279#undef ELF_HWCAP280#define ELF_HWCAP2 COMPAT_ELF_HWCAP281#endif82 83#ifdef COMPAT_ARCH_DLINFO84#undef ARCH_DLINFO85#define ARCH_DLINFO COMPAT_ARCH_DLINFO86#endif87 88#ifdef COMPAT_ELF_ET_DYN_BASE89#undef ELF_ET_DYN_BASE90#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE91#endif92 93#ifdef COMPAT_ELF_PLAT_INIT94#undef ELF_PLAT_INIT95#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT96#endif97 98#ifdef COMPAT_SET_PERSONALITY99#undef SET_PERSONALITY100#define SET_PERSONALITY COMPAT_SET_PERSONALITY101#endif102 103#ifdef compat_start_thread104#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \105 compat_start_thread(regs, new_ip, new_sp)106#endif107 108#ifdef COMPAT_START_THREAD109#undef START_THREAD110#define START_THREAD COMPAT_START_THREAD111#endif112 113#ifdef compat_arch_setup_additional_pages114#define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \115 compat_arch_setup_additional_pages(bprm, interpreter)116#endif117 118#ifdef COMPAT_ARCH_SETUP_ADDITIONAL_PAGES119#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES120#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1121#undef ARCH_SETUP_ADDITIONAL_PAGES122#define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES123#endif124 125#ifdef compat_elf_read_implies_exec126#undef elf_read_implies_exec127#define elf_read_implies_exec compat_elf_read_implies_exec128#endif129 130/*131 * Rename a few of the symbols that binfmt_elf.c will define.132 * These are all local so the names don't really matter, but it133 * might make some debugging less confusing not to duplicate them.134 */135#define elf_format compat_elf_format136#define init_elf_binfmt init_compat_elf_binfmt137#define exit_elf_binfmt exit_compat_elf_binfmt138#define binfmt_elf_test_cases compat_binfmt_elf_test_cases139#define binfmt_elf_test_suite compat_binfmt_elf_test_suite140 141/*142 * We share all the actual code with the native (64-bit) version.143 */144#include "binfmt_elf.c"145