18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 32-bit compatibility support for ELF format executables and core dumps. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2007 Red Hat, Inc. All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Red Hat Author: Roland McGrath. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This file is used in a 64-bit kernel that wants to support 32-bit ELF. 108c2ecf20Sopenharmony_ci * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros 118c2ecf20Sopenharmony_ci * used below, with definitions appropriate for 32-bit ABI compatibility. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * We use macros to rename the ABI types and machine-dependent 148c2ecf20Sopenharmony_ci * functions used in binfmt_elf.c to compat versions. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/elfcore-compat.h> 188c2ecf20Sopenharmony_ci#include <linux/time.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define ELF_COMPAT 1 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * Rename the basic ELF layout types to refer to the 32-bit class of files. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci#undef ELF_CLASS 268c2ecf20Sopenharmony_ci#define ELF_CLASS ELFCLASS32 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#undef elfhdr 298c2ecf20Sopenharmony_ci#undef elf_phdr 308c2ecf20Sopenharmony_ci#undef elf_shdr 318c2ecf20Sopenharmony_ci#undef elf_note 328c2ecf20Sopenharmony_ci#undef elf_addr_t 338c2ecf20Sopenharmony_ci#undef ELF_GNU_PROPERTY_ALIGN 348c2ecf20Sopenharmony_ci#define elfhdr elf32_hdr 358c2ecf20Sopenharmony_ci#define elf_phdr elf32_phdr 368c2ecf20Sopenharmony_ci#define elf_shdr elf32_shdr 378c2ecf20Sopenharmony_ci#define elf_note elf32_note 388c2ecf20Sopenharmony_ci#define elf_addr_t Elf32_Addr 398c2ecf20Sopenharmony_ci#define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * Some data types as stored in coredump. 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci#define user_long_t compat_long_t 458c2ecf20Sopenharmony_ci#define user_siginfo_t compat_siginfo_t 468c2ecf20Sopenharmony_ci#define copy_siginfo_to_external copy_siginfo_to_external32 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* 498c2ecf20Sopenharmony_ci * The machine-dependent core note format types are defined in elfcore-compat.h, 508c2ecf20Sopenharmony_ci * which requires asm/elf.h to define compat_elf_gregset_t et al. 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define elf_prstatus compat_elf_prstatus 538c2ecf20Sopenharmony_ci#define elf_prpsinfo compat_elf_prpsinfo 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#undef ns_to_kernel_old_timeval 568c2ecf20Sopenharmony_ci#define ns_to_kernel_old_timeval ns_to_old_timeval32 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * To use this file, asm/elf.h must define compat_elf_check_arch. 608c2ecf20Sopenharmony_ci * The other following macros can be defined if the compat versions 618c2ecf20Sopenharmony_ci * differ from the native ones, or omitted when they match. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#undef ELF_ARCH 658c2ecf20Sopenharmony_ci#undef elf_check_arch 668c2ecf20Sopenharmony_ci#define elf_check_arch compat_elf_check_arch 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_PLATFORM 698c2ecf20Sopenharmony_ci#undef ELF_PLATFORM 708c2ecf20Sopenharmony_ci#define ELF_PLATFORM COMPAT_ELF_PLATFORM 718c2ecf20Sopenharmony_ci#endif 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_HWCAP 748c2ecf20Sopenharmony_ci#undef ELF_HWCAP 758c2ecf20Sopenharmony_ci#define ELF_HWCAP COMPAT_ELF_HWCAP 768c2ecf20Sopenharmony_ci#endif 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_HWCAP2 798c2ecf20Sopenharmony_ci#undef ELF_HWCAP2 808c2ecf20Sopenharmony_ci#define ELF_HWCAP2 COMPAT_ELF_HWCAP2 818c2ecf20Sopenharmony_ci#endif 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#ifdef COMPAT_ARCH_DLINFO 848c2ecf20Sopenharmony_ci#undef ARCH_DLINFO 858c2ecf20Sopenharmony_ci#define ARCH_DLINFO COMPAT_ARCH_DLINFO 868c2ecf20Sopenharmony_ci#endif 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_ET_DYN_BASE 898c2ecf20Sopenharmony_ci#undef ELF_ET_DYN_BASE 908c2ecf20Sopenharmony_ci#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE 918c2ecf20Sopenharmony_ci#endif 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_EXEC_PAGESIZE 948c2ecf20Sopenharmony_ci#undef ELF_EXEC_PAGESIZE 958c2ecf20Sopenharmony_ci#define ELF_EXEC_PAGESIZE COMPAT_ELF_EXEC_PAGESIZE 968c2ecf20Sopenharmony_ci#endif 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#ifdef COMPAT_ELF_PLAT_INIT 998c2ecf20Sopenharmony_ci#undef ELF_PLAT_INIT 1008c2ecf20Sopenharmony_ci#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT 1018c2ecf20Sopenharmony_ci#endif 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#ifdef COMPAT_SET_PERSONALITY 1048c2ecf20Sopenharmony_ci#undef SET_PERSONALITY 1058c2ecf20Sopenharmony_ci#define SET_PERSONALITY COMPAT_SET_PERSONALITY 1068c2ecf20Sopenharmony_ci#endif 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#ifdef compat_start_thread 1098c2ecf20Sopenharmony_ci#undef start_thread 1108c2ecf20Sopenharmony_ci#define start_thread compat_start_thread 1118c2ecf20Sopenharmony_ci#endif 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#ifdef compat_arch_setup_additional_pages 1148c2ecf20Sopenharmony_ci#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES 1158c2ecf20Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 1168c2ecf20Sopenharmony_ci#undef arch_setup_additional_pages 1178c2ecf20Sopenharmony_ci#define arch_setup_additional_pages compat_arch_setup_additional_pages 1188c2ecf20Sopenharmony_ci#endif 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#ifdef compat_elf_read_implies_exec 1218c2ecf20Sopenharmony_ci#undef elf_read_implies_exec 1228c2ecf20Sopenharmony_ci#define elf_read_implies_exec compat_elf_read_implies_exec 1238c2ecf20Sopenharmony_ci#endif 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* 1268c2ecf20Sopenharmony_ci * Rename a few of the symbols that binfmt_elf.c will define. 1278c2ecf20Sopenharmony_ci * These are all local so the names don't really matter, but it 1288c2ecf20Sopenharmony_ci * might make some debugging less confusing not to duplicate them. 1298c2ecf20Sopenharmony_ci */ 1308c2ecf20Sopenharmony_ci#define elf_format compat_elf_format 1318c2ecf20Sopenharmony_ci#define init_elf_binfmt init_compat_elf_binfmt 1328c2ecf20Sopenharmony_ci#define exit_elf_binfmt exit_compat_elf_binfmt 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* 1358c2ecf20Sopenharmony_ci * We share all the actual code with the native (64-bit) version. 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci#include "binfmt_elf.c" 138