diff options
author | Martin Storsjö <martin@martin.st> | 2021-05-12 14:14:23 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2021-05-12 14:57:19 +0300 |
commit | 0ced2f9e10f942ba9f59b7f6a75dd13c2389a6d2 (patch) | |
tree | c542eea012b8dc86283d76364e9169c0e08f49e4 | |
parent | d16ddb34aa7995c6ac78e523d1cefd6796a63176 (diff) |
Only call GetModuleHandle and AddVectoredExceptionHandler when targeting Windows Desktop
Don't call them when targeting e.g. UWP.
This requires building with a new enough SDK that does have the
winapifamily.h header (and that it's included implicitly by regular
platform headers); it's been available since the Windows 8.0 SDK
(and since mingw-w64 v3.0.0) so it should be safe.
Also rewrite the GetProcAddress call to avoid calling it if
GetModuleHandleW(L"kernel32.dll") would return NULL for some reason.
-rw-r--r-- | src/win32/thread.c | 9 | ||||
-rw-r--r-- | tests/checkasm/checkasm.c | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/win32/thread.c b/src/win32/thread.c index 5e878bf..7983d21 100644 --- a/src/win32/thread.c +++ b/src/win32/thread.c @@ -40,9 +40,12 @@ static HRESULT (WINAPI *set_thread_description)(HANDLE, PCWSTR); COLD void dav1d_init_thread(void) { - set_thread_description = - (void*)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), - "SetThreadDescription"); +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + HANDLE kernel32 = GetModuleHandleW(L"kernel32.dll"); + if (kernel32) + set_thread_description = + (void*)GetProcAddress(kernel32, "SetThreadDescription"); +#endif } #undef dav1d_set_thread_name diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 689830e..eeb1d15 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -755,10 +755,12 @@ void checkasm_report(const char *const name, ...) { void checkasm_set_signal_handler_state(const int enabled) { #ifdef _WIN32 +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (enabled) AddVectoredExceptionHandler(0, signal_handler); else RemoveVectoredExceptionHandler(signal_handler); +#endif #else void (*const handler)(int) = enabled ? signal_handler : SIG_DFL; signal(SIGBUS, handler); |