forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_posixUserMode.c
142 lines (111 loc) · 3.5 KB
/
env_posixUserMode.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
//
// env_posixUserMode.c
// Platform-specific code for POSIX-compatible systems (Linux, macOS, other Unix-likes)
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvPosixUsermode(void)
{
return 0;
}
VOID
SYMCRYPT_CALL
SymCryptInitEnvPosixUsermode( 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 function never fails because it doesn't have to do anything in User mode.
//
g_SymCryptCpuFeaturesNotPresent &= ~SYMCRYPT_CPU_FEATURE_SAVEXMM_NOFAIL;
#elif SYMCRYPT_CPU_ARM
g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~SYMCRYPT_CPU_FEATURE_NEON;
#elif SYMCRYPT_CPU_ARM64
SymCryptDetectCpuFeaturesFromIsProcessorFeaturePresent();
#endif
SymCryptInitEnvCommon( version );
}
// UGLY HACK: Forward declare __stack_chk_fail introduced by -fstack-protector-strong
// For OpenEnclave binaries we cannot have any PLT entries, but clang ignores -fno-plt for
// __stack_chk_fail.
// Opened issue against clang here: https://github.com/llvm/llvm-project/issues/54816
// If we introduce a direct reference to it in our code then clang does figure out it must be linked
// without PLT
void __stack_chk_fail(void);
// On X86, __stack_chk_fail_local is used as a wrapper for __stack_chk_fail. The compiler should
// generate it for us, but for some reason it is not doing so on gcc 9.4.0.
void __stack_chk_fail_local(void)
{
__stack_chk_fail();
}
_Analysis_noreturn_
VOID
SYMCRYPT_CALL
SymCryptFatalEnvPosixUsermode( ULONG fatalCode )
{
UINT32 fatalCodeVar;
SymCryptFatalIntercept( fatalCode );
//
// Put the fatal code in a location where it shows up in the dump
//
SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode );
//
// Create an AV, which can trigger a core dump so that we get to
// see what is going wrong.
//
SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );
SymCryptFatalHang( fatalCode );
// Never reached - call is to force clang not to use PLT entry for this function
// See forward declaration above
__stack_chk_fail();
}
#if SYMCRYPT_CPU_AMD64
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveXmmEnvPosixUsermode( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
{
UNREFERENCED_PARAMETER( pSaveData );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreXmmEnvPosixUsermode( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
{
UNREFERENCED_PARAMETER( pSaveData );
}
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveYmmEnvPosixUsermode( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
{
UNREFERENCED_PARAMETER( pSaveData );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreYmmEnvPosixUsermode( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
{
UNREFERENCED_PARAMETER( pSaveData );
}
VOID
SYMCRYPT_CALL
SymCryptCpuidExFuncEnvPosixUsermode( int cpuInfo[4], int function_id, int subfunction_id )
{
__cpuidex( cpuInfo, function_id, subfunction_id );
}
#endif
VOID
SYMCRYPT_CALL
SymCryptTestInjectErrorEnvPosixUsermode( 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 );
}