diff options
| author | Silvio Traversaro <silvio@traversaro.it> | 2020-07-15 08:07:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-15 08:07:53 +0200 |
| commit | 0a494c01b0586faa5f89465c0728f0fb209c08df (patch) | |
| tree | 7462316b9e8a743d034bd8ee482a3f55a22d03bd | |
| parent | 61ad60f591700cc083b8a310c020554a59374a0a (diff) | |
| parent | 8ec5ffef2ecabd2474706b11e0238e8fca40b800 (diff) | |
| download | dlfcn-win32-0a494c01b0586faa5f89465c0728f0fb209c08df.tar.gz dlfcn-win32-0a494c01b0586faa5f89465c0728f0fb209c08df.tar.bz2 dlfcn-win32-0a494c01b0586faa5f89465c0728f0fb209c08df.zip | |
Merge pull request #74 from pali/master
Replace VirtualQueryEx() call by GetModuleHandleExA() call
| -rw-r--r-- | dlfcn.c | 18 |
1 files changed, 2 insertions, 16 deletions
| @@ -369,24 +369,10 @@ void *dlsym( void *handle, const char *name ) | |||
| 369 | * The next object is the one found upon the application of a load | 369 | * The next object is the one found upon the application of a load |
| 370 | * order symbol resolution algorithm. To get caller function of dlsym() | 370 | * order symbol resolution algorithm. To get caller function of dlsym() |
| 371 | * use _ReturnAddress() intrinsic. To get HMODULE of caller function | 371 | * use _ReturnAddress() intrinsic. To get HMODULE of caller function |
| 372 | * use undocumented hack from https://stackoverflow.com/a/2396380 | 372 | * use standard GetModuleHandleExA() function. |
| 373 | * The HMODULE of a DLL is the same value as the module's base address. | ||
| 374 | */ | 373 | */ |
| 375 | MEMORY_BASIC_INFORMATION info; | 374 | if( !GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) _ReturnAddress( ), &hCaller ) ) |
| 376 | size_t sLen; | ||
| 377 | sLen = VirtualQueryEx( hCurrentProc, _ReturnAddress(), &info, sizeof( info ) ); | ||
| 378 | if( sLen != sizeof( info ) ) | ||
| 379 | { | ||
| 380 | if( sLen != 0 ) | ||
| 381 | SetLastError( ERROR_INVALID_PARAMETER ); | ||
| 382 | goto end; | 375 | goto end; |
| 383 | } | ||
| 384 | hCaller = (HMODULE) info.AllocationBase; | ||
| 385 | if( !hCaller ) | ||
| 386 | { | ||
| 387 | SetLastError( ERROR_INVALID_PARAMETER ); | ||
| 388 | goto end; | ||
| 389 | } | ||
| 390 | } | 376 | } |
| 391 | 377 | ||
| 392 | if( handle != RTLD_NEXT ) | 378 | if( handle != RTLD_NEXT ) |
