aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #81 from ramiropolla/masterSilvio Traversaro2020-09-139-600/+127
|\ | | | | Relicense to MIT
| * Rephrase configure script copyright noticeSilvio Traversaro2020-09-131-1/+5
| |
| * Relicense to MITRamiro Polla2020-08-309-600/+123
| | | | | | | | | | | | 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).
* | Merge pull request #80 from pali/masterSilvio Traversaro2020-09-131-0/+16
|\ \ | |/ |/| Add Travis CI testing
| * Add Travis CI testingPali Rohár2020-08-261-0/+16
|/
* Merge pull request #76 from pali/masterSilvio Traversaro2020-08-051-0/+3
|\ | | | | Fix compilation with older environments
| * Fix compilation with older environmentsPali Rohár2020-08-041-0/+3
|/ | | | | | | | | | | | | | 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
* Merge pull request #74 from pali/masterSilvio Traversaro2020-07-151-16/+2
|\ | | | | Replace VirtualQueryEx() call by GetModuleHandleExA() call
| * Replace VirtualQueryEx() call by GetModuleHandleExA() callPali Rohár2020-07-141-16/+2
|/ | | | | | | | | | | | 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.
* Merge pull request #69 from reborn2266/fix_mmleakSilvio Traversaro2020-03-241-0/+3
|\ | | | | fix memory leak in dlsym()
| * fix memory leak in dlsym()Mars Cheng2020-03-241-0/+3
|/
* Merge pull request #68 from pali/masterSilvio Traversaro2020-02-221-1/+1
|\ | | | | Show "(null)" in error message when passed filname to dlopen() was NULL and error occurred
| * Show "(null)" in error message when passed filname to dlopen() was NULL and ↵Pali Rohár2020-02-191-1/+1
|/ | | | | | | | | | 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.
* Merge pull request #67 from pali/masterSilvio Traversaro2019-10-131-0/+93
|\ | | | | Add test which check that dlopen() can open same files as open()
| * Add test which check that dlopen() can open same files as open()Pali Rohár2019-09-121-0/+93
|/ | | | | This ensures that dlopen() expects filenames encoded in same codepage as WinAPI's open() function.
* Merge pull request #65 from pali/masterSilvio Traversaro2019-09-012-11/+26
|\ | | | | Update documentation in dlfcn.h, specially for RTLD_LAZY
| * Update documentation in dlfcn.h, specially for RTLD_LAZYPali Rohár2019-08-292-11/+26
|/
* Merge pull request #63 from pali/masterSilvio Traversaro2019-08-231-18/+20
|\ | | | | Makefile: Fix building both static and shared library at the same time
| * Makefile: Fix building both static and shared library at the same timePali Rohár2019-08-221-18/+20
|/ | | | | | | | 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.
* Merge pull request #62 from pali/masterSilvio Traversaro2019-08-221-15/+9
|\ | | | | Reduce memory usage by 64K
| * Reduce memory usage by 64KPali Rohár2019-08-221-15/+9
|/ | | | One buffer for error message is enough.
* Merge pull request #59 from pali/masterSilvio Traversaro2019-08-213-47/+47
|\ | | | | Fix compile warnings
| * Fix more gcc warningsPali Rohár2019-07-261-6/+10
| | | | | | | | | | ISO C90 forbids mixed declarations and code ISO C++ forbids converting a string constant to 'char*'
| * Fix gcc warning: ISO C forbids return between function pointer and void *Pali Rohár2019-07-253-37/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Fix gcc warning: comparison between signed and unsigned integer expressionsPali Rohár2019-07-251-3/+4
| | | | | | | | | | GetTempPathA() returns DWORD (32/64bit unsigned integer) and not int (32 signed integer).
| * Do not include intrin.h filePali Rohár2019-07-251-1/+0
|/ | | | | | | | | | | | 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.
* Merge pull request #58 from pali/masterSilvio Traversaro2019-07-251-0/+5
|\ | | | | Correctly process malloc() error in dlsym()
| * Correctly process malloc() error in dlsym()Pali Rohár2019-07-241-0/+5
|/ | | | malloc() may fail, so propagate this error to caller.
* Merge pull request #55 from pali/masterSilvio Traversaro2019-07-231-0/+7
|\ | | | | Turn off GUI error messages around LoadLibraryA also in test
| * Turn off GUI error messages around LoadLibraryA also in testPali Rohár2019-06-111-0/+7
|/ | | | Otherwise running test show GUI error messages which needs to be closed.
* Merge pull request #54 from pali/masterSilvio Traversaro2019-06-112-67/+228
|\ | | | | Correctly process and indicate errors
| * Add test for non-library filePali Rohár2019-05-231-0/+61
| |
| * Add tests for non-existent file and file with too long namePali Rohár2019-05-231-0/+50
| |
| * Test that dlerror() returns non-NULL error for failed callsPali Rohár2019-05-231-20/+37
| |
| * Correctly process and indicate error when file name is too longPali Rohár2019-05-231-47/+55
| |
| * Correctly process malloc() error in local_add()Pali Rohár2019-05-231-8/+15
| | | | | | | | malloc() may fail, so propagate this error to caller of dlopen().
| * Correctly process and indicate error in dlsym() functionPali Rohár2019-05-231-1/+10
| | | | | | | | | | Function save_err_str() checks for error by GetLastError() call. So ensure that last error is always set when error occurs.
| * Correctly process and indicate error from LoadLibraryExA() functionPali Rohár2019-05-231-16/+25
|/ | | | | | 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().
* Merge pull request #52 from pali/masterSilvio Traversaro2019-05-211-1/+1
|\ | | | | Call FormatMessage() with FORMAT_MESSAGE_IGNORE_INSERTS
| * Call FormatMessage() with FORMAT_MESSAGE_IGNORE_INSERTSPali Rohár2019-05-211-1/+1
|/ | | | | | 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.
* Merge pull request #51 from pali/masterv1.2.0Silvio Traversaro2019-05-206-30/+26
|\ | | | | Load Psapi.dll at runtime, this avoids linking caveat
| * Load Psapi.dll at runtime, this avoids linking caveatPali Rohár2019-05-066-30/+26
|/
* Merge pull request #50 from pali/masterSilvio Traversaro2019-05-062-95/+134
|\ | | | | Simplify UNICODE build
| * Test also UNICODE builds on AppVeyor CIPali Rohár2019-04-251-0/+102
| |
| * Simplify implementation of save_err_str()Pali Rohár2019-04-251-26/+22
| | | | | | | | | | Check return value of FormatMessageA() function and remove copy_string() function as it is not needed.
| * Remove ifdef hack for snprintf()Pali Rohár2019-04-251-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.
| * Simplify code around #ifdef UNICODEPali Rohár2019-04-251-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.
* Merge pull request #44 from pali/masterSilvio Traversaro2019-02-149-120/+335
|\ | | | | Fix resolving global symbols and implement RTLD_DEFAULT and RTLD_NEXT
| * Implement support for dlsym() with RTLD_DEFAULT and RTLD_NEXTPali Rohár2019-02-148-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.
| * Fix resolving global symbols when LoadLibrary() is called after dlopen()Pali Rohár2019-02-146-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 */