Don't initialize module before grub_dl_add() succeeds
PATCH 1/3 Don't initialize module before grub_dl_add() succeeds
ChangeLog:
* kern/dl.c (grub_dl_load_core): Call grub_dl_call_init() only after grub_dl_add() succeeds. Set mod->ref_count to 1 later to allow grub_dl_unload() to work.
Original patch by Joe Auricchio <[email protected]>
--- kern/dl.c | 14 +++++--------- 1 files changed, 5 insertions(+), 9 deletions(-)
kern/dl.c +5 -9
@@ -539,14 +539,13 @@ grub_dl_load_core (void *addr, grub_size_t size)if (! mod)return 0 ; - mod->ref_count =1 ; -grub_dprintf ("modules" ,"relocating to %p\n" , mod);if (grub_dl_resolve_name (mod, e) ||grub_dl_resolve_dependencies (mod, e) ||grub_dl_load_segments (mod, e) ||grub_dl_resolve_symbols (mod, e) - ||grub_arch_dl_relocate_symbols (mod, e)) + ||grub_arch_dl_relocate_symbols (mod, e) + ||grub_dl_add (mod)) { mod->fini =0 ;grub_dl_unload (mod);
@@ -557,13 +556,10 @@ grub_dl_load_core (void *addr, grub_size_t size)grub_dprintf ("modules" ,"module name: %s\n" , mod->name);grub_dprintf ("modules" ,"init function: %p\n" , mod->init); -grub_dl_call_init (mod); -if (grub_dl_add (mod)) - { -grub_dl_unload (mod); -return 0 ; - } + mod->ref_count =1 ; + +grub_dl_call_init (mod);return mod; }
PATCH 2/3 Eliminate grub_dl_call_init()
It's just two lines long and there is only one caller. Besides, there is no equivalent for mod->fini.
ChangeLog:
* kern/dl.c (grub_dl_call_init): Remove. (grub_dl_load_core): Call mod->init directly. --- kern/dl.c | 10 ++-------- 1 files changed, 2 insertions(+), 8 deletions(-)
kern/dl.c +2 -8
@@ -393,13 +393,6 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)return GRUB_ERR_NONE ; } -static void -grub_dl_call_init (grub_dl_t mod) -{ -if (mod->init) - (mod->init) (mod); -} -static grub_err_t grub_dl_resolve_name (grub_dl_t mod,Elf_Ehdr *e) {
@@ -559,7 +552,8 @@ grub_dl_load_core (void *addr, grub_size_t size) mod->ref_count =1 ; -grub_dl_call_init (mod); +if (mod->init) + (mod->init) (mod);return mod; }
Re: [PATCH 2/3] Eliminate grub_dl_call_init()
Quoted 2 lines · Pavel Roskin
It's just two lines long and there is only one caller. Besides, there is no equivalent for
mod->fini.
This patch is fine for me
Quoted 44 lines
ChangeLog:
*
kern/dl.c(grub_dl_call_init): Remove. (grub_dl_load_core): Callmod->initdirectly.
---
kern/dl.c | 10 ++--------1 files changed, 2 insertions(+), 8 deletions(-)kern/dl.c +0
-7@@ -393,13 +393,6 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) return GRUB_ERR_NONE; } -static void -grub_dl_call_init (grub_dl_t mod) -{ - if (mod->init) - (mod->init) (mod); -} -static
grub_err_t
grub_dl_resolve_name (grub_dl_tmod,Elf_Ehdr*e) {kern/dl.c +2
-1@@ -559,7 +552,8 @@ grub_dl_load_core (void *addr, grub_size_t size) mod->ref_count = 1; - grub_dl_call_init (mod); + if (mod->init) + (mod->init) (mod); return mod; }_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
PATCH 3/3 Merge struct grub_dl_list into struct grub_dl
In reply to Pavel RoskinThere is no need to keep a separate list of the modules. It requires additional memory allocation and additional error handling. Now grub_dl_add() can only fail if the module is already loaded.
ChangeLog:
* include/grub/dl.h (struct grub_dl): Add next field.
* kern/dl.c: Remove struct grub_dl_list. Use mod->next to iterate over modules.
--- include/grub/dl.h | 1 + kern/dl.c | 55 +++++++++++++++++++---------------------------------- 2 files changed, 21 insertions(+), 35 deletions(-)
include/grub/dl.h +1 -0
@@ -82,6 +82,7 @@ struct grub_dlElf_Sym *symtab;void (*init) (struct grub_dl *mod);void (*fini) (void ); +struct grub_dl *next; };typedef struct grub_dl *grub_dl_t ;
kern/dl.c +20 -35
115 lines not on this page · raw message
Quoted 6 lines · Pavel Roskin
ChangeLog:
*
kern/dl.c(grub_dl_load_core): Callgrub_dl_call_init()only aftergrub_dl_add()succeeds. Setmod->ref_countto 1 later to allowgrub_dl_unload()to work.
Original patch by Joe Auricchio <[email protected]>
Ok with me
Quoted 49 lines
---
kern/dl.c | 14 +++++---------1 files changed, 5 insertions(+), 9 deletions(-)kern/dl.c +5
-9@@ -539,14 +539,13 @@ grub_dl_load_core (void *addr, grub_size_t size) if (! mod) return 0; - mod->ref_count = 1; - grub_dprintf ("modules", "relocating to %p\n", mod); if (grub_dl_resolve_name (mod, e) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) || grub_dl_resolve_symbols (mod, e) - || grub_arch_dl_relocate_symbols (mod, e)) + || grub_arch_dl_relocate_symbols (mod, e) + || grub_dl_add (mod)) { mod->fini = 0; grub_dl_unload (mod);@@ -557,13 +556,10 @@ grub_dl_load_core (void *addr, grub_size_t size) grub_dprintf ("modules", "module name: %s\n", mod->name); grub_dprintf ("modules", "init function: %p\n", mod->init); - grub_dl_call_init (mod); - if (grub_dl_add (mod)) - { - grub_dl_unload (mod); - return 0; - } + mod->ref_count = 1; + + grub_dl_call_init (mod); return mod; }_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git