X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fmodules.c;h=5fff929a29e8a5f9b4764e0a1f3aa05793e190c1;hb=85e4f7e3d5bea5db49e4dee4d94f9b2348017de3;hp=8202b086671f8583b7cb2572d1fe7f07e809c39a;hpb=18cee9bfed176b900c2d497ee49b55797363e049;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/modules.c b/KernelLand/Kernel/modules.c index 8202b086..5fff929a 100644 --- a/KernelLand/Kernel/modules.c +++ b/KernelLand/Kernel/modules.c @@ -8,9 +8,11 @@ #define USE_EDI 0 #define USE_UDI 0 +#define MODULE_FLAG_LOADERROR 0x1 // === PROTOTYPES === int Module_int_Initialise(tModule *Module, const char *ArgString); +size_t Modules_int_PopulateBuiltins(tModule **Array); void Modules_int_GetBuiltinArray(void); void Modules_LoadBuiltins(void); void Modules_SetBuiltinParams(const char *Name, char *ArgString); @@ -80,6 +82,15 @@ int Module_int_Initialise(tModule *Module, const char *ArgString) "Module %p (%s) is for another architecture (%i)", Module, Module->Name, Module->Arch ); + LEAVE('i', MODULE_ERR_BADMODULE); + return MODULE_ERR_BADMODULE; + } + + LOG("Module->Flags = %x", Module->Flags); + if(Module->Flags & MODULE_FLAG_LOADERROR ) { + Log_Warning("Module", "%s has already attempted to load and encountered errors", Module->Name); + LEAVE('i', MODULE_ERR_MISC); + return MODULE_ERR_MISC; } deps = Module->Dependencies; @@ -177,6 +188,7 @@ int Module_int_Initialise(tModule *Module, const char *ArgString) Log_Warning("Module", "Unable to load reason - Unknown code %i", ret); break; } + Module->Flags |= MODULE_FLAG_LOADERROR; LEAVE_RET('i', ret); return ret; } @@ -191,59 +203,51 @@ int Module_int_Initialise(tModule *Module, const char *ArgString) LEAVE_RET('i', 0); } -/** - * \brief Scans the builtin modules and creates an array of them - */ -void Modules_int_GetBuiltinArray(void) +size_t Modules_int_PopulateBuiltins(tModule **Array) { - int i; - tModule *module; - - // Count - module = &gKernelModules; - i = 0; - while( (tVAddr)module < (tVAddr)&gKernelModulesEnd ) + size_t count = 0; + for( tModule *module = &gKernelModules; module < (tModule*)&gKernelModulesEnd; ) { if(module->Magic == MODULE_MAGIC) { - i ++; + if( Array ) { + Array[count] = module; + } + count ++; module ++; } - else + else { module = (void*)( (tVAddr)module + 4 ); + } } - - // Create - giNumBuiltinModules = i; - gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) ); - gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) ); - - - // Fill - module = &gKernelModules; - i = 0; - while( (tVAddr)module < (tVAddr)&gKernelModulesEnd ) + return count; +} + +/** + * \brief Scans the builtin modules and creates an array of them + */ +void Modules_int_GetBuiltinArray(void) +{ + if( !gapBuiltinModules ) { - if(module->Magic == MODULE_MAGIC) { - gapBuiltinModules[i] = module; - i ++; - module ++; - } - else - module = (void*)( (tVAddr)module + 4 ); + // Count + giNumBuiltinModules = Modules_int_PopulateBuiltins(NULL); + + // Create + gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) ); + gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) ); + + // Fill + Modules_int_PopulateBuiltins(gapBuiltinModules); } } /** * \brief Initialises builtin modules */ -void Modules_LoadBuiltins() +void Modules_LoadBuiltins(void) { - int i; - - if( !gapBuiltinModules ) - Modules_int_GetBuiltinArray(); - - for( i = 0; i < giNumBuiltinModules; i++ ) + Modules_int_GetBuiltinArray(); + for( int i = 0; i < giNumBuiltinModules; i++ ) { Module_int_Initialise( gapBuiltinModules[i], @@ -330,7 +334,7 @@ int Module_LoadMem(void *Buffer, Uint Length, const char *ArgString) VFS_GetMemPath(path, Buffer, Length); - return Module_LoadFile( path, ArgString ); + return Module_LoadFile( path, ArgString ) == EOK; } /** @@ -349,15 +353,15 @@ int Module_LoadFile(const char *Path, const char *ArgString) // Error check if(base == NULL) { Log_Warning("Module", "Module_LoadFile - Unable to load '%s'", Path); - return 0; + return ENOENT; } // TODO: I need a way of relocating the dependencies before everything else, so // they can be resolved before any other link errors if( !Binary_Relocate(base) ) { - Log_Warning("Relocation of module %s failed", Path); + Log_Warning("Module", "Relocation of module %s failed", Path); Binary_Unload(base); - return 0; + return EINVAL; } // Check for Acess Driver @@ -373,24 +377,34 @@ int Module_LoadFile(const char *Path, const char *ArgString) if( !loader ) { Binary_Unload(base); Log_Warning("Module", "Module '%s' does not have a Module Info struct", Path); - return 0; + return EINVAL; } } - if( !Module_int_ResolveDeps(info) ) { - Log_Warning("Dependencies not met for '%s'", Path); - Binary_Unload(base); - return 0; + if( loader ) + { + if( loader->Loader(base) ) + { + Binary_Unload(base); + return EINVAL; + } } - - // Initialise (and register) - if( loader ? loader->Loader(base) : Module_int_Initialise( info, ArgString ) ) + else { - Binary_Unload(base); - return 0; + if( !Module_int_ResolveDeps(info) ) { + Log_Warning("Module", "Dependencies not met for '%s'", Path); + Binary_Unload(base); + return EINVAL; + } + + if( Module_int_Initialise(info, ArgString) ) + { + Binary_Unload(base); + return EINVAL; + } } - return 1; + return 0; } /**