diff options
author | Michael Brown | 2007-01-12 00:43:29 +0100 |
---|---|---|
committer | Michael Brown | 2007-01-12 00:43:29 +0100 |
commit | f59ad50504ae8b12f32f528f1d39a7b638b75501 (patch) | |
tree | b69a1755ac5fdbdd765ba1bc8a899e97c4cdd865 /src/image | |
parent | alloca() can be useful in some (limited) circumstances. (diff) | |
download | ipxe-f59ad50504ae8b12f32f528f1d39a7b638b75501.tar.gz ipxe-f59ad50504ae8b12f32f528f1d39a7b638b75501.tar.xz ipxe-f59ad50504ae8b12f32f528f1d39a7b638b75501.zip |
Provide registration mechanism for loaded images, so that we can e.g.
refer to them by name from the command line, or build them into a
multiboot module list.
Use setting image->type to disambiguate between "not my image" and "bad
image"; this avoids relying on specific values of the error code.
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/elf.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/image/elf.c b/src/image/elf.c index d69a3e31..9dc08675 100644 --- a/src/image/elf.c +++ b/src/image/elf.c @@ -30,6 +30,8 @@ #include <gpxe/image.h> #include <gpxe/elf.h> +struct image_type elf_image_type __image_type; + typedef Elf32_Ehdr Elf_Ehdr; typedef Elf32_Phdr Elf_Phdr; typedef Elf32_Off Elf_Off; @@ -40,7 +42,7 @@ typedef Elf32_Off Elf_Off; * @v image ELF file * @ret rc Return status code */ -static int elf_execute ( struct image *image __unused ) { +static int elf_exec ( struct image *image __unused ) { return -ENOTSUP; } @@ -63,7 +65,7 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr ) { /* Check segment lies within image */ if ( ( phdr->p_offset + phdr->p_filesz ) > image->len ) { DBG ( "ELF segment outside ELF file\n" ); - return -ERANGE; + return -ENOEXEC; } /* Find start address: use physical address for preference, @@ -75,7 +77,7 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr ) { dest = phdr->p_vaddr; if ( ! dest ) { DBG ( "ELF segment loads to physical address 0\n" ); - return -ERANGE; + return -ENOEXEC; } buffer = phys_to_user ( dest ); @@ -117,13 +119,17 @@ int elf_load ( struct image *image ) { return -ENOEXEC; } + /* This is an ELF image, valid or otherwise */ + if ( ! image->type ) + image->type = &elf_image_type; + /* Read ELF program headers */ for ( phoff = ehdr.e_phoff , phnum = ehdr.e_phnum ; phnum ; phoff += ehdr.e_phentsize, phnum-- ) { if ( phoff > image->len ) { DBG ( "ELF program header %d outside ELF image\n", phnum ); - return -ERANGE; + return -ENOEXEC; } copy_from_user ( &phdr, image->data, phoff, sizeof ( phdr ) ); if ( ( rc = elf_load_segment ( image, &phdr ) ) != 0 ) @@ -132,7 +138,6 @@ int elf_load ( struct image *image ) { /* Fill in entry point address */ image->entry = ehdr.e_entry; - image->execute = elf_execute; return 0; } @@ -141,4 +146,5 @@ int elf_load ( struct image *image ) { struct image_type elf_image_type __image_type = { .name = "ELF", .load = elf_load, + .exec = elf_exec, }; |