static struct snobj *handle_connect_modules(struct snobj *arg) { const char *m1_name; const char *m2_name; uint16_t gate; struct module *m1; struct module *m2; int ret; m1_name = snobj_eval_str(arg, "m1"); m2_name = snobj_eval_str(arg, "m2"); gate = snobj_eval_uint(arg, "gate"); if (!m1_name || !m2_name) return snobj_err(EINVAL, "Missing 'm1' or 'm2' field in arg"); if ((m1 = find_module(m1_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m1_name); if ((m2 = find_module(m2_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m2_name); ret = connect_modules(m1, gate, m2); if (ret < 0) return snobj_err(-ret, "Connection '%s'[%d]->'%s' failed", m1_name, gate, m2_name); printf("%s[%d] -> %s\n", m1_name, gate, m2_name); return NULL; }
errval_t start_networking(coreid_t core, struct module_info* driver, char* record) { assert(driver != NULL); errval_t err = SYS_ERR_OK; if (is_started(driver)) { return KALUGA_ERR_DRIVER_ALREADY_STARTED; } if (!is_auto_driver(driver)) { return KALUGA_ERR_DRIVER_NOT_AUTO; } struct module_info* netd = find_module("netd"); if (netd == NULL || !is_auto_driver(netd)) { KALUGA_DEBUG("netd not found or not declared as auto."); return KALUGA_ERR_DRIVER_NOT_AUTO; } struct module_info* ngd_mng = find_module("NGD_mng"); if (ngd_mng == NULL || !is_auto_driver(ngd_mng)) { KALUGA_DEBUG("NGD_mng not found or not declared as auto."); return KALUGA_ERR_DRIVER_NOT_AUTO; } err = spawn_program(core, driver->path, driver->argv + 1, environ, 0, &driver->did); if (err_is_fail(err)) { DEBUG_ERR(err, "Spawning %s failed.", driver->path); return err; } // XXX: Manually add cardname (overwrite first (auto) argument) // +Weird convention, e1000n binary but cardname=e1000 char* cardname = strcmp(driver->binary, "e1000n") == 0 ? "e1000" : driver->binary; size_t name_len = strlen("cardname=") + strlen(cardname) + 1; char* card_argument = malloc(name_len); sprintf(card_argument, "cardname=%s", cardname); printf("############# starting network with argiments %s\n", card_argument); // Spawn netd and ngd_mng netd->argv[0] = card_argument; err = spawn_program(core, netd->path, netd->argv, environ, 0, &netd->did); ngd_mng->argv[0] = card_argument; err = spawn_program(core, ngd_mng->path, ngd_mng->argv, environ, 0, &ngd_mng->did); free(card_argument); return err; }
/* Try to find an module named 'name' within the given import. If the given import is NULL, then both the current import AND the builtin import are searched. */ lily_module_entry *lily_find_module(lily_symtab *symtab, lily_module_entry *module, const char *name) { lily_module_entry *result; if (module == NULL) result = find_module(symtab->active_module, name); else result = find_module(module, name); return result; }
struct vox_module_methods* vox_load_module (const char *name, int type) { char fullpath[MAXPATHLEN]; int found = find_module (name, fullpath); if (!found) return NULL; /* * Instead of track references to modules and store pointers to methods in * the hash table, we open modules with RTLD_NODELETE, so closure only * decrements reference counter and leaves a pointer to methods valid. */ void *handle = dlopen (fullpath, RTLD_LAZY | RTLD_NODELETE); if (handle == NULL) return NULL; struct vox_module* (*module_init)() = (struct vox_module* (*)()) dlfunc (handle, "module_init"); if (module_init == NULL) { dlclose (handle); return NULL; } dlclose (handle); struct vox_module *module = module_init(); if (module->type != type) return NULL; return module->methods; }
static void clousure_globals(void) { bp_fun_t calledfun, fun, funtemp; bp_ident_t y, funglobals; discover_globals_in_module(); //add globals in enforse to the module for (fun = bp_functions; fun; fun = fun->next) { discover_globals_in_module_in_expression(fun->enforce, fun); } clousure_calledmodule(); for (fun = bp_functions; fun; fun = fun->next) { for (calledfun = fun->calledmodule; calledfun; calledfun = calledfun->next) { funtemp = find_module(bp_functions, calledfun->funname); for (funglobals = funtemp->globals; funglobals; funglobals = funglobals->next) { y = Is_there_var(fun->globals, funglobals->varname); if (!y) { bp_decls = fun->globals; Insert_var(funglobals->varname); fun->globals = bp_decls; } } } } }
static struct snobj *handle_enable_tcpdump(struct snobj *q) { const char *m_name; const char *fifo; gate_t gate; struct module *m; int ret; m_name = snobj_eval_str(q, "name"); gate = snobj_eval_uint(q, "gate"); fifo = snobj_eval_str(q, "fifo"); if (!m_name) return snobj_err(EINVAL, "Missing 'name' field"); if ((m = find_module(m_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m_name); if (gate >= m->allocated_gates) return snobj_err(EINVAL, "Gate '%hu' does not exist", gate); ret = enable_tcpdump(fifo, m, gate); if (ret < 0) { return snobj_err(-ret, "Enabling tcpdump %s[%d] failed", m_name, gate); } return NULL; }
int process_dii(struct carousel *car, struct DownloadInfoIndication *dii, uint32_t transactionId) { unsigned int nmodules; unsigned int i; int processed = 0; verbose("DownloadInfoIndication "); verbose("transactionId: %u, ", transactionId); verbose("downloadId: %u, ", ntohl(dii->downloadId)); nmodules = DII_numberOfModules(dii); // verbose2("numberOfModules: %u, ", nmodules); for(i=0; i<nmodules; i++) { struct DIIModule *mod; mod = DII_module(dii, i); vverbose("Module %u", i); vverbose(" moduleId: %u", ntohs(mod->moduleId)); vverbose(" moduleVersion: %u", mod->moduleVersion); vverbose(" moduleSize: %u", ntohl(mod->moduleSize)); if(find_module(car, ntohs(mod->moduleId), mod->moduleVersion, ntohl(dii->downloadId)) == NULL) { vverbose("Adding module %u", i); add_module(car, dii, mod); processed = 1; } } return processed; }
void cmd_modon( const ArgList& args ) { if (args.size( ) < 2) { core::system_errspeak( "Expected a module name." ); return; } size_t i_arg = 1; string arg = (args.size( ) > i_arg++) ? args[ i_arg - 1 ] : ""; while (arg.length( )) { unsigned int mod = find_module( arg ); if (mod != -1) { core::system_speak( "Enabling " + arg ); enable_module( mod, true ); } else { core::system_errspeak( "Can't find module " + arg ); } arg = (args.size( ) > i_arg++) ? args[ i_arg - 1 ] : ""; } }
void *register_module(const char *module_file, const char *type) { void *module = NULL; int mod_type; struct modules_list *l = NULL; struct module_tmp_struct *check_mod; int check_mod_type; l = modules_lists_table[mod_type = module_type(type)]; if (l == NULL) return NULL; module = load_module(module_file); if (!module) { ci_debug_printf(3, "Error while loading module %s\n", module_file); return NULL; } check_mod = (struct module_tmp_struct *)module; if (find_module(check_mod->name, &check_mod_type) != NULL) { ci_debug_printf(1, "Error, the module %s is already loaded\n", check_mod->name); return NULL; } init_module(module, mod_type); add_to_modules_list(l, module); return module; }
/* sets obj->mod if object is not vmlinux and module is found */ static void klp_find_object_module(struct klp_object *obj) { struct module *mod; if (!klp_is_module(obj)) return; mutex_lock(&module_mutex); /* * We do not want to block removal of patched modules and therefore * we do not take a reference here. The patches are removed by * klp_module_going() instead. */ mod = find_module(obj->name); /* * Do not mess work of klp_module_coming() and klp_module_going(). * Note that the patch might still be needed before klp_module_going() * is called. Module functions can be called even in the GOING state * until mod->exit() finishes. This is especially important for * patches that modify semantic of the functions. */ if (mod && mod->klp_alive) obj->mod = mod; mutex_unlock(&module_mutex); }
int load_module2(struct mod **modp, const struct pl *name) { struct mod *m = NULL; int err = 0; if (!name) return EINVAL; /* Try static */ err = mod_add(&m, find_module(name)); if (err) 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; }
int __init __symbol_put_init(void) { const char * symbol_name ; const char * mod_name ; struct module * fmodule ; symbol_name = "symbol_A"; mod_name = "test_module"; //定义待查找的模块名为“test_module” fmodule = find_module( mod_name ); //调用查找模块函数 if(fmodule != NULL ) { printk("<0>before calling __symbol_put,\n"); printk("<0>ref of %s is: %d\n",mod_name, module_refcount(fmodule)); __symbol_put(symbol_name); //will dec the count printk("<0>after calling __symbol_put,\n"); printk("<0>ref of %s is: %d\n",mod_name, module_refcount(fmodule)); } else { printk("<0>find %s failed!\n", mod_name ); } return 0; }
PUBLIC HTAAModule * HTAA_newModule (const char * scheme, HTNetBefore * before, HTNetAfter * after, HTNetAfter * update, HTUTree_gc * gc) { if (scheme) { HTAAModule * pres = find_module(scheme); /* If found then update entry - else create a new one */ if (!pres) { if (!(pres = (HTAAModule *) HT_CALLOC(1, sizeof(HTAAModule)))) HT_OUTOFMEM("HTAA_newModule"); StrAllocCopy(pres->scheme, scheme); pres->before = before; pres->after = after; pres->update = update; pres->gc = gc; /* Add the new AA Module to the list */ HTList_addObject(HTSchemes, (void *) pres); HTTRACE(AUTH_TRACE, "Auth Engine. Created module %p\n" _ pres); } else { HTTRACE(AUTH_TRACE, "Auth Engine. Found module %p\n" _ pres); } return pres; } else { HTTRACE(AUTH_TRACE, "Auth Engine. Bad argument\n"); return NULL; } }
declaration * find_class (umlclassnode *node) { declaration *d; if (node->key->package != NULL) { umlpackagelist pkglist = make_package_list (node->key->package); module *m = find_module (decls, pkglist); if (m == NULL || m->contents == NULL) return 0; d = m->contents; } else { d = decls; } while (d != NULL) { if (d->decl_kind == dk_class) { umlclassnode *cl = d->u.this_class; if (!strcmp (cl->key->name, node->key->name)) return d; } d = d->next; } return NULL; }
//-------------------------------------------------------------------------- uint32 win32_debmod_t::calc_imagesize(ea_t ea) { if ( _GetModuleInformation ) { HMODULE hMod; if ( ea == 0 ) { hMod = 0; } else { modbase_to_entry_t mbh = {ea, }; int code = for_each_module(pid, &get_module_by_base, &mbh); if ( code == 1 ) hMod = mbh.me.hModule; else hMod = (HMODULE)ea; // last resort } MODULEINFO mi; if ( _GetModuleInformation(process_handle, hMod, &mi, sizeof(mi)) ) return mi.SizeOfImage; } wince_module_t wm; if ( find_module(ea, &wm) ) return get_e32(&wm).vsize; return 0; }
//-------------------------------------------------------------------------- uint32 win32_debmod_t::calc_imagesize(ea_t ea) { wince_module_t wm; if ( find_module(ea, &wm) ) return get_e32(&wm).vsize; return 0; }
static struct snobj *handle_disable_tcpdump(struct snobj *arg) { const char *m_name; uint16_t gate; struct module *m; int ret; m_name = snobj_eval_str(arg, "name"); gate = snobj_eval_uint(arg, "gate"); if (!m_name) return snobj_err(EINVAL, "Missing 'name' field in arg"); if ((m = find_module(m_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m_name); if (gate >= m->allocated_gates) return snobj_err(EINVAL, "Gate '%hu' does not exist", gate); ret = disable_tcpdump(m, gate); if (ret < 0) { return snobj_err(-ret, "Disabling tcpdump %s[%d] failed", m_name, gate); } return NULL; }
static struct snobj *handle_disconnect_modules(struct snobj *arg) { const char *m_name; uint16_t gate; struct module *m; int ret; m_name = snobj_eval_str(arg, "name"); gate = snobj_eval_uint(arg, "gate"); if (!m_name) return snobj_err(EINVAL, "Missing 'name' field in arg"); if ((m = find_module(m_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m_name); ret = disconnect_modules(m, gate); if (ret < 0) return snobj_err(-ret, "Disconnection '%s'[%d] failed", m_name, gate); printf("%s[%d] -> <dead end>\n", m_name, gate); return NULL; }
/** * Unregister a module * * @param module The name of the module to remove */ static void unregister_module(const char *module) { MODULES *mod = find_module(module); MODULES *ptr; if (!mod) return; // Module not found if (registered == mod) registered = mod->next; else { ptr = registered; while (ptr && ptr->next != mod) ptr = ptr->next; } /*< * The module is now not in the linked list and all * memory related to it can be freed */ free(mod->module); free(mod->type); free(mod->version); free(mod); }
static struct module *get_ugly(void) { struct module *mod; mutex_lock(&module_mutex); mod = find_module(TARGET_MODULE); mutex_unlock(&module_mutex); return mod; }
static struct snobj *handle_attach_task(struct snobj *q) { const char *m_name; const char *tc_name; task_id_t tid; struct module *m; struct task *t; m_name = snobj_eval_str(q, "name"); if (!m_name) return snobj_err(EINVAL, "Missing 'name' field"); if ((m = find_module(m_name)) == NULL) return snobj_err(ENOENT, "No module '%s' found", m_name); tid = snobj_eval_uint(q, "taskid"); if (tid >= MAX_TASKS_PER_MODULE) return snobj_err(EINVAL, "'taskid' must be between 0 and %d", MAX_TASKS_PER_MODULE - 1); if ((t = m->tasks[tid]) == NULL) return snobj_err(ENOENT, "Task %s:%hu does not exist", m_name, tid); tc_name = snobj_eval_str(q, "tc"); if (tc_name) { struct tc *c; c = ns_lookup(NS_TYPE_TC, tc_name); if (!c) return snobj_err(ENOENT, "No TC '%s' found", tc_name); task_attach(t, c); } else { int wid; /* TODO: worker_id_t */ if (task_is_attached(t)) return snobj_err(EBUSY, "Task %s:%hu is already " "attached to a TC", m_name, tid); wid = snobj_eval_uint(q, "wid"); if (wid >= MAX_WORKERS) return snobj_err(EINVAL, "'wid' must be between 0 and %d", MAX_WORKERS - 1); if (!is_worker_active(wid)) return snobj_err(EINVAL, "Worker %d does not exist", wid); assign_default_tc(wid, t); } return NULL; }
Block* find_module_for_require_statement(Term* term) { if (term->input(0) == NULL) return NULL; Value* moduleName = term_value(term->input(0)); return find_module(term->owningBlock, moduleName); }
//-------------------------------------------------------------------------- static bool find_impdir(area_t *impdir) { impdir->startEA = impdir->endEA = 0; uint32 ea32 = uint32(an_imported_func); for ( ea_t pos = curmod.startEA; pos <= curmod.endEA && (pos = bin_search(pos, curmod.endEA, (uchar *)&ea32, NULL, 4, BIN_SEARCH_FORWARD, BIN_SEARCH_NOBREAK|BIN_SEARCH_CASE)) != BADADDR; pos += sizeof(DWORD) ) { // skip unaligned matches if ( (pos & 3) != 0 ) continue; // cool, we found a pointer to an imported function // now try to determine the impdir bounds ea_t bounds[2] = {pos, pos}; for ( int k=0; k < 2; k++ ) { ea_t ea = pos; while ( true ) { if ( k == 1 ) ea += ptrSz; else ea -= ptrSz; ea_t func = is_9x ? win9x_find_thunk(ea) : getPtr(ea); if ( func == 0 ) continue; if ( !isEnabled(func) ) break; if ( curmod.contains(func) ) break; module_info_t mi; if ( !find_module(func, &mi) ) break; bounds[k] = ea; } } bounds[1] += ptrSz; asize_t bsize = bounds[1] - bounds[0]; if ( bsize > impdir->size() ) *impdir = area_t(bounds[0], bounds[1]); } return impdir->startEA != 0; }
/* * returns a block that has been memalloc()'ed */ char *read_option(struct module *am, char *name) { int ao=0, bo=0, co=0; char *as=NULL, *bs=NULL, *cs=NULL; struct module *bm=NULL; char *result=NULL; int size; /* do_error("read_option(%p, %s)", am, name);*/ if (am!=NULL) ao = find_option(am, name); if ((bm = find_module("global"))!=NULL) bo = find_option(bm, name); /* else do_error("erk! lost global!");*/ if (cli!=NULL) co = find_option(cli, name); /* do_error("read_option(): ao = %i, bo = %i, co = %i", ao, bo, co);*/ /* if any are 'set', then they override; otherwise, they build up */ if (ao>0) { bo=0; co=0; } /* if (bo>0) co=0;*/ if (co>0) bo=0; /* cli overrides global block. This makes /much/ more sense ... */ if (ao==0 && bo==0 && co==0) return NULL; /* couldn't find it */ as = get_option(am, ao); bs = get_option(bm, bo); cs = get_option(cli, co); size = ((as==NULL)?(0):(strlen(as))) + ((bs==NULL)?(0):(strlen(bs))) + ((cs==NULL)?(0):(strlen(cs))) + 1; result = memalloc(size); result[0]=0; /* cli + global + per-module. Different to absolute overrides, above, where * cli is more important than global. */ if (cs!=NULL) strcat(result, cs); if (bs!=NULL) strcat(result, bs); if (as!=NULL) strcat(result, as); return result; }
PUBLIC HTAAModule * HTAA_findModule (const char * scheme) { if (scheme) { HTAAModule * pres = find_module(scheme); HTTRACE(AUTH_TRACE, "Auth Engine. did %sfind %s\n" _ pres ? "" : "NOT " _ scheme); return pres; } else { HTTRACE(AUTH_TRACE, "Auth Engine. Bad augument\n"); } return NULL; }
// delete_module.cmt long delete_module(const char *modname, unsigned int flags) { struct mod *mod; init_retcodes(); mod = find_module(modules, modname); if (mod == NULL) return 0; errno = mod->errcode; return mod->ret; }
/** * Unload a module. * * No errors are returned since it is not clear that much can be done * to fix issues relating to unloading modules. * * @param module The name of the module */ void unload_module(const char *module) { MODULES *mod = find_module(module); void *handle; if (!mod) return; handle = mod->handle; unregister_module(module); dlclose(handle); }
int do_cleanup_module(const char __user * name_user) { struct module *mod; char name[MODULE_NAME_LEN]; int ret = 0, forced = 0; struct mm_struct *mm = current->mm; lock_mm(mm); int length = strlen(name_user); if (!copy_from_user(mm, name, name_user, length, 1)) { unlock_mm(mm); return -E_INVAL; } unlock_mm(mm); name[length] = '\0'; mod = find_module(name); if (!mod) { ret = -E_NOENT; goto out; //return -E_NOENT; } if (!list_empty(&mod->modules_which_use_me)) { ret = -E_INVAL; goto out; } if (mod->state != MODULE_STATE_LIVE) { kprintf("do_cleanup_module: %s already dying\n", mod->name); ret = -E_BUSY; } if (mod->init && !mod->exit) { kprintf("do_cleanup_module: %s can't be removed\n", mod->name); ret = -E_BUSY; } mod->waiter = current; mod->state = MODULE_STATE_GOING; if (mod->exit != NULL) mod->exit(); strncpy(last_unloaded_module, mod->name, strlen(mod->name)); free_module(mod); return ret; out: return ret; }
PUBLIC BOOL HTAA_deleteModule (const char * scheme) { if (scheme) { HTAAModule * pres = find_module(scheme); if (pres) { HTList_removeObject(HTSchemes, pres); HTTRACE(AUTH_TRACE, "Auth Engine. deleted %p\n" _ pres); delete_module(pres); return YES; } } return NO; }
TEST(api_module, global_syx_ref__refer_exported_symbol_of_imported_module__restrictive) { ScmObj sym = SCM_OBJ_INIT, syx = SCM_OBJ_INIT, actual = SCM_OBJ_INIT; SCM_REFSTK_INIT_REG(&sym, &syx, &actual); sym = scm_make_symbol_from_cstr("var", SCM_ENC_ASCII); syx = SCM_EOF_OBJ; make_module("imp"); make_module("test"); import_module("imp", true); find_module("imp"); TEST_ASSERT_EQUAL_INT(0, scm_capi_define_global_syx(module, sym, syx, true)); find_module("test"); TEST_ASSERT_EQUAL_INT(0, scm_capi_refer_global_syx(module, sym, SCM_CSETTER_L(actual))); TEST_ASSERT_SCM_EQ(syx, actual); }