/* * Initialize the module system by loading the Symbols.dylib module. * Once loaded, locate the _lookup_symbol function so that internal * symbols can be resolved. */ int init_module_system() { // Start any modules that were compiled in first. start_built_in_modules(); int retVal = 0; void (*module_start)(void) = NULL; char* module_data = symbols_module_start + BOOT2_ADDR; // Intialize module system if(symbols_module_start != (void*)0xFFFFFFFF) { // Module system was compiled in (Symbols.dylib addr known) module_start = parse_mach(module_data, &load_module, &add_symbol, NULL); if(module_start && module_start != (void*)0xFFFFFFFF) { // Notify the system that it was laoded module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT); (*module_start)(); // Start the module. This will point to load_all_modules due to the way the dylib was constructed. execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL); DBG("Module %s Loaded.\n", SYMBOLS_MODULE); retVal = 1; } else { module_data -= 0x10; // XCODE 4 HACK module_start = parse_mach(module_data, &load_module, &add_symbol, NULL); if(module_start && module_start != (void*)0xFFFFFFFF) { // Notify the system that it was laoded module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT); (*module_start)(); // Start the module. This will point to load_all_modules due to the way the dylib was constructed. execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL); DBG("Module %s Loaded.\n", SYMBOLS_MODULE); retVal = 1; } else { // The module does not have a valid start function printf("Unable to start %s\n", SYMBOLS_MODULE); getchar(); } } } return retVal; }
/* * Load a module file in /Extra/modules/ */ int load_module(char* module) { int retVal = 1; void (*module_start)(void) = NULL; char modString[128]; int fh = -1; // Check to see if the module has already been loaded if(is_module_loaded(module)) { DBG("Module '%s' already loaded.\n", module); return 1; } snprintf(modString, sizeof(modString), MODULE_PATH "%s", module); fh = open(modString, 0); if(fh < 0) { DBG("[WARNING!] Unable to locate module '%s'. Not loaded.\n", modString); DBGPAUSE(); return 0; } unsigned int moduleSize = file_size(fh); if(moduleSize == 0) { DBG("[WARNING!] The module '%s' has a file size=%d. Not loading.\n", modString, moduleSize); return 0; } char* module_base = (char*) malloc(moduleSize); if (moduleSize && read(fh, module_base, moduleSize) == moduleSize) { // Module loaded into memory, parse it module_start = parse_mach(module_base, &load_module, &add_symbol, NULL); if(module_start && module_start != (void*)0xFFFFFFFF) { // Notify the system that it was laoded module_loaded(module, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/); (*module_start)(); // Start the module DBG("Module %s Loaded.\n", module); DBGPAUSE(); } #if CONFIG_MODULE_DEBUG else // The module does not have a valid start function. This may be a library. { printf("[WARNING!] Unable to start module '%s'.\n", module); getchar(); } #else else msglog("[WARNING!] Unable to start module '%s'.\n", module);
/* * Initialize the module system by loading the Symbols.dylib module. * Once loaded, locate the _lookup_symbol function so that internal * symbols can be resolved. */ int init_module_system() { // Start any modules that were compiled in first. start_built_in_modules(); int retVal = 0; void (*module_start)(void) = NULL; extern char symbols_start __asm("section$start$__DATA$__Symbols"); char* module_data = &symbols_start; // Intialize module system if(module_data) { // Module system was compiled in (Symbols.dylib addr known) module_start = parse_mach(module_data, &load_module, &add_symbol, NULL); if(module_start && (module_start != (void*)0xFFFFFFFF)) { // Notify the system that it was laoded module_loaded(SYMBOLS_MODULE, module_start, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT); (*module_start)(); // Start the module. This will point to load_all_modules due to the way the dylib was constructed. DBG("Module %s Loaded.\n", SYMBOLS_MODULE); retVal = 1; } else { // The module does not have a valid start function printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data); pause(); } } // Look for modules located in the multiboot header. if(gMI && (gMI->mi_flags & MULTIBOOT_INFO_HAS_MODS)) { if(gMI->mi_mods_count) { struct multiboot_module* mod = (struct multiboot_module*)gMI->mi_mods_addr; while(gMI->mi_mods_count--) { if(mod->mm_string) { // Convert string to module name, check for dylib. if(strcmp(&mod->mm_string[strlen(mod->mm_string) - sizeof("dylib")], ".dylib") == 0) { module_data = (char*)mod->mm_mod_start; char* last = strrchr(mod->mm_string, '/'); if(last) { last++; } else { last = mod->mm_string; } char *name = strdup(last); name[strlen(last) - sizeof("dylib")] = 0; DBG("Loading multiboot module %s\n", name); module_start = parse_mach(module_data, &load_module, &add_symbol, NULL); if(module_start && (module_start != (void*)0xFFFFFFFF)) { // Notify the system that it was laoded module_loaded(name, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/); (*module_start)(); // Start the module DBG("Module %s Loaded.\n", name); DBGPAUSE(); } } } } } } if(retVal) execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL); return retVal; }