third_party/virtualbox/src/VBox/HostDrivers/Support/posix/SUPR3HardenedMain-posix.cpp
/**
 * Returns the start address of the given symbol if found or NULL otherwise.
 *
 * @returns Start address of the symbol or NULL if not found.
 * @param   pszSymbol           The symbol name.
 * @param   pfnResolve          The resolver to call before trying to query the start address.
 */
Returns the start address of the given symbol if found or NULL otherwise.
@returns Start address of the symbol or NULL if not found.
@param   pszSymbol           The symbol name.
@param   pfnResolve          The resolver to call before trying to query the start address.
Returns the start address of the given symbol if found or NULL otherwise . @returns Start address of the symbol or NULL if not found . @param pszSymbol The symbol name . @param pfnResolve The resolver to call before trying to query the start address .
static void *supR3HardenedMainPosixGetStartBySymbol(const char *pszSymbol, PFNSUPHARDENEDSYMRESOLVE pfnResolve)
{
#ifndef RT_OS_SOLARIS
    return dlsym(RTLD_DEFAULT, pszSymbol);
    RT_NOREF(pfnResolve);
#else  
    pfnResolve();
    uint8_t *pbSym = (uint8_t *)dlsym(RTLD_DEFAULT, pszSymbol);
# ifdef RT_ARCH_AMD64
    DISSTATE Dis;
    uint32_t cbInstr = 1;
    int rc = DISInstr(pbSym, DISCPUMODE_64BIT, &Dis, &cbInstr);
    if (   RT_FAILURE(rc)
        || Dis.pCurInstr->uOpcode != OP_JMP
        || !(Dis.ModRM.Bits.Mod == 0 && Dis.ModRM.Bits.Rm == 5 ))
        return NULL;
    pbSym = (pbSym + cbInstr + Dis.Param1.uDisp.i32);
    pbSym = (uint8_t *)*((uintptr_t *)pbSym);
# else
#  error "Unsupported architecture"
# endif
    return pbSym;
#endif 
}
static void * supR3HardenedMainPosixGetStartBySymbol ( const char * pszSymbol , PFNSUPHARDENEDSYMRESOLVE pfnResolve ) { #ifndef RT_OS_SOLARIS return dlsym ( RTLD_DEFAULT , pszSymbol ) ; RT_NOREF ( pfnResolve ) ; #else pfnResolve ( ) ; uint8_t * pbSym = ( uint8_t * ) dlsym ( RTLD_DEFAULT , pszSymbol ) ; # ifdef RT_ARCH_AMD64 DISSTATE Dis ; uint32_t cbInstr = 1 ; int rc = DISInstr ( pbSym , DISCPUMODE_64BIT , & Dis , & cbInstr ) ; if ( RT_FAILURE ( rc ) || Dis . pCurInstr -> uOpcode != OP_JMP || ! ( Dis . ModRM . Bits . Mod == 0 && Dis . ModRM . Bits . Rm == 5 ) ) return NULL ; pbSym = ( pbSym + cbInstr + Dis . Param1 . uDisp . i32 ) ; pbSym = ( uint8_t * ) * ( ( uintptr_t * ) pbSym ) ; # else #  error  "Unsupported architecture" # endif return pbSym ; #endif }
Returns the start address of the given symbol if found or NULL otherwise.
Returns the start address of the given symbol if found or NULL otherwise .
/* RT_OS_SOLARIS */ /*
     * Solaris is tricky as dlsym doesn't return the actual start address of
     * the symbol but the start of the trampoline in the PLT of the caller.
     *
     * Disassemble the first jmp instruction to get at the entry in the global
     * offset table where the actual address is stored.
     *
     * To counter lazy symbol resolving, we first have to call the API before
     * trying to resolve and disassemble it.
     */ /* wrt RIP */ /* Extract start address. */ /* RT_OS_SOLARIS */