示例#1
0
文件: symbol.c 项目: ohio813/tracer
bool symbol_skip_on_tracing(module *m, symbol *s)
{
    if (m->skip_all_symbols_in_module_on_trace)
        return true;

    if (s->skip_on_tracing==Fuzzy_False)
        return false;
    if (s->skip_on_tracing==Fuzzy_True)
        return true;

    // run regexp, etc
    int j;
    trace_skip_element * i;
    for (i=trace_skip_options, j=0; i; i=i->next, j++)
    {
        if (regexec (&i->re_path, m->path, 0, NULL, 0)==0)
            if (regexec (&i->re_module, get_module_name(m), 0, NULL, 0)==0)
                if (regexec (&i->re_function, s->name, 0, NULL, 0)==0)
                {
                    L ("Symbol %s!%s!%s will be skipped during tracing\n", m->path, get_module_name(m), s->name);
                    s->skip_on_tracing=Fuzzy_True;
                    return true;
                };
    };

    s->skip_on_tracing=Fuzzy_False;
    return false;
};
示例#2
0
文件: symbol.c 项目: ohio813/tracer
void add_symbol (address a, char *name, add_symbol_params *params)
{
    module *m=params->m;
    rbtree *symtbl=m->symbols;
    oassert(symtbl && "symbols=NULL in module");
    MemoryCache *mc=params->mc;

    if (one_time_int3_bp_re && params->t==SYM_TYPE_PE_EXPORT && module_adr_in_executable_section (m, a))
    {
        strbuf sb=STRBUF_INIT;
        strbuf_addstr (&sb, get_module_name(m));
        strbuf_addc (&sb, '!');
        strbuf_addstr (&sb, name);

        if (regexec (one_time_int3_bp_re, sb.buf, 0, NULL, 0)==0)
            set_onetime_INT3_BP(a, params->p, m, name, mc);

        strbuf_deinit (&sb);
    };

    if (dump_seh && string_is_ends_with (name, "security_cookie"))
    {
        m->security_cookie_adr=a;
        m->security_cookie_adr_known=true;
        if (symbol_c_debug)
            L ("%s() got address of security_cookie (0x" PRI_REG_HEX ") for %s!%s\n", __FUNCTION__, a, get_module_name(m), name);
    };

    bool dump_symbol=false;
    if (dump_all_symbols_re)
    {
        strbuf sb=STRBUF_INIT;
        strbuf_addstr (&sb, get_module_name(m));
        strbuf_addc (&sb, '!');
        strbuf_addstr (&sb, name);

        if (regexec (dump_all_symbols_re, sb.buf, 0, NULL, 0)==0)
            dump_symbol=true;

        strbuf_deinit (&sb);
    };

    if (dump_symbol || (dump_all_symbols_re==NULL && dump_all_symbols))
    {
        dump_PID_if_need(params->p);
        L("New symbol. Module=[%s], address=[0x" PRI_ADR_HEX "], name=[%s]\n", get_module_name(m), a, name);
    };

    symbol *new_sym=create_symbol(params->t, name);
    symbol *first_sym=(symbol*)rbtree_lookup(symtbl, (void*)a);

    if (first_sym)
        new_sym->next=first_sym; // insert at beginning of list

    rbtree_insert(symtbl, (void*)a, (void*)new_sym);
};
示例#3
0
s32 cellSysmoduleUnloadModule(u16 id)
{
	cellSysmodule.warning("cellSysmoduleUnloadModule(id=%s)", get_module_id(id));

	const auto name = get_module_name(id);

	if (!name)
	{
		cellSysmodule.error("cellSysmoduleUnloadModule() failed: unknown module 0x%04X", id);
		return CELL_SYSMODULE_ERROR_UNKNOWN;
	}

	//if (Module<>* m = Emu.GetModuleManager().GetModuleById(id))
	//{
	//	if (!m->IsLoaded())
	//	{
	//		cellSysmodule.error("cellSysmoduleUnloadModule() failed: module not loaded (id=0x%04x)", id);
	//		return CELL_SYSMODULE_ERROR_FATAL;
	//	}

	//	m->Unload();
	//}
	
	return CELL_OK;
}
static int insmod_modules(char * buf)
{
        char * module_name;
        char insmod_name[128];
        char ko[] = ".ko";
        memset(insmod_name,0,sizeof(insmod_name));
        
        module_name = get_module_name(buf);
#ifdef DEBUG
        ALOGD("module_name:%s\n",module_name);
#endif
        if(module_name != NULL){
                sprintf(insmod_name,"%s%s%s",INSMOD_PATH,module_name,ko);
                
#ifdef  DEBUG
                ALOGD("start to insmod %s\n",insmod_name);
#endif                
                if (insmod(insmod_name, "") < 0) {
                        ALOGD(" %s insmod failed!\n",insmod_name);
                        rmmod(module_name);//it may be load driver already,try remove it and insmod again.
                        if (insmod(insmod_name, "") < 0){
                                ALOGD("%s,Once again fail to load!",insmod_name);
                                return 0;
                        }
                } 
        }
        return 1;
}
示例#5
0
/**
 * load a lib
 */
void slib_import(const char *name, const char *fullname) {
#if defined(LNX_EXTLIB) || defined(WIN_EXTLIB)
  slib_t *lib;
  int (*minit) (void);
  const char *(*get_module_name) (void);
  int mok = 0;
  int name_index = 0;

  if (strncmp(name, "lib", 3) == 0) {
    // libmysql -> store mysql
    name_index = 3;
  }

  lib = &slib_table[slib_count];
  memset(lib, 0, sizeof(slib_t));
  strncpy(lib->name, name + name_index, 255);
  strncpy(lib->fullname, fullname, 1023);
  lib->id = slib_count;

  if (!opt_quiet) {
    log_printf("lib: importing %s", fullname);
  }
  if (slib_llopen(lib)) {
    mok = 1;

    // init
    minit = slib_getoptptr(lib, "sblib_init");
    if (minit) {
      if (!minit()) {
        mok = 0;
        log_printf("lib: %s->sblib_init(), failed", lib->name);
      }
    }

    // override default name
    get_module_name = slib_getoptptr(lib, "sblib_get_module_name");
    if (get_module_name) {
      strncpy(lib->name, get_module_name(), 255);
    }

    slib_import_routines(lib);
    mok = 1;
  }
  else {
    log_printf("lib: can't open %s", fullname);
  }
  if (mok) {
    slib_count++;
    if (!opt_quiet) {
      log_printf("... done\n");
    }
  }
  else {
    if (!opt_quiet) {
      log_printf("... error\n");
    }
  }
#endif
}
示例#6
0
void Pass::execute() {
  FileSetBlock *fsb = _suif_env->get_file_set_block();
  if (fsb == NULL)
    suif_warning("%s: Pass execution attempted without a file set block\n",
		 get_module_name().c_str());
  else
    do_file_set_block( fsb );
}
示例#7
0
void SimpleModule::check_arg_count(suif_vector<LString>* args,
				   unsigned cnt)
{
  if (args->size() != cnt) {
    SUIF_THROW(SuifException(get_module_name() + " expects exactly " +
			     String((long)cnt) + " arguments"));
  }
}
示例#8
0
文件: native.c 项目: Cobinja/cjs
static GjsNativeModule *
lookup_native_module(JSContext  *context,
                     JSObject   *parent,
                     const char *name,
                     gboolean    is_definition)
{
    GjsNativeModule *native_module;
    GString *module_id;

    module_id = g_string_new(name);
    while (parent != NULL) {
        char *name;
        jsval tmp;

        name = get_module_name(context, parent, &tmp);
        if (name != NULL) {
            g_string_prepend_c(module_id, '.');
            g_string_prepend(module_id, name);
            g_free(name);
        }

        /* Move up to parent */
        parent = module_get_parent(context, parent);
    }

    if (is_definition)
        gjs_debug(GJS_DEBUG_NATIVE,
                  "Defining native module '%s'",
                  module_id->str);

    if (modules != NULL)
        native_module = g_hash_table_lookup(modules, module_id->str);
    else
        native_module = NULL;

    if (native_module == NULL) {
        if (is_definition) {
            gjs_throw(context,
                      "No native module '%s' has registered itself",
                      module_id->str);
        }
        g_string_free(module_id, TRUE);
        return NULL;
    }

    g_string_free(module_id, TRUE);

    return native_module;
}
示例#9
0
void create_snapshot ( char *file_to_dump , void *module_base , char *snapshot )
{
  SNAPSHOT_HEADER header;
  unsigned int sections;
  unsigned int filelen;
  char module_name [ 256 ];
  FILE *f;

/* Creo el OUTPUT FILE */
  f = fopen ( snapshot , "wb" );

/* Si el file NO pudo ser creado */
  if ( f == NULL )
  {
    printf ( "Error: Invalid output_file\n" );
    exit ( 0 );
  }

/* Obtengo el SIZE del MODULO en MEMORIA */
  filelen = get_module_size ( ( void * ) module_base );
//  printf ( "filelen = %x\n" , filelen );

/* Obtengo el numero de secciones del file */
  sections = get_sections_number ( ( unsigned int ) module_base , ( unsigned int ) module_base + filelen );
  printf ( "sections_number = %i\n" , sections );

/* Seteo el header del file */
  header.sig = 0x70616E73;
  header.version = 2;
  header.flags = 0x00000000;
  header.blockcount = sections;
  fwrite ( &header , sizeof ( header ) , 1 , f ); 

/* Obtengo el nombre LIMPIO del modulo */
  get_module_name ( file_to_dump , module_name );
//  printf ( "name: %s con size = %i\n" , module_name , strlen ( module_name ) );

/* Dumpeo TODAS las secciones en el file */
  dump_sections ( f , module_name , ( unsigned int ) module_base , ( unsigned int ) module_base + filelen );

/* Mensaje al usuario */
  printf ( "[x] Setting image base at: %.8x\n" , module_base );

/* Cierro el file */
  fclose ( f );
}
示例#10
0
static
jint get_all_modules(JNIEnv *env) {
    jvmtiError err;
    jint cnt = -1;
    jint idx = 0;
    jobject* modules;

    printf(">>> Inspecting modules with GetAllModules\n");
    err = (*jvmti)->GetAllModules(jvmti, &cnt, &modules);
    if (err != JVMTI_ERROR_NONE) {
        printf("Error in GetAllModules: %d\n", err);
        return -1;
    }
    for (idx = 0; idx < cnt; ++idx) {
        get_module_name(env, modules[idx]);
    }
    return cnt;
}
示例#11
0
void handleMidiSend(void)
{
  static uint8_t readBlock[MODULE_NAME_BYTES];
  static size_t idx = 0;

  if (idx == 0) {
    /* Read block into buffer. */
    get_module_name(readBlock, MODULE_NAME_BYTES);
  }

  if (idx >= MODULE_NAME_BYTES) {
    /* Reset SysEx sending. */
    idx = 0;
    isSendingSysExMsg = false;
  } else {
    sendSysExByte(readBlock[idx]);
    idx++;
  }
}
示例#12
0
s32 cellSysmoduleLoadModule(u16 id)
{
	cellSysmodule.warning("cellSysmoduleLoadModule(id=%s)", get_module_id(id));

	const auto name = get_module_name(id);

	if (!name)
	{
		cellSysmodule.error("cellSysmoduleLoadModule() failed: unknown module 0x%04X", id);
		return CELL_SYSMODULE_ERROR_UNKNOWN;
	}

	//if (Module<>* m = Emu.GetModuleManager().GetModuleById(id))
	//{
	//	// CELL_SYSMODULE_ERROR_DUPLICATED shouldn't be returned
	//	m->Load();
	//}

	return CELL_OK;
}
示例#13
0
int obs_open_module(obs_module_t **module, const char *path,
		const char *data_path)
{
	struct obs_module mod = {0};
	int errorcode;

	if (!module || !path || !obs)
		return MODULE_ERROR;

	blog(LOG_INFO, "---------------------------------");

	mod.module = os_dlopen(path);
	if (!mod.module) {
		blog(LOG_WARNING, "Module '%s' not found", path);
		return MODULE_FILE_NOT_FOUND;
	}

	errorcode = load_module_exports(&mod, path);
	if (errorcode != MODULE_SUCCESS)
		return errorcode;

	mod.bin_path  = bstrdup(path);
	mod.file      = strrchr(mod.bin_path, '/');
	mod.file      = (!mod.file) ? mod.bin_path : (mod.file + 1);
	mod.mod_name  = get_module_name(mod.file);
	mod.data_path = bstrdup(data_path);
	mod.next      = obs->first_module;

	if (mod.file) {
		blog(LOG_INFO, "Loading module: %s", mod.file);
	}

	*module = bmemdup(&mod, sizeof(mod));
	obs->first_module = (*module);
	mod.set_pointer(*module);

	if (mod.set_locale)
		mod.set_locale(obs->locale);

	return MODULE_SUCCESS;
}
示例#14
0
/**
 * Prints LIBCx version and memory usage statistics to stdout.
 */
void print_stats()
{
  int rc;
  _HEAPSTATS hst;

  printf("LIBCx version: " VERSION_MAJ_MIN_BLD LIBCX_DEBUG_SUFFIX LIBCX_DEV_SUFFIX "\n");

  {
    char name[CCHMAXPATH] = {0};
    get_module_name(name, sizeof(name));
    printf("LIBCx module:  %s\n", name);
  }

  global_lock();

  char buf[StatsBufSize];
  format_stats(buf, sizeof(buf));
  fputs(buf, stdout);

  global_unlock();
}
示例#15
0
文件: suifprinter.cpp 项目: jrk/suif2
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void
SuifPrinterModule::init()
{
  _pr = _suif_env->get_print_subsystem();
  if (!_pr) {
     cerr << "SuifPrinterModule: There is no PrintSubSystem!!!\n";
     exit(1);
  }
  _string_table = _pr->retrieve_string_repository(get_module_name());

  /*
  // Now read in from a standard set of print_strings pre-defined for
  // suifnodes and basicnodes.
  int size = sizeof(defaultPrintStrings)/sizeof(PrnStrClass);

  {
    for (int i = 0; i < size; ++i) {
      _string_table->set_print_string(defaultPrintStrings[i].class_name,
				      defaultPrintStrings[i].prn_str);
    }
  }
  size = sizeof(defaultPrintRefStrings)/sizeof(PrnStrClass);
  for (int i = 0; i < size; ++i) {
     _string_table->set_print_ref_string(defaultPrintRefStrings[i].class_name,
					 defaultPrintRefStrings[i].prn_str);
  }
  */
  /*
 // Now do the deferred initialization
  for (list<print_init_fn>::iterator iter = _print_inits->begin();
       iter != _print_inits->end();
       iter++) {
    print_init_fn fn = (*iter);
    (*fn)(_suif_env);
  }
  */
  _initialized = true;

}
示例#16
0
int
main(int argc, char **argv)
{
	struct gengetopt_args_info cmdline;

	if (cmdline_parser(argc, argv, &cmdline) != 0)
		return 1;

	const char *module_path = cmdline.module_arg;
	if (!cmdline.module_given)
		module_path = default_pkcs11_provider;
#ifdef _WIN32
	DWORD expanded_len;
	char module_path_expanded[PATH_MAX], default_expanded[PATH_MAX], onepin_expanded[PATH_MAX];
	expand(module_path, module_path_expanded, expanded_len);
	expand(default_pkcs11_provider, default_expanded, expanded_len);
	expand(default_onepin_pkcs11_provider, onepin_expanded, expanded_len);
#endif

	const char *module_name = get_module_name(module_path);
	if (!module_name) {
		fprintf(stderr, "Could not load initialize %s\n", module_path);
		return 1;
	}

	if (!cmdline.skip_chrome_flag)
		add_module_chrome(module_path, module_name);
	if (!cmdline.skip_firefox_flag)
		add_module_firefox(module_path, module_name);
	if (!cmdline.skip_thunderbird_flag)
		add_module_thunderbird(module_path, module_name);
	if (!cmdline.skip_seamonkey_flag)
		add_module_seamonkey(module_path, module_name);

	cmdline_parser_free (&cmdline);

	return 0;
}
示例#17
0
static
jvmtiError get_module(JNIEnv *env,
                      jobject loader,
                      const char* pkg_name,
                      jobject* module_ptr,
                      const char** mod_name_ptr) {
    jvmtiError err = JVMTI_ERROR_NONE;
    const char* name = (pkg_name == NULL) ? "<NULL>" : pkg_name;

    printf(">>> getting module by loader %p and package \"%s\"\n", loader, name);
    *mod_name_ptr = NULL;
    err = (*jvmti)->GetNamedModule(jvmti, loader, pkg_name, module_ptr);
    if (err != JVMTI_ERROR_NONE) {
        printf("    Error in GetNamedModule for package \"%s\": %s (%d)\n",
               pkg_name, TranslateError(err), err);
        return err;
    }
    printf("    returned module: %p\n", *module_ptr);
    if (*module_ptr == NULL) { // named module was not found
        return err;
    }
    *mod_name_ptr = get_module_name(env, *module_ptr);
    return err;
}
static inline bool walk_stack(struct exception_handler_data *data,
		HANDLE thread, struct stack_trace *trace)
{
	struct module_info module_info = {0};
	DWORD64 func_offset;
	char sym_name[256];
	char *p;

	bool success = data->stack_walk64(trace->image_type,
			data->process, thread, &trace->frame, &trace->context,
			NULL, data->sym_function_table_access64,
			data->sym_get_module_base64, NULL);
	if (!success)
		return false;

	module_info.addr = trace->frame.AddrPC.Offset;
	get_module_name(data, &module_info);

	if (!!module_info.name_utf8[0]) {
		p = strrchr(module_info.name_utf8, '\\');
		p = p ? (p + 1) : module_info.name_utf8;
	} else {
		strcpy(module_info.name_utf8, "<unknown>");
		p = module_info.name_utf8;
	}

	success = !!data->sym_from_addr(data->process,
			trace->frame.AddrPC.Offset, &func_offset,
			data->sym_info);

	if (success)
		os_wcs_to_utf8(data->sym_info->Name, 0, sym_name, 256);

#ifdef _WIN64
#define SUCCESS_FORMAT \
	"%016I64X %016I64X %016I64X %016I64X " \
	"%016I64X %016I64X %s!%s+0x%I64x\r\n"
#define FAIL_FORMAT \
	"%016I64X %016I64X %016I64X %016I64X " \
	"%016I64X %016I64X %s!0x%I64x\r\n"
#else
#define SUCCESS_FORMAT \
	"%08.8I64X %08.8I64X %08.8I64X %08.8I64X " \
	"%08.8I64X %08.8I64X %s!%s+0x%I64x\r\n"
#define FAIL_FORMAT \
	"%08.8I64X %08.8I64X %08.8I64X %08.8I64X " \
	"%08.8I64X %08.8I64X %s!0x%I64x\r\n"

	trace->frame.AddrStack.Offset &= 0xFFFFFFFFF;
	trace->frame.AddrPC.Offset &= 0xFFFFFFFFF;
	trace->frame.Params[0] &= 0xFFFFFFFF;
	trace->frame.Params[1] &= 0xFFFFFFFF;
	trace->frame.Params[2] &= 0xFFFFFFFF;
	trace->frame.Params[3] &= 0xFFFFFFFF;
#endif

	if (success && (data->sym_info->Flags & SYMFLAG_EXPORT) == 0) {
		dstr_catf(&data->str, SUCCESS_FORMAT,
				trace->frame.AddrStack.Offset,
				trace->frame.AddrPC.Offset,
				trace->frame.Params[0],
				trace->frame.Params[1],
				trace->frame.Params[2],
				trace->frame.Params[3],
				p, sym_name, func_offset);
	} else {
		dstr_catf(&data->str, FAIL_FORMAT,
				trace->frame.AddrStack.Offset,
				trace->frame.AddrPC.Offset,
				trace->frame.Params[0],
				trace->frame.Params[1],
				trace->frame.Params[2],
				trace->frame.Params[3],
				p, trace->frame.AddrPC.Offset);
	}

	return true;
}
示例#19
0
void DEFAULT_CC
scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
	int display = 0;
	tbus data;
	struct session_item* s_item;

	tc_mutex_lock(session_creation_lock);
	data = auth_userpass(NULL, s->username, s->password);

	#ifdef CHECK_PREMIUM_EDITION
	bool valid = true;
	if (get_module_version(get_module_name()) & PREMIUM_EDITION) {
	  printf("%s %i %i  %i \n", __FUNCTION__, g_time3(), last_time_premium_edition_check, CHECK_INTERVAL);
	  if (((g_time3() - last_time_premium_edition_check) > CHECK_INTERVAL) ||  last_time_premium_edition_check == 0) {
	    printf("%s FOFOFOOF\n", __FUNCTION__);
	    valid = check_premium_edition();
	  }
	}
	if (!valid) {
	  data = 0;
	  scp_v0s_deny_connection(c, "Unable to launch the session\nInvalid License\nPlease contact your administrator\n");
	  tc_mutex_unlock(session_creation_lock);
	  return;
	}
#endif

	if (data == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s failed to authenticate", s->username);
		scp_v0s_deny_connection(c, "Your username or \nyour password is invalid");
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	lock_chain_acquire();
	s_item = session_get_bydata(s->username);
	lock_chain_release();

	if (s_item != 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "A session for User %s already exist", s->username);
		display = s_item->display;
		if (s_item->status == SESMAN_SESSION_STATUS_TO_DESTROY)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "Session for user %s is in destroy, unable to initialize a new session", s->username);
			scp_v0s_deny_connection(c, "Your last session is currently \nended, retry later");
		}
		else
		{
			session_update_status_by_user(s_item->name, SESMAN_SESSION_STATUS_ACTIVE);
			log_message(&(g_cfg->log), LOG_LEVEL_INFO, "switch from status DISCONNECTED to ACTIVE");
			session_switch_resolution(s->width, s->height, display);
			session_add_client_pid(s_item->name, s->client_pid);

			scp_v0s_allow_connection(c, display);
		}

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "No session already started for the user %s", s->username);
	if (access_login_allowed(s->username) == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s is not allow to start session", s->username);
		display = 0;
		scp_v0s_deny_connection(c, "You are not allowed\nto start a session\n");

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}

	log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
	if (SCP_SESSION_TYPE_XVNC == s->type)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XVNC,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XRDP,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}

	auth_end(data);
	if (display == 0)
	{
		data = 0;
		scp_v0s_deny_connection(c, "Unable to launch the session\nPlease contact\nyour administrator\n");
	}
	else
	{
		scp_v0s_allow_connection(c, display);
	}

	tc_mutex_unlock(session_creation_lock);
}
示例#20
0
void SimpleModule::check_file_set_block(void)
{
  if (get_file_set_block() == NULL) {
    SUIF_THROW(SuifException(get_module_name() + " expects a file set block."));
  }
}
示例#21
0
/**
 * Initializes the shared structures.
 */
static void shared_init()
{
  APIRET arc;
  int rc;

  arc = DosExitList(EXLST_ADD, ProcessExit);
  ASSERT_MSG(arc == NO_ERROR, "%ld", arc);

#if defined(TRACE_ENABLED) && !defined(TRACE_USE_LIBC_LOG)
  /*
   * Allocate a larger buffer to fit lengthy TRACE messages and disable
   * auto-flush on EOL (to avoid breaking lines by stdout operations
   * from other threads/processes).
   */
  setvbuf(stdout, NULL, _IOFBF, 0x10000);
#endif

  while (1)
  {
    /* First, try to open the mutex */
    arc = DosOpenMutexSem(MUTEX_LIBCX, &gMutex);
    TRACE("DosOpenMutexSem = %lu\n", arc);

    if (arc == NO_ERROR)
    {
      /*
       * Init is (being) done by another process, request the mutex to
       * guarantee shared memory is already alloated, then get access to
       * it and open shared heap located in that memory.
       */
      arc = DosRequestMutexSem(gMutex, SEM_INDEFINITE_WAIT);
      ASSERT_MSG(arc == NO_ERROR, "%ld", arc);

      if (arc == NO_ERROR)
      {
        arc = DosGetNamedSharedMem((PPVOID)&gpData, SHAREDMEM_LIBCX, PAG_READ | PAG_WRITE);
        TRACE("DosGetNamedSharedMem = %lu\n", arc);
        if (arc)
        {
          /*
           * This failure means that another process was too fast to do what
           * it wanted and initiated global uninitialization before we got the
           * mutex so shared memory was already freed by this time. Retry.
           */
          DosReleaseMutexSem(gMutex);
          DosCloseMutexSem(gMutex);
          continue;
        }

        /*
         * It's an ordinary LIBCx process. Increase coutners.
         */

        TRACE("gpData->heap = %p\n", gpData->heap);
        ASSERT(gpData->heap);

        rc = _uopen(gpData->heap);
        ASSERT_MSG(rc == 0, "%d (%d)", rc, errno);

        ASSERT(gpData->refcnt);
        gpData->refcnt++;
        TRACE("gpData->refcnt = %d\n", gpData->refcnt);
      }

      break;
    }

    if (arc == ERROR_SEM_NOT_FOUND)
    {
      /* We are the first process, create the mutex */
      arc = DosCreateMutexSem(MUTEX_LIBCX, &gMutex, 0, TRUE);
      TRACE("DosCreateMutexSem = %ld\n", arc);

      if (arc == ERROR_DUPLICATE_NAME)
      {
        /* Another process is faster, attempt to open the mutex again */
        continue;
      }
    }

    ASSERT_MSG(arc == NO_ERROR, "%ld", arc);

    /*
     * It's a process that successfully created the main mutex, i.e. the first
     * LIBCx process. Proceed with the initial setup by allocating shared
     * memory and heap.
     */

    /* Allocate shared memory */
    arc = DosAllocSharedMem((PPVOID)&gpData, SHAREDMEM_LIBCX, HEAP_SIZE,
                            PAG_READ | PAG_WRITE | OBJ_ANY);
    TRACE("DosAllocSharedMem(OBJ_ANY) = %ld\n", arc);

    if (arc && arc != ERROR_ALREADY_EXISTS)
    {
      /* High memory may be unavailable, try w/o OBJ_ANY */
      arc = DosAllocSharedMem((PPVOID)&gpData, SHAREDMEM_LIBCX, HEAP_SIZE,
                              PAG_READ | PAG_WRITE);
      TRACE("DosAllocSharedMem = %ld\n", arc);
    }

    ASSERT_MSG(arc == NO_ERROR, "%ld", arc);

    TRACE("gpData %p\n", gpData);

    /* Commit the initial block */
    arc = DosSetMem(gpData, HEAP_INIT_SIZE, PAG_DEFAULT | PAG_COMMIT);
    ASSERT_MSG(arc == NO_ERROR, "%ld", arc);

    gpData->size = HEAP_INIT_SIZE;

    /* Create shared heap */
    gpData->heap = _ucreate(gpData + 1, HEAP_INIT_SIZE - sizeof(*gpData),
                            _BLOCK_CLEAN, _HEAP_REGULAR | _HEAP_SHARED,
                            mem_alloc, NULL);
    TRACE("gpData->heap = %p\n", gpData->heap);
    ASSERT(gpData->heap);

    rc = _uopen(gpData->heap);
    ASSERT_MSG(rc == 0, "%d (%d)", rc, errno);

    gpData->refcnt = 1;

    /* Initialize common structures */
    GLOBAL_NEW_ARRAY(gpData->procs, PROC_DESC_HASH_SIZE);
    TRACE("gpData->procs = %p\n", gpData->procs);
    ASSERT(gpData->procs);

    GLOBAL_NEW_ARRAY(gpData->files, FILE_DESC_HASH_SIZE);
    TRACE("gpData->files = %p\n", gpData->files);
    ASSERT(gpData->files);

    break;
  }

  /*
   * Perform common initialization (both for the first and ordinary processes).
   */

  /* Make sure a process description for this process is created */
  ProcDesc *proc = get_proc_desc(getpid());
  ASSERT(proc);

  /* Initialize individual components */
  mmap_init(proc);
  fcntl_locking_init(proc);

  /* Check if it's a spawn2 wrapper (e.g. spawn2-wrapper.c) */
  {
    char dll[CCHMAXPATH + sizeof(SPAWN2_WRAPPERNAME) + 1];
    if (get_module_name(dll, sizeof(dll)))
    {
      strcpy(_getname(dll), SPAWN2_WRAPPERNAME);

      char exe[CCHMAXPATH + 1];
      if (_execname(exe, sizeof(exe)) == 0 && stricmp(dll, exe) == 0)
      {
        proc->flags |= Proc_Spawn2Wrapper;
        TRACE("spawn2 wrapper\n");

        /* Make sure the semaphore is available (needed for spawn2-wrapper.c) */
        ASSERT(gpData->spawn2_sem);
        global_spawn2_sem(proc);
      }
    }
  }

  DosReleaseMutexSem(gMutex);

  TRACE("done\n");
}
示例#22
0
文件: native.c 项目: Cobinja/cjs
/**
 * gjs_import_native_module:
 * @context:
 * @module_obj:
 * @filename: filename or %NULL
 * @flags_p:
 *
 * Imports a native module by g_module_open a shared library.
 * If @filename is %NULL, do not dlopen, assume the library
 * is already loaded in the modules hash table
 */
JSBool
gjs_import_native_module(JSContext        *context,
                         JSObject         *module_obj,
                         const char       *filename,
                         GjsNativeFlags *flags_p)
{
    GModule *gmodule = NULL;
    GjsNativeModule *native_module;
    JSObject *parent;
    jsval tmp;

    if (flags_p)
        *flags_p = 0;

    if (filename != NULL) {
        /* Vital to load in global scope so any dependent libs
         * are loaded into the main app. We don't want a second
         * private copy of GTK or something.
         */
        gmodule = g_module_open(filename, 0);
        if (gmodule == NULL) {
            gjs_throw(context,
                      "Failed to load '%s': %s",
                      filename, g_module_error());
            return JS_FALSE;
        }
    }

    /* dlopen() as a side effect should have registered us as
     * a native module. We just have to reverse-engineer
     * the module id from module_obj.
     */
    {
        char *module_name = get_module_name(context, module_obj, &tmp);
        native_module = lookup_native_module (context,
                                              module_get_parent(context, module_obj),
                                              module_name,
                                              TRUE);
        g_free(module_name);
    }

    if (!native_module) {
        if (gmodule)
            g_module_close(gmodule);
        return JS_FALSE;
    }

    if (flags_p)
        *flags_p = native_module->flags;

    if (gmodule) {
        /* make the module resident, which makes the close() a no-op
         * (basically we leak the module permanently)
         */
        g_module_make_resident(gmodule);
        g_module_close(gmodule);
    }

    if (native_module->flags & GJS_NATIVE_SUPPLIES_MODULE_OBJ) {

        /* In this case we just throw away "module_obj" eventually,
         * since the native module defines itself in the parent of
         * module_obj directly.
         */
        parent = module_get_parent(context, module_obj);
        return (* native_module->func) (context, parent);
    } else {
        return (* native_module->func) (context, module_obj);
    }
}
示例#23
0
 virtual Module *clone() const { 
   return(new S2CPass(get_suif_env(), get_module_name()));
 }
示例#24
0
文件: tree.c 项目: Pidbip/egtkwave
void build_tree_from_name(const char *s, int which)
{
struct tree *t, *nt;
struct tree *tchain = NULL, *tchain_iter;
struct tree *prevt;
#ifdef _WAVE_HAVE_JUDY
PPvoid_t PPValue = NULL;
char str[2048];
#endif

if(s==NULL || !s[0]) return;

t = GLOBALS->treeroot;

if(t)
	{
	prevt = NULL;
	while(s)
		{
rs:		s=get_module_name(s);

		if(t && !strcmp(t->name, GLOBALS->module_tree_c_1))
			{
			prevt = t;
			t = t->child;
			continue;
			}

#ifdef _WAVE_HAVE_JUDY
rescan:
		if(prevt && prevt->children_in_gui)
			{
			/* find with judy */
			int len = gen_hier_string(str, prevt);
			strcpy(str+len, GLOBALS->module_tree_c_1);
			PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0);
			if(*PPValue)
				{
				t = *PPValue;
				prevt = t;
				t = t->child;
				continue;
				}

			goto construct;
			}
#endif

		tchain = tchain_iter = t;
		if(s && t)
			{
#ifdef _WAVE_HAVE_JUDY
			int dep = 0;
#endif
		      	nt = t->next;
		      	while(nt)
				{
				if(nt && !strcmp(nt->name, GLOBALS->module_tree_c_1))
					{
					/* move to front to speed up next compare if in same hier during build */
					if(prevt)
						{
						tchain_iter->next = nt->next;
						nt->next = tchain;
						prevt->child = nt;
						}

					prevt = nt;
					t = nt->child;
					goto rs;
					}

				tchain_iter = nt;
				nt = nt->next;
#ifdef _WAVE_HAVE_JUDY
				dep++;
#endif
				}

#ifdef _WAVE_HAVE_JUDY
			if(prevt && (dep >= FST_TREE_SEARCH_NEXT_LIMIT))
				{
				int len = gen_hier_string(str, prevt);
				prevt->children_in_gui = 1; /* "borrowed" for tree build */
				t = prevt->child;

				Judy1Set ((Pvoid_t)&GLOBALS->sym_tree_addresses, (Word_t)prevt, PJE0);
				/* assemble judy based on scopename + prevt pnt */
				while(t)
					{
					strcpy(str+len, t->name);
					PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0);
					*PPValue = t;

					t = t->next;
					}

				goto rescan; /* this level of hier is built, now do insert */
				}
#endif
			}

#ifdef _WAVE_HAVE_JUDY
construct:
#endif
		nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1);
		memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1);

		if(s)
			{
			nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME;

#ifdef _WAVE_HAVE_JUDY
			if(prevt && prevt->children_in_gui)
				{
				*PPValue = nt;
				}
#endif

			if(prevt)				/* make first in chain */
				{
				nt->next = prevt->child;
				prevt->child = nt;
				}
				else				/* make second in chain as it's toplevel */
				{
				nt->next = tchain->next;	
				tchain->next = nt;
				}
			}
			else
			{
			nt->child = prevt;			/* parent */
			nt->t_which = which;
			nt->next = GLOBALS->terminals_tchain_tree_c_1;
			GLOBALS->terminals_tchain_tree_c_1 = nt;
			return;
			}
	
		/* blindly clone fac from next part of hier on down */
		t = nt;
		while(s)
			{
			s=get_module_name(s);
		
			nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1);
			memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1);

			if(s)
				{
				nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME;
				t->child = nt;
				t = nt;
				}
				else
				{
				nt->child = t;			/* parent */
				nt->t_which = which;
				nt->next = GLOBALS->terminals_tchain_tree_c_1;
				GLOBALS->terminals_tchain_tree_c_1 = nt;
				}
			}
		}
	}
else	
	{
	/* blindly create first fac in the tree (only ever called once) */
	while(s)
		{
		s=get_module_name(s);

		nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1);
		memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1);

		if(!s) nt->t_which=which; else nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME;

		if((GLOBALS->treeroot)&&(t)) /* scan-build : && t should be unnecessary to avoid null pointer deref, but add defensively */
			{
			t->child = nt;
			t = nt;
			}
			else
			{
			GLOBALS->treeroot = t = nt;
			}
		}
	}
}
示例#25
0
文件: SEH.c 项目: dennis714/tracer
// returns address of next SEH frame
address dump_SEH_frame (fds* s, struct process* p, struct thread* t, struct MemoryCache *mc, address a)
{
	struct my_EXCEPTION_REGISTRATION current_SEH_frame;
	bool b;

	b=MC_ReadBuffer (mc, a, 
			sizeof(struct my_EXCEPTION_REGISTRATION), (BYTE*)&current_SEH_frame);
	if (b==false)
	{
		L ("%s() cannot read current SEH frame\n", __FUNCTION__);
		return REG_MAX;
	};

	strbuf sb=STRBUF_INIT;
	process_get_sym (p, current_SEH_frame.handler, true /* add_module_name */, true /* add_offset */, &sb);

	L ("* SEH frame at 0x" PRI_ADR_HEX " prev=0x" PRI_ADR_HEX " handler=0x" PRI_ADR_HEX " (%s)\n", 
			a, current_SEH_frame.prev, current_SEH_frame.handler, sb.buf);

	bool SEH3=false, SEH4=false;

	if (string_is_ends_with (sb.buf, "except_handler3"))
		SEH3=true;

	REG security_cookie;
	bool security_cookie_known=false;
	if (string_is_ends_with (sb.buf, "except_handler4"))
	{
		SEH4=true;
		struct module *m=find_module_for_address(p, current_SEH_frame.handler);
		if (m->security_cookie_adr_known)
		{
			b=MC_ReadREG (mc, m->security_cookie_adr, &security_cookie);
			if (b==false)
				L ("%s() can't read security_cookie at 0x" PRI_ADR_HEX " for %s\n", 
						__FUNCTION__, m->security_cookie_adr, get_module_name (m));
			else
				security_cookie_known=true;
		}
		else
		{
			L ("SEH4 frame is here, but address of security_cookie is not known\n");
			L ("Try to place .PDB or .MAP file here with this symbol in it\n");
		};
	};

	if (SEH3==false && SEH4==false)
		goto exit;

	struct my_VC_EXCEPTION_REGISTRATION_RECORD current_SEH3_frame;
	b=MC_ReadBuffer (mc, a,
			sizeof(struct my_VC_EXCEPTION_REGISTRATION_RECORD), (BYTE*)&current_SEH3_frame);
	if (b==false)
	{
		L ("%s() cannot read current SEH3/4 frame\n", __FUNCTION__);
		return REG_MAX;
	};

	int previous_trylevel=current_SEH3_frame.previous_trylevel;
	L ("SEH%d frame. previous trylevel=%d\n", SEH3 ? 3 : 4, previous_trylevel);
	address scopetable_address=current_SEH3_frame.scopetable;
	if (SEH4 && security_cookie_known)
	{
		scopetable_address^=security_cookie;
		struct my_EH4_SCOPETABLE_HEADER EH4_header;
		b=MC_ReadBuffer (mc, scopetable_address,
				sizeof(struct my_EH4_SCOPETABLE_HEADER), (BYTE*)&EH4_header);
		if (b==false)
		{
			L ("%s() cannot read current SEH4 frame header. scopetable_address=0x" PRI_ADR_HEX "\n", 
					__FUNCTION__, scopetable_address);
			return REG_MAX;
		};
		L ("SEH4 header:\tGSCookieOffset=0x%x GSCookieXOROffset=0x%x\n", EH4_header.GSCookieOffset, EH4_header.GSCookieXOROffset);
		L ("\t\tEHCookieOffset=0x%x EHCookieXOROffset=0x%x\n", EH4_header.EHCookieOffset, EH4_header.EHCookieXOROffset);

		unsigned adr_of_EBP=a + ((byte*)&current_SEH3_frame.EBP - (byte*)&current_SEH3_frame.prev);

		if (EH4_header.EHCookieOffset!=-2)
			check_SEH4_cookie (mc, adr_of_EBP, EH4_header.EHCookieOffset, EH4_header.EHCookieXOROffset, security_cookie, "EH");
		if (EH4_header.GSCookieOffset!=-2)
			check_SEH4_cookie (mc, adr_of_EBP, EH4_header.GSCookieOffset, EH4_header.GSCookieXOROffset, security_cookie, "GS");

		scopetable_address+=sizeof(struct my_EH4_SCOPETABLE_HEADER);
	};
	if (previous_trylevel>=0 && (SEH3 || (SEH4 && security_cookie_known)))
		dump_scopetable(mc, p, scopetable_address, previous_trylevel+1);

exit:
	strbuf_deinit (&sb);
	return current_SEH_frame.prev;
};