test.c


Log

Author Commit Date CI Message
Pali Rohár ff302674 2019-07-26T18:21:30 Fix more gcc warnings ISO C90 forbids mixed declarations and code ISO C++ forbids converting a string constant to 'char*'
Pali Rohár 2bb5f487 2019-07-25T20:34:46 Fix gcc warning: ISO C forbids return between function pointer and void * Instead of using compiler specific pragma to disable particular warning, rewrite code which cast from function pointer to data pointer according to POSIX dlopen() documentation. This also fix compile warning under MSVC. According to the ISO C standard, casting between function pointers and 'void *', as done above, produces undefined results. POSIX.1-2003 and POSIX.1-2008 accepted this state of affairs and proposed the following workaround: *(void **) (&cosine) = dlsym(handle, "cos"); This (clumsy) cast conforms with the ISO C standard and will avoid any compiler warnings.
Pali Rohár 403b240f 2019-07-25T20:34:28 Fix gcc warning: comparison between signed and unsigned integer expressions GetTempPathA() returns DWORD (32/64bit unsigned integer) and not int (32 signed integer).
Pali Rohár 5c2ec8f9 2019-06-11T00:54:38 Turn off GUI error messages around LoadLibraryA also in test Otherwise running test show GUI error messages which needs to be closed.
Pali Rohár e646c9ab 2019-05-23T20:24:17 Add test for non-library file
Pali Rohár 27319bfc 2019-05-23T20:24:12 Add tests for non-existent file and file with too long name
Pali Rohár f6f6dd2d 2019-05-23T20:24:05 Test that dlerror() returns non-NULL error for failed calls
Pali Rohár 63d7bda4 2019-01-29T22:57:04 Implement support for dlsym() with RTLD_DEFAULT and RTLD_NEXT 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.
Pali Rohár 29c46a54 2019-01-29T22:38:42 Fix resolving global symbols when LoadLibrary() is called after dlopen() 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 */
Silvio 5bcd8c53 2017-05-01T11:03:01 Fix bug in dlerror second consecutive call 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.
Silvio d22f7719 2017-03-05T16:48:00 Add testing of CMake exported targets
Silvio 540fa7a4 2017-03-05T16:16:16 Fix tests in Visual Studio 2015 For checking the loading of symbols from the global handle, the printf symbol was loaded, but since Visual Studio 2015 printf is defined as a inline function. To fix this, the test has been modified to load the symbol of the fwrite function.
Timothy Gu dd4254a3 2014-10-08T15:50:21 Add linked modules to a separate global list Fixes #2.
Timothy Gu c421b701 2015-03-15T16:09:44 Check for memory leak when _DEBUG is defined
Timothy Gu e16a6e8e 2014-02-10T03:46:33 test: add trying to load nonexistent symbols test
Timothy Gu 043b3358 2014-02-10T03:35:19 test: add forgotten test "Open library again (without closing it first) with RTLD_GLOBAL"
Timothy Gu f1642131 2014-02-10T03:30:50 test: more updates and fixes
Timothy Gu 507ae09f 2014-02-10T03:08:12 test.c: make errors stand out
Timothy Gu 346543d6 2014-02-10T03:05:45 License stuff
Timothy Gu f92c7718 2014-01-22T04:26:18 Fix local symbol in global handle test
Timothy Gu cd276891 2014-01-22T04:24:38 test.c: return 1 if error
Ramiro Polla 85d184f7 2007-06-29T20:36:07 Cosmetics: white space
Ramiro Polla 4c4b268c 2007-06-28T05:50:08 Initial Revision