module: Replace cur_module with module_current()syslinux-5.01-pre4
commit7c42c59ebd9d33efe3a5f12542580a8c1379447d
authorMatt Fleming <matt.fleming@intel.com>
Wed, 23 Jan 2013 14:46:08 +0000 (23 14:46 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Wed, 23 Jan 2013 15:05:29 +0000 (23 15:05 +0000)
treec6338ddd6002668c32e1dbe421333455ecc1b8c9
parentb3dd49f09630ec1338d2ee987f794d49ca01c227
module: Replace cur_module with module_current()

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>
com32/include/sys/module.h
com32/lib/sys/module/elf_module.c
com32/lib/sys/module/exec.c