Пример #1
0
int
pcifn_enum(topo_mod_t *mp, tnode_t *parent)
{
	char *ccstr;
	int rv = 0;
	int i, e;
	uint_t cc;
	topo_mod_t *child_mod;

	topo_mod_dprintf(mp, "Enumerating beneath pci(ex) function.\n");

	/*
	 * Extract the class code of the PCI function and make sure
	 * it matches the type that the module cares about.
	 */
	if (topo_prop_get_string(parent,
	    TOPO_PGROUP_PCI, TOPO_PROP_CLASS, &ccstr, &e) < 0)
		return (0);
	if (sscanf(ccstr, "%x", &cc) != 1) {
		topo_mod_strfree(mp, ccstr);
		return (0);
	}
	topo_mod_strfree(mp, ccstr);
	cc = cc >> 16;

	for (i = 0; i < Pcifn_enumerator_count; i++) {

		if (cc != Pcifn_enumerators[i].pfne_class)
			continue;

		child_mod = module_load(mp, parent,
		    Pcifn_enumerators[i].pfne_modname);

		if (child_mod) {
			rv = module_run(mp, parent,
			    &Pcifn_enumerators[i]) != 0 ? -1 : 0;
			topo_mod_unload(child_mod);
		}
	}
	return (rv);
}
Пример #2
0
int sys_init_module(void* image, unsigned long len, const char* param_values) {
    if(unlikely(!image || !len)) {
        errno = EINVAL;
        return -1;
    }

    if(unlikely(current_task->uid != TASK_ROOT_UID)) {
        errno = EPERM;
        return -1;
    }

    char* name;
    if(module_check(image, (size_t) len, &name) != 0)
        return -1;

    if(module_load(name) != 0)
        return -1;

    if(module_run(name) != 0)
        return -1;

    return 0;
});