0
0

Add files

This commit is contained in:
Ayyuce Demirbas 2017-03-26 21:37:57 +03:00
parent 2431412fdb
commit 26b524b2d0
875 changed files with 898985 additions and 0 deletions

113
LICENSE.txt Normal file
View File

@ -0,0 +1,113 @@
Windows Research Kernel Source Code License
This license governs use of the accompanying software, and your use of
the software constitutes acceptance of this license. Your license rights
below are subject to the restrictions in the license, and are available
to you only so long as you remain eligible due to your affiliation with
an accredited educational institution. (For more details on eligibility
see http://www.microsoft.com/WindowsAcademic).
You may use and modify this software for any non-commercial purpose within
your educational institution, including making a reasonable number of copies.
Teaching, academic research, and personal experimentation are examples of
purposes which can be non-commercial. You may post copies on an internal
secure server, and it may be installed and used on personal machines of
eligible users.
You may distribute snippets of this software in research papers, books or
other teaching materials, or publish snippets of the software on websites
or on-line community forums that are intended for teaching and research.
The total amount of source code in each of your snippets should not
exceed 50 lines. If you wish to use a larger portion of the software,
please contact compsci@microsoft.com.
You may not use or distribute this software or any derivative works in
any form for commercial purposes. Examples of commercial purposes would
be running business operations, licensing, leasing, or selling the software,
or distributing the software for use with commercial products.
If you wish to commercialize your work related to the software or take
part in research with industrial partners, you need to contact
iplg@microsoft.com to enquire about a commercial license.
You may distribute the software and modifications to the software for
non-commercial purposes, but only to other eligible users of the
software (for example, to another university student or professor to
support joint academic research). You may not grant rights to the
software or derivative works that are broader than those provided
by this license. For example, you may not distribute modifications
of the software under terms that would permit commercial use, or under
terms that purport to require the software or derivative works to be
sublicensed to others.
You may use any information in intangible form that you remember after
accessing the software. However, this right does not grant you a license
to any of Microsoft's copyrights or patents for anything you might
create using such information.
In return for the license rights above, you must agree to these obligations:
1. You will not remove any copyright or other notices from the software,
nor reverse engineer or decompile binary portions of the software,
unless your laws give you the right to do so despite this restriction.
2. You will include a verbatim copy of this license if you distribute
the software in any form.
3. If you distribute derivative works of the software in source code
form you will do so only under this license, and if you distribute
derivative works of the software solely in object form you will do so
only under a license that complies with this license.
4. If you have modified the software or created derivative works,
and distribute such modifications or derivative works, you will cause
the modified files to carry prominent notices describing your changes
and the date of the changes, so that recipients know that they are not
receiving the original software.
5. Microsoft welcomes your comments and suggestions on the source code,
which you provide on a strictly voluntary basis. If you give Microsoft
comments and suggestions regarding bug fixes, enhancements or other
modifications to the source code, you agree that Microsoft may,
in connection with Microsoft products and services use, disclose or
otherwise commercialize your comments and suggestions entirely without
any obligation or restriction based on intellectual property rights or
otherwise. You will not give any comments or suggestions that you have
reason to believe are subject to any patent, copyright, or other
intellectual property claim or right of any third party.
6. THE SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS MEANS NO EXPRESS,
IMPLIED OR STATUTORY WARRANTY, INCLUDING WITHOUT LIMITATION, WARRANTIES
OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY WARRANTY
OF TITLE OR NON-INFRINGEMENT. YOU MUST PASS THIS DISCLAIMER ON WHENEVER
YOU DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
7. MICROSOFT WILL NOT BE LIABLE FOR ANY DAMAGES RELATED TO THE SOFTWARE
OR THIS LICENSE, INCLUDING DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL
OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT THE LAW PERMITS, NO MATTER
WHAT LEGAL THEORY IT IS BASED ON. YOU MUST PASS THIS LIMITATION OF
LIABILITY ON WHENEVER YOU DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
8. If you sue anyone over patents that you think may apply to the software
or anyone's use of the software, your license to the software ends
immediately.
9. You will not use the software to aid the development of any software
programs that are designed to:
(a) harm or intentionally interfere with the operation of a computer
system including any data or information stored on such computer
system; and/or
(b) surreptitiously gain or maintain high level access to a computer
system, self-propagate, and/or execute in a manner that prevents
detection, including but not limited to, so-called “rootkit”
software programs, viruses, or worms.
10. Your rights under the license end immediately if you breach it
in any way.
11. Microsoft reserves all rights not expressly granted to you in this
license.
License Version: 5 December 2008.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

13
README.txt Normal file
View File

@ -0,0 +1,13 @@
ATTENTION!
If you double-click on file WRKCopy.bat, Windows Research Kernel will be
installed in directory C:\WRK-v1.2\
If you want to use different installation settings, open console window
and run WRKCopy.bat with option /w WRK_destination_dir
For example:
>E:\Resources\Windows_Research_Kernel\Get_WRK\WRKCopy /w C:\TMP\MyWRK
Alternatively, just drag-and-drop the folder WRK-v1.2 (or its contents)
to the destination directory of your choice.

12
WRK-v1.2/Build.bat Normal file
View File

@ -0,0 +1,12 @@
@ECHO OFF
IF [%2] EQU [] goto setenv
set path=%2\tools\%1;%path%
set wrkarch=%1
goto dothejob
:setenv
call WRKEnv.bat %1
:dothejob
cd base\ntos\
nmake -nologo %wrkarch%=
cd ..\..

11
WRK-v1.2/Clean.bat Normal file
View File

@ -0,0 +1,11 @@
IF [%2] EQU [] goto setenv
set path=%2\tools\%1;%path%
set wrkarch=%1
goto dothejob
:setenv
call WRKEnv.bat %1
:dothejob
cd base\ntos\
nmake %wrkarch%= clean
cd ..\..

Binary file not shown.

Binary file not shown.

113
WRK-v1.2/LICENSE.txt Normal file
View File

@ -0,0 +1,113 @@
Windows Research Kernel Source Code License
This license governs use of the accompanying software, and your use of
the software constitutes acceptance of this license. Your license rights
below are subject to the restrictions in the license, and are available
to you only so long as you remain eligible due to your affiliation with
an accredited educational institution. (For more details on eligibility
see http://www.microsoft.com/WindowsAcademic).
You may use and modify this software for any non-commercial purpose within
your educational institution, including making a reasonable number of copies.
Teaching, academic research, and personal experimentation are examples of
purposes which can be non-commercial. You may post copies on an internal
secure server, and it may be installed and used on personal machines of
eligible users.
You may distribute snippets of this software in research papers, books or
other teaching materials, or publish snippets of the software on websites
or on-line community forums that are intended for teaching and research.
The total amount of source code in each of your snippets should not
exceed 50 lines. If you wish to use a larger portion of the software,
please contact compsci@microsoft.com.
You may not use or distribute this software or any derivative works in
any form for commercial purposes. Examples of commercial purposes would
be running business operations, licensing, leasing, or selling the software,
or distributing the software for use with commercial products.
If you wish to commercialize your work related to the software or take
part in research with industrial partners, you need to contact
iplg@microsoft.com to enquire about a commercial license.
You may distribute the software and modifications to the software for
non-commercial purposes, but only to other eligible users of the
software (for example, to another university student or professor to
support joint academic research). You may not grant rights to the
software or derivative works that are broader than those provided
by this license. For example, you may not distribute modifications
of the software under terms that would permit commercial use, or under
terms that purport to require the software or derivative works to be
sublicensed to others.
You may use any information in intangible form that you remember after
accessing the software. However, this right does not grant you a license
to any of Microsoft's copyrights or patents for anything you might
create using such information.
In return for the license rights above, you must agree to these obligations:
1. You will not remove any copyright or other notices from the software,
nor reverse engineer or decompile binary portions of the software,
unless your laws give you the right to do so despite this restriction.
2. You will include a verbatim copy of this license if you distribute
the software in any form.
3. If you distribute derivative works of the software in source code
form you will do so only under this license, and if you distribute
derivative works of the software solely in object form you will do so
only under a license that complies with this license.
4. If you have modified the software or created derivative works,
and distribute such modifications or derivative works, you will cause
the modified files to carry prominent notices describing your changes
and the date of the changes, so that recipients know that they are not
receiving the original software.
5. Microsoft welcomes your comments and suggestions on the source code,
which you provide on a strictly voluntary basis. If you give Microsoft
comments and suggestions regarding bug fixes, enhancements or other
modifications to the source code, you agree that Microsoft may,
in connection with Microsoft products and services use, disclose or
otherwise commercialize your comments and suggestions entirely without
any obligation or restriction based on intellectual property rights or
otherwise. You will not give any comments or suggestions that you have
reason to believe are subject to any patent, copyright, or other
intellectual property claim or right of any third party.
6. THE SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS MEANS NO EXPRESS,
IMPLIED OR STATUTORY WARRANTY, INCLUDING WITHOUT LIMITATION, WARRANTIES
OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY WARRANTY
OF TITLE OR NON-INFRINGEMENT. YOU MUST PASS THIS DISCLAIMER ON WHENEVER
YOU DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
7. MICROSOFT WILL NOT BE LIABLE FOR ANY DAMAGES RELATED TO THE SOFTWARE
OR THIS LICENSE, INCLUDING DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL
OR INCIDENTAL DAMAGES, TO THE MAXIMUM EXTENT THE LAW PERMITS, NO MATTER
WHAT LEGAL THEORY IT IS BASED ON. YOU MUST PASS THIS LIMITATION OF
LIABILITY ON WHENEVER YOU DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
8. If you sue anyone over patents that you think may apply to the software
or anyone's use of the software, your license to the software ends
immediately.
9. You will not use the software to aid the development of any software
programs that are designed to:
(a) harm or intentionally interfere with the operation of a computer
system including any data or information stored on such computer
system; and/or
(b) surreptitiously gain or maintain high level access to a computer
system, self-propagate, and/or execute in a manner that prevents
detection, including but not limited to, so-called “rootkit”
software programs, viruses, or worms.
10. Your rights under the license end immediately if you breach it
in any way.
11. Microsoft reserves all rights not expressly granted to you in this
license.
License Version: 5 December 2008.

148
WRK-v1.2/README.txt Normal file
View File

@ -0,0 +1,148 @@
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of
the Windows Research Kernel Source Code License agreement
(see License.txt). If you do not agree to the terms, do not use the code.
***
WRK v1.2
The Windows Research Kernel v1.2 contains the sources for the core of
the Windows (NTOS) kernel and a build environment for a kernel that will run on
x86 (Windows Server 2003 Service Pack 1) and
amd64 (Windows XP x64 Professional)
A future version may also support booting WRK kernels on Windows XP x86 systems,
but the current kernels will fail to boot due to differences in some shared
structures.
The NTOS kernel implements the basic OS functions
for processes, threads, virtual memory and cache managers, I/O management,
the registry, executive functions such as the kernel heap and synchronization,
the object manager, the local procedure call mechanism, the security reference
monitor, low-level CPU management (thread scheduling, Asynchronous and Deferred
Procedure calls, interrupt/trap handling, exceptions), etc.
The NT Hardware Abstraction Layer, file systems, network stacks, and device
drivers are implemented separately from NTOS and loaded into kernel mode
as dynamic libraries. Sources for these dynamic components are not included
in the WRK, but some are available in various development kits published
by Microsoft, such as the Installable File System (IFS) Kit and the
Windows Driver Development Kit (DDK).
WRK v1.2 includes most of the NTOS kernel sources from the latest released
version of Windows, which supports the AMD64 architecture on the Desktop.
The kernel sources excluded from the kit are primarily in the areas of
plug-and-play, power management, the device verifier, kernel debugger
interface, and virtual dos machine. The primary modifications to WRK
from the released kernel are related to cleanup and removal of server
support, such as code related to the Intel IA64.
***
Organization of the WRK sources
The file License.txt contains the license covering use of the WRK.
The public\ directory contains a number of include files shared among system
components. base\ntos\ contains the NTOS sources.
The primary NTOS source components included in the WRK are organized as follows:
cache\ - cache manager
config\ - registry implementation
dbgk\ - user-mode debugger support
ex\ - executive functions (kernel heap, synchronization, time)
fsrtl\ - file system run-time support
io\ - I/O manager
ke\ - scheduler, CPU management, low-level synchronization
lpc\ - local procedure call implementation
mm\ - virtual memory manager
ob\ - kernel object manager
ps\ - process/thread support
se\ - security functions
wmi\ - Windows Management Instrumentation
inc\ - NTOS-only include files
rtl\ - kernel run-time support
init\ - kernel startup
***
Copying and building the WRK
WRK can be built on Windows Server 2003 or later, or on Windows XP or later.
To copy WRK to your machine:
- open a console window;
- switch to DVD;
- switch to \Resources\Windows_Research_Kernel\Get_WRK\;
- run WRKCopy.bat /w <destination_directory>
(if you run WRKCopy.bat without parameters, WRK will be copied to C:\WRK-v1.2\);
ALTERNATIVELY
- open Windows Explorer (MyComputer);
- create the destination directory on your hard drive;
- switch to DVD;
- navigate to \Resources\Windows_Research_Kernel\Get_WRK\WRK-v1.2\;
- select all files and subdirectories, drag and drop them to the destination
directory.
To adjust the WRK environment setting batch file:
- open console window;
- switch to the directory WRK was copied to;
- run Notepad WRKEnv.bat;
- make sure the "set path=..." statement contains the directory WinDbg was
installed to; (unchanged WRKEnv.bat refers to default directory
C:\Program Files\Debugging Tools for Windows);
- save the file and exit Notepad.
To build WRK from command line:
- open console window;
- switch to the directory WRK was copied to;
- run Build <arch> (or Rebuild <arch> or Clean <arch>), see note about <arch>
below;
ALTERNATIVELY
- open console window;
- switch to the directory WRK was copied to;
- run WRKEnv <arch>, see note about <arch> below;
- switch to base\ntos;
- run nmake %wrkarch%=
To build WRK in Visual Studio 2008 environment:
- start VS2008;
- open solution <WRK_DIR>\WRK.sln, where <WRK_DIR> is the directory WRK was
copied to;
- make sure the configuration is amd64/Win32 or x86/Win32, as is appropriate;
- select Build/Build Solution (or Rebuild Solution, or Clean Solution).
To start Windows Debugger from command line:
- open console window;
- switch to the directory WRK was copied to;
- run WRKDebug <arch>, see note about <arch> below;
ALTERNATIVELY
- open console window;
- switch to the directory WRK was copied to;
- run WRKEnv <arch>, see note about <arch> below;
- run WinDbg %windbgargs%
-----------------------------------------------------------------------------
NOTE ABOUT <ARCH>
Batch files Build.bat, Rebuild.bat, Clean.bat, WRKEnv.bat and WRKDebug.bat
take one parameter target architecture, which is x86 or amd64.
For the first use of either of these batch files, default target architecture
is x86.
Once the target architecture was defined (explicitly or by default), it
cannot be changed for current console window, and <arch> parameter of the
batch files is ignored.
The title of the window where the WRK environment has been set to some target
architecture changes to “WRK x86” or “WRK amd64”.
To work with different target architecture, open another console window.
-----------------------------------------------------------------------------
***

5
WRK-v1.2/Rebuild.bat Normal file
View File

@ -0,0 +1,5 @@
@ECHO OFF
call clean.bat %1 %2
call build.bat %1 %2

19
WRK-v1.2/WRK.sln Normal file
View File

@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsResearchKernel", "WRK.vcproj", "{7B312FB7-F0A3-41FE-89D1-6100FDC35009}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
amd64|Win32 = amd64|Win32
x86|Win32 = x86|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B312FB7-F0A3-41FE-89D1-6100FDC35009}.amd64|Win32.ActiveCfg = amd64|Win32
{7B312FB7-F0A3-41FE-89D1-6100FDC35009}.amd64|Win32.Build.0 = amd64|Win32
{7B312FB7-F0A3-41FE-89D1-6100FDC35009}.x86|Win32.ActiveCfg = x86|Win32
{7B312FB7-F0A3-41FE-89D1-6100FDC35009}.x86|Win32.Build.0 = x86|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

2770
WRK-v1.2/WRK.vcproj Normal file

File diff suppressed because it is too large Load Diff

3
WRK-v1.2/WRKDebug.bat Normal file
View File

@ -0,0 +1,3 @@
call WRKEnv.bat %1
windbg %windbgargs%

24
WRK-v1.2/WRKEnv.bat Normal file
View File

@ -0,0 +1,24 @@
@echo off
rem
rem This batch file sets the following WRK build and debug environment variables:
rem wrkarch - the target architecture, "x86" or "amd64"; 1st parameter of the batch file; default is x86
rem path - the search path, modified to include the tools for respective target architecture
rem and Windows Debugger (WinDbg)
rem windbgargs - the arguments for WinDbg
rem _NT_SYMBOL_PATH - symbol path for WinDbg
rem
rem Usage: copy this file to your hard drive and edit it to reflect your installation;
rem open a console window and run this batch file;
rem run command "set" to make sure the environment is set properly;
rem now you can build WRK and run Windbg from this console window.
rem
IF DEFINED wrkarch goto finish
SET wrkarch=x86
IF NOT [%1] EQU [] SET wrkarch=%1
SET path=%cd%\tools\%wrkarch%;%path%;C:\Program Files\Debugging Tools for Windows
SET windbgargs=-k com:pipe,port=\\.\pipe\debug,resets=0,reconnect
SET _NT_SYMBOL_PATH="%cd%\base\ntos\build\exe;%cd%\WS03SP1HALS\x86\halacpim"
@title WRK %wrkarch%
:finish

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,109 @@
/*++
Copyright (c) 1997-2000 Microsoft Corporation
Module Name:
NtdllTracer.h
Abstract:
This file contains structures and functions definitions used in Ntdll
events tracing
--*/
#ifndef _NTDLL_WMI_TRACE_
#define _NTDLL_WMI_TRACE_
#define MEMORY_FROM_LOOKASIDE 1 //Activity from LookAside
#define MEMORY_FROM_LOWFRAG 2 //Activity from Low Frag Heap
#define MEMORY_FROM_MAINPATH 3 //Activity from Main Code Path
#define MEMORY_FROM_SLOWPATH 4 //Activity from Slow Code Path
#define LOG_LOOKASIDE 0x00000001 //Bit for LookAside trace
#define FAILED_TLSINDEX -1
#define MAX_PID 10
#ifndef UserSharedData
#define UserSharedData USER_SHARED_DATA
#endif
#define IN_TRACING 0x00000001 // Flag to see if this thread is tracing.
extern BOOLEAN bNtdllTrace;
#define IsCritSecLogging(CriticalSection) ((USER_SHARED_DATA->TraceLogging & ENABLECRITSECTRACE) \
&&(bNtdllTrace || GlobalCounter != (USER_SHARED_DATA->TraceLogging >> 16)) \
&&((HandleToUlong(NtCurrentTeb()->EtwTraceData) & IN_TRACING) != IN_TRACING))
extern
ULONG GlobalCounter;
#define IsHeapLogging(HeapHandle) (USER_SHARED_DATA->TraceLogging & ENABLEHEAPTRACE &&\
(bNtdllTrace || GlobalCounter != (USER_SHARED_DATA->TraceLogging >> 16))&& \
((HandleToUlong(NtCurrentTeb()->EtwTraceData) & IN_TRACING) != IN_TRACING))
//
// When calling from deep inside heap allocation routines, we do not want to
// be initializing ETW process heap since that gets into recursive behaviour.
//
#define IsDeepHeapLogging(HeapHandle) (USER_SHARED_DATA->TraceLogging & ENABLEHEAPTRACE &&\
(bNtdllTrace || GlobalCounter != (USER_SHARED_DATA->TraceLogging >> 16))&& \
(EtwpProcessHeap != NULL) && \
((HandleToUlong(NtCurrentTeb()->EtwTraceData) & IN_TRACING) != IN_TRACING))
typedef struct _THREAD_LOCAL_DATA THREAD_LOCAL_DATA, *PTHREAD_LOCAL_DATA, **PPTHREAD_LOCAL_DATA;
typedef struct _THREAD_LOCAL_DATA {
PTHREAD_LOCAL_DATA FLink; //Forward Link
PTHREAD_LOCAL_DATA BLink; //Backward Link
PWMI_BUFFER_HEADER pBuffer; //Pointer to thread buffer info.
LONG ReferenceCount;
} THREAD_LOCAL_DATA, *PTHREAD_LOCAL_DATA, **PPTHREAD_LOCAL_DATA;
extern
PVOID EtwpProcessHeap;
#ifndef EtwpGetCycleCount
__int64
EtwpGetCycleCount();
#endif // EtwpGetCycleCount
void
ReleaseBufferLocation(PTHREAD_LOCAL_DATA pThreadLocalData);
NTSTATUS
AcquireBufferLocation(PVOID *pEvent, PPTHREAD_LOCAL_DATA pThreadLocalData, PUSHORT ReqSize);
typedef struct _NTDLL_EVENT_COMMON {
PVOID Handle; //Handle of Heap
}NTDLL_EVENT_COMMON, *PNTDLL_EVENT_COMMON;
typedef struct _NTDLL_EVENT_HANDLES {
RTL_CRITICAL_SECTION CriticalSection; //Critical section
ULONG dwTlsIndex; //TLS Index
TRACEHANDLE hRegistrationHandle; //Registration Handle used for Unregistration.
TRACEHANDLE hLoggerHandle; //Handle to Trace Logger
PTHREAD_LOCAL_DATA pThreadListHead; //Link List that contains all threads info invovled in tracing.
}NTDLL_EVENT_HANDLES, *PNTDLL_EVENT_HANDLES, **PPNTDLL_EVENT_HANDLES;
extern LONG TraceLevel;
extern PNTDLL_EVENT_HANDLES NtdllTraceHandles;
extern RTL_CRITICAL_SECTION UMLogCritSect;
extern RTL_CRITICAL_SECTION PMCritSect;
extern RTL_CRITICAL_SECTION LoaderLock;
#endif //_NTDLL_WMI_TRACE_

View File

@ -0,0 +1 @@
*** This file is here solely to preserve the directory structure when WRK is xcopy'ed ***

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,76 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
// If you do not agree to the terms, do not use the code.
//
#pragma warning(3:4092) // sizeof returns 'unsigned long'
#pragma warning(4:4096) // '__cdecl' must be used with '...'
#pragma warning(4:4121) // structure is sensitive to alignment
#pragma warning(3:4125) // decimal digit in octal sequence
#pragma warning(3:4130) // logical operation on address of string constant
#pragma warning(3:4132) // const object should be initialized
#if _DBG_MEMCPY_INLINE_
#pragma warning(disable:4163) // not available as an intrinsic function
#endif
#pragma warning(4:4206) // Source File is empty
#pragma warning(4:4101) // Unreferenced local variable
#pragma warning(4:4208) // delete[exp] - exp evaluated but ignored
#pragma warning(3:4212) // function declaration used ellipsis
#pragma warning(3:4242) // convertion possible loss of data
#pragma warning(4:4267) // convertion from size_t to smaller type
#pragma warning(4:4312) // conversion to type of greater size
#pragma warning(disable:4324) // structure padded due to __declspec(align())
#pragma warning(error:4700) // Local used w/o being initialized
#pragma warning(error:4259) // pure virtual function was not defined
#pragma warning(disable:4071) // no function prototype given - formals unspecified
#pragma warning(error:4013) // function' undefined - assuming extern returning int
#pragma warning(error:4551) // Function call missing argument list
#pragma warning(error:4806) // unsafe operation involving type 'bool'
#pragma warning(4:4509) // use of SEH with destructor
#pragma warning(4:4177) // pragma data_seg s/b at global scope
#pragma warning(disable:4274) // #ident ignored
#pragma warning(disable:4786) // identifier was truncated to 255 characters in debug information.
#pragma warning(disable:4503) // decorated name length exceeded, name was truncated.
#pragma warning(disable:4263) // Derived override doesn't match base - who cares...
#pragma warning(disable:4264) // base function is hidden - again who cares.
#pragma warning(disable:4710) // Function marked as inline - wasn't
#pragma warning(disable:4917) // A GUID can only be associated with a class, interface or namespace
#pragma warning(error:4552) // <<, >> ops used to no effect (probably missing an = sign)
#pragma warning(error:4553) // == op used w/o effect (probably s/b an = sign)
#pragma warning(3:4288) // nonstandard extension used (loop counter)
#pragma warning(3:4532) // jump out of __finally block
#pragma warning(error:4312) // cast of 32-bit int to 64-bit ptr
#pragma warning(error:4296) // expression is always true/false
#pragma warning(3:4546) // function call before comma missing argument list
// disable until __noop(arg,arg,arg) doesn't generate false hits.
// #pragma warning(3:4547) // '<' : operator before comma has no effect; expected operator with side-effect
// #pragma warning(3:4548) // expression before comma has no effect; expected expression with side-effect
#pragma warning(disable:4197) // illegal use of const/volatile: qualifier ignored (disabled until sources fixed)
#pragma warning(disable:4675) // picked overload found via Koenig lookup
#pragma warning(disable:4356) // static member cannot be initialized via derived class
#ifndef __cplusplus
#undef try
#undef except
#undef finally
#undef leave
#define try __try
#define except __except
#define finally __finally
#define leave __leave
#endif
#if _MSC_VER <= 1400
#pragma warning(disable: 4068) // turn off unknown pragma warning so prefast pragmas won't show
// show up in build.wrn/build.err
#endif
#if defined(_M_IX86) && _MSC_FULL_VER >= 13102154
#define __TYPENAME typename
#else
#define __TYPENAME
#endif

View File

@ -0,0 +1,66 @@
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
# If you do not agree to the terms, do not use the code.
#
kernel = wrk$(machine)
asobjs=
ccobjs=
ccarchobjs=
default: kernelexp kernellib kernelexe
nodefault=1
!include $(ntos)\BUILD\makefile.build
linklibpath = -LIBPATH:$(topobj) -LIBPATH:PREBUILT\$(targ)
ntoswrklib = ntoswrk.lib
ntosarchlib = ntosarch.lib
bootlibs = bootvid.lib sdbapint.lib kdcom.lib
fullkernel = EXE\$(kernel)
# kernel link definitions
LINKFLAGS = -IGNORE:4087,4001,4010,4037,4039,4065,4070,4078,4087,4089,4221,4198 -WX -NODEFAULTLIB -machine:$(machine) $(linklibpath)
LINK = link.exe -nologo
LINKEDIT = link.exe -edit -nologo
LIB = $(LIB) $(linklibpath)
!if "$(targ)" == "i386"
archlinkopts = -safeseh -functionpadmin:5 -debugtype:cv,fixup -STACK:0x40000,0x2000 -align:0x1000
hotpatch = -stub:PREBUILT\i386\stub512.com
entrypoint = KiSystemStartup@4
!else
archlinkopts = -functionpadmin:6 -debugtype:cv,fixup,pdata -STACK:0x80000,0x2000
hotpatch = PREBUILT\amd64\hotpatch.obj
LINKFLAGS = -IGNORE:4108,4088,4218,4218,4235 $(LINKFLAGS)
LIBFLAGS = -IGNORE:4108,4088,4218,4218,4235 $(LIBFLAGS)
entrypoint = KiSystemStartup
!endif
ntosmerge = -merge:PAGECONST=PAGE -merge:INITCONST=INIT -merge:INITDATA=INIT -merge:PAGELKCONST=PAGELK \
-merge:PAGEVRFY_CONST=PAGEVRFY -MERGE:_PAGE=PAGE -MERGE:_TEXT=.text -merge:.rdata=.text
ntosversion = -release -version:5.2 -osversion:5.2 -subsystem:native,5.02
ntoslinkopts = $(ntosversion) $(ntosmerge) -SECTION:INIT,d -OPT:REF -OPT:ICF -INCREMENTAL:NO \
-FULLBUILD -debug $(archlinkopts) -opt:nowin98 -pdbcompress -driver
kernelexp:
copy ..\init\ntoskrnl.src+..\init\$(targ)def.src $(OBJ)\$(kernel).pp
$(CC) $(CFLAGS0) -EP $(OBJ)\$(kernel).pp > $(fullkernel).def
-del $(OBJ)\$(kernel).pp
$(LIB) $(LIBFLAGS) -IGNORE:4001 $(OBJ)\*.lib $(ntoswrklib) -def:$(fullkernel).def -out:$(fullkernel).lib
kernellib:
$(LIB) $(fullkernel).lib $(ntosarchlib) -out:$(fullkernel).lib
kernelexe:
$(LINK) $(LINKFLAGS) $(ntoslinkopts) -out:$(fullkernel).exe -map:$(fullkernel).map -pdb:$(fullkernel).pdb -entry:$(entrypoint) \
$(hotpatch) PREBUILT\$(targ)\ntoskrnl.res $(OBJ)\ntkrnlmp.obj $(OBJ)\*.lib $(ntoswrklib) hal.lib $(fullkernel).exp $(bootlibs)
$(LINKEDIT) -section:.rsrc,!d $(fullkernel).exe

View File

@ -0,0 +1,83 @@
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
# If you do not agree to the terms, do not use the code.
#
!if !defined(ntos) || !defined(pub) || !defined(module) || !defined(topobj) || !defined(targ) || ("$(targ)" != "i386" && "$(targ)" != "amd64")
!ERROR Usage: nmake ntos=ntosdir pub=pubdir module=ntossubdir targ=[i386|amd64]
!endif
!if "$(targ)" == "i386"
targdefs = -D_X86_=1 -Di386=1 -DSTD_CALL -DFPO=0
targaopts = -safeseh -coff -Zm
targcopts = -Gm- -Gz -GX- -G6 -Ze -Gi- -QIfdiv- -Z7 -Oxs -Oy-
targlopts =
machine = x86
archml = ml
!else
targdefs = -D_WIN64 -D_AMD64_ -DAMD64
targaopts =
targcopts = -Wp64 -Oxt -EHs-c- /Oxt -Gs12288 -GL- -MT -U_MT
targlopts = -IGNORE:4108,4088,4218,4218,4235
machine = amd64
archml = ml64
!endif
tempdir = $(topobj)\temp
ipub = $(pub)\internal
baseinc = $(ntos)\..\inc
incs = -I..\$(targ) -I. -I$(ntos)\$(module) -I$(ntos)\inc -I$(pub)\ddk\inc -I$(ipub)\ds\inc -I$(ipub)\sdktools\inc \
-I$(baseinc) -I$(ipub)\base\inc -I$(pub)\sdk\inc -I$(pub)\sdk\inc\crt -I$(pub)\halkit\inc
defs = $(targdefs) -DCONDITION_HANDLING=1 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 -DWINNT=1 \
-D_WIN32_WINNT=0x0502 -DWINVER=0x0502 -D_WIN32_IE=0x0603 -DWIN32_LEAN_AND_MEAN=1 -DDBG=0 -DDEVL=1 \
-D__BUILDMACHINE__=WRK1.2(university) -DNDEBUG -D_NTSYSTEM_ -DNT_SMT -DNTOS_KERNEL_RUNTIME=1
aopts = -Cx -Zi $(targaopts)
copts = -Zl -Zp8 -Gy -cbstring -W3 -WX -GR- -GF -GS $(targcopts)
compilerwarnings = -FI$(ntos)\BUILD\WARNING.h
AS = $(archml).exe -nologo
AFLAGS = $(aopts) $(incs) -Foobj$(targ)\ $(defs) $(specialaflags)
CC = cl.exe -nologo
CFLAGS0 = $(copts) $(incs) -Foobj$(targ)\ $(defs) $(specialcflags)
CFLAGS = $(CFLAGS0) $(compilerwarnings)
LIBFLAGS = $(targlopts) -IGNORE:4010,4037,4039,4065,4070,4078,4087,4089,4221,4198 -WX -nodefaultlib -machine:$(machine)
LIB = lib.exe -nologo
OBJ = obj$(targ)
!ifndef nodefault
default: build $(localtargets)
!endif
# assembly files
{..\$(targ)\}.asm{$(OBJ)\}.obj::
$(AS) $(AFLAGS) -c $<
# arch-specific C files
{..\$(targ)\}.c{$(OBJ)\}.obj::
$(CC) $(CFLAGS) -c $<
# C files
{..\}.c{$(OBJ)\}.obj::
$(CC) $(CFLAGS) -c $<
# library
$(topobj)\$(library).lib: $(asobjs) $(ccarchobjs) $(ccobjs)
@echo linking $(library).lib
$(LIB) $(LIBFLAGS) -out:$@ $**
# pseudo targets
build: $(topobj)\$(library).lib
clean: clean0 $(localclean)
clean0:
-del $(asobjs) $(ccarchobjs) $(ccobjs) $(extraobjs)

View File

@ -0,0 +1 @@
*** This file is here solely to preserve the directory structure when WRK is xcopy'ed ***

View File

@ -0,0 +1 @@
*** This file is here solely to preserve the directory structure when WRK is xcopy'ed ***

View File

@ -0,0 +1,340 @@
;++
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
; You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
; If you do not agree to the terms, do not use the code.
;
;
; Module Name:
;
; vdm.inc
;
; Abstract:
;
; This module contains the structure and constant definitions for
; the vdm component
;--
.386p
TRUE equ 1
FALSE equ 0
;
; Macro's to only do locked memory operations on MP systems
;
IFDEF NT_UP
MPLOCK equ <>
ELSE
MPLOCK equ <lock>
ENDIF
page , 132
subttl "Macro to dispatch exception"
;++
;
; Macro Description:
;
; This macro allocates exception record on stack, sets up exception
; record using specified parameters and finally sets up arguments
; and calls _KiDispatchException.
;
; Arguments:
;
; ExcepCode - Exception code to put into exception record
; ExceptFlags - Exception flags to put into exception record
; ExceptRecord - Associated exception record
; ExceptAddress - Addr of instruction which the hardware exception occurs
; NumParms - Number of additional parameters
; ParameterList - the additional parameter list
;
; Return Value:
;
; None.
;
;--
DISPATCH_EXCEPTION macro ExceptCode, ExceptFlags, ExceptRecord, ExceptAddress,\
NumParms, ParameterList
local de10, de20
; Set up exception record for raising exception
?i = 0
sub esp, ExceptionRecordSize + NumParms * 4
; allocate exception record
mov dword ptr [esp]+ErExceptionCode, ExceptCode
; set up exception code
mov dword ptr [esp]+ErExceptionFlags, ExceptFlags
; set exception flags
mov dword ptr [esp]+ErExceptionRecord, ExceptRecord
; set associated exception record
mov dword ptr [esp]+ErExceptionAddress, ExceptAddress
mov dword ptr [esp]+ErNumberParameters, NumParms
; set number of parameters
IRP z, <ParameterList>
mov dword ptr [esp]+(ErExceptionInformation+?i*4), z
?i = ?i + 1
ENDM
; set up arguments and call _KiDispatchException
mov ecx, esp ; (ecx)->exception record
test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
jz de10
mov eax,0FFFFh
jmp de20
de10: mov eax,[ebp]+TsSegCs
de20: and eax,MODE_MASK
; 1 - set first chance TRUE
; eax - PreviousMode
; ebp - trap frame addr
; 0 - Null exception frame
; ecx - exception record addr
; dispatchexception as appropriate
stdCall _KiDispatchException, <ecx, 0, ebp, eax, 1>
add esp,ExceptionRecordSize + NumParms*4
ENDM
;
; Prefix Flags
;
PREFIX_ES equ 00000100h
PREFIX_CS equ 00000200h
PREFIX_SS equ 00000400h
PREFIX_DS equ 00000800h
PREFIX_FS equ 00001000h
PREFIX_GS equ 00002000h
PREFIX_OPER32 equ 00004000h
PREFIX_ADDR32 equ 00008000h
PREFIX_LOCK equ 00010000h
PREFIX_REPNE equ 00020000h
PREFIX_REP equ 00040000h
PREFIX_SEG_ALL equ 00003f00h
NUM_OPCODE equ 255
;
; Reginfo structure
;
RegInfo struc
RiSegSs dd 0
RiEsp dd 0
RiEFlags dd 0
RiSegCs dd 0
RiEip dd 0
RiTrapFrame dd 0
RiCsLimit dd 0
RiCsBase dd 0
RiCsFlags dd 0
RiSsLimit dd 0
RiSsBase dd 0
RiSsFlags dd 0
RiPrefixFlags dd 0
RiOperand dd 0
RegInfo ends
REGINFOSIZE EQU 56
MAX_VDM_ADDR EQU 0FFFFFFH
DR7_GLOBAL EQU 002AAH
;
;Fast Read/Write Defines
;
SVC_DEMFASTREAD equ 42h
SVC_DEMFASTWRITE equ 43h
DOS_BOP equ 50h
;
;
; Size of Exception Record
;
ExceptionRecordSize = (ErNumberParameters + 4 + 3) AND 0fffffffcH ;
;
; Magic value
;
OPCODE_MAGIC equ 00f5ah
;++
; diBEGIN - BEGIN index table
;
; ENTRY name = name of di table
; badindex = local label for unspecified entries
;
; EXIT ?sindex = specific entry index
; ?badindex = default index for unspecified entries
;--
diBEGIN macro name,badindex ;; Beginning of dispatch table
?sopc = 0
?badindex = badindex
name label byte ;; Start of dispatch table
endm
;++
; dtI - SPECIFIC index table entry
;
; ENTRY opc = opcode value
; index = INDEX_ value corresponding to opcode
; ?badindex = unspecified entry index
; ?sopc = specific entry index
;
; EXIT Unspecified entries prior to "index" filled in;
; Specified entry filled in.
; ?sopc = next index to fill in;
;--
dtI macro opc,index ;; Specific entry in dispatch table
if ?sopc gt opc
%out dtI: opcode out of order
.err
else
if ?sopc lt opc ;; Fill unspecified entries
rept opc - ?sopc
db ?badindex
endm
endif
db index ;; Specified entry
?sopc = opc+1 ;; Set new start index
endif
endm
;++
; diEND - END index table
;
; ENTRY index = highest entry in table
; ?sopc = specific entry index
;
; EXIT rest of the table filled in
;--
diEND macro index ;; End of dispatch table
if ?sopc lt index ;; Fill in rest of table
rept index - ?sopc
db ?badindex
endm
db ?badindex ;; fill in last entry of table!
endif
endm
;++
; dtBEGIN - BEGIN dispatch table
;
; ENTRY name = name of dt table
; badaddr = local label for unspecified entries
;
; EXIT ?sindex = specific entry index
; ?badaddr = default handler for unspecified entries
;--
dtBEGIN macro name,badaddr ;; Beginning of dispatch table
?sindex = 0
?badaddr = badaddr
name label dword ;; Start of dispatch table
endm
;++
; dtS - SPECIFIC dispatch table entry
;
; ENTRY index = index of entry
; addr = address of handler
; ?badaddr = unspecified entry handler
; ?sindex = specific entry index
;
; EXIT Unspecified entries prior to "index" filled in;
; Specified entry filled in.
; ?sindex = next index to fill in;
;--
dtS macro index,addr ;; Specific entry in dispatch table
if ?sindex gt index
%out dtS: index out of order
.err
else
if ?sindex lt index ;; Fill unspecified entries
rept index - ?sindex
dd offset FLAT:?badaddr
endm
endif
dd offset FLAT:addr ;; Specified entry
?sindex = index+1 ;; Set new start index
endif
endm
;++
; dtEND - END dispatch table
;
; ENTRY index = highest entry in table
; ?sindex = specific entry index
;
; EXIT rest of the table filled in
;--
dtEND macro index ;; End of dispatch table
if ?sindex lt index ;; Fill in rest of table
rept index - ?sindex
dd offset FLAT:?badaddr
endm
dd offset FLAT:?badaddr ;; fill in last entry of table!
endif
endm
;++
; CsToLinearPM
;
;--
CsToLinearPM macro sel, erraddr
lea eax,[esi].RiCsLimit
push eax
lea eax,[esi].RiCsBase
push eax
lea eax,[esi].RiCsFlags
push eax
push sel
call _Ki386GetSelectorParameters@16
or al,al
jz erraddr
test [esi].RiCsFlags,SEL_TYPE_EXECUTE
jz erraddr
test [esi].RiCsFlags,SEL_TYPE_2GIG
jz @f
; Correct limit value for granularity
shl [esi].RiCsLimit,12
or [esi].RiCsLimit,0FFFh
@@:
endm
;++
; CsToLinearV86
;
;--
CsToLinearV86 macro
movzx eax,word ptr [esi].RiSegCs
shl eax,4
mov [esi].RiCsBase,eax
mov [esi].RiCsLimit,0FFFFh
mov [esi].RiCsFlags,0
endm

View File

@ -0,0 +1,28 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
halverifier.c
Abstract:
This module contains the routines to verify hal usage & apis.
--*/
#ifndef _HAL_VERIFIER_
#define _HAL_VERIFIER_
VOID
VfHalVerifierInitialize(
VOID
);
#endif

View File

@ -0,0 +1,66 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfbugcheck.h
Abstract:
This header defines the prototypes and constants required for verifier
bugchecks.
--*/
#ifndef _VFBUGCHECK_H_
#define _VFBUGCHECK_H_
extern LONG IovpInitCalled;
#define KDASSERT(x) { if (KdDebuggerEnabled) { ASSERT(x) ; } }
#define ASSERT_SPINLOCK_HELD(x)
#define DCPARAM_ROUTINE 0x00000001
#define DCPARAM_IRP 0x00000008
#define DCPARAM_IRPSNAP 0x00000040
#define DCPARAM_DEVOBJ 0x00000200
#define DCPARAM_STATUS 0x00001000
#define DCPARAM_ULONG 0x00008000
#define DCPARAM_PVOID 0x00040000
#define WDM_FAIL_ROUTINE(ParenWrappedParamList) \
{ \
if (IovpInitCalled) { \
VfBugcheckThrowIoException##ParenWrappedParamList;\
} \
}
VOID
FASTCALL
VfBugcheckInit(
VOID
);
NTSTATUS
VfBugcheckThrowIoException(
IN DCERROR_ID MessageIndex,
IN ULONG MessageParameterMask,
...
);
NTSTATUS
VfBugcheckThrowException(
IN PVFMESSAGE_TEMPLATE_TABLE MessageTable OPTIONAL,
IN VFMESSAGE_ERRORID MessageID,
IN PCSTR MessageParamFormat,
IN va_list * MessageParameters
);
#endif // _VFBUGCHECK_H_

View File

@ -0,0 +1,28 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfddi.h
Abstract:
This header contains prototypes for verifier device driver interfaces.
--*/
VOID
VfDdiInit(
VOID
);
VOID
VfDdiExposeWmiObjects(
VOID
);

View File

@ -0,0 +1,440 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfdeadlock.h
Abstract:
Detect deadlocks in arbitrary synchronization objects.
--*/
#ifndef _VF_DEADLOCK_
#define _VF_DEADLOCK_
//
// Deadlock detection package initialization.
//
VOID
VfDeadlockDetectionInitialize(
);
//
// Functions called from IovCallDriver (driver verifier replacement for
// IoCallDriver) just before and after the real call to the driver is made.
//
BOOLEAN
VfDeadlockBeforeCallDriver (
IN PDEVICE_OBJECT DeviceObject,
IN OUT PIRP Irp
);
VOID
VfDeadlockAfterCallDriver (
IN PDEVICE_OBJECT DeviceObject,
IN OUT PIRP Irp,
IN BOOLEAN PagingIrp
);
//
// Maximum depth of stack traces captured.
//
#define VI_MAX_STACK_DEPTH 8
#define NO_OF_DEADLOCK_PARTICIPANTS 32
//
// VI_DEADLOCK_NODE
//
typedef struct _VI_DEADLOCK_NODE {
//
// Node representing the acquisition of the previous resource.
//
struct _VI_DEADLOCK_NODE * Parent;
//
// Node representing the next resource acquisitions, that are
// done after acquisition of the current resource.
//
struct _LIST_ENTRY ChildrenList;
//
// Field used to chain siblings in the tree. A parent node has the
// ChildrenList field as the head of the children list that is chained
// with the Siblings field.
//
struct _LIST_ENTRY SiblingsList;
union {
//
// List of nodes representing the same resource acquisition
// as the current node but in different contexts (lock combinations).
//
struct _LIST_ENTRY ResourceList;
//
// Used to chain free nodes. This is used only after the node has
// been deleted (resource was freed). Nodes are kept in a cache
// to reduce contention for the kernel pool.
//
struct _LIST_ENTRY FreeListEntry;
};
//
// Back pointer to the descriptor for this resource.
//
struct _VI_DEADLOCK_RESOURCE * Root;
//
// When we find a deadlock, we keep this info around in order to
// be able to identify the parties involved who have caused
// the deadlock.
//
struct _VI_DEADLOCK_THREAD * ThreadEntry;
//
// Fields used for decision making within the deadlock analysis
// algorithm.
//
// Active: 1 if the node represents a resource currently acquired,
// 0 if resource was acquired in the past.
//
// OnlyTryAcquiredUsed: 1 if resource was always acquired with TryAcquire.
// 0 if at least once normal acquire was used. A node that uses
// only TryAcquire cannot be involved in a deadlock.
//
// ReleasedOutOfOrder: 1 if the resource was at least once released
// out of order. The flag is used while looking for cycles because
// this type of nodes will appear as part of the cycle but there is
// no deadlock.
//
// SequenceNumber: field that gets a unique stamp during each deadlock
// analysis run. It helps figure out if the node was touched
// already in the current graph traversal.
//
struct {
ULONG Active : 1;
ULONG OnlyTryAcquireUsed : 1;
ULONG ReleasedOutOfOrder : 1;
ULONG SequenceNumber : 29;
};
//
// Stack traces for the resource acquisition moment.
// Used when displaying deadlock proofs. On free builds
// anything other than the first entry (return address)
// may be bogus in case stack trace capturing failed.
//
PVOID StackTrace[VI_MAX_STACK_DEPTH];
PVOID ParentStackTrace[VI_MAX_STACK_DEPTH];
} VI_DEADLOCK_NODE, *PVI_DEADLOCK_NODE;
//
// VI_DEADLOCK_RESOURCE
//
typedef struct _VI_DEADLOCK_RESOURCE {
//
// Resource type (mutex, spinlock, etc.).
//
VI_DEADLOCK_RESOURCE_TYPE Type;
//
// Resource flags
//
// NodeCount : number of resource nodes created for this resource.
//
// RecursionCount : number of times this resource has been recursively acquired
// It makes sense to put this counter in the resource because as long as
// resource is acquired only one thread can operate on it.
//
struct {
ULONG NodeCount : 16;
ULONG RecursionCount : 16;
};
//
// The address of the synchronization object used by the kernel.
//
PVOID ResourceAddress;
//
// The thread that currently owns the resource. The field is
// null if nobody owns the resource.
//
struct _VI_DEADLOCK_THREAD * ThreadOwner;
//
// List of resource nodes representing acquisitions of this resource.
//
LIST_ENTRY ResourceList;
union {
//
// List used for chaining resources from a hash bucket.
//
LIST_ENTRY HashChainList;
//
// Used to chain free resources. This list is used only after
// the resource has been freed and we put the structure
// into a cache to reduce kernel pool contention.
//
LIST_ENTRY FreeListEntry;
};
//
// Stack trace of the resource creator. On free builds we
// may have here only a return address that is bubbled up
// from verifier thunks.
//
PVOID StackTrace [VI_MAX_STACK_DEPTH];
//
// Stack trace for last acquire
//
PVOID LastAcquireTrace [VI_MAX_STACK_DEPTH];
//
// Stack trace for last release
//
PVOID LastReleaseTrace [VI_MAX_STACK_DEPTH];
} VI_DEADLOCK_RESOURCE, * PVI_DEADLOCK_RESOURCE;
//
// VI_DEADLOCK_THREAD
//
typedef struct _VI_DEADLOCK_THREAD {
//
// Kernel thread address
//
PKTHREAD Thread;
//
// The node representing the last resource acquisition made by
// this thread.
//
//
// We have separate graph branches for spinlocks and other types
// of locks (fast mutex, mutex). The thread keeps a list of both types
// so that we can properly release locks
//
PVI_DEADLOCK_NODE CurrentSpinNode;
PVI_DEADLOCK_NODE CurrentOtherNode;
union {
//
// Thread list. It is used for chaining into a hash bucket.
//
LIST_ENTRY ListEntry;
//
// Used to chain free nodes. The list is used only after we decide
// to delete the thread structure (possibly because it does not
// hold resources anymore). Keeping the structures in a cache
// reduces pool contention.
//
LIST_ENTRY FreeListEntry;
};
//
// Count of resources currently acquired by a thread. When this becomes
// zero the thread will be destroyed. The count goes up during acquire
// and down during release.
//
ULONG NodeCount;
//
// This counter is used to count how many IoCallDriver() calls with
// paging IRPs are active for this thread. This information is necessary
// to decide if we should temporarily disable deadlock verification
// to avoid known lack of lock hierarchy issues in file system drivers.
//
ULONG PagingCount;
} VI_DEADLOCK_THREAD, *PVI_DEADLOCK_THREAD;
//
// Deadlock verifier globals
//
typedef struct _VI_DEADLOCK_GLOBALS {
//
// Structure counters: [0] - current, [1] - maximum
//
ULONG Nodes[2];
ULONG Resources[2];
ULONG Threads[2];
//
// Maximum times for Acquire() and Release() in ticks.
//
LONGLONG TimeAcquire;
LONGLONG TimeRelease;
//
// Total number of kernel pool bytes used by the deadlock verifier
//
SIZE_T BytesAllocated;
//
// Resource and thread collection.
//
PLIST_ENTRY ResourceDatabase;
PLIST_ENTRY ThreadDatabase;
//
// How many times ExAllocatePool failed on us?
// If this is >0 we stop deadlock verification.
//
ULONG AllocationFailures;
//
// How many nodes have been trimmed when we decided to forget
// partially the history of some resources.
//
ULONG NodesTrimmedBasedOnAge;
ULONG NodesTrimmedBasedOnCount;
//
// Deadlock analysis statistics
//
ULONG NodesSearched;
ULONG MaxNodesSearched;
ULONG SequenceNumber;
ULONG RecursionDepthLimit;
ULONG SearchedNodesLimit;
ULONG DepthLimitHits;
ULONG SearchLimitHits;
//
// Number of times we have to exhonerate a deadlock because
// it was protected by a common resource (e.g. thread 1 takes ABC,
// thread 2 takes ACB -- this will get flagged initially by our algorithm
// since B&C are taken out of order but is not actually a deadlock.
//
ULONG ABC_ACB_Skipped;
ULONG OutOfOrderReleases;
ULONG NodesReleasedOutOfOrder;
#if DBG
//
// How many locks are held simultaneously while the system is running?
//
ULONG NodeLevelCounter[8];
ULONG GraphNodes[8];
#endif
ULONG TotalReleases;
ULONG RootNodesDeleted;
//
// Used to control how often we delete portions of the dependency
// graph.
//
ULONG ForgetHistoryCounter;
//
// How often was a worker items dispatched to trim the
// pool cache.
//
ULONG PoolTrimCounter;
//
// Caches of freed structures (thread, resource, node) used to
// decrease kernel pool contention.
//
LIST_ENTRY FreeResourceList;
LIST_ENTRY FreeThreadList;
LIST_ENTRY FreeNodeList;
ULONG FreeResourceCount;
ULONG FreeThreadCount;
ULONG FreeNodeCount;
//
// Resource address that caused the deadlock
//
PVOID Instigator;
//
// Number of participants in the deadlock
//
ULONG NumberOfParticipants;
//
// List of the nodes that participate in the deadlock
//
PVI_DEADLOCK_NODE Participant [NO_OF_DEADLOCK_PARTICIPANTS];
LOGICAL CacheReductionInProgress;
} VI_DEADLOCK_GLOBALS, *PVI_DEADLOCK_GLOBALS;
#endif

View File

@ -0,0 +1,31 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfdebug.h
Abstract:
This header contains debugging macros used by the driver verifier code.
--*/
extern ULONG VfSpewLevel;
#if DBG
#define VERIFIER_DBGPRINT(txt,level) \
{ \
if (VfSpewLevel>(level)) { \
DbgPrint##txt; \
}\
}
#else
#define VERIFIER_DBGPRINT(txt,level)
#endif

View File

@ -0,0 +1,60 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfdef.h
Abstract:
This header collects together the various files necessary to create a basic
set of definitions for the verifier.
--*/
//
// Disable W4 level warnings generated by public headers.
//
#include "vfpragma.h"
#include "ntos.h"
#include "vfdebug.h"
#include "vfmacro.h"
#include "vfinit.h"
#include "vfsettings.h"
#include "vfmessage.h"
#include "vfbugcheck.h"
#include "vfprint.h"
#include "vfutil.h"
#include "vfstack.h"
#include "vftriage.h"
#include "vfirp.h"
#include "vfirpdb.h"
#include "vfirplog.h"
#include "vfdevobj.h"
#include "vfpacket.h"
#include "halverifier.h"
#include "vfdeadlock.h"
#include "..\io\trackirp.h"
#include "..\io\sessnirp.h"
#include "..\ob\obvutil.h"
#include "..\io\iovutil.h"
#include "..\io\pnpmgr\ppvutil.h"
#include "vffilter.h"
#include "vfmajor.h"
#include "vfpnp.h"
#include "vfpower.h"
#include "vfwmi.h"
#include "vfgeneric.h"
#include "vfrandom.h"
#include "vfddi.h"

View File

@ -0,0 +1,69 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfdevobj.h
Abstract:
This header exposes function hooks that verify drivers properly manage
device objects.
--*/
typedef enum {
VF_DEVOBJ_PDO = 0,
VF_DEVOBJ_BUS_FILTER,
VF_DEVOBJ_LOWER_DEVICE_FILTER,
VF_DEVOBJ_LOWER_CLASS_FILTER,
VF_DEVOBJ_FDO,
VF_DEVOBJ_UPPER_DEVICE_FILTER,
VF_DEVOBJ_UPPER_CLASS_FILTER
} VF_DEVOBJ_TYPE, *PVF_DEVOBJ_TYPE;
VOID
VfDevObjPreAddDevice(
IN PDEVICE_OBJECT PhysicalDeviceObject,
IN PDRIVER_OBJECT DriverObject,
IN PDRIVER_ADD_DEVICE AddDeviceFunction,
IN VF_DEVOBJ_TYPE DevObjType
);
VOID
VfDevObjPostAddDevice(
IN PDEVICE_OBJECT PhysicalDeviceObject,
IN PDRIVER_OBJECT DriverObject,
IN PDRIVER_ADD_DEVICE AddDeviceFunction,
IN VF_DEVOBJ_TYPE DevObjType,
IN NTSTATUS Result
);
VOID
VfDevObjAdjustFdoForVerifierFilters(
IN OUT PDEVICE_OBJECT *FunctionalDeviceObject
);
VOID
VerifierIoAttachDeviceToDeviceStack(
IN PDEVICE_OBJECT NewDevice,
IN PDEVICE_OBJECT ExistingDevice
);
VOID
VerifierIoDetachDevice(
IN PDEVICE_OBJECT LowerDevice
);
VOID
VerifierIoDeleteDevice(
IN PDEVICE_OBJECT DeviceObject
);

View File

@ -0,0 +1,34 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vffilter.h
Abstract:
This header contains prototypes for using the verifier driver filter.
--*/
VOID
VfFilterInit(
VOID
);
VOID
VfFilterAttach(
IN PDEVICE_OBJECT PhysicalDeviceObject,
IN VF_DEVOBJ_TYPE DeviceObjectType
);
BOOLEAN
VfFilterIsVerifierFilterObject(
IN PDEVICE_OBJECT DeviceObject
);

View File

@ -0,0 +1,24 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfgeneric.h
Abstract:
This header contains prototypes for verifying generic IRPs are handled
correctly.
--*/
VOID
VfGenericInit(
VOID
);

View File

@ -0,0 +1,24 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfinit.h
Abstract:
This header exposes the routines necessary to initialize the driver verifier.
--*/
VOID
FASTCALL
VfInitVerifier(
IN ULONG MmFlags
);

View File

@ -0,0 +1,216 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfirp.h
Abstract:
This module contains prototypes for functions used to manage IRPs used in
the verification process.
--*/
struct _IOV_STACK_LOCATION;
struct _IOV_REQUEST_PACKET;
struct _IOFCALLDRIVER_STACKDATA;
typedef struct _IOV_STACK_LOCATION *PIOV_STACK_LOCATION;
typedef struct _IOV_REQUEST_PACKET *PIOV_REQUEST_PACKET;
typedef struct _IOV_SESSION_DATA *PIOV_SESSION_DATA;
typedef struct _IOFCALLDRIVER_STACKDATA *PIOFCALLDRIVER_STACKDATA;
//
// Mini-snapshots of the IRP are stored on the stack for cases when the
// verifier needs to inform the developer as to the mistake, but no longer
// has the original IRP in memory. Because these may be stored on the stack,
// they need to be small and light.
//
typedef struct _IRP_MINI_SNAPSHOT {
PIRP Irp;
IO_STACK_LOCATION IoStackLocation;
} IRP_MINI_SNAPSHOT, *PIRP_MINI_SNAPSHOT;
typedef struct _IOV_STACK_LOCATION {
BOOLEAN InUse;
ULONG Flags;
PIOV_STACK_LOCATION RequestsFirstStackLocation;
LIST_ENTRY CallStackData;
PIO_STACK_LOCATION IrpSp;
PVOID LastDispatch;
LARGE_INTEGER PerfDispatchStart;
LARGE_INTEGER PerfStackLocationStart;
PDEVICE_OBJECT ReferencingObject;
LONG ReferencingCount;
IO_STATUS_BLOCK InitialStatusBlock;
IO_STATUS_BLOCK LastStatusBlock;
PETHREAD ThreadDispatchedTo;
} IOV_STACK_LOCATION;
typedef struct _IOV_SESSION_DATA {
PIOV_REQUEST_PACKET IovRequestPacket;
LONG SessionRefCount;
LIST_ENTRY SessionLink;
ULONG SessionFlags;
PETHREAD OriginatorThread;
PDEVICE_OBJECT DeviceLastCalled; // Last device called
ULONG ForwardMethod;
PIRP BestVisibleIrp;
PVERIFIER_SETTINGS_SNAPSHOT VerifierSettings;
IOV_STACK_LOCATION StackData[ANYSIZE_ARRAY];
} IOV_SESSION_DATA;
typedef struct _IOFCALLDRIVER_STACKDATA {
PIOV_SESSION_DATA IovSessionData;
PIOV_STACK_LOCATION IovStackLocation;
PIOV_REQUEST_PACKET IovPacket;
ULONG Flags;
LIST_ENTRY SharedLocationList;
PDRIVER_DISPATCH DispatchRoutine;
NTSTATUS ExpectedStatus;
NTSTATUS NewStatus;
PDEVICE_OBJECT RemovePdo;
IRP_MINI_SNAPSHOT IrpSnapshot;
} IOFCALLDRIVER_STACKDATA;
typedef struct _IOFCOMPLETEREQUEST_STACKDATA {
PIOV_SESSION_DATA IovSessionData;
PIOV_REQUEST_PACKET IovRequestPacket;
BOOLEAN IsRemoveIrp;
LONG LocationsAdvanced;
ULONG RaisedCount;
KIRQL PreviousIrql;
PVOID CompletionRoutine;
} IOFCOMPLETEREQUEST_STACKDATA, *PIOFCOMPLETEREQUEST_STACKDATA;
VOID
FASTCALL
VfIrpInit(
VOID
);
PIRP
FASTCALL
VfIrpAllocate(
IN CCHAR StackSize
);
VOID
FASTCALL
VfIrpMakeTouchable(
IN PIRP Irp
);
VOID
FASTCALL
VfIrpMakeUntouchable(
IN PIRP Irp OPTIONAL
);
VOID
FASTCALL
VfIrpFree(
IN PIRP Irp OPTIONAL
);
VOID
FASTCALL
VerifierIoAllocateIrp1(
IN CCHAR StackSize,
IN BOOLEAN ChargeQuota,
IN OUT PIRP *IrpPointer
);
VOID
FASTCALL
VerifierIoAllocateIrp2(
IN PIRP Irp
);
VOID
FASTCALL
VerifierIoFreeIrp(
IN PIRP Irp,
IN OUT PBOOLEAN FreeHandled
);
VOID
FASTCALL
VerifierIoInitializeIrp(
IN OUT PIRP Irp,
IN USHORT PacketSize,
IN CCHAR StackSize,
IN OUT PBOOLEAN InitializeHandled
);
BOOLEAN
FASTCALL
VfIrpReserveCallStackData(
IN PIRP Irp,
OUT PIOFCALLDRIVER_STACKDATA *IofCallDriverStackData
);
VOID
FASTCALL
VfIrpPrepareAllocaCallStackData(
OUT PIOFCALLDRIVER_STACKDATA IofCallDriverStackData
);
VOID
FASTCALL
VfIrpReleaseCallStackData(
IN PIOFCALLDRIVER_STACKDATA IofCallDriverStackData OPTIONAL
);
//
// VfIrpCallDriverPreprocess is a macro function that may do an alloca as
// part of it's operation. As such callers must be careful not to use
// variable length arrays in a scope that encompasses
// VfIrpCallDriverPreProcess but not VfIrpCallDriverPostProcess.
//
#define VfIrpCallDriverPreProcess(DeviceObject, IrpPointer, CallStackData, CallerAddress) \
if (!VfIrpReserveCallStackData(*(IrpPointer), (CallStackData))) { \
*(CallStackData) = alloca(sizeof(IOFCALLDRIVER_STACKDATA)); \
VfIrpPrepareAllocaCallStackData(*(CallStackData)); \
} \
IovpCallDriver1((DeviceObject), (IrpPointer), *(CallStackData), (CallerAddress))
#define VfIrpCallDriverPostProcess(DeviceObject, FinalStatus, CallStackData) \
IovpCallDriver2(DeviceObject, FinalStatus, CallStackData); \
VfIrpReleaseCallStackData(CallStackData)
BOOLEAN
VfIrpSendSynchronousIrp(
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION TopStackLocation,
IN BOOLEAN Untouchable,
IN NTSTATUS InitialStatus,
IN ULONG_PTR InitialInformation OPTIONAL,
OUT ULONG_PTR *FinalInformation OPTIONAL,
OUT NTSTATUS *FinalStatus OPTIONAL
);
VOID
FASTCALL
VfIrpWatermark(
IN PIRP Irp,
IN ULONG Flags
);

View File

@ -0,0 +1,128 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfirpdb.h
Abstract:
This header exposes prototypes for functions used to manage the database of
IRP tracking data.
--*/
struct _IOV_DATABASE_HEADER;
typedef struct _IOV_DATABASE_HEADER IOV_DATABASE_HEADER;
typedef struct _IOV_DATABASE_HEADER *PIOV_DATABASE_HEADER;
typedef enum _IOV_REFERENCE_TYPE {
IOVREFTYPE_PACKET = 0,
IOVREFTYPE_POINTER
} IOV_REFERENCE_TYPE;
typedef enum {
IRPDBEVENT_POINTER_COUNT_ZERO = 1,
IRPDBEVENT_REFERENCE_COUNT_ZERO
} IRP_DATABASE_EVENT;
typedef VOID (*PFN_IRPDBEVENT_CALLBACK)(
IN PIOV_DATABASE_HEADER IovHeader,
IN PIRP TrackedIrp OPTIONAL,
IN IRP_DATABASE_EVENT Event
);
typedef struct _IOV_DATABASE_HEADER {
PIRP TrackedIrp; // Tracked IRP
KSPIN_LOCK HeaderLock; // Spinlock on data structure
KIRQL LockIrql; // IRQL taken at.
LONG ReferenceCount; // # of reasons to keep this packet
LONG PointerCount; // # of reasons to track by irp addr
ULONG HeaderFlags;
LIST_ENTRY HashLink; // Link in hash table.
LIST_ENTRY ChainLink; // Head is HeadPacket
PIOV_DATABASE_HEADER ChainHead; // First packet in a chain.
PFN_IRPDBEVENT_CALLBACK NotificationCallback;
};
VOID
FASTCALL
VfIrpDatabaseInit(
VOID
);
BOOLEAN
FASTCALL
VfIrpDatabaseEntryInsertAndLock(
IN PIRP Irp,
IN PFN_IRPDBEVENT_CALLBACK NotificationCallback,
IN OUT PIOV_DATABASE_HEADER IovHeader
);
PIOV_DATABASE_HEADER
FASTCALL
VfIrpDatabaseEntryFindAndLock(
IN PIRP Irp
);
VOID
FASTCALL
VfIrpDatabaseEntryAcquireLock(
IN PIOV_DATABASE_HEADER IovHeader OPTIONAL
);
VOID
FASTCALL
VfIrpDatabaseEntryReleaseLock(
IN PIOV_DATABASE_HEADER IovHeader
);
VOID
FASTCALL
VfIrpDatabaseEntryReference(
IN PIOV_DATABASE_HEADER IovHeader,
IN IOV_REFERENCE_TYPE IovRefType
);
VOID
FASTCALL
VfIrpDatabaseEntryDereference(
IN PIOV_DATABASE_HEADER IovHeader,
IN IOV_REFERENCE_TYPE IovRefType
);
VOID
FASTCALL
VfIrpDatabaseEntryAppendToChain(
IN OUT PIOV_DATABASE_HEADER IovExistingHeader,
IN OUT PIOV_DATABASE_HEADER IovNewHeader
);
VOID
FASTCALL
VfIrpDatabaseEntryRemoveFromChain(
IN OUT PIOV_DATABASE_HEADER IovHeader
);
PIOV_DATABASE_HEADER
FASTCALL
VfIrpDatabaseEntryGetChainPrevious(
IN PIOV_DATABASE_HEADER IovHeader
);
PIOV_DATABASE_HEADER
FASTCALL
VfIrpDatabaseEntryGetChainNext(
IN PIOV_DATABASE_HEADER IovHeader
);

View File

@ -0,0 +1,75 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfirplog.h
Abstract:
This header exposes functions for logging IRP events.
--*/
//
// Log-snapshots are retrievable by user mode for profiling and targetted
// probing of stacks. Content-wise they are heavier.
//
typedef struct _IRPLOG_SNAPSHOT {
ULONG Count;
UCHAR MajorFunction;
UCHAR MinorFunction;
UCHAR Flags;
UCHAR Control;
ULONGLONG ArgArray[4];
} IRPLOG_SNAPSHOT, *PIRPLOG_SNAPSHOT;
VOID
VfIrpLogInit(
VOID
);
VOID
VfIrpLogRecordEvent(
IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot,
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
ULONG
VfIrpLogGetIrpDatabaseSiloCount(
VOID
);
NTSTATUS
VfIrpLogLockDatabase(
IN ULONG SiloNumber
);
NTSTATUS
VfIrpLogRetrieveWmiData(
IN ULONG SiloNumber,
OUT PUCHAR OutputBuffer OPTIONAL,
OUT ULONG *OffsetInstanceNameOffsets,
OUT ULONG *InstanceCount,
OUT ULONG *DataBlockOffset,
OUT ULONG *TotalRequiredSize
);
VOID
VfIrpLogUnlockDatabase(
IN ULONG SiloNumber
);
VOID
VfIrpLogDeleteDeviceLogs(
IN PDEVICE_OBJECT DeviceObject
);

View File

@ -0,0 +1,35 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfmacro.h
Abstract:
This header contains a collection of macros used by the verifier.
--*/
//
// This macro takes an array and returns the number of elements in it.
//
#define ARRAY_COUNT(array) (sizeof(array)/sizeof(array[0]))
//
// This macro takes a value and an alignment and rounds the entry up
// appropriately. The alignment MUST be a power of two!
//
#define ALIGN_UP_ULONG(value, alignment) (((value)+(alignment)-1)&(~(alignment-1)))
//
// This macro compares two guids in their binary form for equivalence.
//
#define IS_EQUAL_GUID(a,b) (RtlCompareMemory(a, b, sizeof(GUID)) == sizeof(GUID))

View File

@ -0,0 +1,221 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfmajor.h
Abstract:
This header contains prototypes for per-major IRP code verification.
--*/
//
// Use this major code to register a handler for default or all IRPs (context
// specific to function)
//
#define IRP_MJ_ALL_MAJORS 0xFF
typedef VOID (FASTCALL *PFN_DUMP_IRP_STACK)(
IN PIO_STACK_LOCATION IrpSp
);
typedef VOID (FASTCALL *PFN_VERIFY_NEW_REQUEST)(
IN PIOV_REQUEST_PACKET IrpTrackingData,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
typedef VOID (FASTCALL *PFN_VERIFY_IRP_STACK_DOWNWARD)(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
typedef VOID (FASTCALL *PFN_VERIFY_IRP_STACK_UPWARD)(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN BOOLEAN IsNewlyCompleted,
IN BOOLEAN RequestFinalized
);
typedef BOOLEAN (FASTCALL *PFN_IS_SYSTEM_RESTRICTED_IRP)(
IN PIO_STACK_LOCATION IrpSp
);
typedef BOOLEAN (FASTCALL *PFN_ADVANCE_IRP_STATUS)(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS OriginalStatus,
IN OUT NTSTATUS *StatusToAdvance
);
typedef BOOLEAN (FASTCALL *PFN_IS_VALID_IRP_STATUS)(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS Status
);
typedef BOOLEAN (FASTCALL *PFN_IS_NEW_REQUEST)(
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp
);
typedef VOID (FASTCALL *PFN_VERIFY_NEW_IRP)(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
typedef VOID (FASTCALL *PFN_VERIFY_FINAL_IRP_STACK)(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp
);
typedef VOID (FASTCALL *PFN_TEST_STARTED_PDO_STACK)(
IN PDEVICE_OBJECT PhysicalDeviceObject
);
typedef LOGICAL (FASTCALL *PFN_BUILD_LOG_ENTRY)(
IN PIRP Irp,
IN ULONG CurrentCount,
IN PIRPLOG_SNAPSHOT CurrentEntryArray,
OUT PIRPLOG_SNAPSHOT IrpSnapshot
);
VOID
VfMajorInit(
VOID
);
VOID
FASTCALL
VfMajorRegisterHandlers(
IN UCHAR IrpMajorCode,
IN PFN_DUMP_IRP_STACK DumpIrpStack OPTIONAL,
IN PFN_VERIFY_NEW_REQUEST VerifyNewRequest OPTIONAL,
IN PFN_VERIFY_IRP_STACK_DOWNWARD VerifyStackDownward OPTIONAL,
IN PFN_VERIFY_IRP_STACK_UPWARD VerifyStackUpward OPTIONAL,
IN PFN_IS_SYSTEM_RESTRICTED_IRP IsSystemRestrictedIrp OPTIONAL,
IN PFN_ADVANCE_IRP_STATUS AdvanceIrpStatus OPTIONAL,
IN PFN_IS_VALID_IRP_STATUS IsValidIrpStatus OPTIONAL,
IN PFN_IS_NEW_REQUEST IsNewRequest OPTIONAL,
IN PFN_VERIFY_NEW_IRP VerifyNewIrp OPTIONAL,
IN PFN_VERIFY_FINAL_IRP_STACK VerifyFinalIrpStack OPTIONAL,
IN PFN_TEST_STARTED_PDO_STACK TestStartedPdoStack OPTIONAL,
IN PFN_BUILD_LOG_ENTRY BuildIrpLogEntry OPTIONAL
);
VOID
FASTCALL
VfMajorDumpIrpStack(
IN PIO_STACK_LOCATION IrpSp
);
VOID
FASTCALL
VfMajorVerifyNewRequest(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfMajorVerifyIrpStackDownward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfMajorVerifyIrpStackUpward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN BOOLEAN IsNewlyCompleted,
IN BOOLEAN RequestFinalized
);
BOOLEAN
FASTCALL
VfMajorIsSystemRestrictedIrp(
IN PIO_STACK_LOCATION IrpSp
);
BOOLEAN
FASTCALL
VfMajorAdvanceIrpStatus(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS OriginalStatus,
IN OUT NTSTATUS *StatusToAdvance
);
BOOLEAN
FASTCALL
VfMajorIsValidIrpStatus(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS Status
);
BOOLEAN
FASTCALL
VfMajorIsNewRequest(
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp
);
VOID
FASTCALL
VfMajorVerifyNewIrp(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfMajorVerifyFinalIrpStack(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp
);
VOID
FASTCALL
VfMajorTestStartedPdoStack(
IN PDEVICE_OBJECT PhysicalDeviceObject
);
LOGICAL
FASTCALL
VfMajorBuildIrpLogEntry(
IN PIRP Irp,
IN ULONG CurrentCount,
IN PIRPLOG_SNAPSHOT CurrentEntryArray,
OUT PIRPLOG_SNAPSHOT IrpSnapshot
);

View File

@ -0,0 +1,237 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfmessage.h
Abstract:
This module contains prototypes for functions used to retrieve text and
flags associated with each error.
--*/
//
// The verifier uses tables of messages and with indexes into the tables.
//
typedef ULONG VFMESSAGE_TABLEID;
typedef ULONG VFMESSAGE_ERRORID;
//
// VFM_ flags control how a verifier message is handled.
//
// VFM_FLAG_INITIALIZED - Set when the error template has been updated with
// error-class information
//
// VFM_FLAG_BEEP - Set if error should beep in debugger
//
// VFM_FLAG_ZAPPED - Set if error was "zapped" (ie prints instead of
// stops) via debugger
//
// VFM_FLAG_CLEARED - Set if error was cleared (disabled) in debugger
//
// VFM_DEPLOYMENT_FAILURE - Set if the error is severe enough to warrant
// removal of the driver from a production system
//
// VFM_LOGO_FAILURE - Set if the error should disallow certification
// for the hardware or the driver
//
// VFM_IGNORE_DRIVER_LIST - Set if error should fire regardless of whether
// the offending driver is being verified or not.
//
#define VFM_FLAG_INITIALIZED 0x00000001
#define VFM_FLAG_BEEP 0x00000002
#define VFM_FLAG_ZAPPED 0x00000004
#define VFM_FLAG_CLEARED 0x00000008
#define VFM_DEPLOYMENT_FAILURE 0x00000010
#define VFM_LOGO_FAILURE 0x00000020
#define VFM_IGNORE_DRIVER_LIST 0x00000040
//
// A message class contains VFM_ flags and some generic text describing the
// problem class.
//
typedef struct _VFMESSAGE_CLASS {
ULONG ClassFlags;
PCSTR MessageClassText;
} VFMESSAGE_CLASS, *PVFMESSAGE_CLASS;
typedef VFMESSAGE_CLASS const *PCVFMESSAGE_CLASS;
//
// Individual error template. Identifies the index, the message class it's
// associated with, the parameters it takes along with the formatted text it
// displays. Note the ulong flags field - this should always be preinited to
// zero!
//
typedef struct _VFMESSAGE_TEMPLATE {
VFMESSAGE_ERRORID MessageID;
PCVFMESSAGE_CLASS MessageClass;
ULONG Flags;
PCSTR ParamString;
PCSTR MessageText;
} VFMESSAGE_TEMPLATE, *PVFMESSAGE_TEMPLATE;
//
// Message index 0 is reserved for use in the override tables
//
#define VIMESSAGE_ALL_IDS 0
//
// An override entry allows the verifier to special case generic assertions
// that occur against specific drivers. This is done by overriding the error
// class on the fly.
//
typedef struct _VFMESSAGE_OVERRIDE {
VFMESSAGE_ERRORID MessageID;
PCSTR DriverName;
PCVFMESSAGE_CLASS ReplacementClass;
} VFMESSAGE_OVERRIDE, *PVFMESSAGE_OVERRIDE;
typedef VFMESSAGE_OVERRIDE const *PCVFMESSAGE_OVERRIDE;
//
// The table of errors. Contains the TableID (used for internal lookup),
// bugcheck major ID, array of messages and array of overrides
//
typedef struct _VFMESSAGE_TEMPLATE_TABLE {
VFMESSAGE_TABLEID TableID;
ULONG BugCheckMajor;
PVFMESSAGE_TEMPLATE TemplateArray;
ULONG TemplateCount;
PCVFMESSAGE_OVERRIDE OverrideArray;
ULONG OverrideCount;
} VFMESSAGE_TEMPLATE_TABLE, *PVFMESSAGE_TEMPLATE_TABLE;
//
// Retrieves an internal error table based on ID.
//
VOID
VfMessageRetrieveInternalTable(
IN VFMESSAGE_TABLEID TableID,
OUT PVFMESSAGE_TEMPLATE_TABLE *MessageTable
);
//
// Retrieves and formats the appropriate error message.
//
VOID
VfMessageRetrieveErrorData(
IN PVFMESSAGE_TEMPLATE_TABLE MessageTable OPTIONAL,
IN VFMESSAGE_ERRORID MessageID,
IN PSTR AnsiDriverName,
OUT ULONG *BugCheckMajor,
OUT PCVFMESSAGE_CLASS *MessageClass,
OUT PCSTR *MessageTextTemplate,
OUT PULONG *TemplateFlags
);
//
// This file contains a set of internal message tables.
//
// The IO Verifier Table Index is...
//
#define VFMESSAGE_TABLE_IOVERIFIER 1
//
// IO Verifier Messages
//
typedef enum _DCERROR_ID {
DCERROR_UNSPECIFIED = 0x200,
DCERROR_DELETE_WHILE_ATTACHED,
DCERROR_DETACH_NOT_ATTACHED,
DCERROR_CANCELROUTINE_FORWARDED,
DCERROR_NULL_DEVOBJ_FORWARDED,
DCERROR_QUEUED_IRP_FORWARDED,
DCERROR_NEXTIRPSP_DIRTY,
DCERROR_IRPSP_COPIED,
DCERROR_INSUFFICIENT_STACK_LOCATIONS,
DCERROR_QUEUED_IRP_COMPLETED,
DCERROR_FREE_OF_INUSE_TRACKED_IRP,
DCERROR_FREE_OF_INUSE_IRP,
DCERROR_FREE_OF_THREADED_IRP,
DCERROR_REINIT_OF_ALLOCATED_IRP_WITH_QUOTA,
DCERROR_PNP_IRP_BAD_INITIAL_STATUS,
DCERROR_POWER_IRP_BAD_INITIAL_STATUS,
DCERROR_WMI_IRP_BAD_INITIAL_STATUS,
DCERROR_SKIPPED_DEVICE_OBJECT,
DCERROR_BOGUS_FUNC_TRASHED,
DCERROR_BOGUS_STATUS_TRASHED,
DCERROR_BOGUS_INFO_TRASHED,
DCERROR_PNP_FAILURE_FORWARDED,
DCERROR_PNP_IRP_STATUS_RESET,
DCERROR_PNP_IRP_NEEDS_HANDLING,
DCERROR_PNP_IRP_HANDS_OFF,
DCERROR_POWER_FAILURE_FORWARDED,
DCERROR_POWER_IRP_STATUS_RESET,
DCERROR_INVALID_STATUS,
DCERROR_UNNECCESSARY_COPY,
DCERROR_SHOULDVE_DETACHED,
DCERROR_SHOULDVE_DELETED,
DCERROR_MISSING_DISPATCH_FUNCTION,
DCERROR_WMI_IRP_NOT_FORWARDED,
DCERROR_DELETED_PRESENT_PDO,
DCERROR_BUS_FILTER_ERRONEOUSLY_DETACHED,
DCERROR_BUS_FILTER_ERRONEOUSLY_DELETED,
DCERROR_INCONSISTANT_STATUS,
DCERROR_UNINITIALIZED_STATUS,
DCERROR_IRP_RETURNED_WITHOUT_COMPLETION,
DCERROR_COMPLETION_ROUTINE_PAGABLE,
DCERROR_PENDING_BIT_NOT_MIGRATED,
DCERROR_CANCELROUTINE_ON_FORWARDED_IRP,
DCERROR_PNP_IRP_NEEDS_PDO_HANDLING,
DCERROR_TARGET_RELATION_LIST_EMPTY,
DCERROR_TARGET_RELATION_NEEDS_REF,
DCERROR_BOGUS_PNP_IRP_COMPLETED,
DCERROR_SUCCESSFUL_PNP_IRP_NOT_FORWARDED,
DCERROR_UNTOUCHED_PNP_IRP_NOT_FORWARDED,
DCERROR_BOGUS_POWER_IRP_COMPLETED,
DCERROR_SUCCESSFUL_POWER_IRP_NOT_FORWARDED,
DCERROR_UNTOUCHED_POWER_IRP_NOT_FORWARDED,
DCERROR_PNP_QUERY_CAP_BAD_VERSION,
DCERROR_PNP_QUERY_CAP_BAD_SIZE,
DCERROR_PNP_QUERY_CAP_BAD_ADDRESS,
DCERROR_PNP_QUERY_CAP_BAD_UI_NUM,
DCERROR_RESTRICTED_IRP,
DCERROR_REINIT_OF_ALLOCATED_IRP_WITHOUT_QUOTA,
DCERROR_UNFORWARDED_IRP_COMPLETED,
DCERROR_DISPATCH_CALLED_AT_BAD_IRQL,
DCERROR_BOGUS_MINOR_STATUS_TRASHED,
DCERROR_CANCELROUTINE_AFTER_COMPLETION,
DCERROR_PENDING_RETURNED_NOT_MARKED,
DCERROR_PENDING_MARKED_NOT_RETURNED,
DCERROR_POWER_PAGABLE_NOT_INHERITED,
DCERROR_DOUBLE_DELETION,
DCERROR_DETACHED_IN_SURPRISE_REMOVAL,
DCERROR_DELETED_IN_SURPRISE_REMOVAL,
DCERROR_DO_INITIALIZING_NOT_CLEARED,
DCERROR_DO_FLAG_NOT_COPIED,
DCERROR_INCONSISTANT_DO_FLAGS,
DCERROR_DEVICE_TYPE_NOT_COPIED,
DCERROR_NON_FAILABLE_IRP,
DCERROR_NON_PDO_RETURNED_IN_RELATION,
DCERROR_DUPLICATE_ENUMERATION,
DCERROR_FILE_IO_AT_BAD_IRQL,
DCERROR_MISHANDLED_TARGET_DEVICE_RELATIONS,
DCERROR_PENDING_RETURNED_NOT_MARKED_2,
DCERROR_DDI_REQUIRES_PDO,
DCERROR_MAXIMUM
} DCERROR_ID;

View File

@ -0,0 +1,158 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfpacket.h
Abstract:
This header exposes functions used to manage the verifier packet data that
tracks IRPs.
--*/
//
// Currently, ntddk.h uses up to 0x2000 for Irp->Flags
//
#define IRPFLAG_EXAMINE_MASK 0xC0000000
#define IRPFLAG_EXAMINE_NOT_TRACKED 0x80000000
#define IRPFLAG_EXAMINE_TRACKED 0x40000000
#define IRPFLAG_EXAMINE_UNMARKED 0x00000000
#define TRACKFLAG_ACTIVE 0x00000001
#define IRP_ALLOC_COUNT 8
#define IRP_LOG_ENTRIES 16
typedef enum {
IOV_EVENT_NONE = 0,
IOV_EVENT_IO_ALLOCATE_IRP,
IOV_EVENT_IO_CALL_DRIVER,
IOV_EVENT_IO_CALL_DRIVER_UNWIND,
IOV_EVENT_IO_COMPLETE_REQUEST,
IOV_EVENT_IO_COMPLETION_ROUTINE,
IOV_EVENT_IO_COMPLETION_ROUTINE_UNWIND,
IOV_EVENT_IO_CANCEL_IRP,
IOV_EVENT_IO_FREE_IRP
} IOV_LOG_EVENT;
typedef struct {
IOV_LOG_EVENT Event;
PETHREAD Thread;
PVOID Address;
ULONG_PTR Data;
LARGE_INTEGER TimeStamp;
} IOV_LOG_ENTRY, *PIOV_LOG_ENTRY;
struct _IOV_SESSION_DATA;
struct _IOV_REQUEST_PACKET;
typedef struct _IOV_SESSION_DATA *PIOV_SESSION_DATA;
typedef struct _IOV_REQUEST_PACKET *PIOV_REQUEST_PACKET;
typedef struct _IOV_REQUEST_PACKET {
IOV_DATABASE_HEADER;
ULONG Flags;
KIRQL DepartureIrql; // Irql IRP will be dispatched at.
KIRQL ArrivalIrql; // Irql IRP was sent in at.
LIST_ENTRY SessionHead; // List of all sessions.
CCHAR StackCount; // StackCount of tracked IRP.
ULONG QuotaCharge; // Quota charged against IRP.
PEPROCESS QuotaProcess; // Process quota was charged to.
PIO_COMPLETION_ROUTINE RealIrpCompletionRoutine;
UCHAR RealIrpControl;
PVOID RealIrpContext;
PVOID AllocatorStack[IRP_ALLOC_COUNT];
//
// The following information is for the assertion routines to read.
//
UCHAR TopStackLocation;
CCHAR PriorityBoost; // Boost from IofCompleteRequest
UCHAR LastLocation; // Last location from IofCallDriver
ULONG RefTrackingCount;
//
// This field is only set on surrogate IRPs, and contains the locked system
// VA for the destination of a direct I/O IRP that's being buffered.
//
PUCHAR SystemDestVA;
#if DBG
IOV_LOG_ENTRY LogEntries[IRP_LOG_ENTRIES];
ULONG LogEntryHead;
ULONG LogEntryTail;
#endif
PVERIFIER_SETTINGS_SNAPSHOT VerifierSettings;
PIOV_SESSION_DATA pIovSessionData;
} IOV_REQUEST_PACKET;
PIOV_REQUEST_PACKET
FASTCALL
VfPacketCreateAndLock(
IN PIRP Irp
);
PIOV_REQUEST_PACKET
FASTCALL
VfPacketFindAndLock(
IN PIRP Irp
);
VOID
FASTCALL
VfPacketAcquireLock(
IN PIOV_REQUEST_PACKET IrpTrackingData
);
VOID
FASTCALL
VfPacketReleaseLock(
IN PIOV_REQUEST_PACKET IrpTrackingData
);
VOID
FASTCALL
VfPacketReference(
IN PIOV_REQUEST_PACKET IovPacket,
IN IOV_REFERENCE_TYPE IovRefType
);
VOID
FASTCALL
VfPacketDereference(
IN PIOV_REQUEST_PACKET IovPacket,
IN IOV_REFERENCE_TYPE IovRefType
);
PIOV_SESSION_DATA
FASTCALL
VfPacketGetCurrentSessionData(
IN PIOV_REQUEST_PACKET IovPacket
);
VOID
FASTCALL
VfPacketLogEntry(
IN PIOV_REQUEST_PACKET IovPacket,
IN IOV_LOG_EVENT IovLogEvent,
IN PVOID Address,
IN ULONG_PTR Data
);

View File

@ -0,0 +1,84 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfpnp.h
Abstract:
This header contains prototypes for verifying Pnp IRPs are handled
correctly.
--*/
VOID
VfPnpInit(
VOID
);
VOID
FASTCALL
VfPnpVerifyNewRequest(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfPnpVerifyIrpStackDownward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfPnpVerifyIrpStackUpward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN BOOLEAN IsNewlyCompleted,
IN BOOLEAN RequestFinalized
);
VOID
FASTCALL
VfPnpDumpIrpStack(
IN PIO_STACK_LOCATION IrpSp
);
BOOLEAN
FASTCALL
VfPnpIsSystemRestrictedIrp(
IN PIO_STACK_LOCATION IrpSp
);
BOOLEAN
FASTCALL
VfPnpAdvanceIrpStatus(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS OriginalStatus,
IN OUT NTSTATUS *StatusToAdvance
);
VOID
FASTCALL
VfPnpTestStartedPdoStack(
IN PDEVICE_OBJECT PhysicalDeviceObject
);

View File

@ -0,0 +1,84 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfpower.h
Abstract:
This header contains prototypes for verifying Power IRPs are handled
correctly.
--*/
VOID
VfPowerInit(
VOID
);
VOID
FASTCALL
VfPowerVerifyNewRequest(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfPowerVerifyIrpStackDownward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfPowerVerifyIrpStackUpward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN BOOLEAN IsNewlyCompleted,
IN BOOLEAN RequestFinalized
);
VOID
FASTCALL
VfPowerDumpIrpStack(
IN PIO_STACK_LOCATION IrpSp
);
BOOLEAN
FASTCALL
VfPowerIsSystemRestrictedIrp(
IN PIO_STACK_LOCATION IrpSp
);
BOOLEAN
FASTCALL
VfPowerAdvanceIrpStatus(
IN PIO_STACK_LOCATION IrpSp,
IN NTSTATUS OriginalStatus,
IN OUT NTSTATUS *StatusToAdvance
);
VOID
FASTCALL
VfPowerTestStartedPdoStack(
IN PDEVICE_OBJECT PhysicalDeviceObject
);

View File

@ -0,0 +1,32 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfpragma.h
Abstract:
This header contains disable instructions for W4 warnings generated
by public headers. This way we can still compile modules at W4.
--*/
//
// Disable W4 level warnings generated by public headers.
//
#pragma warning(disable:4214) // bit field types other than int
#pragma warning(disable:4201) // nameless struct/union
#pragma warning(disable:4324) // alignment sensitive to declspec
#pragma warning(disable:4127) // condition expression is constant
#pragma warning(disable:4115) // named type definition in parentheses
#pragma warning(disable:4232) // dllimport not static
#pragma warning(disable:4206) // translation unit empty
#pragma warning(disable:4054) // function pointer to data pointer cast

View File

@ -0,0 +1,29 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfprint.h
Abstract:
This header exposes prototypes required when outputting various data types
to the debugger.
--*/
VOID
VfPrintDumpIrpStack(
IN PIO_STACK_LOCATION IrpSp
);
VOID
VfPrintDumpIrp(
IN PIRP IrpToFlag
);

View File

@ -0,0 +1,31 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfrandom.h
Abstract:
This header exposes support for random number generation as needed by the
verifier.
--*/
VOID
VfRandomInit(
VOID
);
ULONG
FASTCALL
VfRandomGetNumber(
IN ULONG Minimum,
IN ULONG Maximum
);

View File

@ -0,0 +1,316 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfsettings.h
Abstract:
This header contains prototypes for manipulating verifier options and
values.
--*/
typedef PVOID PVERIFIER_SETTINGS_SNAPSHOT;
typedef enum {
//
// This option lets the verifer begin tracking all IRPs. It must be enabled
// for most of the other IRP verification options to work.
//
VERIFIER_OPTION_TRACK_IRPS = 1,
//
// This option forces all IRPs to be allocated from the special pool.
// VERIFIER_OPTION_TRACK_IRPS need not be enabled.
//
VERIFIER_OPTION_MONITOR_IRP_ALLOCS,
//
// This option enables various checks for basic/common IRP handling mistakes.
//
VERIFIER_OPTION_POLICE_IRPS,
//
// This option enables checks specific to major/minor codes.
//
VERIFIER_OPTION_MONITOR_MAJORS,
//
// This option causes the call stacks of IRP dispatch and completion
// routines to be seeded with 0xFFFFFFFF. This value is illegal for a
// status code, and such seeding flushes out uninitialized variable bugs.
//
VERIFIER_OPTION_SEEDSTACK,
//
// This option sends a bogus QueryDeviceRelations IRP to newly built stacks.
// The particular IRP sent is of type -1, and has a -1 passed in for the
// device list.
//
VERIFIER_OPTION_RELATION_IGNORANCE_TEST,
//
// This option causes the verifier to stop on unnecessary IRP stack copies.
// It is useful for optimizing drivers.
//
VERIFIER_OPTION_FLAG_UNNECCESSARY_COPIES,
VERIFIER_OPTION_SEND_BOGUS_WMI_IRPS,
VERIFIER_OPTION_SEND_BOGUS_POWER_IRPS,
//
// If this option is enabled, the verifier makes sure drivers mark the IRP
// pending if and only if STATUS_PENDING is returned, and visa versa.
//
VERIFIER_OPTION_MONITOR_PENDING_IO,
//
// If this option is enabled, the verifier makes all IRPs return in an
// asynchronous manner. Specifically, all IRPs are marked pending, and
// STATUS_PENDING is returned from every IoCallDriver.
//
VERIFIER_OPTION_FORCE_PENDING,
//
// If this option is enabled, the verifier will change the status code of
// successful IRPs to alternate success status's. This catches many IRP
// forwarding bugs.
//
VERIFIER_OPTION_ROTATE_STATUS,
//
// If this option is enabled, the verifier will undo the effects of
// IoSkipCurrentIrpStackLocation so that all stacks appear to be copied.
// (Exempting the case where an IRP was forwarded to another stack)
//
VERIFIER_OPTION_CONSUME_ALWAYS,
//
// If this option is enabled, the verifier will update SRB's to handle
// surrogate IRPs. Some SCSI IRPs can't be surrogated unless the
// SRB->OriginalRequest pointer is updated. This is due to a busted SRB
// architecture. Note that the technique used to identify an SRB IRP is
// "fuzzy", and could in theory touch an IRP it shouldn't have!
//
VERIFIER_OPTION_SMASH_SRBS,
//
// If this option is enabled, the verifier will replace original IRPs with
// surrogates when traveling down the stack. The surrogates are allocated
// from special pool, and get freed immediately upon completion. This lets
// the verifier catch drivers that touch IRPs after they're completed.
//
VERIFIER_OPTION_SURROGATE_IRPS,
//
// If this option is enabled, the verifier buffers all direct I/O. It does
// this by allocating an alternate MDL and copying the MDL contents back
// to user mode only after IRP completion. This allows overruns, underruns,
// and late accesses to be detected.
//
VERIFIER_OPTION_BUFFER_DIRECT_IO,
//
// If this option is enabled, the verifier delays completion of all IRPs
// via timer. VERIFIER_OPTION_FORCE_PENDING is set by inference.
//
VERIFIER_OPTION_DEFER_COMPLETION,
//
// If this option is enabled, the verifier completes every IRP at
// PASSIVE_LEVEL, regardless of major function.
// VERIFIER_OPTION_FORCE_PENDING is set by inference.
//
VERIFIER_OPTION_COMPLETE_AT_PASSIVE,
//
// If this option is enabled, the verifier completes every IRP at
// DISPATCH_LEVEL, regardless of major function.
//
VERIFIER_OPTION_COMPLETE_AT_DISPATCH,
//
// If this option is enabled, the verifier monitors cancel routines to make
// sure they are cleared appropriately.
//
VERIFIER_OPTION_VERIFY_CANCEL_LOGIC,
VERIFIER_OPTION_RANDOMLY_CANCEL_IRPS,
//
// If this option is enabled, the verifier inserts filter device objects
// into WDM stacks to ensure IRPs are properly forwarded.
//
VERIFIER_OPTION_INSERT_WDM_FILTERS,
//
// If this option is enabled, the verifier monitors drivers to ensure they
// don't send system reserved IRPs to WDM stacks.
//
VERIFIER_OPTION_PROTECT_RESERVED_IRPS,
//
// If this option is enabled, the verifier walks the entire stack to ensure
// the DO bits are properly built during AddDevice. This includes the
// DO_POWER_PAGABLE flag.
//
VERIFIER_OPTION_VERIFY_DO_FLAGS,
//
// If this option is enabled, the verifier watches Target device relation
// IRPs to make sure the device object is properly reference counted.
//
VERIFIER_OPTION_TEST_TARGET_REFCOUNT,
//
// Lets you detect when deadlocks can occur
//
VERIFIER_OPTION_DETECT_DEADLOCKS,
//
// If this option is enabled, all dma operations will be hooked and
// validated.
//
VERIFIER_OPTION_VERIFY_DMA,
//
// This option double buffers all dma and erects guard pages on each side
// of all common buffers and mapped buffers. Is memory-intensive but can
// catch hardware buffer overruns and drivers that don't flush adapter
// buffers.
//
VERIFIER_OPTION_DOUBLE_BUFFER_DMA,
//
// If this option is enabled, you get notified when the performance counter
// is being naughty
//
VERIFIER_OPTION_VERIFY_PERFORMANCE_COUNTER,
//
// If this option is enabled, the verifier checks for implementations of
// IRP_MN_DEVICE_USAGE_NOTIFICATION and IRP_MN_SURPRISE_REMOVAL. The
// verifier will also make sure PnP Cancel IRPs are not explicitely failed.
//
VERIFIER_OPTION_EXTENDED_REQUIRED_IRPS,
//
// If this option is enabled, the verifier mixes up device relations
// to ensure drivers aren't depending on ordering.
//
VERIFIER_OPTION_SCRAMBLE_RELATIONS,
//
// If this option is enabled, the verifier ensures proper detaching and
// deletion occurs on removes and surprise removes.
//
VERIFIER_OPTION_MONITOR_REMOVES,
//
// If this option is enabled, the verifier ensures device relations only
// consist of PDO's.
//
VERIFIER_OPTION_EXAMINE_RELATION_PDOS,
//
// If this option is enabled, the verifier enabled hardware verification
// (bus specific behavior)
//
VERIFIER_OPTION_HARDWARE_VERIFICATION,
//
// If this option is enabled, the verifier ensures system BIOS verification
//
VERIFIER_OPTION_SYSTEM_BIOS_VERIFICATION,
//
// If this option is enabled, the verifier exposes IRP history data that
// can be used to test for security holes.
//
VERIFIER_OPTION_EXPOSE_IRP_HISTORY,
VERIFIER_OPTION_MAX
} VERIFIER_OPTION;
typedef enum {
//
// If VERIFIER_OPTION_DEFER_COMPLETION is set, this value contains the time
// an IRP will be deferred, in 100us units.
//
VERIFIER_VALUE_IRP_DEFERRAL_TIME = 1,
//
// This shall be the percentage of allocates to fail during low resource
// simulation.
//
VERIFIER_VALUE_LOW_RESOURCE_PERCENTAGE,
//
// If VERIFIER_OPTION_EXPOSE_IRP_HISTORY is set, this value contains the
// amount of IRPs per device object to log.
//
VERIFIER_VALUE_IRPLOG_COUNT,
VERIFIER_VALUE_MAX
} VERIFIER_VALUE;
VOID
FASTCALL
VfSettingsInit(
IN ULONG MmFlags
);
BOOLEAN
FASTCALL
VfSettingsIsOptionEnabled(
IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
IN VERIFIER_OPTION VerifierOption
);
VOID
FASTCALL
VfSettingsCreateSnapshot(
IN OUT PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot
);
ULONG
FASTCALL
VfSettingsGetSnapshotSize(
VOID
);
VOID
FASTCALL
VfSettingsSetOption(
IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
IN VERIFIER_OPTION VerifierOption,
IN BOOLEAN Setting
);
VOID
FASTCALL
VfSettingsGetValue(
IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
IN VERIFIER_VALUE VerifierValue,
OUT ULONG *Value
);
VOID
FASTCALL
VfSettingsSetValue(
IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
IN VERIFIER_VALUE VerifierValue,
IN ULONG Value
);

View File

@ -0,0 +1,25 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfstack.h
Abstract:
This header contains prototypes for verifying drivers don't improperly use
thread stacks.
--*/
VOID
FASTCALL
VfStackSeedStack(
IN ULONG Seed
);

View File

@ -0,0 +1,23 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vftriage
Abstract:
Code to support driver verifier triage decisions and running mode.
--*/
#ifndef INCLUDED_VFTRIAGE_H
#define INCLUDED_VFTRIAGE_H
#endif // #ifndef INCLUDED_VFTRIAGE_H

View File

@ -0,0 +1,38 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfutil.h
Abstract:
This header contains prototypes for various functions required to do driver
verification.
--*/
typedef enum {
VFMP_INSTANT = 0,
VFMP_INSTANT_NONPAGED
} MEMORY_PERSISTANCE;
BOOLEAN
VfUtilIsMemoryRangeReadable(
IN PVOID Location,
IN size_t Length,
IN MEMORY_PERSISTANCE Persistance
);
VOID
VfSetVerifierEnabled (
LOGICAL Value
);

View File

@ -0,0 +1,70 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
If you do not agree to the terms, do not use the code.
Module Name:
vfwmi.h
Abstract:
This header contains prototypes for verifying System Control IRPs are
handled correctly.
--*/
VOID
VfWmiInit(
VOID
);
VOID
FASTCALL
VfWmiVerifyNewRequest(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfWmiVerifyIrpStackDownward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PDEVICE_OBJECT DeviceObject,
IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN PVOID CallerAddress OPTIONAL
);
VOID
FASTCALL
VfWmiVerifyIrpStackUpward(
IN PIOV_REQUEST_PACKET IovPacket,
IN PIO_STACK_LOCATION IrpSp,
IN PIOV_STACK_LOCATION RequestHeadLocationData,
IN PIOV_STACK_LOCATION StackLocationData,
IN BOOLEAN IsNewlyCompleted,
IN BOOLEAN RequestFinalized
);
VOID
FASTCALL
VfWmiDumpIrpStack(
IN PIO_STACK_LOCATION IrpSp
);
VOID
FASTCALL
VfWmiTestStartedPdoStack(
IN PDEVICE_OBJECT PhysicalDeviceObject
);

File diff suppressed because it is too large Load Diff

26
WRK-v1.2/base/ntos/cache/BUILD/makefile vendored Normal file
View File

@ -0,0 +1,26 @@
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# You may only use this code if you agree to the terms of the Windows Research Kernel Source Code License agreement (see License.txt).
# If you do not agree to the terms, do not use the code.
#
library = $(module)
asobjs=
ccarchobjs=
ccobjs= \
$(OBJ)\cachedat.obj \
$(OBJ)\cachesub.obj \
$(OBJ)\copysup.obj \
$(OBJ)\fssup.obj \
$(OBJ)\lazyrite.obj \
$(OBJ)\logsup.obj \
$(OBJ)\mdlsup.obj \
$(OBJ)\pinsup.obj \
$(OBJ)\ccperf.obj \
$(OBJ)\vacbsup.obj
!include $(ntos)\BUILD\makefile.build

View File

@ -0,0 +1 @@
*** This file is here solely to preserve the directory structure when WRK is xcopy'ed ***

Some files were not shown because too many files have changed in this diff Show More