Exemplo n.º 1
0
int main(void)
{
	/* NOTE! 这些初始化函数的位置别随便改动! */
	trap_init();	/* 在设置其他中断之前 */
	console_init();	/* 需打印的在这之后 */
	keyboard_init();
	hd_init();		/* 需读磁盘的放其后 */
/*	graph_init(); */
	mem_init();
	sched_init();
	buff_init();	/* 在内存初始化之后 */
	inode_init();
	file_table_init();
	debug_init();
	sti();
	super_init(0);	/* 开中断之后 */
	files_init();

/*	unsigned short color = rgb_to_565color(255,255,255);
	draw_rect(0, 0, 800, 600, color, 1); */

	move_to_user_mode();

	/*
	 * 进程0马上execve(),替换掉用户态空间,这样进程0就
	 * 可以写时复制了。注意此时原来的用户态堆栈也被丢弃
	 * 了,换成了新堆栈。更多参见内存管理。
	 */
	if(!execve("/init"))
		printf("main: execve init-process failed.\n");
Exemplo n.º 2
0
// this is called during hardware initialization.
// allocate memory.
void app_init(void) {
  print_dbg("\r\n net_init... ");
  net_init();

  print_dbg("\r\n preset_init...");  
  presets_init();

  print_dbg("\r\n scene_init...");
  scene_init();

  print_dbg("\r\n files_init...");
  files_init();

  /// WARNING: initialization order is important.

  print_dbg("\r\n render_init...");
  render_init();

  /// move these after scene load,
  // so that initial graphics reflect scene data
  /* print_dbg("\r\n pages_init..."); */
  /* pages_init(); */

  /* print_dbg("\r\n play_init..."); */
  /* play_init(); */

  // initialize flash-management buffers
  print_dbg("\r\n flash_bees_init...");
  flash_bees_init();
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    honggfuzz_t hfuzz;
    if (cmdlineParse(argc, argv, &hfuzz) == false) {
        LOG_F("Parsing of the cmd-line arguments failed");
    }

    if (!files_init(&hfuzz)) {
        LOG_F("Couldn't load input files");
        exit(EXIT_FAILURE);
    }

    if (hfuzz.dictionaryFile && (files_parseDictionary(&hfuzz) == false)) {
        LOG_F("Couldn't parse dictionary file ('%s')", hfuzz.dictionaryFile);
    }

    if (hfuzz.blacklistFile && (files_parseBlacklist(&hfuzz) == false)) {
        LOG_F("Couldn't parse stackhash blacklist file ('%s')", hfuzz.blacklistFile);
    }

    /*
     * So far so good
     */
    fuzz_main(&hfuzz);

    abort();                    /* NOTREACHED */
    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
// this is called during hardware initialization.
// allocate memory.
void app_init(void) {

  print_dbg("\r\n preset_init...");  
  presets_init();

  // this must come after preset init!
  // uses preset data when adding system ops...
  print_dbg("\r\n net_init... ");
  net_init();

  print_dbg("\r\n scene_init...");
  scene_init();

  print_dbg("\r\n files_init...");
  files_init();

  /// WARNING: initialization order is important.

  print_dbg("\r\n render_init...");
  render_init();

  // initialize flash-management buffers
  print_dbg("\r\n flash_bees_init...");
  flash_bees_init();
}
Exemplo n.º 5
0
static
void
init(void)
{
	stringarray_init(&freestrings);

	incpath_init();
	commandline_macros_init();
	commandline_files_init();

	place_init();
	files_init();
	directive_init();
	macros_init();
}
Exemplo n.º 6
0
static void all_init(void)
{
    log_init();
    files_init();
    ext_init();
    cli_init();
    mallocer_init();    // as all users do not init it...
    ref_init(); // as all users do not init it...
    hash_init();    // as all users do not init it...
    redim_array_init(); // if there are no users then some ext functions used by the www interface won't be defined
    os_detect_init();   // dummy function just to include os_detect in junkie (that does not use it, but plugins may want to)

    // Openssl don't like to be inited several times so let's do it once and for all
    SSL_load_error_strings();
    SSL_library_init();
    OpenSSL_add_all_algorithms();

    for (unsigned i = 0; i < NB_ELEMS(initers); i++) {
        initers[i].init();
    }

    ext_rebind();
}
Exemplo n.º 7
0
int options_parse(int argc, const char** argv, options_t* options)
{
  uint64_t val;
  int i;

  /* Initialize options to default values. */
  options->nconnections = DEFAULT_CONNECTIONS;
  options->nthreads = DEFAULT_THREADS;
  options->receive = DEFAULT_RECEIVE;
  options->number_thread_loops = DEFAULT_LOOPS;
  options->number_connection_loops = DEFAULT_LOOPS;
  options->client_sends_first = CLIENT_SENDS_FIRST;
  options->set_read_write_event = SET_READ_WRITE_EVENT;
  options->nprocessors = 0;

  files_init(&options->files);

  /* Last parameter is not an option. */
  argc--;

  i = 1;
  while (i < argc) {
    if (strcasecmp(argv[i], "--connections") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_CONNECTIONS,
                       MAX_CONNECTIONS,
                       &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->nconnections = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--threads") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1], MIN_THREADS, MAX_THREADS, &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->nthreads = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--receive") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1], MIN_RECEIVE, MAX_RECEIVE, &val) < 0) {
        files_free(&options->files);
        return -1;
      }

      options->receive = (unsigned) val;

      i += 2;
    } else if (strcasecmp(argv[i], "--thread-loops") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_LOOPS,
                       MAX_LOOPS,
                       &options->number_thread_loops) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--connection-loops") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_uint64(argv[i + 1],
                       MIN_LOOPS,
                       MAX_LOOPS,
                       &options->number_connection_loops) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--client-sends-first") == 0) {
      options->client_sends_first = 1;

      i++;
    } else if (strcasecmp(argv[i], "--server-sends-first") == 0) {
      options->client_sends_first = 0;

      i++;
    } else if (strcasecmp(argv[i], "--set-read-write-event") == 0) {
      options->set_read_write_event = 1;

      i++;
    } else if (strcasecmp(argv[i], "--do-not-set-read-write-event") == 0) {
      options->set_read_write_event = 0;

      i++;
    } else if (strcasecmp(argv[i], "--processors") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (parse_processors(argv[i + 1],
                           options->processors,
                           &options->nprocessors) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else if (strcasecmp(argv[i], "--file") == 0) {
      /* Last parameter? */
      if (i + 1 == argc) {
        files_free(&options->files);
        return -1;
      }

      if (files_add(&options->files, argv[i + 1]) < 0) {
        files_free(&options->files);
        return -1;
      }

      i += 2;
    } else {
      files_free(&options->files);
      return -1;
    }
  }

  /* If no files have been specified... */
  if (options->files.used == 0) {
    if (files_add_dummy(&options->files) < 0) {
      files_free(&options->files);
      return -1;
    }
  }

  options->nthreads = MIN(options->nthreads, options->nconnections);

  if (options->receive == 0) {
    options->client_sends_first = 1;
  }

  return 0;
}
/**
 * listens to the passed server socket, accepts new connection requests and
 *   services them until application termination.
 *
 * @function   child_process
 *
 * @date       2016-02-14
 *
 * @revision   none
 *
 * @designer   Eric Tsang
 *
 * @programmer Eric Tsang
 *
 * @note       none
 *
 * @signature  int child_process(int serverSocket)
 *
 * @param      serverSocket server socket on the local host to accept and
 *   service connection requests from.
 *
 * @return     exit code of the process.
 */
int child_process(int serverSocket)
{
    // create selectable files set
    Files files;
    files_init(&files);

    // add server socket to select event loop
    files_add_file(&files,serverSocket);

    // execute select event loop
    while (true)
    {
        // wait for select to unblock to report socket activity
        // wait for an event on any socket to occur
        if(files_select(&files) == -1)
        {
            fatal_error("failed on select");
        }

        // loop through sockets, and handle them
        for(std::set<int>::iterator socketIt = files.fdSet.begin(); socketIt != files.fdSet.end(); ++socketIt)
        {
            int curSock = *socketIt;

            // if this socket doesn't have any activity, move on to next socket
            if(!FD_ISSET(curSock,&files.selectFds))
            {
                continue;
            }

            // handling case when client socket has data available for reading
            if (curSock != serverSocket)
            {
                // read data from socket...
                static char buf[ECHO_BUFFER_LEN];
                register int bytesRead;

                // read and echo back to client
                while ((bytesRead = recv(curSock,buf,ECHO_BUFFER_LEN,0)) > 0)
                {
                    send(curSock,buf,bytesRead,0);
                }

                // if call would block, continue event loop
                if (bytesRead == -1 && errno == EWOULDBLOCK)
                {
                    errno = 0;
                }

                // close socket if connection is closed or unexpected error
                else
                {
                    // close socket & remove from select event loop
                    close(curSock);
                    files_rm_file(&files,curSock);
                }
                continue;
            }

            // handling case when server socket receives a connection request
            else
            {
                // accept the remote connection
                int newSocket = accept(serverSocket,0,0);

                // ignore EAGAIN because this socket is shared, and connection
                // may have been accepted by another process
                if (newSocket == -1 && errno != EAGAIN)
                {
                    fatal_error("accept");
                }

                // propagate error if it is unexpected
                else if (errno == EAGAIN)
                {
                    errno = 0;
                    continue;
                }

                // configure new socket to be non-blocking
                int existingFlags = fcntl(newSocket,F_GETFL,0);
                if (fcntl(newSocket,F_SETFL,O_NONBLOCK|existingFlags) == -1)
                {
                    fatal_error("fcntl");
                }

                // add new socket to select loop
                files_add_file(&files,newSocket);
                continue;
            }
        }
    }
    return EX_OK;
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{
    int c;
    int ll = l_INFO;
    honggfuzz_t hfuzz;

    hfuzz.inputFile = NULL;
    hfuzz.nullifyStdio = false;
    hfuzz.fuzzStdin = false;
    hfuzz.saveUnique = false;
    hfuzz.fileExtn = "fuzz";
    hfuzz.flipRate = 0.001f;
    hfuzz.flipMode = 'B';
    hfuzz.fuzzStart = 0;
    hfuzz.fuzzEnd = UINT_MAX;
    hfuzz.externalCommand = NULL;
    hfuzz.tmOut = 3;
    hfuzz.ignoreAddr = (void *)0UL;
    hfuzz.threadsMax = 5;
    hfuzz.asLimit = 0UL;
    hfuzz.cmdline = NULL;
    hfuzz.pid = 0;

    hfuzz.files = NULL;
    hfuzz.threadsCnt = 0;

    printf(AB PROG_NAME " version " PROG_VERSION "\n" PROG_AUTHORS AC "\n");
    if (argc < 2) {
        usage();
        exit(EXIT_SUCCESS);
    }

    for (;;) {
        c = getopt(argc, argv, "hqsuf:d:e:r:m:c:t:a:n:l:p:b:w:");
        if (c < 0)
            break;

        switch (c) {
        case 'f':
            hfuzz.inputFile = optarg;
            break;
        case 'h':
            usage();
            break;
        case 'q':
            hfuzz.nullifyStdio = true;
            break;
        case 's':
            hfuzz.fuzzStdin = true;
            break;
        case 'u':
            hfuzz.saveUnique = true;
            break;
        case 'd':
            ll = atoi(optarg);
            break;
        case 'e':
            hfuzz.fileExtn = optarg;
            break;
        case 'r':
            hfuzz.flipRate = atof(optarg);
            break;
        case 'm':
            hfuzz.flipMode = optarg[0];
            break;
        case 'c':
            hfuzz.externalCommand = optarg;
            break;
        case 't':
            hfuzz.tmOut = atol(optarg);
            break;
        case 'a':
            hfuzz.ignoreAddr = (void *)atol(optarg);
            break;
        case 'n':
            hfuzz.threadsMax = atol(optarg);
            break;
        case 'l':
            hfuzz.asLimit = strtoul(optarg, NULL, 10);
            break;
        case 'p':
            hfuzz.pid = atoi(optarg);
            break;
        case 'b':
            hfuzz.fuzzStart = strtoul(optarg, NULL, 10);
            break;
        case 'w':
            hfuzz.fuzzEnd = strtoul(optarg, NULL, 10);
            break;
        default:
            break;
        }
    }
    hfuzz.cmdline = &argv[optind];

    util_rndInit();
    log_setMinLevel(ll);

    if (!hfuzz.cmdline[0]) {
        LOGMSG(l_FATAL, "Please specify binary to fuzz");
        usage();
    }

    if (!hfuzz.fuzzStdin && !checkFor_FILE_PLACEHOLDER(hfuzz.cmdline)) {
        LOGMSG(l_FATAL,
               "You must specify '" FILE_PLACEHOLDER
               "' when the -s (stdin fuzzing) option is not set");
        usage();
    }

    if (hfuzz.pid) {
        LOGMSG(l_INFO, "External PID specified, concurrency disabled");
        hfuzz.threadsMax = 1;
    }

    if (strchr(hfuzz.fileExtn, '/')) {
        LOGMSG(l_FATAL, "The file extension contains the '/' character: '%s'", hfuzz.fileExtn);
        usage();
    }

    if (hfuzz.fuzzStart > hfuzz.fuzzEnd || hfuzz.fuzzStart == hfuzz.fuzzEnd) {
        LOGMSG(l_FATAL, "Invalid mangle fuzz area file offsets");
        usage();
    }

    LOGMSG(l_INFO,
           "debugLevel: %d, inputFile '%s', nullifyStdio: %d, fuzzStdin: %d, saveUnique: %d, flipRate: %lf, "
           "flipMode: '%c', externalCommand: '%s', tmOut: %ld, threadsMax: %ld, fileExtn '%s', ignoreAddr: %p, "
           "memoryLimit: %lu (MiB), fuzzExe: '%s', fuzzedPid: %d",
           ll, hfuzz.inputFile, hfuzz.nullifyStdio ? 1 : 0,
           hfuzz.fuzzStdin ? 1 : 0, hfuzz.saveUnique ? 1 : 0, hfuzz.flipRate, hfuzz.flipMode,
           hfuzz.externalCommand == NULL ? "NULL" : hfuzz.externalCommand, hfuzz.tmOut,
           hfuzz.threadsMax, hfuzz.fileExtn, hfuzz.ignoreAddr, hfuzz.asLimit, hfuzz.cmdline[0],
           hfuzz.pid);

    if (!(hfuzz.fuzzers = malloc(sizeof(hfuzz.fuzzers[0]) * hfuzz.threadsMax))) {
        LOGMSG_P(l_FATAL, "Couldn't allocate memory");
        exit(EXIT_FAILURE);
    }
    memset(hfuzz.fuzzers, '\0', sizeof(hfuzz.fuzzers[0]) * hfuzz.threadsMax);

    if (!files_init(&hfuzz)) {
        LOGMSG(l_FATAL, "Couldn't load input files");
        exit(EXIT_FAILURE);
    }

    /*
     * So far so good
     */
    fuzz_main(&hfuzz);

    abort();                    /* NOTREACHED */
    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
int main (int argc, char *argv[])
{
	struct parameters params;
	lists_t_strs *deferred_overrides;
	lists_t_strs *args;

#ifdef HAVE_UNAME_SYSCALL
	int rc;
	struct utsname uts;
#endif

#ifdef PACKAGE_REVISION
	logit ("This is Music On Console (revision %s)", PACKAGE_REVISION);
#else
	logit ("This is Music On Console (version %s)", PACKAGE_VERSION);
#endif

#ifdef CONFIGURATION
	logit ("Configured:%s", CONFIGURATION);
#endif

#ifdef HAVE_UNAME_SYSCALL
	rc = uname (&uts);
	if (rc == 0)
		logit ("Running on: %s %s %s", uts.sysname, uts.release, uts.machine);
#endif

	log_command_line (argc, argv);

	files_init ();

	if (get_home () == NULL)
		fatal ("Could not determine user's home directory!");

	memset (&params, 0, sizeof(params));
	options_init ();
	deferred_overrides = lists_strs_new (4);

	/* set locale according to the environment variables */
	if (!setlocale(LC_ALL, ""))
		logit ("Could not set locale!");

	args = process_command_line (argc, argv, &params, deferred_overrides);

	if (params.dont_run_iface && params.only_server)
		fatal ("-c, -a and -p options can't be used with --server!");

	if (!params.config_file)
		params.config_file = xstrdup (create_file_name ("config"));
	options_parse (params.config_file);
	if (params.config_file)
		free (params.config_file);
	params.config_file = NULL;

	process_deferred_overrides (deferred_overrides);
	lists_strs_free (deferred_overrides);
	deferred_overrides = NULL;

	check_moc_dir ();

	io_init ();
	rcc_init ();
	decoder_init (params.debug);
	srand (time(NULL));

	if (!params.only_server && params.dont_run_iface)
		server_command (&params, args);
	else
		start_moc (&params, args);

	lists_strs_free (args);
	options_free ();
	decoder_cleanup ();
	io_cleanup ();
	rcc_cleanup ();
	files_cleanup ();
	compat_cleanup ();

	exit (EXIT_SUCCESS);
}