Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/symcrypt/lib/env_windowsUserModeWin8_1.c
15010 views
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
17
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvWindowsUsermodeWin8_1nLater()
18
{
19
return 0;
20
}
21
22
VOID
23
SYMCRYPT_CALL
24
SymCryptInitEnvWindowsUsermodeWin8_1nLater( UINT32 version )
25
{
26
if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED )
27
{
28
return;
29
}
30
31
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
32
//
33
// First we detect what the CPU has
34
//
35
SymCryptDetectCpuFeaturesByCpuid( SYMCRYPT_CPUID_DETECT_FLAG_CHECK_OS_SUPPORT_FOR_YMM );
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
65
SymCryptDetectCpuFeaturesFromIsProcessorFeaturePresent();
66
67
#endif
68
69
SymCryptInitEnvCommon( version );
70
}
71
72
_Analysis_noreturn_
73
VOID
74
SYMCRYPT_CALL
75
SymCryptFatalEnvWindowsUsermodeWin8_1nLater( UINT32 fatalCode )
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
//
91
__fastfail( FAST_FAIL_CRYPTO_LIBRARY );
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
111
SYMCRYPT_ERROR
112
SYMCRYPT_CALL
113
SymCryptSaveXmmEnvWindowsUsermodeWin8_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
125
VOID
126
SYMCRYPT_CALL
127
SymCryptRestoreXmmEnvWindowsUsermodeWin8_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
138
SYMCRYPT_ERROR
139
SYMCRYPT_CALL
140
SymCryptSaveYmmEnvWindowsUsermodeWin8_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
152
VOID
153
SYMCRYPT_CALL
154
SymCryptRestoreYmmEnvWindowsUsermodeWin8_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
166
VOID
167
SYMCRYPT_CALL
168
SymCryptTestInjectErrorEnvWindowsUsermodeWin8_1nLater( PBYTE pbBuf, SIZE_T cbBuf )
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
180
VOID
181
SYMCRYPT_CALL
182
SymCryptCpuidExFuncEnvWindowsUsermodeWin8_1nLater( int cpuInfo[4], int function_id, int subfunction_id )
183
{
184
__cpuidex( cpuInfo, function_id, subfunction_id );
185
}
186
187
#endif
188
189