コード例 #1
0
ファイル: dlfcn.c プロジェクト: BenjaminLefoul/ring-daemon
void *dlopen( const char *file, int mode )
{
	HMODULE hModule;
	UINT uMode;
	current_error = NULL;
/* Do not let Windows display the critical-error-handler message box */
	uMode = SetErrorMode( SEM_FAILCRITICALERRORS );
	if( file == 0 )
	{
/* POSIX says that if the value of file is 0, a handle on a global
* symbol object must be provided. That object must be able to access
* all symbols from the original program file, and any objects loaded
* with the RTLD_GLOBAL flag.
* The return value from GetModuleHandle( ) allows us to retrieve
* symbols only from the original program file. For objects loaded with
* the RTLD_GLOBAL flag, we create our own list later on.
*/
hModule = GetModuleHandle( NULL );
if( !hModule )
	save_err_ptr_str( file );
}
else
{
	char lpFileName[MAX_PATH];
	int i;
/* MSDN says backslashes *must* be used instead of forward slashes. */
	for( i = 0 ; i < sizeof(lpFileName)-1 ; i++ )
	{
		if( !file[i] )
			break;
		else if( file[i] == '/' )
			lpFileName[i] = '\\';
		else
			lpFileName[i] = file[i];
	}
	lpFileName[i] = '\0';
/* POSIX says the search path is implementation-defined.
* LOAD_WITH_ALTERED_SEARCH_PATH is used to make it behave more closely
* to UNIX's search paths (start with system folders instead of current
* folder).
*/
hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL,
	LOAD_WITH_ALTERED_SEARCH_PATH );
/* If the object was loaded with RTLD_GLOBAL, add it to list of global
* objects, so that its symbols may be retrieved even if the handle for
* the original program file is passed. POSIX says that if the same
* file is specified in multiple invocations, and any of them are
* RTLD_GLOBAL, even if any further invocations use RTLD_LOCAL, the
* symbols will remain global.
*/
if( !hModule )
	save_err_str( lpFileName );
else if( (mode & RTLD_GLOBAL) )
	global_add( hModule );
}
/* Return to previous state of the error-mode bit flags. */
SetErrorMode( uMode );
return (void *) hModule;
}
コード例 #2
0
ファイル: dlfcn.c プロジェクト: n13l/openaaa
void
*dlopen(const char *file, int mode)
{
    HMODULE hModule;
    UINT uMode;

    current_error = NULL;

    /* Do not let Windows display the critical-error-handler message box */
    uMode = SetErrorMode(SEM_FAILCRITICALERRORS);

    if( file == 0 )
    {
        /* POSIX says that if the value of file is 0, a handle on a global
         * symbol object must be provided. That object must be able to access
         * all symbols from the original program file, and any objects loaded
         * with the RTLD_GLOBAL flag.
         * The return value from GetModuleHandle( ) allows us to retrieve
         * symbols only from the original program file. For objects loaded with
         * the RTLD_GLOBAL flag, we create our own list later on.
         */
        hModule = GetModuleHandle( NULL );

        if( !hModule )
            save_err_ptr_str( file );
    }
    else
    {
        char lpFileName[MAX_PATH];
        int i;

        /* MSDN says backslashes *must* be used instead of forward slashes. */
        for( i = 0 ; i < sizeof(lpFileName)-1 ; i++ )
        {
            if( !file[i] )
                break;
            else if( file[i] == '/' )
                lpFileName[i] = '\\';
            else
                lpFileName[i] = file[i];
        }
        lpFileName[i] = '\0';

        hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL, 
                                 LOAD_WITH_ALTERED_SEARCH_PATH );

        if( !hModule )
            save_err_str( lpFileName );
        else if( (mode & RTLD_GLOBAL) )
            global_add(hModule);
    }

    /* Return to previous state of the error-mode bit flags. */
    SetErrorMode( uMode );

    return (void *) hModule;
}
コード例 #3
0
ファイル: global.c プロジェクト: x3ro/tinyos-legacy
u16 global_lookup(struct global_state *gstate, const char *name)
/* Returns: the index for global variable name in environment.
     If name doesn't exist yet, it is created with a variable
     whose value is NULL.
*/
{
  struct symbol *pos;
  struct string *tname;

  if (table_lookup(gstate->global, name, &pos))
    return (u16)intval(pos->data);

  GCPRO1(gstate);
  tname = alloc_string(name);
  GCPOP(1);

  return global_add(gstate, tname, NULL);
}
コード例 #4
0
ファイル: global.c プロジェクト: x3ro/tinyos-legacy
u16 mglobal_lookup(struct global_state *gstate, struct string *name)
/* Returns: the index for global variable name in environment.
     If name doesn't exist yet, it is created with a variable
     whose value is NULL.
*/
{
  struct symbol *pos;
  struct string *tname;

  if (table_lookup(gstate->global, name->str, &pos))
    return (u16)intval(pos->data);

  GCPRO2(gstate, name);
  tname = alloc_string_n(string_len(name));
  strcpy(tname->str, name->str);
  GCPOP(2);

  return global_add(gstate, tname, NULL);
}
コード例 #5
0
ファイル: dlfcn.c プロジェクト: fmutant/scriptorium
void *dlopen( const char *file, int mode )
{
    HMODULE hModule;
    UINT uMode;

    current_error = NULL;

    /* Do not let Windows display the critical-error-handler message box */
    uMode = SetErrorMode( SEM_FAILCRITICALERRORS );

    if( file == 0 )
    {
        HMODULE hAddtnlMods[1024]; // Already loaded modules
        HANDLE hCurrentProc = GetCurrentProcess( );
        DWORD cbNeeded;

        /* POSIX says that if the value of file is 0, a handle on a global
         * symbol object must be provided. That object must be able to access
         * all symbols from the original program file, and any objects loaded
         * with the RTLD_GLOBAL flag.
         * The return value from GetModuleHandle( ) allows us to retrieve
         * symbols only from the original program file. For objects loaded with
         * the RTLD_GLOBAL flag, we create our own list later on. For objects
         * outside of the program file but already loaded (e.g. linked DLLs)
         * they are added below.
         */
        hModule = GetModuleHandle( NULL );

        if( !hModule )
            save_err_ptr_str( file );


        /* GetModuleHandle( NULL ) only returns the current program file. So
	 * if we want to get ALL loaded module including those in linked DLLs,
	 * we have to use EnumProcessModules( ).
         */
        if( EnumProcessModules( hCurrentProc, hAddtnlMods,
                                sizeof( hAddtnlMods ), &cbNeeded ) != 0 )
        {
            DWORD i;
            for( i = 0; i < cbNeeded / sizeof( HMODULE ); i++ )
            {
                global_add( &first_automatic_object, hAddtnlMods[i] );
            }
        }
        auto_ref_count++;
    }
    else
    {
        char lpFileName[MAX_PATH];
        int i;

        /* MSDN says backslashes *must* be used instead of forward slashes. */
        for( i = 0 ; i < sizeof(lpFileName)-1 ; i++ )
        {
            if( !file[i] )
                break;
            else if( file[i] == '/' )
                lpFileName[i] = '\\';
            else
                lpFileName[i] = file[i];
        }
        lpFileName[i] = '\0';

        /* POSIX says the search path is implementation-defined.
         * LOAD_WITH_ALTERED_SEARCH_PATH is used to make it behave more closely
         * to UNIX's search paths (start with system folders instead of current
         * folder).
         */
        hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL, 
                                 LOAD_WITH_ALTERED_SEARCH_PATH );

        /* If the object was loaded with RTLD_GLOBAL, add it to list of global
         * objects, so that its symbols may be retrieved even if the handle for
         * the original program file is passed. POSIX says that if the same
         * file is specified in multiple invocations, and any of them are
         * RTLD_GLOBAL, even if any further invocations use RTLD_LOCAL, the
         * symbols will remain global.
         */
        if( !hModule )
            save_err_str( lpFileName );
        else if( (mode & RTLD_GLOBAL) )
            global_add( &first_object, hModule );
    }

    /* Return to previous state of the error-mode bit flags. */
    SetErrorMode( uMode );

    return (void *) hModule;
}