ReactOS 0.4.17-dev-1005-g171e1de
env_windowsUserModeWin8_1.c
Go to the documentation of this file.
1//
2// env_windowsUserMode.c
3// Platform-specific code for windows user mode.
4//
5// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
6//
7
8//#include "precomp.h"
9
10#pragma warning(push)
11#pragma warning(disable: 5103) // Arm64's wdm.h included below currently generate a lot of 5103 warnings
12#include <windows.h>
13#pragma warning(pop)
14#include "symcrypt.h"
15#include "sc_lib.h"
16
18{
19 return 0;
20}
21
22VOID
25{
27 {
28 return;
29 }
30
31#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
32 //
33 // First we detect what the CPU has
34 //
36
37 //
38 // We also need to be sure that the OS supports the extended registers.
39 //
40 {
41 ULONGLONG FeatureMask = GetEnabledXStateFeatures();
42
43 if( !(FeatureMask & XSTATE_MASK_AVX) )
44 {
45 g_SymCryptCpuFeaturesNotPresent |= SYMCRYPT_CPU_FEATURE_AVX2;
46 }
47
48 if( !(FeatureMask & XSTATE_MASK_AVX512) )
49 {
50 g_SymCryptCpuFeaturesNotPresent |= SYMCRYPT_CPU_FEATURE_AVX512;
51 }
52 }
53
54 //
55 // Our SaveXmm function never fails because it doesn't have to do anything in User mode.
56 //
57 g_SymCryptCpuFeaturesNotPresent &= ~SYMCRYPT_CPU_FEATURE_SAVEXMM_NOFAIL;
58
59#elif SYMCRYPT_CPU_ARM
60
61 g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~SYMCRYPT_CPU_FEATURE_NEON;
62
63#elif SYMCRYPT_CPU_ARM64
64
66
67#endif
68
70}
71
73VOID
76{
77 UINT32 fatalCodeVar;
78
79 SymCryptFatalIntercept( fatalCode );
80
81 //
82 // Put the fatal code in a location where it shows up in the dump
83 //
84 SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode );
85
86 //
87 // Our first preference is to fastfail,
88 // the second to create an AV, which triggers a Watson report so that we get to
89 // see what is going wrong.
90 //
92
93 //
94 // Next we write to the NULL pointer, this causes an AV
95 //
96 SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );
97
98 //
99 // If that fails, we terminate the process. (This function call also ensures that this environment is actually
100 // used in user mode and not some other environment.)
101 // (During testing we had the TerminateProcess as the first option, but that makes debugging very hard as
102 // it leaves no traces of what went wrong.)
103 //
104 TerminateProcess( GetCurrentProcess(), fatalCode );
105
106 SymCryptFatalHang( fatalCode );
107}
108
109#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86
110
113SymCryptSaveXmmEnvWindowsUsermodeWin8_1nLater( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
114{
115 //
116 // In usermode there is no need to save XMM registers.
117 // The compiler should inline this function and optimize it away.
118 //
119
120 UNREFERENCED_PARAMETER( pSaveArea );
121
122 return SYMCRYPT_NO_ERROR;
123}
124
125VOID
127SymCryptRestoreXmmEnvWindowsUsermodeWin8_1nLater( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
128{
129 //
130 // In usermode there is no need to save XMM registers.
131 // The compiler should inline this function and optimize it away.
132 //
133
134 UNREFERENCED_PARAMETER( pSaveArea );
135}
136
137
140SymCryptSaveYmmEnvWindowsUsermodeWin8_1nLater( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
141{
142 //
143 // In usermode there is no need to save XMM registers.
144 // The compiler should inline this function and optimize it away.
145 //
146
147 UNREFERENCED_PARAMETER( pSaveArea );
148
149 return SYMCRYPT_NO_ERROR;
150}
151
152VOID
154SymCryptRestoreYmmEnvWindowsUsermodeWin8_1nLater( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
155{
156 //
157 // In usermode there is no need to save XMM registers.
158 // The compiler should inline this function and optimize it away.
159 //
160
161 UNREFERENCED_PARAMETER( pSaveArea );
162}
163
164#endif
165
166VOID
169{
170 //
171 // This feature is only used during testing. In production it is always
172 // an empty function that the compiler can optimize away.
173 //
174 UNREFERENCED_PARAMETER( pbBuf );
175 UNREFERENCED_PARAMETER( cbBuf );
176}
177
178#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86
179
180VOID
182SymCryptCpuidExFuncEnvWindowsUsermodeWin8_1nLater( int cpuInfo[4], int function_id, int subfunction_id )
183{
184 __cpuidex( cpuInfo, function_id, subfunction_id );
185}
186
187#endif
VOID SYMCRYPT_CALL SymCryptFatalIntercept(UINT32 fatalCode)
#define NULL
Definition: types.h:112
#define GetCurrentProcess()
Definition: compat.h:759
static const WCHAR version[]
Definition: asmname.c:66
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1425
VOID SYMCRYPT_CALL SymCryptInitEnvWindowsUsermodeWin8_1nLater(UINT32 version)
VOID SYMCRYPT_CALL SymCryptTestInjectErrorEnvWindowsUsermodeWin8_1nLater(PBYTE pbBuf, SIZE_T cbBuf)
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvWindowsUsermodeWin8_1nLater()
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatalEnvWindowsUsermodeWin8_1nLater(UINT32 fatalCode)
__INTRIN_INLINE void __cpuidex(int CPUInfo[4], int InfoType, int ECXValue)
Definition: intrin_x86.h:1680
__fastfail(FAST_FAIL_INVALID_ARG)
_Analysis_noreturn_ SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SymCryptFatalHang(UINT32 fatalCode)
Definition: libmain.c:101
UINT32 g_SymCryptFlags
Definition: libmain.c:18
VOID SYMCRYPT_CALL SymCryptInitEnvCommon(UINT32 version)
Definition: libmain.c:43
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _Analysis_noreturn_
Definition: no_sal2.h:392
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
BYTE * PBYTE
Definition: pedump.c:66
#define FAST_FAIL_CRYPTO_LIBRARY
Definition: sc_lib.h:58
#define SYMCRYPT_FLAG_LIB_INITIALIZED
Definition: sc_lib.h:22
VOID SYMCRYPT_CALL SymCryptDetectCpuFeaturesFromIsProcessorFeaturePresent(void)
VOID SYMCRYPT_CALL SymCryptDetectCpuFeaturesByCpuid(UINT32 flags)
#define SYMCRYPT_CPUID_DETECT_FLAG_CHECK_OS_SUPPORT_FOR_YMM
Definition: sc_lib.h:1025
#define SYMCRYPT_FORCE_WRITE32(_p, _v)
Definition: symcrypt.h:423
SYMCRYPT_ERROR
Definition: symcrypt.h:227
#define SYMCRYPT_CALL
UINT32 SYMCRYPT_CPU_FEATURES
SYMCRYPT_CPU_FEATURES g_SymCryptCpuFeaturesNotPresent
Definition: libmain.c:20
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint64_t ULONGLONG
Definition: typedefs.h:67
uint32_t UINT32
Definition: typedefs.h:59
WINBASEAPI DWORD64 WINAPI GetEnabledXStateFeatures()
#define XSTATE_MASK_AVX512
Definition: ketypes.h:1304
#define XSTATE_MASK_AVX
Definition: ketypes.h:1302