From: Nirbheek Chauhan Date: Wed, 8 Jul 2020 17:40:34 +0000 (+0530) Subject: crypto/win: Don't use disallowed APIs on UWP X-Git-Tag: openssl-3.0.0-alpha10~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce1119265005bd254fc92395f72490c19adc707c;p=thirdparty%2Fopenssl.git crypto/win: Don't use disallowed APIs on UWP CreateFiber and ConvertThreadToFiber are not allowed in Windows Store (Universal Windows Platform) apps since they have been replaced by their Ex variants which have a new dwFlags parameter. This flag allows the fiber to do floating-point arithmetic in the fiber on x86, which would silently cause corruption otherwise since the floating-point state is not switched by default. Switch to these "new" APIs which were added in Vista. See: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createfiberex#parameters Reviewed-by: Richard Levitte Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/12400) --- diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c index 0db9efe3c1c..72cc27c214c 100644 --- a/crypto/async/arch/async_win.c +++ b/crypto/async/arch/async_win.c @@ -34,7 +34,11 @@ void async_local_cleanup(void) int async_fibre_init_dispatcher(async_fibre *fibre) { +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 + fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH); +# else fibre->fibre = ConvertThreadToFiber(NULL); +# endif if (fibre->fibre == NULL) { fibre->converted = 0; fibre->fibre = GetCurrentFiber(); diff --git a/crypto/async/arch/async_win.h b/crypto/async/arch/async_win.h index 87e661d7663..eb61b032e0c 100644 --- a/crypto/async/arch/async_win.h +++ b/crypto/async/arch/async_win.h @@ -26,8 +26,16 @@ typedef struct async_fibre_st { # define async_fibre_swapcontext(o,n,r) \ (SwitchToFiber((n)->fibre), 1) -# define async_fibre_makecontext(c) \ + +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 +# define async_fibre_makecontext(c) \ + ((c)->fibre = CreateFiberEx(0, 0, FIBER_FLAG_FLOAT_SWITCH, \ + async_start_func_win, 0)) +# else +# define async_fibre_makecontext(c) \ ((c)->fibre = CreateFiber(0, async_start_func_win, 0)) +# endif + # define async_fibre_free(f) (DeleteFiber((f)->fibre)) int async_fibre_init_dispatcher(async_fibre *fibre);