aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-01-23 14:46:08 +0000
committerMatt Fleming <matt.fleming@intel.com>2013-01-23 15:05:29 +0000
commit7c42c59ebd9d33efe3a5f12542580a8c1379447d (patch)
treec6338ddd6002668c32e1dbe421333455ecc1b8c9
parentb3dd49f09630ec1338d2ee987f794d49ca01c227 (diff)
downloadsyslinux-7c42c59ebd9d33efe3a5f12542580a8c1379447d.tar.gz
syslinux-7c42c59ebd9d33efe3a5f12542580a8c1379447d.tar.xz
syslinux-7c42c59ebd9d33efe3a5f12542580a8c1379447d.zip
module: Replace cur_module with module_current()syslinux-5.01-pre4
It's easy for cur_module and prev_module to get out of sync with reality (the actual module that is running), so add module_current() which returns the module at the head of the module_list, i.e. the module that was loaded most recently. Better still, by using the list we don't have to do any kind of stacking of module pointers ourselves. This fixes a bug where cur_module contained a stale pointer (the module had actually been unloaded) but the pointer value had since been reallocated for a new module in spawn_load(), meaning that the following check, if (!strcmp(cur_module->name, module->name)) was always going to be true, even though *no* module was actually loaded at this point as we were reloading ldlinux.c32 from start_ldlinux(). This could have been fixed with a NULL-assignment after module_unload(), but using the modules_head list to detect the current module is much cleaner. Note that the core module loaded in load_env32() is always on the list, therefore module_current() will always return a valid pointer. Signed-off-by: Matt Fleming <matt.fleming@intel.com>
-rw-r--r--com32/include/sys/module.h11
-rw-r--r--com32/lib/sys/module/elf_module.c2
-rw-r--r--com32/lib/sys/module/exec.c11
3 files changed, 15 insertions, 9 deletions
diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index a18561a9..8d144203 100644
--- a/com32/include/sys/module.h
+++ b/com32/include/sys/module.h
@@ -203,6 +203,17 @@ extern struct list_head modules_head;
list_for_each_entry_safe(m, n, &modules_head, list)
/**
+ * module_current - return the module at the head of the module list.
+ */
+static inline struct elf_module *module_current(void)
+{
+ struct elf_module *head;
+
+ head = list_entry((&modules_head)->next, typeof(*head), list);
+ return head;
+}
+
+/**
* modules_init - initialize the module subsystem.
*
* This function must be called before any module operation is to be performed.
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index e61480f5..6a540273 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -534,7 +534,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 2b3a4c09..18c8306d 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -137,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.
*
@@ -161,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);
@@ -176,11 +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);
module_unload(cur_module);
- cur_module = NULL;
}
res = module_load(module);
@@ -188,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)
{
@@ -220,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)