forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_windowsBootLib.c
182 lines (147 loc) · 4.58 KB
/
env_windowsBootLib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// env_windowsBootLib.c
// Platform-specific code for windows boot library environment.
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include <ntddk.h>
#include <windef.h>
#include "symcrypt.h"
#include "sc_lib.h"
//
// The BlStatusError function, part of the bootlib, is normally defined in blstatus.h
// We can't include that header file from outside the onecore codebase.
// We copied the definition here.
//
VOID
BlStatusError (
__in ULONG ErrorCode,
__in ULONG_PTR ErrorParameter1,
__in ULONG_PTR ErrorParameter2,
__in ULONG_PTR ErrorParameter3,
__in ULONG_PTR ErrorParameter4
);
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvWindowsBootlibrary()
{
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
//
// We disable AVX2 for X86 (including X86-64)
// This reduces codesize for bootmgr on PCAT which is codesize-constrained,
// and is simpler than creating a separate PCAT-bootlib SymCrypt environment.
//
return SYMCRYPT_CPU_FEATURE_AVX2;
#elif SYMCRYPT_CPU_ARM | SYMCRYPT_CPU_ARM64
return 0;
#endif
}
//
// Bootlib code calls the init multiple times, and it gets inlined too often.
//
SYMCRYPT_NOINLINE
VOID
SYMCRYPT_CALL
SymCryptInitEnvWindowsBootlibrary( UINT32 version )
{
if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED )
{
return;
}
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
SymCryptDetectCpuFeaturesByCpuid( SYMCRYPT_CPUID_DETECT_FLAG_CHECK_OS_SUPPORT_FOR_YMM );
//
// Our SaveXmm functions never fail because they don't do anything.
//
g_SymCryptCpuFeaturesNotPresent &= ~SYMCRYPT_CPU_FEATURE_SAVEXMM_NOFAIL;
#elif SYMCRYPT_CPU_ARM
// We run in a CPU mode that allows us to read the configuration registers
SymCryptDetectCpuFeaturesFromRegisters();
#elif SYMCRYPT_CPU_ARM64
// We run in a CPU mode that allows us to read the configuration registers
SymCryptDetectCpuFeaturesFromRegistersNoTry();
#endif
SymCryptInitEnvCommon( version );
}
_Analysis_noreturn_
VOID
SYMCRYPT_CALL
SymCryptFatalEnvWindowsBootlibrary( UINT32 fatalCode )
{
UINT32 fatalCodeVar;
SymCryptFatalIntercept( fatalCode );
//
// Put the fatal code in a location where it shows up in the dump
//
SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode );
//
// First we try to report the error using the Boot library infrastructure
//
BlStatusError ( fatalCode, 0, 0, 0, 0 );
//
// Then try a breakpoint; maybe that will work
//
__debugbreak();
SymCryptFatalHang( fatalCode );
}
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveXmmEnvWindowsBootlibrary( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
//
// In Bootlibrary there is no need to save XMM registers.
// The compiler should inline this function and optimize it away.
//
UNREFERENCED_PARAMETER( pSaveArea );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreXmmEnvWindowsBootlibrary( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
//
// In Bootlibrary there is no need to save XMM registers.
// The compiler should inline this function and optimize it away.
//
UNREFERENCED_PARAMETER( pSaveArea );
}
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveYmmEnvWindowsBootlibrary( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
//
// In Bootlibrary there is no need to save XMM registers.
// The compiler should inline this function and optimize it away.
//
UNREFERENCED_PARAMETER( pSaveArea );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreYmmEnvWindowsBootlibrary( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
//
// In Bootlibrary there is no need to save XMM registers.
// The compiler should inline this function and optimize it away.
//
UNREFERENCED_PARAMETER( pSaveArea );
}
#endif
VOID
SYMCRYPT_CALL
SymCryptTestInjectErrorEnvWindowsBootlibrary( PBYTE pbBuf, SIZE_T cbBuf )
{
//
// This feature is only used during testing. In production it is always
// an empty function that the compiler can optimize away.
//
UNREFERENCED_PARAMETER( pbBuf );
UNREFERENCED_PARAMETER( cbBuf );
}
#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86
VOID
SYMCRYPT_CALL
SymCryptCpuidExFuncEnvWindowsBootlibrary( int cpuInfo[4], int function_id, int subfunction_id )
{
__cpuidex( cpuInfo, function_id, subfunction_id );
}
#endif