Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * 32-bit compatibility support for ELF format executables and core dumps. |
| 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All rights reserved. |
| 5 | * |
| 6 | * This copyrighted material is made available to anyone wishing to use, |
| 7 | * modify, copy, or redistribute it subject to the terms and conditions |
| 8 | * of the GNU General Public License v.2. |
| 9 | * |
| 10 | * Red Hat Author: Roland McGrath. |
| 11 | * |
| 12 | * This file is used in a 64-bit kernel that wants to support 32-bit ELF. |
| 13 | * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros |
| 14 | * used below, with definitions appropriate for 32-bit ABI compatibility. |
| 15 | * |
| 16 | * We use macros to rename the ABI types and machine-dependent |
| 17 | * functions used in binfmt_elf.c to compat versions. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/elfcore-compat.h> |
| 21 | #include <linux/time.h> |
| 22 | |
| 23 | /* |
| 24 | * Rename the basic ELF layout types to refer to the 32-bit class of files. |
| 25 | */ |
| 26 | #undef ELF_CLASS |
| 27 | #define ELF_CLASS ELFCLASS32 |
| 28 | |
| 29 | #undef elfhdr |
| 30 | #undef elf_phdr |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 31 | #undef elf_shdr |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 32 | #undef elf_note |
| 33 | #undef elf_addr_t |
| 34 | #define elfhdr elf32_hdr |
| 35 | #define elf_phdr elf32_phdr |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 36 | #define elf_shdr elf32_shdr |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 37 | #define elf_note elf32_note |
| 38 | #define elf_addr_t Elf32_Addr |
| 39 | |
| 40 | /* |
Denys Vlasenko | 49ae4d4 | 2012-10-04 17:15:35 -0700 | [diff] [blame] | 41 | * Some data types as stored in coredump. |
| 42 | */ |
Denys Vlasenko | 2aa362c | 2012-10-04 17:15:36 -0700 | [diff] [blame] | 43 | #define user_long_t compat_long_t |
Denys Vlasenko | 49ae4d4 | 2012-10-04 17:15:35 -0700 | [diff] [blame] | 44 | #define user_siginfo_t compat_siginfo_t |
| 45 | #define copy_siginfo_to_user copy_siginfo_to_user32 |
| 46 | |
| 47 | /* |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 48 | * The machine-dependent core note format types are defined in elfcore-compat.h, |
| 49 | * which requires asm/elf.h to define compat_elf_gregset_t et al. |
| 50 | */ |
| 51 | #define elf_prstatus compat_elf_prstatus |
| 52 | #define elf_prpsinfo compat_elf_prpsinfo |
| 53 | |
Arnd Bergmann | 890c52a | 2018-02-19 11:13:23 +0100 | [diff] [blame] | 54 | #ifdef CONFIG_ELF_CORE |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 55 | /* |
| 56 | * Compat version of cputime_to_compat_timeval, perhaps this |
| 57 | * should be an inline in <linux/compat.h>. |
| 58 | */ |
| 59 | static void cputime_to_compat_timeval(const cputime_t cputime, |
| 60 | struct compat_timeval *value) |
| 61 | { |
| 62 | struct timeval tv; |
| 63 | cputime_to_timeval(cputime, &tv); |
| 64 | value->tv_sec = tv.tv_sec; |
| 65 | value->tv_usec = tv.tv_usec; |
| 66 | } |
Arnd Bergmann | 890c52a | 2018-02-19 11:13:23 +0100 | [diff] [blame] | 67 | #endif |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 68 | |
| 69 | #undef cputime_to_timeval |
| 70 | #define cputime_to_timeval cputime_to_compat_timeval |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * To use this file, asm/elf.h must define compat_elf_check_arch. |
| 75 | * The other following macros can be defined if the compat versions |
| 76 | * differ from the native ones, or omitted when they match. |
| 77 | */ |
| 78 | |
| 79 | #undef ELF_ARCH |
| 80 | #undef elf_check_arch |
| 81 | #define elf_check_arch compat_elf_check_arch |
| 82 | |
| 83 | #ifdef COMPAT_ELF_PLATFORM |
| 84 | #undef ELF_PLATFORM |
| 85 | #define ELF_PLATFORM COMPAT_ELF_PLATFORM |
| 86 | #endif |
| 87 | |
| 88 | #ifdef COMPAT_ELF_HWCAP |
| 89 | #undef ELF_HWCAP |
| 90 | #define ELF_HWCAP COMPAT_ELF_HWCAP |
| 91 | #endif |
| 92 | |
Ard Biesheuvel | 66d6e3b | 2014-03-03 07:34:44 +0000 | [diff] [blame] | 93 | #ifdef COMPAT_ELF_HWCAP2 |
| 94 | #undef ELF_HWCAP2 |
| 95 | #define ELF_HWCAP2 COMPAT_ELF_HWCAP2 |
| 96 | #endif |
| 97 | |
Roland McGrath | 2f79e48 | 2008-01-30 13:31:46 +0100 | [diff] [blame] | 98 | #ifdef COMPAT_ARCH_DLINFO |
| 99 | #undef ARCH_DLINFO |
| 100 | #define ARCH_DLINFO COMPAT_ARCH_DLINFO |
| 101 | #endif |
| 102 | |
| 103 | #ifdef COMPAT_ELF_ET_DYN_BASE |
| 104 | #undef ELF_ET_DYN_BASE |
| 105 | #define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE |
| 106 | #endif |
| 107 | |
| 108 | #ifdef COMPAT_ELF_EXEC_PAGESIZE |
| 109 | #undef ELF_EXEC_PAGESIZE |
| 110 | #define ELF_EXEC_PAGESIZE COMPAT_ELF_EXEC_PAGESIZE |
| 111 | #endif |
| 112 | |
| 113 | #ifdef COMPAT_ELF_PLAT_INIT |
| 114 | #undef ELF_PLAT_INIT |
| 115 | #define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT |
| 116 | #endif |
| 117 | |
| 118 | #ifdef COMPAT_SET_PERSONALITY |
| 119 | #undef SET_PERSONALITY |
| 120 | #define SET_PERSONALITY COMPAT_SET_PERSONALITY |
| 121 | #endif |
| 122 | |
| 123 | #ifdef compat_start_thread |
| 124 | #undef start_thread |
| 125 | #define start_thread compat_start_thread |
| 126 | #endif |
| 127 | |
| 128 | #ifdef compat_arch_setup_additional_pages |
| 129 | #undef ARCH_HAS_SETUP_ADDITIONAL_PAGES |
| 130 | #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 |
| 131 | #undef arch_setup_additional_pages |
| 132 | #define arch_setup_additional_pages compat_arch_setup_additional_pages |
| 133 | #endif |
| 134 | |
| 135 | /* |
| 136 | * Rename a few of the symbols that binfmt_elf.c will define. |
| 137 | * These are all local so the names don't really matter, but it |
| 138 | * might make some debugging less confusing not to duplicate them. |
| 139 | */ |
| 140 | #define elf_format compat_elf_format |
| 141 | #define init_elf_binfmt init_compat_elf_binfmt |
| 142 | #define exit_elf_binfmt exit_compat_elf_binfmt |
| 143 | |
| 144 | /* |
| 145 | * We share all the actual code with the native (64-bit) version. |
| 146 | */ |
| 147 | #include "binfmt_elf.c" |