Define ELF32_EHDR_FLAGS_OK()/ELF64_EHDR_FLAGS_OK() and use it

as an added measure to make sure that we can execute a binary.
These default to (1) if elf_machdep.h does not override them.

On Sun2, ELF32_EHDR_FLAGS_OK() checks for the presense of EF_M68000,
since the 68010 cannot run binaries for the 68020-and-up.
This commit is contained in:
thorpej 2002-01-28 22:15:54 +00:00
parent 3ee53752e9
commit 07d023a3aa
3 changed files with 27 additions and 4 deletions

View File

@ -1,8 +1,14 @@
/* $NetBSD: elf_machdep.h,v 1.4 2002/01/28 21:52:49 thorpej Exp $ */
/* $NetBSD: elf_machdep.h,v 1.5 2002/01/28 22:15:55 thorpej Exp $ */
#ifndef _MACHINE_ELF_MACHDEP_H_
#define _MACHINE_ELF_MACHDEP_H_
#include <m68k/elf_machdep.h>
/*
* The 68010 can't execute binaries for 68020-and-up.
*/
#define ELF32_EHDR_FLAGS_OK(eh) \
(((eh)->e_flags & EF_M68000) != 0)
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec_elf32.c,v 1.69 2001/11/12 15:25:03 lukem Exp $ */
/* $NetBSD: exec_elf32.c,v 1.70 2002/01/28 22:15:55 thorpej Exp $ */
/*-
* Copyright (c) 1994, 2000 The NetBSD Foundation, Inc.
@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.69 2001/11/12 15:25:03 lukem Exp $");
__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.70 2002/01/28 22:15:55 thorpej Exp $");
/* If not included by exec_elf64.c, ELFSIZE won't be defined. */
#ifndef ELFSIZE
@ -192,6 +192,9 @@ ELFNAME(check_header)(Elf_Ehdr *eh, int type)
return (ENOEXEC);
}
if (ELF_EHDR_FLAGS_OK(eh) == 0)
return (ENOEXEC);
if (eh->e_type != type)
return (ENOEXEC);

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec_elf.h,v 1.59 2001/12/09 23:06:00 thorpej Exp $ */
/* $NetBSD: exec_elf.h,v 1.60 2002/01/28 22:15:54 thorpej Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -772,6 +772,20 @@ struct netbsd_elfcore_procinfo {
#define ELF_NO_ADDR ELF32_NO_ADDR
#endif
#ifndef ELF32_EHDR_FLAGS_OK
#define ELF32_EHDR_FLAGS_OK(eh) 1
#endif
#ifndef ELF64_EHDR_FLAGS_OK
#define ELF64_EHDR_FLAGS_OK(eh) 1
#endif
#if defined(ELFSIZE) && (ELFSIZE == 64)
#define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh)
#else
#define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh)
#endif
#if defined(ELFSIZE)
struct elf_args {
Elf_Addr arg_entry; /* program entry point */