162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * 32-bit compatibility support for ELF format executables and core dumps. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2007 Red Hat, Inc. All rights reserved. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Red Hat Author: Roland McGrath. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This file is used in a 64-bit kernel that wants to support 32-bit ELF. 1062306a36Sopenharmony_ci * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros 1162306a36Sopenharmony_ci * used below, with definitions appropriate for 32-bit ABI compatibility. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * We use macros to rename the ABI types and machine-dependent 1462306a36Sopenharmony_ci * functions used in binfmt_elf.c to compat versions. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <linux/elfcore-compat.h> 1862306a36Sopenharmony_ci#include <linux/time.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define ELF_COMPAT 1 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * Rename the basic ELF layout types to refer to the 32-bit class of files. 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci#undef ELF_CLASS 2662306a36Sopenharmony_ci#define ELF_CLASS ELFCLASS32 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#undef elfhdr 2962306a36Sopenharmony_ci#undef elf_phdr 3062306a36Sopenharmony_ci#undef elf_shdr 3162306a36Sopenharmony_ci#undef elf_note 3262306a36Sopenharmony_ci#undef elf_addr_t 3362306a36Sopenharmony_ci#undef ELF_GNU_PROPERTY_ALIGN 3462306a36Sopenharmony_ci#define elfhdr elf32_hdr 3562306a36Sopenharmony_ci#define elf_phdr elf32_phdr 3662306a36Sopenharmony_ci#define elf_shdr elf32_shdr 3762306a36Sopenharmony_ci#define elf_note elf32_note 3862306a36Sopenharmony_ci#define elf_addr_t Elf32_Addr 3962306a36Sopenharmony_ci#define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * Some data types as stored in coredump. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define user_long_t compat_long_t 4562306a36Sopenharmony_ci#define user_siginfo_t compat_siginfo_t 4662306a36Sopenharmony_ci#define copy_siginfo_to_external copy_siginfo_to_external32 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 4962306a36Sopenharmony_ci * The machine-dependent core note format types are defined in elfcore-compat.h, 5062306a36Sopenharmony_ci * which requires asm/elf.h to define compat_elf_gregset_t et al. 5162306a36Sopenharmony_ci */ 5262306a36Sopenharmony_ci#define elf_prstatus compat_elf_prstatus 5362306a36Sopenharmony_ci#define elf_prstatus_common compat_elf_prstatus_common 5462306a36Sopenharmony_ci#define elf_prpsinfo compat_elf_prpsinfo 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#undef ns_to_kernel_old_timeval 5762306a36Sopenharmony_ci#define ns_to_kernel_old_timeval ns_to_old_timeval32 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* 6062306a36Sopenharmony_ci * To use this file, asm/elf.h must define compat_elf_check_arch. 6162306a36Sopenharmony_ci * The other following macros can be defined if the compat versions 6262306a36Sopenharmony_ci * differ from the native ones, or omitted when they match. 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#undef elf_check_arch 6662306a36Sopenharmony_ci#define elf_check_arch compat_elf_check_arch 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#ifdef COMPAT_ELF_PLATFORM 6962306a36Sopenharmony_ci#undef ELF_PLATFORM 7062306a36Sopenharmony_ci#define ELF_PLATFORM COMPAT_ELF_PLATFORM 7162306a36Sopenharmony_ci#endif 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#ifdef COMPAT_ELF_HWCAP 7462306a36Sopenharmony_ci#undef ELF_HWCAP 7562306a36Sopenharmony_ci#define ELF_HWCAP COMPAT_ELF_HWCAP 7662306a36Sopenharmony_ci#endif 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#ifdef COMPAT_ELF_HWCAP2 7962306a36Sopenharmony_ci#undef ELF_HWCAP2 8062306a36Sopenharmony_ci#define ELF_HWCAP2 COMPAT_ELF_HWCAP2 8162306a36Sopenharmony_ci#endif 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#ifdef COMPAT_ARCH_DLINFO 8462306a36Sopenharmony_ci#undef ARCH_DLINFO 8562306a36Sopenharmony_ci#define ARCH_DLINFO COMPAT_ARCH_DLINFO 8662306a36Sopenharmony_ci#endif 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci#ifdef COMPAT_ELF_ET_DYN_BASE 8962306a36Sopenharmony_ci#undef ELF_ET_DYN_BASE 9062306a36Sopenharmony_ci#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE 9162306a36Sopenharmony_ci#endif 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#ifdef COMPAT_ELF_PLAT_INIT 9462306a36Sopenharmony_ci#undef ELF_PLAT_INIT 9562306a36Sopenharmony_ci#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT 9662306a36Sopenharmony_ci#endif 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#ifdef COMPAT_SET_PERSONALITY 9962306a36Sopenharmony_ci#undef SET_PERSONALITY 10062306a36Sopenharmony_ci#define SET_PERSONALITY COMPAT_SET_PERSONALITY 10162306a36Sopenharmony_ci#endif 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#ifdef compat_start_thread 10462306a36Sopenharmony_ci#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \ 10562306a36Sopenharmony_ci compat_start_thread(regs, new_ip, new_sp) 10662306a36Sopenharmony_ci#endif 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#ifdef COMPAT_START_THREAD 10962306a36Sopenharmony_ci#undef START_THREAD 11062306a36Sopenharmony_ci#define START_THREAD COMPAT_START_THREAD 11162306a36Sopenharmony_ci#endif 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci#ifdef compat_arch_setup_additional_pages 11462306a36Sopenharmony_ci#define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \ 11562306a36Sopenharmony_ci compat_arch_setup_additional_pages(bprm, interpreter) 11662306a36Sopenharmony_ci#endif 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#ifdef COMPAT_ARCH_SETUP_ADDITIONAL_PAGES 11962306a36Sopenharmony_ci#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES 12062306a36Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 12162306a36Sopenharmony_ci#undef ARCH_SETUP_ADDITIONAL_PAGES 12262306a36Sopenharmony_ci#define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES 12362306a36Sopenharmony_ci#endif 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci#ifdef compat_elf_read_implies_exec 12662306a36Sopenharmony_ci#undef elf_read_implies_exec 12762306a36Sopenharmony_ci#define elf_read_implies_exec compat_elf_read_implies_exec 12862306a36Sopenharmony_ci#endif 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* 13162306a36Sopenharmony_ci * Rename a few of the symbols that binfmt_elf.c will define. 13262306a36Sopenharmony_ci * These are all local so the names don't really matter, but it 13362306a36Sopenharmony_ci * might make some debugging less confusing not to duplicate them. 13462306a36Sopenharmony_ci */ 13562306a36Sopenharmony_ci#define elf_format compat_elf_format 13662306a36Sopenharmony_ci#define init_elf_binfmt init_compat_elf_binfmt 13762306a36Sopenharmony_ci#define exit_elf_binfmt exit_compat_elf_binfmt 13862306a36Sopenharmony_ci#define binfmt_elf_test_cases compat_binfmt_elf_test_cases 13962306a36Sopenharmony_ci#define binfmt_elf_test_suite compat_binfmt_elf_test_suite 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/* 14262306a36Sopenharmony_ci * We share all the actual code with the native (64-bit) version. 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_ci#include "binfmt_elf.c" 145