From 67c9c489ba80c23739854905cf6d2f378193c9a8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 May 2012 12:39:49 +0800 Subject: [PATCH] Kernel - Moved module relocation to after dependencies are resolved --- KernelLand/Kernel/binary.c | 12 +---------- KernelLand/Kernel/modules.c | 43 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/KernelLand/Kernel/binary.c b/KernelLand/Kernel/binary.c index e72de28b..8a8bc3eb 100644 --- a/KernelLand/Kernel/binary.c +++ b/KernelLand/Kernel/binary.c @@ -768,17 +768,7 @@ void *Binary_LoadKernel(const char *File) pKBinary->Next = glLoadedKernelLibs; glLoadedKernelLibs = pKBinary; SHORTREL( &glKBinListLock ); - - // Relocate Library - if( !Binary_Relocate( (void*)base ) ) - { - Log_Warning("Binary", "Relocation of '%s' failed, unloading", File); - Binary_Unload( (void*)base ); - Binary_Dereference( pBinary ); - LEAVE('n'); - return 0; - } - + LEAVE('p', base); return (void*)base; } diff --git a/KernelLand/Kernel/modules.c b/KernelLand/Kernel/modules.c index d703290f..e3e0ebeb 100644 --- a/KernelLand/Kernel/modules.c +++ b/KernelLand/Kernel/modules.c @@ -341,6 +341,7 @@ int Module_LoadFile(const char *Path, const char *ArgString) { void *base; tModule *info; + tModuleLoader *loader = NULL; // Load Binary base = Binary_LoadKernel(Path); @@ -352,36 +353,36 @@ int Module_LoadFile(const char *Path, const char *ArgString) } // Check for Acess Driver - if( Binary_FindSymbol(base, "DriverInfo", (Uint*)&info ) == 0 ) + if( Binary_FindSymbol(base, "DriverInfo", (Uint*)&info ) ) { - tModuleLoader *tmp; - for( tmp = gModule_Loaders; tmp; tmp = tmp->Next) + for( loader = gModule_Loaders; loader; loader = loader->Next) { - if( tmp->Detector(base) == 0 ) continue; - - return tmp->Loader(base); - } - - #if USE_EDI - // Check for EDI Driver - if( Binary_FindSymbol(base, "driver_init", NULL ) != 0 ) - { - return Module_InitEDI( base ); // And intialise + if( loader->Detector(base) ) + break; } - #endif // Unknown module type?, return error + if( !loader ) { + Binary_Unload(base); + Log_Warning("Module", "Module '%s' does not have a Module Info struct", Path); + return 0; + } + } + + if( !Module_int_ResolveDeps(info) ) { + Log_Warning("Dependencies not met for '%s'", Path); Binary_Unload(base); - #if USE_EDI - Log_Warning("Module", "Module '%s' has neither a Module Info struct, nor an EDI entrypoint", Path); - #else - Log_Warning("Module", "Module '%s' does not have a Module Info struct", Path); - #endif return 0; } - + + if( !Binary_Relocate(base) ) { + Log_Warning("Relocation of module %s failed", Path); + Binary_Unload(base); + return 0; + } + // Initialise (and register) - if( Module_int_Initialise( info, ArgString ) ) + if( loader ? loader->Loader(base) : Module_int_Initialise( info, ArgString ) ) { Binary_Unload(base); return 0; -- 2.20.1