diff options
| author | 2022-01-06 09:22:30 +0100 | |
|---|---|---|
| committer | 2022-01-06 09:22:30 +0100 | |
| commit | 8f66cfa156f04cc6f1f6a78bff261122de6801ca (patch) | |
| tree | c5c50a4515dca0b6003975d7683e5beaac21c731 | |
| parent | 8bc9ccc2bff2e3f92a952bf9ae9fa218f448c774 (diff) | |
| download | libirecovery-8f66cfa156f04cc6f1f6a78bff261122de6801ca.tar.gz libirecovery-8f66cfa156f04cc6f1f6a78bff261122de6801ca.tar.bz2  | |
Check availability of constructor attribute and use it on Windows in favor of DllMain
| -rw-r--r-- | configure.ac | 18 | ||||
| -rw-r--r-- | src/libirecovery.c | 28 | 
2 files changed, 36 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index 518366c..e844956 100644 --- a/configure.ac +++ b/configure.ac  | |||
| @@ -82,6 +82,24 @@ case ${host_os} in | |||
| 82 | esac | 82 | esac | 
| 83 | AM_CONDITIONAL(WIN32, test x$win32 = xtrue) | 83 | AM_CONDITIONAL(WIN32, test x$win32 = xtrue) | 
| 84 | 84 | ||
| 85 | # Check if the C compiler supports __attribute__((constructor)) | ||
| 86 | AC_CACHE_CHECK([wether the C compiler supports constructor/destructor attributes], | ||
| 87 | ac_cv_attribute_constructor, [ | ||
| 88 | ac_cv_attribute_constructor=no | ||
| 89 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( | ||
| 90 | [[ | ||
| 91 | static void __attribute__((constructor)) test_constructor(void) { | ||
| 92 | } | ||
| 93 | static void __attribute__((destructor)) test_destructor(void) { | ||
| 94 | } | ||
| 95 | ]], [])], | ||
| 96 | [ac_cv_attribute_constructor=yes] | ||
| 97 | )] | ||
| 98 | ) | ||
| 99 | if test "$ac_cv_attribute_constructor" = "yes"; then | ||
| 100 | AC_DEFINE(HAVE_ATTRIBUTE_CONSTRUCTOR, 1, [Define if the C compiler supports constructor/destructor attributes]) | ||
| 101 | fi | ||
| 102 | |||
| 85 | AC_ARG_WITH([dummy], | 103 | AC_ARG_WITH([dummy], | 
| 86 | [AS_HELP_STRING([--with-dummy], [Use no USB driver at all [default=no]. This is only useful if you just want to query the device list by product type or hardware model. All other operations are no-ops or will return IRECV_E_UNSUPPORTED.])], | 104 | [AS_HELP_STRING([--with-dummy], [Use no USB driver at all [default=no]. This is only useful if you just want to query the device list by product type or hardware model. All other operations are no-ops or will return IRECV_E_UNSUPPORTED.])], | 
| 87 | [], | 105 | [], | 
diff --git a/src/libirecovery.c b/src/libirecovery.c index 0e971a0..b0f6409 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c  | |||
| @@ -442,7 +442,23 @@ static void _irecv_deinit(void) | |||
| 442 | static thread_once_t init_once = THREAD_ONCE_INIT; | 442 | static thread_once_t init_once = THREAD_ONCE_INIT; | 
| 443 | static thread_once_t deinit_once = THREAD_ONCE_INIT; | 443 | static thread_once_t deinit_once = THREAD_ONCE_INIT; | 
| 444 | 444 | ||
| 445 | #ifdef WIN32 | 445 | #ifndef HAVE_ATTRIBUTE_CONSTRUCTOR | 
| 446 | #if defined(__llvm__) || defined(__GNUC__) | ||
| 447 | #define HAVE_ATTRIBUTE_CONSTRUCTOR | ||
| 448 | #endif | ||
| 449 | #endif | ||
| 450 | |||
| 451 | #ifdef HAVE_ATTRIBUTE_CONSTRUCTOR | ||
| 452 | static void __attribute__((constructor)) libirecovery_initialize(void) | ||
| 453 | { | ||
| 454 | thread_once(&init_once, _irecv_init); | ||
| 455 | } | ||
| 456 | |||
| 457 | static void __attribute__((destructor)) libirecovery_deinitialize(void) | ||
| 458 | { | ||
| 459 | thread_once(&deinit_once, _irecv_deinit); | ||
| 460 | } | ||
| 461 | #elif defined(WIN32) | ||
| 446 | BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) | 462 | BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) | 
| 447 | { | 463 | { | 
| 448 | switch (dwReason) { | 464 | switch (dwReason) { | 
| @@ -458,15 +474,7 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) | |||
| 458 | return 1; | 474 | return 1; | 
| 459 | } | 475 | } | 
| 460 | #else | 476 | #else | 
| 461 | static void __attribute__((constructor)) libirecovery_initialize(void) | 477 | #warning No compiler support for constructor/destructor attributes, some features might not be available. | 
| 462 | { | ||
| 463 | thread_once(&init_once, _irecv_init); | ||
| 464 | } | ||
| 465 | |||
| 466 | static void __attribute__((destructor)) libirecovery_deinitialize(void) | ||
| 467 | { | ||
| 468 | thread_once(&deinit_once, _irecv_deinit); | ||
| 469 | } | ||
| 470 | #endif | 478 | #endif | 
| 471 | 479 | ||
| 472 | #ifdef HAVE_IOKIT | 480 | #ifdef HAVE_IOKIT | 
