// === 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);
Log_Warning("Module", "Unable to load, reason: Miscelanious");
break;
case MODULE_ERR_NOTNEEDED:
- Log_Debug("Module", "Unable to load, reason: Module not needed");
+// Log_Debug("Module", "Unable to load, reason: Module not needed");
break;
case MODULE_ERR_MALLOC:
Log_Warning("Module", "Unable to load, reason: Error in malloc/realloc/calloc, probably not good");
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],
VFS_GetMemPath(path, Buffer, Length);
- return Module_LoadFile( path, ArgString );
+ return Module_LoadFile( path, ArgString ) == EOK;
}
/**
// 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
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, ArgString) )
+ {
+ 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;
}
/**