diff options
| author | Silvio Traversaro <silvio@traversaro.it> | 2025-05-03 12:27:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-03 12:27:40 +0200 |
| commit | 8bfddb5aa345ce10ba98e925acbc7bfb53639679 (patch) | |
| tree | 43c768ea57ebe87edb35aeb7f71e7a90efc7bc92 /tests | |
| parent | 3b52e651f385df00045dd8966407fd9de57fc94b (diff) | |
| parent | 7989e4dc4fa1dc31b4c353c72b092209a773c78f (diff) | |
| download | dlfcn-win32-8bfddb5aa345ce10ba98e925acbc7bfb53639679.tar.gz dlfcn-win32-8bfddb5aa345ce10ba98e925acbc7bfb53639679.tar.bz2 dlfcn-win32-8bfddb5aa345ce10ba98e925acbc7bfb53639679.zip | |
Remove use of CRT, fix gcc compilation in C++ mode, fix missing includes and fix warnings
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/test-dladdr.c | 9 | ||||
| -rw-r--r-- | tests/test.c | 1 |
3 files changed, 8 insertions, 4 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cd321f2..1fe7387 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
| @@ -31,6 +31,4 @@ if(WIN32 AND NOT BUILD_SHARED_LIBS) | |||
| 31 | endif() | 31 | endif() |
| 32 | endif() | 32 | endif() |
| 33 | 33 | ||
| 34 | install(TARGETS test-dladdr EXPORT dlfcn-win32-targets RUNTIME DESTINATION bin) | ||
| 35 | |||
| 36 | add_test(NAME test-dladdr COMMAND test-dladdr WORKING_DIRECTORY $<TARGET_FILE_DIR:test-dladdr>) | 34 | add_test(NAME test-dladdr COMMAND test-dladdr WORKING_DIRECTORY $<TARGET_FILE_DIR:test-dladdr>) |
diff --git a/tests/test-dladdr.c b/tests/test-dladdr.c index 5568f23..aa815b0 100644 --- a/tests/test-dladdr.c +++ b/tests/test-dladdr.c | |||
| @@ -140,6 +140,7 @@ __declspec(dllexport) | |||
| 140 | #endif | 140 | #endif |
| 141 | int main(int argc, char **argv) | 141 | int main(int argc, char **argv) |
| 142 | { | 142 | { |
| 143 | #ifdef _WIN32 | ||
| 143 | #if defined(_M_ARM64) || defined(__aarch64__) | 144 | #if defined(_M_ARM64) || defined(__aarch64__) |
| 144 | /* points to non reachable address */ | 145 | /* points to non reachable address */ |
| 145 | unsigned char zero_thunk_address[12] = { 0x10, 0x00, 0x00, 0x90, 0x10, 0x02, 0x40, 0xF9, 0x00, 0x02, 0x1F, 0xD6 }; | 146 | unsigned char zero_thunk_address[12] = { 0x10, 0x00, 0x00, 0x90, 0x10, 0x02, 0x40, 0xF9, 0x00, 0x02, 0x1F, 0xD6 }; |
| @@ -147,13 +148,16 @@ int main(int argc, char **argv) | |||
| 147 | unsigned char invalid_thunk_address[12] = { 0x10, 0x00, 0x00, 0xb0, 0x10, 0x06, 0x47, 0xF9, 0x00, 0x02, 0x1F, 0xD6 }; | 148 | unsigned char invalid_thunk_address[12] = { 0x10, 0x00, 0x00, 0xb0, 0x10, 0x06, 0x47, 0xF9, 0x00, 0x02, 0x1F, 0xD6 }; |
| 148 | /* no import thunk */ | 149 | /* no import thunk */ |
| 149 | unsigned char no_import_thunk[12] = { 0x11, 0x00, 0x00, 0xb0, 0x31, 0x06, 0x47, 0xF9, 0x20, 0x02, 0x1F, 0xD6 }; | 150 | unsigned char no_import_thunk[12] = { 0x11, 0x00, 0x00, 0xb0, 0x31, 0x06, 0x47, 0xF9, 0x20, 0x02, 0x1F, 0xD6 }; |
| 150 | #else | 151 | #elif defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) |
| 151 | /* points to non reachable address */ | 152 | /* points to non reachable address */ |
| 152 | unsigned char zero_thunk_address[6] = { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 }; | 153 | unsigned char zero_thunk_address[6] = { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 }; |
| 153 | /* points to executable base */ | 154 | /* points to executable base */ |
| 154 | unsigned char invalid_thunk_address[6] = { 0xFF, 0x25, 0x00, 0x00, 0x40, 0x00 }; | 155 | unsigned char invalid_thunk_address[6] = { 0xFF, 0x25, 0x00, 0x00, 0x40, 0x00 }; |
| 155 | /* no import thunk */ | 156 | /* no import thunk */ |
| 156 | unsigned char no_import_thunk[6] = { 0xFF, 0x26, 0x00, 0x00, 0x40, 0x00 }; | 157 | unsigned char no_import_thunk[6] = { 0xFF, 0x26, 0x00, 0x00, 0x40, 0x00 }; |
| 158 | #else | ||
| 159 | #error "thunk test cases are not defined for this architecture" | ||
| 160 | #endif | ||
| 157 | #endif | 161 | #endif |
| 158 | int result = 0; | 162 | int result = 0; |
| 159 | UNUSED(argv); | 163 | UNUSED(argv); |
| @@ -169,11 +173,12 @@ int main(int argc, char **argv) | |||
| 169 | result |= check_dladdr( "function from executable", (void*)main, "main", Pass ); | 173 | result |= check_dladdr( "function from executable", (void*)main, "main", Pass ); |
| 170 | result |= check_dladdr( "static function from executable", (void*)print_dl_info, "print_dl_info", Fail ); | 174 | result |= check_dladdr( "static function from executable", (void*)print_dl_info, "print_dl_info", Fail ); |
| 171 | result |= check_dladdr( "address with positive offset", ((char*)atoi)+1, "atoi", PassWithDifferentAddress ); | 175 | result |= check_dladdr( "address with positive offset", ((char*)atoi)+1, "atoi", PassWithDifferentAddress ); |
| 176 | |||
| 177 | #ifdef _WIN32 | ||
| 172 | result |= check_dladdr( "zero address from import thunk", zero_thunk_address, "", NoInfo ); | 178 | result |= check_dladdr( "zero address from import thunk", zero_thunk_address, "", NoInfo ); |
| 173 | result |= check_dladdr( "invalid address from import thunk", invalid_thunk_address, "", NoInfo ); | 179 | result |= check_dladdr( "invalid address from import thunk", invalid_thunk_address, "", NoInfo ); |
| 174 | result |= check_dladdr( "no import thunk", no_import_thunk, "", NoInfo ); | 180 | result |= check_dladdr( "no import thunk", no_import_thunk, "", NoInfo ); |
| 175 | 181 | ||
| 176 | #ifdef _WIN32 | ||
| 177 | result |= check_dladdr( "last entry in iat", (void*)VirtualQuery, "VirtualQuery", PassWithDifferentAddress ); | 182 | result |= check_dladdr( "last entry in iat", (void*)VirtualQuery, "VirtualQuery", PassWithDifferentAddress ); |
| 178 | 183 | ||
| 179 | result |= check_dladdr ( "address through import thunk", (void*)GetModuleHandleA, "GetModuleHandleA", PassWithDifferentAddress ); | 184 | result |= check_dladdr ( "address through import thunk", (void*)GetModuleHandleA, "GetModuleHandleA", PassWithDifferentAddress ); |
diff --git a/tests/test.c b/tests/test.c index 1d0d437..4fa7089 100644 --- a/tests/test.c +++ b/tests/test.c | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | #include <io.h> | 36 | #include <io.h> |
| 37 | #include <fcntl.h> | 37 | #include <fcntl.h> |
| 38 | #include <direct.h> | 38 | #include <direct.h> |
| 39 | #include <errno.h> | ||
| 39 | #include "dlfcn.h" | 40 | #include "dlfcn.h" |
| 40 | 41 | ||
| 41 | /* If these dlclose's fails, we don't care as the handles are going to be | 42 | /* If these dlclose's fails, we don't care as the handles are going to be |
