exec_elf32.c revision 1.139
11.139Schristos/*	$NetBSD: exec_elf32.c,v 1.139 2014/03/07 01:34:29 christos 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.139Schristos__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.139 2014/03/07 01:34:29 christos 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.139Schristos		.es_prio = EXECSW_PRIO_ANY,
631.139Schristos		.es_arglen = ELF32_AUXSIZE,
641.139Schristos		.es_copyargs = elf32_copyargs,
651.139Schristos		.es_setregs = NULL,
661.139Schristos		.es_coredump = coredump_elf32,
671.139Schristos		.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.137Sad
911.137Sad	switch (cmd) {
921.137Sad	case MODULE_CMD_INIT:
931.137Sad		return exec_add(exec_elf32_execsw,
941.137Sad		    __arraycount(exec_elf32_execsw));
951.137Sad
961.137Sad	case MODULE_CMD_FINI:
971.137Sad		return exec_remove(exec_elf32_execsw,
981.137Sad		    __arraycount(exec_elf32_execsw));
991.1Sfvdl
1001.1Sfvdl	default:
1011.137Sad		return ENOTTY;
1021.137Sad        }
1031.1Sfvdl}
104