示例#1
0
int FAST_FUNC bb_init_module(const char *filename, const char *options)
{
	size_t len = MAXINT(ssize_t);
	char *image;
	int rc = ENOENT;

#if ENABLE_FEATURE_2_4_MODULES
	if (get_linux_version_code() < KERNEL_VERSION(2,6,0))
		return bb_init_module_24(filename, options);
#endif

	/* Use the 2.6 way */
	image = xmalloc_open_zipped_read_close(filename, &len);
	if (image) {
		if (init_module(image, len, options) != 0)
			rc = errno;
		else
			rc = 0;
		free(image);
	}

	return rc;
}
示例#2
0
bool codegen(ast_t* program, pass_opt_t* opt)
{
  PONY_LOG(opt, VERBOSITY_MINIMAL, ("Generating\n"));

  pony_mkdir(opt->output);

  compile_t c;
  memset(&c, 0, sizeof(compile_t));

  init_module(&c, program, opt);
  init_runtime(&c);
  genprim_reachable_init(&c, program);

  bool ok;

  if(c.opt->library)
    ok = genlib(&c, program);
  else
    ok = genexe(&c, program);

  codegen_cleanup(&c);
  return ok;
}
示例#3
0
文件: scan.c 项目: bitfixer/bitfixer
void restore_scan_state(void)
{
	ScanState *save;

	init_module();

	save = (ScanState *)utarray_back(scan_state);
	sym = save->sym;
	str_set(input_buf, save->input_buf);
	at_bol = save->at_bol;
	EOL = save->EOL;
	cs = save->cs;
	act = save->act;
	p   = save->p   >= 0 ? str_data(input_buf) + save->p   : NULL;
	pe  = save->pe  >= 0 ? str_data(input_buf) + save->pe  : NULL;
	eof = save->eof >= 0 ? str_data(input_buf) + save->eof : NULL;
	ts  = save->ts  >= 0 ? str_data(input_buf) + save->ts  : NULL;
	te  = save->te  >= 0 ? str_data(input_buf) + save->te  : NULL;
//	str_set(sym_string, save->sym_string);
	expect_opcode = save->expect_opcode;

	utarray_pop_back(scan_state);
}
示例#4
0
/*-----------------------------------------------------------------------------
*   allocate a new module, setup module_start[] and reset ASMPC of all sections, 
*   return new unique ID; make it the current module
*----------------------------------------------------------------------------*/
int new_module_id( void )
{
	Section *section;
	SectionHashElem *iter;
	int module_id;

	init_module();
	module_id = get_last_module_id() + 1;

	/* expand all sections this new ID */
	for ( section = get_first_section( &iter ) ; section != NULL ; 
		  section = get_next_section( &iter ) )
	{
		section->asmpc = 0;
		section->opcode_size = 0;
		(void) section_module_start( section, module_id );
	}
	
	/* init to default section */
	set_cur_section( g_default_section );
	
	return (g_cur_module = module_id);		/* assign and return */
}
示例#5
0
/* Return:
 * 0 on success,
 * -errno on open/read error,
 * errno on init_module() error
 */
int FAST_FUNC bb_init_module(const char *filename, const char *options)
{
	size_t image_size;
	char *image;
	int rc;
	bool mmaped;

	if (!options)
		options = "";

//TODO: audit bb_init_module_24 to match error code convention
#if ENABLE_FEATURE_2_4_MODULES
	if (get_linux_version_code() < KERNEL_VERSION(2,6,0))
		return bb_init_module_24(filename, options);
#endif

	image_size = INT_MAX - 4095;
	mmaped = 0;
	image = try_to_mmap_module(filename, &image_size);
	if (image) {
		mmaped = 1;
	} else {
		errno = ENOMEM; /* may be changed by e.g. open errors below */
		image = xmalloc_open_zipped_read_close(filename, &image_size);
		if (!image)
			return -errno;
	}

	errno = 0;
	init_module(image, image_size, options);
	rc = errno;
	if (mmaped)
		munmap(image, image_size);
	else
		free(image);
	return rc;
}
示例#6
0
static int
click_modevent(module_t mod, int type, void *data)
{
	int ret;

	/* Load and unload the VFS part first */
	ret = vfs_modevent(mod, type, data);
	if (ret != 0) {
		return ret;
	}

	switch (type) {
	case MOD_LOAD:
		printf("Click module loading\n");
		if (init_module()) {
			ret = EINVAL;
			break;
		}
		ret = 0;
		break;
	case MOD_UNLOAD:
		printf("Click module unloading\n");
		cleanup_module();
		ret = 0;
		break;
	case MOD_SHUTDOWN:
		printf("Click module shutdown\n");
		ret = 0;
		break;
	default:
		printf("Click: unknown module command %d\n", type);
		ret = EOPNOTSUPP;
		break;
	}

	return ret;
}
示例#7
0
static int insmod(const char *filename, char *options)
{
    void *module;
    unsigned size;
    int ret;

    module = read_file(filename, &size);
    if (!module) {
#ifdef HAVE_AEE_FEATURE
        raise_aed_ke("W:insmod:Module \"%s\" not found.\n", filename);
#endif
        return -1;
    }

    ret = init_module(module, size, options);
#ifdef HAVE_AEE_FEATURE
    if (ret < 0) {
        const char *prop;

        prop = property_get("vold.post_fs_data_done");
        if (! prop) {
            prop = "notset";
        }       

        if (EEXIST == errno && *prop == '0') {
             printf("In encrypt phone, it will trigger_post_fs_data. Threefore skip insmod (File exists) error. \n");
        }
        else {
             raise_aed_ke("W:insmod:Failed to init module \"%s\" (%s), Check kernel log for more info.\n", filename, strerror(errno));
        }
    }
#endif

    free(module);

    return ret;
}
示例#8
0
/* append binary contents of file, whole file if num_bytes < 0 */
void patch_file_contents( FILE *file, int addr, long num_bytes )
{
	long start_ptr;
	Byte *buffer;

	init_module();

	/* get bin file size */
	if ( num_bytes < 0 )
	{
		start_ptr = ftell( file );
		
		fseek( file, 0, SEEK_END );				/* file pointer to end of file */
		num_bytes = ftell( file ) - start_ptr;
		
		fseek( file, start_ptr, SEEK_SET );		/* file pointer to original position */
	}

	if ( num_bytes > 0 )
	{
		buffer = alloc_space( addr, num_bytes );
		xfget_chars( file, (char *) buffer, num_bytes );
	}
}
示例#9
0
文件: scan.c 项目: bitfixer/bitfixer
/*-----------------------------------------------------------------------------
*   Get the next token, fill the corresponding tok* variables
*----------------------------------------------------------------------------*/
tokid_t GetSym( void )
{
	init_module();

	init_sym();

	/* keep returning TK_NEWLINE until EOL is cleared 
	*  NOTE: HACK for inconsistent parser in handling newlines, should be removed */
	if ( EOL )
	{
		at_bol = TRUE;
		sym.tstart = "\n"; sym.tlen = 1;
		return (sym.tok = TK_NEWLINE);			/* assign and return */
	}

	/* loop filling buffer when needed */
	do 
	{
		/* refill buffer if needed, check for end of file */
		if ( ! fill_buffer() )
		{
			sym.tok = TK_END;
			ts = te = p;
			break;
		}

		/* run the state machine */
		sym.tok = _scan_get();

	} while ( sym.tok == TK_END );

	sym.tstart = ts; sym.tlen = te - ts;			/* remember token position */

	at_bol = EOL = (sym.tok == TK_NEWLINE) ? TRUE : FALSE;
	return sym.tok;
}
示例#10
0
void CodeGen_GPU_Host<CodeGen_CPU>::compile(Stmt stmt, string name,
                                            const vector<Argument> &args,
                                            const vector<Buffer> &images_to_embed) {

    init_module();

    // also set up the child codegenerator - this is set up once per
    // PTX_Host::compile, and reused across multiple PTX_Dev::compile
    // invocations for different kernels.
    cgdev->init_module();

    module = get_initial_module_for_target(target, context);

    // grab runtime helper functions


    // Fix the target triple
    debug(1) << "Target triple of initial module: " << module->getTargetTriple() << "\n";

    llvm::Triple triple = CodeGen_CPU::get_target_triple();
    module->setTargetTriple(triple.str());

    debug(1) << "Target triple of initial module: " << module->getTargetTriple() << "\n";

    // Pass to the generic codegen
    CodeGen::compile(stmt, name, args, images_to_embed);

    // Unset constant flag for embedded image global variables
    for (size_t i = 0; i < images_to_embed.size(); i++) {
        string name = images_to_embed[i].name();
        GlobalVariable *global = module->getNamedGlobal(name + ".buffer");
        global->setConstant(false);
    }

    std::vector<char> kernel_src = cgdev->compile_to_src();

    Value *kernel_src_ptr = CodeGen_CPU::create_constant_binary_blob(kernel_src, "halide_kernel_src");

    // Remember the entry block so we can branch to it upon init success.
    BasicBlock *entry = &function->getEntryBlock();

    // Insert a new block to run initialization at the beginning of the function.
    BasicBlock *init_kernels_bb = BasicBlock::Create(*context, "init_kernels",
                                                     function, entry);
    builder->SetInsertPoint(init_kernels_bb);
    Value *user_context = get_user_context();
    Value *kernel_size = ConstantInt::get(i32, kernel_src.size());
    Value *init = module->getFunction("halide_init_kernels");
    internal_assert(init) << "Could not find function halide_init_kernels in initial module\n";
    Value *result = builder->CreateCall4(init, user_context,
                                         get_module_state(),
                                         kernel_src_ptr, kernel_size);
    Value *did_succeed = builder->CreateICmpEQ(result, ConstantInt::get(i32, 0));
    CodeGen_CPU::create_assertion(did_succeed, "Failure inside halide_init_kernels");

    // Upon success, jump to the original entry.
    builder->CreateBr(entry);

    // Optimize the module
    CodeGen::optimize_module();
}
示例#11
0
char *get_map_filename(char *filename)
{
	init_module();
	return path_replace_ext(filename, FILEEXT_MAP);
}
示例#12
0
char *get_lib_filename( char *filename )
{
    init_module();
	return path_replace_ext( filename, FILEEXT_LIB );
}
示例#13
0
char *get_err_filename( char *filename )
{
    init_module();
	return path_replace_ext( filename, FILEEXT_ERR );
}
示例#14
0
__declspec( dllexport ) void				LibInit()			{ init_module(); }
示例#15
0
文件: errors.c 项目: meesokim/z88dk
void set_error_file( char *filename )
{
    init_module();
    errors.filename = strpool_add( filename );	/* may be NULL */
}
示例#16
0
文件: errors.c 项目: meesokim/z88dk
void errors_init( void ) 
{
	init_module();
}
示例#17
0
文件: errors.c 项目: meesokim/z88dk
/*-----------------------------------------------------------------------------
*	define the next FILE, LINENO, MODULE to use in error messages
*	error_xxx(), fatal_xxx(), warn_xxx()
*----------------------------------------------------------------------------*/
void set_error_null( void )
{
    init_module();
    errors.filename = errors.module = NULL;
    errors.line = 0;
}
示例#18
0
/* Called once form pthread_once in timer_init. This initializes the
   module and ensures that reinit_after_fork will be executed in any
   child process.  */
void
__timer_init_once (void)
{
  init_module ();
  pthread_atfork (0, 0, reinit_after_fork);
}
示例#19
0
/* This is a handler executed in a child process after a fork()
   occurs.  It reinitializes the module, resetting all of the data
   structures to their initial state.  The mutex is initialized in
   case it was locked in the parent process.  */
static void
reinit_after_fork (void)
{
  init_module ();
  pthread_mutex_init (&__timer_mutex, 0);
}
示例#20
0
文件: errors.c 项目: meesokim/z88dk
void set_error_module( char *modulename )
{
    init_module();
    errors.module = strpool_add( modulename );	/* may be NULL */
}
示例#21
0
char *get_def_filename( char *filename )
{
    init_module();
	return path_replace_ext( filename, FILEEXT_DEF );
}
示例#22
0
文件: errors.c 项目: meesokim/z88dk
void set_error_line( int lineno )
{
    init_module();
    errors.line = lineno;
}
示例#23
0
char *get_bin_filename( char *filename )
{
    init_module();
	return path_replace_ext( filename, FILEEXT_BIN );
}
示例#24
0
文件: errors.c 项目: meesokim/z88dk
char *get_error_file(void)
{
	init_module();
	return errors.filename;
}
示例#25
0
char *get_sym_filename( char *filename )
{
    init_module();
	return path_replace_ext( filename, FILEEXT_SYM );
}
示例#26
0
文件: errors.c 项目: meesokim/z88dk
int get_error_line(void)
{
	init_module();
	return errors.line;
}
示例#27
0
char *get_reloc_filename(char *filename)
{
	init_module();
	return path_replace_ext(filename, FILEEXT_RELOC);
}
示例#28
0
文件: errors.c 项目: meesokim/z88dk
/*-----------------------------------------------------------------------------
*	reset count of errors and return current count
*----------------------------------------------------------------------------*/
void reset_error_count( void )
{
    init_module();
    errors.count = 0;
}
示例#29
0
static bool setupFilesystem(char* module) {
	if (module) {
		// unmount and rmmod if the module was specified on the commandline, i.e. ensure that the specified module is indeed running
		shutdownFilesystem();

		// if still mounted
		if (access("/dev/gator/buffer", F_OK) == 0) {
			logg->logError(__FILE__, __LINE__, "Unable to remove the running gator.ko. Manually remove the module or use the running module by not specifying one on the commandline");
			handleException();
		}
	}

	const int retval = mountGatorFS();
	if (retval == 1) {
		logg->logMessage("Driver already running at startup");
		driverRunningAtStart = true;
	} else if (retval == 0) {
		logg->logMessage("Driver already mounted at startup");
		driverRunningAtStart = driverMountedAtStart = true;
	} else {
		char command[256]; // arbitrarily large amount
		char location[256]; // arbitrarily large amount

		if (module) {
			strncpy(location, module, sizeof(location));
		} else {
			// Is the driver co-located in the same directory?
			if (util->getApplicationFullPath(location, sizeof(location)) != 0) { // allow some buffer space
				logg->logMessage("Unable to determine the full path of gatord, the cwd will be used");
			}
			strncat(location, "gator.ko", sizeof(location) - strlen(location) - 1);
		}

		if (access(location, F_OK) == -1) {
			if (module == NULL) {
				// The gator kernel is not already loaded and unable to locate gator.ko in the default location
				return false;
			} else {
				// gator location specified on the command line but it was not found
				logg->logError(__FILE__, __LINE__, "gator module not found at %s", location);
				handleException();
			}
		}

		// Load driver
		bool success = init_module(location);
		if (!success) {
			logg->logMessage("init_module failed, trying insmod");
			snprintf(command, sizeof(command), "insmod %s >/dev/null 2>&1", location);
			if (system(command) != 0) {
				logg->logMessage("Unable to load gator.ko driver with command: %s", command);
				logg->logError(__FILE__, __LINE__, "Unable to load (insmod) gator.ko driver:\n  >>> gator.ko must be built against the current kernel version & configuration\n  >>> See dmesg for more details");
				handleException();
			}
		}

		if (mountGatorFS() == -1) {
			logg->logError(__FILE__, __LINE__, "Unable to mount the gator filesystem needed for profiling.");
			handleException();
		}
	}

	return true;
}
示例#30
0
文件: errors.c 项目: meesokim/z88dk
int get_num_errors( void )
{
    init_module();
    return errors.count;
}