aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/module
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib/sys/module')
-rw-r--r--com32/lib/sys/module/elf_module.c8
-rw-r--r--com32/lib/sys/module/exec.c4
-rw-r--r--com32/lib/sys/module/shallow_module.c25
3 files changed, 32 insertions, 5 deletions
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 4b1f2bbd..99b0c17b 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -417,6 +417,7 @@ static int extract_operations(struct elf_module *module) {
module->main_func = NULL;
}
+
return 0;
}
@@ -468,8 +469,11 @@ int module_load(struct elf_module *module) {
// The file image is no longer needed
image_unload(module);
- DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (init@0x%08X, exit@0x%08X)\n",
- module->name, *(module->init_func), *(module->exit_func));
+ DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (main@0x%08X, init@0x%08X, exit@0x%08X)\n",
+ module->name,
+ (module->main_func == NULL) ? NULL : *(module->main_func),
+ (module->init_func == NULL) ? NULL : *(module->init_func),
+ (module->exit_func == NULL) ? NULL : *(module->exit_func));
return 0;
diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index 3cd53187..9da1d572 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -30,7 +30,7 @@ static char *module_get_fullname(const char *name) {
return name_buff;
}
-int exec_init() {
+int exec_init(size_t root_addr) {
int res;
res = modules_init();
@@ -44,7 +44,7 @@ int exec_init() {
if (mod_root == NULL)
return -1;
- res = module_load_shallow(mod_root);
+ res = module_load_shallow(mod_root, root_addr);
if (res != 0) {
mod_root = NULL;
diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c
index f198c0db..f43582c4 100644
--- a/com32/lib/sys/module/shallow_module.c
+++ b/com32/lib/sys/module/shallow_module.c
@@ -115,8 +115,29 @@ out:
return res;
}
+static int offset_symbols(struct elf_module *module, Elf32_Off offset) {
+ unsigned int i;
+ Elf32_Sym *crt_sym = NULL;
+
+ for (i = 1; i < module->symtable_size; i++) {
+ crt_sym = (Elf32_Sym*)(module->sym_table + i*module->syment_size);
+
+ // Skip the undefined or absolute symbols
+ if (crt_sym->st_shndx == SHN_UNDEF || crt_sym->st_shndx == SHN_ABS)
+ continue;
+ // Also skip the non-local symbols
+ if (ELF32_ST_BIND(crt_sym->st_info) != STB_GLOBAL &&
+ ELF32_ST_BIND(crt_sym->st_info) != STB_WEAK)
+ continue;
+
+ crt_sym->st_value += offset;
+ }
+
+ return 0;
+}
+
-int module_load_shallow(struct elf_module *module) {
+int module_load_shallow(struct elf_module *module, Elf32_Off offset) {
int res;
Elf32_Ehdr elf_hdr;
@@ -143,6 +164,8 @@ int module_load_shallow(struct elf_module *module) {
// Check the symbols for duplicates / missing definitions
CHECKED(res, check_symbols(module), error);
+ CHECKED(res, offset_symbols(module, offset), error);
+
// Add the module at the beginning of the module list
list_add(&module->list, &modules_head);