aboutsummaryrefslogtreecommitdiff
path: root/testdll3.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2019-04-25Test also UNICODE builds on AppVeyor CIPali Rohár1-0/+102
2019-04-25Simplify implementation of save_err_str()Pali Rohár1-26/+22
Check return value of FormatMessageA() function and remove copy_string() function as it is not needed.
2019-04-25Remove ifdef hack for snprintf()Pali Rohár1-5/+5
Old version of MSVC does not support snprintf() function and sprintf_s() is not replacement for C99 snprintf(). As the only usage of snprintf() is to format void* pointer we can use sprintf() with enough long buffer.
2019-04-25Simplify code around #ifdef UNICODEPali Rohár1-69/+10
The whole dlfcn.h API works with char* (ANSI) strings. For WINAPI UNICODE builds it is still possible to call WINAPI ANSI functions with -A suffix. E.g. LoadLibraryExA() instead of LoadLibraryEx() or FormatMessageA() instead of FormatMessage(). This simplify whole implementation when compiling with UNICODE support as there is no need to do conversion from wchar_t to char and vice-versa.
2019-02-14Implement support for dlsym() with RTLD_DEFAULT and RTLD_NEXTPali Rohár8-10/+193
dlsym() with RTLD_DEFAULT handle behaves in same way like with global handle returned by dlopen() with NULL file name. dlsym() with RTLD_NEXT handle search for next loaded module which provides specified symbol. "Next" means module which in EnumProcessModules() result after the module which called dlsym(). To get caller function of dlsym() use _ReturnAddress() intrinsic. To get module where is caller function use the fact that HMODULE is the same value as the module's base address. When compiling under gcc, defines _ReturnAddress() macro via gcc's builtin as it does not provide MSC's specific _ReturnAddress() intrinsic. Added tests demonstrate that both RTLD_DEFAULT and RTLD_NEXT are working as expected.
2019-02-14Fix resolving global symbols when LoadLibrary() is called after dlopen()Pali Rohár6-112/+144
Usage of first_automatic_object cache is wrong. This cache is filled by all loaded DLL files (either implicitly or explicitly with LoadLibrary() call) by EnumProcessModules() call at first usage of dlopen(). So dlsym() can resolve global symbols only if they were loaded prior to dlopen() call. Any future usage of LoadLibrary() does not include newly loaded DLLs into first_automatic_object cache. To fix this problem, first_automatic_object cache is fully removed and EnumProcessModules() call is issued directly in dlsym() call. As EnumProcessModules() returns all DLLs, included those which were loaded by dlopen() with RTLD_LOCAL, it may break RTLD_LOCAL support. To address this problem switch linked-list of all loaded DLLs with RTLD_GLOBAL to linked-list of all loaded DLLs with RTLD_LOCAL flag. And then skip modules from EnumProcessModules() which are in linked-list. Also in WinAPI all DLLs loaded by LoadLibrary() behaves like RTLD_GLOBAL. So above change is compatible with this behavior. There may be another problem. Before retrieving HMODULE for DLL filename (which is done by LoadLibrary()), it is not possible to detect if DLL was already loaded by RTLD_LOCAL or not. And after calling LoadLibrary() it is not possible to know if DLL was loaded either by dlsym() with RTLD_LOCAL or by LoadLibrary() (which is equivalent to RTLD_GLOBAL). To address this problem, compare number of loaded modules (counted by EnumProcessModules()) before and after LoadLibrary() called from dlsym(). If number does not change it means that DLL was already loaded. So based on this result either add or remove HMODULE from linked-list of RTLD_LOCAL modules. Added test demonstrate usage of: global = dlopen(NULL, RTLD_GLOBAL); /* global handle */ LoadLibrary("library.dll"); /* this provides function */ function = dlsym(global, "function"); /* resolve function from library.dll */
2019-02-12Add MinGW and MinGW-w64 tests to AppVeyorSilvio Traversaro1-5/+84
2018-01-17#include <stdlib.h>Jean-Damien Durand1-0/+1
2017-08-24Mention the possibility of defining CMAKE_DL_LIBSSilvio Traversaro1-0/+13
2017-08-24Document how to use the library when using CMakeSilvio Traversaro1-0/+11
2017-05-04[README] Fix AppVeyor badgeSilvio Traversaro1-1/+1
2017-05-01[appveyor] Test the library using Visual Studio 15Silvio Traversaro1-6/+16
See https://www.appveyor.com/docs/build-environment/ for the logic behind the option used.
2017-05-01Fix bug in dlerror second consecutive callSilvio2-0/+21
According to the specs, a second consecutive call to dlerror should always return NULL . This was the case in dlfcn-win32 before https://github.com/dlfcn-win32/dlfcn-win32/pull/20 introduce a regression that caused dlerror to crash on the second consecutive call. In this commit the issue is fixed as suggested in https://github.com/dlfcn-win32/dlfcn-win32/issues/34 and a regression test has been added.
2017-03-19Minor AppVeyor configuration cleanupKamekameha1-16/+16
2017-03-19[readme] Update AppVeyor badgeSilvio Traversaro1-1/+1
2017-03-05Add testing of CMake exported targetsSilvio3-1/+27
2017-03-05Add AppVeyor badgeSilvio Traversaro1-1/+1