aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dlfcn.c18
1 files changed, 2 insertions, 16 deletions
diff --git a/dlfcn.c b/dlfcn.c
index 01e878b..a45a619 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -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 )