#include <elf.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | elf_load (struct image *image) |
| Load ELF image into memory. | |
Definition in file elf.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int elf_load | ( | struct image * | image | ) |
Load ELF image into memory.
| image | ELF file |
| rc | Return status code |
Definition at line 121 of file elf.c.
References assert, copy_from_user(), image::data, DBGC, Elf32_Ehdr::e_entry, Elf32_Ehdr::e_ident, Elf32_Ehdr::e_phentsize, Elf32_Ehdr::e_phnum, Elf32_Ehdr::e_phoff, EI_MAG0, elf_load_segment(), ELFMAG, ENOEXEC, image::len, memcmp(), NULL, image::phys, image::priv, SELFMAG, and image::type.
Referenced by elfboot_load(), and multiboot_load_elf().
00121 { 00122 Elf_Ehdr ehdr; 00123 Elf_Phdr phdr; 00124 Elf_Off phoff; 00125 unsigned int phnum; 00126 int rc; 00127 00128 /* Image type must already have been set by caller */ 00129 assert ( image->type != NULL ); 00130 00131 /* Read ELF header */ 00132 copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) ); 00133 if ( memcmp ( &ehdr.e_ident[EI_MAG0], ELFMAG, SELFMAG ) != 0 ) { 00134 DBGC ( image, "ELF %p has invalid signature\n", image ); 00135 return -ENOEXEC; 00136 } 00137 00138 /* Invalidate execution address */ 00139 image->priv.phys = 0; 00140 00141 /* Read ELF program headers */ 00142 for ( phoff = ehdr.e_phoff , phnum = ehdr.e_phnum ; phnum ; 00143 phoff += ehdr.e_phentsize, phnum-- ) { 00144 if ( phoff > image->len ) { 00145 DBGC ( image, "ELF %p program header %d outside " 00146 "image\n", image, phnum ); 00147 return -ENOEXEC; 00148 } 00149 copy_from_user ( &phdr, image->data, phoff, sizeof ( phdr ) ); 00150 if ( ( rc = elf_load_segment ( image, &phdr, &ehdr ) ) != 0 ) 00151 return rc; 00152 } 00153 00154 /* Check for a valid execution address */ 00155 if ( ! image->priv.phys ) { 00156 DBGC ( image, "ELF %p entry point %lx outside image\n", 00157 image, ( ( unsigned long ) ehdr.e_entry ) ); 00158 return -ENOEXEC; 00159 } 00160 00161 return 0; 00162 }
1.5.7.1