Improve gettext support. Stylistic fixes and error handling fixes while
on it.
This commit is contained in:
parent
215c90cb82
commit
9c4b5c13e6
184 changed files with 1175 additions and 959 deletions
|
@ -49,26 +49,25 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
||||
CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
|
||||
{
|
||||
Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
|
||||
char *phdr_base;
|
||||
int i;
|
||||
|
||||
if (ehdr->e_ident[EI_CLASS] != ELFCLASSXX)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF class");
|
||||
|
||||
if (ehdr->e_ident[EI_MAG0] != ELFMAG0
|
||||
|| ehdr->e_ident[EI_MAG1] != ELFMAG1
|
||||
|| ehdr->e_ident[EI_MAG2] != ELFMAG2
|
||||
|| ehdr->e_ident[EI_MAG3] != ELFMAG3
|
||||
|| ehdr->e_version != EV_CURRENT
|
||||
|| ehdr->e_ident[EI_DATA] != ELFDATA2LSB
|
||||
|| ehdr->e_machine != E_MACHINE)
|
||||
return grub_error(GRUB_ERR_UNKNOWN_OS, "no valid ELF header found");
|
||||
|| ehdr->e_ident[EI_DATA] != ELFDATA2LSB)
|
||||
return grub_error(GRUB_ERR_UNKNOWN_OS, N_("invalid arch independent ELF magic"));
|
||||
|
||||
if (ehdr->e_ident[EI_CLASS] != ELFCLASSXX || ehdr->e_machine != E_MACHINE
|
||||
|| ehdr->e_version != EV_CURRENT)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch dependent ELF magic"));
|
||||
|
||||
if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type");
|
||||
return grub_error (GRUB_ERR_UNKNOWN_OS, N_("this ELF file is not of the right type"));
|
||||
|
||||
/* FIXME: Should we support program headers at strange locations? */
|
||||
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH)
|
||||
|
@ -115,13 +114,16 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
|||
{
|
||||
if (grub_file_seek (file, (grub_off_t) phdr(i)->p_offset)
|
||||
== (grub_off_t) -1)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"invalid offset in program header");
|
||||
return grub_errno;
|
||||
|
||||
if (grub_file_read (file, source, phdr(i)->p_filesz)
|
||||
!= (grub_ssize_t) phdr(i)->p_filesz)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"couldn't read segment from file");
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
filename);
|
||||
return grub_errno;
|
||||
}
|
||||
}
|
||||
|
||||
if (phdr(i)->p_filesz < phdr(i)->p_memsz)
|
||||
|
@ -159,13 +161,16 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
|||
return grub_errno;
|
||||
|
||||
if (grub_file_seek (file, ehdr->e_shoff) == (grub_off_t) -1)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"invalid offset to section headers");
|
||||
return grub_errno;
|
||||
|
||||
if (grub_file_read (file, shdr, ehdr->e_shnum * ehdr->e_shentsize)
|
||||
!= (grub_ssize_t) ehdr->e_shnum * ehdr->e_shentsize)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"couldn't read sections headers from file");
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
filename);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
for (shdrptr = shdr, i = 0; i < ehdr->e_shnum;
|
||||
shdrptr += ehdr->e_shentsize, i++)
|
||||
|
@ -202,13 +207,16 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
|||
}
|
||||
|
||||
if (grub_file_seek (file, sh->sh_offset) == (grub_off_t) -1)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"invalid offset in section header");
|
||||
return grub_errno;
|
||||
|
||||
if (grub_file_read (file, src, sh->sh_size)
|
||||
!= (grub_ssize_t) sh->sh_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"couldn't read segment from file");
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
filename);
|
||||
return grub_errno;
|
||||
}
|
||||
sh->sh_addr = target;
|
||||
}
|
||||
grub_multiboot_add_elfsyms (ehdr->e_shnum, ehdr->e_shentsize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue