exec_elf32.c revision 1.141
11.141Smaxv/* $NetBSD: exec_elf32.c,v 1.141 2014/07/22 08:18:33 maxv Exp $ */ 21.1Sfvdl 31.1Sfvdl/* 41.9Scgd * Copyright (c) 1996 Christopher G. Demetriou 51.1Sfvdl * All rights reserved. 61.1Sfvdl * 71.1Sfvdl * Redistribution and use in source and binary forms, with or without 81.1Sfvdl * modification, are permitted provided that the following conditions 91.1Sfvdl * are met: 101.1Sfvdl * 1. Redistributions of source code must retain the above copyright 111.1Sfvdl * notice, this list of conditions and the following disclaimer. 121.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 131.1Sfvdl * notice, this list of conditions and the following disclaimer in the 141.1Sfvdl * documentation and/or other materials provided with the distribution. 151.137Sad * 3. All advertising materials mentioning features or use of this software 161.137Sad * must display the following acknowledgement: 171.137Sad * This product includes software developed by Christopher G. Demetriou 181.137Sad * for the NetBSD Project. 191.137Sad * 4. The name of the author may not be used to endorse or promote products 201.1Sfvdl * derived from this software without specific prior written permission 211.1Sfvdl * 221.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 231.1Sfvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Sfvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Sfvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 261.1Sfvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 271.1Sfvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281.1Sfvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291.1Sfvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301.1Sfvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 311.1Sfvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Sfvdl */ 331.69Slukem 341.69Slukem#include <sys/cdefs.h> 351.141Smaxv__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.141 2014/07/22 08:18:33 maxv Exp $"); 361.30Sthorpej 371.137Sad#define ELFSIZE 32 381.8Schristos 391.137Sad#include "exec_elf.c" 401.90Schristos 411.137Sad#include <sys/module.h> 421.128Schristos 431.137Sad#define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \ 441.137Sad sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1)) 451.137Sad 461.137Sad#ifdef COREDUMP 471.137Sad#define DEP "coredump" 481.137Sad#else 491.137Sad#define DEP NULL 501.137Sad#endif 511.137Sad 521.138SchristosMODULE(MODULE_CLASS_EXEC, exec_elf32, DEP); 531.137Sad 541.137Sadstatic struct execsw exec_elf32_execsw[] = { 551.139Schristos { 561.139Schristos .es_hdrsz = sizeof (Elf32_Ehdr), 571.139Schristos .es_makecmds = exec_elf32_makecmds, 581.139Schristos .u = { 591.139Schristos .elf_probe_func = netbsd_elf32_probe, 601.139Schristos }, 611.139Schristos .es_emul = &emul_netbsd, 621.141Smaxv .es_prio = EXECSW_PRIO_FIRST, 631.139Schristos .es_arglen = ELF32_AUXSIZE, 641.139Schristos .es_copyargs = elf32_copyargs, 651.139Schristos .es_setregs = NULL, 661.139Schristos .es_coredump = coredump_elf32, 671.140Srjs .es_setup_stack = exec_setup_stack, 681.139Schristos }, 691.137Sad#if EXEC_ELF_NOTELESS 701.139Schristos { 711.139Schristos .es_hdrsz = sizeof (Elf32_Ehdr), 721.139Schristos .es_makecmds = exec_elf32_makecmds, 731.139Schristos .u { 741.139Schristos elf_probe_func = NULL, 751.139Schristos }, 761.139Schristos .es_emul = &emul_netbsd, 771.139Schristos .es_prio = EXECSW_PRIO_LAST, 781.139Schristos .es_arglen = ELF32_AUXSIZE, 791.139Schristos .es_copyargs = elf32_copyargs, 801.139Schristos .es_setregs = NULL, 811.139Schristos .es_coredump = coredump_elf32, 821.139Schristos .es_setup_stack = exec_setup_stack, 831.139Schristos }, 841.137Sad#endif 851.137Sad}; 861.137Sad 871.137Sadstatic int 881.137Sadexec_elf32_modcmd(modcmd_t cmd, void *arg) 891.137Sad{ 901.141Smaxv#if ARCH_ELFSIZE == 64 911.141Smaxv /* 921.141Smaxv * If we are on a 64bit system, we don't want the 32bit execsw[] to be 931.141Smaxv * added in the global array, because the exec_elf32 module only works 941.141Smaxv * on 32bit systems. 951.141Smaxv * 961.141Smaxv * However, we need the exec_elf32 module, because it will make the 32bit 971.141Smaxv * functions available for netbsd32 and linux32. 981.141Smaxv * 991.141Smaxv * Therefore, allow this module on 64bit systems, but make it dormant. 1001.141Smaxv */ 1011.137Sad 1021.141Smaxv (void)exec_elf32_execsw; /* unused */ 1031.141Smaxv 1041.141Smaxv switch (cmd) { 1051.141Smaxv case MODULE_CMD_INIT: 1061.141Smaxv case MODULE_CMD_FINI: 1071.141Smaxv return 0; 1081.141Smaxv default: 1091.141Smaxv return ENOTTY; 1101.141Smaxv } 1111.141Smaxv#else /* ARCH_ELFSIZE == 64 */ 1121.137Sad switch (cmd) { 1131.137Sad case MODULE_CMD_INIT: 1141.137Sad return exec_add(exec_elf32_execsw, 1151.137Sad __arraycount(exec_elf32_execsw)); 1161.137Sad 1171.137Sad case MODULE_CMD_FINI: 1181.137Sad return exec_remove(exec_elf32_execsw, 1191.137Sad __arraycount(exec_elf32_execsw)); 1201.1Sfvdl 1211.1Sfvdl default: 1221.137Sad return ENOTTY; 1231.137Sad } 1241.141Smaxv#endif /* ARCH_ELFSIZE == 64 */ 1251.1Sfvdl} 126