Log

Author Commit Date CI Message
Pali Rohár d1a0d28f 2021-02-03T21:00:28 Fix MSVC 14.00 compile warning: warning C4244: '=' : conversion from 'ULONG_PTR' to 'char', possible loss of data
Pali Rohár 06fea3fe 2021-02-03T20:59:58 Add helper function MyGetModuleHandleFromAddress() This function implements calling GetModuleHandleExA() with correct flags to retrieve hModule from passed address. To allow compilation also with older compilers and environments (like WDK) with any _WIN32_WINNT value, retrieve pointer to this function via GetProcAddress(). And as a fallback implementation use old code via VirtualQuery() which was there prior commit 8ec5ffef2eca.
Pali Rohár 0e9d85a9 2021-02-03T20:59:18 Fix helper function MyEnumProcessModules() Call SetErrorMode(SEM_FAILCRITICALERRORS) prior opening Psapi.dll library to avoid GUI error messages. Close Psapi.dll library via FreeLibrary() if symbol was not retrieved to prevent possible memory leaks. Try to get K32EnumProcessModules symbol from Kernel32.dll library as it is preferred way how to call EnumProcessModules() on Windows 7 and newer versions. If retrieving EnumProcessModules symbol failed with both methods then do not try it again on next MyEnumProcessModules() function call.
Pali Rohár c172ee21 2021-02-03T20:58:39 Avoid calling SetLastError() and GetLastError() internally There is no need for propagating internal errors via SetLastError() and GetLastError() calls. Just use additional argument for save_err_str() function. Also dlfcn API is POSIX and does not use GetLastError().
Pali Rohár b89f8932 2021-02-03T20:58:15 Move hCurrentProc variable to scope where is used
Pali Rohár f7e7a5d7 2021-02-03T20:57:40 Fix some style issues
Silvio Traversaro 3ec513f9 2021-02-03T18:33:32 Merge pull request #94 from pali/dladdr dladdr() - Retrieve symbol name and address from export table
Pali Rohár b46da884 2021-01-29T14:00:30 Remove duplicate checks for NULL pointers is_valid_address() already rejects NULL addresses, so there is no need to check address for NULL.
Pali Rohár e53ecd53 2021-01-29T13:59:41 Remove code for finding symbol name in import table It is not required as import table can use only symbols which are exported and therefore are in export table. So if symbol is not found in export table it cannot be in import table.
Pali Rohár 86a41b92 2021-01-25T23:27:22 Function dladdr() now retrieve symbol name and symbol address from both export and import tables dladdr tests for Windows now should always pass like on other systems.
Silvio Traversaro a5af061c 2021-01-25T21:44:50 Merge pull request #72 from rhabacker/master Add function dladdr()
Ralf Habacker 3a016513 2020-12-28T12:29:13 CI: Add static building for cmake
Ralf Habacker ebd7badd 2021-01-17T12:51:08 cmake: add support to build test-dladdr on unix like os This is used to obtain test result references.
Ralf Habacker 0ea2334d 2020-12-11T14:32:52 Add function dladdr() and associated test application test-dladdr
Silvio Traversaro 06ffb62a 2020-12-22T17:31:32 Merge pull request #93 from rhabacker/travis-cmake-support Add cmake build support to travis CI
Ralf Habacker 38ea653d 2020-12-22T10:57:10 Add cmake build support to travis CI
Silvio Traversaro 1f0a9b1b 2020-12-13T19:02:34 Merge pull request #90 from pali/master Rewrite function save_err_ptr_str() to not use sprintf()
Pali Rohár d230e1ca 2020-12-13T14:48:44 Rewrite function save_err_ptr_str() to not use sprintf() sprintf() is marked by MSVC as unsafe and suppressing compile warning does not work. It is still generated on AppVeyor. So rewrite code for converting pointer number to string via open coded for-loop and do not use unsafe sprintf() function anymore. New code correctly handles both 32bit and 64bit variants and does not use any #ifdef _MSC_VER anymore.
Silvio Traversaro b1b55b2a 2020-12-13T12:10:41 Merge pull request #89 from pali/master Add _CRT_SECURE_NO_WARNINGS for test.c to disable MSVC deprecation warnings
Pali Rohár e042c1de 2020-12-13T02:22:06 Add _CRT_SECURE_NO_WARNINGS for test.c to disable MSVC deprecation warnings
Silvio Traversaro 5f1c9149 2020-12-13T01:29:18 Merge pull request #88 from pali/master Run Travis tests also under i586-mingw32msvc-gcc compiler
Pali Rohár 22020637 2020-12-12T02:47:24 ci-build.sh: Move install_prefix to cmake place where it is used
Pali Rohár 3cddb7b9 2020-12-12T01:02:47 Run Travis tests also under i586-mingw32msvc-gcc compiler Beware that i586-mingw32msvc-gcc is sometimes just a symlink to i686-w64-mingw32-gcc. Real i586-mingw32msvc-gcc compiler is available in mingw32 package only in dist trusty.
Silvio Traversaro 008df693 2020-11-26T11:16:05 Merge pull request #85 from rhabacker/cmake-wine-support Add support to use wine to run cross compiled tests for cmake
Ralf Habacker 49c3a337 2020-11-03T14:43:41 cmake: Keep warning in sync with Makefile based build system
Ralf Habacker 90302fc5 2020-11-03T10:05:33 Add cmake building support to Travis CI To make it easier to extend the CI support and to be able to execute the contained tests locally, a dedicated shell script tools/ci_build.sh was added to execute the tests.
Ralf Habacker 2821345e 2020-11-02T13:06:55 cmake: add option ENABLE_WINE to enable support for running cross compiled tests with wine For details about the ENABLE_WINE option, which support three modes AUTO|ON|OFF see the documentation of cmake macro check_auto_option(). A custom path for the wine executable can be specified by adding -DWINE_EXECUTABLE=<path> to the cmake command line. The cmake related macros were copied from https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/cmake/modules/Macros.cmake
Ralf Habacker 53b1d71a 2020-11-03T10:45:36 cmake: separate targets in tests subdir for reasier reading
Ralf Habacker 3292a137 2020-11-02T12:50:41 cmake: Let make target 'test' be accessable from topmost build directory The cmake command enable_testing() must be placed in the topmost CMakeLists.txt so that the make target 'test' is available in the topmost build directory.
Silvio Traversaro 0b899996 2020-11-08T11:48:21 Merge pull request #86 from pali/master Change order of variables in appveyor build matrix
Pali Rohár 214d5668 2020-11-04T18:12:50 Change order of variables in appveyor build matrix This change no function effect as it changes only order of defined variables. The only visible change is on appveyor web where variables are printed in other as they are defined. If list of variables is too long, variables defined later are hidden on the web interface. Variable APPVEYOR_BUILD_WORKER_IMAGE was moved to the end of list as it is less important to know as variable GENERATOR (defines which compiler is used).
Ralf Habacker 11c80b8e 2020-11-02T12:37:36 cmake: place all generated binaries into one place This is required for running test applications, because by default cmake places binaries into the associated subdir.
Silvio Traversaro d640d80f 2020-09-21T22:31:41 Merge pull request #79 from rhabacker/cmake-refactoring CMake build system fixes
Silvio Traversaro 33e2fdc2 2020-09-21T22:29:54 Merge pull request #82 from rhabacker/drop-obsolete-vcproj-files Drop obsolete visual studio related files
Ralf Habacker ff6060ba 2020-09-06T23:13:47 Drop obsolete visual studio related files These files can be easily recreated with cmake on the fly, which is already used by CI-system.
Ralf Habacker faa2ff80 2020-09-14T12:21:55 Makefile: Adjust paths of source files, which are now located in subdirectories
Ralf Habacker 218e7785 2020-08-25T23:24:25 Fix cmake warning 'No project() command is present'
Ralf Habacker f0ac8495 2020-08-25T23:34:19 Move cmake targets into sub directories
Ralf Habacker 5ead6f2d 2020-08-25T23:31:13 Update minimum required cmake version to 2.8.11 to simplify code According to https://cmake.org/pipermail/cmake/2013-May/054792.html cmake 2.8.11 was released in 2013, so we can assume that no older version will be used anymore.
Silvio Traversaro c5a5e6d5 2020-09-13T19:35:47 Merge pull request #81 from ramiropolla/master Relicense to MIT
Silvio Traversaro d240aff1 2020-09-13T19:26:54 Rephrase configure script copyright notice
Silvio Traversaro f601b05f 2020-09-13T19:11:46 Merge pull request #80 from pali/master Add Travis CI testing
Ramiro Polla 4583f267 2020-08-30T13:43:50 Relicense to MIT The licensing note in the configure script has been reworked, similarly to how libvpx did it (they were also based on FFmpeg's configure script and also use a more permissive license).
Pali Rohár 48d16ae0 2020-08-26T19:27:28 Add Travis CI testing
Silvio Traversaro e5d9fab4 2020-08-05T08:50:41 Merge pull request #76 from pali/master Fix compilation with older environments
Pali Rohár e1d593d9 2020-08-04T18:35:01 Fix compilation with older environments This change should fix following compile error: dlfcn.c: In function 'dlsym': dlfcn.c:374:14: warning: implicit declaration of function 'GetModuleHandleExA' dlfcn.c: undefined reference to `GetModuleHandleExA' Documentation for function GetModuleHandleExA() says: To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later. Fixes: https://github.com/dlfcn-win32/dlfcn-win32/issues/75
Silvio Traversaro 0a494c01 2020-07-15T08:07:53 Merge pull request #74 from pali/master Replace VirtualQueryEx() call by GetModuleHandleExA() call
Pali Rohár 8ec5ffef 2020-07-14T21:14:56 Replace VirtualQueryEx() call by GetModuleHandleExA() call Usage of VirtualQueryEx() call is needed for retrieving HMODULE of passed function address and it is just an undocumented hack. Based on @rhabacker's tests it is unstable and does not work correctly. https://github.com/dlfcn-win32/dlfcn-win32/pull/72#issuecomment-656581418 So replace VirtualQueryEx() call by standard GetModuleHandleExA() function with special GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS flag which should do the same thing but it is documented and it is working correctly.
Silvio Traversaro 61ad60f5 2020-03-24T16:54:12 Merge pull request #69 from reborn2266/fix_mmleak fix memory leak in dlsym()
Mars Cheng cea65639 2020-03-24T20:05:29 fix memory leak in dlsym()
Silvio Traversaro 32be0765 2020-02-22T13:54:54 Merge pull request #68 from pali/master Show "(null)" in error message when passed filname to dlopen() was NULL and error occurred
Pali Rohár 70c5c20a 2020-02-19T22:39:29 Show "(null)" in error message when passed filname to dlopen() was NULL and error occurred It does not make sense to pass file variable (which is NULL) to function save_err_ptr_str() which converts its argument to string. We can call directly save_err_str() with string value. Also it is highly unexpected that GetModuleHandle(NULL) call fails.
Silvio Traversaro 974b39c7 2019-10-13T09:43:21 Merge pull request #67 from pali/master Add test which check that dlopen() can open same files as open()
Pali Rohár ab246dbf 2019-09-12T16:37:03 Add test which check that dlopen() can open same files as open() This ensures that dlopen() expects filenames encoded in same codepage as WinAPI's open() function.
Silvio Traversaro 07ef52a5 2019-09-01T14:35:56 Merge pull request #65 from pali/master Update documentation in dlfcn.h, specially for RTLD_LAZY
Pali Rohár 5d576e6d 2019-08-29T21:07:32 Update documentation in dlfcn.h, specially for RTLD_LAZY
Silvio Traversaro e7fef1b5 2019-08-23T10:19:56 Merge pull request #63 from pali/master Makefile: Fix building both static and shared library at the same time
Pali Rohár 2b342400 2019-08-22T23:36:22 Makefile: Fix building both static and shared library at the same time Static library libdl.a must be build without -DSHARED flag for obvious reason. So -DSHARED cannot be in global CFLAGS. Define also two separate test targets: test.exe for shared library and test-static.exe for static library.
Silvio Traversaro 1dfd103a 2019-08-22T23:05:54 Merge pull request #62 from pali/master Reduce memory usage by 64K
Pali Rohár 588b5782 2019-08-22T17:25:11 Reduce memory usage by 64K One buffer for error message is enough.
Silvio Traversaro 7f1a5e55 2019-08-21T10:48:49 Merge pull request #59 from pali/master Fix compile warnings
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 39ff58c2 2019-07-25T20:32:53 Do not include intrin.h file Include file intrin.h is not needed for compiling dlfcn.c as _ReturnAddress intrinsic is defined in dlfcn.c manually. Moreover _ReturnAddress is available only as an intrinsic, there is no function implementation. So even including intrin.h file does not provide function variant for _ReturnAddress. More important, include file intrin.h is not available in older Windows Driver Kit 7.1.0. So removing usage of intrin.h file makes compilation of dlfcn-win32 also under these older WDK versions.
Silvio Traversaro e476c014 2019-07-25T16:59:14 Merge pull request #58 from pali/master Correctly process malloc() error in dlsym()
Pali Rohár 242b94ac 2019-07-24T23:06:57 Correctly process malloc() error in dlsym() malloc() may fail, so propagate this error to caller.
Silvio Traversaro 4e17b083 2019-07-23T18:00:04 Merge pull request #55 from pali/master Turn off GUI error messages around LoadLibraryA also in test
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.
Silvio Traversaro 11ff86bf 2019-06-11T00:19:48 Merge pull request #54 from pali/master Correctly process and indicate errors
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 207311ce 2019-05-23T20:23:58 Correctly process and indicate error when file name is too long
Pali Rohár 44589dba 2019-05-23T20:23:50 Correctly process malloc() error in local_add() malloc() may fail, so propagate this error to caller of dlopen().
Pali Rohár 4fe419ca 2019-05-23T20:23:33 Correctly process and indicate error in dlsym() function Function save_err_str() checks for error by GetLastError() call. So ensure that last error is always set when error occurs.
Pali Rohár a5c0031e 2019-05-23T20:22:44 Correctly process and indicate error from LoadLibraryExA() function Function save_err_str() checks for error by GetLastError() call. Calling EnumProcessModules() may change or reset it. So call save_err_str() immediately after LoadLibraryExA().
Silvio Traversaro 1488731c 2019-05-21T18:55:39 Merge pull request #52 from pali/master Call FormatMessage() with FORMAT_MESSAGE_IGNORE_INSERTS
Pali Rohár 9ce1ba6f 2019-05-21T00:35:11 Call FormatMessage() with FORMAT_MESSAGE_IGNORE_INSERTS Documentation says: In particular, it is unsafe to take an arbitrary system error code returned from an API and use FORMAT_MESSAGE_FROM_SYSTEM without FORMAT_MESSAGE_IGNORE_INSERTS.
Silvio Traversaro 0fc1d9de 2019-05-20T23:41:19 Merge pull request #51 from pali/master Load Psapi.dll at runtime, this avoids linking caveat
Pali Rohár f3da31d7 2019-05-06T21:47:33 Load Psapi.dll at runtime, this avoids linking caveat
Silvio Traversaro 84295c9a 2019-05-06T21:02:00 Merge pull request #50 from pali/master Simplify UNICODE build
Pali Rohár e0a58321 2019-04-25T20:01:34 Test also UNICODE builds on AppVeyor CI
Pali Rohár 83add392 2019-04-25T19:36:57 Simplify implementation of save_err_str() Check return value of FormatMessageA() function and remove copy_string() function as it is not needed.
Pali Rohár d9d49f2d 2019-04-25T19:26:23 Remove ifdef hack for snprintf() 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.
Pali Rohár 04bbf248 2019-04-25T18:18:31 Simplify code around #ifdef UNICODE 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.
Silvio Traversaro 278c782a 2019-02-14T14:57:29 Merge pull request #44 from pali/master Fix resolving global symbols and implement RTLD_DEFAULT and RTLD_NEXT
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 Traversaro 1530bed6 2019-02-14T08:37:16 Merge pull request #48 from dlfcn-win32/appveyor-mingw-take-two Add MinGW and MinGW-w64 builds to AppVeyor (take 2)
Silvio Traversaro 23d77533 2019-02-11T00:31:22 Add MinGW and MinGW-w64 tests to AppVeyor
Silvio Traversaro f1acf5d2 2018-03-08T09:20:45 Merge pull request #41 from jddurand/master #include <stdlib.h>
Jean-Damien Durand d26298df 2018-01-17T10:02:39 #include <stdlib.h>
Silvio Traversaro f1edc335 2017-09-27T18:36:26 Merge pull request #40 from dlfcn-win32/document-cmake-usage Document how to use the library when using CMake
Silvio Traversaro b30b758e 2017-08-24T21:50:51 Mention the possibility of defining CMAKE_DL_LIBS
Silvio Traversaro de4a39d3 2017-08-24T21:43:59 Document how to use the library when using CMake
Silvio Traversaro 2d03bf63 2017-05-04T20:14:12 Merge pull request #39 from dlfcn-win32/traversaro-patch-2 [README] Fix AppVeyor badge
Silvio Traversaro 7c60c2d3 2017-05-04T13:20:27 [README] Fix AppVeyor badge
Silvio Traversaro ef7e412d 2017-05-04T13:12:09 Merge pull request #38 from dlfcn-win32/appveyor-test-vs2017 [appveyor] Test the library using Visual Studio 15 2017
Silvio Traversaro 49606058 2017-05-04T13:12:01 Merge pull request #36 from dlfcn-win32/fix-dlerror Fix bug in dlerror second consecutive call