diff --git a/sdk/lib/crt/float/_controlfp_s.c b/sdk/lib/crt/float/_controlfp_s.c new file mode 100644 index 00000000000..5f5363770ce --- /dev/null +++ b/sdk/lib/crt/float/_controlfp_s.c @@ -0,0 +1,31 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Implementation of _controlfp_s (adapted from wine msvcrt/math.c) + * COPYRIGHT: Copyright 2000 Jon Griffiths + * Copyright 2010 Piotr Caban + * Copyright 2021 Roman Masanin <36927roma@gmail.com> + */ + +#include +#include + +#ifdef _M_ARM +#define INVALID_MASK ~(_MCW_EM | _MCW_RC | _MCW_DN) +#else +#define INVALID_MASK ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN) +#endif + +int CDECL _controlfp_s(unsigned int* cur, unsigned int newval, unsigned int mask) +{ + unsigned int val; + + if (!MSVCRT_CHECK_PMT((newval & mask & INVALID_MASK) == 0)) + { + if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */ + return EINVAL; + } + val = _controlfp(newval, mask); + if (cur) *cur = val; + return 0; +} diff --git a/sdk/lib/crt/float/arm/_controlfp.c b/sdk/lib/crt/float/arm/_controlfp.c index 2c697841ea2..1bce54126d9 100644 --- a/sdk/lib/crt/float/arm/_controlfp.c +++ b/sdk/lib/crt/float/arm/_controlfp.c @@ -68,16 +68,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask) return flags; } -int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask) -{ - unsigned int val; - - if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_RC | _MCW_DN)) )) - { - if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */ - return EINVAL; - } - val = _controlfp(newval, mask); - if (cur) *cur = val; - return 0; -} diff --git a/sdk/lib/crt/float/float.cmake b/sdk/lib/crt/float/float.cmake index d3ca0e6a9c6..86568dcb7d1 100644 --- a/sdk/lib/crt/float/float.cmake +++ b/sdk/lib/crt/float/float.cmake @@ -6,6 +6,7 @@ list(APPEND LIBCNTPR_FLOAT_SOURCE list(APPEND CRT_FLOAT_SOURCE ${LIBCNTPR_FLOAT_SOURCE} float/chgsign.c + float/_controlfp_s.c float/copysign.c float/fpclass.c float/fpecode.c diff --git a/sdk/lib/crt/float/i386/cntrlfp.c b/sdk/lib/crt/float/i386/cntrlfp.c index b78cbc7cd26..09fe41449e6 100644 --- a/sdk/lib/crt/float/i386/cntrlfp.c +++ b/sdk/lib/crt/float/i386/cntrlfp.c @@ -113,25 +113,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask) return flags; } - -/********************************************************************* - * _controlfp_s (MSVCRT.@) - */ -int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask) -{ -#ifdef __i386__ - unsigned int val; - - if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN)))) - { - if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */ - return EINVAL; - } - val = _controlfp( newval, mask ); - if (cur) *cur = val; - return 0; -#else - FIXME(":Not Implemented!\n"); - return 0; -#endif -}