示例#1
0
/*++
Function :

    FMTMSG_LoadLibrary
    
    Loads the dynamic library
--*/
static LPVOID FMTMSG_LoadLibrary( )
{
    CHAR PathAndFileName[ MAX_PATH ];
    LPVOID lpLibRotorPalRt;
    
    if ( !PAL_GetPALDirectoryA( PathAndFileName, MAX_PATH ) )
    {
        ERROR( "Unable to retrieve the path.\n" );
        goto error;
    }

#define ROTOR_PALRT PAL_SHLIB_PREFIX "rotor_palrt" PAL_SHLIB_SUFFIX

    if (strncat_s( PathAndFileName, sizeof(PathAndFileName), ROTOR_PALRT, MAX_PATH ) != SAFECRT_SUCCESS)
    {
        ERROR( "strncat_s failed!\n" );
        goto error;
    }

    TRACE( "%s'\n",PathAndFileName ); 

    /* the refcounting in dlopen / dlclose calls does not tend to be threadsafe - take 
       the modulelist lock to avoid a potential race condition from the PAL side */
    LockModuleList();
    lpLibRotorPalRt = dlopen( PathAndFileName, RTLD_LAZY );
    if ( lpLibRotorPalRt )
    {
        if ( InterlockedCompareExchangePointer(&s_lpLibRotorPalRt, lpLibRotorPalRt, NULL) != NULL )
        {
            /* somebody beat us to it */
            dlclose( lpLibRotorPalRt );
        }
    }
    else
    {
        ERROR( "%s\n", strerror( errno ) );
    }
    UnlockModuleList();

error:
    return s_lpLibRotorPalRt;
}
示例#2
0
PALIMPORT
BOOL
PALAPI
PAL_GetPALDirectoryA(
             OUT LPSTR lpDirectoryName,
             IN UINT*  cchDirectoryName)
{
    BOOL bRet;
    PathCharString directory;

    PERF_ENTRY(PAL_GetPALDirectoryA);
    ENTRY( "PAL_GetPALDirectoryA( %p, %d )\n", lpDirectoryName, *cchDirectoryName );

    bRet = PAL_GetPALDirectoryA(directory);

    if (bRet) 
    {
        if (directory.GetCount() > *cchDirectoryName)
        {
            SetLastError( ERROR_INSUFFICIENT_BUFFER );
            bRet = FALSE;
            *cchDirectoryName = directory.GetCount();
        }
        else if (strcpy_s(lpDirectoryName, directory.GetCount(), directory.GetString()) == SAFECRT_SUCCESS) 
        {
        }
        else 
        {
            bRet = FALSE;
        }
    }

    LOGEXIT( "PAL_GetPALDirectoryA returns BOOL %d.\n", bRet);
    PERF_EXIT(PAL_GetPALDirectoryA);
    return bRet;
}