Exemplo n.º 1
0
void
__kmp_env_set( char const * name, char const * value, int overwrite ) {

    #if KMP_OS_UNIX
        int rc = setenv( name, value, overwrite );
        if ( rc != 0 ) {
            // Dead code. I tried to put too many variables into Linux* OS
            // environment on IA-32 architecture. When application consumes
            // more than ~2.5 GB of memory, entire system feels bad. Sometimes
            // application is killed (by OS?), sometimes system stops 
            // responding... But this error message never appears. --ln
            __kmp_msg(
                kmp_ms_fatal,
                KMP_MSG( CantSetEnvVar, name ),
                KMP_HNT( NotEnoughMemory ),
                __kmp_msg_null
            );
        }; // if
    #elif KMP_OS_WINDOWS
        BOOL rc;
        if ( ! overwrite ) {
            rc = GetEnvironmentVariable( name, NULL, 0 );
            if ( rc ) {
                // Variable exists, do not overwrite.
                return;
            }; // if
            DWORD error = GetLastError();
            if ( error != ERROR_ENVVAR_NOT_FOUND ) {
                __kmp_msg(
                    kmp_ms_fatal,
                    KMP_MSG( CantGetEnvVar, name ),
                    KMP_ERR( error ),
                    __kmp_msg_null
                );
            }; // if
        }; // if
        rc = SetEnvironmentVariable( name, value );
        if ( ! rc ) {
            DWORD error = GetLastError();
            __kmp_msg(
                kmp_ms_fatal,
                KMP_MSG( CantSetEnvVar, name ),
                KMP_ERR( error ),
                __kmp_msg_null
            );
        }; // if
    #else
        #error Unknown or unsupported OS.
    #endif

} // func __kmp_env_set
Exemplo n.º 2
0
int
__kmp_debug_assert(
    char const *  msg,
    char const *  file,
    int           line
) {

    if ( file == NULL ) {
        file = KMP_I18N_STR( UnknownFile );
    } else {
        // Remove directories from path, leave only file name. File name is enough, there is no need
        // in bothering developers and customers with full paths.
        char const * slash = strrchr( file, '/' );
        if ( slash != NULL ) {
            file = slash + 1;
        }; // if
    }; // if

#ifdef KMP_DEBUG
    __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
    __kmp_debug_printf( "Assertion failure at %s(%d): %s.\n", file, line, msg );
    __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
#ifdef USE_ASSERT_BREAK
#if KMP_OS_WINDOWS
    DebugBreak();
#endif
#endif // USE_ASSERT_BREAK
#ifdef USE_ASSERT_STALL
    /*    __kmp_infinite_loop(); */
    for(;;);
#endif // USE_ASSERT_STALL
#ifdef USE_ASSERT_SEG
    {
        int volatile * ZERO = (int*) 0;
        ++ (*ZERO);
    }
#endif // USE_ASSERT_SEG
#endif

    __kmp_msg(
        kmp_ms_fatal,
        KMP_MSG( AssertionFailure, file, line ),
        KMP_HNT( SubmitBugReport ),
        __kmp_msg_null
    );

    return 0;

} // __kmp_debug_assert
Exemplo n.º 3
0
void
__kmp_i18n_do_catopen(
) {

    LCID          locale_id = GetThreadLocale();
    WORD 	  lang_id = LANGIDFROMLCID( locale_id );
    WORD          primary_lang_id = PRIMARYLANGID( lang_id );
    kmp_str_buf_t path;

    KMP_DEBUG_ASSERT( status == KMP_I18N_CLOSED );
    KMP_DEBUG_ASSERT( cat    == KMP_I18N_NULLCAT );

    __kmp_str_buf_init( & path );

    // Do not try to open English catalog because internal messages are
    // exact copy of messages in English catalog.
    if ( primary_lang_id == LANG_ENGLISH ) {
	status = KMP_I18N_ABSENT;  // mark catalog as absent so it will not be re-opened.
	goto end;
    }; // if

    // Construct resource DLL name.
    /*
        Simple
            LoadLibrary( name )
        is not suitable due to security issue (see
        http://www.microsoft.com/technet/security/advisory/2269637.mspx). We have to specify full
        path to the message catalog.
    */
    {

        // Get handle of our DLL first.
        HMODULE handle;
        BOOL brc =
            GetModuleHandleEx(
                GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                reinterpret_cast< LPCSTR >( & __kmp_i18n_do_catopen ),
                & handle
            );
        if ( ! brc ) {    // Error occurred.
            status = KMP_I18N_ABSENT;  // mark catalog as absent so it will not be re-opened.
            goto end;
            // TODO: Enable multiple messages (KMP_MSG) to be passed to __kmp_msg; and print
            // a proper warning.
        }; // if

        // Now get path to the our DLL.
        for ( ; ; ) {
            DWORD drc = GetModuleFileName( handle, path.str, path.size );
            if ( drc == 0 ) {    // Error occurred.
                status = KMP_I18N_ABSENT;
                goto end;
            }; // if
            if ( drc < path.size ) {
                path.used = drc;
                break;
            }; // if
            __kmp_str_buf_reserve( & path, path.size * 2 );
        }; // forever

        // Now construct the name of message catalog.
        kmp_str_fname fname;
        __kmp_str_fname_init( & fname, path.str );
        __kmp_str_buf_clear( & path );
        __kmp_str_buf_print( & path, "%s%lu/%s", fname.dir, (unsigned long)( locale_id ), name );
        __kmp_str_fname_free( & fname );

    }

    // For security reasons, use LoadLibraryEx() and load message catalog as a data file.
    cat = LoadLibraryEx( path.str, NULL, LOAD_LIBRARY_AS_DATAFILE );
    status = ( cat == KMP_I18N_NULLCAT ? KMP_I18N_ABSENT : KMP_I18N_OPENED );

    if ( status == KMP_I18N_ABSENT ) {
      if (__kmp_generate_warnings > kmp_warnings_low) { // AC: only issue warning in case explicitly asked to
	DWORD error = GetLastError();
	// Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so
	// __kmp_i18n_catgets() will not try to open catalog but will return default message.
        /*
         If message catalog for another architecture found (e.g. OpenMP RTL
	 for IA-32 architecture opens libompui.dll for Intel(R) 64)
	 Windows* OS returns error 193 (ERROR_BAD_EXE_FORMAT). However,
         FormatMessage fails to return a message for this error, so user
	 will see:

         OMP: Warning #2: Cannot open message catalog "1041\libompui.dll":
         OMP: System error #193: (No system error message available)
         OMP: Info #3: Default messages will be used.

         Issue a hint in this case to let cause of trouble more understandable.
        */
	__kmp_msg(
	    kmp_ms_warning,
	    KMP_MSG( CantOpenMessageCatalog, path.str ),
	    KMP_SYSERRCODE( error ),
            ( error == ERROR_BAD_EXE_FORMAT ? KMP_HNT( BadExeFormat, path.str, KMP_ARCH_STR ) : __kmp_msg_null ),
	    __kmp_msg_null
	);
	KMP_INFORM( WillUseDefaultMessages );
      }
    } else { // status == KMP_I18N_OPENED

        int section = get_section( kmp_i18n_prp_Version );
        int number  = get_number( kmp_i18n_prp_Version );
        char const * expected = __kmp_i18n_default_table.sect[ section ].str[ number ];
        kmp_str_buf_t version;   // Actual version of the catalog.
        __kmp_str_buf_init( & version );
        __kmp_str_buf_print( & version, "%s", ___catgets( kmp_i18n_prp_Version ) );
            // String returned by catgets is invalid after closing the catalog, so copy it.
        if ( strcmp( version.str, expected ) != 0 ) {
            // Close bad catalog.
            __kmp_i18n_catclose();
            status = KMP_I18N_ABSENT;  // And mark it as absent.
            if (__kmp_generate_warnings > kmp_warnings_low) {
                // And now print a warning using default messages.
                __kmp_msg(
                    kmp_ms_warning,
                    KMP_MSG( WrongMessageCatalog, path.str, version.str, expected ),
                    __kmp_msg_null
                );
                KMP_INFORM( WillUseDefaultMessages );
            } // __kmp_generate_warnings
        }; // if
        __kmp_str_buf_free( & version );

    }; // if
    code_page = get_code_page();

    end:
        __kmp_str_buf_free( & path );
        return;

} // func __kmp_i18n_do_catopen
Exemplo n.º 4
0
void
__kmp_i18n_do_catopen(
) {
    int    english = 0;
    char * lang    = __kmp_env_get( "LANG" );
    // TODO: What about LC_ALL or LC_MESSAGES?

    KMP_DEBUG_ASSERT( status == KMP_I18N_CLOSED );
    KMP_DEBUG_ASSERT( cat    == KMP_I18N_NULLCAT );

    english =
	lang == NULL                       ||  // In all these cases English language is used.
	strcmp( lang, "" )            == 0 ||
        strcmp( lang, " " )           == 0 ||
              // Workaround for Fortran RTL bug DPD200137873 "Fortran runtime resets LANG env var
              // to space if it is not set".
	strcmp( lang, "C" )           == 0 ||
	strcmp( lang, "POSIX" )       == 0;

    if ( ! english ) {  // English language is not yet detected, let us continue.
        // Format of LANG is: [language[_territory][.codeset][@modifier]]
        // Strip all parts except language.
        char * tail = NULL;
        __kmp_str_split( lang, '@', & lang, & tail );
        __kmp_str_split( lang, '.', & lang, & tail );
        __kmp_str_split( lang, '_', & lang, & tail );
        english = ( strcmp( lang, "en" ) == 0 );
    }; // if

    KMP_INTERNAL_FREE( lang );

    // Do not try to open English catalog because internal messages are
    // exact copy of messages in English catalog.
    if ( english ) {
	status = KMP_I18N_ABSENT;  // mark catalog as absent so it will not be re-opened.
	return;
    }

    cat = catopen( name, 0 );
    // TODO: Why do we pass 0 in flags?
    status = ( cat == KMP_I18N_NULLCAT ? KMP_I18N_ABSENT : KMP_I18N_OPENED );

    if ( status == KMP_I18N_ABSENT ) {
      if (__kmp_generate_warnings > kmp_warnings_low) { // AC: only issue warning in case explicitly asked to
        int    error   = errno; // Save errno immediately.
	char * nlspath = __kmp_env_get( "NLSPATH" );
        char * lang    = __kmp_env_get( "LANG" );

	// Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so
	// __kmp_i18n_catgets() will not try to open catalog, but will return default message.
	__kmp_msg(
	    kmp_ms_warning,
	    KMP_MSG( CantOpenMessageCatalog, name ),
	    KMP_ERR( error ),
	    KMP_HNT( CheckEnvVar, "NLSPATH", nlspath ),
            KMP_HNT( CheckEnvVar, "LANG", lang ),
	    __kmp_msg_null
	);
	KMP_INFORM( WillUseDefaultMessages );
        KMP_INTERNAL_FREE( nlspath );
        KMP_INTERNAL_FREE( lang );
      }
    } else { // status == KMP_I18N_OPENED

        int section = get_section( kmp_i18n_prp_Version );
        int number  = get_number( kmp_i18n_prp_Version );
        char const * expected = __kmp_i18n_default_table.sect[ section ].str[ number ];
            // Expected version of the catalog.
        kmp_str_buf_t version;   // Actual version of the catalog.
        __kmp_str_buf_init( & version );
        __kmp_str_buf_print( & version, "%s", catgets( cat, section, number, NULL ) );

            // String returned by catgets is invalid after closing the catalog, so copy it.
        if ( strcmp( version.str, expected ) != 0 ) {
            __kmp_i18n_catclose();     // Close bad catalog.
            status = KMP_I18N_ABSENT;  // And mark it as absent.
            if (__kmp_generate_warnings > kmp_warnings_low) { // AC: only issue warning in case explicitly asked to
                // And now print a warning using default messages.
                char const * name    = "NLSPATH";
                char const * nlspath = __kmp_env_get( name );
                __kmp_msg(
                    kmp_ms_warning,
                    KMP_MSG( WrongMessageCatalog, name, version.str, expected ),
                    KMP_HNT( CheckEnvVar, name, nlspath ),
                    __kmp_msg_null
                );
                KMP_INFORM( WillUseDefaultMessages );
                KMP_INTERNAL_FREE( (void *) nlspath );
            } // __kmp_generate_warnings
        }; // if
        __kmp_str_buf_free( & version );

    }; // if

} // func __kmp_i18n_do_catopen