ReactOS 0.4.15-dev-5666-gc548b97
driver.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for driver.c:

Go to the source code of this file.

Classes

struct  _LOAD_UNLOAD_PARAMS
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _LOAD_UNLOAD_PARAMS LOAD_UNLOAD_PARAMS
 
typedef struct _LOAD_UNLOAD_PARAMSPLOAD_UNLOAD_PARAMS
 

Functions

NTSTATUS IopDoLoadUnloadDriver (_In_opt_ PUNICODE_STRING RegistryPath, _Inout_ PDRIVER_OBJECT *DriverObject)
 Process load and unload driver operations. This is mostly for NtLoadDriver and NtUnloadDriver, because their code should run inside PsInitialSystemProcess.
 
NTSTATUS NTAPI IopInvalidDeviceRequest (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI IopDeleteDriver (IN PVOID ObjectBody)
 
NTSTATUS IopGetDriverNames (_In_ HANDLE ServiceHandle, _Out_ PUNICODE_STRING DriverName, _Out_opt_ PUNICODE_STRING ServiceName)
 
BOOLEAN NTAPI IopSuffixUnicodeString (IN PCUNICODE_STRING String1, IN PCUNICODE_STRING String2)
 
VOID FASTCALL IopDisplayLoadingMessage (PUNICODE_STRING ServiceName)
 
NTSTATUS FASTCALL IopNormalizeImagePath (_Inout_ _When_(return >=0, _At_(ImagePath->Buffer, _Post_notnull_ __drv_allocatesMem(Mem))) PUNICODE_STRING ImagePath, _In_ PUNICODE_STRING ServiceName)
 
NTSTATUS IopInitializeDriverModule (_In_ PLDR_DATA_TABLE_ENTRY ModuleObject, _In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *OutDriverObject, _Out_ NTSTATUS *DriverEntryStatus)
 Initialize a loaded driver.
 
NTSTATUS NTAPI MiResolveImageReferences (IN PVOID ImageBase, IN PUNICODE_STRING ImageFileDirectory, IN PUNICODE_STRING NamePrefix OPTIONAL, OUT PCHAR *MissingApi, OUT PWCHAR *MissingDriver, OUT PLOAD_IMPORTS *LoadImports)
 
NTSTATUS NTAPI LdrProcessDriverModule (PLDR_DATA_TABLE_ENTRY LdrEntry, PUNICODE_STRING FileName, PLDR_DATA_TABLE_ENTRY *ModuleObject)
 
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance (PUNICODE_STRING DeviceInstance)
 
static BOOLEAN IopInitializeBuiltinDriver (IN PLDR_DATA_TABLE_ENTRY BootLdrEntry)
 
VOID FASTCALL IopInitializeBootDrivers (VOID)
 
VOID FASTCALL IopInitializeSystemDrivers (VOID)
 
NTSTATUS NTAPI IopUnloadDriver (PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
 
VOID NTAPI IopReinitializeDrivers (VOID)
 
VOID NTAPI IopReinitializeBootDrivers (VOID)
 
NTSTATUS NTAPI IoCreateDriver (_In_opt_ PUNICODE_STRING DriverName, _In_ PDRIVER_INITIALIZE InitializationFunction)
 
VOID NTAPI IoDeleteDriver (_In_ PDRIVER_OBJECT DriverObject)
 
VOID NTAPI IoRegisterBootDriverReinitialization (IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
 
VOID NTAPI IoRegisterDriverReinitialization (IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
 
NTSTATUS NTAPI IoAllocateDriverObjectExtension (IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
 
PVOID NTAPI IoGetDriverObjectExtension (IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
 
NTSTATUS IopLoadDriver (_In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *DriverObject)
 
static VOID NTAPI IopLoadUnloadDriverWorker (_Inout_ PVOID Parameter)
 
NTSTATUS NTAPI NtLoadDriver (IN PUNICODE_STRING DriverServiceName)
 
NTSTATUS NTAPI NtUnloadDriver (IN PUNICODE_STRING DriverServiceName)
 

Variables

ERESOURCE IopDriverLoadResource
 
LIST_ENTRY DriverReinitListHead
 
KSPIN_LOCK DriverReinitListLock
 
PLIST_ENTRY DriverReinitTailEntry
 
PLIST_ENTRY DriverBootReinitTailEntry
 
LIST_ENTRY DriverBootReinitListHead
 
KSPIN_LOCK DriverBootReinitListLock
 
UNICODE_STRING IopHardwareDatabaseKey
 
static const WCHAR ServicesKeyName [] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
 
POBJECT_TYPE IoDriverObjectType = NULL
 
BOOLEAN ExpInTextModeSetup
 
BOOLEAN PnpSystemInit
 
BOOLEAN PnPBootDriversLoaded
 
KEVENT PiEnumerationFinished
 
USHORT IopGroupIndex
 
PLIST_ENTRY IopGroupTable
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file driver.c.

Typedef Documentation

◆ LOAD_UNLOAD_PARAMS

◆ PLOAD_UNLOAD_PARAMS

Function Documentation

◆ IoAllocateDriverObjectExtension()

NTSTATUS NTAPI IoAllocateDriverObjectExtension ( IN PDRIVER_OBJECT  DriverObject,
IN PVOID  ClientIdentificationAddress,
IN ULONG  DriverObjectExtensionSize,
OUT PVOID DriverObjectExtension 
)

Definition at line 1811 of file driver.c.

1815{
1816 KIRQL OldIrql;
1817 PIO_CLIENT_EXTENSION DriverExtensions, NewDriverExtension;
1818 BOOLEAN Inserted = FALSE;
1819
1820 /* Assume failure */
1821 *DriverObjectExtension = NULL;
1822
1823 /* Allocate the extension */
1824 NewDriverExtension = ExAllocatePoolWithTag(NonPagedPool,
1825 sizeof(IO_CLIENT_EXTENSION) +
1826 DriverObjectExtensionSize,
1828 if (!NewDriverExtension) return STATUS_INSUFFICIENT_RESOURCES;
1829
1830 /* Clear the extension for teh caller */
1831 RtlZeroMemory(NewDriverExtension,
1832 sizeof(IO_CLIENT_EXTENSION) + DriverObjectExtensionSize);
1833
1834 /* Acqure lock */
1836
1837 /* Fill out the extension */
1839
1840 /* Loop the current extensions */
1841 DriverExtensions = IoGetDrvObjExtension(DriverObject)->
1842 ClientDriverExtension;
1843 while (DriverExtensions)
1844 {
1845 /* Check if the identifier matches */
1846 if (DriverExtensions->ClientIdentificationAddress ==
1848 {
1849 /* We have a collision, break out */
1850 break;
1851 }
1852
1853 /* Go to the next one */
1854 DriverExtensions = DriverExtensions->NextExtension;
1855 }
1856
1857 /* Check if we didn't collide */
1858 if (!DriverExtensions)
1859 {
1860 /* Link this one in */
1861 NewDriverExtension->NextExtension =
1862 IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
1863 IoGetDrvObjExtension(DriverObject)->ClientDriverExtension =
1864 NewDriverExtension;
1865 Inserted = TRUE;
1866 }
1867
1868 /* Release the lock */
1870
1871 /* Check if insertion failed */
1872 if (!Inserted)
1873 {
1874 /* Free the entry and fail */
1875 ExFreePoolWithTag(NewDriverExtension, TAG_DRIVER_EXTENSION);
1877 }
1878
1879 /* Otherwise, return the pointer */
1880 *DriverObjectExtension = NewDriverExtension + 1;
1881 return STATUS_SUCCESS;
1882}
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define NonPagedPool
Definition: env_spec_w32.h:307
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment KeRaiseIrqlToDpcLevel
Definition: CrNtStubs.h:68
static LPWSTR ClientIdentificationAddress
Definition: hidclass.c:16
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define IoGetDrvObjExtension(DriverObject)
Definition: io.h:136
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID ClientIdentificationAddress
Definition: iotypes.h:829
struct _IO_CLIENT_EXTENSION * NextExtension
Definition: iotypes.h:828
#define TAG_DRIVER_EXTENSION
Definition: tag.h:61
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792

Referenced by _IRQL_requires_max_(), DriverEntry(), HidRegisterMinidriver(), KoDriverInitialize(), KsInitializeDriver(), Mx::MxAllocateDriverObjectExtension(), NdisMRegisterMiniport(), PciIdeXInitialize(), ScsiPortInitialize(), StorPortInitialize(), StreamClassRegisterAdapter(), VideoPortInitialize(), and WdfWriteKmdfVersionToRegistry().

◆ IoCreateDriver()

NTSTATUS NTAPI IoCreateDriver ( _In_opt_ PUNICODE_STRING  DriverName,
_In_ PDRIVER_INITIALIZE  InitializationFunction 
)

Definition at line 1561 of file driver.c.

1564{
1565 WCHAR NameBuffer[100];
1566 USHORT NameLength;
1567 UNICODE_STRING LocalDriverName;
1570 ULONG ObjectSize;
1572 UNICODE_STRING ServiceKeyName;
1574 ULONG i, RetryCount = 0;
1575
1576try_again:
1577 /* First, create a unique name for the driver if we don't have one */
1578 if (!DriverName)
1579 {
1580 /* Create a random name and set up the string */
1581 NameLength = (USHORT)swprintf(NameBuffer,
1582 DRIVER_ROOT_NAME L"%08u",
1584 LocalDriverName.Length = NameLength * sizeof(WCHAR);
1585 LocalDriverName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
1586 LocalDriverName.Buffer = NameBuffer;
1587 }
1588 else
1589 {
1590 /* So we can avoid another code path, use a local var */
1591 LocalDriverName = *DriverName;
1592 }
1593
1594 /* Initialize the Attributes */
1595 ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
1597 &LocalDriverName,
1599 NULL,
1600 NULL);
1601
1602 /* Create the Object */
1606 KernelMode,
1607 NULL,
1608 ObjectSize,
1609 0,
1610 0,
1611 (PVOID*)&DriverObject);
1612 if (!NT_SUCCESS(Status)) return Status;
1613
1614 DPRINT("IopCreateDriver(): created DO %p\n", DriverObject);
1615
1616 /* Set up the Object */
1617 RtlZeroMemory(DriverObject, ObjectSize);
1619 DriverObject->Size = sizeof(DRIVER_OBJECT);
1621 DriverObject->DriverExtension = (PDRIVER_EXTENSION)(DriverObject + 1);
1622 DriverObject->DriverExtension->DriverObject = DriverObject;
1623 DriverObject->DriverInit = InitializationFunction;
1624 /* Loop all Major Functions */
1625 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1626 {
1627 /* Invalidate each function */
1628 DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
1629 }
1630
1631 /* Set up the service key name buffer */
1632 ServiceKeyName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
1633 ServiceKeyName.Buffer = ExAllocatePoolWithTag(PagedPool, LocalDriverName.MaximumLength, TAG_IO);
1634 if (!ServiceKeyName.Buffer)
1635 {
1636 /* Fail */
1640 }
1641
1642 /* For builtin drivers, the ServiceKeyName is equal to DriverName */
1643 RtlCopyUnicodeString(&ServiceKeyName, &LocalDriverName);
1644 ServiceKeyName.Buffer[ServiceKeyName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1645 DriverObject->DriverExtension->ServiceKeyName = ServiceKeyName;
1646
1647 /* Make a copy of the driver name to store in the driver object */
1648 DriverObject->DriverName.MaximumLength = LocalDriverName.Length;
1649 DriverObject->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool,
1650 DriverObject->DriverName.MaximumLength,
1651 TAG_IO);
1652 if (!DriverObject->DriverName.Buffer)
1653 {
1654 /* Fail */
1658 }
1659
1660 RtlCopyUnicodeString(&DriverObject->DriverName, &LocalDriverName);
1661
1662 /* Add the Object and get its handle */
1664 NULL,
1666 0,
1667 NULL,
1668 &hDriver);
1669
1670 /* Eliminate small possibility when this function is called more than
1671 once in a row, and KeTickCount doesn't get enough time to change */
1672 if (!DriverName && (Status == STATUS_OBJECT_NAME_COLLISION) && (RetryCount < 100))
1673 {
1674 RetryCount++;
1675 goto try_again;
1676 }
1677
1678 if (!NT_SUCCESS(Status)) return Status;
1679
1680 /* Now reference it */
1682 0,
1684 KernelMode,
1686 NULL);
1687
1688 /* Close the extra handle */
1690
1691 if (!NT_SUCCESS(Status))
1692 {
1693 /* Fail */
1696 return Status;
1697 }
1698
1699 /* Finally, call its init function */
1700 DPRINT("Calling driver entrypoint at %p\n", InitializationFunction);
1701 Status = InitializationFunction(DriverObject, NULL);
1702 if (!NT_SUCCESS(Status))
1703 {
1704 /* If it didn't work, then kill the object */
1705 DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &LocalDriverName, Status);
1708 return Status;
1709 }
1710
1711 /* Windows does this fixup, keep it for compatibility */
1712 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1713 {
1714 /*
1715 * Make sure the driver didn't set any dispatch entry point to NULL!
1716 * Doing so is illegal; drivers shouldn't touch entry points they
1717 * do not implement.
1718 */
1719
1720 /* Check if it did so anyway */
1721 if (!DriverObject->MajorFunction[i])
1722 {
1723 /* Print a warning in the debug log */
1724 DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
1725 &DriverObject->DriverName, i);
1726
1727 /* Fix it up */
1728 DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
1729 }
1730 }
1731
1732 /* Return the Status */
1733 return Status;
1734}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf
Definition: precomp.h:40
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define DRIVER_ROOT_NAME
Definition: ldr.h:5
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FILE_READ_DATA
Definition: nt_native.h:628
#define UNICODE_NULL
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
POBJECT_TYPE IoDriverObjectType
Definition: driver.c:33
NTSTATUS NTAPI IopInvalidDeviceRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: driver.c:65
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2935
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:951
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1361
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT
Definition: sndvol32.h:71
PDRIVER_INITIALIZE DriverInit
Definition: iotypes.h:2286
ULONG LowPart
Definition: ketypes.h:917
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_IO
Definition: tag.h:80
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2227
struct _DRIVER_OBJECT DRIVER_OBJECT
struct _DRIVER_EXTENSION * PDRIVER_EXTENSION
#define IO_TYPE_DRIVER
#define IRP_MJ_MAXIMUM_FUNCTION
#define ObDereferenceObject
Definition: obfuncs.h:203
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by HaliInitPnpDriver(), IopInitializeBootDrivers(), IopInitializePlugPlayServices(), and WmiInitialize().

◆ IoDeleteDriver()

VOID NTAPI IoDeleteDriver ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 1741 of file driver.c.

1743{
1744 /* Simply dereference the Object */
1746}

◆ IoGetDriverObjectExtension()

PVOID NTAPI IoGetDriverObjectExtension ( IN PDRIVER_OBJECT  DriverObject,
IN PVOID  ClientIdentificationAddress 
)

Definition at line 1889 of file driver.c.

1891{
1892 KIRQL OldIrql;
1893 PIO_CLIENT_EXTENSION DriverExtensions;
1894
1895 /* Acquire lock */
1897
1898 /* Loop the list until we find the right one */
1899 DriverExtensions = IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
1900 while (DriverExtensions)
1901 {
1902 /* Check for a match */
1903 if (DriverExtensions->ClientIdentificationAddress ==
1905 {
1906 /* Break out */
1907 break;
1908 }
1909
1910 /* Keep looping */
1911 DriverExtensions = DriverExtensions->NextExtension;
1912 }
1913
1914 /* Release lock */
1916
1917 /* Return nothing or the extension */
1918 if (!DriverExtensions) return NULL;
1919 return DriverExtensions + 1;
1920}

Referenced by _Dispatch_type_(), _IRQL_requires_max_(), ClassAddDevice(), ClassDispatchPnp(), ClassGetPdoId(), ClassPnpQueryFdoRelations(), ClassPnpStartDevice(), ClassUnload(), ConDrvCreateController(), ConDrvDeleteController(), CreateClassDeviceObject(), CreateGreenFdo(), DestroyPortDriver(), GreenAddDevice(), GreenDispatch(), HidClassAddDevice(), i8042RemoveDevice(), IntVideoPortAddDevice(), IntVideoPortFilterResourceRequirements(), IntVideoPortPnPStartDevice(), KeyboardAddDevice(), KopDispatchCreate(), KsAddDevice(), Mx::MxGetDriverObjectExtension(), NdisIAddDevice(), PciIdeXAddDevice(), PciIdeXFdoStartDevice(), PortAddDevice(), PortUnload(), ScreenAddDevice(), ScsiPortInitialize(), SermouseAddDevice(), StorPortInitialize(), StreamClassAddDevice(), StreamClassStartDevice(), VfdCreateDevice(), VfdDeleteDevice(), VfdStoreLink(), VfdUnloadDriver(), VideoPortGetAccessRanges(), VideoPortInitialize(), and WdfDeleteKmdfVersionFromRegistry().

◆ IopDeleteDriver()

VOID NTAPI IopDeleteDriver ( IN PVOID  ObjectBody)

Definition at line 77 of file driver.c.

78{
79 PDRIVER_OBJECT DriverObject = ObjectBody;
80 PIO_CLIENT_EXTENSION DriverExtension, NextDriverExtension;
81 PAGED_CODE();
82
83 DPRINT1("Deleting driver object '%wZ'\n", &DriverObject->DriverName);
84
85 /* There must be no device objects remaining at this point */
86 ASSERT(!DriverObject->DeviceObject);
87
88 /* Get the extension and loop them */
89 DriverExtension = IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
90 while (DriverExtension)
91 {
92 /* Get the next one */
93 NextDriverExtension = DriverExtension->NextExtension;
95
96 /* Move on */
97 DriverExtension = NextDriverExtension;
98 }
99
100 /* Check if the driver image is still loaded */
101 if (DriverObject->DriverSection)
102 {
103 /* Unload it */
104 MmUnloadSystemImage(DriverObject->DriverSection);
105 }
106
107 /* Check if it has a name */
108 if (DriverObject->DriverName.Buffer)
109 {
110 /* Free it */
111 ExFreePool(DriverObject->DriverName.Buffer);
112 }
113
114 /* Check if it has a service key name */
115 if (DriverObject->DriverExtension->ServiceKeyName.Buffer)
116 {
117 /* Free it */
118 ExFreePool(DriverObject->DriverExtension->ServiceKeyName.Buffer);
119 }
120}
#define PAGED_CODE()
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NTAPI MmUnloadSystemImage(IN PVOID ImageHandle)
Definition: sysldr.c:898
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31

Referenced by IopCreateObjectTypes().

◆ IopDisplayLoadingMessage()

VOID FASTCALL IopDisplayLoadingMessage ( PUNICODE_STRING  ServiceName)

Definition at line 315 of file driver.c.

316{
317 CHAR TextBuffer[256];
318 UNICODE_STRING DotSys = RTL_CONSTANT_STRING(L".SYS");
319
320 if (ExpInTextModeSetup) return;
321 if (!KeLoaderBlock) return;
324 "%s%sSystem32\\Drivers\\%wZ%s\r\n",
328 IopSuffixUnicodeString(&DotSys, ServiceName) ? "" : ".SYS");
330}
static WCHAR ServiceName[]
Definition: browser.c:19
char TextBuffer[BUFFERLEN]
Definition: combotst.c:45
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
NTHALAPI VOID NTAPI HalDisplayString(PUCHAR String)
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
BOOLEAN NTAPI IopSuffixUnicodeString(IN PCUNICODE_STRING String1, IN PCUNICODE_STRING String2)
Definition: driver.c:281
BOOLEAN ExpInTextModeSetup
Definition: init.c:69
PSTR ArcBootDeviceName
Definition: arc.h:503
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define snprintf
Definition: wintirpc.h:48
char CHAR
Definition: xmlstorage.h:175

Referenced by IopInitializeBuiltinDriver(), and IopLoadDriver().

◆ IopDoLoadUnloadDriver()

NTSTATUS IopDoLoadUnloadDriver ( _In_opt_ PUNICODE_STRING  RegistryPath,
_Inout_ PDRIVER_OBJECT DriverObject 
)

Process load and unload driver operations. This is mostly for NtLoadDriver and NtUnloadDriver, because their code should run inside PsInitialSystemProcess.

Parameters
[in]RegistryPathThe registry path
DriverObjectThe driver object
Returns
Status of the operation

Definition at line 2084 of file driver.c.

2087{
2088 LOAD_UNLOAD_PARAMS LoadParams;
2089
2090 /* Prepare parameters block */
2091 LoadParams.RegistryPath = RegistryPath;
2092 LoadParams.DriverObject = *DriverObject;
2093
2095 {
2096 LoadParams.SetEvent = TRUE;
2098
2099 /* Initialize and queue a work item */
2100 ExInitializeWorkItem(&LoadParams.WorkItem, IopLoadUnloadDriverWorker, &LoadParams);
2102
2103 /* And wait till it completes */
2105 }
2106 else
2107 {
2108 /* If we're already in a system process, call it right here */
2109 LoadParams.SetEvent = FALSE;
2110 IopLoadUnloadDriverWorker(&LoadParams);
2111 }
2112
2113 return LoadParams.Status;
2114}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
static VOID NTAPI IopLoadUnloadDriverWorker(_Inout_ PVOID Parameter)
Definition: driver.c:2038
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
WORK_QUEUE_ITEM WorkItem
Definition: driver.c:50
NTSTATUS Status
Definition: driver.c:48
BOOLEAN SetEvent
Definition: driver.c:53
PUNICODE_STRING RegistryPath
Definition: driver.c:49
PDRIVER_OBJECT DriverObject
Definition: driver.c:52
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
@ UserRequest
Definition: ketypes.h:409
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by IopUnloadDriver(), and NtLoadDriver().

◆ IopGetDeviceObjectFromDeviceInstance()

PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance ( PUNICODE_STRING  DeviceInstance)

Definition at line 118 of file plugplay.c.

119{
121 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
122
123 if (IopRootDeviceNode == NULL)
124 return NULL;
125
126 if (DeviceInstance == NULL ||
127 DeviceInstance->Length == 0)
128 {
130 {
133 }
134 else
135 return NULL;
136 }
137
138 /* Traverse the device tree to find the matching device node */
139 DeviceInstanceContext.InstancePath = DeviceInstance;
140 DeviceInstanceContext.DeviceObject = NULL;
144 &DeviceInstanceContext);
146
147 /* In case of error or instance not found, this will still be NULL from above. */
148 return DeviceInstanceContext.DeviceObject;
149}
static const WCHAR DeviceInstance[]
Definition: interface.c:28
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:229
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
NTSTATUS IopFindDeviceInstanceTraverse(_In_ PDEVICE_NODE DeviceNode, _Inout_ PVOID Context)
Definition: plugplay.c:98
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:855
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopInitializeBuiltinDriver().

◆ IopGetDriverNames()

NTSTATUS IopGetDriverNames ( _In_ HANDLE  ServiceHandle,
_Out_ PUNICODE_STRING  DriverName,
_Out_opt_ PUNICODE_STRING  ServiceName 
)

Definition at line 123 of file driver.c.

127{
128 UNICODE_STRING driverName = {.Buffer = NULL}, serviceName;
131
132 PAGED_CODE();
133
134 /* 1. Check the "ObjectName" field in the driver's registry key (it has priority) */
135 status = IopGetRegistryValue(ServiceHandle, L"ObjectName", &kvInfo);
136 if (NT_SUCCESS(status))
137 {
138 /* We've got the ObjectName, use it as the driver name */
139 if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
140 {
141 ExFreePool(kvInfo);
143 }
144
145 driverName.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
146 driverName.MaximumLength = kvInfo->DataLength;
148 if (!driverName.Buffer)
149 {
150 ExFreePool(kvInfo);
152 }
153
154 RtlMoveMemory(driverName.Buffer,
155 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
156 driverName.Length);
157 driverName.Buffer[driverName.Length / sizeof(WCHAR)] = UNICODE_NULL;
158 ExFreePool(kvInfo);
159 }
160
161 /* Check whether we need to get ServiceName as well, either to construct
162 * the driver name (because we could not use "ObjectName"), or because
163 * it is requested by the caller. */
164 PKEY_BASIC_INFORMATION basicInfo = NULL;
165 if (!NT_SUCCESS(status) || ServiceName != NULL)
166 {
167 /* Retrieve the necessary buffer size */
168 ULONG infoLength;
169 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
171 {
173 goto Cleanup;
174 }
175
176 /* Allocate the buffer and retrieve the data */
177 basicInfo = ExAllocatePoolWithTag(PagedPool, infoLength, TAG_IO);
178 if (!basicInfo)
179 {
181 goto Cleanup;
182 }
183
184 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, basicInfo, infoLength, &infoLength);
185 if (!NT_SUCCESS(status))
186 {
187 goto Cleanup;
188 }
189
190 serviceName.Length = basicInfo->NameLength;
191 serviceName.MaximumLength = basicInfo->NameLength;
192 serviceName.Buffer = basicInfo->Name;
193 }
194
195 /* 2. There is no "ObjectName" - construct it ourselves. Depending on the driver type,
196 * it will be either "\Driver<ServiceName>" or "\FileSystem<ServiceName>" */
197 if (driverName.Buffer == NULL)
198 {
199 ASSERT(basicInfo); // Container for serviceName
200
201 /* Retrieve the driver type */
202 ULONG driverType;
203 status = IopGetRegistryValue(ServiceHandle, L"Type", &kvInfo);
204 if (!NT_SUCCESS(status))
205 {
206 goto Cleanup;
207 }
208 if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
209 {
210 ExFreePool(kvInfo);
212 goto Cleanup;
213 }
214
215 RtlMoveMemory(&driverType,
216 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
217 sizeof(ULONG));
218 ExFreePool(kvInfo);
219
220 /* Compute the necessary driver name string size */
221 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
222 driverName.MaximumLength = sizeof(FILESYSTEM_ROOT_NAME);
223 else
224 driverName.MaximumLength = sizeof(DRIVER_ROOT_NAME);
225
226 driverName.MaximumLength += serviceName.Length;
227 driverName.Length = 0;
228
229 /* Allocate and build it */
231 if (!driverName.Buffer)
232 {
234 goto Cleanup;
235 }
236
237 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
239 else
241
243 }
244
245 if (ServiceName != NULL)
246 {
247 ASSERT(basicInfo); // Container for serviceName
248
249 /* Allocate a copy for the caller */
251 if (!buf)
252 {
254 goto Cleanup;
255 }
256 RtlMoveMemory(buf, serviceName.Buffer, serviceName.Length);
257 ServiceName->MaximumLength = serviceName.Length;
258 ServiceName->Length = serviceName.Length;
259 ServiceName->Buffer = buf;
260 }
261
262 *DriverName = driverName;
264
265Cleanup:
266 if (basicInfo)
267 ExFreePoolWithTag(basicInfo, TAG_IO);
268
269 if (!NT_SUCCESS(status) && driverName.Buffer)
270 ExFreePoolWithTag(driverName.Buffer, TAG_IO);
271
272 return status;
273}
static const WCHAR Cleanup[]
Definition: register.c:80
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define REG_SZ
Definition: layer.c:22
#define FILESYSTEM_ROOT_NAME
Definition: ldr.h:6
@ KeyBasicInformation
Definition: nt_native.h:1131
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSTATUS NTAPI IopGetRegistryValue(IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
Definition: pnpmgr.c:1606
#define STATUS_ILL_FORMED_SERVICE_ENTRY
Definition: ntstatus.h:588
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: ps.c:97
char serviceName[]
Definition: tftpd.cpp:34
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define SERVICE_RECOGNIZER_DRIVER
Definition: cmtypes.h:956
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:954

Referenced by IopInitializeDriverModule(), and PiAttachFilterDriversCallback().

◆ IopInitializeBootDrivers()

VOID FASTCALL IopInitializeBootDrivers ( VOID  )

Definition at line 1008 of file driver.c.

1009{
1010 PLIST_ENTRY ListHead, NextEntry, NextEntry2;
1011 PLDR_DATA_TABLE_ENTRY LdrEntry;
1013 UNICODE_STRING DriverName;
1014 ULONG i, Index;
1015 PDRIVER_INFORMATION DriverInfo, DriverInfoTag;
1017 PBOOT_DRIVER_LIST_ENTRY BootEntry;
1018 DPRINT("IopInitializeBootDrivers()\n");
1019
1020 /* Create the RAW FS built-in driver */
1021 RtlInitUnicodeString(&DriverName, L"\\FileSystem\\RAW");
1022
1023 Status = IoCreateDriver(&DriverName, RawFsDriverEntry);
1024 if (!NT_SUCCESS(Status))
1025 {
1026 /* Fail */
1027 return;
1028 }
1029
1030 /* Get highest group order index */
1032 if (IopGroupIndex == 0xFFFF)
1033 {
1035 }
1036
1037 /* Allocate the group table */
1039 IopGroupIndex * sizeof(LIST_ENTRY),
1040 TAG_IO);
1041 if (IopGroupTable == NULL)
1042 {
1044 }
1045
1046 /* Initialize the group table lists */
1047 for (i = 0; i < IopGroupIndex; i++) InitializeListHead(&IopGroupTable[i]);
1048
1049 /* Loop the boot modules */
1050 ListHead = &KeLoaderBlock->LoadOrderListHead;
1051 for (NextEntry = ListHead->Flink;
1052 NextEntry != ListHead;
1053 NextEntry = NextEntry->Flink)
1054 {
1055 /* Get the entry */
1056 LdrEntry = CONTAINING_RECORD(NextEntry,
1058 InLoadOrderLinks);
1059
1060 /* Check if the DLL needs to be initialized */
1061 if (LdrEntry->Flags & LDRP_DRIVER_DEPENDENT_DLL)
1062 {
1063 /* Call its entrypoint */
1064 MmCallDllInitialize(LdrEntry, NULL);
1065 }
1066 }
1067
1068 /* Loop the boot drivers */
1069 ListHead = &KeLoaderBlock->BootDriverListHead;
1070 for (NextEntry = ListHead->Flink;
1071 NextEntry != ListHead;
1072 NextEntry = NextEntry->Flink)
1073 {
1074 /* Get the entry */
1075 BootEntry = CONTAINING_RECORD(NextEntry,
1077 Link);
1078
1079 // FIXME: TODO: This LdrEntry is to be used in a special handling
1080 // for SETUPLDR (a similar procedure is done on Windows), where
1081 // the loader would, under certain conditions, be loaded in the
1082 // SETUPLDR-specific code block below...
1083#if 0
1084 /* Get the driver loader entry */
1085 LdrEntry = BootEntry->LdrEntry;
1086#endif
1087
1088 /* Allocate our internal accounting structure */
1090 sizeof(DRIVER_INFORMATION),
1091 TAG_IO);
1092 if (DriverInfo)
1093 {
1094 /* Zero it and initialize it */
1097 DriverInfo->DataTableEntry = BootEntry;
1098
1099 /* Open the registry key */
1101 NULL,
1102 &BootEntry->RegistryPath,
1103 KEY_READ);
1104 DPRINT("IopOpenRegistryKeyEx(%wZ) returned 0x%08lx\n", &BootEntry->RegistryPath, Status);
1105#if 0
1106 if (NT_SUCCESS(Status))
1107#else // Hack still needed...
1108 if ((NT_SUCCESS(Status)) || /* ReactOS HACK for SETUPLDR */
1109 ((KeLoaderBlock->SetupLdrBlock) && ((KeyHandle = (PVOID)1)))) // yes, it's an assignment!
1110#endif
1111 {
1112 /* Save the handle */
1114
1115 /* Get the group oder index */
1117
1118 /* Get the tag position */
1120
1121 /* Insert it into the list, at the right place */
1123 NextEntry2 = IopGroupTable[Index].Flink;
1124 while (NextEntry2 != &IopGroupTable[Index])
1125 {
1126 /* Get the driver info */
1127 DriverInfoTag = CONTAINING_RECORD(NextEntry2,
1129 Link);
1130
1131 /* Check if we found the right tag position */
1132 if (DriverInfoTag->TagPosition > DriverInfo->TagPosition)
1133 {
1134 /* We're done */
1135 break;
1136 }
1137
1138 /* Next entry */
1139 NextEntry2 = NextEntry2->Flink;
1140 }
1141
1142 /* Insert us right before the next entry */
1143 NextEntry2 = NextEntry2->Blink;
1144 InsertHeadList(NextEntry2, &DriverInfo->Link);
1145 }
1146 }
1147 }
1148
1149 /* Loop each group index */
1150 for (i = 0; i < IopGroupIndex; i++)
1151 {
1152 /* Loop each group table */
1153 for (NextEntry = IopGroupTable[i].Flink;
1154 NextEntry != &IopGroupTable[i];
1155 NextEntry = NextEntry->Flink)
1156 {
1157 /* Get the entry */
1158 DriverInfo = CONTAINING_RECORD(NextEntry,
1160 Link);
1161
1162 /* Get the driver loader entry */
1163 LdrEntry = DriverInfo->DataTableEntry->LdrEntry;
1164
1165 /* Initialize it */
1166 if (IopInitializeBuiltinDriver(LdrEntry))
1167 {
1168 // it does not make sense to enumerate the tree if there are no new devices added
1171 NULL,
1172 NULL);
1173 }
1174 }
1175 }
1176
1177 /* HAL Root Bus is being initialized before loading the boot drivers so this may cause issues
1178 * when some devices are not being initialized with their drivers. This flag is used to delay
1179 * all actions with devices (except PnP root device) until boot drivers are loaded.
1180 * See PiQueueDeviceAction function
1181 */
1183
1184 DbgPrint("BOOT DRIVERS LOADED\n");
1185
1188 NULL,
1189 NULL);
1190}
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define InsertHeadList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DbgPrint
Definition: hal.h:12
#define LDRP_DRIVER_DEPENDENT_DLL
Definition: ldrtypes.h:56
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
DRIVER_INFORMATION DriverInfo
Definition: main.c:59
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1455
NTSTATUS NTAPI RawFsDriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: rawfs.c:1193
@ PiActionEnumRootDevices
Definition: io.h:527
@ PiActionEnumDeviceTree
Definition: io.h:526
USHORT NTAPI PpInitGetGroupOrderIndex(IN HANDLE ServiceHandle)
Definition: pnpinit.c:155
USHORT NTAPI PipGetDriverTagPriority(IN HANDLE ServiceHandle)
Definition: pnpinit.c:198
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2655
NTSTATUS NTAPI MmCallDllInitialize(IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN PLIST_ENTRY ListHead)
Definition: sysldr.c:295
static BOOLEAN IopInitializeBuiltinDriver(IN PLDR_DATA_TABLE_ENTRY BootLdrEntry)
Definition: driver.c:792
NTSTATUS NTAPI IoCreateDriver(_In_opt_ PUNICODE_STRING DriverName, _In_ PDRIVER_INITIALIZE InitializationFunction)
Definition: driver.c:1561
PLIST_ENTRY IopGroupTable
Definition: driver.c:41
USHORT IopGroupIndex
Definition: driver.c:40
BOOLEAN PnPBootDriversLoaded
Definition: pnpinit.c:26
Definition: arc.h:199
UNICODE_STRING RegistryPath
Definition: arc.h:202
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:203
HANDLE ServiceHandle
Definition: io.h:406
PBOOT_DRIVER_LIST_ENTRY DataTableEntry
Definition: io.h:405
LIST_ENTRY Link
Definition: io.h:403
USHORT TagPosition
Definition: io.h:407
Definition: btrfs_drv.h:1876
ULONG Flags
Definition: ntddk_ex.h:207
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
LIST_ENTRY LoadOrderListHead
Definition: arc.h:493
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:511
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static int Link(const char **args)
Definition: vfdcmd.c:2414
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by IoInitSystem().

◆ IopInitializeBuiltinDriver()

static BOOLEAN IopInitializeBuiltinDriver ( IN PLDR_DATA_TABLE_ENTRY  BootLdrEntry)
static

Definition at line 792 of file driver.c.

793{
796 PWCHAR Buffer, FileNameWithoutPath;
797 PWSTR FileExtension;
798 PUNICODE_STRING ModuleName = &BootLdrEntry->BaseDllName;
799 PLDR_DATA_TABLE_ENTRY LdrEntry;
800 PLIST_ENTRY NextEntry;
803
804 /*
805 * Display 'Loading XXX...' message
806 */
809
811 ModuleName->Length + sizeof(UNICODE_NULL),
812 TAG_IO);
813 if (Buffer == NULL)
814 {
815 return FALSE;
816 }
817
820
821 /*
822 * Generate filename without path (not needed by freeldr)
823 */
824 FileNameWithoutPath = wcsrchr(Buffer, L'\\');
825 if (FileNameWithoutPath == NULL)
826 {
827 FileNameWithoutPath = Buffer;
828 }
829 else
830 {
831 FileNameWithoutPath++;
832 }
833
834 /*
835 * Strip the file extension from ServiceName
836 */
837 Success = RtlCreateUnicodeString(&ServiceName, FileNameWithoutPath);
839 if (!Success)
840 {
841 return FALSE;
842 }
843
844 FileExtension = wcsrchr(ServiceName.Buffer, L'.');
845 if (FileExtension != NULL)
846 {
847 ServiceName.Length -= (USHORT)wcslen(FileExtension) * sizeof(WCHAR);
848 FileExtension[0] = UNICODE_NULL;
849 }
850
852
853 // Make the registry path for the driver
854 RegistryPath.Length = 0;
855 RegistryPath.MaximumLength = sizeof(ServicesKeyName) + ServiceName.Length;
857 if (RegistryPath.Buffer == NULL)
858 {
859 return FALSE;
860 }
864
865 HANDLE serviceHandle;
868 if (!NT_SUCCESS(Status))
869 {
870 return FALSE;
871 }
872
873 /* Lookup the new Ldr entry in PsLoadedModuleList */
874 for (NextEntry = PsLoadedModuleList.Flink;
875 NextEntry != &PsLoadedModuleList;
876 NextEntry = NextEntry->Flink)
877 {
878 LdrEntry = CONTAINING_RECORD(NextEntry,
880 InLoadOrderLinks);
882 {
883 break;
884 }
885 }
886 ASSERT(NextEntry != &PsLoadedModuleList);
887
888 /*
889 * Initialize the driver
890 */
891 NTSTATUS driverEntryStatus;
893 serviceHandle,
895 &driverEntryStatus);
896
897 if (!NT_SUCCESS(Status))
898 {
899 DPRINT1("Driver '%wZ' load failed, status (%x)\n", ModuleName, Status);
900 return FALSE;
901 }
902
903 // The driver has been loaded, now check if where are any PDOs
904 // for that driver, and queue AddDevice call for them.
905 // The check is possible because HKLM/SYSTEM/CCS/Services/<ServiceName>/Enum directory
906 // is populated upon a new device arrival based on a (critical) device database
907
908 // Legacy drivers may add devices inside DriverEntry.
909 // We're lazy and always assume that they are doing so
910 BOOLEAN deviceAdded = !!(DriverObject->Flags & DRVO_LEGACY_DRIVER);
911
912 HANDLE enumServiceHandle;
913 UNICODE_STRING enumName = RTL_CONSTANT_STRING(L"Enum");
914
915 Status = IopOpenRegistryKeyEx(&enumServiceHandle, serviceHandle, &enumName, KEY_READ);
916 ZwClose(serviceHandle);
917
918 if (NT_SUCCESS(Status))
919 {
920 ULONG instanceCount = 0;
922 Status = IopGetRegistryValue(enumServiceHandle, L"Count", &kvInfo);
923 if (!NT_SUCCESS(Status))
924 {
925 goto Cleanup;
926 }
927 if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
928 {
929 ExFreePool(kvInfo);
930 goto Cleanup;
931 }
932
933 RtlMoveMemory(&instanceCount,
934 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
935 sizeof(ULONG));
936 ExFreePool(kvInfo);
937
938 DPRINT("Processing %u instances for %wZ module\n", instanceCount, ModuleName);
939
940 for (ULONG i = 0; i < instanceCount; i++)
941 {
942 WCHAR num[11];
943 UNICODE_STRING instancePath;
944 RtlStringCchPrintfW(num, sizeof(num), L"%u", i);
945
946 Status = IopGetRegistryValue(enumServiceHandle, num, &kvInfo);
947 if (!NT_SUCCESS(Status))
948 {
949 continue;
950 }
951 if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
952 {
953 ExFreePool(kvInfo);
954 continue;
955 }
956
957 instancePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
958 instancePath.MaximumLength = kvInfo->DataLength;
960 instancePath.MaximumLength,
961 TAG_IO);
962 if (instancePath.Buffer)
963 {
964 RtlMoveMemory(instancePath.Buffer,
965 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
966 instancePath.Length);
967 instancePath.Buffer[instancePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
968
970 if (pdo != NULL)
971 {
974 deviceAdded = TRUE;
975 }
976 else
977 {
978 DPRINT1("No device node found matching instance path '%wZ'\n", &instancePath);
979 }
980 }
981
982 ExFreePool(kvInfo);
983 }
984
985 ZwClose(enumServiceHandle);
986 }
987Cleanup:
988 /* Remove extra reference from IopInitializeDriverModule */
990
991 return deviceAdded;
992}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1280
Definition: bufpool.h:45
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define wcsrchr
Definition: compat.h:16
@ Success
Definition: eventcreate.c:712
GLuint GLuint num
Definition: glext.h:9618
VOID NTAPI InbvIndicateProgress(VOID)
Gives some progress feedback, without specifying any explicit number of progress steps or percentage....
Definition: inbv.c:625
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
@ PiActionAddBootDevices
Definition: io.h:529
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:118
static const WCHAR ServicesKeyName[]
Definition: driver.c:31
NTSTATUS IopInitializeDriverModule(_In_ PLDR_DATA_TABLE_ENTRY ModuleObject, _In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *OutDriverObject, _Out_ NTSTATUS *DriverEntryStatus)
Initialize a loaded driver.
Definition: driver.c:428
VOID FASTCALL IopDisplayLoadingMessage(PUNICODE_STRING ServiceName)
Definition: driver.c:315
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
ACPI_SIZE Length
Definition: actypes.h:1053
uint16_t * PWSTR
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2226

Referenced by IopInitializeBootDrivers().

◆ IopInitializeDriverModule()

NTSTATUS IopInitializeDriverModule ( _In_ PLDR_DATA_TABLE_ENTRY  ModuleObject,
_In_ HANDLE  ServiceHandle,
_Out_ PDRIVER_OBJECT OutDriverObject,
_Out_ NTSTATUS DriverEntryStatus 
)

Initialize a loaded driver.

Parameters
[in]ModuleObjectModule object representing the driver. It can be retrieved by IopLoadServiceModule. Freed on failure, so in a such case this should not be accessed anymore
[in]ServiceHandleHandle to a driver's CCS/Services/<ServiceName> key
[out]DriverObjectThis contains the driver object if it was created (even with unsuccessfull result)
[out]DriverEntryStatusThis contains the status value returned by the driver's DriverEntry routine (will not be valid of the return value is not STATUS_SUCCESS or STATUS_FAILED_DRIVER_ENTRY)
Returns
Status of the operation

Definition at line 428 of file driver.c.

433{
436
437 PAGED_CODE();
438
439 Status = IopGetDriverNames(ServiceHandle, &DriverName, &ServiceName);
440 if (!NT_SUCCESS(Status))
441 {
442 MmUnloadSystemImage(ModuleObject);
443 return Status;
444 }
445
446 DPRINT("Driver name: '%wZ'\n", &DriverName);
447
448 /*
449 * Retrieve the driver's PE image NT header and perform some sanity checks.
450 * NOTE: We suppose that since the driver has been successfully loaded,
451 * its NT and optional headers are all valid and have expected sizes.
452 */
453 PIMAGE_NT_HEADERS NtHeaders = RtlImageNtHeader(ModuleObject->DllBase);
454 ASSERT(NtHeaders);
455 // NOTE: ModuleObject->SizeOfImage is actually (number of PTEs)*PAGE_SIZE.
456 ASSERT(ModuleObject->SizeOfImage == ROUND_TO_PAGES(NtHeaders->OptionalHeader.SizeOfImage));
457 ASSERT(ModuleObject->EntryPoint == RVA(ModuleObject->DllBase, NtHeaders->OptionalHeader.AddressOfEntryPoint));
458
459 /* Obtain the registry path for the DriverInit routine */
460 PKEY_NAME_INFORMATION nameInfo;
461 ULONG infoLength;
462 Status = ZwQueryKey(ServiceHandle, KeyNameInformation, NULL, 0, &infoLength);
464 {
465 nameInfo = ExAllocatePoolWithTag(NonPagedPool, infoLength, TAG_IO);
466 if (nameInfo)
467 {
468 Status = ZwQueryKey(ServiceHandle,
470 nameInfo,
471 infoLength,
472 &infoLength);
473 if (NT_SUCCESS(Status))
474 {
475 RegistryPath.Length = nameInfo->NameLength;
476 RegistryPath.MaximumLength = nameInfo->NameLength;
477 RegistryPath.Buffer = nameInfo->Name;
478 }
479 else
480 {
481 ExFreePoolWithTag(nameInfo, TAG_IO);
482 }
483 }
484 else
485 {
487 }
488 }
489 else
490 {
492 }
493
494 if (!NT_SUCCESS(Status))
495 {
497 RtlFreeUnicodeString(&DriverName);
498 MmUnloadSystemImage(ModuleObject);
499 return Status;
500 }
501
502 /* Create the driver object */
503 ULONG ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
504 OBJECT_ATTRIBUTES objAttrs;
505 PDRIVER_OBJECT driverObject;
507 &DriverName,
509 NULL,
510 NULL);
511
514 &objAttrs,
516 NULL,
517 ObjectSize,
518 0,
519 0,
520 (PVOID*)&driverObject);
521 if (!NT_SUCCESS(Status))
522 {
523 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
525 RtlFreeUnicodeString(&DriverName);
526 MmUnloadSystemImage(ModuleObject);
527 DPRINT1("Error while creating driver object \"%wZ\" status %x\n", &DriverName, Status);
528 return Status;
529 }
530
531 DPRINT("Created driver object 0x%p for \"%wZ\"\n", driverObject, &DriverName);
532
533 RtlZeroMemory(driverObject, ObjectSize);
534 driverObject->Type = IO_TYPE_DRIVER;
535 driverObject->Size = sizeof(DRIVER_OBJECT);
536
537 /* Set the legacy flag if this is not a WDM driver */
539 driverObject->Flags |= DRVO_LEGACY_DRIVER;
540
541 driverObject->DriverSection = ModuleObject;
542 driverObject->DriverStart = ModuleObject->DllBase;
543 driverObject->DriverSize = ModuleObject->SizeOfImage;
544 driverObject->DriverInit = ModuleObject->EntryPoint;
546 driverObject->DriverExtension = (PDRIVER_EXTENSION)(driverObject + 1);
547 driverObject->DriverExtension->DriverObject = driverObject;
548
549 /* Loop all Major Functions */
550 for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
551 {
552 /* Invalidate each function */
553 driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
554 }
555
556 /* Add the Object and get its handle */
558 Status = ObInsertObject(driverObject, NULL, FILE_READ_DATA, 0, NULL, &hDriver);
559 if (!NT_SUCCESS(Status))
560 {
561 ExFreePoolWithTag(nameInfo, TAG_IO);
563 RtlFreeUnicodeString(&DriverName);
564 return Status;
565 }
566
567 /* Now reference it */
569 0,
572 (PVOID*)&driverObject,
573 NULL);
574
575 /* Close the extra handle */
577
578 if (!NT_SUCCESS(Status))
579 {
580 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
582 RtlFreeUnicodeString(&DriverName);
583 return Status;
584 }
585
586 /* Set up the service key name buffer */
587 UNICODE_STRING serviceKeyName;
588 serviceKeyName.Length = 0;
589 // NULL-terminate for Windows compatibility
590 serviceKeyName.MaximumLength = ServiceName.MaximumLength + sizeof(UNICODE_NULL);
592 serviceKeyName.MaximumLength,
593 TAG_IO);
594 if (!serviceKeyName.Buffer)
595 {
596 ObMakeTemporaryObject(driverObject);
597 ObDereferenceObject(driverObject);
598 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
600 RtlFreeUnicodeString(&DriverName);
602 }
603
604 /* Copy the name and set it in the driver extension */
605 RtlCopyUnicodeString(&serviceKeyName, &ServiceName);
607 driverObject->DriverExtension->ServiceKeyName = serviceKeyName;
608
609 /* Make a copy of the driver name to store in the driver object */
610 UNICODE_STRING driverNamePaged;
611 driverNamePaged.Length = 0;
612 // NULL-terminate for Windows compatibility
613 driverNamePaged.MaximumLength = DriverName.MaximumLength + sizeof(UNICODE_NULL);
614 driverNamePaged.Buffer = ExAllocatePoolWithTag(PagedPool,
615 driverNamePaged.MaximumLength,
616 TAG_IO);
617 if (!driverNamePaged.Buffer)
618 {
619 ObMakeTemporaryObject(driverObject);
620 ObDereferenceObject(driverObject);
621 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
622 RtlFreeUnicodeString(&DriverName);
624 }
625
626 RtlCopyUnicodeString(&driverNamePaged, &DriverName);
627 driverObject->DriverName = driverNamePaged;
628
629 /* Finally, call its init function */
630 Status = driverObject->DriverInit(driverObject, &RegistryPath);
631 *DriverEntryStatus = Status;
632 if (!NT_SUCCESS(Status))
633 {
634 DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &DriverName, Status);
635 // return a special status value in case of failure
637 }
638
639 /* HACK: We're going to say if we don't have any DOs from DriverEntry, then we're not legacy.
640 * Other parts of the I/O manager depend on this behavior */
641 if (!driverObject->DeviceObject)
642 {
643 driverObject->Flags &= ~DRVO_LEGACY_DRIVER;
644 }
645
646 /* Windows does this fixup, keep it for compatibility */
647 for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
648 {
649 /*
650 * Make sure the driver didn't set any dispatch entry point to NULL!
651 * Doing so is illegal; drivers shouldn't touch entry points they
652 * do not implement.
653 */
654
655 /* Check if it did so anyway */
656 if (!driverObject->MajorFunction[i])
657 {
658 /* Print a warning in the debug log */
659 DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
660 &driverObject->DriverName, i);
661
662 /* Fix it up */
663 driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
664 }
665 }
666
667 // TODO: for legacy drivers, unload the driver if it didn't create any DO
668
669 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
670 RtlFreeUnicodeString(&DriverName);
671
672 if (!NT_SUCCESS(Status))
673 {
674 // if the driver entry has been failed, clear the object
675 ObMakeTemporaryObject(driverObject);
676 ObDereferenceObject(driverObject);
677 return Status;
678 }
679
680 *OutDriverObject = driverObject;
681
683
684 /* Set the driver as initialized */
685 IopReadyDeviceObjects(driverObject);
686
688
689 return STATUS_SUCCESS;
690}
DWORD RVA
Definition: compat.h:1262
#define RtlImageNtHeader
Definition: compat.h:806
@ KeyNameInformation
Definition: winternl.h:831
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
Definition: ntimage.h:462
VOID NTAPI IopReadyDeviceObjects(IN PDRIVER_OBJECT Driver)
Definition: device.c:34
VOID NTAPI MmFreeDriverInitialization(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: sysldr.c:1622
BOOLEAN PnpSystemInit
Definition: iomgr.c:17
NTSTATUS IopGetDriverNames(_In_ HANDLE ServiceHandle, _Out_ PUNICODE_STRING DriverName, _Out_opt_ PUNICODE_STRING ServiceName)
Definition: driver.c:123
VOID NTAPI IopReinitializeDrivers(VOID)
Definition: driver.c:1481
UNICODE_STRING IopHardwareDatabaseKey
Definition: driver.c:29
#define STATUS_FAILED_DRIVER_ENTRY
Definition: ntstatus.h:911
struct _DRIVER_OBJECT * DriverObject
Definition: iotypes.h:2219
UNICODE_STRING ServiceKeyName
Definition: iotypes.h:2222
PUNICODE_STRING HardwareDatabase
Definition: iotypes.h:2284
PVOID DriverStart
Definition: iotypes.h:2279
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2289
PVOID DriverSection
Definition: iotypes.h:2281
CSHORT Size
Definition: iotypes.h:2276
ULONG DriverSize
Definition: iotypes.h:2280
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2282
CSHORT Type
Definition: iotypes.h:2275
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2277
UNICODE_STRING DriverName
Definition: iotypes.h:2283
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
int32_t INT
Definition: typedefs.h:58
#define ROUND_TO_PAGES(Size)

Referenced by IopInitializeBuiltinDriver(), and IopLoadDriver().

◆ IopInitializeSystemDrivers()

VOID FASTCALL IopInitializeSystemDrivers ( VOID  )

Definition at line 1195 of file driver.c.

1196{
1197 PUNICODE_STRING *DriverList, *SavedList;
1198
1200
1201 /* No system drivers on the boot cd */
1202 if (KeLoaderBlock->SetupLdrBlock) return; // ExpInTextModeSetup
1203
1204 /* Get the driver list */
1205 SavedList = DriverList = CmGetSystemDriverList();
1206 ASSERT(DriverList);
1207
1208 /* Loop it */
1209 while (*DriverList)
1210 {
1211 /* Load the driver */
1212 ZwLoadDriver(*DriverList);
1213
1214 /* Free the entry */
1215 RtlFreeUnicodeString(*DriverList);
1216 ExFreePool(*DriverList);
1217
1218 /* Next entry */
1220 DriverList++;
1221 }
1222
1223 /* Free the list */
1224 ExFreePool(SavedList);
1225
1228 NULL,
1229 NULL);
1230}
PUNICODE_STRING *NTAPI CmGetSystemDriverList(VOID)
Definition: cmsysini.c:1727
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2714

Referenced by IoInitSystem().

◆ IopInvalidDeviceRequest()

NTSTATUS NTAPI IopInvalidDeviceRequest ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 65 of file driver.c.

68{
69 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
70 Irp->IoStatus.Information = 0;
73}
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by IoCreateDriver(), and IopInitializeDriverModule().

◆ IopLoadDriver()

NTSTATUS IopLoadDriver ( _In_ HANDLE  ServiceHandle,
_Out_ PDRIVER_OBJECT DriverObject 
)

Definition at line 1923 of file driver.c.

1926{
1927 UNICODE_STRING ImagePath;
1929 PLDR_DATA_TABLE_ENTRY ModuleObject;
1931
1933 Status = IopGetRegistryValue(ServiceHandle, L"ImagePath", &kvInfo);
1934 if (NT_SUCCESS(Status))
1935 {
1936 if ((kvInfo->Type != REG_EXPAND_SZ && kvInfo->Type != REG_SZ) || kvInfo->DataLength == 0)
1937 {
1938 ExFreePool(kvInfo);
1940 }
1941
1942 ImagePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
1943 ImagePath.MaximumLength = kvInfo->DataLength;
1945 if (!ImagePath.Buffer)
1946 {
1947 ExFreePool(kvInfo);
1949 }
1950
1951 RtlMoveMemory(ImagePath.Buffer,
1952 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
1953 ImagePath.Length);
1954 ImagePath.Buffer[ImagePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1955 ExFreePool(kvInfo);
1956 }
1957 else
1958 {
1959 return Status;
1960 }
1961
1962 /*
1963 * Normalize the image path for all later processing.
1964 */
1965 Status = IopNormalizeImagePath(&ImagePath, NULL);
1966 if (!NT_SUCCESS(Status))
1967 {
1968 DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
1969 return Status;
1970 }
1971
1972 DPRINT("FullImagePath: '%wZ'\n", &ImagePath);
1973
1976
1977 /*
1978 * Load the driver module
1979 */
1980 DPRINT("Loading module from %wZ\n", &ImagePath);
1981 Status = MmLoadSystemImage(&ImagePath, NULL, NULL, 0, (PVOID)&ModuleObject, &BaseAddress);
1982 RtlFreeUnicodeString(&ImagePath);
1983
1984 if (!NT_SUCCESS(Status))
1985 {
1986 DPRINT("MmLoadSystemImage() failed (Status %lx)\n", Status);
1989 return Status;
1990 }
1991
1992 // Display the loading message
1993 ULONG infoLength;
1994 Status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
1996 {
1998 if (servName)
1999 {
2000 Status = ZwQueryKey(ServiceHandle,
2002 servName,
2003 infoLength,
2004 &infoLength);
2005 if (NT_SUCCESS(Status))
2006 {
2008 .Length = servName->NameLength,
2009 .MaximumLength = servName->NameLength,
2010 .Buffer = servName->Name
2011 };
2012
2014 }
2015 ExFreePoolWithTag(servName, TAG_IO);
2016 }
2017 }
2018
2019 NTSTATUS driverEntryStatus;
2020 Status = IopInitializeDriverModule(ModuleObject,
2021 ServiceHandle,
2023 &driverEntryStatus);
2024 if (!NT_SUCCESS(Status))
2025 {
2026 DPRINT1("IopInitializeDriverModule() failed (Status %lx)\n", Status);
2027 }
2028
2031
2032 return Status;
2033}
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
NTSTATUS NTAPI MmLoadSystemImage(IN PUNICODE_STRING FileName, IN PUNICODE_STRING NamePrefix OPTIONAL, IN PUNICODE_STRING LoadedName OPTIONAL, IN ULONG Flags, OUT PVOID *ModuleObject, OUT PVOID *ImageBaseAddress)
Definition: sysldr.c:2885
ERESOURCE IopDriverLoadResource
Definition: driver.c:19
NTSTATUS FASTCALL IopNormalizeImagePath(_Inout_ _When_(return >=0, _At_(ImagePath->Buffer, _Post_notnull_ __drv_allocatesMem(Mem))) PUNICODE_STRING ImagePath, _In_ PUNICODE_STRING ServiceName)
Definition: driver.c:354
#define TAG_RTLREGISTRY
Definition: tag.h:97

Referenced by IopLoadUnloadDriverWorker(), and PiAttachFilterDriversCallback().

◆ IopLoadUnloadDriverWorker()

static VOID NTAPI IopLoadUnloadDriverWorker ( _Inout_ PVOID  Parameter)
static

Definition at line 2038 of file driver.c.

2040{
2041 PLOAD_UNLOAD_PARAMS LoadParams = Parameter;
2042
2044
2045 if (LoadParams->DriverObject)
2046 {
2047 // unload request
2048 LoadParams->DriverObject->DriverUnload(LoadParams->DriverObject);
2049 LoadParams->Status = STATUS_SUCCESS;
2050 }
2051 else
2052 {
2053 // load request
2054 HANDLE serviceHandle;
2056 status = IopOpenRegistryKeyEx(&serviceHandle, NULL, LoadParams->RegistryPath, KEY_READ);
2057 if (!NT_SUCCESS(status))
2058 {
2059 LoadParams->Status = status;
2060 }
2061 else
2062 {
2063 LoadParams->Status = IopLoadDriver(serviceHandle, &LoadParams->DriverObject);
2064 ZwClose(serviceHandle);
2065 }
2066 }
2067
2068 if (LoadParams->SetEvent)
2069 {
2070 KeSetEvent(&LoadParams->Event, 0, FALSE);
2071 }
2072}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
_In_ PVOID Parameter
Definition: ldrtypes.h:241
NTSTATUS IopLoadDriver(_In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *DriverObject)
Definition: driver.c:1923
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2288

Referenced by IopDoLoadUnloadDriver().

◆ IopNormalizeImagePath()

NTSTATUS FASTCALL IopNormalizeImagePath ( _Inout_ _When_(return >=0, _At_(ImagePath->Buffer, _Post_notnull_ __drv_allocatesMem(Mem))) PUNICODE_STRING  ImagePath,
_In_ PUNICODE_STRING  ServiceName 
)

Definition at line 354 of file driver.c.

358{
359 UNICODE_STRING SystemRootString = RTL_CONSTANT_STRING(L"\\SystemRoot\\");
360 UNICODE_STRING DriversPathString = RTL_CONSTANT_STRING(L"\\SystemRoot\\System32\\drivers\\");
361 UNICODE_STRING DotSysString = RTL_CONSTANT_STRING(L".sys");
362 UNICODE_STRING InputImagePath;
363
364 DPRINT("Normalizing image path '%wZ' for service '%wZ'\n", ImagePath, ServiceName);
365
366 InputImagePath = *ImagePath;
367 if (InputImagePath.Length == 0)
368 {
369 ImagePath->Length = 0;
370 ImagePath->MaximumLength = DriversPathString.Length +
371 ServiceName->Length +
372 DotSysString.Length +
373 sizeof(UNICODE_NULL);
374 ImagePath->Buffer = ExAllocatePoolWithTag(NonPagedPool,
375 ImagePath->MaximumLength,
376 TAG_IO);
377 if (ImagePath->Buffer == NULL)
378 return STATUS_NO_MEMORY;
379
380 RtlCopyUnicodeString(ImagePath, &DriversPathString);
382 RtlAppendUnicodeStringToString(ImagePath, &DotSysString);
383 }
384 else if (InputImagePath.Buffer[0] != L'\\')
385 {
386 ImagePath->Length = 0;
387 ImagePath->MaximumLength = SystemRootString.Length +
388 InputImagePath.Length +
389 sizeof(UNICODE_NULL);
390 ImagePath->Buffer = ExAllocatePoolWithTag(NonPagedPool,
391 ImagePath->MaximumLength,
392 TAG_IO);
393 if (ImagePath->Buffer == NULL)
394 return STATUS_NO_MEMORY;
395
396 RtlCopyUnicodeString(ImagePath, &SystemRootString);
397 RtlAppendUnicodeStringToString(ImagePath, &InputImagePath);
398
399 /* Free caller's string */
401 }
402
403 DPRINT("Normalized image path is '%wZ' for service '%wZ'\n", ImagePath, ServiceName);
404
405 return STATUS_SUCCESS;
406}
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260

Referenced by IopLoadDriver(), and IopUnloadDriver().

◆ IopReinitializeBootDrivers()

VOID NTAPI IopReinitializeBootDrivers ( VOID  )

Definition at line 1517 of file driver.c.

1518{
1519 PDRIVER_REINIT_ITEM ReinitItem;
1521
1522 /* Get the first entry and start looping */
1525 while (Entry)
1526 {
1527 /* Get the item */
1528 ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
1529
1530 /* Increment reinitialization counter */
1531 ReinitItem->DriverObject->DriverExtension->Count++;
1532
1533 /* Remove the device object flag */
1534 ReinitItem->DriverObject->Flags &= ~DRVO_BOOTREINIT_REGISTERED;
1535
1536 /* Call the routine */
1537 ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
1538 ReinitItem->Context,
1539 ReinitItem->DriverObject->
1540 DriverExtension->Count);
1541
1542 /* Free the entry */
1544
1545 /* Move to the next one */
1548 }
1549
1550 /* Wait for all device actions being finished*/
1552}
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
KEVENT PiEnumerationFinished
Definition: devaction.c:50
KSPIN_LOCK DriverBootReinitListLock
Definition: driver.c:27
LIST_ENTRY DriverBootReinitListHead
Definition: driver.c:26
base of all file and directory entries
Definition: entries.h:83
PDRIVER_OBJECT DriverObject
Definition: io.h:449
PDRIVER_REINITIALIZE ReinitRoutine
Definition: io.h:450
PVOID Context
Definition: io.h:451
@ Executive
Definition: ketypes.h:403

Referenced by IoInitSystem().

◆ IopReinitializeDrivers()

VOID NTAPI IopReinitializeDrivers ( VOID  )

Definition at line 1481 of file driver.c.

1482{
1483 PDRIVER_REINIT_ITEM ReinitItem;
1485
1486 /* Get the first entry and start looping */
1489 while (Entry)
1490 {
1491 /* Get the item */
1492 ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
1493
1494 /* Increment reinitialization counter */
1495 ReinitItem->DriverObject->DriverExtension->Count++;
1496
1497 /* Remove the device object flag */
1498 ReinitItem->DriverObject->Flags &= ~DRVO_REINIT_REGISTERED;
1499
1500 /* Call the routine */
1501 ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
1502 ReinitItem->Context,
1503 ReinitItem->DriverObject->
1504 DriverExtension->Count);
1505
1506 /* Free the entry */
1508
1509 /* Move to the next one */
1512 }
1513}
LIST_ENTRY DriverReinitListHead
Definition: driver.c:21
KSPIN_LOCK DriverReinitListLock
Definition: driver.c:22

Referenced by IoInitSystem(), and IopInitializeDriverModule().

◆ IopSuffixUnicodeString()

BOOLEAN NTAPI IopSuffixUnicodeString ( IN PCUNICODE_STRING  String1,
IN PCUNICODE_STRING  String2 
)

Definition at line 281 of file driver.c.

284{
285 PWCHAR pc1;
286 PWCHAR pc2;
288
289 if (String2->Length < String1->Length)
290 return FALSE;
291
292 Length = String1->Length / 2;
293 pc1 = String1->Buffer;
294 pc2 = &String2->Buffer[String2->Length / sizeof(WCHAR) - Length];
295
296 if (pc1 && pc2)
297 {
298 while (Length--)
299 {
300 if( *pc1++ != *pc2++ )
301 return FALSE;
302 }
303 return TRUE;
304 }
305 return FALSE;
306}
static const unsigned char pc1[56]
Definition: des.c:54
static const unsigned char pc2[48]
Definition: des.c:68
_In_ const STRING * String2
Definition: rtlfuncs.h:2345
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

Referenced by IopDisplayLoadingMessage().

◆ IopUnloadDriver()

NTSTATUS NTAPI IopUnloadDriver ( PUNICODE_STRING  DriverServiceName,
BOOLEAN  UnloadPnpDrivers 
)

Definition at line 1254 of file driver.c.

1255{
1256 UNICODE_STRING Backslash = RTL_CONSTANT_STRING(L"\\");
1258 UNICODE_STRING ImagePath;
1263 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1265 USHORT LastBackslash;
1266 BOOLEAN SafeToUnload = TRUE;
1268 UNICODE_STRING CapturedServiceName;
1269
1270 PAGED_CODE();
1271
1273
1274 /* Need the appropriate priviliege */
1276 {
1277 DPRINT1("No unload privilege!\n");
1279 }
1280
1281 /* Capture the service name */
1282 Status = ProbeAndCaptureUnicodeString(&CapturedServiceName,
1284 DriverServiceName);
1285 if (!NT_SUCCESS(Status))
1286 {
1287 return Status;
1288 }
1289
1290 DPRINT("IopUnloadDriver('%wZ', %u)\n", &CapturedServiceName, UnloadPnpDrivers);
1291
1292 /* We need a service name */
1293 if (CapturedServiceName.Length == 0 || CapturedServiceName.Buffer == NULL)
1294 {
1295 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1297 }
1298
1299 /*
1300 * Get the service name from the registry key name
1301 */
1303 &CapturedServiceName,
1304 &Backslash,
1305 &LastBackslash);
1306 if (NT_SUCCESS(Status))
1307 {
1308 NT_ASSERT(CapturedServiceName.Length >= LastBackslash + sizeof(WCHAR));
1309 ServiceName.Buffer = &CapturedServiceName.Buffer[LastBackslash / sizeof(WCHAR) + 1];
1310 ServiceName.Length = CapturedServiceName.Length - LastBackslash - sizeof(WCHAR);
1311 ServiceName.MaximumLength = CapturedServiceName.MaximumLength - LastBackslash - sizeof(WCHAR);
1312 }
1313 else
1314 {
1315 ServiceName = CapturedServiceName;
1316 }
1317
1318 /*
1319 * Construct the driver object name
1320 */
1321 Status = RtlUShortAdd(sizeof(DRIVER_ROOT_NAME),
1322 ServiceName.Length,
1323 &ObjectName.MaximumLength);
1324 if (!NT_SUCCESS(Status))
1325 {
1326 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1327 return Status;
1328 }
1329 ObjectName.Length = 0;
1331 ObjectName.MaximumLength,
1332 TAG_IO);
1333 if (!ObjectName.Buffer)
1334 {
1335 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1337 }
1340
1341 /*
1342 * Find the driver object
1343 */
1345 0,
1346 0,
1347 0,
1349 KernelMode,
1350 0,
1351 (PVOID*)&DriverObject);
1352
1353 if (!NT_SUCCESS(Status))
1354 {
1355 DPRINT1("Can't locate driver object for %wZ\n", &ObjectName);
1357 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1358 return Status;
1359 }
1360
1361 /* Free the buffer for driver object name */
1363
1364 /* Check that driver is not already unloading */
1365 if (DriverObject->Flags & DRVO_UNLOAD_INVOKED)
1366 {
1367 DPRINT1("Driver deletion pending\n");
1369 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1370 return STATUS_DELETE_PENDING;
1371 }
1372
1373 /*
1374 * Get path of service...
1375 */
1377
1378 RtlInitUnicodeString(&ImagePath, NULL);
1379
1380 QueryTable[0].Name = L"ImagePath";
1382 QueryTable[0].EntryContext = &ImagePath;
1383
1385 CapturedServiceName.Buffer,
1386 QueryTable,
1387 NULL,
1388 NULL);
1389
1390 /* We no longer need service name */
1391 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1392
1393 if (!NT_SUCCESS(Status))
1394 {
1395 DPRINT1("RtlQueryRegistryValues() failed (Status %x)\n", Status);
1397 return Status;
1398 }
1399
1400 /*
1401 * Normalize the image path for all later processing.
1402 */
1404
1405 if (!NT_SUCCESS(Status))
1406 {
1407 DPRINT1("IopNormalizeImagePath() failed (Status %x)\n", Status);
1409 return Status;
1410 }
1411
1412 /* Free the service path */
1413 ExFreePool(ImagePath.Buffer);
1414
1415 /*
1416 * Unload the module and release the references to the device object
1417 */
1418
1419 /* Call the load/unload routine, depending on current process */
1420 if (DriverObject->DriverUnload && DriverObject->DriverSection &&
1421 (UnloadPnpDrivers || (DriverObject->Flags & DRVO_LEGACY_DRIVER)))
1422 {
1423 /* Loop through each device object of the driver
1424 and set DOE_UNLOAD_PENDING flag */
1425 DeviceObject = DriverObject->DeviceObject;
1426 while (DeviceObject)
1427 {
1428 /* Set the unload pending flag for the device */
1429 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1430 DeviceExtension->ExtensionFlags |= DOE_UNLOAD_PENDING;
1431
1432 /* Make sure there are no attached devices or no reference counts */
1433 if ((DeviceObject->ReferenceCount) || (DeviceObject->AttachedDevice))
1434 {
1435 /* Not safe to unload */
1436 DPRINT1("Drivers device object is referenced or has attached devices\n");
1437
1438 SafeToUnload = FALSE;
1439 }
1440
1441 DeviceObject = DeviceObject->NextDevice;
1442 }
1443
1444 /* If not safe to unload, then return success */
1445 if (!SafeToUnload)
1446 {
1448 return STATUS_SUCCESS;
1449 }
1450
1451 DPRINT1("Unloading driver '%wZ' (manual)\n", &DriverObject->DriverName);
1452
1453 /* Set the unload invoked flag and call the unload routine */
1457
1458 /* Mark the driver object temporary, so it could be deleted later */
1460
1461 /* Dereference it 2 times */
1464
1465 return Status;
1466 }
1467 else
1468 {
1469 DPRINT1("No DriverUnload function! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
1470
1471 /* Dereference one time (refd inside this function) */
1473
1474 /* Return unloading failure */
1476 }
1477}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define ExGetPreviousMode
Definition: ex.h:139
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4197
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:129
#define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END
Definition: rtl.h:25
NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
const LUID SeLoadDriverPrivilege
Definition: priv.c:29
NTSTATUS IopDoLoadUnloadDriver(_In_opt_ PUNICODE_STRING RegistryPath, _Inout_ PDRIVER_OBJECT *DriverObject)
Process load and unload driver operations. This is mostly for NtLoadDriver and NtUnloadDriver,...
Definition: driver.c:2084
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:322
NTSTATUS NTAPI ObReferenceObjectByName(IN PUNICODE_STRING ObjectPath, IN ULONG Attributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, OUT PVOID *ObjectPtr)
Definition: obref.c:409
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
Definition: probe.h:142
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:239
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
#define DRVO_UNLOAD_INVOKED
Definition: iotypes.h:2225
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define NT_ASSERT
Definition: rtlfuncs.h:3310
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3287
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by NtUnloadDriver().

◆ IoRegisterBootDriverReinitialization()

VOID NTAPI IoRegisterBootDriverReinitialization ( IN PDRIVER_OBJECT  DriverObject,
IN PDRIVER_REINITIALIZE  ReinitRoutine,
IN PVOID  Context 
)

Definition at line 1753 of file driver.c.

1756{
1757 PDRIVER_REINIT_ITEM ReinitItem;
1758
1759 /* Allocate the entry */
1761 sizeof(DRIVER_REINIT_ITEM),
1762 TAG_REINIT);
1763 if (!ReinitItem) return;
1764
1765 /* Fill it out */
1766 ReinitItem->DriverObject = DriverObject;
1767 ReinitItem->ReinitRoutine = ReinitRoutine;
1768 ReinitItem->Context = Context;
1769
1770 /* Set the Driver Object flag and insert the entry into the list */
1773 &ReinitItem->ItemEntry,
1775}
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LIST_ENTRY ItemEntry
Definition: io.h:448
#define TAG_REINIT
Definition: tag.h:84
#define DRVO_BOOTREINIT_REGISTERED
Definition: iotypes.h:4471

Referenced by DriverEntry().

◆ IoRegisterDriverReinitialization()

VOID NTAPI IoRegisterDriverReinitialization ( IN PDRIVER_OBJECT  DriverObject,
IN PDRIVER_REINITIALIZE  ReinitRoutine,
IN PVOID  Context 
)

Definition at line 1782 of file driver.c.

1785{
1786 PDRIVER_REINIT_ITEM ReinitItem;
1787
1788 /* Allocate the entry */
1790 sizeof(DRIVER_REINIT_ITEM),
1791 TAG_REINIT);
1792 if (!ReinitItem) return;
1793
1794 /* Fill it out */
1795 ReinitItem->DriverObject = DriverObject;
1796 ReinitItem->ReinitRoutine = ReinitRoutine;
1797 ReinitItem->Context = Context;
1798
1799 /* Set the Driver Object flag and insert the entry into the list */
1802 &ReinitItem->ItemEntry,
1804}
#define DRVO_REINIT_REGISTERED
Definition: iotypes.h:4469

Referenced by DiskBootDriverReinit(), and DriverEntry().

◆ LdrProcessDriverModule()

NTSTATUS NTAPI LdrProcessDriverModule ( PLDR_DATA_TABLE_ENTRY  LdrEntry,
PUNICODE_STRING  FileName,
PLDR_DATA_TABLE_ENTRY ModuleObject 
)

Definition at line 707 of file driver.c.

710{
712 UNICODE_STRING BaseName, BaseDirectory;
713 PLOAD_IMPORTS LoadedImports = (PVOID)-2;
714 PCHAR MissingApiName, Buffer;
715 PWCHAR MissingDriverName;
716 PVOID DriverBase = LdrEntry->DllBase;
717
718 /* Allocate a buffer we'll use for names */
722 if (!Buffer)
723 {
724 /* Fail */
726 }
727
728 /* Check for a separator */
729 if (FileName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
730 {
731 PWCHAR p;
732 ULONG BaseLength;
733
734 /* Loop the path until we get to the base name */
735 p = &FileName->Buffer[FileName->Length / sizeof(WCHAR)];
736 while (*(p - 1) != OBJ_NAME_PATH_SEPARATOR) p--;
737
738 /* Get the length */
739 BaseLength = (ULONG)(&FileName->Buffer[FileName->Length / sizeof(WCHAR)] - p);
740 BaseLength *= sizeof(WCHAR);
741
742 /* Setup the string */
743 BaseName.Length = (USHORT)BaseLength;
744 BaseName.Buffer = p;
745 }
746 else
747 {
748 /* Otherwise, we already have a base name */
749 BaseName.Length = FileName->Length;
750 BaseName.Buffer = FileName->Buffer;
751 }
752
753 /* Setup the maximum length */
754 BaseName.MaximumLength = BaseName.Length;
755
756 /* Now compute the base directory */
757 BaseDirectory = *FileName;
758 BaseDirectory.Length -= BaseName.Length;
759 BaseDirectory.MaximumLength = BaseDirectory.Length;
760
761 /* Resolve imports */
762 MissingApiName = Buffer;
763 Status = MiResolveImageReferences(DriverBase,
764 &BaseDirectory,
765 NULL,
766 &MissingApiName,
767 &MissingDriverName,
768 &LoadedImports);
769
770 /* Free the temporary buffer */
772
773 /* Check the result of the imports resolution */
774 if (!NT_SUCCESS(Status)) return Status;
775
776 /* Return */
777 *ModuleObject = LdrEntry;
778 return STATUS_SUCCESS;
779}
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define MAXIMUM_FILENAME_LENGTH
Definition: env_spec_w32.h:41
struct _FileName FileName
Definition: fatprocs.h:896
GLfloat GLfloat p
Definition: glext.h:8902
signed char * PCHAR
Definition: retypes.h:7
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI MiResolveImageReferences(IN PVOID ImageBase, IN PUNICODE_STRING ImageFileDirectory, IN PUNICODE_STRING NamePrefix OPTIONAL, OUT PCHAR *MissingApi, OUT PWCHAR *MissingDriver, OUT PLOAD_IMPORTS *LoadImports)
Definition: sysldr.c:987
PVOID DllBase
Definition: btrfs_drv.h:1880
#define TAG_LDR_WSTR
Definition: tag.h:102

◆ MiResolveImageReferences()

NTSTATUS NTAPI MiResolveImageReferences ( IN PVOID  ImageBase,
IN PUNICODE_STRING  ImageFileDirectory,
IN PUNICODE_STRING NamePrefix  OPTIONAL,
OUT PCHAR MissingApi,
OUT PWCHAR MissingDriver,
OUT PLOAD_IMPORTS LoadImports 
)

Definition at line 987 of file sysldr.c.

993{
994 static UNICODE_STRING DriversFolderName = RTL_CONSTANT_STRING(L"drivers\\");
995 PCHAR MissingApiBuffer = *MissingApi, ImportName;
996 PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor, CurrentImport;
997 ULONG ImportSize, ImportCount = 0, LoadedImportsSize, ExportSize;
998 PLOAD_IMPORTS LoadedImports, NewImports;
999 ULONG GdiLink, NormalLink, i;
1000 BOOLEAN ReferenceNeeded, Loaded;
1001 ANSI_STRING TempString;
1002 UNICODE_STRING NameString, DllName;
1003 PLDR_DATA_TABLE_ENTRY LdrEntry = NULL, DllEntry, ImportEntry = NULL;
1004 PVOID ImportBase, DllBase;
1005 PLIST_ENTRY NextEntry;
1006 PIMAGE_EXPORT_DIRECTORY ExportDirectory;
1008 PIMAGE_THUNK_DATA OrigThunk, FirstThunk;
1009 PAGED_CODE();
1010 DPRINT("%s - ImageBase: %p. ImageFileDirectory: %wZ\n",
1011 __FUNCTION__, ImageBase, ImageFileDirectory);
1012
1013 /* No name string buffer yet */
1014 NameString.Buffer = NULL;
1015
1016 /* Assume no imports */
1017 *LoadImports = MM_SYSLDR_NO_IMPORTS;
1018
1019 /* Get the import descriptor */
1020 ImportDescriptor = RtlImageDirectoryEntryToData(ImageBase,
1021 TRUE,
1023 &ImportSize);
1024 if (!ImportDescriptor) return STATUS_SUCCESS;
1025
1026 /* Loop all imports to count them */
1027 for (CurrentImport = ImportDescriptor;
1028 (CurrentImport->Name) && (CurrentImport->OriginalFirstThunk);
1029 CurrentImport++)
1030 {
1031 /* One more */
1032 ImportCount++;
1033 }
1034
1035 /* Make sure we have non-zero imports */
1036 if (ImportCount)
1037 {
1038 /* Calculate and allocate the list we'll need */
1039 LoadedImportsSize = ImportCount * sizeof(PVOID) + sizeof(SIZE_T);
1040 LoadedImports = ExAllocatePoolWithTag(PagedPool,
1041 LoadedImportsSize,
1043 if (LoadedImports)
1044 {
1045 /* Zero it */
1046 RtlZeroMemory(LoadedImports, LoadedImportsSize);
1047 LoadedImports->Count = ImportCount;
1048 }
1049 }
1050 else
1051 {
1052 /* No table */
1053 LoadedImports = NULL;
1054 }
1055
1056 /* Reset the import count and loop descriptors again */
1057 ImportCount = GdiLink = NormalLink = 0;
1058 while ((ImportDescriptor->Name) && (ImportDescriptor->OriginalFirstThunk))
1059 {
1060 /* Get the name */
1061 ImportName = (PCHAR)((ULONG_PTR)ImageBase + ImportDescriptor->Name);
1062
1063 /* Check if this is a GDI driver */
1064 GdiLink = GdiLink |
1065 !(_strnicmp(ImportName, "win32k", sizeof("win32k") - 1));
1066
1067 /* We can also allow dxapi (for Windows compat, allow IRT and coverage) */
1068 NormalLink = NormalLink |
1069 ((_strnicmp(ImportName, "win32k", sizeof("win32k") - 1)) &&
1070 (_strnicmp(ImportName, "dxapi", sizeof("dxapi") - 1)) &&
1071 (_strnicmp(ImportName, "coverage", sizeof("coverage") - 1)) &&
1072 (_strnicmp(ImportName, "irt", sizeof("irt") - 1)));
1073
1074 /* Check if this is a valid GDI driver */
1075 if ((GdiLink) && (NormalLink))
1076 {
1077 /* It's not, it's importing stuff it shouldn't be! */
1079 goto Failure;
1080 }
1081
1082 /* Check for user-mode printer or video card drivers, which don't belong */
1083 if (!(_strnicmp(ImportName, "ntdll", sizeof("ntdll") - 1)) ||
1084 !(_strnicmp(ImportName, "winsrv", sizeof("winsrv") - 1)) ||
1085 !(_strnicmp(ImportName, "advapi32", sizeof("advapi32") - 1)) ||
1086 !(_strnicmp(ImportName, "kernel32", sizeof("kernel32") - 1)) ||
1087 !(_strnicmp(ImportName, "user32", sizeof("user32") - 1)) ||
1088 !(_strnicmp(ImportName, "gdi32", sizeof("gdi32") - 1)))
1089 {
1090 /* This is not kernel code */
1092 goto Failure;
1093 }
1094
1095 /* Check if this is a "core" import, which doesn't get referenced */
1096 if (!(_strnicmp(ImportName, "ntoskrnl", sizeof("ntoskrnl") - 1)) ||
1097 !(_strnicmp(ImportName, "win32k", sizeof("win32k") - 1)) ||
1098 !(_strnicmp(ImportName, "hal", sizeof("hal") - 1)))
1099 {
1100 /* Don't reference this */
1101 ReferenceNeeded = FALSE;
1102 }
1103 else
1104 {
1105 /* Reference these modules */
1106 ReferenceNeeded = TRUE;
1107 }
1108
1109 /* Now setup a unicode string for the import */
1110 RtlInitAnsiString(&TempString, ImportName);
1111 Status = RtlAnsiStringToUnicodeString(&NameString, &TempString, TRUE);
1112 if (!NT_SUCCESS(Status))
1113 {
1114 /* Failed */
1115 goto Failure;
1116 }
1117
1118 /* We don't support name prefixes yet */
1119 if (NamePrefix) DPRINT1("Name Prefix not yet supported!\n");
1120
1121 /* Remember that we haven't loaded the import at this point */
1122CheckDllState:
1123 Loaded = FALSE;
1124 ImportBase = NULL;
1125
1126 /* Loop the driver list */
1127 NextEntry = PsLoadedModuleList.Flink;
1128 while (NextEntry != &PsLoadedModuleList)
1129 {
1130 /* Get the loader entry and compare the name */
1131 LdrEntry = CONTAINING_RECORD(NextEntry,
1133 InLoadOrderLinks);
1134 if (RtlEqualUnicodeString(&NameString,
1135 &LdrEntry->BaseDllName,
1136 TRUE))
1137 {
1138 /* Get the base address */
1139 ImportBase = LdrEntry->DllBase;
1140
1141 /* Check if we haven't loaded yet, and we need references */
1142 if (!(Loaded) && (ReferenceNeeded))
1143 {
1144 /* Make sure we're not already loading */
1145 if (!(LdrEntry->Flags & LDRP_LOAD_IN_PROGRESS))
1146 {
1147 /* Increase the load count */
1148 LdrEntry->LoadCount++;
1149 }
1150 }
1151
1152 /* Done, break out */
1153 break;
1154 }
1155
1156 /* Go to the next entry */
1157 NextEntry = NextEntry->Flink;
1158 }
1159
1160 /* Check if we haven't loaded the import yet */
1161 if (!ImportBase)
1162 {
1163 /* Setup the import DLL name */
1164 DllName.MaximumLength = NameString.Length +
1165 ImageFileDirectory->Length +
1166 sizeof(UNICODE_NULL);
1168 DllName.MaximumLength,
1169 TAG_LDR_WSTR);
1170 if (!DllName.Buffer)
1171 {
1172 /* We're out of resources */
1174 goto Failure;
1175 }
1176
1177 /* Add the import name to the base directory */
1178 RtlCopyUnicodeString(&DllName, ImageFileDirectory);
1180 &NameString);
1181
1182 /* Load the image */
1183 Status = MmLoadSystemImage(&DllName,
1184 NamePrefix,
1185 NULL,
1186 FALSE,
1187 (PVOID *)&DllEntry,
1188 &DllBase);
1189
1190 /* win32k / GDI drivers can also import from system32 folder */
1192 (MI_IS_SESSION_ADDRESS(ImageBase) || 1)) // HACK
1193 {
1194 /* Free the old name buffer */
1196
1197 /* Calculate size for a string the adds 'drivers\' */
1198 DllName.MaximumLength += DriversFolderName.Length;
1199
1200 /* Allocate the new buffer */
1202 DllName.MaximumLength,
1203 TAG_LDR_WSTR);
1204 if (!DllName.Buffer)
1205 {
1206 /* We're out of resources */
1208 goto Failure;
1209 }
1210
1211 /* Copy image directory and append 'drivers\' folder name */
1212 RtlCopyUnicodeString(&DllName, ImageFileDirectory);
1213 RtlAppendUnicodeStringToString(&DllName, &DriversFolderName);
1214
1215 /* Now add the import name */
1216 RtlAppendUnicodeStringToString(&DllName, &NameString);
1217
1218 /* Try once again to load the image */
1219 Status = MmLoadSystemImage(&DllName,
1220 NamePrefix,
1221 NULL,
1222 FALSE,
1223 (PVOID *)&DllEntry,
1224 &DllBase);
1225 }
1226
1227 if (!NT_SUCCESS(Status))
1228 {
1229 /* Fill out the information for the error */
1230 *MissingDriver = DllName.Buffer;
1231 *(PULONG)MissingDriver |= 1;
1232 *MissingApi = NULL;
1233
1234 DPRINT1("Failed to load dependency: %wZ\n", &DllName);
1235
1236 /* Don't free the name */
1237 DllName.Buffer = NULL;
1238
1239 /* Cleanup and return */
1240 goto Failure;
1241 }
1242
1243 /* We can free the DLL Name */
1245 DllName.Buffer = NULL;
1246
1247 /* We're now loaded */
1248 Loaded = TRUE;
1249
1250 /* Sanity check */
1251 ASSERT(DllBase == DllEntry->DllBase);
1252
1253 /* Call the initialization routines */
1255 if (!NT_SUCCESS(Status))
1256 {
1257 /* We failed, unload the image */
1258 MmUnloadSystemImage(DllEntry);
1259 ERROR_DBGBREAK("MmCallDllInitialize failed with status 0x%x\n", Status);
1260 Loaded = FALSE;
1261 }
1262
1263 /* Loop again to make sure that everything is OK */
1264 goto CheckDllState;
1265 }
1266
1267 /* Check if we're support to reference this import */
1268 if ((ReferenceNeeded) && (LoadedImports))
1269 {
1270 /* Make sure we're not already loading */
1271 if (!(LdrEntry->Flags & LDRP_LOAD_IN_PROGRESS))
1272 {
1273 /* Add the entry */
1274 LoadedImports->Entry[ImportCount] = LdrEntry;
1275 ImportCount++;
1276 }
1277 }
1278
1279 /* Free the import name */
1280 RtlFreeUnicodeString(&NameString);
1281
1282 /* Set the missing driver name and get the export directory */
1283 *MissingDriver = LdrEntry->BaseDllName.Buffer;
1284 ExportDirectory = RtlImageDirectoryEntryToData(ImportBase,
1285 TRUE,
1287 &ExportSize);
1288 if (!ExportDirectory)
1289 {
1290 /* Cleanup and return */
1291 DPRINT1("Warning: Driver failed to load, %S not found\n", *MissingDriver);
1293 goto Failure;
1294 }
1295
1296 /* Make sure we have an IAT */
1297 if (ImportDescriptor->OriginalFirstThunk)
1298 {
1299 /* Get the first thunks */
1300 OrigThunk = (PVOID)((ULONG_PTR)ImageBase +
1301 ImportDescriptor->OriginalFirstThunk);
1302 FirstThunk = (PVOID)((ULONG_PTR)ImageBase +
1303 ImportDescriptor->FirstThunk);
1304
1305 /* Loop the IAT */
1306 while (OrigThunk->u1.AddressOfData)
1307 {
1308 /* Snap thunk */
1309 Status = MiSnapThunk(ImportBase,
1310 ImageBase,
1311 OrigThunk++,
1312 FirstThunk++,
1313 ExportDirectory,
1314 ExportSize,
1315 FALSE,
1316 MissingApi);
1317 if (!NT_SUCCESS(Status))
1318 {
1319 /* Cleanup and return */
1320 goto Failure;
1321 }
1322
1323 /* Reset the buffer */
1324 *MissingApi = MissingApiBuffer;
1325 }
1326 }
1327
1328 /* Go to the next import */
1329 ImportDescriptor++;
1330 }
1331
1332 /* Check if we have an import list */
1333 if (LoadedImports)
1334 {
1335 /* Reset the count again, and loop entries */
1336 ImportCount = 0;
1337 for (i = 0; i < LoadedImports->Count; i++)
1338 {
1339 if (LoadedImports->Entry[i])
1340 {
1341 /* Got an entry, OR it with 1 in case it's the single entry */
1342 ImportEntry = (PVOID)((ULONG_PTR)LoadedImports->Entry[i] |
1344 ImportCount++;
1345 }
1346 }
1347
1348 /* Check if we had no imports */
1349 if (!ImportCount)
1350 {
1351 /* Free the list and set it to no imports */
1352 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1353 LoadedImports = MM_SYSLDR_NO_IMPORTS;
1354 }
1355 else if (ImportCount == 1)
1356 {
1357 /* Just one entry, we can free the table and only use our entry */
1358 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1359 LoadedImports = (PLOAD_IMPORTS)ImportEntry;
1360 }
1361 else if (ImportCount != LoadedImports->Count)
1362 {
1363 /* Allocate a new list */
1364 LoadedImportsSize = ImportCount * sizeof(PVOID) + sizeof(SIZE_T);
1365 NewImports = ExAllocatePoolWithTag(PagedPool,
1366 LoadedImportsSize,
1368 if (NewImports)
1369 {
1370 /* Set count */
1371 NewImports->Count = 0;
1372
1373 /* Loop all the imports */
1374 for (i = 0; i < LoadedImports->Count; i++)
1375 {
1376 /* Make sure it's valid */
1377 if (LoadedImports->Entry[i])
1378 {
1379 /* Copy it */
1380 NewImports->Entry[NewImports->Count] = LoadedImports->Entry[i];
1381 NewImports->Count++;
1382 }
1383 }
1384
1385 /* Free the old copy */
1386 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1387 LoadedImports = NewImports;
1388 }
1389 }
1390
1391 /* Return the list */
1392 *LoadImports = LoadedImports;
1393 }
1394
1395 /* Return success */
1396 return STATUS_SUCCESS;
1397
1398Failure:
1399
1400 /* Cleanup and return */
1401 RtlFreeUnicodeString(&NameString);
1402
1403 if (LoadedImports)
1404 {
1405 MiDereferenceImports(LoadedImports);
1406 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1407 }
1408
1409 return Status;
1410}
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
#define __FUNCTION__
Definition: types.h:112
@ Loaded
Definition: fs_rec.h:187
#define LDRP_LOAD_IN_PROGRESS
Definition: ldrtypes.h:42
struct _LOAD_IMPORTS * PLOAD_IMPORTS
unsigned int * PULONG
Definition: retypes.h:1
#define MI_IS_SESSION_ADDRESS(Address)
Definition: miarm.h:171
#define MM_SYSLDR_NO_IMPORTS
Definition: miarm.h:204
#define MM_SYSLDR_SINGLE_ENTRY
Definition: miarm.h:207
#define PCHAR
Definition: match.c:90
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define STATUS_DRIVER_ENTRYPOINT_NOT_FOUND
Definition: ntstatus.h:736
#define STATUS_PROCEDURE_NOT_FOUND
Definition: ntstatus.h:358
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
#define ERROR_DBGBREAK(...)
Definition: debug.h:221
union _IMAGE_THUNK_DATA32::@2114 u1
USHORT LoadCount
Definition: ntddk_ex.h:208
SIZE_T Count
Definition: ldrtypes.h:172
PLDR_DATA_TABLE_ENTRY Entry[1]
Definition: ldrtypes.h:173
NTSTATUS NTAPI MiSnapThunk(IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA Name, IN PIMAGE_THUNK_DATA Address, IN PIMAGE_EXPORT_DIRECTORY ExportDirectory, IN ULONG ExportSize, IN BOOLEAN SnapForwarder, OUT PCHAR *MissingApi)
Definition: sysldr.c:678
NTSTATUS NTAPI MiDereferenceImports(IN PLOAD_IMPORTS ImportList)
Definition: sysldr.c:382
NTSTATUS NTAPI MmLoadSystemImage(IN PUNICODE_STRING FileName, IN PUNICODE_STRING NamePrefix OPTIONAL, IN PUNICODE_STRING LoadedName OPTIONAL, IN ULONG Flags, OUT PVOID *ModuleObject, OUT PVOID *ImageBaseAddress)
Definition: sysldr.c:2885
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
NTSTATUS NTAPI MmUnloadSystemImage(IN PVOID ImageHandle)
Definition: sysldr.c:898
NTSTATUS NTAPI MmCallDllInitialize(IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN PLIST_ENTRY ListHead)
Definition: sysldr.c:295
#define TAG_LDR_IMPORTS
Definition: tag.h:103
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by LdrProcessDriverModule(), and MmLoadSystemImage().

◆ NtLoadDriver()

NTSTATUS NTAPI NtLoadDriver ( IN PUNICODE_STRING  DriverServiceName)

Definition at line 2132 of file driver.c.

2133{
2134 UNICODE_STRING CapturedServiceName = { 0, 0, NULL };
2138
2139 PAGED_CODE();
2140
2142
2143 /* Need the appropriate priviliege */
2145 {
2146 DPRINT1("No load privilege!\n");
2148 }
2149
2150 /* Capture the service name */
2151 Status = ProbeAndCaptureUnicodeString(&CapturedServiceName,
2153 DriverServiceName);
2154 if (!NT_SUCCESS(Status))
2155 {
2156 return Status;
2157 }
2158
2159 DPRINT("NtLoadDriver('%wZ')\n", &CapturedServiceName);
2160
2161 /* We need a service name */
2162 if (CapturedServiceName.Length == 0 || CapturedServiceName.Buffer == NULL)
2163 {
2164 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
2166 }
2167
2168 /* Load driver and call its entry point */
2170 Status = IopDoLoadUnloadDriver(&CapturedServiceName, &DriverObject);
2171
2172 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
2173 return Status;
2174}
#define KeGetPreviousMode()
Definition: ketypes.h:1108

Referenced by NtStartDriver(), ScmLoadDriver(), and wmain().

◆ NtUnloadDriver()

NTSTATUS NTAPI NtUnloadDriver ( IN PUNICODE_STRING  DriverServiceName)

Definition at line 2193 of file driver.c.

2194{
2195 return IopUnloadDriver(DriverServiceName, FALSE);
2196}
NTSTATUS NTAPI IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
Definition: driver.c:1254

Referenced by LoadVia_SystemExtendServiceTableInformation(), LoadVia_SystemLoadGdiDriverInformation(), NtStopDriver(), ScmUnloadDriver(), START_TEST(), and wmain().

Variable Documentation

◆ DriverBootReinitListHead

LIST_ENTRY DriverBootReinitListHead

◆ DriverBootReinitListLock

KSPIN_LOCK DriverBootReinitListLock

◆ DriverBootReinitTailEntry

PLIST_ENTRY DriverBootReinitTailEntry

Definition at line 25 of file driver.c.

◆ DriverReinitListHead

LIST_ENTRY DriverReinitListHead

Definition at line 21 of file driver.c.

Referenced by IoInitSystem(), IopReinitializeDrivers(), and IoRegisterDriverReinitialization().

◆ DriverReinitListLock

KSPIN_LOCK DriverReinitListLock

Definition at line 22 of file driver.c.

Referenced by IoInitSystem(), IopReinitializeDrivers(), and IoRegisterDriverReinitialization().

◆ DriverReinitTailEntry

PLIST_ENTRY DriverReinitTailEntry

Definition at line 23 of file driver.c.

◆ ExpInTextModeSetup

BOOLEAN ExpInTextModeSetup
extern

◆ IoDriverObjectType

◆ IopDriverLoadResource

ERESOURCE IopDriverLoadResource

Definition at line 19 of file driver.c.

Referenced by IoInitSystem(), and IopLoadDriver().

◆ IopGroupIndex

USHORT IopGroupIndex

Definition at line 40 of file driver.c.

Referenced by IopInitializeBootDrivers().

◆ IopGroupTable

PLIST_ENTRY IopGroupTable

Definition at line 41 of file driver.c.

Referenced by IopInitializeBootDrivers().

◆ IopHardwareDatabaseKey

UNICODE_STRING IopHardwareDatabaseKey
Initial value:
=
RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM")

Definition at line 29 of file driver.c.

Referenced by IopInitializeDriverModule().

◆ PiEnumerationFinished

KEVENT PiEnumerationFinished
extern

Definition at line 50 of file devaction.c.

Referenced by IopReinitializeBootDrivers().

◆ PnPBootDriversLoaded

BOOLEAN PnPBootDriversLoaded
extern

Definition at line 26 of file pnpinit.c.

Referenced by IopInitializeBootDrivers().

◆ PnpSystemInit

BOOLEAN PnpSystemInit
extern

Definition at line 17 of file iomgr.c.

Referenced by IopInitializeDriverModule().

◆ ServicesKeyName

const WCHAR ServicesKeyName[] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
static

Definition at line 31 of file driver.c.

Referenced by IopInitializeBuiltinDriver(), and MmCallDllInitialize().