diff options
| author | Matt Fleming <matt.fleming@intel.com> | 2013-01-29 14:01:07 +0000 |
|---|---|---|
| committer | Matt Fleming <matt.fleming@intel.com> | 2013-01-29 15:11:28 +0000 |
| commit | bf20364b582c383b4927f898de213b1cc0981a80 (patch) | |
| tree | 5412e0c14cf74df0d7ea29ff182e23d3281aac3e /com32/lib/sys | |
| parent | afd985f6eec18a0f66a8fc55f9c5e3431128310f (diff) | |
| parent | a2d79191b501276026a0a16ec2fa664630a20476 (diff) | |
| download | syslinux-6.00-pre4.tar.gz | |
Merge tag 'syslinux-5.01' into firmwaresyslinux-6.00-pre4
Conflicts:
Makefile
NEWS
com32/cmenu/Makefile
com32/elflink/ldlinux/Makefile
com32/gfxboot/Makefile
com32/gpllib/Makefile
com32/include/sys/module.h
com32/lib/Makefile
com32/lib/sys/module/elf_module.c
com32/menu/Makefile
com32/rosh/Makefile
com32/samples/Makefile
core/init.c
mk/elf.mk
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'com32/lib/sys')
| -rw-r--r-- | com32/lib/sys/module/common.c | 5 | ||||
| -rw-r--r-- | com32/lib/sys/module/elf_module.c | 2 | ||||
| -rw-r--r-- | com32/lib/sys/module/exec.c | 49 | ||||
| -rw-r--r-- | com32/lib/sys/module/i386/elf_module.c | 8 | ||||
| -rw-r--r-- | com32/lib/sys/module/i386/shallow_module.c | 161 | ||||
| -rw-r--r-- | com32/lib/sys/module/shallow_module.c | 161 | ||||
| -rw-r--r-- | com32/lib/sys/module/x86_64/elf_module.c | 8 | ||||
| -rw-r--r-- | com32/lib/sys/module/x86_64/shallow_module.c | 161 |
8 files changed, 26 insertions, 529 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c index 2ecc9e59..4c83789e 100644 --- a/com32/lib/sys/module/common.c +++ b/com32/lib/sys/module/common.c @@ -185,6 +185,11 @@ void modules_term(void) { struct elf_module *module_alloc(const char *name) { struct elf_module *result = malloc(sizeof(struct elf_module)); + if (!result) { + dprintf("module: Failed to alloc elf_module\n"); + return NULL; + } + memset(result, 0, sizeof(struct elf_module)); INIT_LIST_HEAD(&result->list); diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c index 0d27c92b..e3d9928a 100644 --- a/com32/lib/sys/module/elf_module.c +++ b/com32/lib/sys/module/elf_module.c @@ -218,7 +218,7 @@ int module_load(struct elf_module *module) { CHECKED(res, prepare_dynlinking(module), error); //printf("check... 4\n"); - head = list_entry((&modules_head)->next, typeof(*head), list); + head = module_current(); /* Find modules we need to load as dependencies */ if (module->str_table) { diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 559bafc7..18c8306d 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -18,32 +18,8 @@ #define DBG_PRINT(fmt, args...) dprintf("[EXEC] " fmt, ##args) -static struct elf_module *mod_root = NULL; struct elf_module *__syslinux_current = NULL; -int exec_init(void) -{ - int res; - - res = modules_init(); - if (res != 0) - return res; - - // Load the root module - mod_root = module_alloc(EXEC_ROOT_NAME); - - if (mod_root == NULL) - return -1; - - res = module_load_shallow(mod_root, 0); - if (res != 0) { - mod_root = NULL; - return res; - } - - return 0; -} - int get_module_type(struct elf_module *module) { if(module->main_func) return EXEC_MODULE; @@ -161,8 +137,6 @@ int spawnl(const char *name, const char *arg, ...) } #endif -struct elf_module *cur_module; - /* * Load a module and runs its start function. * @@ -185,7 +159,7 @@ int spawn_load(const char *name, int argc, char **argv) struct elf_module *previous; //malloc_tag_t prev_mem_tag; struct elf_module *module = module_alloc(name); - struct elf_module *prev_module; + struct elf_module *cur_module; int type; dprintf("enter: name = %s", name); @@ -200,23 +174,11 @@ int spawn_load(const char *name, int argc, char **argv) } } + cur_module = module_current(); if (!strcmp(cur_module->name, module->name)) { dprintf("We is running this module %s already!", module->name); - /* - * If we're already running the module and it's of - * type EXEC_MODULE, then just return. We don't reload - * the module because that might cause us to re-run - * the init functions, which will cause us to run the - * main function, which will take control of this - * process. - * - * This can happen if some other EXEC_MODULE is - * resolving a symbol that is exported by the current - * EXEC_MODULE. - */ - if (get_module_type(module) == EXEC_MODULE) - return 0; + module_unload(cur_module); } res = module_load(module); @@ -224,11 +186,9 @@ int spawn_load(const char *name, int argc, char **argv) goto out; type = get_module_type(module); - prev_module = cur_module; - cur_module = module; dprintf("type = %d, prev = %s, cur = %s", - type, prev_module->name, cur_module->name); + type, cur_module->name, module->name); if(type==EXEC_MODULE) { @@ -256,7 +216,6 @@ int spawn_load(const char *name, int argc, char **argv) // Restore the process context __syslinux_current = previous; - cur_module = prev_module; res = module_unload(module); if (res != 0) diff --git a/com32/lib/sys/module/i386/elf_module.c b/com32/lib/sys/module/i386/elf_module.c index a3792554..d30f4ce2 100644 --- a/com32/lib/sys/module/i386/elf_module.c +++ b/com32/lib/sys/module/i386/elf_module.c @@ -46,6 +46,9 @@ int load_segments(struct elf_module *module, Elf_Ehdr *elf_hdr) { // Load the PHT pht = malloc(elf_hdr->e_phnum * elf_hdr->e_phentsize); + if (!pht) + return -1; + image_read(pht, elf_hdr->e_phnum * elf_hdr->e_phentsize, module); // Compute the memory needings of the module @@ -149,6 +152,11 @@ int load_segments(struct elf_module *module, Elf_Ehdr *elf_hdr) { // Load the SHT sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); + if (!sht) { + res = -1; + goto out; + } + image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); // Setup the symtable size diff --git a/com32/lib/sys/module/i386/shallow_module.c b/com32/lib/sys/module/i386/shallow_module.c deleted file mode 100644 index fbcf781b..00000000 --- a/com32/lib/sys/module/i386/shallow_module.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * shallow_module.c - * - * Created on: Aug 11, 2008 - * Author: Stefan Bucur <stefanb@zytor.com> - */ - - -#include <string.h> -#include <sys/module.h> - -#include "common.h" -#include "elfutils.h" - - -static int check_header_shallow(Elf32_Ehdr *elf_hdr) { - int res; - - res = check_header_common(elf_hdr); - - if (res != 0) - return res; - - if (elf_hdr->e_shoff == 0x00000000) { - DBG_PRINT("SHT missing\n"); - return -1; - } - - return 0; -} - -static int load_shallow_sections(struct elf_module *module, Elf32_Ehdr *elf_hdr) { - int i; - int res = 0; - void *sht = NULL; - void *buffer = NULL; - Elf32_Shdr *crt_sht; - Elf32_Off buff_offset; - - Elf32_Off min_offset = 0xFFFFFFFF; - Elf32_Off max_offset = 0x00000000; - Elf32_Word max_align = 0x1; - - Elf32_Off sym_offset = 0xFFFFFFFF; - Elf32_Off str_offset = 0xFFFFFFFF; - - - char *sh_strtable; - - // We buffer the data up to the SHT - buff_offset = module->u.l._cr_offset; - - buffer = malloc(elf_hdr->e_shoff - buff_offset); - // Get to the SHT - image_read(buffer, elf_hdr->e_shoff - buff_offset, module); - - // Load the SHT - sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); - image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); - - // Get the string table of the section names - crt_sht = (Elf32_Shdr*)(sht + elf_hdr->e_shstrndx * elf_hdr->e_shentsize); - sh_strtable = (char*)(buffer + (crt_sht->sh_offset - buff_offset)); - - for (i = 0; i < elf_hdr->e_shnum; i++) { - crt_sht = (Elf32_Shdr*)(sht + i*elf_hdr->e_shentsize); - - if (strcmp(".symtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the symbol table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - sym_offset = crt_sht->sh_offset; - - module->syment_size = crt_sht->sh_entsize; - module->symtable_size = crt_sht->sh_size / crt_sht->sh_entsize; - } - if (strcmp(".strtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the string table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - str_offset = crt_sht->sh_offset; - - module->strtable_size = crt_sht->sh_size; - } - } - - if (elf_malloc(&module->module_addr, max_align, - max_offset - min_offset) != 0) { - DBG_PRINT("Could not allocate sections\n"); - goto out; - } - - // Copy the data - image_seek(min_offset, module); - image_read(module->module_addr, max_offset - min_offset, module); - - // Setup module information - module->module_size = max_offset - min_offset; - module->str_table = (char*)(module->module_addr + (str_offset - min_offset)); - module->sym_table = module->module_addr + (sym_offset - min_offset); - -out: - // Release the SHT - if (sht != NULL) - free(sht); - - // Release the buffer - if (buffer != NULL) - free(buffer); - - return res; -} - - -int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr) { - int res; - Elf32_Ehdr elf_hdr; - - // Do not allow duplicate modules - if (module_find(module->name) != NULL) { - DBG_PRINT("Module already loaded.\n"); - return -1; - } - - res = image_load(module); - - if (res < 0) - return res; - - module->shallow = 1; - - CHECKED(res, image_read(&elf_hdr, sizeof(Elf32_Ehdr), module), error); - - // Checking the header signature and members - CHECKED(res, check_header_shallow(&elf_hdr), error); - - CHECKED(res, load_shallow_sections(module, &elf_hdr), error); - module->base_addr = base_addr; - - // Check the symbols for duplicates / missing definitions - CHECKED(res, check_symbols(module), error); - - // Add the module at the beginning of the module list - list_add(&module->list, &modules_head); - - // The file image is no longer needed - image_unload(module); - - DBG_PRINT("SHALLOW MODULE %s LOADED SUCCESSFULLY\n", module->name); - - return 0; - -error: - image_unload(module); - - return res; -} diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c deleted file mode 100644 index 8a88e403..00000000 --- a/com32/lib/sys/module/shallow_module.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * shallow_module.c - * - * Created on: Aug 11, 2008 - * Author: Stefan Bucur <stefanb@zytor.com> - */ - - -#include <string.h> -#include <sys/module.h> - -#include "common.h" -#include "elfutils.h" - - -static int check_header_shallow(Elf32_Ehdr *elf_hdr) { - int res; - - res = check_header_common(elf_hdr); - - if (res != 0) - return res; - - if (elf_hdr->e_shoff == 0x00000000) { - DBG_PRINT("SHT missing\n"); - return -1; - } - - return 0; -} - -static int load_shallow_sections(struct elf_module *module, Elf32_Ehdr *elf_hdr) { - int i; - int res = 0; - char *sht = NULL; - char *buffer = NULL; - Elf32_Shdr *crt_sht; - Elf32_Off buff_offset; - - Elf32_Off min_offset = 0xFFFFFFFF; - Elf32_Off max_offset = 0x00000000; - Elf32_Word max_align = 0x1; - - Elf32_Off sym_offset = 0xFFFFFFFF; - Elf32_Off str_offset = 0xFFFFFFFF; - - - char *sh_strtable; - - // We buffer the data up to the SHT - buff_offset = module->u.l._cr_offset; - - buffer = malloc(elf_hdr->e_shoff - buff_offset); - // Get to the SHT - image_read(buffer, elf_hdr->e_shoff - buff_offset, module); - - // Load the SHT - sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); - image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); - - // Get the string table of the section names - crt_sht = (Elf32_Shdr*)(sht + elf_hdr->e_shstrndx * elf_hdr->e_shentsize); - sh_strtable = (char*)(buffer + (crt_sht->sh_offset - buff_offset)); - - for (i = 0; i < elf_hdr->e_shnum; i++) { - crt_sht = (Elf32_Shdr*)(sht + i*elf_hdr->e_shentsize); - - if (strcmp(".symtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the symbol table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - sym_offset = crt_sht->sh_offset; - - module->syment_size = crt_sht->sh_entsize; - module->symtable_size = crt_sht->sh_size / crt_sht->sh_entsize; - } - if (strcmp(".strtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the string table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - str_offset = crt_sht->sh_offset; - - module->strtable_size = crt_sht->sh_size; - } - } - - if (elf_malloc(&module->module_addr, max_align, - max_offset - min_offset) != 0) { - DBG_PRINT("Could not allocate sections\n"); - goto out; - } - - // Copy the data - image_seek(min_offset, module); - image_read(module->module_addr, max_offset - min_offset, module); - - // Setup module information - module->module_size = max_offset - min_offset; - module->str_table = (char *)module->module_addr + (str_offset - min_offset); - module->sym_table = (char *)module->module_addr + (sym_offset - min_offset); - -out: - // Release the SHT - if (sht != NULL) - free(sht); - - // Release the buffer - if (buffer != NULL) - free(buffer); - - return res; -} - - -int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr) { - int res; - Elf32_Ehdr elf_hdr; - - // Do not allow duplicate modules - if (module_find(module->name) != NULL) { - DBG_PRINT("Module already loaded.\n"); - return -1; - } - - res = image_load(module); - - if (res < 0) - return res; - - module->shallow = 1; - - CHECKED(res, image_read(&elf_hdr, sizeof(Elf32_Ehdr), module), error); - - // Checking the header signature and members - CHECKED(res, check_header_shallow(&elf_hdr), error); - - CHECKED(res, load_shallow_sections(module, &elf_hdr), error); - module->base_addr = base_addr; - - // Check the symbols for duplicates / missing definitions - CHECKED(res, check_symbols(module), error); - - // Add the module at the beginning of the module list - list_add(&module->list, &modules_head); - - // The file image is no longer needed - image_unload(module); - - DBG_PRINT("SHALLOW MODULE %s LOADED SUCCESSFULLY\n", module->name); - - return 0; - -error: - image_unload(module); - - return res; -} diff --git a/com32/lib/sys/module/x86_64/elf_module.c b/com32/lib/sys/module/x86_64/elf_module.c index 64404a17..dd24bd12 100644 --- a/com32/lib/sys/module/x86_64/elf_module.c +++ b/com32/lib/sys/module/x86_64/elf_module.c @@ -46,6 +46,9 @@ int load_segments(struct elf_module *module, Elf_Ehdr *elf_hdr) { // Load the PHT pht = malloc(elf_hdr->e_phnum * elf_hdr->e_phentsize); + if (!pht) + return -1; + image_read(pht, elf_hdr->e_phnum * elf_hdr->e_phentsize, module); // Compute the memory needings of the module @@ -149,6 +152,11 @@ int load_segments(struct elf_module *module, Elf_Ehdr *elf_hdr) { // Load the SHT sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); + if (!sht) { + res = -1; + goto out; + } + image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); // Setup the symtable size diff --git a/com32/lib/sys/module/x86_64/shallow_module.c b/com32/lib/sys/module/x86_64/shallow_module.c deleted file mode 100644 index b7248150..00000000 --- a/com32/lib/sys/module/x86_64/shallow_module.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * shallow_module.c - * - * Created on: Aug 11, 2008 - * Author: Stefan Bucur <stefanb@zytor.com> - */ - - -#include <string.h> -#include <sys/module.h> - -#include "common.h" -#include "elfutils.h" - - -static int check_header_shallow(Elf64_Ehdr *elf_hdr) { - int res; - - res = check_header_common(elf_hdr); - - if (res != 0) - return res; - - if (elf_hdr->e_shoff == 0x00000000) { - DBG_PRINT("SHT missing\n"); - return -1; - } - - return 0; -} - -static int load_shallow_sections(struct elf_module *module, Elf64_Ehdr *elf_hdr) { - int i; - int res = 0; - void *sht = NULL; - void *buffer = NULL; - Elf64_Shdr *crt_sht; - Elf64_Off buff_offset; - - Elf64_Off min_offset = 0xFFFFFFFFFFFFFFFF; - Elf64_Off max_offset = 0x0000000000000000; - Elf64_Word max_align = 0x1; - - Elf64_Off sym_offset = 0xFFFFFFFFFFFFFFFF; - Elf64_Off str_offset = 0xFFFFFFFFFFFFFFFF; - - - char *sh_strtable; - - // We buffer the data up to the SHT - buff_offset = module->u.l._cr_offset; - - buffer = malloc(elf_hdr->e_shoff - buff_offset); - // Get to the SHT - image_read(buffer, elf_hdr->e_shoff - buff_offset, module); - - // Load the SHT - sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); - image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); - - // Get the string table of the section names - crt_sht = (Elf64_Shdr*)(sht + elf_hdr->e_shstrndx * elf_hdr->e_shentsize); - sh_strtable = (char*)(buffer + (crt_sht->sh_offset - buff_offset)); - - for (i = 0; i < elf_hdr->e_shnum; i++) { - crt_sht = (Elf64_Shdr*)(sht + i*elf_hdr->e_shentsize); - - if (strcmp(".symtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the symbol table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - sym_offset = crt_sht->sh_offset; - - module->syment_size = crt_sht->sh_entsize; - module->symtable_size = crt_sht->sh_size / crt_sht->sh_entsize; - } - if (strcmp(".strtab", sh_strtable + crt_sht->sh_name) == 0) { - // We found the string table - min_offset = MIN(min_offset, crt_sht->sh_offset); - max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size); - max_align = MAX(max_align, crt_sht->sh_addralign); - - str_offset = crt_sht->sh_offset; - - module->strtable_size = crt_sht->sh_size; - } - } - - if (elf_malloc(&module->module_addr, max_align, - max_offset - min_offset) != 0) { - DBG_PRINT("Could not allocate sections\n"); - goto out; - } - - // Copy the data - image_seek(min_offset, module); - image_read(module->module_addr, max_offset - min_offset, module); - - // Setup module information - module->module_size = max_offset - min_offset; - module->str_table = (char*)(module->module_addr + (str_offset - min_offset)); - module->sym_table = module->module_addr + (sym_offset - min_offset); - -out: - // Release the SHT - if (sht != NULL) - free(sht); - - // Release the buffer - if (buffer != NULL) - free(buffer); - - return res; -} - - -int module_load_shallow(struct elf_module *module, Elf64_Addr base_addr) { - int res; - Elf64_Ehdr elf_hdr; - - // Do not allow duplicate modules - if (module_find(module->name) != NULL) { - DBG_PRINT("Module already loaded.\n"); - return -1; - } - - res = image_load(module); - - if (res < 0) - return res; - - module->shallow = 1; - - CHECKED(res, image_read(&elf_hdr, sizeof(Elf64_Ehdr), module), error); - - // Checking the header signature and members - CHECKED(res, check_header_shallow(&elf_hdr), error); - - CHECKED(res, load_shallow_sections(module, &elf_hdr), error); - module->base_addr = base_addr; - - // Check the symbols for duplicates / missing definitions - CHECKED(res, check_symbols(module), error); - - // Add the module at the beginning of the module list - list_add(&module->list, &modules_head); - - // The file image is no longer needed - image_unload(module); - - DBG_PRINT("SHALLOW MODULE %s LOADED SUCCESSFULLY\n", module->name); - - return 0; - -error: - image_unload(module); - - return res; -} |
