/* * Use voodoo to load modules required by current hardware. */ int i386_autoload(void) { int error; int disabled; char *rv; /* XXX use PnP to locate stuff here */ /* autoload ACPI support */ /* XXX should be in 4th keyed off acpi_load */ disabled = 0; rv = getenv("hint.acpi.0.disabled"); if (rv != NULL && strncmp(rv, "0", 1) != 0) { disabled = 1; } if (getenv("acpi_load") && (!disabled)) { error = mod_load("acpi", NULL, 0, NULL); if (error != 0) printf("ACPI autoload failed - %s\n", strerror(error)); } disabled = 0; rv = getenv("hint.ehci.0.disabled"); if (rv != NULL && strncmp(rv, "0", 1) != 0) { disabled = 1; } if (getenv("ehci_load") && (!disabled)) { error = mod_load("ehci", NULL, 0, NULL); if (error != 0) printf("EHCI autoload failed - %s\n", strerror(error)); } disabled = 0; rv = getenv("hint.xhci.0.disabled"); if (rv != NULL && strncmp(rv, "0", 1) != 0) { disabled = 1; } if (getenv("xhci_load") && (!disabled)) { error = mod_load("xhci", NULL, 0, NULL); if (error != 0) printf("XHCI autoload failed - %s\n", strerror(error)); } return(0); }
u32t _std mod_searchload(const char *name, u32t flags, qserr *error) { char path[QS_MAXPATH+1], mname[E32MODNAME+5], *epos; strncpy(mname,name,E32MODNAME); mname[E32MODNAME] = 0; epos = strrchr(mname,'.'); if (!epos||strlen(epos)>4) { epos = mname + strlen(mname); strcpy(epos,".DLL"); } else epos = 0; strupr(mname); if (error) *error = 0; *path=0; _searchenv(mname,"LIBPATH",path); if (!*path) _searchenv(mname,"PATH",path); if (!*path) _searchenv(name,"LIBPATH",path); if (!*path) _searchenv(name,"PATH",path); if (!*path&&epos) { strcpy(epos,".EXE"); _searchenv(mname,"PATH",path); } if (!*path) return 0; return mod_load(path, flags, error, 0); }
/*-----------------------------------------------------------------------------------*/ unsigned char load(const char *name) { unsigned char res; /* Now open the file */ ctrl.callerdata = cfs_open(name, 0); if(ctrl.callerdata < 0) { /* Could not open the file, display an error and return */ /* ### */ return LOADER_ERR_OPEN; } /* Load the module */ res = mod_load(&ctrl); /* Close the input file */ cfs_close(ctrl.callerdata); /* Check the return code */ if(res != MLOAD_OK) { /* Wrong module, out of memory or whatever. Print an error * message and return. */ /* ### */ return res; } /* We've successfully loaded the module. */ return LOADER_OK; }
int load_modules() { plat_dir_t* dir = plat_opendir(mod_search_path); plat_dir_entry_t* d = NULL; char path[MODPATHLEN]; if(!dir) { logmsg(LOG_CRIT, "Failed to open directory %s", mod_search_path); logerror(); return -1; } while((d = plat_readdir(dir)) != NULL) { if( plat_dirent_hidden(d) || plat_dirent_type(d) != DET_REG) continue; path_join(path, MODPATHLEN, mod_search_path, d->d_name, NULL); mod_load(path); } plat_closedir(dir); return 0; }
int mod_load_dependencies(const char *dependencies) { if (!dependencies) return POM_OK; char *dupped_str = strdup(dependencies); char *str = dupped_str; if (!str) { pom_oom(strlen(dependencies)); return POM_ERR; } char *token, *saveptr; for (; ; str = NULL) { token = strtok_r(str, ", ", &saveptr); if (!token) break; struct mod_reg *tmp; for (tmp = mod_reg_head; tmp && strcmp(token, tmp->name); tmp = tmp->next); if (tmp) { // Already loaded, skip continue; } if (!mod_load(token)) { pomlog(POMLOG_ERR "Failed to load dependency %s", token); free(dupped_str); return POM_ERR; } } free(dupped_str); return POM_OK; }
int mod_load_all() { char *path = getenv(MOD_LIBDIR_ENV_VAR); if (!path) path = POM_LIBDIR; DIR *d; d = opendir(path); if (!d) { pomlog(POMLOG_ERR "Could not open directory %s for browsing : %s", path, pom_strerror(errno)); return POM_ERR; } struct dirent tmp, *dp; while (1) { if (readdir_r(d, &tmp, &dp) < 0) { pomlog(POMLOG_ERR "Error while reading directory entry : %s", pom_strerror(errno)); closedir(d); return POM_ERR; } if (!dp) // EOF break; size_t len = strlen(dp->d_name); if (len < strlen(POM_LIB_EXT) + 1) continue; if (!strcmp(dp->d_name + strlen(dp->d_name) - strlen(POM_LIB_EXT), POM_LIB_EXT)) { char *name = strdup(dp->d_name); if (!name) { pom_oom(strlen(dp->d_name)); closedir(d); return POM_ERR; } *(name + strlen(dp->d_name) - strlen(POM_LIB_EXT)) = 0; // Check if a dependency already loaded this module pom_mutex_lock(&mod_reg_lock); struct mod_reg *tmp; for (tmp = mod_reg_head; tmp && strcmp(name, tmp->name); tmp = tmp->next); if (tmp) { pom_mutex_unlock(&mod_reg_lock); free(name); continue; } pom_mutex_unlock(&mod_reg_lock); mod_load(name); free(name); } } closedir(d); return POM_OK; }
int main(int argc, char **argv) { _SIZEOF(mod_channel_data_t); _SIZEOF(mod_division_data_t); _SIZEOF(mod_pattern_data_t); if (argc == 2) { mod_setup(); mod_load(argv[1]); mod_process(); mod_save("../../test.mod"); } return 0; }
static int command_load(int argc, char *argv[]) { char *typestr; int dofile, ch, error; dofile = 0; optind = 1; optreset = 1; typestr = NULL; if (argc == 1) { command_errmsg = "no filename specified"; return(CMD_ERROR); } while ((ch = getopt(argc, argv, "t:")) != -1) { switch(ch) { case 't': typestr = optarg; dofile = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind - 1); argc -= (optind - 1); /* * Request to load a raw file? */ if (dofile) { if ((typestr == NULL) || (*typestr == 0)) { command_errmsg = "invalid load type"; return(CMD_ERROR); } return(mod_loadobj(typestr, argv[1])); } /* * Looks like a request for a module. */ error = mod_load(argv[1], argc - 2, argv + 2); if (error == EEXIST) sprintf(command_errbuf, "warning: module '%s' already loaded", argv[1]); return (error == 0 ? CMD_OK : CMD_ERROR); }
struct ptype* ptype_alloc_unit(const char* type, char* unit) { struct ptype_reg *reg; for (reg = ptype_reg_head; reg && strcmp(reg->info->name, type); reg = reg->next); if (!reg) { // This should only be needed at startup pomlog(POMLOG_DEBUG "Ptype of type %s not found, trying to load module", type); char ptype_mod_name[64] = { 0 }; strcat(ptype_mod_name, "ptype_"); strncat(ptype_mod_name, type, sizeof(ptype_mod_name) - 1 - strlen(ptype_mod_name)); if (!mod_load(ptype_mod_name)) { pomlog(POMLOG_ERR "Ptype of type %s not found", type); return NULL; } for (reg = ptype_reg_head; reg && strcmp(reg->info->name, type); reg = reg->next); if (!reg) { pomlog(POMLOG_ERR "Ptype of type %s not found even after loading module", type); return NULL; } } struct ptype *ret = malloc(sizeof(struct ptype)); if (!ret) { pom_oom(sizeof(struct ptype)); return NULL; } memset(ret, 0, sizeof(struct ptype)); ret->type = reg; if (reg->info->alloc) { if (reg->info->alloc(ret) != POM_OK) { pomlog(POMLOG_ERR "Error while allocating ptype %s", type); free(ret); return NULL; } } if (unit) { ret->unit = strdup(unit); if (!ret->unit) pom_oom(strlen(unit)); } return ret; }
static int load_module(struct mod **modp, const struct pl *modpath, const struct pl *name) { char file[FS_PATH_MAX]; char namestr[256]; struct mod *m = NULL; int err = 0; if (!name) return EINVAL; #ifdef STATIC /* Try static first */ pl_strcpy(name, namestr, sizeof(namestr)); if (mod_find(namestr)) { info("static module already loaded: %r\n", name); return EALREADY; } err = mod_add(&m, lookup_static_module(name)); if (!err) goto out; #else (void)namestr; #endif /* Then dynamic */ if (re_snprintf(file, sizeof(file), "%r/%r", modpath, name) < 0) { err = ENOMEM; goto out; } err = mod_load(&m, file); if (err) goto out; out: if (err) { warning("module %r: %m\n", name, err); } else if (modp) *modp = m; return err; }
void init_initrd(void) { if (multiboot_info.mods_count < 1) { panic("No initrd."); } void *disk; char *params; int size = mod_load(0, &disk, ¶ms); dbg_printf(DBG_FS, "Loading initrd '%s' at %p with %d bytes length.\n", params, disk, size); if (!check_img(disk)) { panic("Module 1 is not a kOS initrd (%s)\n", params); } root = parse_dir(disk + sizeof(struct id_header), disk); vfs_register(&initrd); }
void __fastcall__ tgi_load_driver (const char* name) /* Install the given driver. This function is identical to tgi_load with the * only difference that the name of the driver is specified explicitly. You * should NOT use this function in most cases, use tgi_load() instead. */ { static struct mod_ctrl ctrl = { read /* Read from disk */ }; unsigned Res; /* Check if we do already have a driver loaded. If so, remove it. */ if (tgi_drv != 0) { tgi_unload (); } /* Now open the file */ ctrl.callerdata = open (name, O_RDONLY); if (ctrl.callerdata >= 0) { /* Load the module */ Res = mod_load (&ctrl); /* Close the input file */ close (ctrl.callerdata); /* Check the return code */ if (Res == MLOAD_OK) { /* Check the driver signature, install the driver */ tgi_install (ctrl.module); return; } } /* Error loading the driver */ tgi_error = TGI_ERR_CANNOT_LOAD; }
static int module_handler(const struct pl *val, void *arg) { struct pl *modpath = arg; char filepath[256]; struct mod *mod; int err; if (val->p && val->l && (*val->p == '/')) (void)re_snprintf(filepath, sizeof(filepath), "%r", val); else (void)re_snprintf(filepath, sizeof(filepath), "%r/%r", modpath, val); err = mod_load(&mod, filepath); if (err) { restund_warning("can't load module %s (%m)\n", filepath, err); goto out; } out: return err; }
static int file_load_dependancies(struct loaded_module *base_file) { struct module_metadata *md; char *dmodname; int error; md = mod_findmetadata(base_file, MODINFOMD_DEPLIST); if (md == NULL) return (0); error = 0; do { dmodname = (char *)md->md_data; if (mod_findmodule(NULL, dmodname) == NULL) { printf("loading required module '%s'\n", dmodname); error = mod_load(dmodname, 0, NULL); if (error && error != EEXIST) break; } md = metadata_next(md, MODINFOMD_DEPLIST); } while (md); return (error); }
static int load_module(struct mod **modp, const struct pl *modpath, const struct pl *name) { char file[256]; struct mod *m = NULL; int err = 0; if (!name) return EINVAL; #ifdef STATIC /* Try static first */ err = mod_add(&m, find_module(name)); if (!err) goto out; #endif /* Then dynamic */ if (re_snprintf(file, sizeof(file), "%r/%r", modpath, name) < 0) { err = ENOMEM; goto out; } err = mod_load(&m, file); if (err) goto out; if (modp) *modp = m; out: if (err) { DEBUG_WARNING("module %r: %m\n", name, err); } return err; }
/*---------------------------------------------------------------------------*/ void ethernet_init(void) { static const char signature[4] = {0x65, 0x74, 0x68, 0x01}; #ifdef STATIC_DRIVER extern void STATIC_DRIVER; module = &STATIC_DRIVER; module->buffer = uip_buf; module->buffer_size = UIP_BUFSIZE; if(module->init(config.ethernet.addr)) { #define _stringize(arg) #arg #define stringize(arg) _stringize(arg) log_message(stringize(STATIC_DRIVER), ": No hardware"); #undef _stringize #undef stringize error_exit(); } #else /* STATIC_DRIVER */ struct mod_ctrl module_control = {cfs_read}; uint8_t byte; module_control.callerdata = cfs_open(config.ethernet.name, CFS_READ); if(module_control.callerdata < 0) { log_message(config.ethernet.name, ": File not found"); error_exit(); } byte = mod_load(&module_control); if(byte != MLOAD_OK) { log_message(config.ethernet.name, byte == MLOAD_ERR_MEM? ": Out of memory": ": No module"); error_exit(); } cfs_close(module_control.callerdata); module = module_control.module; for(byte = 0; byte < 4; ++byte) { if(module->signature[byte] != signature[byte]) { log_message(config.ethernet.name, ": No ETH driver"); error_exit(); } } module->buffer = uip_buf; module->buffer_size = UIP_BUFSIZE; if(module->init(config.ethernet.addr)) { log_message(config.ethernet.name, ": No hardware"); error_exit(); } #endif /* STATIC_DRIVER */ uip_setethaddr(module->ethernet_address); }
int insmod(FAR const char *filename, FAR const char *modulename) { struct mod_loadinfo_s loadinfo; FAR struct module_s *modp; mod_initializer_t initializer; int ret; DEBUGASSERT(filename != NULL && modulename != NULL); sinfo("Loading file: %s\n", filename); /* Get exclusive access to the module registry */ mod_registry_lock(); /* Check if this module is already installed */ if (mod_registry_find(modulename) != NULL) { mod_registry_unlock(); ret = -EEXIST; goto errout_with_lock; } /* Initialize the ELF library to load the program binary. */ ret = mod_initialize(filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { serr("ERROR: Failed to initialize to load module: %d\n", ret); goto errout_with_lock; } /* Allocate a module registry entry to hold the module data */ modp = (FAR struct module_s *)kmm_zalloc(sizeof(struct module_s)); if (ret != 0) { sinfo("Failed to initialize for load of ELF program: %d\n", ret); goto errout_with_loadinfo; } /* Save the module name in the registry entry */ strncpy(modp->modulename, modulename, MODULENAME_MAX); /* Load the program binary */ ret = mod_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { sinfo("Failed to load ELF program binary: %d\n", ret); goto errout_with_registry_entry; } /* Bind the program to the kernel symbol table */ ret = mod_bind(&loadinfo); if (ret != 0) { sinfo("Failed to bind symbols program binary: %d\n", ret); goto errout_with_load; } /* Return the load information */ modp->alloc = (FAR void *)loadinfo.textalloc; #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) modp->textsize = loadinfo.textsize; modp->datasize = loadinfo.datasize; #endif /* Get the module initializer entry point */ initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) modp->initializer = initializer; #endif mod_dumpinitializer(initializer, &loadinfo); /* Call the module initializer */ ret = initializer(&modp->uninitializer, &modp->arg); if (ret < 0) { sinfo("Failed to initialize the module: %d\n", ret); goto errout_with_load; } /* Add the new module entry to the registry */ mod_registry_add(modp); mod_uninitialize(&loadinfo); mod_registry_unlock(); return OK; errout_with_load: mod_unload(&loadinfo); errout_with_registry_entry: kmm_free(modp); errout_with_loadinfo: mod_uninitialize(&loadinfo); errout_with_lock: mod_registry_unlock(); set_errno(-ret); return ERROR; }
int load_module_dynamic(struct mod **modp, const struct pl *modpath, const struct pl *name) { char file[256]; struct mod *m = NULL; int err = 0; if (!name) return EINVAL; if (re_snprintf(file, sizeof(file), "%r\\%r", modpath, name) < 0) { err = ENOMEM; goto out; } err = mod_load(&m, file); if (err) goto out; // set function pointers { pf_set_mem_alloc_cb pf = (pf_set_mem_alloc_cb)mod_sym(m, "set_mem_alloc_cb"); if (pf) pf(mem_alloc); } { pf_set_mem_deref_cb pf = (pf_set_mem_deref_cb)mod_sym(m, "set_mem_deref_cb"); if (pf) pf(mem_deref); } { pf_set_aucodec_register_cb pf = (pf_set_aucodec_register_cb)mod_sym(m, "set_aucodec_register_cb"); if (pf) pf(aucodec_register); } { pf_set_aucodec_unregister_cb pf = (pf_set_aucodec_unregister_cb)mod_sym(m, "set_aucodec_unregister_cb"); if (pf) pf(aucodec_unregister); } { pf_validate_dll pf = (pf_validate_dll)mod_sym(m, "validate_dll"); if (pf) { int rc = pf(); if (rc) { DEBUG_INFO("Failed to validate dll, rc = %d\n", rc); err = ELIBBAD; goto out; } } else { DEBUG_INFO("No validate_dll() symbol\n"); err = ELIBBAD; goto out; } } err = mod_call_init(m); if (err) { goto out; } if (modp) *modp = m; out: if (err) { DEBUG_WARNING("module %r: %m\n", name, err); } return err; }
static int command_load(int argc, char *argv[]) { char *typestr; int dofile, dokld, ch, error; dokld = dofile = 0; optind = 1; optreset = 1; typestr = NULL; if (argc == 1) { command_errmsg = "no filename specified"; return (CMD_CRIT); } while ((ch = getopt(argc, argv, "kt:")) != -1) { switch(ch) { case 'k': dokld = 1; break; case 't': typestr = optarg; dofile = 1; break; case '?': default: /* getopt has already reported an error */ return (CMD_OK); } } argv += (optind - 1); argc -= (optind - 1); printf("Loading %s...\n", argv[1]); /* * Request to load a raw file? */ if (dofile) { if ((typestr == NULL) || (*typestr == 0)) { command_errmsg = "invalid load type"; return (CMD_CRIT); } if (file_findfile(argv[1], typestr) != NULL) { snprintf(command_errbuf, sizeof (command_errbuf), "warning: file '%s' already loaded", argv[1]); return (CMD_WARN); } if (file_loadraw(argv[1], typestr, argc - 2, argv + 2, 1) != NULL) return (CMD_OK); /* Failing to load mfs_root is never going to end well! */ if (strcmp("mfs_root", typestr) == 0) return (CMD_FATAL); return (CMD_ERROR); } /* * Do we have explicit KLD load ? */ if (dokld || file_havepath(argv[1])) { error = mod_loadkld(argv[1], argc - 2, argv + 2); if (error == EEXIST) { snprintf(command_errbuf, sizeof (command_errbuf), "warning: KLD '%s' already loaded", argv[1]); return (CMD_WARN); } return (error == 0 ? CMD_OK : CMD_CRIT); } /* * Looks like a request for a module. */ error = mod_load(argv[1], NULL, argc - 2, argv + 2); if (error == EEXIST) { snprintf(command_errbuf, sizeof (command_errbuf), "warning: module '%s' already loaded", argv[1]); return (CMD_WARN); } return (error == 0 ? CMD_OK : CMD_CRIT); }