ReactOS 0.4.15-dev-6656-gbbb33a6
driver.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <mm/ARM3/miarm.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 1812 of file driver.c.

1816{
1817 KIRQL OldIrql;
1818 PIO_CLIENT_EXTENSION DriverExtensions, NewDriverExtension;
1819 BOOLEAN Inserted = FALSE;
1820
1821 /* Assume failure */
1822 *DriverObjectExtension = NULL;
1823
1824 /* Allocate the extension */
1825 NewDriverExtension = ExAllocatePoolWithTag(NonPagedPool,
1826 sizeof(IO_CLIENT_EXTENSION) +
1827 DriverObjectExtensionSize,
1829 if (!NewDriverExtension) return STATUS_INSUFFICIENT_RESOURCES;
1830
1831 /* Clear the extension for teh caller */
1832 RtlZeroMemory(NewDriverExtension,
1833 sizeof(IO_CLIENT_EXTENSION) + DriverObjectExtensionSize);
1834
1835 /* Acqure lock */
1837
1838 /* Fill out the extension */
1840
1841 /* Loop the current extensions */
1842 DriverExtensions = IoGetDrvObjExtension(DriverObject)->
1843 ClientDriverExtension;
1844 while (DriverExtensions)
1845 {
1846 /* Check if the identifier matches */
1847 if (DriverExtensions->ClientIdentificationAddress ==
1849 {
1850 /* We have a collision, break out */
1851 break;
1852 }
1853
1854 /* Go to the next one */
1855 DriverExtensions = DriverExtensions->NextExtension;
1856 }
1857
1858 /* Check if we didn't collide */
1859 if (!DriverExtensions)
1860 {
1861 /* Link this one in */
1862 NewDriverExtension->NextExtension =
1863 IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
1864 IoGetDrvObjExtension(DriverObject)->ClientDriverExtension =
1865 NewDriverExtension;
1866 Inserted = TRUE;
1867 }
1868
1869 /* Release the lock */
1871
1872 /* Check if insertion failed */
1873 if (!Inserted)
1874 {
1875 /* Free the entry and fail */
1876 ExFreePoolWithTag(NewDriverExtension, TAG_DRIVER_EXTENSION);
1878 }
1879
1880 /* Otherwise, return the pointer */
1881 *DriverObjectExtension = NewDriverExtension + 1;
1882 return STATUS_SUCCESS;
1883}
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:1109
#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 1562 of file driver.c.

1565{
1566 WCHAR NameBuffer[100];
1567 USHORT NameLength;
1568 UNICODE_STRING LocalDriverName;
1571 ULONG ObjectSize;
1573 UNICODE_STRING ServiceKeyName;
1575 ULONG i, RetryCount = 0;
1576
1577try_again:
1578 /* First, create a unique name for the driver if we don't have one */
1579 if (!DriverName)
1580 {
1581 /* Create a random name and set up the string */
1582 NameLength = (USHORT)swprintf(NameBuffer,
1583 DRIVER_ROOT_NAME L"%08u",
1585 LocalDriverName.Length = NameLength * sizeof(WCHAR);
1586 LocalDriverName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
1587 LocalDriverName.Buffer = NameBuffer;
1588 }
1589 else
1590 {
1591 /* So we can avoid another code path, use a local var */
1592 LocalDriverName = *DriverName;
1593 }
1594
1595 /* Initialize the Attributes */
1596 ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
1598 &LocalDriverName,
1600 NULL,
1601 NULL);
1602
1603 /* Create the Object */
1607 KernelMode,
1608 NULL,
1609 ObjectSize,
1610 0,
1611 0,
1612 (PVOID*)&DriverObject);
1613 if (!NT_SUCCESS(Status)) return Status;
1614
1615 DPRINT("IopCreateDriver(): created DO %p\n", DriverObject);
1616
1617 /* Set up the Object */
1618 RtlZeroMemory(DriverObject, ObjectSize);
1620 DriverObject->Size = sizeof(DRIVER_OBJECT);
1622 DriverObject->DriverExtension = (PDRIVER_EXTENSION)(DriverObject + 1);
1623 DriverObject->DriverExtension->DriverObject = DriverObject;
1624 DriverObject->DriverInit = InitializationFunction;
1625 /* Loop all Major Functions */
1626 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1627 {
1628 /* Invalidate each function */
1629 DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
1630 }
1631
1632 /* Set up the service key name buffer */
1633 ServiceKeyName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
1634 ServiceKeyName.Buffer = ExAllocatePoolWithTag(PagedPool, LocalDriverName.MaximumLength, TAG_IO);
1635 if (!ServiceKeyName.Buffer)
1636 {
1637 /* Fail */
1641 }
1642
1643 /* For builtin drivers, the ServiceKeyName is equal to DriverName */
1644 RtlCopyUnicodeString(&ServiceKeyName, &LocalDriverName);
1645 ServiceKeyName.Buffer[ServiceKeyName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1646 DriverObject->DriverExtension->ServiceKeyName = ServiceKeyName;
1647
1648 /* Make a copy of the driver name to store in the driver object */
1649 DriverObject->DriverName.MaximumLength = LocalDriverName.Length;
1650 DriverObject->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool,
1651 DriverObject->DriverName.MaximumLength,
1652 TAG_IO);
1653 if (!DriverObject->DriverName.Buffer)
1654 {
1655 /* Fail */
1659 }
1660
1661 RtlCopyUnicodeString(&DriverObject->DriverName, &LocalDriverName);
1662
1663 /* Add the Object and get its handle */
1665 NULL,
1667 0,
1668 NULL,
1669 &hDriver);
1670
1671 /* Eliminate small possibility when this function is called more than
1672 once in a row, and KeTickCount doesn't get enough time to change */
1673 if (!DriverName && (Status == STATUS_OBJECT_NAME_COLLISION) && (RetryCount < 100))
1674 {
1675 RetryCount++;
1676 goto try_again;
1677 }
1678
1679 if (!NT_SUCCESS(Status)) return Status;
1680
1681 /* Now reference it */
1683 0,
1685 KernelMode,
1687 NULL);
1688
1689 /* Close the extra handle */
1691
1692 if (!NT_SUCCESS(Status))
1693 {
1694 /* Fail */
1697 return Status;
1698 }
1699
1700 /* Finally, call its init function */
1701 DPRINT("Calling driver entrypoint at %p\n", InitializationFunction);
1702 Status = InitializationFunction(DriverObject, NULL);
1703 if (!NT_SUCCESS(Status))
1704 {
1705 /* If it didn't work, then kill the object */
1706 DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &LocalDriverName, Status);
1709 return Status;
1710 }
1711
1712 /* Windows does this fixup, keep it for compatibility */
1713 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1714 {
1715 /*
1716 * Make sure the driver didn't set any dispatch entry point to NULL!
1717 * Doing so is illegal; drivers shouldn't touch entry points they
1718 * do not implement.
1719 */
1720
1721 /* Check if it did so anyway */
1722 if (!DriverObject->MajorFunction[i])
1723 {
1724 /* Print a warning in the debug log */
1725 DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
1726 &DriverObject->DriverName, i);
1727
1728 /* Fix it up */
1729 DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
1730 }
1731 }
1732
1733 /* Return the Status */
1734 return Status;
1735}
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
#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:34
NTSTATUS NTAPI IopInvalidDeviceRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: driver.c:66
#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:1039
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1449
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
uint32_t ULONG
Definition: typedefs.h:59
_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(), KdpInitDriver(), and WmiInitialize().

◆ IoDeleteDriver()

VOID NTAPI IoDeleteDriver ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 1742 of file driver.c.

1744{
1745 /* Simply dereference the Object */
1747}

Referenced by KdpDriverReinit().

◆ IoGetDriverObjectExtension()

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

Definition at line 1890 of file driver.c.

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

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(), PciIdeXStartMiniport(), 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 78 of file driver.c.

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

Referenced by IopCreateObjectTypes().

◆ IopDisplayLoadingMessage()

VOID FASTCALL IopDisplayLoadingMessage ( PUNICODE_STRING  ServiceName)

Definition at line 316 of file driver.c.

317{
318 CHAR TextBuffer[256];
319 UNICODE_STRING DotSys = RTL_CONSTANT_STRING(L".SYS");
320
321 if (ExpInTextModeSetup) return;
322 if (!KeLoaderBlock) return;
325 "%s%sSystem32\\Drivers\\%wZ%s\r\n",
329 IopSuffixUnicodeString(&DotSys, ServiceName) ? "" : ".SYS");
331}
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:282
BOOLEAN ExpInTextModeSetup
Definition: init.c:69
PSTR ArcBootDeviceName
Definition: arc.h:550
#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 2085 of file driver.c.

2088{
2089 LOAD_UNLOAD_PARAMS LoadParams;
2090
2091 /* Prepare parameters block */
2092 LoadParams.RegistryPath = RegistryPath;
2093 LoadParams.DriverObject = *DriverObject;
2094
2096 {
2097 LoadParams.SetEvent = TRUE;
2099
2100 /* Initialize and queue a work item */
2101 ExInitializeWorkItem(&LoadParams.WorkItem, IopLoadUnloadDriverWorker, &LoadParams);
2103
2104 /* And wait till it completes */
2106 }
2107 else
2108 {
2109 /* If we're already in a system process, call it right here */
2110 LoadParams.SetEvent = FALSE;
2111 IopLoadUnloadDriverWorker(&LoadParams);
2112 }
2113
2114 return LoadParams.Status;
2115}
#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:2039
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
WORK_QUEUE_ITEM WorkItem
Definition: driver.c:51
NTSTATUS Status
Definition: driver.c:49
BOOLEAN SetEvent
Definition: driver.c:54
PUNICODE_STRING RegistryPath
Definition: driver.c:50
PDRIVER_OBJECT DriverObject
Definition: driver.c:53
_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 121 of file plugplay.c.

122{
124 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
125
126 if (IopRootDeviceNode == NULL)
127 return NULL;
128
129 if (DeviceInstance == NULL ||
130 DeviceInstance->Length == 0)
131 {
133 {
136 }
137 else
138 return NULL;
139 }
140
141 /* Traverse the device tree to find the matching device node */
142 DeviceInstanceContext.InstancePath = DeviceInstance;
143 DeviceInstanceContext.DeviceObject = NULL;
147 &DeviceInstanceContext);
149
150 /* In case of error or instance not found, this will still be NULL from above. */
151 return DeviceInstanceContext.DeviceObject;
152}
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:101
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 124 of file driver.c.

128{
129 UNICODE_STRING driverName = {.Buffer = NULL}, serviceName;
132
133 PAGED_CODE();
134
135 /* 1. Check the "ObjectName" field in the driver's registry key (it has priority) */
136 status = IopGetRegistryValue(ServiceHandle, L"ObjectName", &kvInfo);
137 if (NT_SUCCESS(status))
138 {
139 /* We've got the ObjectName, use it as the driver name */
140 if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
141 {
142 ExFreePool(kvInfo);
144 }
145
146 driverName.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
147 driverName.MaximumLength = kvInfo->DataLength;
149 if (!driverName.Buffer)
150 {
151 ExFreePool(kvInfo);
153 }
154
155 RtlMoveMemory(driverName.Buffer,
156 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
157 driverName.Length);
158 driverName.Buffer[driverName.Length / sizeof(WCHAR)] = UNICODE_NULL;
159 ExFreePool(kvInfo);
160 }
161
162 /* Check whether we need to get ServiceName as well, either to construct
163 * the driver name (because we could not use "ObjectName"), or because
164 * it is requested by the caller. */
165 PKEY_BASIC_INFORMATION basicInfo = NULL;
166 if (!NT_SUCCESS(status) || ServiceName != NULL)
167 {
168 /* Retrieve the necessary buffer size */
169 ULONG infoLength;
170 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
172 {
174 goto Cleanup;
175 }
176
177 /* Allocate the buffer and retrieve the data */
178 basicInfo = ExAllocatePoolWithTag(PagedPool, infoLength, TAG_IO);
179 if (!basicInfo)
180 {
182 goto Cleanup;
183 }
184
185 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, basicInfo, infoLength, &infoLength);
186 if (!NT_SUCCESS(status))
187 {
188 goto Cleanup;
189 }
190
191 serviceName.Length = basicInfo->NameLength;
192 serviceName.MaximumLength = basicInfo->NameLength;
193 serviceName.Buffer = basicInfo->Name;
194 }
195
196 /* 2. There is no "ObjectName" - construct it ourselves. Depending on the driver type,
197 * it will be either "\Driver<ServiceName>" or "\FileSystem<ServiceName>" */
198 if (driverName.Buffer == NULL)
199 {
200 ASSERT(basicInfo); // Container for serviceName
201
202 /* Retrieve the driver type */
203 ULONG driverType;
204 status = IopGetRegistryValue(ServiceHandle, L"Type", &kvInfo);
205 if (!NT_SUCCESS(status))
206 {
207 goto Cleanup;
208 }
209 if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
210 {
211 ExFreePool(kvInfo);
213 goto Cleanup;
214 }
215
216 RtlMoveMemory(&driverType,
217 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
218 sizeof(ULONG));
219 ExFreePool(kvInfo);
220
221 /* Compute the necessary driver name string size */
222 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
223 driverName.MaximumLength = sizeof(FILESYSTEM_ROOT_NAME);
224 else
225 driverName.MaximumLength = sizeof(DRIVER_ROOT_NAME);
226
227 driverName.MaximumLength += serviceName.Length;
228 driverName.Length = 0;
229
230 /* Allocate and build it */
232 if (!driverName.Buffer)
233 {
235 goto Cleanup;
236 }
237
238 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
240 else
242
244 }
245
246 if (ServiceName != NULL)
247 {
248 ASSERT(basicInfo); // Container for serviceName
249
250 /* Allocate a copy for the caller */
252 if (!buf)
253 {
255 goto Cleanup;
256 }
257 RtlMoveMemory(buf, serviceName.Buffer, serviceName.Length);
258 ServiceName->MaximumLength = serviceName.Length;
259 ServiceName->Length = serviceName.Length;
260 ServiceName->Buffer = buf;
261 }
262
263 *DriverName = driverName;
265
266Cleanup:
267 if (basicInfo)
268 ExFreePoolWithTag(basicInfo, TAG_IO);
269
270 if (!NT_SUCCESS(status) && driverName.Buffer)
271 ExFreePoolWithTag(driverName.Buffer, TAG_IO);
272
273 return status;
274}
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:1036
#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 1009 of file driver.c.

1010{
1011 PLIST_ENTRY ListHead, NextEntry, NextEntry2;
1012 PLDR_DATA_TABLE_ENTRY LdrEntry;
1014 UNICODE_STRING DriverName;
1015 ULONG i, Index;
1016 PDRIVER_INFORMATION DriverInfo, DriverInfoTag;
1018 PBOOT_DRIVER_LIST_ENTRY BootEntry;
1019 DPRINT("IopInitializeBootDrivers()\n");
1020
1021 /* Create the RAW FS built-in driver */
1022 RtlInitUnicodeString(&DriverName, L"\\FileSystem\\RAW");
1023
1024 Status = IoCreateDriver(&DriverName, RawFsDriverEntry);
1025 if (!NT_SUCCESS(Status))
1026 {
1027 /* Fail */
1028 return;
1029 }
1030
1031 /* Get highest group order index */
1033 if (IopGroupIndex == 0xFFFF)
1034 {
1036 }
1037
1038 /* Allocate the group table */
1040 IopGroupIndex * sizeof(LIST_ENTRY),
1041 TAG_IO);
1042 if (IopGroupTable == NULL)
1043 {
1045 }
1046
1047 /* Initialize the group table lists */
1048 for (i = 0; i < IopGroupIndex; i++) InitializeListHead(&IopGroupTable[i]);
1049
1050 /* Loop the boot modules */
1051 ListHead = &KeLoaderBlock->LoadOrderListHead;
1052 for (NextEntry = ListHead->Flink;
1053 NextEntry != ListHead;
1054 NextEntry = NextEntry->Flink)
1055 {
1056 /* Get the entry */
1057 LdrEntry = CONTAINING_RECORD(NextEntry,
1059 InLoadOrderLinks);
1060
1061 /* Check if the DLL needs to be initialized */
1062 if (LdrEntry->Flags & LDRP_DRIVER_DEPENDENT_DLL)
1063 {
1064 /* Call its entrypoint */
1065 MmCallDllInitialize(LdrEntry, NULL);
1066 }
1067 }
1068
1069 /* Loop the boot drivers */
1070 ListHead = &KeLoaderBlock->BootDriverListHead;
1071 for (NextEntry = ListHead->Flink;
1072 NextEntry != ListHead;
1073 NextEntry = NextEntry->Flink)
1074 {
1075 /* Get the entry */
1076 BootEntry = CONTAINING_RECORD(NextEntry,
1078 Link);
1079
1080 // FIXME: TODO: This LdrEntry is to be used in a special handling
1081 // for SETUPLDR (a similar procedure is done on Windows), where
1082 // the loader would, under certain conditions, be loaded in the
1083 // SETUPLDR-specific code block below...
1084#if 0
1085 /* Get the driver loader entry */
1086 LdrEntry = BootEntry->LdrEntry;
1087#endif
1088
1089 /* Allocate our internal accounting structure */
1091 sizeof(DRIVER_INFORMATION),
1092 TAG_IO);
1093 if (DriverInfo)
1094 {
1095 /* Zero it and initialize it */
1098 DriverInfo->DataTableEntry = BootEntry;
1099
1100 /* Open the registry key */
1102 NULL,
1103 &BootEntry->RegistryPath,
1104 KEY_READ);
1105 DPRINT("IopOpenRegistryKeyEx(%wZ) returned 0x%08lx\n", &BootEntry->RegistryPath, Status);
1106#if 0
1107 if (NT_SUCCESS(Status))
1108#else // Hack still needed...
1109 if ((NT_SUCCESS(Status)) || /* ReactOS HACK for SETUPLDR */
1110 ((KeLoaderBlock->SetupLdrBlock) && ((KeyHandle = (PVOID)1)))) // yes, it's an assignment!
1111#endif
1112 {
1113 /* Save the handle */
1115
1116 /* Get the group oder index */
1118
1119 /* Get the tag position */
1121
1122 /* Insert it into the list, at the right place */
1124 NextEntry2 = IopGroupTable[Index].Flink;
1125 while (NextEntry2 != &IopGroupTable[Index])
1126 {
1127 /* Get the driver info */
1128 DriverInfoTag = CONTAINING_RECORD(NextEntry2,
1130 Link);
1131
1132 /* Check if we found the right tag position */
1133 if (DriverInfoTag->TagPosition > DriverInfo->TagPosition)
1134 {
1135 /* We're done */
1136 break;
1137 }
1138
1139 /* Next entry */
1140 NextEntry2 = NextEntry2->Flink;
1141 }
1142
1143 /* Insert us right before the next entry */
1144 NextEntry2 = NextEntry2->Blink;
1145 InsertHeadList(NextEntry2, &DriverInfo->Link);
1146 }
1147 }
1148 }
1149
1150 /* Loop each group index */
1151 for (i = 0; i < IopGroupIndex; i++)
1152 {
1153 /* Loop each group table */
1154 for (NextEntry = IopGroupTable[i].Flink;
1155 NextEntry != &IopGroupTable[i];
1156 NextEntry = NextEntry->Flink)
1157 {
1158 /* Get the entry */
1159 DriverInfo = CONTAINING_RECORD(NextEntry,
1161 Link);
1162
1163 /* Get the driver loader entry */
1164 LdrEntry = DriverInfo->DataTableEntry->LdrEntry;
1165
1166 /* Initialize it */
1167 if (IopInitializeBuiltinDriver(LdrEntry))
1168 {
1169 // it does not make sense to enumerate the tree if there are no new devices added
1172 NULL,
1173 NULL);
1174 }
1175 }
1176 }
1177
1178 /* HAL Root Bus is being initialized before loading the boot drivers so this may cause issues
1179 * when some devices are not being initialized with their drivers. This flag is used to delay
1180 * all actions with devices (except PnP root device) until boot drivers are loaded.
1181 * See PiQueueDeviceAction function
1182 */
1184
1185 DbgPrint("BOOT DRIVERS LOADED\n");
1186
1189 NULL,
1190 NULL);
1191}
#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:885
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:149
USHORT NTAPI PipGetDriverTagPriority(IN HANDLE ServiceHandle)
Definition: pnpinit.c:192
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 ModuleListHead)
Definition: sysldr.c:432
static BOOLEAN IopInitializeBuiltinDriver(IN PLDR_DATA_TABLE_ENTRY BootLdrEntry)
Definition: driver.c:793
NTSTATUS NTAPI IoCreateDriver(_In_opt_ PUNICODE_STRING DriverName, _In_ PDRIVER_INITIALIZE InitializationFunction)
Definition: driver.c:1562
PLIST_ENTRY IopGroupTable
Definition: driver.c:42
USHORT IopGroupIndex
Definition: driver.c:41
BOOLEAN PnPBootDriversLoaded
Definition: pnpinit.c:20
Definition: arc.h:246
UNICODE_STRING RegistryPath
Definition: arc.h:249
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:250
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:542
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:558
#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 793 of file driver.c.

794{
797 PWCHAR Buffer, FileNameWithoutPath;
798 PWSTR FileExtension;
799 PUNICODE_STRING ModuleName = &BootLdrEntry->BaseDllName;
800 PLDR_DATA_TABLE_ENTRY LdrEntry;
801 PLIST_ENTRY NextEntry;
804
805 /*
806 * Display 'Loading XXX...' message
807 */
810
812 ModuleName->Length + sizeof(UNICODE_NULL),
813 TAG_IO);
814 if (Buffer == NULL)
815 {
816 return FALSE;
817 }
818
821
822 /*
823 * Generate filename without path (not needed by freeldr)
824 */
825 FileNameWithoutPath = wcsrchr(Buffer, L'\\');
826 if (FileNameWithoutPath == NULL)
827 {
828 FileNameWithoutPath = Buffer;
829 }
830 else
831 {
832 FileNameWithoutPath++;
833 }
834
835 /*
836 * Strip the file extension from ServiceName
837 */
838 Success = RtlCreateUnicodeString(&ServiceName, FileNameWithoutPath);
840 if (!Success)
841 {
842 return FALSE;
843 }
844
845 FileExtension = wcsrchr(ServiceName.Buffer, L'.');
846 if (FileExtension != NULL)
847 {
848 ServiceName.Length -= (USHORT)wcslen(FileExtension) * sizeof(WCHAR);
849 FileExtension[0] = UNICODE_NULL;
850 }
851
853
854 // Make the registry path for the driver
855 RegistryPath.Length = 0;
856 RegistryPath.MaximumLength = sizeof(ServicesKeyName) + ServiceName.Length;
858 if (RegistryPath.Buffer == NULL)
859 {
860 return FALSE;
861 }
865
866 HANDLE serviceHandle;
869 if (!NT_SUCCESS(Status))
870 {
871 return FALSE;
872 }
873
874 /* Lookup the new Ldr entry in PsLoadedModuleList */
875 for (NextEntry = PsLoadedModuleList.Flink;
876 NextEntry != &PsLoadedModuleList;
877 NextEntry = NextEntry->Flink)
878 {
879 LdrEntry = CONTAINING_RECORD(NextEntry,
881 InLoadOrderLinks);
883 {
884 break;
885 }
886 }
887 ASSERT(NextEntry != &PsLoadedModuleList);
888
889 /*
890 * Initialize the driver
891 */
892 NTSTATUS driverEntryStatus;
894 serviceHandle,
896 &driverEntryStatus);
897
898 if (!NT_SUCCESS(Status))
899 {
900 DPRINT1("Driver '%wZ' load failed, status (%x)\n", ModuleName, Status);
901 return FALSE;
902 }
903
904 // The driver has been loaded, now check if where are any PDOs
905 // for that driver, and queue AddDevice call for them.
906 // The check is possible because HKLM/SYSTEM/CCS/Services/<ServiceName>/Enum directory
907 // is populated upon a new device arrival based on a (critical) device database
908
909 // Legacy drivers may add devices inside DriverEntry.
910 // We're lazy and always assume that they are doing so
911 BOOLEAN deviceAdded = !!(DriverObject->Flags & DRVO_LEGACY_DRIVER);
912
913 HANDLE enumServiceHandle;
914 UNICODE_STRING enumName = RTL_CONSTANT_STRING(L"Enum");
915
916 Status = IopOpenRegistryKeyEx(&enumServiceHandle, serviceHandle, &enumName, KEY_READ);
917 ZwClose(serviceHandle);
918
919 if (NT_SUCCESS(Status))
920 {
921 ULONG instanceCount = 0;
923 Status = IopGetRegistryValue(enumServiceHandle, L"Count", &kvInfo);
924 if (!NT_SUCCESS(Status))
925 {
926 goto Cleanup;
927 }
928 if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
929 {
930 ExFreePool(kvInfo);
931 goto Cleanup;
932 }
933
934 RtlMoveMemory(&instanceCount,
935 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
936 sizeof(ULONG));
937 ExFreePool(kvInfo);
938
939 DPRINT("Processing %u instances for %wZ module\n", instanceCount, ModuleName);
940
941 for (ULONG i = 0; i < instanceCount; i++)
942 {
943 WCHAR num[11];
944 UNICODE_STRING instancePath;
945 RtlStringCchPrintfW(num, sizeof(num), L"%u", i);
946
947 Status = IopGetRegistryValue(enumServiceHandle, num, &kvInfo);
948 if (!NT_SUCCESS(Status))
949 {
950 continue;
951 }
952 if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
953 {
954 ExFreePool(kvInfo);
955 continue;
956 }
957
958 instancePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
959 instancePath.MaximumLength = kvInfo->DataLength;
961 instancePath.MaximumLength,
962 TAG_IO);
963 if (instancePath.Buffer)
964 {
965 RtlMoveMemory(instancePath.Buffer,
966 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
967 instancePath.Length);
968 instancePath.Buffer[instancePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
969
971 if (pdo != NULL)
972 {
975 deviceAdded = TRUE;
976 }
977 else
978 {
979 DPRINT1("No device node found matching instance path '%wZ'\n", &instancePath);
980 }
981 }
982
983 ExFreePool(kvInfo);
984 }
985
986 ZwClose(enumServiceHandle);
987 }
988Cleanup:
989 /* Remove extra reference from IopInitializeDriverModule */
991
992 return deviceAdded;
993}
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:121
static const WCHAR ServicesKeyName[]
Definition: driver.c:32
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:429
VOID FASTCALL IopDisplayLoadingMessage(PUNICODE_STRING ServiceName)
Definition: driver.c:316
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 429 of file driver.c.

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

1197{
1198 PUNICODE_STRING *DriverList, *SavedList;
1199
1201
1202 /* No system drivers on the boot cd */
1203 if (KeLoaderBlock->SetupLdrBlock) return; // ExpInTextModeSetup
1204
1205 /* Get the driver list */
1206 SavedList = DriverList = CmGetSystemDriverList();
1207 ASSERT(DriverList);
1208
1209 /* Loop it */
1210 while (*DriverList)
1211 {
1212 /* Load the driver */
1213 ZwLoadDriver(*DriverList);
1214
1215 /* Free the entry */
1216 RtlFreeUnicodeString(*DriverList);
1217 ExFreePool(*DriverList);
1218
1219 /* Next entry */
1221 DriverList++;
1222 }
1223
1224 /* Free the list */
1225 ExFreePool(SavedList);
1226
1229 NULL,
1230 NULL);
1231}
PUNICODE_STRING *NTAPI CmGetSystemDriverList(VOID)
Definition: cmsysini.c:1721
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 66 of file driver.c.

69{
70 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
71 Irp->IoStatus.Information = 0;
74}
_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 1924 of file driver.c.

1927{
1928 UNICODE_STRING ImagePath;
1930 PLDR_DATA_TABLE_ENTRY ModuleObject;
1932
1934 Status = IopGetRegistryValue(ServiceHandle, L"ImagePath", &kvInfo);
1935 if (NT_SUCCESS(Status))
1936 {
1937 if ((kvInfo->Type != REG_EXPAND_SZ && kvInfo->Type != REG_SZ) || kvInfo->DataLength == 0)
1938 {
1939 ExFreePool(kvInfo);
1941 }
1942
1943 ImagePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
1944 ImagePath.MaximumLength = kvInfo->DataLength;
1946 if (!ImagePath.Buffer)
1947 {
1948 ExFreePool(kvInfo);
1950 }
1951
1952 RtlMoveMemory(ImagePath.Buffer,
1953 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
1954 ImagePath.Length);
1955 ImagePath.Buffer[ImagePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1956 ExFreePool(kvInfo);
1957 }
1958 else
1959 {
1960 return Status;
1961 }
1962
1963 /*
1964 * Normalize the image path for all later processing.
1965 */
1966 Status = IopNormalizeImagePath(&ImagePath, NULL);
1967 if (!NT_SUCCESS(Status))
1968 {
1969 DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
1970 return Status;
1971 }
1972
1973 DPRINT("FullImagePath: '%wZ'\n", &ImagePath);
1974
1977
1978 /*
1979 * Load the driver module
1980 */
1981 DPRINT("Loading module from %wZ\n", &ImagePath);
1982 Status = MmLoadSystemImage(&ImagePath, NULL, NULL, 0, (PVOID)&ModuleObject, &BaseAddress);
1983 RtlFreeUnicodeString(&ImagePath);
1984
1985 if (!NT_SUCCESS(Status))
1986 {
1987 DPRINT("MmLoadSystemImage() failed (Status %lx)\n", Status);
1990 return Status;
1991 }
1992
1993 // Display the loading message
1994 ULONG infoLength;
1995 Status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
1997 {
1999 if (servName)
2000 {
2001 Status = ZwQueryKey(ServiceHandle,
2003 servName,
2004 infoLength,
2005 &infoLength);
2006 if (NT_SUCCESS(Status))
2007 {
2009 .Length = servName->NameLength,
2010 .MaximumLength = servName->NameLength,
2011 .Buffer = servName->Name
2012 };
2013
2015 }
2016 ExFreePoolWithTag(servName, TAG_IO);
2017 }
2018 }
2019
2020 NTSTATUS driverEntryStatus;
2021 Status = IopInitializeDriverModule(ModuleObject,
2022 ServiceHandle,
2024 &driverEntryStatus);
2025 if (!NT_SUCCESS(Status))
2026 {
2027 DPRINT1("IopInitializeDriverModule() failed (Status %lx)\n", Status);
2028 }
2029
2032
2033 return Status;
2034}
#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:1822
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:2935
ERESOURCE IopDriverLoadResource
Definition: driver.c:20
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:355
#define TAG_RTLREGISTRY
Definition: tag.h:97

Referenced by IopLoadUnloadDriverWorker(), and PiAttachFilterDriversCallback().

◆ IopLoadUnloadDriverWorker()

static VOID NTAPI IopLoadUnloadDriverWorker ( _Inout_ PVOID  Parameter)
static

Definition at line 2039 of file driver.c.

2041{
2042 PLOAD_UNLOAD_PARAMS LoadParams = Parameter;
2043
2045
2046 if (LoadParams->DriverObject)
2047 {
2048 // unload request
2049 LoadParams->DriverObject->DriverUnload(LoadParams->DriverObject);
2050 LoadParams->Status = STATUS_SUCCESS;
2051 }
2052 else
2053 {
2054 // load request
2055 HANDLE serviceHandle;
2057 status = IopOpenRegistryKeyEx(&serviceHandle, NULL, LoadParams->RegistryPath, KEY_READ);
2058 if (!NT_SUCCESS(status))
2059 {
2060 LoadParams->Status = status;
2061 }
2062 else
2063 {
2064 LoadParams->Status = IopLoadDriver(serviceHandle, &LoadParams->DriverObject);
2065 ZwClose(serviceHandle);
2066 }
2067 }
2068
2069 if (LoadParams->SetEvent)
2070 {
2071 KeSetEvent(&LoadParams->Event, 0, FALSE);
2072 }
2073}
#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:1924
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 355 of file driver.c.

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

Referenced by IopLoadDriver(), and IopUnloadDriver().

◆ IopReinitializeBootDrivers()

VOID NTAPI IopReinitializeBootDrivers ( VOID  )

Definition at line 1518 of file driver.c.

1519{
1520 PDRIVER_REINIT_ITEM ReinitItem;
1522
1523 /* Get the first entry and start looping */
1526 while (Entry)
1527 {
1528 /* Get the item */
1529 ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
1530
1531 /* Increment reinitialization counter */
1532 ReinitItem->DriverObject->DriverExtension->Count++;
1533
1534 /* Remove the device object flag */
1535 ReinitItem->DriverObject->Flags &= ~DRVO_BOOTREINIT_REGISTERED;
1536
1537 /* Call the routine */
1538 ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
1539 ReinitItem->Context,
1540 ReinitItem->DriverObject->
1541 DriverExtension->Count);
1542
1543 /* Free the entry */
1545
1546 /* Move to the next one */
1549 }
1550
1551 /* Wait for all device actions being finished*/
1553}
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:28
LIST_ENTRY DriverBootReinitListHead
Definition: driver.c:27
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 1482 of file driver.c.

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

Referenced by IoInitSystem(), and IopInitializeDriverModule().

◆ IopSuffixUnicodeString()

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

Definition at line 282 of file driver.c.

285{
286 PWCHAR pc1;
287 PWCHAR pc2;
289
290 if (String2->Length < String1->Length)
291 return FALSE;
292
293 Length = String1->Length / 2;
294 pc1 = String1->Buffer;
295 pc2 = &String2->Buffer[String2->Length / sizeof(WCHAR) - Length];
296
297 if (pc1 && pc2)
298 {
299 while (Length--)
300 {
301 if( *pc1++ != *pc2++ )
302 return FALSE;
303 }
304 return TRUE;
305 }
306 return FALSE;
307}
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:2357
_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 1255 of file driver.c.

1256{
1257 UNICODE_STRING Backslash = RTL_CONSTANT_STRING(L"\\");
1259 UNICODE_STRING ImagePath;
1264 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1266 USHORT LastBackslash;
1267 BOOLEAN SafeToUnload = TRUE;
1269 UNICODE_STRING CapturedServiceName;
1270
1271 PAGED_CODE();
1272
1274
1275 /* Need the appropriate priviliege */
1277 {
1278 DPRINT1("No unload privilege!\n");
1280 }
1281
1282 /* Capture the service name */
1283 Status = ProbeAndCaptureUnicodeString(&CapturedServiceName,
1285 DriverServiceName);
1286 if (!NT_SUCCESS(Status))
1287 {
1288 return Status;
1289 }
1290
1291 DPRINT("IopUnloadDriver('%wZ', %u)\n", &CapturedServiceName, UnloadPnpDrivers);
1292
1293 /* We need a service name */
1294 if (CapturedServiceName.Length == 0 || CapturedServiceName.Buffer == NULL)
1295 {
1296 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1298 }
1299
1300 /*
1301 * Get the service name from the registry key name
1302 */
1304 &CapturedServiceName,
1305 &Backslash,
1306 &LastBackslash);
1307 if (NT_SUCCESS(Status))
1308 {
1309 NT_ASSERT(CapturedServiceName.Length >= LastBackslash + sizeof(WCHAR));
1310 ServiceName.Buffer = &CapturedServiceName.Buffer[LastBackslash / sizeof(WCHAR) + 1];
1311 ServiceName.Length = CapturedServiceName.Length - LastBackslash - sizeof(WCHAR);
1312 ServiceName.MaximumLength = CapturedServiceName.MaximumLength - LastBackslash - sizeof(WCHAR);
1313 }
1314 else
1315 {
1316 ServiceName = CapturedServiceName;
1317 }
1318
1319 /*
1320 * Construct the driver object name
1321 */
1322 Status = RtlUShortAdd(sizeof(DRIVER_ROOT_NAME),
1323 ServiceName.Length,
1324 &ObjectName.MaximumLength);
1325 if (!NT_SUCCESS(Status))
1326 {
1327 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1328 return Status;
1329 }
1330 ObjectName.Length = 0;
1332 ObjectName.MaximumLength,
1333 TAG_IO);
1334 if (!ObjectName.Buffer)
1335 {
1336 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1338 }
1341
1342 /*
1343 * Find the driver object
1344 */
1346 0,
1347 0,
1348 0,
1350 KernelMode,
1351 0,
1352 (PVOID*)&DriverObject);
1353
1354 if (!NT_SUCCESS(Status))
1355 {
1356 DPRINT1("Can't locate driver object for %wZ\n", &ObjectName);
1358 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1359 return Status;
1360 }
1361
1362 /* Free the buffer for driver object name */
1364
1365 /* Check that driver is not already unloading */
1366 if (DriverObject->Flags & DRVO_UNLOAD_INVOKED)
1367 {
1368 DPRINT1("Driver deletion pending\n");
1370 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1371 return STATUS_DELETE_PENDING;
1372 }
1373
1374 /*
1375 * Get path of service...
1376 */
1378
1379 RtlInitUnicodeString(&ImagePath, NULL);
1380
1381 QueryTable[0].Name = L"ImagePath";
1383 QueryTable[0].EntryContext = &ImagePath;
1384
1386 CapturedServiceName.Buffer,
1387 QueryTable,
1388 NULL,
1389 NULL);
1390
1391 /* We no longer need service name */
1392 ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
1393
1394 if (!NT_SUCCESS(Status))
1395 {
1396 DPRINT1("RtlQueryRegistryValues() failed (Status %x)\n", Status);
1398 return Status;
1399 }
1400
1401 /*
1402 * Normalize the image path for all later processing.
1403 */
1405
1406 if (!NT_SUCCESS(Status))
1407 {
1408 DPRINT1("IopNormalizeImagePath() failed (Status %x)\n", Status);
1410 return Status;
1411 }
1412
1413 /* Free the service path */
1414 ExFreePool(ImagePath.Buffer);
1415
1416 /*
1417 * Unload the module and release the references to the device object
1418 */
1419
1420 /* Call the load/unload routine, depending on current process */
1421 if (DriverObject->DriverUnload && DriverObject->DriverSection &&
1422 (UnloadPnpDrivers || (DriverObject->Flags & DRVO_LEGACY_DRIVER)))
1423 {
1424 /* Loop through each device object of the driver
1425 and set DOE_UNLOAD_PENDING flag */
1426 DeviceObject = DriverObject->DeviceObject;
1427 while (DeviceObject)
1428 {
1429 /* Set the unload pending flag for the device */
1430 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1431 DeviceExtension->ExtensionFlags |= DOE_UNLOAD_PENDING;
1432
1433 /* Make sure there are no attached devices or no reference counts */
1434 if ((DeviceObject->ReferenceCount) || (DeviceObject->AttachedDevice))
1435 {
1436 /* Not safe to unload */
1437 DPRINT1("Drivers device object is referenced or has attached devices\n");
1438
1439 SafeToUnload = FALSE;
1440 }
1441
1442 DeviceObject = DeviceObject->NextDevice;
1443 }
1444
1445 /* If not safe to unload, then return success */
1446 if (!SafeToUnload)
1447 {
1449 return STATUS_SUCCESS;
1450 }
1451
1452 DPRINT1("Unloading driver '%wZ' (manual)\n", &DriverObject->DriverName);
1453
1454 /* Set the unload invoked flag and call the unload routine */
1458
1459 /* Mark the driver object temporary, so it could be deleted later */
1461
1462 /* Dereference it 2 times */
1465
1466 return Status;
1467 }
1468 else
1469 {
1470 DPRINT1("No DriverUnload function! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
1471
1472 /* Dereference one time (refd inside this function) */
1474
1475 /* Return unloading failure */
1477 }
1478}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define ExGetPreviousMode
Definition: ex.h:140
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:4209
#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:2085
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 1754 of file driver.c.

1757{
1758 PDRIVER_REINIT_ITEM ReinitItem;
1759
1760 /* Allocate the entry */
1762 sizeof(DRIVER_REINIT_ITEM),
1763 TAG_REINIT);
1764 if (!ReinitItem) return;
1765
1766 /* Fill it out */
1767 ReinitItem->DriverObject = DriverObject;
1768 ReinitItem->ReinitRoutine = ReinitRoutine;
1769 ReinitItem->Context = Context;
1770
1771 /* Set the Driver Object flag and insert the entry into the list */
1774 &ReinitItem->ItemEntry,
1776}
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(), KdpDriverEntry(), and KdpDriverReinit().

◆ IoRegisterDriverReinitialization()

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

Definition at line 1783 of file driver.c.

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

Referenced by DiskBootDriverReinit(), DriverEntry(), and KdpDriverReinit().

◆ LdrProcessDriverModule()

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

Definition at line 708 of file driver.c.

711{
713 UNICODE_STRING BaseName, BaseDirectory;
714 PLOAD_IMPORTS LoadedImports = MM_SYSLDR_NO_IMPORTS;
715 PCHAR MissingApiName, Buffer;
716 PWCHAR MissingDriverName;
717 PVOID DriverBase = LdrEntry->DllBase;
718
719 /* Allocate a buffer we'll use for names */
723 if (!Buffer)
724 {
725 /* Fail */
727 }
728
729 /* Check for a separator */
730 if (FileName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
731 {
732 PWCHAR p;
733 ULONG BaseLength;
734
735 /* Loop the path until we get to the base name */
736 p = &FileName->Buffer[FileName->Length / sizeof(WCHAR)];
737 while (*(p - 1) != OBJ_NAME_PATH_SEPARATOR) p--;
738
739 /* Get the length */
740 BaseLength = (ULONG)(&FileName->Buffer[FileName->Length / sizeof(WCHAR)] - p);
741 BaseLength *= sizeof(WCHAR);
742
743 /* Setup the string */
744 BaseName.Length = (USHORT)BaseLength;
745 BaseName.Buffer = p;
746 }
747 else
748 {
749 /* Otherwise, we already have a base name */
750 BaseName.Length = FileName->Length;
751 BaseName.Buffer = FileName->Buffer;
752 }
753
754 /* Setup the maximum length */
755 BaseName.MaximumLength = BaseName.Length;
756
757 /* Now compute the base directory */
758 BaseDirectory = *FileName;
759 BaseDirectory.Length -= BaseName.Length;
760 BaseDirectory.MaximumLength = BaseDirectory.Length;
761
762 /* Resolve imports */
763 MissingApiName = Buffer;
764 Status = MiResolveImageReferences(DriverBase,
765 &BaseDirectory,
766 NULL,
767 &MissingApiName,
768 &MissingDriverName,
769 &LoadedImports);
770
771 /* Free the temporary buffer */
773
774 /* Check the result of the imports resolution */
775 if (!NT_SUCCESS(Status)) return Status;
776
777 /* Return */
778 *ModuleObject = LdrEntry;
779 return STATUS_SUCCESS;
780}
#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
#define MM_SYSLDR_NO_IMPORTS
Definition: miarm.h:200
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:1033
PVOID DllBase
Definition: btrfs_drv.h:1880
#define TAG_LDR_WSTR
Definition: tag.h:102
char * PCHAR
Definition: typedefs.h:51

◆ 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 1033 of file sysldr.c.

1039{
1040 static UNICODE_STRING DriversFolderName = RTL_CONSTANT_STRING(L"drivers\\");
1041 PCHAR MissingApiBuffer = *MissingApi, ImportName;
1042 PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor, CurrentImport;
1043 ULONG ImportSize, ImportCount = 0, LoadedImportsSize, ExportSize;
1044 PLOAD_IMPORTS LoadedImports, NewImports;
1045 ULONG i;
1046 BOOLEAN GdiLink, NormalLink;
1047 BOOLEAN ReferenceNeeded, Loaded;
1048 ANSI_STRING TempString;
1049 UNICODE_STRING NameString, DllName;
1050 PLDR_DATA_TABLE_ENTRY LdrEntry = NULL, DllEntry, ImportEntry = NULL;
1051 PVOID ImportBase, DllBase;
1052 PLIST_ENTRY NextEntry;
1053 PIMAGE_EXPORT_DIRECTORY ExportDirectory;
1055 PIMAGE_THUNK_DATA OrigThunk, FirstThunk;
1056
1057 PAGED_CODE();
1058
1059 DPRINT("%s - ImageBase: %p. ImageFileDirectory: %wZ\n",
1060 __FUNCTION__, ImageBase, ImageFileDirectory);
1061
1062 /* No name string buffer yet */
1063 NameString.Buffer = NULL;
1064
1065 /* Assume no imports */
1066 *LoadImports = MM_SYSLDR_NO_IMPORTS;
1067
1068 /* Get the import descriptor */
1069 ImportDescriptor = RtlImageDirectoryEntryToData(ImageBase,
1070 TRUE,
1072 &ImportSize);
1073 if (!ImportDescriptor) return STATUS_SUCCESS;
1074
1075 /* Loop all imports to count them */
1076 for (CurrentImport = ImportDescriptor;
1077 (CurrentImport->Name) && (CurrentImport->OriginalFirstThunk);
1078 CurrentImport++)
1079 {
1080 /* One more */
1081 ImportCount++;
1082 }
1083
1084 /* Make sure we have non-zero imports */
1085 if (ImportCount)
1086 {
1087 /* Calculate and allocate the list we'll need */
1088 LoadedImportsSize = ImportCount * sizeof(PVOID) + sizeof(SIZE_T);
1089 LoadedImports = ExAllocatePoolWithTag(PagedPool,
1090 LoadedImportsSize,
1092 if (LoadedImports)
1093 {
1094 /* Zero it */
1095 RtlZeroMemory(LoadedImports, LoadedImportsSize);
1096 LoadedImports->Count = ImportCount;
1097 }
1098 }
1099 else
1100 {
1101 /* No table */
1102 LoadedImports = NULL;
1103 }
1104
1105 /* Reset the import count and loop descriptors again */
1106 GdiLink = NormalLink = FALSE;
1107 ImportCount = 0;
1108 while ((ImportDescriptor->Name) && (ImportDescriptor->OriginalFirstThunk))
1109 {
1110 /* Get the name */
1111 ImportName = (PCHAR)((ULONG_PTR)ImageBase + ImportDescriptor->Name);
1112
1113 /* Check if this is a GDI driver */
1114 GdiLink = GdiLink ||
1115 !(_strnicmp(ImportName, "win32k", sizeof("win32k") - 1));
1116
1117 /* We can also allow dxapi (for Windows compat, allow IRT and coverage) */
1118 NormalLink = NormalLink ||
1119 ((_strnicmp(ImportName, "win32k", sizeof("win32k") - 1)) &&
1120 (_strnicmp(ImportName, "dxapi", sizeof("dxapi") - 1)) &&
1121 (_strnicmp(ImportName, "coverage", sizeof("coverage") - 1)) &&
1122 (_strnicmp(ImportName, "irt", sizeof("irt") - 1)));
1123
1124 /* Check if this is a valid GDI driver */
1125 if (GdiLink && NormalLink)
1126 {
1127 /* It's not, it's importing stuff it shouldn't be! */
1129 goto Failure;
1130 }
1131
1132 /* Check for user-mode printer or video card drivers, which don't belong */
1133 if (!(_strnicmp(ImportName, "ntdll", sizeof("ntdll") - 1)) ||
1134 !(_strnicmp(ImportName, "winsrv", sizeof("winsrv") - 1)) ||
1135 !(_strnicmp(ImportName, "advapi32", sizeof("advapi32") - 1)) ||
1136 !(_strnicmp(ImportName, "kernel32", sizeof("kernel32") - 1)) ||
1137 !(_strnicmp(ImportName, "user32", sizeof("user32") - 1)) ||
1138 !(_strnicmp(ImportName, "gdi32", sizeof("gdi32") - 1)))
1139 {
1140 /* This is not kernel code */
1142 goto Failure;
1143 }
1144
1145 /* Check if this is a "core" import, which doesn't get referenced */
1146 if (!(_strnicmp(ImportName, "ntoskrnl", sizeof("ntoskrnl") - 1)) ||
1147 !(_strnicmp(ImportName, "win32k", sizeof("win32k") - 1)) ||
1148 !(_strnicmp(ImportName, "hal", sizeof("hal") - 1)))
1149 {
1150 /* Don't reference this */
1151 ReferenceNeeded = FALSE;
1152 }
1153 else
1154 {
1155 /* Reference these modules */
1156 ReferenceNeeded = TRUE;
1157 }
1158
1159 /* Now setup a unicode string for the import */
1160 RtlInitAnsiString(&TempString, ImportName);
1161 Status = RtlAnsiStringToUnicodeString(&NameString, &TempString, TRUE);
1162 if (!NT_SUCCESS(Status))
1163 {
1164 /* Failed */
1165 goto Failure;
1166 }
1167
1168 /* We don't support name prefixes yet */
1169 if (NamePrefix) DPRINT1("Name Prefix not yet supported!\n");
1170
1171 /* Remember that we haven't loaded the import at this point */
1172CheckDllState:
1173 Loaded = FALSE;
1174 ImportBase = NULL;
1175
1176 /* Loop the driver list */
1177 NextEntry = PsLoadedModuleList.Flink;
1178 while (NextEntry != &PsLoadedModuleList)
1179 {
1180 /* Get the loader entry and compare the name */
1181 LdrEntry = CONTAINING_RECORD(NextEntry,
1183 InLoadOrderLinks);
1184 if (RtlEqualUnicodeString(&NameString,
1185 &LdrEntry->BaseDllName,
1186 TRUE))
1187 {
1188 /* Get the base address */
1189 ImportBase = LdrEntry->DllBase;
1190
1191 /* Check if we haven't loaded yet, and we need references */
1192 if (!(Loaded) && (ReferenceNeeded))
1193 {
1194 /* Make sure we're not already loading */
1195 if (!(LdrEntry->Flags & LDRP_LOAD_IN_PROGRESS))
1196 {
1197 /* Increase the load count */
1198 LdrEntry->LoadCount++;
1199 }
1200 }
1201
1202 /* Done, break out */
1203 break;
1204 }
1205
1206 /* Go to the next entry */
1207 NextEntry = NextEntry->Flink;
1208 }
1209
1210 /* Check if we haven't loaded the import yet */
1211 if (!ImportBase)
1212 {
1213 /* Setup the import DLL name */
1214 DllName.MaximumLength = NameString.Length +
1215 ImageFileDirectory->Length +
1216 sizeof(UNICODE_NULL);
1218 DllName.MaximumLength,
1219 TAG_LDR_WSTR);
1220 if (!DllName.Buffer)
1221 {
1222 /* We're out of resources */
1224 goto Failure;
1225 }
1226
1227 /* Add the import name to the base directory */
1228 RtlCopyUnicodeString(&DllName, ImageFileDirectory);
1230 &NameString);
1231
1232 /* Load the image */
1233 Status = MmLoadSystemImage(&DllName,
1234 NamePrefix,
1235 NULL,
1236 FALSE,
1237 (PVOID *)&DllEntry,
1238 &DllBase);
1239
1240 /* win32k / GDI drivers can also import from system32 folder */
1242 (MI_IS_SESSION_ADDRESS(ImageBase) || 1)) // HACK
1243 {
1244 /* Free the old name buffer */
1246
1247 /* Calculate size for a string the adds 'drivers\' */
1248 DllName.MaximumLength += DriversFolderName.Length;
1249
1250 /* Allocate the new buffer */
1252 DllName.MaximumLength,
1253 TAG_LDR_WSTR);
1254 if (!DllName.Buffer)
1255 {
1256 /* We're out of resources */
1258 goto Failure;
1259 }
1260
1261 /* Copy image directory and append 'drivers\' folder name */
1262 RtlCopyUnicodeString(&DllName, ImageFileDirectory);
1263 RtlAppendUnicodeStringToString(&DllName, &DriversFolderName);
1264
1265 /* Now add the import name */
1266 RtlAppendUnicodeStringToString(&DllName, &NameString);
1267
1268 /* Try once again to load the image */
1269 Status = MmLoadSystemImage(&DllName,
1270 NamePrefix,
1271 NULL,
1272 FALSE,
1273 (PVOID *)&DllEntry,
1274 &DllBase);
1275 }
1276
1277 if (!NT_SUCCESS(Status))
1278 {
1279 /* Fill out the information for the error */
1280 *MissingDriver = DllName.Buffer;
1281 *(PULONG)MissingDriver |= 1;
1282 *MissingApi = NULL;
1283
1284 DPRINT1("Failed to load dependency: %wZ\n", &DllName);
1285
1286 /* Don't free the name */
1287 DllName.Buffer = NULL;
1288
1289 /* Cleanup and return */
1290 goto Failure;
1291 }
1292
1293 /* We can free the DLL Name */
1295 DllName.Buffer = NULL;
1296
1297 /* We're now loaded */
1298 Loaded = TRUE;
1299
1300 /* Sanity check */
1301 ASSERT(DllBase == DllEntry->DllBase);
1302
1303 /* Call the initialization routines */
1305 if (!NT_SUCCESS(Status))
1306 {
1307 /* We failed, unload the image */
1308 MmUnloadSystemImage(DllEntry);
1309 ERROR_DBGBREAK("MmCallDllInitialize failed with status 0x%x\n", Status);
1310 Loaded = FALSE;
1311 }
1312
1313 /* Loop again to make sure that everything is OK */
1314 goto CheckDllState;
1315 }
1316
1317 /* Check if we're support to reference this import */
1318 if ((ReferenceNeeded) && (LoadedImports))
1319 {
1320 /* Make sure we're not already loading */
1321 if (!(LdrEntry->Flags & LDRP_LOAD_IN_PROGRESS))
1322 {
1323 /* Add the entry */
1324 LoadedImports->Entry[ImportCount] = LdrEntry;
1325 ImportCount++;
1326 }
1327 }
1328
1329 /* Free the import name */
1330 RtlFreeUnicodeString(&NameString);
1331
1332 /* Set the missing driver name and get the export directory */
1333 *MissingDriver = LdrEntry->BaseDllName.Buffer;
1334 ExportDirectory = RtlImageDirectoryEntryToData(ImportBase,
1335 TRUE,
1337 &ExportSize);
1338 if (!ExportDirectory)
1339 {
1340 /* Cleanup and return */
1341 DPRINT1("Warning: Driver failed to load, %S not found\n", *MissingDriver);
1343 goto Failure;
1344 }
1345
1346 /* Make sure we have an IAT */
1347 if (ImportDescriptor->OriginalFirstThunk)
1348 {
1349 /* Get the first thunks */
1350 OrigThunk = (PVOID)((ULONG_PTR)ImageBase +
1351 ImportDescriptor->OriginalFirstThunk);
1352 FirstThunk = (PVOID)((ULONG_PTR)ImageBase +
1353 ImportDescriptor->FirstThunk);
1354
1355 /* Loop the IAT */
1356 while (OrigThunk->u1.AddressOfData)
1357 {
1358 /* Snap thunk */
1359 Status = MiSnapThunk(ImportBase,
1360 ImageBase,
1361 OrigThunk++,
1362 FirstThunk++,
1363 ExportDirectory,
1364 ExportSize,
1365 FALSE,
1366 MissingApi);
1367 if (!NT_SUCCESS(Status))
1368 {
1369 /* Cleanup and return */
1370 goto Failure;
1371 }
1372
1373 /* Reset the buffer */
1374 *MissingApi = MissingApiBuffer;
1375 }
1376 }
1377
1378 /* Go to the next import */
1379 ImportDescriptor++;
1380 }
1381
1382 /* Check if we have an import list */
1383 if (LoadedImports)
1384 {
1385 /* Reset the count again, and loop entries */
1386 ImportCount = 0;
1387 for (i = 0; i < LoadedImports->Count; i++)
1388 {
1389 if (LoadedImports->Entry[i])
1390 {
1391 /* Got an entry, OR it with 1 in case it's the single entry */
1392 ImportEntry = (PVOID)((ULONG_PTR)LoadedImports->Entry[i] |
1394 ImportCount++;
1395 }
1396 }
1397
1398 /* Check if we had no imports */
1399 if (!ImportCount)
1400 {
1401 /* Free the list and set it to no imports */
1402 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1403 LoadedImports = MM_SYSLDR_NO_IMPORTS;
1404 }
1405 else if (ImportCount == 1)
1406 {
1407 /* Just one entry, we can free the table and only use our entry */
1408 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1409 LoadedImports = (PLOAD_IMPORTS)ImportEntry;
1410 }
1411 else if (ImportCount != LoadedImports->Count)
1412 {
1413 /* Allocate a new list */
1414 LoadedImportsSize = ImportCount * sizeof(PVOID) + sizeof(SIZE_T);
1415 NewImports = ExAllocatePoolWithTag(PagedPool,
1416 LoadedImportsSize,
1418 if (NewImports)
1419 {
1420 /* Set count */
1421 NewImports->Count = 0;
1422
1423 /* Loop all the imports */
1424 for (i = 0; i < LoadedImports->Count; i++)
1425 {
1426 /* Make sure it's valid */
1427 if (LoadedImports->Entry[i])
1428 {
1429 /* Copy it */
1430 NewImports->Entry[NewImports->Count] = LoadedImports->Entry[i];
1431 NewImports->Count++;
1432 }
1433 }
1434
1435 /* Free the old copy */
1436 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1437 LoadedImports = NewImports;
1438 }
1439 }
1440
1441 /* Return the list */
1442 *LoadImports = LoadedImports;
1443 }
1444
1445 /* Return success */
1446 return STATUS_SUCCESS;
1447
1448Failure:
1449
1450 /* Cleanup and return */
1451 RtlFreeUnicodeString(&NameString);
1452
1453 if (LoadedImports)
1454 {
1455 MiDereferenceImports(LoadedImports);
1456 ExFreePoolWithTag(LoadedImports, TAG_LDR_IMPORTS);
1457 }
1458
1459 return Status;
1460}
#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:116
@ Loaded
Definition: fs_rec.h:187
#define LDRP_LOAD_IN_PROGRESS
Definition: ldrtypes.h:42
struct _LOAD_IMPORTS * PLOAD_IMPORTS
#define MI_IS_SESSION_ADDRESS(Address)
Definition: miarm.h:171
#define MM_SYSLDR_SINGLE_ENTRY
Definition: miarm.h:202
#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::@2113 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:747
NTSTATUS NTAPI MiDereferenceImports(IN PLOAD_IMPORTS ImportList)
Definition: sysldr.c:526
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:2935
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
NTSTATUS NTAPI MmCallDllInitialize(_In_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ PLIST_ENTRY ModuleListHead)
Definition: sysldr.c:432
NTSTATUS NTAPI MmUnloadSystemImage(IN PVOID ImageHandle)
Definition: sysldr.c:944
#define TAG_LDR_IMPORTS
Definition: tag.h:103
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
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 2133 of file driver.c.

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

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

◆ NtUnloadDriver()

NTSTATUS NTAPI NtUnloadDriver ( IN PUNICODE_STRING  DriverServiceName)

Definition at line 2194 of file driver.c.

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

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 26 of file driver.c.

◆ DriverReinitListHead

LIST_ENTRY DriverReinitListHead

Definition at line 22 of file driver.c.

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

◆ DriverReinitListLock

KSPIN_LOCK DriverReinitListLock

Definition at line 23 of file driver.c.

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

◆ DriverReinitTailEntry

PLIST_ENTRY DriverReinitTailEntry

Definition at line 24 of file driver.c.

◆ ExpInTextModeSetup

BOOLEAN ExpInTextModeSetup
extern

◆ IoDriverObjectType

◆ IopDriverLoadResource

ERESOURCE IopDriverLoadResource

Definition at line 20 of file driver.c.

Referenced by IoInitSystem(), and IopLoadDriver().

◆ IopGroupIndex

USHORT IopGroupIndex

Definition at line 41 of file driver.c.

Referenced by IopInitializeBootDrivers().

◆ IopGroupTable

PLIST_ENTRY IopGroupTable

Definition at line 42 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 30 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 20 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 32 of file driver.c.

Referenced by IopInitializeBuiltinDriver(), and MmCallDllInitialize().