1 |
/* multiboot.c - boot a multiboot OS image. */ |
/* multiboot.c - boot a multiboot OS image. */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
140 |
|
|
141 |
ehdr = (Elf32_Ehdr *) buffer; |
ehdr = (Elf32_Ehdr *) buffer; |
142 |
|
|
143 |
if (!((ehdr->e_ident[EI_MAG0] == ELFMAG0) |
if (grub_dl_check_header (ehdr, sizeof(*ehdr))) |
|
&& (ehdr->e_ident[EI_MAG1] == ELFMAG1) |
|
|
&& (ehdr->e_ident[EI_MAG2] == ELFMAG2) |
|
|
&& (ehdr->e_ident[EI_MAG3] == ELFMAG3) |
|
|
&& (ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
|
|
&& (ehdr->e_ident[EI_DATA] == ELFDATA2LSB) |
|
|
&& (ehdr->e_ident[EI_VERSION] == EV_CURRENT) |
|
|
&& (ehdr->e_type == ET_EXEC) && (ehdr->e_machine == EM_386) |
|
|
&& (ehdr->e_version == EV_CURRENT))) |
|
144 |
{ |
{ |
145 |
grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found"); |
grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found"); |
146 |
goto fail; |
goto fail; |
147 |
} |
} |
148 |
|
|
149 |
|
if (ehdr->e_type != ET_EXEC) |
150 |
|
{ |
151 |
|
grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type"); |
152 |
|
goto fail; |
153 |
|
} |
154 |
|
|
155 |
/* FIXME: Should we support program headers at strange locations? */ |
/* FIXME: Should we support program headers at strange locations? */ |
156 |
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH) |
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH) |
157 |
{ |
{ |