diff options
author | Silvio Traversaro <silvio@traversaro.it> | 2019-08-21 10:48:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-21 10:48:49 +0200 |
commit | 7f1a5e55754cb97dcde8c7a63f5466bea5d5ab8b (patch) | |
tree | 0c96b5b7df91d6dacbeee6e5fbcb283793b68dbb | |
parent | e476c014827446c08430e4ee87c5417dd68150e3 (diff) | |
parent | ff3026745272b9aa61731ee4150735e2c5cfcb70 (diff) | |
download | dlfcn-win32-7f1a5e55754cb97dcde8c7a63f5466bea5d5ab8b.tar.gz dlfcn-win32-7f1a5e55754cb97dcde8c7a63f5466bea5d5ab8b.tar.bz2 dlfcn-win32-7f1a5e55754cb97dcde8c7a63f5466bea5d5ab8b.zip |
Merge pull request #59 from pali/master
Fix compile warnings
-rw-r--r-- | dlfcn.c | 7 | ||||
-rw-r--r-- | test.c | 85 | ||||
-rw-r--r-- | testdll2.c | 2 |
3 files changed, 47 insertions, 47 deletions
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #ifdef _MSC_VER | 31 | #ifdef _MSC_VER |
32 | /* https://docs.microsoft.com/en-us/cpp/intrinsics/returnaddress */ | 32 | /* https://docs.microsoft.com/en-us/cpp/intrinsics/returnaddress */ |
33 | #include <intrin.h> | ||
34 | #pragma intrinsic(_ReturnAddress) | 33 | #pragma intrinsic(_ReturnAddress) |
35 | #else | 34 | #else |
36 | /* https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html */ | 35 | /* https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html */ |
@@ -455,11 +454,7 @@ end: | |||
455 | save_err_str( name ); | 454 | save_err_str( name ); |
456 | } | 455 | } |
457 | 456 | ||
458 | // warning C4054: 'type cast' : from function pointer 'FARPROC' to data pointer 'void *' | 457 | return *(void **) (&symbol); |
459 | #ifdef _MSC_VER | ||
460 | #pragma warning( suppress: 4054 ) | ||
461 | #endif | ||
462 | return (void*) symbol; | ||
463 | } | 458 | } |
464 | 459 | ||
465 | char *dlerror( void ) | 460 | char *dlerror( void ) |
@@ -86,6 +86,7 @@ int main() | |||
86 | char toolongfile[32767]; | 86 | char toolongfile[32767]; |
87 | DWORD code; | 87 | DWORD code; |
88 | char nonlibraryfile[MAX_PATH]; | 88 | char nonlibraryfile[MAX_PATH]; |
89 | DWORD length; | ||
89 | HANDLE tempfile; | 90 | HANDLE tempfile; |
90 | DWORD dummy; | 91 | DWORD dummy; |
91 | UINT uMode; | 92 | UINT uMode; |
@@ -99,14 +100,14 @@ int main() | |||
99 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); | 100 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); |
100 | #endif | 101 | #endif |
101 | 102 | ||
102 | ret = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile ); | 103 | length = GetTempPathA( sizeof( nonlibraryfile ) - sizeof( "temp.dll" ), nonlibraryfile ); |
103 | if( ret == 0 || ret > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) ) | 104 | if( length == 0 || length > sizeof( nonlibraryfile ) - sizeof( "temp.dll" ) ) |
104 | { | 105 | { |
105 | printf( "ERROR\tGetTempPath failed\n" ); | 106 | printf( "ERROR\tGetTempPath failed\n" ); |
106 | RETURN_ERROR; | 107 | RETURN_ERROR; |
107 | } | 108 | } |
108 | 109 | ||
109 | memcpy( nonlibraryfile + ret, "temp.dll", sizeof( "temp.dll" ) ); | 110 | memcpy( nonlibraryfile + length, "temp.dll", sizeof( "temp.dll" ) ); |
110 | 111 | ||
111 | tempfile = CreateFileA( (LPCSTR) nonlibraryfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL ); | 112 | tempfile = CreateFileA( (LPCSTR) nonlibraryfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL ); |
112 | if( tempfile == INVALID_HANDLE_VALUE ) | 113 | if( tempfile == INVALID_HANDLE_VALUE ) |
@@ -240,7 +241,7 @@ int main() | |||
240 | else | 241 | else |
241 | printf( "SUCCESS\tGot global handle: %p\n", global ); | 242 | printf( "SUCCESS\tGot global handle: %p\n", global ); |
242 | 243 | ||
243 | fwrite_local = dlsym(global, "fwrite"); | 244 | *(void **) (&fwrite_local) = dlsym( global, "fwrite" ); |
244 | if (!fwrite_local) | 245 | if (!fwrite_local) |
245 | { | 246 | { |
246 | error = dlerror(); | 247 | error = dlerror(); |
@@ -251,12 +252,14 @@ int main() | |||
251 | RETURN_ERROR; | 252 | RETURN_ERROR; |
252 | } | 253 | } |
253 | else | 254 | else |
254 | printf("SUCCESS\tGot symbol from global handle: %p\n", fwrite_local); | 255 | printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&fwrite_local) ); |
255 | char * hello_world = "Hello world from local fwrite!\n"; | 256 | { |
256 | fwrite_local(hello_world,sizeof(char),strlen(hello_world),stderr); | 257 | const char *hello_world = "Hello world from local fwrite!\n"; |
257 | fflush(stderr); | 258 | fwrite_local( hello_world, sizeof( char ), strlen( hello_world ), stderr ); |
259 | fflush( stderr ); | ||
260 | } | ||
258 | 261 | ||
259 | fputs_default = dlsym(RTLD_DEFAULT, "fputs"); | 262 | *(void **) (&fputs_default) = dlsym( RTLD_DEFAULT, "fputs" ); |
260 | if (!fputs_default) | 263 | if (!fputs_default) |
261 | { | 264 | { |
262 | error = dlerror(); | 265 | error = dlerror(); |
@@ -267,12 +270,14 @@ int main() | |||
267 | RETURN_ERROR; | 270 | RETURN_ERROR; |
268 | } | 271 | } |
269 | else | 272 | else |
270 | printf("SUCCESS\tGot symbol from default handle: %p\n", fputs_default); | 273 | printf( "SUCCESS\tGot symbol from default handle: %p\n", *(void **) (&fputs_default) ); |
271 | char * hello_world_fputs = "Hello world from default fputs!\n"; | 274 | { |
272 | fputs_default(hello_world_fputs, stderr); | 275 | const char *hello_world_fputs = "Hello world from default fputs!\n"; |
273 | fflush(stderr); | 276 | fputs_default( hello_world_fputs, stderr ); |
277 | fflush( stderr ); | ||
278 | } | ||
274 | 279 | ||
275 | function = dlsym( library, "function" ); | 280 | *(void **) (&function) = dlsym( library, "function" ); |
276 | if( !function ) | 281 | if( !function ) |
277 | { | 282 | { |
278 | error = dlerror( ); | 283 | error = dlerror( ); |
@@ -283,11 +288,11 @@ int main() | |||
283 | RETURN_ERROR; | 288 | RETURN_ERROR; |
284 | } | 289 | } |
285 | else | 290 | else |
286 | printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); | 291 | printf( "SUCCESS\tGot symbol from library handle: %p\n", *(void **) (&function) ); |
287 | 292 | ||
288 | RUNFUNC; | 293 | RUNFUNC; |
289 | 294 | ||
290 | function2_from_library2 = dlsym( library2, "function2" ); | 295 | *(void **) (&function2_from_library2) = dlsym( library2, "function2" ); |
291 | if( !function2_from_library2 ) | 296 | if( !function2_from_library2 ) |
292 | { | 297 | { |
293 | error = dlerror( ); | 298 | error = dlerror( ); |
@@ -298,7 +303,7 @@ int main() | |||
298 | RETURN_ERROR; | 303 | RETURN_ERROR; |
299 | } | 304 | } |
300 | else | 305 | else |
301 | printf( "SUCCESS\tGot symbol from library2 handle: %p\n", function2_from_library2 ); | 306 | printf( "SUCCESS\tGot symbol from library2 handle: %p\n", *(void **) (&function2_from_library2) ); |
302 | 307 | ||
303 | ret = function2_from_library2 (); | 308 | ret = function2_from_library2 (); |
304 | if( ret != 2 ) | 309 | if( ret != 2 ) |
@@ -308,11 +313,11 @@ int main() | |||
308 | RETURN_ERROR; | 313 | RETURN_ERROR; |
309 | } | 314 | } |
310 | 315 | ||
311 | nonexistentfunction = dlsym( library, "nonexistentfunction" ); | 316 | *(void **) (&nonexistentfunction) = dlsym( library, "nonexistentfunction" ); |
312 | if( nonexistentfunction ) | 317 | if( nonexistentfunction ) |
313 | { | 318 | { |
314 | error = dlerror( ); | 319 | error = dlerror( ); |
315 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction ); | 320 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", *(void **) (&nonexistentfunction) ); |
316 | CLOSE_LIB; | 321 | CLOSE_LIB; |
317 | CLOSE_GLOBAL; | 322 | CLOSE_GLOBAL; |
318 | RETURN_ERROR; | 323 | RETURN_ERROR; |
@@ -326,7 +331,7 @@ int main() | |||
326 | else | 331 | else |
327 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error ); | 332 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error ); |
328 | 333 | ||
329 | function = dlsym( global, "function" ); | 334 | *(void **) (&function) = dlsym( global, "function" ); |
330 | if( !function ) | 335 | if( !function ) |
331 | { | 336 | { |
332 | error = dlerror( ); | 337 | error = dlerror( ); |
@@ -337,15 +342,15 @@ int main() | |||
337 | RETURN_ERROR; | 342 | RETURN_ERROR; |
338 | } | 343 | } |
339 | else | 344 | else |
340 | printf( "SUCCESS\tGot symbol from global handle: %p\n", function ); | 345 | printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) ); |
341 | 346 | ||
342 | RUNFUNC; | 347 | RUNFUNC; |
343 | 348 | ||
344 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | 349 | *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" ); |
345 | if( nonexistentfunction ) | 350 | if( nonexistentfunction ) |
346 | { | 351 | { |
347 | error = dlerror( ); | 352 | error = dlerror( ); |
348 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction ); | 353 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", *(void **) (&nonexistentfunction) ); |
349 | CLOSE_LIB; | 354 | CLOSE_LIB; |
350 | CLOSE_GLOBAL; | 355 | CLOSE_GLOBAL; |
351 | RETURN_ERROR; | 356 | RETURN_ERROR; |
@@ -391,7 +396,7 @@ int main() | |||
391 | else | 396 | else |
392 | printf( "SUCCESS\tOpened library locally: %p\n", library ); | 397 | printf( "SUCCESS\tOpened library locally: %p\n", library ); |
393 | 398 | ||
394 | function = dlsym( library, "function" ); | 399 | *(void **) (&function) = dlsym( library, "function" ); |
395 | if( !function ) | 400 | if( !function ) |
396 | { | 401 | { |
397 | error = dlerror( ); | 402 | error = dlerror( ); |
@@ -402,15 +407,15 @@ int main() | |||
402 | RETURN_ERROR; | 407 | RETURN_ERROR; |
403 | } | 408 | } |
404 | else | 409 | else |
405 | printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); | 410 | printf( "SUCCESS\tGot symbol from library handle: %p\n", *(void **) (&function) ); |
406 | 411 | ||
407 | RUNFUNC; | 412 | RUNFUNC; |
408 | 413 | ||
409 | nonexistentfunction = dlsym( library, "nonexistentfunction" ); | 414 | *(void **) (&nonexistentfunction) = dlsym( library, "nonexistentfunction" ); |
410 | if( nonexistentfunction ) | 415 | if( nonexistentfunction ) |
411 | { | 416 | { |
412 | error = dlerror( ); | 417 | error = dlerror( ); |
413 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", nonexistentfunction ); | 418 | printf( "ERROR\tGot nonexistent symbol from library handle: %p\n", *(void **) (&nonexistentfunction) ); |
414 | CLOSE_LIB; | 419 | CLOSE_LIB; |
415 | CLOSE_GLOBAL; | 420 | CLOSE_GLOBAL; |
416 | RETURN_ERROR; | 421 | RETURN_ERROR; |
@@ -424,12 +429,12 @@ int main() | |||
424 | else | 429 | else |
425 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error ); | 430 | printf( "SUCCESS\tCould not get nonexistent symbol from library handle: %s\n", error ); |
426 | 431 | ||
427 | function = dlsym( global, "function" ); | 432 | *(void **) (&function) = dlsym( global, "function" ); |
428 | if( function ) | 433 | if( function ) |
429 | { | 434 | { |
430 | error = dlerror( ); | 435 | error = dlerror( ); |
431 | printf( "ERROR\tGot local symbol from global handle: %s @ %p\n", | 436 | printf( "ERROR\tGot local symbol from global handle: %s @ %p\n", |
432 | error ? error : "", function ); | 437 | error ? error : "", *(void **) (&function) ); |
433 | CLOSE_LIB; | 438 | CLOSE_LIB; |
434 | CLOSE_GLOBAL; | 439 | CLOSE_GLOBAL; |
435 | RETURN_ERROR; | 440 | RETURN_ERROR; |
@@ -437,11 +442,11 @@ int main() | |||
437 | else | 442 | else |
438 | printf( "SUCCESS\tDid not get local symbol from global handle.\n" ); | 443 | printf( "SUCCESS\tDid not get local symbol from global handle.\n" ); |
439 | 444 | ||
440 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | 445 | *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" ); |
441 | if( nonexistentfunction ) | 446 | if( nonexistentfunction ) |
442 | { | 447 | { |
443 | error = dlerror( ); | 448 | error = dlerror( ); |
444 | printf( "ERROR\tGot nonexistent local symbol from global handle: %p\n", nonexistentfunction ); | 449 | printf( "ERROR\tGot nonexistent local symbol from global handle: %p\n", *(void **) (&nonexistentfunction) ); |
445 | CLOSE_LIB; | 450 | CLOSE_LIB; |
446 | CLOSE_GLOBAL; | 451 | CLOSE_GLOBAL; |
447 | RETURN_ERROR; | 452 | RETURN_ERROR; |
@@ -467,7 +472,7 @@ int main() | |||
467 | else | 472 | else |
468 | printf( "SUCCESS\tOpened library globally without closing it first: %p\n", library ); | 473 | printf( "SUCCESS\tOpened library globally without closing it first: %p\n", library ); |
469 | 474 | ||
470 | function = dlsym( global, "function" ); | 475 | *(void **) (&function) = dlsym( global, "function" ); |
471 | if( !function ) | 476 | if( !function ) |
472 | { | 477 | { |
473 | error = dlerror( ); | 478 | error = dlerror( ); |
@@ -478,15 +483,15 @@ int main() | |||
478 | RETURN_ERROR; | 483 | RETURN_ERROR; |
479 | } | 484 | } |
480 | else | 485 | else |
481 | printf( "SUCCESS\tGot symbol from global handle: %p\n", function ); | 486 | printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) ); |
482 | 487 | ||
483 | RUNFUNC; | 488 | RUNFUNC; |
484 | 489 | ||
485 | nonexistentfunction = dlsym( global, "nonexistentfunction" ); | 490 | *(void **) (&nonexistentfunction) = dlsym( global, "nonexistentfunction" ); |
486 | if( nonexistentfunction ) | 491 | if( nonexistentfunction ) |
487 | { | 492 | { |
488 | error = dlerror( ); | 493 | error = dlerror( ); |
489 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", nonexistentfunction ); | 494 | printf( "ERROR\tGot nonexistent symbol from global handle: %p\n", *(void **) (&nonexistentfunction) ); |
490 | CLOSE_LIB; | 495 | CLOSE_LIB; |
491 | CLOSE_GLOBAL; | 496 | CLOSE_GLOBAL; |
492 | RETURN_ERROR; | 497 | RETURN_ERROR; |
@@ -517,7 +522,7 @@ int main() | |||
517 | } | 522 | } |
518 | } | 523 | } |
519 | 524 | ||
520 | function = dlsym(global, "fwrite"); | 525 | *(void **) (&function) = dlsym( global, "fwrite" ); |
521 | if (!function) | 526 | if (!function) |
522 | { | 527 | { |
523 | error = dlerror(); | 528 | error = dlerror(); |
@@ -528,7 +533,7 @@ int main() | |||
528 | RETURN_ERROR; | 533 | RETURN_ERROR; |
529 | } | 534 | } |
530 | else | 535 | else |
531 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); | 536 | printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) ); |
532 | 537 | ||
533 | 538 | ||
534 | uMode = SetErrorMode( SEM_FAILCRITICALERRORS ); | 539 | uMode = SetErrorMode( SEM_FAILCRITICALERRORS ); |
@@ -540,7 +545,7 @@ int main() | |||
540 | RETURN_ERROR; | 545 | RETURN_ERROR; |
541 | } | 546 | } |
542 | else | 547 | else |
543 | printf( "SUCCESS\tOpened library3 via WINAPI: %p\n", library3 ); | 548 | printf( "SUCCESS\tOpened library3 via WINAPI: %p\n", (void *)library3 ); |
544 | 549 | ||
545 | ret = dlclose( library ); | 550 | ret = dlclose( library ); |
546 | if( ret ) | 551 | if( ret ) |
@@ -553,7 +558,7 @@ int main() | |||
553 | else | 558 | else |
554 | printf( "SUCCESS\tClosed library.\n" ); | 559 | printf( "SUCCESS\tClosed library.\n" ); |
555 | 560 | ||
556 | function = dlsym(global, "function3"); | 561 | *(void **) (&function) = dlsym( global, "function3" ); |
557 | if (!function) | 562 | if (!function) |
558 | { | 563 | { |
559 | error = dlerror(); | 564 | error = dlerror(); |
@@ -564,7 +569,7 @@ int main() | |||
564 | RETURN_ERROR; | 569 | RETURN_ERROR; |
565 | } | 570 | } |
566 | else | 571 | else |
567 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); | 572 | printf( "SUCCESS\tGot symbol from global handle: %p\n", *(void **) (&function) ); |
568 | 573 | ||
569 | RUNFUNC; | 574 | RUNFUNC; |
570 | 575 | ||
@@ -38,7 +38,7 @@ EXPORT int function2( void ) | |||
38 | char *error; | 38 | char *error; |
39 | int (*function2_orig)(void); | 39 | int (*function2_orig)(void); |
40 | printf( "Hello, world! from wrapper library\n" ); | 40 | printf( "Hello, world! from wrapper library\n" ); |
41 | function2_orig = dlsym(RTLD_NEXT, "function2"); | 41 | *(void **) (&function2_orig) = dlsym( RTLD_NEXT, "function2" ); |
42 | if (!function2_orig) | 42 | if (!function2_orig) |
43 | { | 43 | { |
44 | error = dlerror( ); | 44 | error = dlerror( ); |