12f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 22f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 32-bit compatibility support for ELF format executables and core dumps. 32f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 42f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * Copyright (C) 2007 Red Hat, Inc. All rights reserved. 52f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 62f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * This copyrighted material is made available to anyone wishing to use, 72f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * modify, copy, or redistribute it subject to the terms and conditions 82f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * of the GNU General Public License v.2. 92f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 102f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * Red Hat Author: Roland McGrath. 112f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 122f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * This file is used in a 64-bit kernel that wants to support 32-bit ELF. 132f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros 142f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * used below, with definitions appropriate for 32-bit ABI compatibility. 152f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * 162f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * We use macros to rename the ABI types and machine-dependent 172f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * functions used in binfmt_elf.c to compat versions. 182f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 192f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 202f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#include <linux/elfcore-compat.h> 212f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#include <linux/time.h> 222f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 232f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 242f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * Rename the basic ELF layout types to refer to the 32-bit class of files. 252f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 262f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_CLASS 272f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_CLASS ELFCLASS32 282f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 292f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef elfhdr 302f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef elf_phdr 311fcccbac89f5bbc5e41aa72086960059fce372daDaisuke HATAYAMA#undef elf_shdr 322f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef elf_note 332f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef elf_addr_t 342f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elfhdr elf32_hdr 352f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_phdr elf32_phdr 361fcccbac89f5bbc5e41aa72086960059fce372daDaisuke HATAYAMA#define elf_shdr elf32_shdr 372f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_note elf32_note 382f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_addr_t Elf32_Addr 392f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 402f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 412f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * The machine-dependent core note format types are defined in elfcore-compat.h, 422f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * which requires asm/elf.h to define compat_elf_gregset_t et al. 432f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 442f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_prstatus compat_elf_prstatus 452f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_prpsinfo compat_elf_prpsinfo 462f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 472f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 482f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * Compat version of cputime_to_compat_timeval, perhaps this 492f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * should be an inline in <linux/compat.h>. 502f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 512f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrathstatic void cputime_to_compat_timeval(const cputime_t cputime, 522f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath struct compat_timeval *value) 532f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath{ 542f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath struct timeval tv; 552f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath cputime_to_timeval(cputime, &tv); 562f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath value->tv_sec = tv.tv_sec; 572f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath value->tv_usec = tv.tv_usec; 582f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath} 592f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 602f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef cputime_to_timeval 612f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define cputime_to_timeval cputime_to_compat_timeval 622f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 632f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 642f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 652f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * To use this file, asm/elf.h must define compat_elf_check_arch. 662f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * The other following macros can be defined if the compat versions 672f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * differ from the native ones, or omitted when they match. 682f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 692f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 702f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_ARCH 712f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef elf_check_arch 722f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_check_arch compat_elf_check_arch 732f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 742f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ELF_PLATFORM 752f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_PLATFORM 762f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_PLATFORM COMPAT_ELF_PLATFORM 772f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 782f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 792f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ELF_HWCAP 802f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_HWCAP 812f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_HWCAP COMPAT_ELF_HWCAP 822f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 832f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 842f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ARCH_DLINFO 852f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ARCH_DLINFO 862f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ARCH_DLINFO COMPAT_ARCH_DLINFO 872f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 882f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 892f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ELF_ET_DYN_BASE 902f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_ET_DYN_BASE 912f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE 922f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 932f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 942f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ELF_EXEC_PAGESIZE 952f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_EXEC_PAGESIZE 962f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_EXEC_PAGESIZE COMPAT_ELF_EXEC_PAGESIZE 972f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 982f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 992f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_ELF_PLAT_INIT 1002f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ELF_PLAT_INIT 1012f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT 1022f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 1032f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 1042f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef COMPAT_SET_PERSONALITY 1052f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef SET_PERSONALITY 1062f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define SET_PERSONALITY COMPAT_SET_PERSONALITY 1072f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 1082f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 1092f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef compat_start_thread 1102f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef start_thread 1112f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define start_thread compat_start_thread 1122f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 1132f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 1142f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#ifdef compat_arch_setup_additional_pages 1152f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES 1162f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 1172f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#undef arch_setup_additional_pages 1182f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define arch_setup_additional_pages compat_arch_setup_additional_pages 1192f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#endif 1202f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 1212f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 1222f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * Rename a few of the symbols that binfmt_elf.c will define. 1232f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * These are all local so the names don't really matter, but it 1242f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * might make some debugging less confusing not to duplicate them. 1252f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 1262f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define elf_format compat_elf_format 1272f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define init_elf_binfmt init_compat_elf_binfmt 1282f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#define exit_elf_binfmt exit_compat_elf_binfmt 1292f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath 1302f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath/* 1312f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath * We share all the actual code with the native (64-bit) version. 1322f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath */ 1332f79e48ae2651fff08d08dab3acf1294467c1155Roland McGrath#include "binfmt_elf.c" 134