[WIN32SS] Improve the FILE header section. Brought to you by Adam Stachowicz. CORE...
[reactos.git] / reactos / win32ss / gdi / eng / float.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Engine floating point functions
5 * FILE: win32ss/gdi/eng/float.c
6 * PROGRAMER: David Welch
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <win32k.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 #ifdef _PREFAST_
19 #pragma warning(disable:__WARNING_WRONG_KIND)
20 #endif
21
22 _Check_return_
23 _Success_(return)
24 _Kernel_float_restored_
25 _At_(*pBuffer, _Kernel_requires_resource_held_(EngFloatState)
26 _Kernel_releases_resource_(EngFloatState))
27 ENGAPI
28 BOOL
29 APIENTRY
30 EngRestoreFloatingPointState(
31 _In_reads_(_Inexpressible_(statesize)) PVOID pBuffer)
32 {
33 NTSTATUS Status;
34
35 Status = KeRestoreFloatingPointState((PKFLOATING_SAVE)pBuffer);
36 if (!NT_SUCCESS(Status))
37 {
38 return FALSE;
39 }
40
41 return TRUE;
42 }
43
44 _Check_return_
45 _Success_(((pBuffer != NULL && cjBufferSize != 0) && return == 1) ||
46 ((pBuffer == NULL || cjBufferSize == 0) && return > 0))
47 _When_(pBuffer != NULL && cjBufferSize != 0 && return == 1, _Kernel_float_saved_
48 _At_(*pBuffer, _Post_valid_ _Kernel_acquires_resource_(EngFloatState)))
49 _On_failure_(_Post_satisfies_(return == 0))
50 ENGAPI
51 ULONG
52 APIENTRY
53 EngSaveFloatingPointState(
54 _At_(*pBuffer, _Kernel_requires_resource_not_held_(EngFloatState))
55 _Out_writes_bytes_opt_(cjBufferSize) PVOID pBuffer,
56 _Inout_ ULONG cjBufferSize)
57 {
58 KFLOATING_SAVE TempBuffer;
59 NTSTATUS Status;
60
61 if ((pBuffer == NULL) || (cjBufferSize == 0))
62 {
63 /* Check for floating point support. */
64 Status = KeSaveFloatingPointState(&TempBuffer);
65 if (Status != STATUS_SUCCESS)
66 {
67 return(0);
68 }
69
70 KeRestoreFloatingPointState(&TempBuffer);
71 return(sizeof(KFLOATING_SAVE));
72 }
73
74 if (cjBufferSize < sizeof(KFLOATING_SAVE))
75 {
76 return(0);
77 }
78
79 Status = KeSaveFloatingPointState((PKFLOATING_SAVE)pBuffer);
80 if (!NT_SUCCESS(Status))
81 {
82 return FALSE;
83 }
84
85 return TRUE;
86 }
87