| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|\
| |
| | |
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.
|
|\
| |
| | |
Reduce memory usage by 64K
|
|/
|
|
| |
One buffer for error message is enough.
|
|\
| |
| | |
Fix compile warnings
|
| |
| |
| |
| |
| | |
ISO C90 forbids mixed declarations and code
ISO C++ forbids converting a string constant to 'char*'
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| | |
GetTempPathA() returns DWORD (32/64bit unsigned integer) and not int
(32 signed integer).
|
|/
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
Correctly process malloc() error in dlsym()
|
|/
|
|
| |
malloc() may fail, so propagate this error to caller.
|
|\
| |
| | |
Turn off GUI error messages around LoadLibraryA also in test
|
|/
|
|
| |
Otherwise running test show GUI error messages which needs to be closed.
|
|\
| |
| | |
Correctly process and indicate errors
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
| |
| |
| | |
malloc() may fail, so propagate this error to caller of dlopen().
|
| |
| |
| |
| |
| | |
Function save_err_str() checks for error by GetLastError() call. So ensure
that last error is always set when error occurs.
|
|/
|
|
|
|
| |
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().
|
|\
| |
| | |
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.
|
|\
| |
| | |
Load Psapi.dll at runtime, this avoids linking caveat
|
|/ |
|
|\
| |
| | |
Simplify UNICODE build
|
| | |
|
| |
| |
| |
| |
| | |
Check return value of FormatMessageA() function and remove copy_string()
function as it is not needed.
|
| |
| |
| |
| |
| |
| | |
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.
|
|/
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
Fix resolving global symbols and implement 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.
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 */
|
|\
| |
| | |
Add MinGW and MinGW-w64 builds to AppVeyor (take 2)
|
|/ |
|
|\
| |
| | |
#include <stdlib.h>
|
|/ |
|
|\
| |
| | |
Document how to use the library when using CMake
|
| | |
|
|/ |
|
|\
| |
| | |
[README] Fix AppVeyor badge
|
|/ |
|
|\
| |
| | |
[appveyor] Test the library using Visual Studio 15 2017
|
| |
| |
| | |
See https://www.appveyor.com/docs/build-environment/ for the logic behind the option used.
|
|\ \
| |/
|/| |
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.
|
|\
| |
| | |
Minor AppVeyor configuration cleanup
|
|/ |
|
| |
|