Windows Driver: Use system functions directly instead of dynamic loading since we are targeting Windows 10

This commit is contained in:
Mounir IDRASSI 2024-11-17 21:37:16 +01:00
parent 42fdbcf3ce
commit 93868acfdd
No known key found for this signature in database
GPG Key ID: FC1B00364B3FE937
6 changed files with 53 additions and 223 deletions

View File

@ -91,7 +91,7 @@ void hmac_sha256
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the key is longer than the hash algorithm block size, /* If the key is longer than the hash algorithm block size,
let key = sha256(key), as per HMAC specifications. */ let key = sha256(key), as per HMAC specifications. */
@ -136,7 +136,7 @@ void hmac_sha256
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent leaks */ /* Prevent leaks */
@ -208,7 +208,7 @@ void derive_key_sha256 (const unsigned char *pwd, int pwd_len, const unsigned ch
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the password is longer than the hash algorithm block size, /* If the password is longer than the hash algorithm block size,
let pwd = sha256(pwd), as per HMAC specifications. */ let pwd = sha256(pwd), as per HMAC specifications. */
@ -275,7 +275,7 @@ void derive_key_sha256 (const unsigned char *pwd, int pwd_len, const unsigned ch
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent possible leaks. */ /* Prevent possible leaks. */
@ -341,7 +341,7 @@ void hmac_sha512
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the key is longer than the hash algorithm block size, /* If the key is longer than the hash algorithm block size,
@ -387,7 +387,7 @@ void hmac_sha512
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent leaks */ /* Prevent leaks */
@ -433,7 +433,7 @@ void derive_key_sha512 (const unsigned char *pwd, int pwd_len, const unsigned ch
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the password is longer than the hash algorithm block size, /* If the password is longer than the hash algorithm block size,
@ -500,7 +500,7 @@ void derive_key_sha512 (const unsigned char *pwd, int pwd_len, const unsigned ch
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent possible leaks. */ /* Prevent possible leaks. */
@ -565,7 +565,7 @@ void hmac_blake2s
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the key is longer than the hash algorithm block size, /* If the key is longer than the hash algorithm block size,
let key = blake2s(key), as per HMAC specifications. */ let key = blake2s(key), as per HMAC specifications. */
@ -610,7 +610,7 @@ void hmac_blake2s
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent leaks */ /* Prevent leaks */
@ -682,7 +682,7 @@ void derive_key_blake2s (const unsigned char *pwd, int pwd_len, const unsigned c
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
/* If the password is longer than the hash algorithm block size, /* If the password is longer than the hash algorithm block size,
let pwd = blake2s(pwd), as per HMAC specifications. */ let pwd = blake2s(pwd), as per HMAC specifications. */
@ -749,7 +749,7 @@ void derive_key_blake2s (const unsigned char *pwd, int pwd_len, const unsigned c
#if defined (DEVICE_DRIVER) && !defined(_M_ARM64) #if defined (DEVICE_DRIVER) && !defined(_M_ARM64)
if (NT_SUCCESS (saveStatus)) if (NT_SUCCESS (saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
/* Prevent possible leaks. */ /* Prevent possible leaks. */

View File

@ -286,53 +286,6 @@ typedef unsigned char BOOLEAN;
#define FALSE !TRUE #define FALSE !TRUE
#endif #endif
typedef NTSTATUS (NTAPI *KeSaveExtendedProcessorStateFn) (
__in ULONG64 Mask,
PXSTATE_SAVE XStateSave
);
typedef VOID (NTAPI *KeRestoreExtendedProcessorStateFn) (
PXSTATE_SAVE XStateSave
);
typedef NTSTATUS (NTAPI *ExGetFirmwareEnvironmentVariableFn) (
PUNICODE_STRING VariableName,
LPGUID VendorGuid,
PVOID Value,
PULONG ValueLength,
PULONG Attributes
);
typedef ULONG64 (NTAPI *KeQueryInterruptTimePreciseFn)(
PULONG64 QpcTimeStamp
);
typedef BOOLEAN (NTAPI *KeAreAllApcsDisabledFn) ();
typedef void (NTAPI *KeSetSystemGroupAffinityThreadFn)(
PGROUP_AFFINITY Affinity,
PGROUP_AFFINITY PreviousAffinity
);
typedef USHORT (NTAPI *KeQueryActiveGroupCountFn)();
typedef ULONG (NTAPI *KeQueryActiveProcessorCountExFn)(
USHORT GroupNumber
);
extern NTSTATUS NTAPI KeSaveExtendedProcessorStateVC (
__in ULONG64 Mask,
PXSTATE_SAVE XStateSave
);
extern VOID NTAPI KeRestoreExtendedProcessorStateVC (
PXSTATE_SAVE XStateSave
);
extern BOOLEAN VC_KeAreAllApcsDisabled (VOID);
#else /* !TC_WINDOWS_DRIVER */ #else /* !TC_WINDOWS_DRIVER */
#if !defined(_UEFI) #if !defined(_UEFI)

View File

@ -1100,7 +1100,7 @@ void camellia_encrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uin
{ {
#if defined (TC_WINDOWS_DRIVER) #if defined (TC_WINDOWS_DRIVER)
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (NT_SUCCESS (KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState))) if (NT_SUCCESS (KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState)))
{ {
#endif #endif
while (blockCount >= 16) while (blockCount >= 16)
@ -1111,7 +1111,7 @@ void camellia_encrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uin
blockCount -= 16; blockCount -= 16;
} }
#if defined (TC_WINDOWS_DRIVER) #if defined (TC_WINDOWS_DRIVER)
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
} }
#endif #endif
} }
@ -1136,7 +1136,7 @@ void camellia_decrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uin
{ {
#if defined (TC_WINDOWS_DRIVER) #if defined (TC_WINDOWS_DRIVER)
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (NT_SUCCESS (KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState))) if (NT_SUCCESS (KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState)))
{ {
#endif #endif
while (blockCount >= 16) while (blockCount >= 16)
@ -1147,7 +1147,7 @@ void camellia_decrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uin
blockCount -= 16; blockCount -= 16;
} }
#if defined (TC_WINDOWS_DRIVER) #if defined (TC_WINDOWS_DRIVER)
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
} }
#endif #endif
} }

View File

@ -363,7 +363,7 @@ static void ComputeBootLoaderFingerprint(PDEVICE_OBJECT LowerDeviceObject, uint8
NTSTATUS saveStatus = STATUS_INVALID_PARAMETER; NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
XSTATE_SAVE SaveState; XSTATE_SAVE SaveState;
if (IsCpuIntel() && HasSAVX()) if (IsCpuIntel() && HasSAVX())
saveStatus = KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState); saveStatus = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
#endif #endif
WHIRLPOOL_add (ioBuffer, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &whirlpool); WHIRLPOOL_add (ioBuffer, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &whirlpool);
WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &whirlpool); WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &whirlpool);
@ -401,7 +401,7 @@ static void ComputeBootLoaderFingerprint(PDEVICE_OBJECT LowerDeviceObject, uint8
#ifndef _M_ARM64 #ifndef _M_ARM64
if (NT_SUCCESS(saveStatus)) if (NT_SUCCESS(saveStatus))
KeRestoreExtendedProcessorStateVC(&SaveState); KeRestoreExtendedProcessorState(&SaveState);
#endif #endif
} }
else else
@ -978,7 +978,6 @@ static NTSTATUS DispatchPower (PDEVICE_OBJECT DeviceObject, PIRP Irp, DriveFilte
// Dismount the system drive on shutdown on Windows 7 and later // Dismount the system drive on shutdown on Windows 7 and later
if (DriverShuttingDown if (DriverShuttingDown
&& EraseKeysOnShutdown && EraseKeysOnShutdown
&& IsOSAtLeast (WIN_7)
&& Extension->BootDrive && Extension->BootDrive
&& Extension->DriveMounted && Extension->DriveMounted
&& irpSp->MinorFunction == IRP_MN_SET_POWER && irpSp->MinorFunction == IRP_MN_SET_POWER

View File

@ -142,14 +142,6 @@ static BOOL PagingFileCreationPrevented = FALSE;
static BOOL EnableExtendedIoctlSupport = FALSE; static BOOL EnableExtendedIoctlSupport = FALSE;
static BOOL AllowTrimCommand = FALSE; static BOOL AllowTrimCommand = FALSE;
static BOOL RamEncryptionActivated = FALSE; static BOOL RamEncryptionActivated = FALSE;
static KeSaveExtendedProcessorStateFn KeSaveExtendedProcessorStatePtr = NULL;
static KeRestoreExtendedProcessorStateFn KeRestoreExtendedProcessorStatePtr = NULL;
static ExGetFirmwareEnvironmentVariableFn ExGetFirmwareEnvironmentVariablePtr = NULL;
static KeQueryInterruptTimePreciseFn KeQueryInterruptTimePrecisePtr = NULL;
static KeAreAllApcsDisabledFn KeAreAllApcsDisabledPtr = NULL;
static KeSetSystemGroupAffinityThreadFn KeSetSystemGroupAffinityThreadPtr = NULL;
static KeQueryActiveGroupCountFn KeQueryActiveGroupCountPtr = NULL;
static KeQueryActiveProcessorCountExFn KeQueryActiveProcessorCountExPtr = NULL;
int EncryptionIoRequestCount = 0; int EncryptionIoRequestCount = 0;
int EncryptionItemCount = 0; int EncryptionItemCount = 0;
int EncryptionFragmentSize = 0; int EncryptionFragmentSize = 0;
@ -187,22 +179,15 @@ BOOL IsUefiBoot ()
Dump ("IsUefiBoot BEGIN\n"); Dump ("IsUefiBoot BEGIN\n");
ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL); ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
if (ExGetFirmwareEnvironmentVariablePtr) ULONG valueLengh = 0;
{ UNICODE_STRING emptyName;
ULONG valueLengh = 0; GUID guid;
UNICODE_STRING emptyName; RtlInitUnicodeString(&emptyName, L"");
GUID guid; memset (&guid, 0, sizeof(guid));
RtlInitUnicodeString(&emptyName, L""); Dump ("IsUefiBoot calling ExGetFirmwareEnvironmentVariable\n");
memset (&guid, 0, sizeof(guid)); ntStatus = ExGetFirmwareEnvironmentVariable (&emptyName, &guid, NULL, &valueLengh, NULL);
Dump ("IsUefiBoot calling ExGetFirmwareEnvironmentVariable\n"); Dump ("IsUefiBoot ExGetFirmwareEnvironmentVariable returned 0x%08x\n", ntStatus);
ntStatus = ExGetFirmwareEnvironmentVariablePtr (&emptyName, &guid, NULL, &valueLengh, NULL);
Dump ("IsUefiBoot ExGetFirmwareEnvironmentVariable returned 0x%08x\n", ntStatus);
}
else
{
Dump ("IsUefiBoot ExGetFirmwareEnvironmentVariable not found on the system\n");
}
if (STATUS_NOT_IMPLEMENTED != ntStatus) if (STATUS_NOT_IMPLEMENTED != ntStatus)
bStatus = TRUE; bStatus = TRUE;
@ -229,17 +214,10 @@ void GetDriverRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed)
iSeed = KeQueryPerformanceCounter (&iSeed2); iSeed = KeQueryPerformanceCounter (&iSeed2);
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx); WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx); WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
if (KeQueryInterruptTimePrecisePtr)
{ iSeed.QuadPart = KeQueryInterruptTimePrecise ((PULONG64) & iSeed2.QuadPart);
iSeed.QuadPart = KeQueryInterruptTimePrecisePtr ((PULONG64) & iSeed2.QuadPart); WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx); WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
}
else
{
iSeed.QuadPart = KeQueryInterruptTime ();
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
}
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */ /* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
if (0 == jent_entropy_init ()) if (0 == jent_entropy_init ())
@ -293,48 +271,6 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Dump("OsMajorVersion=%d OsMinorVersion=%d\n", OsMajorVersion, OsMinorVersion); Dump("OsMajorVersion=%d OsMinorVersion=%d\n", OsMajorVersion, OsMinorVersion);
// KeAreAllApcsDisabled is available starting from Windows Server 2003
if ((OsMajorVersion > 5) || (OsMajorVersion == 5 && OsMinorVersion >= 2))
{
UNICODE_STRING KeAreAllApcsDisabledFuncName;
RtlInitUnicodeString(&KeAreAllApcsDisabledFuncName, L"KeAreAllApcsDisabled");
KeAreAllApcsDisabledPtr = (KeAreAllApcsDisabledFn)MmGetSystemRoutineAddress(&KeAreAllApcsDisabledFuncName);
}
// KeSaveExtendedProcessorState/KeRestoreExtendedProcessorState are available starting from Windows 7
// KeQueryActiveGroupCount/KeQueryActiveProcessorCountEx/KeSetSystemGroupAffinityThread are available starting from Windows 7
if ((OsMajorVersion > 6) || (OsMajorVersion == 6 && OsMinorVersion >= 1))
{
UNICODE_STRING saveFuncName, restoreFuncName, groupCountFuncName, procCountFuncName, setAffinityFuncName;
RtlInitUnicodeString(&saveFuncName, L"KeSaveExtendedProcessorState");
RtlInitUnicodeString(&restoreFuncName, L"KeRestoreExtendedProcessorState");
RtlInitUnicodeString(&groupCountFuncName, L"KeQueryActiveGroupCount");
RtlInitUnicodeString(&procCountFuncName, L"KeQueryActiveProcessorCountEx");
RtlInitUnicodeString(&setAffinityFuncName, L"KeSetSystemGroupAffinityThread");
KeSaveExtendedProcessorStatePtr = (KeSaveExtendedProcessorStateFn)MmGetSystemRoutineAddress(&saveFuncName);
KeRestoreExtendedProcessorStatePtr = (KeRestoreExtendedProcessorStateFn)MmGetSystemRoutineAddress(&restoreFuncName);
KeSetSystemGroupAffinityThreadPtr = (KeSetSystemGroupAffinityThreadFn)MmGetSystemRoutineAddress(&setAffinityFuncName);
KeQueryActiveGroupCountPtr = (KeQueryActiveGroupCountFn)MmGetSystemRoutineAddress(&groupCountFuncName);
KeQueryActiveProcessorCountExPtr = (KeQueryActiveProcessorCountExFn)MmGetSystemRoutineAddress(&procCountFuncName);
}
// ExGetFirmwareEnvironmentVariable is available starting from Windows 8
if ((OsMajorVersion > 6) || (OsMajorVersion == 6 && OsMinorVersion >= 2))
{
UNICODE_STRING funcName;
RtlInitUnicodeString(&funcName, L"ExGetFirmwareEnvironmentVariable");
ExGetFirmwareEnvironmentVariablePtr = (ExGetFirmwareEnvironmentVariableFn)MmGetSystemRoutineAddress(&funcName);
}
// KeQueryInterruptTimePrecise is available starting from Windows 8.1
if ((OsMajorVersion > 6) || (OsMajorVersion == 6 && OsMinorVersion >= 3))
{
UNICODE_STRING funcName;
RtlInitUnicodeString(&funcName, L"KeQueryInterruptTimePrecise");
KeQueryInterruptTimePrecisePtr = (KeQueryInterruptTimePreciseFn)MmGetSystemRoutineAddress(&funcName);
}
// Load dump filter if the main driver is already loaded // Load dump filter if the main driver is already loaded
if (NT_SUCCESS(TCDeviceIoControl(NT_ROOT_PREFIX, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof(version)))) if (NT_SUCCESS(TCDeviceIoControl(NT_ROOT_PREFIX, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof(version))))
return DumpFilterEntry((PFILTER_EXTENSION)DriverObject, (PFILTER_INITIALIZATION_DATA)RegistryPath); return DumpFilterEntry((PFILTER_EXTENSION)DriverObject, (PFILTER_INITIALIZATION_DATA)RegistryPath);
@ -994,7 +930,7 @@ NTSTATUS ProcessVolumeDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION
case IOCTL_DISK_GET_DRIVE_GEOMETRY_EX: case IOCTL_DISK_GET_DRIVE_GEOMETRY_EX:
Dump ("ProcessVolumeDeviceControlIrp (IOCTL_DISK_GET_DRIVE_GEOMETRY_EX)\n"); Dump ("ProcessVolumeDeviceControlIrp (IOCTL_DISK_GET_DRIVE_GEOMETRY_EX)\n");
{ {
ULONG minOutputSize = IsOSAtLeast (WIN_SERVER_2003)? sizeof (DISK_GEOMETRY_EX) : sizeof (DISK_GEOMETRY) + sizeof (LARGE_INTEGER); ULONG minOutputSize = sizeof (DISK_GEOMETRY_EX);
ULONG fullOutputSize = sizeof (DISK_GEOMETRY) + sizeof (LARGE_INTEGER) + sizeof (DISK_PARTITION_INFO) + sizeof (DISK_DETECTION_INFO); ULONG fullOutputSize = sizeof (DISK_GEOMETRY) + sizeof (LARGE_INTEGER) + sizeof (DISK_PARTITION_INFO) + sizeof (DISK_DETECTION_INFO);
if (ValidateIOBufferSize (Irp, minOutputSize, ValidateOutput)) if (ValidateIOBufferSize (Irp, minOutputSize, ValidateOutput))
@ -3463,7 +3399,7 @@ NTSTATUS TCDeviceIoControl (PWSTR deviceName, ULONG IoControlCode, void *InputBu
KEVENT event; KEVENT event;
UNICODE_STRING name; UNICODE_STRING name;
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled()) if ((KeGetCurrentIrql() >= APC_LEVEL) || KeAreAllApcsDisabled())
{ {
TCDeviceIoControlWorkItemArgs args; TCDeviceIoControlWorkItemArgs args;
@ -3548,7 +3484,7 @@ NTSTATUS SendDeviceIoControlRequest (PDEVICE_OBJECT deviceObject, ULONG ioContro
PIRP irp; PIRP irp;
KEVENT event; KEVENT event;
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled()) if ((KeGetCurrentIrql() >= APC_LEVEL) || KeAreAllApcsDisabled())
{ {
SendDeviceIoControlRequestWorkItemArgs args; SendDeviceIoControlRequestWorkItemArgs args;
@ -3893,7 +3829,7 @@ static NTSTATUS UpdateFsVolumeInformation (MOUNT_STRUCT* mount, PEXTENSION NewEx
BOOL bIsNTFS = FALSE; BOOL bIsNTFS = FALSE;
ULONG labelMaxLen, labelEffectiveLen; ULONG labelMaxLen, labelEffectiveLen;
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled()) if ((KeGetCurrentIrql() >= APC_LEVEL) || KeAreAllApcsDisabled())
{ {
UpdateFsVolumeInformationWorkItemArgs args; UpdateFsVolumeInformationWorkItemArgs args;
@ -4160,7 +4096,7 @@ NTSTATUS UnmountDevice (UNMOUNT_STRUCT *unmountRequest, PDEVICE_OBJECT deviceObj
HANDLE volumeHandle; HANDLE volumeHandle;
PFILE_OBJECT volumeFileObject; PFILE_OBJECT volumeFileObject;
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled()) if ((KeGetCurrentIrql() >= APC_LEVEL) || KeAreAllApcsDisabled())
{ {
UnmountDeviceWorkItemArgs args; UnmountDeviceWorkItemArgs args;
@ -4190,7 +4126,7 @@ NTSTATUS UnmountDevice (UNMOUNT_STRUCT *unmountRequest, PDEVICE_OBJECT deviceObj
int dismountRetry; int dismountRetry;
// Dismounting a writable NTFS filesystem prevents the driver from being unloaded on Windows 7 // Dismounting a writable NTFS filesystem prevents the driver from being unloaded on Windows 7
if (IsOSAtLeast (WIN_7) && !extension->bReadOnly) if (!extension->bReadOnly)
{ {
NTFS_VOLUME_DATA_BUFFER ntfsData; NTFS_VOLUME_DATA_BUFFER ntfsData;
@ -4454,33 +4390,14 @@ NTSTATUS TCCompleteDiskIrp (PIRP irp, NTSTATUS status, ULONG_PTR information)
size_t GetCpuCount (WORD* pGroupCount) size_t GetCpuCount (WORD* pGroupCount)
{ {
size_t cpuCount = 0; size_t cpuCount = 0;
if (KeQueryActiveGroupCountPtr && KeQueryActiveProcessorCountExPtr) USHORT i, groupCount = KeQueryActiveGroupCount ();
for (i = 0; i < groupCount; i++)
{ {
USHORT i, groupCount = KeQueryActiveGroupCountPtr (); cpuCount += (size_t) KeQueryActiveProcessorCountEx (i);
for (i = 0; i < groupCount; i++)
{
cpuCount += (size_t) KeQueryActiveProcessorCountExPtr (i);
}
if (pGroupCount)
*pGroupCount = groupCount;
} }
else
{
KAFFINITY activeCpuMap = KeQueryActiveProcessors();
size_t mapSize = sizeof (activeCpuMap) * 8;
while (mapSize--) if (pGroupCount)
{ *pGroupCount = groupCount;
if (activeCpuMap & 1)
++cpuCount;
activeCpuMap >>= 1;
}
if (pGroupCount)
*pGroupCount = 1;
}
if (cpuCount == 0) if (cpuCount == 0)
return 1; return 1;
@ -4490,17 +4407,14 @@ size_t GetCpuCount (WORD* pGroupCount)
USHORT GetCpuGroup (size_t index) USHORT GetCpuGroup (size_t index)
{ {
if (KeQueryActiveGroupCountPtr && KeQueryActiveProcessorCountExPtr) USHORT i, groupCount = KeQueryActiveGroupCount ();
size_t cpuCount = 0;
for (i = 0; i < groupCount; i++)
{ {
USHORT i, groupCount = KeQueryActiveGroupCountPtr (); cpuCount += (size_t) KeQueryActiveProcessorCountEx (i);
size_t cpuCount = 0; if (cpuCount >= index)
for (i = 0; i < groupCount; i++)
{ {
cpuCount += (size_t) KeQueryActiveProcessorCountExPtr (i); return i;
if (cpuCount >= index)
{
return i;
}
} }
} }
@ -4509,13 +4423,10 @@ USHORT GetCpuGroup (size_t index)
void SetThreadCpuGroupAffinity (USHORT index) void SetThreadCpuGroupAffinity (USHORT index)
{ {
if (KeSetSystemGroupAffinityThreadPtr) GROUP_AFFINITY groupAffinity = {0};
{ groupAffinity.Mask = ~0ULL;
GROUP_AFFINITY groupAffinity = {0}; groupAffinity.Group = index;
groupAffinity.Mask = ~0ULL; KeSetSystemGroupAffinityThread (&groupAffinity, NULL);
groupAffinity.Group = index;
KeSetSystemGroupAffinityThreadPtr (&groupAffinity, NULL);
}
} }
void EnsureNullTerminatedString (wchar_t *str, size_t maxSizeInBytes) void EnsureNullTerminatedString (wchar_t *str, size_t maxSizeInBytes)
@ -4958,36 +4869,3 @@ BOOL IsOSAtLeast (OSVersionEnum reqMinOS)
return ((OsMajorVersion << 16 | OsMinorVersion << 8) return ((OsMajorVersion << 16 | OsMinorVersion << 8)
>= (major << 16 | minor << 8)); >= (major << 16 | minor << 8));
} }
NTSTATUS NTAPI KeSaveExtendedProcessorStateVC (
__in ULONG64 Mask,
PXSTATE_SAVE XStateSave
)
{
if (KeSaveExtendedProcessorStatePtr)
{
return (KeSaveExtendedProcessorStatePtr) (Mask, XStateSave);
}
else
{
return STATUS_SUCCESS;
}
}
VOID NTAPI KeRestoreExtendedProcessorStateVC (
PXSTATE_SAVE XStateSave
)
{
if (KeRestoreExtendedProcessorStatePtr)
{
(KeRestoreExtendedProcessorStatePtr) (XStateSave);
}
}
BOOLEAN VC_KeAreAllApcsDisabled (VOID)
{
if (KeAreAllApcsDisabledPtr)
return (KeAreAllApcsDisabledPtr) ();
else
return FALSE;
}

View File

@ -947,7 +947,7 @@ NTSTATUS TCSendHostDeviceIoControlRequestEx (PDEVICE_OBJECT DeviceObject,
UNREFERENCED_PARAMETER(DeviceObject); /* Remove compiler warning */ UNREFERENCED_PARAMETER(DeviceObject); /* Remove compiler warning */
if ((KeGetCurrentIrql() >= APC_LEVEL) || VC_KeAreAllApcsDisabled()) if ((KeGetCurrentIrql() >= APC_LEVEL) || KeAreAllApcsDisabled())
{ {
TCSendHostDeviceIoControlRequestExWorkItemArgs args; TCSendHostDeviceIoControlRequestExWorkItemArgs args;