From 000c98745e0131fa5e5cf0de680d21b9962a36b9 Mon Sep 17 00:00:00 2001 From: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com> Date: Wed, 8 Jan 2025 02:38:49 +1100 Subject: [PATCH] [vioscsi] DriverEntry() improved tracing 1. Show the RegistryPath. 2. Show the CrashDump Mode. 3. Show StorPortInitialize() return value (including LONG). 4. Show NTDDI_VERSION. 5. Split NTDDI_ definitions to new file ntddi_ver.h and addedd missing NTDDI definitions 6. Removed references to obsoleted RUN_MIN_CHECKED definition (PR #1228). Signed-off-by: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com> --- vioscsi/ntddi_ver.h | 68 +++++++++++++++++++++++++++++++ vioscsi/vioscsi.c | 97 ++++++++++++++++++++++++++++++++++++++++++--- vioscsi/vioscsi.h | 5 +-- 3 files changed, 160 insertions(+), 10 deletions(-) create mode 100755 vioscsi/ntddi_ver.h diff --git a/vioscsi/ntddi_ver.h b/vioscsi/ntddi_ver.h new file mode 100755 index 000000000..0c8edfca4 --- /dev/null +++ b/vioscsi/ntddi_ver.h @@ -0,0 +1,68 @@ +/* + * This file contains NTDDI_ globals + * + * Copyright (c) 2012-2024 Red Hat, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met : + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and / or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of their contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef ___NTDDIVER_H__ +#define ___NTDDIVER_H__ + +//#include + +// The following are additional definitions not found in current EWDK(s) +// at \Program Files\Windows Kits\10\Include\10.0..0\shared\sdkddkver.h + +#ifndef NTDDI_WINTHRESHOLD +#define NTDDI_WINTHRESHOLD 0x0A000000 /* ABRACADABRA_THRESHOLD */ +#endif + +#define NTDDI_THRESHOLD NTDDI_WINTHRESHOLD + +#ifndef NTDDI_WIN10_NI +#define NTDDI_WIN10_NI 0x0A00000C // Windows 10.0.22449-22631 / Nickel / 22H2 +#define NTDDI_WIN10_CU 0x0A00000D // Windows 10.0.25057-25236 / Copper / 23H1 +#endif + +#ifndef NTDDI_WIN11 +#define NTDDI_WIN11 NTDDI_WIN10_CO +#define NTDDI_WIN11_CO NTDDI_WIN10_CO // Windows 10.0.21277-22000 / Cobalt / 21H2 +#define NTDDI_WIN11_NI NTDDI_WIN10_NI // Windows 10.0.22449-22631 / Nickel / 22H2 +#define NTDDI_WIN11_CU NTDDI_WIN10_CU // Windows 10.0.25057-25236 / Copper / 23H1 +#endif + +#ifndef NTDDI_WIN11_ZN +#define NTDDI_WIN11_ZN 0x0A00000E // Windows 10.0.25246-25398 / Zinc / 23H2 +#define NTDDI_WIN11_GA 0x0A00000F // Windows 10.0.25905-25941 / Gallium / 24H1 +#define NTDDI_WIN11_GE 0x0A000010 // Windows 10.0.25947-26100 / Germanium / 24H2 +#endif + +#ifndef NTDDI_WIN11_DT +#define NTDDI_WIN11_DT 0x0A000011 // Windows 10.0.27686-27691 / Dilithium / 25H1 +#define NTDDI_WIN11_SE 0x0A000012 // Windows 10.0.27764 / Selenium / 25H2 +#endif + + +#endif ___NTDDIVER_H__ diff --git a/vioscsi/vioscsi.c b/vioscsi/vioscsi.c index 14f0d41d3..574c09dca 100755 --- a/vioscsi/vioscsi.c +++ b/vioscsi/vioscsi.c @@ -350,6 +350,8 @@ DriverEntry( HW_INITIALIZATION_DATA hwInitData; ULONG initResult; + ANSI_STRING aRegistryPath; + NTSTATUS u2a_status; #ifdef EVENT_TRACING STORAGE_TRACE_INIT_INFO initInfo; @@ -358,10 +360,20 @@ DriverEntry( InitializeDebugPrints((PDRIVER_OBJECT)DriverObject, (PUNICODE_STRING)RegistryPath); IsCrashDumpMode = FALSE; - RhelDbgPrint(TRACE_LEVEL_FATAL, " Vioscsi driver started...built on %s %s\n", __DATE__, __TIME__); + #if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, " VIOSCSI driver started...built on %s %s\n", __DATE__, __TIME__); + memset(&aRegistryPath, 0, sizeof(aRegistryPath)); + u2a_status = RtlUnicodeStringToAnsiString(&aRegistryPath, RegistryPath, TRUE); + if (u2a_status == STATUS_SUCCESS) { + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " RegistryPath : %s \n", aRegistryPath.Buffer); + RtlFreeAnsiString(&aRegistryPath); + } + #endif if (RegistryPath == NULL) { IsCrashDumpMode = TRUE; + #if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Crash dump mode\n"); + #endif } RtlZeroMemory(&hwInitData, sizeof(HW_INITIALIZATION_DATA)); @@ -394,7 +406,7 @@ DriverEntry( hwInitData.NumberOfAccessRanges = PCI_TYPE0_ADDRESSES; hwInitData.MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS; - hwInitData.SrbTypeFlags = SRB_TYPE_FLAG_STORAGE_REQUEST_BLOCK; + hwInitData.SrbTypeFlags = SRB_TYPE_FLAG_STORAGE_REQUEST_BLOCK; hwInitData.AddressTypeFlags = ADDRESS_TYPE_FLAG_BTL8; initResult = StorPortInitialize(DriverObject, @@ -419,11 +431,84 @@ DriverEntry( } #endif - RhelDbgPrint(TRACE_LEVEL_VERBOSE, - " Initialize returned 0x%x\n", initResult); - + #if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_NONE, " VIOSCSI driver starting..."); + RhelDbgPrint(TRACE_LEVEL_NONE, " Built on %s at %s \n", __DATE__, __TIME__); + memset(&aRegistryPath, 0, sizeof(aRegistryPath)); + u2a_status = RtlUnicodeStringToAnsiString(&aRegistryPath, RegistryPath, TRUE); + if (u2a_status == STATUS_SUCCESS) { + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " RegistryPath : %s \n", aRegistryPath.Buffer); + RtlFreeAnsiString(&aRegistryPath); + } + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Crash dump mode : %s \n", (IsCrashDumpMode) ? "ACTIVATED" : "NOT ACTIVATED"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " StorPortInitialize() returned : 0x%x (%lu) \n", initResult, initResult); + #endif + + #if !defined(RUN_UNCHECKED) + switch (NTDDI_VERSION) { + case NTDDI_WIN10: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : THRESHOLD | Windows 10.0.10240 | 1507 | Threshold 1 \n"); + break; + case NTDDI_WIN10_TH2: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_TH2 | Windows 10.0.10586 | 1511 | Threshold 2 \n"); + break; + case NTDDI_WIN10_RS1: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_RS1 | Windows 10.0.14393 | 1607 | Redstone 1 \n"); + break; + case NTDDI_WIN10_RS2: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_RS2 | Windows 10.0.15063 | 1703 | Redstone 2 \n"); + break; + case NTDDI_WIN10_RS3: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_RS3 | Windows 10.0.16299 | 1709 | Redstone 3 \n"); + break; + case NTDDI_WIN10_RS4: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_RS4 | Windows 10.0.17134 | 1803 | Redstone 4 \n"); + break; + case NTDDI_WIN10_RS5: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_RS5 | Windows 10.0.17763 | 1809 | Redstone 5 \n"); + break; + case NTDDI_WIN10_19H1: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_19H1 | Windows 10.0.18362 | 19H1 | Titanium \n"); + break; + case NTDDI_WIN10_VB: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_VB | Windows 10.0.19041 | 2004 | Vibranium \n"); + break; + case NTDDI_WIN10_MN: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_MN | Windows 10.0.19042 | 20H2 | Manganese \n"); + break; + case NTDDI_WIN10_FE: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_FE | Windows 10.0.19043 | 21H1 | Iron \n"); + break; + case NTDDI_WIN10_CO: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_CO | Windows 10.0.19044-22000 | 21H2 | Cobalt \n"); + break; + case NTDDI_WIN10_NI: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_NI | Windows 10.0.22449-22631 | 22H2 | Nickel \n"); + break; + case NTDDI_WIN10_CU: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN10_CU | Windows 10.0.25057-25236 | 23H1 | Copper \n"); + break; + case NTDDI_WIN11_ZN: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN11_ZN | Windows 10.0.25246-25398 | 23H2 | Zinc \n"); + break; + case NTDDI_WIN11_GA: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN11_GA | Windows 10.0.25905-25941 | 24H1 | Gallium \n"); + break; + case NTDDI_WIN11_GE: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN11_GE | Windows 10.0.25947-26100 | 24H2 | Germanium \n"); + break; + case NTDDI_WIN11_DT: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN11_DT | Windows 10.0.27686-27691 | 25H1 | Dilithium \n"); + break; + case NTDDI_WIN11_SE: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : WIN11_SE | Windows 10.0.27764 | 25H2 | Selenium \n"); + break; + default: + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " NTDDI_VERSION : 0x%x \n", (NTDDI_VERSION)); + break; + } + #endif return initResult; - } ULONG diff --git a/vioscsi/vioscsi.h b/vioscsi/vioscsi.h index ea995fd5e..c143a38cc 100755 --- a/vioscsi/vioscsi.h +++ b/vioscsi/vioscsi.h @@ -36,6 +36,7 @@ #include "scsiwmi.h" #include "osdep.h" +#include "ntddi_ver.h" #include "virtio_pci.h" #include "virtio.h" #include "virtio_ring.h" @@ -45,10 +46,6 @@ typedef struct VirtIOBufferDescriptor VIO_SG, *PVIO_SG; #define VIRTIO_SCSI_CDB_SIZE 32 #define VIRTIO_SCSI_SENSE_SIZE 96 -#ifndef NTDDI_WINTHRESHOLD -#define NTDDI_WINTHRESHOLD 0x0A000000 /* ABRACADABRA_THRESHOLD */ -#endif - #define PHYS_SEGMENTS 32 #define MAX_PHYS_SEGMENTS 512 #define VIOSCSI_POOL_TAG 'SoiV'