Path: blob/master/libs/symcrypt/lib/env_windowsUserModeWin8_1.c
15010 views
//1// env_windowsUserMode.c2// Platform-specific code for windows user mode.3//4// Copyright (c) Microsoft Corporation. Licensed under the MIT license.5//67//#include "precomp.h"89#pragma warning(push)10#pragma warning(disable: 5103) // Arm64's wdm.h included below currently generate a lot of 5103 warnings11#include <windows.h>12#pragma warning(pop)13#include "symcrypt.h"14#include "sc_lib.h"1516SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvWindowsUsermodeWin8_1nLater()17{18return 0;19}2021VOID22SYMCRYPT_CALL23SymCryptInitEnvWindowsUsermodeWin8_1nLater( UINT32 version )24{25if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED )26{27return;28}2930#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD6431//32// First we detect what the CPU has33//34SymCryptDetectCpuFeaturesByCpuid( SYMCRYPT_CPUID_DETECT_FLAG_CHECK_OS_SUPPORT_FOR_YMM );3536//37// We also need to be sure that the OS supports the extended registers.38//39{40ULONGLONG FeatureMask = GetEnabledXStateFeatures();4142if( !(FeatureMask & XSTATE_MASK_AVX) )43{44g_SymCryptCpuFeaturesNotPresent |= SYMCRYPT_CPU_FEATURE_AVX2;45}4647if( !(FeatureMask & XSTATE_MASK_AVX512) )48{49g_SymCryptCpuFeaturesNotPresent |= SYMCRYPT_CPU_FEATURE_AVX512;50}51}5253//54// Our SaveXmm function never fails because it doesn't have to do anything in User mode.55//56g_SymCryptCpuFeaturesNotPresent &= ~SYMCRYPT_CPU_FEATURE_SAVEXMM_NOFAIL;5758#elif SYMCRYPT_CPU_ARM5960g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~SYMCRYPT_CPU_FEATURE_NEON;6162#elif SYMCRYPT_CPU_ARM646364SymCryptDetectCpuFeaturesFromIsProcessorFeaturePresent();6566#endif6768SymCryptInitEnvCommon( version );69}7071_Analysis_noreturn_72VOID73SYMCRYPT_CALL74SymCryptFatalEnvWindowsUsermodeWin8_1nLater( UINT32 fatalCode )75{76UINT32 fatalCodeVar;7778SymCryptFatalIntercept( fatalCode );7980//81// Put the fatal code in a location where it shows up in the dump82//83SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode );8485//86// Our first preference is to fastfail,87// the second to create an AV, which triggers a Watson report so that we get to88// see what is going wrong.89//90__fastfail( FAST_FAIL_CRYPTO_LIBRARY );9192//93// Next we write to the NULL pointer, this causes an AV94//95SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );9697//98// If that fails, we terminate the process. (This function call also ensures that this environment is actually99// used in user mode and not some other environment.)100// (During testing we had the TerminateProcess as the first option, but that makes debugging very hard as101// it leaves no traces of what went wrong.)102//103TerminateProcess( GetCurrentProcess(), fatalCode );104105SymCryptFatalHang( fatalCode );106}107108#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86109110SYMCRYPT_ERROR111SYMCRYPT_CALL112SymCryptSaveXmmEnvWindowsUsermodeWin8_1nLater( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )113{114//115// In usermode there is no need to save XMM registers.116// The compiler should inline this function and optimize it away.117//118119UNREFERENCED_PARAMETER( pSaveArea );120121return SYMCRYPT_NO_ERROR;122}123124VOID125SYMCRYPT_CALL126SymCryptRestoreXmmEnvWindowsUsermodeWin8_1nLater( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )127{128//129// In usermode there is no need to save XMM registers.130// The compiler should inline this function and optimize it away.131//132133UNREFERENCED_PARAMETER( pSaveArea );134}135136137SYMCRYPT_ERROR138SYMCRYPT_CALL139SymCryptSaveYmmEnvWindowsUsermodeWin8_1nLater( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )140{141//142// In usermode there is no need to save XMM registers.143// The compiler should inline this function and optimize it away.144//145146UNREFERENCED_PARAMETER( pSaveArea );147148return SYMCRYPT_NO_ERROR;149}150151VOID152SYMCRYPT_CALL153SymCryptRestoreYmmEnvWindowsUsermodeWin8_1nLater( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )154{155//156// In usermode there is no need to save XMM registers.157// The compiler should inline this function and optimize it away.158//159160UNREFERENCED_PARAMETER( pSaveArea );161}162163#endif164165VOID166SYMCRYPT_CALL167SymCryptTestInjectErrorEnvWindowsUsermodeWin8_1nLater( PBYTE pbBuf, SIZE_T cbBuf )168{169//170// This feature is only used during testing. In production it is always171// an empty function that the compiler can optimize away.172//173UNREFERENCED_PARAMETER( pbBuf );174UNREFERENCED_PARAMETER( cbBuf );175}176177#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86178179VOID180SYMCRYPT_CALL181SymCryptCpuidExFuncEnvWindowsUsermodeWin8_1nLater( int cpuInfo[4], int function_id, int subfunction_id )182{183__cpuidex( cpuInfo, function_id, subfunction_id );184}185186#endif187188189