1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/metamod/engineinfo.cpp Sat Apr 08 19:29:39 2006 +0000
1.3 @@ -0,0 +1,575 @@
1.4 +
1.5 +// vi: set ts=4 sw=4 :
1.6 +// vim: set tw=75 :
1.7 +
1.8 +// engineinfo.cpp - get info about HL engine, like file used
1.9 +// and test segment range
1.10 +//
1.11 +
1.12 +
1.13 +#ifdef _WIN32
1.14 + // Don't include winspool.h; clashes with SERVER_EXECUTE from engine
1.15 +# define _WINSPOOL_H
1.16 +# include <windows.h>
1.17 +# include <winnt.h> // Header structures
1.18 +#else
1.19 +# ifndef _GNU_SOURCE
1.20 +# define _GNU_SOURCE
1.21 +# endif
1.22 +# include <dlfcn.h> // dladdr()
1.23 +# include <link.h> // ElfW(Phdr/Ehdr) macros.
1.24 + // _DYNAMIC, r_debug, link_map, etc.
1.25 +#endif /* _WIN32 */
1.26 +
1.27 +#include <string.h> // strlen(), strrchr(), strcmp()
1.28 +#include <stdio.h> // printf()
1.29 +
1.30 +#include "engineinfo.h" // me
1.31 +
1.32 +//+TBR
1.33 +#ifdef MM_DEBUG
1.34 +#include "log_meta.h" // META_LOG()
1.35 +
1.36 +//#define FLDBG_PRINTF(s) dbg_logprintf s
1.37 +#define FLDBG_PRINTF(s) META_LOG s
1.38 +//#define FLDBG_PRINTF(s) printf s
1.39 +//#define FLDBG_PRINTF(s)
1.40 +#endif
1.41 +//-TBR
1.42 +
1.43 +// Current mask for checking engine function addresses
1.44 +// in VAC protected engine dlls on Win32. This is gonna fail
1.45 +// on Win64.
1.46 +const unsigned long c_VacDllEngineFuncsRangeMask = 0xFFF00000;
1.47 +const unsigned long c_VacDllEngineFuncsRangeMark = 0x01D00000;
1.48 +void* const c_VacDllEngineFuncsRangeStart = (void*)0x01D00000;
1.49 +void* const c_VacDllEngineFuncsRangeEnd = (void*)0x01E00000;
1.50 +
1.51 +
1.52 +bool EngineInfo::check_for_engine_module( const char* _pName )
1.53 +{
1.54 + const char* pC;
1.55 + size_t size;
1.56 +
1.57 + if ( NULL == _pName ) return false;
1.58 +
1.59 +#ifdef _WIN32
1.60 +
1.61 + // The engine module is either sw.dll or hw.dll or swds.dll
1.62 + pC = strrchr( _pName, '.' );
1.63 +
1.64 + pC -= 2;
1.65 + if ( 0 != strcmp(pC, "sw.dll") && 0 != strcmp(pC, "hw.dll") ) {
1.66 + pC -= 2;
1.67 + if ( 0 != strcmp(pC, "swds.dll") ) return false;
1.68 + }
1.69 +
1.70 +//+TBR
1.71 +#ifdef MM_DEBUG
1.72 + FLDBG_PRINTF( ("Locating module %s.", pC) );
1.73 +#endif
1.74 +//-TBR
1.75 + HMODULE hModule = GetModuleHandle( pC );
1.76 + if ( NULL == hModule ) {
1.77 +//+TBR
1.78 +#ifdef MM_DEBUG
1.79 + FLDBG_PRINTF( ("Could not get handle to module %s.", pC) );
1.80 +#endif
1.81 +//-TBR
1.82 + return false;
1.83 + }
1.84 +
1.85 + // Ok, we found the string sw(ds).dll, thus we deduct that this is the
1.86 + // name of the engine's shared object. We copy the string for future
1.87 + // reference and return successfully.
1.88 + size = 0;
1.89 + while ( *pC != '.' && size < c_EngineInfo__typeLen-1 ) {
1.90 + m_type[size++] = *pC++;
1.91 + }
1.92 + m_type[size] = '\0';
1.93 +//+TBR
1.94 +#ifdef MM_DEBUG
1.95 + FLDBG_PRINTF(( "Found engine dll name %s.", m_type ));
1.96 +#endif
1.97 +//-TBR
1.98 +
1.99 +#else /* _WIN32 */
1.100 +
1.101 + const char* pType;
1.102 +
1.103 +//+TBR
1.104 +#ifdef MM_DEBUG
1.105 + FLDBG_PRINTF(( "Checking for engine name in '%s'", _pName ));
1.106 +#endif
1.107 +//-TBR
1.108 +
1.109 + size = strlen( _pName );
1.110 + if ( size < 11 ) {
1.111 + // Forget it, this string is too short to even be 'engine_.so', so
1.112 + // it can't the name of the engine shared library.
1.113 + return false;
1.114 + }
1.115 +
1.116 + // Start parsing at the end. Since we know that the string is at least
1.117 + // 11 characters long we can safely do our parsing without being afraid
1.118 + // of leaving the string.
1.119 + pC = _pName + size -1;
1.120 +
1.121 + // First we see if the string ends in '.so'
1.122 + if ( *pC-- != 'o' || *pC-- != 's' || *pC-- != '.' ) return false;
1.123 +
1.124 + // Now find the '_' which would be the seperator between 'engine' and
1.125 + // the architecture.
1.126 + while ( *pC != '_' && pC != _pName ) --pC;
1.127 + if ( pC == _pName ) return false;
1.128 +
1.129 + // We are at the '_', thus the architecture identifier must start at
1.130 + // the next character.
1.131 + pType = pC +1;
1.132 +
1.133 + // Now we walk further back and check if we find the string 'engine'
1.134 + // backwards.
1.135 + --pC;
1.136 + if ( *pC-- != 'e' || *pC-- != 'n' || *pC-- != 'i' ||
1.137 + *pC-- != 'g' || *pC-- != 'n' || *pC != 'e' ) {
1.138 + return false;
1.139 + }
1.140 +
1.141 + // Ok, we found the string engine_*.so, thus we deduct that this is the
1.142 + // name of the engine's shared object. We copy the architecture string
1.143 + // for future reference and return successfully.
1.144 + size = 0;
1.145 + while ( *pType != '.' && size < c_EngineInfo__typeLen-1 ) {
1.146 + m_type[size++] = *pType++;
1.147 + }
1.148 + m_type[size] = '\0';
1.149 +
1.150 +//+TBR
1.151 +#ifdef MM_DEBUG
1.152 + FLDBG_PRINTF(( "Found engine dso name. Architecture is %s.", m_type ));
1.153 +#endif
1.154 +//-TBR
1.155 +
1.156 +#endif /* _WIN32 */
1.157 +
1.158 +
1.159 + return true;
1.160 +}
1.161 +
1.162 +
1.163 +#ifdef _WIN32
1.164 +
1.165 +int EngineInfo::nthdr_module_name( void )
1.166 +{
1.167 + PIMAGE_DOS_HEADER pDosHeader;
1.168 + PIMAGE_NT_HEADERS pNTHeader;
1.169 + unsigned char* pBaseAddr;
1.170 + const char* pName = "sw.dll";
1.171 +
1.172 + if ( ! check_for_engine_module(pName) ) {
1.173 + pName = "hw.dll";
1.174 + if ( ! check_for_engine_module(pName) ) {
1.175 + pName = "swds.dll";
1.176 + if ( ! check_for_engine_module(pName) ) {
1.177 + return MODULE_NAME_NOTFOUND;
1.178 + }
1.179 + }
1.180 + }
1.181 +
1.182 + // Get the module handle for the engine dll we found.
1.183 + // This is also the modules base address.
1.184 + HMODULE hModule = GetModuleHandle( pName );
1.185 +
1.186 + pBaseAddr = (unsigned char*)hModule;
1.187 +
1.188 +
1.189 + // Check if we find a DOS header
1.190 +//+TBR
1.191 +#ifdef MM_DEBUG
1.192 + FLDBG_PRINTF( ("Checking for DOS header at address %p.", hModule) );
1.193 +#endif
1.194 +//-TBR
1.195 + pDosHeader = (PIMAGE_DOS_HEADER)hModule;
1.196 + if ( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE ) {
1.197 +//+TBR
1.198 +#ifdef MM_DEBUG
1.199 + FLDBG_PRINTF( ("DOS header magic doesn't match: 0x%x.", pDosHeader->e_magic) );
1.200 +#endif
1.201 +//-TBR
1.202 + return INVALID_DOS_SIGN;
1.203 + }
1.204 +
1.205 + // Check if we find a PE header
1.206 +//+TBR
1.207 +#ifdef MM_DEBUG
1.208 + FLDBG_PRINTF( ("DOS header points to NT header at 0x%lx.", pDosHeader->e_lfanew) );
1.209 +#endif
1.210 +//-TBR
1.211 + pNTHeader = (PIMAGE_NT_HEADERS)(pBaseAddr + pDosHeader->e_lfanew);
1.212 +//+TBR
1.213 +#ifdef MM_DEBUG
1.214 + FLDBG_PRINTF( ("Checking for NT header at %p.", pNTHeader) );
1.215 +#endif
1.216 +//-TBR
1.217 + if ( pNTHeader->Signature != IMAGE_NT_SIGNATURE ) {
1.218 +//+TBR
1.219 +#ifdef MM_DEBUG
1.220 + FLDBG_PRINTF( ("NT header signature doesn't match: 0x%lx.", pNTHeader->Signature) );
1.221 +#endif
1.222 +//-TBR
1.223 + return INVALID_NT_SIGN;
1.224 + }
1.225 +
1.226 + set_code_range( pBaseAddr, pNTHeader );
1.227 + return 0;
1.228 +}
1.229 +
1.230 +
1.231 +int EngineInfo::vac_pe_approx( enginefuncs_t* _pFuncs )
1.232 +{
1.233 +//+TBR
1.234 +#ifdef MM_DEBUG
1.235 + FLDBG_PRINTF( ("==DEBUG==> Approximating engine functions address range in VAC dll from 0x%p.", _pFuncs) );
1.236 +#endif
1.237 +//-TBR
1.238 +
1.239 + if ( NULL == _pFuncs ) return INVALID_ARG;
1.240 +
1.241 + // There is really no good and easy way to do this. Right now what
1.242 + // we do is assume that Steam listenservers will normally be
1.243 + // up-to-date and hence have all function pointers set correctly.
1.244 + // So we just check for some anomality and then set some approximated
1.245 + // values.
1.246 +
1.247 + // The known addresses at the time of writing all start with 0x01D and
1.248 + // this lie in the range between 0x01D00000 and 0x01E00000. What we do
1.249 + // is check all functions pointers that are known to be good to start
1.250 + // with 0x01D. If that is the case then we know that the loading address
1.251 + // of the engine functions hasn't changed and we assume the above stated
1.252 + // range to be the range of valid engine function addresses.
1.253 + // If we find functions outside this range we can't determine a valid
1.254 + // range and have to just give up.
1.255 +
1.256 + unsigned long* pengfuncs = (unsigned long*)_pFuncs;
1.257 + unsigned int i, invals = 0;
1.258 + for ( i = 0, pengfuncs += i; i < 140; i++, pengfuncs++ ) {
1.259 + if ( *pengfuncs & c_VacDllEngineFuncsRangeMask != c_VacDllEngineFuncsRangeMark ) {
1.260 + invals++;
1.261 + break;
1.262 + }
1.263 + }
1.264 +
1.265 + if ( invals > 0 ) {
1.266 +//+TBR
1.267 +#ifdef MM_DEBUG
1.268 + FLDBG_PRINTF( ("==DEBUG==> Found %u functions out of range 0x%08lx.", invals, c_VacDllEngineFuncsRangeMark) );
1.269 + FLDBG_PRINTF( (" Unable to determine valid function address range.") );
1.270 +#endif
1.271 +//-TBR
1.272 + strncpy( m_type, "vacdll+?", c_EngineInfo__typeLen );
1.273 + m_state = STATE_INVALID;
1.274 + return STATE_INVALID;
1.275 + }
1.276 +
1.277 + m_codeStart = c_VacDllEngineFuncsRangeStart;
1.278 + m_codeEnd = c_VacDllEngineFuncsRangeEnd;
1.279 +
1.280 + strncpy( m_type, "vacdll", c_EngineInfo__typeLen );
1.281 +
1.282 + m_state = STATE_VALID;
1.283 +
1.284 + return 0;
1.285 +}
1.286 +
1.287 +
1.288 +void EngineInfo::set_code_range( unsigned char* _pBase, PIMAGE_NT_HEADERS _pNThdr )
1.289 +{
1.290 + m_codeStart = _pBase + _pNThdr->OptionalHeader.BaseOfCode;
1.291 + m_codeEnd = _pBase + _pNThdr->OptionalHeader.BaseOfCode + _pNThdr->OptionalHeader.SizeOfCode;
1.292 +
1.293 + m_state = STATE_VALID;
1.294 +
1.295 +//+TBR
1.296 +#ifdef MM_DEBUG
1.297 + FLDBG_PRINTF(( "==DEBUG==> Setting code range:" ));
1.298 + FLDBG_PRINTF(( " pNThdr at %p, BaseOfCode = 0x%lx, end = 0x%lx, SizeOfCode = %ld 0x%lx",
1.299 + _pNThdr, _pNThdr->OptionalHeader.BaseOfCode,
1.300 + _pNThdr->OptionalHeader.BaseOfCode + _pNThdr->OptionalHeader.SizeOfCode,
1.301 + _pNThdr->OptionalHeader.SizeOfCode,
1.302 + _pNThdr->OptionalHeader.SizeOfCode
1.303 + ));
1.304 + FLDBG_PRINTF(( " start address = 0x%p, end address = 0x%p",
1.305 + m_codeStart, m_codeEnd ));
1.306 +#endif
1.307 +//-TBR
1.308 +}
1.309 +
1.310 +
1.311 +#else /* _WIN32 */
1.312 +
1.313 +
1.314 +int EngineInfo::phdr_elfhdr( void* _pElfHdr )
1.315 +{
1.316 + ElfW(Ehdr)* pEhdr = (ElfW(Ehdr)*)_pElfHdr;
1.317 + ElfW(Phdr)* pPhdr;
1.318 +
1.319 + if ( NULL == _pElfHdr ) return INVALID_ARG;
1.320 +
1.321 + if ( pEhdr->e_ident[0] == 0x7f
1.322 + && pEhdr->e_ident[1] == 'E'
1.323 + && pEhdr->e_ident[2] == 'L'
1.324 + && pEhdr->e_ident[3] == 'F' ) {
1.325 +
1.326 + // Looking good, we found an ELF signature.
1.327 + // Let's see if the rest of the data at this address would fit an ELH header, too.
1.328 + if ( (pEhdr->e_ident[EI_CLASS] == ELFCLASS32 //ELFW(CLASS)
1.329 + || pEhdr->e_ident[EI_CLASS] == ELFCLASS64)
1.330 +
1.331 + && (pEhdr->e_ident[EI_DATA] == ELFDATA2LSB
1.332 + || pEhdr->e_ident[EI_DATA] == ELFDATA2MSB)
1.333 +
1.334 + && pEhdr->e_type == ET_DYN ) {
1.335 +
1.336 + // Ok, we believe that this is a shared object's ELF header.
1.337 + // Let's find the program header for the segment that includes
1.338 + // the text section and return it.
1.339 +
1.340 +//+TBR
1.341 +#ifdef MM_DEBUG
1.342 + FLDBG_PRINTF(("%d segments", pEhdr->e_phnum));
1.343 +#endif
1.344 +//-TBR
1.345 + pPhdr = (ElfW(Phdr) *) ((char *) pEhdr + pEhdr->e_phoff);
1.346 + for ( int i = 0; i < pEhdr->e_phnum; i++, pPhdr++ ) {
1.347 +
1.348 + if ( PT_LOAD == pPhdr->p_type
1.349 + && (pPhdr->p_flags & PF_R)
1.350 + && (pPhdr->p_flags & PF_X) ) {
1.351 +
1.352 + // The text section gets loaded and has read and
1.353 + // execute flags set. So this must be it.
1.354 +//+TBR
1.355 +#ifdef MM_DEBUG
1.356 +#ifdef __amd64__
1.357 + FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8ld type=%d flags=", i,
1.358 + (void *) (pEhdr + pPhdr->p_vaddr),
1.359 + pPhdr->p_memsz, (int)(pPhdr->p_type)) );
1.360 +#else
1.361 + FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8d type=%d flags=", i,
1.362 + (void *) (pEhdr + pPhdr->p_vaddr),
1.363 + pPhdr->p_memsz, (int)(pPhdr->p_type)) );
1.364 +#endif
1.365 + FLDBG_PRINTF(("%c%c%c",
1.366 + pPhdr->p_flags & PF_R ? 'R' : ' ',
1.367 + pPhdr->p_flags & PF_W ? 'W' : ' ',
1.368 + pPhdr->p_flags & PF_X ? 'X' : ' ' ));
1.369 + FLDBG_PRINTF(( "" ));
1.370 +#endif
1.371 +//-TBR
1.372 + set_code_range( pEhdr, pPhdr );
1.373 + return 0;
1.374 + }
1.375 + }
1.376 + }
1.377 + }
1.378 +
1.379 + return HEADER_NOTFOUND;
1.380 +}
1.381 +
1.382 +
1.383 +
1.384 +
1.385 +int EngineInfo::phdr_dladdr( void* _pMem )
1.386 +{
1.387 + Dl_info info;
1.388 +
1.389 +//+TBR
1.390 +#ifdef MM_DEBUG
1.391 + FLDBG_PRINTF(( "Trying to find Program Header via dladdr." ));
1.392 + FLDBG_PRINTF(( "Looking up dlinfo for %p", _pMem ));
1.393 +#endif
1.394 +//-TBR
1.395 + if ( 0 != dladdr(_pMem, &info) ) {
1.396 +//+TBR
1.397 +#ifdef MM_DEBUG
1.398 + FLDBG_PRINTF(( "Found info: " ));
1.399 + FLDBG_PRINTF(( " name: %s", info.dli_fname ));
1.400 + FLDBG_PRINTF(( " base: %p", info.dli_fbase ));
1.401 +#endif
1.402 +//-TBR
1.403 + // Check if this is the engine module
1.404 + if ( check_for_engine_module(info.dli_fname) ) {
1.405 + return phdr_elfhdr( info.dli_fbase );
1.406 + }
1.407 + }
1.408 +//+TBR
1.409 +#ifdef MM_DEBUG
1.410 + else {
1.411 + FLDBG_PRINTF(( "No info found." ));
1.412 + }
1.413 +#endif
1.414 +//-TBR
1.415 +
1.416 + return NOTFOUND;
1.417 +}
1.418 +
1.419 +
1.420 +int EngineInfo::phdr_r_debug( void )
1.421 +{
1.422 + ElfW(Dyn)* pDyn;
1.423 + struct r_debug* pr_debug;
1.424 + struct link_map* pMap;
1.425 +
1.426 +//+TBR
1.427 +#ifdef MM_DEBUG
1.428 + FLDBG_PRINTF(( "Trying to find Program Header via r_debug struct." ));
1.429 +#endif
1.430 +//-TBR
1.431 +
1.432 + // Search if we have a DT_DEBUG symbol in our DYNAMIC segment, which
1.433 + // ought to be set to the r_debug structure's address.
1.434 + for (pDyn = _DYNAMIC; pDyn->d_tag != DT_NULL; ++pDyn) {
1.435 + if (pDyn->d_tag == DT_DEBUG) {
1.436 + pr_debug = (struct r_debug *) pDyn->d_un.d_ptr;
1.437 + break;
1.438 + }
1.439 + }
1.440 +
1.441 + if ( DT_NULL == pDyn->d_tag ) {
1.442 +//+TBR
1.443 +#ifdef MM_DEBUG
1.444 + FLDBG_PRINTF(( "Unable to find my DT_DEBUG symbol." ));
1.445 +#endif
1.446 +//-TBR
1.447 + }
1.448 + else if ( NULL == pr_debug ) {
1.449 +//+TBR
1.450 +#ifdef MM_DEBUG
1.451 + FLDBG_PRINTF(( "DT_DEBUG found but is NULL." ));
1.452 +#endif
1.453 +//-TBR
1.454 + }
1.455 + else {
1.456 +//+TBR
1.457 +#ifdef MM_DEBUG
1.458 + FLDBG_PRINTF(( "Found DT_DEBUG symbol." ));
1.459 + FLDBG_PRINTF(( "r_debug is at %p", pr_debug ));
1.460 +#endif
1.461 +//-TBR
1.462 + pMap = pr_debug->r_map;
1.463 +
1.464 + // Walk to the start of the list
1.465 + while ( pMap->l_prev != NULL ) pMap = pMap->l_prev;
1.466 + do {
1.467 +//+TBR
1.468 +#ifdef MM_DEBUG
1.469 + FLDBG_PRINTF(( "link map is at %p", pMap ));
1.470 +
1.471 +#ifdef __amd64__
1.472 + FLDBG_PRINTF(( "base addr = %lx", pMap->l_addr ));
1.473 +#else
1.474 + FLDBG_PRINTF(( "base addr = %x", pMap->l_addr ));
1.475 +#endif
1.476 + FLDBG_PRINTF(( "name is %s\n", pMap->l_name ));
1.477 +#endif
1.478 +//-TBR
1.479 + if ( check_for_engine_module(pMap->l_name) ) {
1.480 + return phdr_elfhdr( (void*)pMap->l_addr );
1.481 + }
1.482 +
1.483 + pMap = pMap->l_next;
1.484 + } while ( NULL != pMap );
1.485 +
1.486 + }
1.487 +
1.488 + return NOTFOUND;
1.489 +}
1.490 +
1.491 +void EngineInfo::set_code_range( void* _pBase, ElfW(Phdr)* _pPhdr )
1.492 +{
1.493 + unsigned char* pBase = (unsigned char*)_pBase;
1.494 + m_codeStart = pBase + _pPhdr->p_vaddr;
1.495 + m_codeEnd = pBase + _pPhdr->p_vaddr + _pPhdr->p_memsz;
1.496 +
1.497 + m_state = STATE_VALID;
1.498 +
1.499 +//+TBR
1.500 +#ifdef MM_DEBUG
1.501 + FLDBG_PRINTF(( "==DEBUG==> Setting code range:" ));
1.502 +#ifdef __amd64__
1.503 + FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%lx, vend = 0x%lx, p_memsz = %ld",
1.504 + _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz ));
1.505 +#else
1.506 + FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%x, vend = 0x%x, p_memsz = %d",
1.507 + _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz ));
1.508 +#endif
1.509 + FLDBG_PRINTF(( " start address = %p, end address = %p",
1.510 + m_codeStart, m_codeEnd ));
1.511 +#endif
1.512 +//-TBR
1.513 +}
1.514 +
1.515 +
1.516 +#endif /* _WIN32 */
1.517 +
1.518 +
1.519 +int EngineInfo::initialise( enginefuncs_t* _pFuncs )
1.520 +{
1.521 + int ret = 0;
1.522 +
1.523 + // Have to do this only once.
1.524 + if ( NULL != m_codeStart ) {
1.525 +//+TBR
1.526 +#ifdef MM_DEBUG
1.527 + FLDBG_PRINTF(( "==DEBUG==> ---------- Engine info already initialised --" ));
1.528 + FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd ));
1.529 +#endif
1.530 +//-TBR
1.531 + return 0;
1.532 + }
1.533 +//+TBR
1.534 +#ifdef MM_DEBUG
1.535 + FLDBG_PRINTF(( "==DEBUG==> ---------- Initialising engine info --" ));
1.536 +#endif
1.537 +//-TBR
1.538 +
1.539 +#ifdef _WIN32
1.540 +
1.541 + ret = nthdr_module_name();
1.542 + if ( MODULE_NAME_NOTFOUND == ret && (! _pFuncs->pfnIsDedicatedServer()) ) {
1.543 + // We could not find the engine dll by name and we are running on
1.544 + // a listen server. This usually means that that we are dealing with
1.545 + // a VAC protected engine dll. No other way than approximating the
1.546 + // range of valid engine function pointers in this case.
1.547 + ret = vac_pe_approx( _pFuncs );
1.548 + }
1.549 +
1.550 +#else /* _WIN32 */
1.551 +
1.552 + // If we have no reference pointer to start from we can only try to use
1.553 + // the r_debug symbol.
1.554 + if ( NULL == _pFuncs ) {
1.555 + ret = phdr_r_debug();
1.556 + }
1.557 +
1.558 + // If we have a refererence pointer we try to use it first.
1.559 + if ( 0 != phdr_dladdr(_pFuncs) ) {
1.560 + ret = phdr_r_debug();
1.561 + }
1.562 +
1.563 +#endif /* _WIN32 */
1.564 +//+TBR
1.565 +#ifdef MM_DEBUG
1.566 + if ( 0 != ret ) {
1.567 + FLDBG_PRINTF(( "==DEBUG==> Unable to determine functions address range!" ));
1.568 + }
1.569 + else {
1.570 + FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd ));
1.571 + }
1.572 +#endif
1.573 +//-TBR
1.574 +
1.575 + return 0;
1.576 +}
1.577 +
1.578 +