Efiemu stylistic fixes and gettext.

* grub-core/efiemu/i386/loadcore32.c
	(grub_arch_efiemu_relocate_symbols32): Avoid set in if.
	* grub-core/efiemu/i386/loadcore64.c
	(grub_arch_efiemu_relocate_symbols64): Likewise.
	* grub-core/efiemu/i386/pc/cfgtables.c
	(grub_machine_efiemu_init_tables): Likewise.
	* grub-core/efiemu/loadcore.c (grub_efiemu_resolve_symbols): Likewise.
	(grub_efiemu_loadcore_initXX): Add a filename argument.
	All users updated.
	Improved error message.
	* grub-core/efiemu/loadcore_common.c (grub_efiemu_loadcore_init):
	Add a filename argument.
	All users updated.
	* grub-core/efiemu/symbols.c (grub_efiemu_set_virtual_address_map):
	Reclassify double relocation as GRUB_ERR_BUG.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-12 18:43:39 +01:00
parent 306fc0741f
commit 0331e102c9
9 changed files with 102 additions and 45 deletions

View file

@ -1,3 +1,23 @@
2012-02-12 Vladimir Serbinenko <phcoder@gmail.com>
Efiemu stylistic fixes and gettext.
* grub-core/efiemu/i386/loadcore32.c
(grub_arch_efiemu_relocate_symbols32): Avoid set in if.
* grub-core/efiemu/i386/loadcore64.c
(grub_arch_efiemu_relocate_symbols64): Likewise.
* grub-core/efiemu/i386/pc/cfgtables.c
(grub_machine_efiemu_init_tables): Likewise.
* grub-core/efiemu/loadcore.c (grub_efiemu_resolve_symbols): Likewise.
(grub_efiemu_loadcore_initXX): Add a filename argument.
All users updated.
Improved error message.
* grub-core/efiemu/loadcore_common.c (grub_efiemu_loadcore_init):
Add a filename argument.
All users updated.
* grub-core/efiemu/symbols.c (grub_efiemu_set_virtual_address_map):
Reclassify double relocation as GRUB_ERR_BUG.
2012-02-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/i386/pc/play.c (grub_cmd_play): Improve error

View file

@ -87,18 +87,23 @@ grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
switch (ELF32_R_TYPE (rel->r_info))
{
case R_386_32:
if ((err = grub_efiemu_write_value
(addr, sym.off + *addr, sym.handle, 0,
seg->ptv_rel_needed, sizeof (grub_uint32_t))))
err = grub_efiemu_write_value (addr, sym.off + *addr,
sym.handle, 0,
seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
case R_386_PC32:
if ((err = grub_efiemu_write_value
(addr, sym.off + *addr - rel->r_offset
- seg->off, sym.handle, seg->handle,
seg->ptv_rel_needed, sizeof (grub_uint32_t))))
err = grub_efiemu_write_value (addr, sym.off + *addr
- rel->r_offset
- seg->off, sym.handle,
seg->handle,
seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
default:

View file

@ -88,25 +88,35 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
switch (ELF64_R_TYPE (rel->r_info))
{
case R_X86_64_64:
if ((err = grub_efiemu_write_value
(addr, *addr64 + rel->r_addend + sym.off, sym.handle,
0, seg->ptv_rel_needed, sizeof (grub_uint64_t))))
err = grub_efiemu_write_value (addr,
*addr64 + rel->r_addend
+ sym.off, sym.handle,
0, seg->ptv_rel_needed,
sizeof (grub_uint64_t));
if (err)
return err;
break;
case R_X86_64_PC32:
if ((err = grub_efiemu_write_value
(addr, *addr32 + rel->r_addend + sym.off
- rel->r_offset - seg->off, sym.handle, seg->handle,
seg->ptv_rel_needed, sizeof (grub_uint32_t))))
err = grub_efiemu_write_value (addr,
*addr32 + rel->r_addend
+ sym.off
- rel->r_offset - seg->off,
sym.handle, seg->handle,
seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
case R_X86_64_32:
case R_X86_64_32S:
if ((err = grub_efiemu_write_value
(addr, *addr32 + rel->r_addend + sym.off, sym.handle,
0, seg->ptv_rel_needed, sizeof (grub_uint32_t))))
err = grub_efiemu_write_value (addr,
*addr32 + rel->r_addend
+ sym.off, sym.handle,
0, seg->ptv_rel_needed,
sizeof (grub_uint32_t));
if (err)
return err;
break;
default:

View file

@ -67,7 +67,8 @@ grub_machine_efiemu_init_tables (void)
if (ptr < (grub_uint8_t *) 0x100000)
{
grub_dprintf ("efiemu", "Registering SMBIOS\n");
if ((err = grub_efiemu_register_configuration_table (smbios, 0, 0, ptr)))
err = grub_efiemu_register_configuration_table (smbios, 0, 0, ptr);
if (err)
return err;
}

View file

@ -120,9 +120,9 @@ grub_efiemu_get_string (unsigned offset, const Elf_Ehdr *e)
unsigned i;
Elf_Shdr *s;
for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff);
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_STRTAB && offset < s->sh_size)
return (char *) e + s->sh_offset + offset;
return 0;
@ -135,9 +135,9 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e)
unsigned i;
Elf_Shdr *s;
for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff);
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
{
if (s->sh_flags & SHF_ALLOC)
{
@ -257,7 +257,8 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
/* Resolve a global symbol. */
if (sym->st_name != 0 && sym->st_shndx == 0)
{
if ((err = grub_efiemu_resolve_symbol (name, &handle, &off)))
err = grub_efiemu_resolve_symbol (name, &handle, &off);
if (err)
return err;
grub_efiemu_elfsyms[i].handle = handle;
grub_efiemu_elfsyms[i].off = off;
@ -267,34 +268,43 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
break;
case STT_OBJECT:
if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off)))
err = grub_efiemu_get_section_addr (segs, sym->st_shndx,
&handle, &off);
if (err)
return err;
off += sym->st_value;
if (bind != STB_LOCAL)
if ((err = grub_efiemu_register_symbol (name, handle, off)))
return err;
{
err = grub_efiemu_register_symbol (name, handle, off);
if (err)
return err;
}
grub_efiemu_elfsyms[i].handle = handle;
grub_efiemu_elfsyms[i].off = off;
break;
case STT_FUNC:
if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off)))
err = grub_efiemu_get_section_addr (segs, sym->st_shndx,
&handle, &off);
if (err)
return err;
off += sym->st_value;
if (bind != STB_LOCAL)
if ((err = grub_efiemu_register_symbol (name, handle, off)))
return err;
{
err = grub_efiemu_register_symbol (name, handle, off);
if (err)
return err;
}
grub_efiemu_elfsyms[i].handle = handle;
grub_efiemu_elfsyms[i].off = off;
break;
case STT_SECTION:
if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off)))
err = grub_efiemu_get_section_addr (segs, sym->st_shndx,
&handle, &off);
if (err)
{
grub_efiemu_elfsyms[i].handle = 0;
grub_efiemu_elfsyms[i].off = 0;
@ -322,7 +332,8 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
/* Load runtime to the memory and request memory for definitive location*/
grub_err_t
SUFFIX (grub_efiemu_loadcore_init) (void *core, grub_size_t core_size,
SUFFIX (grub_efiemu_loadcore_init) (void *core, const char *filename,
grub_size_t core_size,
grub_efiemu_segment_t *segments)
{
Elf_Ehdr *e = (Elf_Ehdr *) core;
@ -333,11 +344,14 @@ SUFFIX (grub_efiemu_loadcore_init) (void *core, grub_size_t core_size,
/* Make sure that every section is within the core. */
if ((grub_size_t) core_size < e->e_shoff + e->e_shentsize * e->e_shnum)
return grub_error (GRUB_ERR_BAD_OS, "ELF sections outside core");
return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
filename);
if ((err = grub_efiemu_init_segments (segments, core)))
err = grub_efiemu_init_segments (segments, core);
if (err)
return err;
if ((err = grub_efiemu_count_symbols (core)))
err = grub_efiemu_count_symbols (core);
if (err)
return err;
grub_efiemu_request_symbols (1);

View file

@ -111,7 +111,8 @@ grub_efiemu_loadcore_unload(void)
/* Load runtime file and do some initial preparations */
grub_err_t
grub_efiemu_loadcore_init (grub_file_t file)
grub_efiemu_loadcore_init (grub_file_t file,
const char *filename)
{
grub_err_t err;
@ -140,7 +141,8 @@ grub_efiemu_loadcore_init (grub_file_t file)
switch (grub_efiemu_mode)
{
case GRUB_EFIEMU32:
err = grub_efiemu_loadcore_init32 (efiemu_core, efiemu_core_size,
err = grub_efiemu_loadcore_init32 (efiemu_core, filename,
efiemu_core_size,
&efiemu_segments);
if (err)
{
@ -152,7 +154,8 @@ grub_efiemu_loadcore_init (grub_file_t file)
break;
case GRUB_EFIEMU64:
err = grub_efiemu_loadcore_init64 (efiemu_core, efiemu_core_size,
err = grub_efiemu_loadcore_init64 (efiemu_core, filename,
efiemu_core_size,
&efiemu_segments);
if (err)
{

View file

@ -201,7 +201,7 @@ grub_efiemu_load_file (const char *filename)
grub_dprintf ("efiemu", "mm initialized\n");
err = grub_efiemu_loadcore_init (file);
err = grub_efiemu_loadcore_init (file, filename);
if (err)
{
grub_file_close (file);

View file

@ -223,7 +223,7 @@ grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
/* Ensure that we are called only once */
if (*ptv_relocated)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "EfiEmu is already relocated");
return grub_error (GRUB_ERR_BUG, "EfiEmu is already relocated");
*ptv_relocated = 1;
/* Correct addresses using information supplied by grub */

View file

@ -152,9 +152,12 @@ struct grub_efiemu_elf_sym
int grub_efiemu_check_header32 (void *ehdr, grub_size_t size);
int grub_efiemu_check_header64 (void *ehdr, grub_size_t size);
grub_err_t grub_efiemu_loadcore_init32 (void *core, grub_size_t core_size,
grub_err_t grub_efiemu_loadcore_init32 (void *core,
const char *filename,
grub_size_t core_size,
grub_efiemu_segment_t *segments);
grub_err_t grub_efiemu_loadcore_init64 (void *core, grub_size_t core_size,
grub_err_t grub_efiemu_loadcore_init64 (void *core, const char *filename,
grub_size_t core_size,
grub_efiemu_segment_t *segments);
grub_err_t grub_efiemu_loadcore_load32 (void *core,
grub_size_t core_size,
@ -165,7 +168,8 @@ grub_err_t grub_efiemu_loadcore_load64 (void *core,
grub_err_t grub_efiemu_loadcore_unload32 (void);
grub_err_t grub_efiemu_loadcore_unload64 (void);
grub_err_t grub_efiemu_loadcore_unload(void);
grub_err_t grub_efiemu_loadcore_init (grub_file_t file);
grub_err_t grub_efiemu_loadcore_init (grub_file_t file,
const char *filename);
grub_err_t grub_efiemu_loadcore_load (void);
/* Configuration tables manipulation. Definitions and functions */