2005-09-27 12:43:36 +00:00
|
|
|
|
/*
|
2006-07-09 00:01:31 +00:00
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2006-07-09 02:34:32 +00:00
|
|
|
|
* FILE: ntoskrnl/io/iomgr/driver.c
|
2006-07-09 00:01:31 +00:00
|
|
|
|
* PURPOSE: Driver Object Management
|
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
|
* Filip Navara (navaraf@reactos.org)
|
|
|
|
|
* Herv<EFBFBD> Poussineau (hpoussin@reactos.org)
|
2003-10-06 18:49:50 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-10-15 17:04:39 +00:00
|
|
|
|
/* INCLUDES *******************************************************************/
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
|
#include <ntoskrnl.h>
|
2003-10-06 18:49:50 +00:00
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
|
#include <debug.h>
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2003-10-15 17:04:39 +00:00
|
|
|
|
/* GLOBALS ********************************************************************/
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2014-10-24 10:02:14 +00:00
|
|
|
|
ERESOURCE IopDriverLoadResource;
|
|
|
|
|
|
2006-07-09 02:34:32 +00:00
|
|
|
|
LIST_ENTRY DriverReinitListHead;
|
|
|
|
|
KSPIN_LOCK DriverReinitListLock;
|
|
|
|
|
PLIST_ENTRY DriverReinitTailEntry;
|
2003-12-15 17:50:23 +00:00
|
|
|
|
|
2006-07-09 02:34:32 +00:00
|
|
|
|
PLIST_ENTRY DriverBootReinitTailEntry;
|
|
|
|
|
LIST_ENTRY DriverBootReinitListHead;
|
|
|
|
|
KSPIN_LOCK DriverBootReinitListLock;
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2006-07-09 02:34:32 +00:00
|
|
|
|
UNICODE_STRING IopHardwareDatabaseKey =
|
2005-06-25 14:04:56 +00:00
|
|
|
|
RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM");
|
2020-11-25 00:18:31 +00:00
|
|
|
|
static const WCHAR ServicesKeyName[] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\";
|
2004-11-07 21:20:51 +00:00
|
|
|
|
|
2005-11-22 02:30:18 +00:00
|
|
|
|
POBJECT_TYPE IoDriverObjectType = NULL;
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2006-10-01 18:27:59 +00:00
|
|
|
|
extern BOOLEAN ExpInTextModeSetup;
|
2012-02-02 18:08:28 +00:00
|
|
|
|
extern BOOLEAN PnpSystemInit;
|
2020-06-24 16:34:44 +00:00
|
|
|
|
extern BOOLEAN PnPBootDriversLoaded;
|
|
|
|
|
extern KEVENT PiEnumerationFinished;
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
USHORT IopGroupIndex;
|
|
|
|
|
PLIST_ENTRY IopGroupTable;
|
|
|
|
|
|
2020-11-20 15:51:33 +00:00
|
|
|
|
/* TYPES *********************************************************************/
|
|
|
|
|
|
|
|
|
|
// Parameters packet for Load/Unload work item's context
|
|
|
|
|
typedef struct _LOAD_UNLOAD_PARAMS
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
PUNICODE_STRING RegistryPath;
|
2020-11-20 15:51:33 +00:00
|
|
|
|
WORK_QUEUE_ITEM WorkItem;
|
|
|
|
|
KEVENT Event;
|
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
|
BOOLEAN SetEvent;
|
|
|
|
|
} LOAD_UNLOAD_PARAMS, *PLOAD_UNLOAD_PARAMS;
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
IopDoLoadUnloadDriver(
|
2020-11-25 00:18:31 +00:00
|
|
|
|
_In_opt_ PUNICODE_STRING RegistryPath,
|
2020-11-20 15:51:33 +00:00
|
|
|
|
_Inout_ PDRIVER_OBJECT *DriverObject);
|
|
|
|
|
|
2004-03-28 09:48:13 +00:00
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2003-10-06 18:49:50 +00:00
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
2004-03-28 09:48:13 +00:00
|
|
|
|
IopInvalidDeviceRequest(
|
2014-10-23 17:59:16 +00:00
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
PIRP Irp)
|
2004-03-27 19:41:32 +00:00
|
|
|
|
{
|
2014-10-23 17:59:16 +00:00
|
|
|
|
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
return STATUS_INVALID_DEVICE_REQUEST;
|
2004-03-27 19:41:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
IopDeleteDriver(IN PVOID ObjectBody)
|
2004-03-28 09:48:13 +00:00
|
|
|
|
{
|
2006-07-09 00:01:31 +00:00
|
|
|
|
PDRIVER_OBJECT DriverObject = ObjectBody;
|
|
|
|
|
PIO_CLIENT_EXTENSION DriverExtension, NextDriverExtension;
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
2012-02-21 01:26:29 +00:00
|
|
|
|
DPRINT1("Deleting driver object '%wZ'\n", &DriverObject->DriverName);
|
|
|
|
|
|
2012-03-08 23:02:45 +00:00
|
|
|
|
/* There must be no device objects remaining at this point */
|
|
|
|
|
ASSERT(!DriverObject->DeviceObject);
|
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Get the extension and loop them */
|
2014-10-23 17:59:16 +00:00
|
|
|
|
DriverExtension = IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
|
2006-07-09 00:01:31 +00:00
|
|
|
|
while (DriverExtension)
|
|
|
|
|
{
|
|
|
|
|
/* Get the next one */
|
|
|
|
|
NextDriverExtension = DriverExtension->NextExtension;
|
|
|
|
|
ExFreePoolWithTag(DriverExtension, TAG_DRIVER_EXTENSION);
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Move on */
|
|
|
|
|
DriverExtension = NextDriverExtension;
|
|
|
|
|
}
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Check if the driver image is still loaded */
|
|
|
|
|
if (DriverObject->DriverSection)
|
|
|
|
|
{
|
|
|
|
|
/* Unload it */
|
2009-04-25 09:07:10 +00:00
|
|
|
|
MmUnloadSystemImage(DriverObject->DriverSection);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
}
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Check if it has a name */
|
|
|
|
|
if (DriverObject->DriverName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
/* Free it */
|
|
|
|
|
ExFreePool(DriverObject->DriverName.Buffer);
|
|
|
|
|
}
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Check if it has a service key name */
|
|
|
|
|
if (DriverObject->DriverExtension->ServiceKeyName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
/* Free it */
|
2007-05-25 13:52:58 +00:00
|
|
|
|
ExFreePool(DriverObject->DriverExtension->ServiceKeyName.Buffer);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
}
|
2004-03-28 09:48:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
NTSTATUS
|
2020-11-26 01:39:38 +00:00
|
|
|
|
IopGetDriverNames(
|
|
|
|
|
_In_ HANDLE ServiceHandle,
|
|
|
|
|
_Out_ PUNICODE_STRING DriverName,
|
|
|
|
|
_Out_opt_ PUNICODE_STRING ServiceName)
|
2005-05-19 22:02:34 +00:00
|
|
|
|
{
|
2020-11-26 01:39:38 +00:00
|
|
|
|
UNICODE_STRING driverName = {.Buffer = NULL}, serviceName;
|
|
|
|
|
PKEY_VALUE_FULL_INFORMATION kvInfo;
|
|
|
|
|
NTSTATUS status;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-26 01:39:38 +00:00
|
|
|
|
PAGED_CODE();
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* 1. Check the "ObjectName" field in the driver's registry key (it has priority) */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
status = IopGetRegistryValue(ServiceHandle, L"ObjectName", &kvInfo);
|
|
|
|
|
if (NT_SUCCESS(status))
|
|
|
|
|
{
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* We've got the ObjectName, use it as the driver name */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
|
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
return STATUS_ILL_FORMED_SERVICE_ENTRY;
|
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2021-06-10 19:20:17 +00:00
|
|
|
|
driverName.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
|
2021-06-10 19:16:27 +00:00
|
|
|
|
driverName.MaximumLength = kvInfo->DataLength;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
driverName.Buffer = ExAllocatePoolWithTag(NonPagedPool, driverName.MaximumLength, TAG_IO);
|
|
|
|
|
if (!driverName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlMoveMemory(driverName.Buffer,
|
|
|
|
|
(PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
|
|
|
|
|
driverName.Length);
|
2021-06-10 19:20:17 +00:00
|
|
|
|
driverName.Buffer[driverName.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
}
|
2019-03-24 13:47:59 +00:00
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Check whether we need to get ServiceName as well, either to construct
|
|
|
|
|
* the driver name (because we could not use "ObjectName"), or because
|
|
|
|
|
* it is requested by the caller. */
|
2021-06-10 20:31:45 +00:00
|
|
|
|
PKEY_BASIC_INFORMATION basicInfo = NULL;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
if (!NT_SUCCESS(status) || ServiceName != NULL)
|
2019-03-24 13:47:59 +00:00
|
|
|
|
{
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Retrieve the necessary buffer size */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
ULONG infoLength;
|
|
|
|
|
status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
|
2021-06-10 19:16:27 +00:00
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL)
|
2020-11-26 01:39:38 +00:00
|
|
|
|
{
|
2021-06-10 21:11:27 +00:00
|
|
|
|
status = (NT_SUCCESS(status) ? STATUS_UNSUCCESSFUL : status);
|
|
|
|
|
goto Cleanup;
|
2021-06-10 19:16:27 +00:00
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Allocate the buffer and retrieve the data */
|
|
|
|
|
basicInfo = ExAllocatePoolWithTag(PagedPool, infoLength, TAG_IO);
|
|
|
|
|
if (!basicInfo)
|
|
|
|
|
{
|
2021-06-10 21:11:27 +00:00
|
|
|
|
status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto Cleanup;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
2021-06-10 19:16:27 +00:00
|
|
|
|
|
|
|
|
|
status = ZwQueryKey(ServiceHandle, KeyBasicInformation, basicInfo, infoLength, &infoLength);
|
|
|
|
|
if (!NT_SUCCESS(status))
|
2020-11-26 01:39:38 +00:00
|
|
|
|
{
|
2021-06-10 21:11:27 +00:00
|
|
|
|
goto Cleanup;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
2021-06-10 19:16:27 +00:00
|
|
|
|
|
|
|
|
|
serviceName.Length = basicInfo->NameLength;
|
|
|
|
|
serviceName.MaximumLength = basicInfo->NameLength;
|
|
|
|
|
serviceName.Buffer = basicInfo->Name;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* 2. There is no "ObjectName" - construct it ourselves. Depending on the driver type,
|
|
|
|
|
* it will be either "\Driver\<ServiceName>" or "\FileSystem\<ServiceName>" */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
if (driverName.Buffer == NULL)
|
2014-10-23 17:59:16 +00:00
|
|
|
|
{
|
2021-06-10 20:31:45 +00:00
|
|
|
|
ASSERT(basicInfo); // Container for serviceName
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Retrieve the driver type */
|
|
|
|
|
ULONG driverType;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
status = IopGetRegistryValue(ServiceHandle, L"Type", &kvInfo);
|
2021-03-18 22:07:22 +00:00
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
|
{
|
2021-06-10 20:31:45 +00:00
|
|
|
|
goto Cleanup;
|
2021-03-18 22:07:22 +00:00
|
|
|
|
}
|
2021-06-10 19:20:17 +00:00
|
|
|
|
if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
|
2020-11-26 01:39:38 +00:00
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
2021-06-10 20:31:45 +00:00
|
|
|
|
status = STATUS_ILL_FORMED_SERVICE_ENTRY;
|
|
|
|
|
goto Cleanup;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
2021-06-16 22:29:58 +00:00
|
|
|
|
|
|
|
|
|
RtlMoveMemory(&driverType,
|
|
|
|
|
(PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
|
|
|
|
|
sizeof(ULONG));
|
2020-11-26 01:39:38 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Compute the necessary driver name string size */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
|
2021-06-10 19:16:27 +00:00
|
|
|
|
driverName.MaximumLength = sizeof(FILESYSTEM_ROOT_NAME);
|
2020-11-26 01:39:38 +00:00
|
|
|
|
else
|
2021-06-10 19:16:27 +00:00
|
|
|
|
driverName.MaximumLength = sizeof(DRIVER_ROOT_NAME);
|
|
|
|
|
|
|
|
|
|
driverName.MaximumLength += serviceName.Length;
|
|
|
|
|
driverName.Length = 0;
|
|
|
|
|
|
|
|
|
|
/* Allocate and build it */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
driverName.Buffer = ExAllocatePoolWithTag(NonPagedPool, driverName.MaximumLength, TAG_IO);
|
|
|
|
|
if (!driverName.Buffer)
|
|
|
|
|
{
|
2021-06-10 20:31:45 +00:00
|
|
|
|
status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto Cleanup;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
|
|
|
|
|
RtlAppendUnicodeToString(&driverName, FILESYSTEM_ROOT_NAME);
|
|
|
|
|
else
|
|
|
|
|
RtlAppendUnicodeToString(&driverName, DRIVER_ROOT_NAME);
|
|
|
|
|
|
|
|
|
|
RtlAppendUnicodeStringToString(&driverName, &serviceName);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
if (ServiceName != NULL)
|
2020-11-26 01:39:38 +00:00
|
|
|
|
{
|
2021-06-10 20:31:45 +00:00
|
|
|
|
ASSERT(basicInfo); // Container for serviceName
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Allocate a copy for the caller */
|
2020-11-26 01:39:38 +00:00
|
|
|
|
PWCHAR buf = ExAllocatePoolWithTag(PagedPool, serviceName.Length, TAG_IO);
|
|
|
|
|
if (!buf)
|
|
|
|
|
{
|
2021-06-10 20:31:45 +00:00
|
|
|
|
status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
goto Cleanup;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
}
|
|
|
|
|
RtlMoveMemory(buf, serviceName.Buffer, serviceName.Length);
|
|
|
|
|
ServiceName->MaximumLength = serviceName.Length;
|
|
|
|
|
ServiceName->Length = serviceName.Length;
|
|
|
|
|
ServiceName->Buffer = buf;
|
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-26 01:39:38 +00:00
|
|
|
|
*DriverName = driverName;
|
2021-06-10 20:31:45 +00:00
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
|
if (basicInfo)
|
|
|
|
|
ExFreePoolWithTag(basicInfo, TAG_IO);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2021-06-10 21:11:27 +00:00
|
|
|
|
if (!NT_SUCCESS(status) && driverName.Buffer)
|
|
|
|
|
ExFreePoolWithTag(driverName.Buffer, TAG_IO);
|
|
|
|
|
|
2021-06-10 20:31:45 +00:00
|
|
|
|
return status;
|
2005-05-19 22:02:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-14 19:21:38 +00:00
|
|
|
|
/*
|
|
|
|
|
* RETURNS
|
|
|
|
|
* TRUE if String2 contains String1 as a suffix.
|
|
|
|
|
*/
|
|
|
|
|
BOOLEAN
|
|
|
|
|
NTAPI
|
|
|
|
|
IopSuffixUnicodeString(
|
|
|
|
|
IN PCUNICODE_STRING String1,
|
|
|
|
|
IN PCUNICODE_STRING String2)
|
|
|
|
|
{
|
|
|
|
|
PWCHAR pc1;
|
|
|
|
|
PWCHAR pc2;
|
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
|
|
if (String2->Length < String1->Length)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
Length = String1->Length / 2;
|
|
|
|
|
pc1 = String1->Buffer;
|
|
|
|
|
pc2 = &String2->Buffer[String2->Length / sizeof(WCHAR) - Length];
|
|
|
|
|
|
|
|
|
|
if (pc1 && pc2)
|
|
|
|
|
{
|
|
|
|
|
while (Length--)
|
|
|
|
|
{
|
|
|
|
|
if( *pc1++ != *pc2++ )
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-27 19:41:32 +00:00
|
|
|
|
/*
|
|
|
|
|
* IopDisplayLoadingMessage
|
|
|
|
|
*
|
|
|
|
|
* Display 'Loading XXX...' message.
|
|
|
|
|
*/
|
2010-12-21 21:48:29 +00:00
|
|
|
|
VOID
|
2005-05-18 19:08:00 +00:00
|
|
|
|
FASTCALL
|
2010-03-13 23:19:05 +00:00
|
|
|
|
IopDisplayLoadingMessage(PUNICODE_STRING ServiceName)
|
2004-03-27 19:41:32 +00:00
|
|
|
|
{
|
2005-05-18 19:08:00 +00:00
|
|
|
|
CHAR TextBuffer[256];
|
2010-03-14 19:21:38 +00:00
|
|
|
|
UNICODE_STRING DotSys = RTL_CONSTANT_STRING(L".SYS");
|
2007-01-25 17:51:45 +00:00
|
|
|
|
|
2007-01-25 01:13:09 +00:00
|
|
|
|
if (ExpInTextModeSetup) return;
|
2010-04-03 07:44:38 +00:00
|
|
|
|
if (!KeLoaderBlock) return;
|
2010-03-13 23:19:05 +00:00
|
|
|
|
RtlUpcaseUnicodeString(ServiceName, ServiceName, FALSE);
|
|
|
|
|
snprintf(TextBuffer, sizeof(TextBuffer),
|
2013-10-13 23:04:13 +00:00
|
|
|
|
"%s%sSystem32\\Drivers\\%wZ%s\r\n",
|
2010-03-13 23:19:05 +00:00
|
|
|
|
KeLoaderBlock->ArcBootDeviceName,
|
|
|
|
|
KeLoaderBlock->NtBootPathName,
|
2010-03-14 19:21:38 +00:00
|
|
|
|
ServiceName,
|
|
|
|
|
IopSuffixUnicodeString(&DotSys, ServiceName) ? "" : ".SYS");
|
2005-05-18 19:08:00 +00:00
|
|
|
|
HalDisplayString(TextBuffer);
|
2004-03-27 19:41:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* IopNormalizeImagePath
|
|
|
|
|
*
|
|
|
|
|
* Normalize an image path to contain complete path.
|
|
|
|
|
*
|
|
|
|
|
* Parameters
|
|
|
|
|
* ImagePath
|
|
|
|
|
* The input path and on exit the result path. ImagePath.Buffer
|
|
|
|
|
* must be allocated by ExAllocatePool on input. Caller is responsible
|
|
|
|
|
* for freeing the buffer when it's no longer needed.
|
|
|
|
|
*
|
|
|
|
|
* ServiceName
|
|
|
|
|
* Name of the service that ImagePath belongs to.
|
|
|
|
|
*
|
|
|
|
|
* Return Value
|
|
|
|
|
* Status
|
|
|
|
|
*
|
|
|
|
|
* Remarks
|
|
|
|
|
* The input image path isn't freed on error.
|
|
|
|
|
*/
|
2012-12-19 23:49:13 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
FASTCALL
|
2004-03-27 19:41:32 +00:00
|
|
|
|
IopNormalizeImagePath(
|
2014-10-23 17:59:16 +00:00
|
|
|
|
_Inout_ _When_(return>=0, _At_(ImagePath->Buffer, _Post_notnull_ __drv_allocatesMem(Mem)))
|
|
|
|
|
PUNICODE_STRING ImagePath,
|
|
|
|
|
_In_ PUNICODE_STRING ServiceName)
|
2004-03-27 19:41:32 +00:00
|
|
|
|
{
|
2014-10-23 22:05:56 +00:00
|
|
|
|
UNICODE_STRING SystemRootString = RTL_CONSTANT_STRING(L"\\SystemRoot\\");
|
2015-03-16 00:25:32 +00:00
|
|
|
|
UNICODE_STRING DriversPathString = RTL_CONSTANT_STRING(L"\\SystemRoot\\System32\\drivers\\");
|
2014-10-23 22:05:56 +00:00
|
|
|
|
UNICODE_STRING DotSysString = RTL_CONSTANT_STRING(L".sys");
|
2014-10-23 17:59:16 +00:00
|
|
|
|
UNICODE_STRING InputImagePath;
|
|
|
|
|
|
|
|
|
|
DPRINT("Normalizing image path '%wZ' for service '%wZ'\n", ImagePath, ServiceName);
|
|
|
|
|
|
2014-10-23 22:05:56 +00:00
|
|
|
|
InputImagePath = *ImagePath;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (InputImagePath.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
ImagePath->Length = 0;
|
2014-10-23 22:05:56 +00:00
|
|
|
|
ImagePath->MaximumLength = DriversPathString.Length +
|
|
|
|
|
ServiceName->Length +
|
|
|
|
|
DotSysString.Length +
|
|
|
|
|
sizeof(UNICODE_NULL);
|
|
|
|
|
ImagePath->Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
ImagePath->MaximumLength,
|
|
|
|
|
TAG_IO);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (ImagePath->Buffer == NULL)
|
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
2014-10-23 22:05:56 +00:00
|
|
|
|
RtlCopyUnicodeString(ImagePath, &DriversPathString);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
RtlAppendUnicodeStringToString(ImagePath, ServiceName);
|
2014-10-23 22:05:56 +00:00
|
|
|
|
RtlAppendUnicodeStringToString(ImagePath, &DotSysString);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
else if (InputImagePath.Buffer[0] != L'\\')
|
|
|
|
|
{
|
|
|
|
|
ImagePath->Length = 0;
|
2014-10-23 22:05:56 +00:00
|
|
|
|
ImagePath->MaximumLength = SystemRootString.Length +
|
|
|
|
|
InputImagePath.Length +
|
|
|
|
|
sizeof(UNICODE_NULL);
|
|
|
|
|
ImagePath->Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
ImagePath->MaximumLength,
|
|
|
|
|
TAG_IO);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (ImagePath->Buffer == NULL)
|
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
2014-10-23 22:05:56 +00:00
|
|
|
|
RtlCopyUnicodeString(ImagePath, &SystemRootString);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
RtlAppendUnicodeStringToString(ImagePath, &InputImagePath);
|
|
|
|
|
|
|
|
|
|
/* Free caller's string */
|
|
|
|
|
ExFreePoolWithTag(InputImagePath.Buffer, TAG_RTLREGISTRY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINT("Normalized image path is '%wZ' for service '%wZ'\n", ImagePath, ServiceName);
|
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2004-03-27 19:41:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Initialize a loaded driver
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*
|
2020-11-20 14:18:43 +00:00
|
|
|
|
* @param[in] ModuleObject
|
|
|
|
|
* Module object representing the driver. It can be retrieved by IopLoadServiceModule.
|
|
|
|
|
* Freed on failure, so in a such case this should not be accessed anymore
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*
|
2020-11-25 00:18:31 +00:00
|
|
|
|
* @param[in] ServiceHandle
|
|
|
|
|
* Handle to a driver's CCS/Services/<ServiceName> key
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*
|
2020-11-20 14:18:43 +00:00
|
|
|
|
* @param[out] DriverObject
|
|
|
|
|
* This contains the driver object if it was created (even with unsuccessfull result)
|
2005-04-11 17:28:14 +00:00
|
|
|
|
*
|
2020-11-20 14:18:43 +00:00
|
|
|
|
* @param[out] DriverEntryStatus
|
|
|
|
|
* This 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)
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*
|
2020-11-20 14:18:43 +00:00
|
|
|
|
* @return Status of the operation
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*/
|
2014-10-23 17:59:16 +00:00
|
|
|
|
NTSTATUS
|
2004-03-27 19:41:32 +00:00
|
|
|
|
IopInitializeDriverModule(
|
2020-11-20 14:18:43 +00:00
|
|
|
|
_In_ PLDR_DATA_TABLE_ENTRY ModuleObject,
|
2020-11-25 00:18:31 +00:00
|
|
|
|
_In_ HANDLE ServiceHandle,
|
2020-11-20 14:18:43 +00:00
|
|
|
|
_Out_ PDRIVER_OBJECT *OutDriverObject,
|
|
|
|
|
_Out_ NTSTATUS *DriverEntryStatus)
|
2004-03-27 19:41:32 +00:00
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
UNICODE_STRING DriverName, RegistryPath, ServiceName;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
PAGED_CODE();
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-26 01:39:38 +00:00
|
|
|
|
Status = IopGetDriverNames(ServiceHandle, &DriverName, &ServiceName);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2020-11-20 14:18:43 +00:00
|
|
|
|
{
|
|
|
|
|
MmUnloadSystemImage(ModuleObject);
|
2020-11-26 01:39:38 +00:00
|
|
|
|
return Status;
|
2020-11-20 14:18:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINT("Driver name: '%wZ'\n", &DriverName);
|
|
|
|
|
|
2021-06-10 23:30:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* Retrieve the driver's PE image NT header and perform some sanity checks.
|
|
|
|
|
* NOTE: We suppose that since the driver has been successfully loaded,
|
|
|
|
|
* its NT and optional headers are all valid and have expected sizes.
|
|
|
|
|
*/
|
|
|
|
|
PIMAGE_NT_HEADERS NtHeaders = RtlImageNtHeader(ModuleObject->DllBase);
|
|
|
|
|
ASSERT(NtHeaders);
|
2021-09-05 23:05:14 +00:00
|
|
|
|
// NOTE: ModuleObject->SizeOfImage is actually (number of PTEs)*PAGE_SIZE.
|
|
|
|
|
ASSERT(ModuleObject->SizeOfImage == ROUND_TO_PAGES(NtHeaders->OptionalHeader.SizeOfImage));
|
2021-06-10 23:30:40 +00:00
|
|
|
|
ASSERT(ModuleObject->EntryPoint == RVA(ModuleObject->DllBase, NtHeaders->OptionalHeader.AddressOfEntryPoint));
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Obtain the registry path for the DriverInit routine */
|
2020-11-25 00:18:31 +00:00
|
|
|
|
PKEY_NAME_INFORMATION nameInfo;
|
2020-11-26 01:39:38 +00:00
|
|
|
|
ULONG infoLength;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
Status = ZwQueryKey(ServiceHandle, KeyNameInformation, NULL, 0, &infoLength);
|
|
|
|
|
if (Status == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
|
{
|
|
|
|
|
nameInfo = ExAllocatePoolWithTag(NonPagedPool, infoLength, TAG_IO);
|
|
|
|
|
if (nameInfo)
|
|
|
|
|
{
|
|
|
|
|
Status = ZwQueryKey(ServiceHandle,
|
|
|
|
|
KeyNameInformation,
|
|
|
|
|
nameInfo,
|
|
|
|
|
infoLength,
|
|
|
|
|
&infoLength);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
RegistryPath.Length = nameInfo->NameLength;
|
|
|
|
|
RegistryPath.MaximumLength = nameInfo->NameLength;
|
|
|
|
|
RegistryPath.Buffer = nameInfo->Name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Status = NT_SUCCESS(Status) ? STATUS_UNSUCCESSFUL : Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-25 00:18:31 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
MmUnloadSystemImage(ModuleObject);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
/* Create the driver object */
|
|
|
|
|
ULONG ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
OBJECT_ATTRIBUTES objAttrs;
|
|
|
|
|
PDRIVER_OBJECT driverObject;
|
|
|
|
|
InitializeObjectAttributes(&objAttrs,
|
|
|
|
|
&DriverName,
|
|
|
|
|
OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
Status = ObCreateObject(KernelMode,
|
|
|
|
|
IoDriverObjectType,
|
|
|
|
|
&objAttrs,
|
|
|
|
|
KernelMode,
|
|
|
|
|
NULL,
|
|
|
|
|
ObjectSize,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
(PVOID*)&driverObject);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
MmUnloadSystemImage(ModuleObject);
|
|
|
|
|
DPRINT1("Error while creating driver object \"%wZ\" status %x\n", &DriverName, Status);
|
|
|
|
|
return Status;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
2020-11-20 14:18:43 +00:00
|
|
|
|
|
|
|
|
|
DPRINT("Created driver object 0x%p for \"%wZ\"\n", driverObject, &DriverName);
|
|
|
|
|
|
|
|
|
|
RtlZeroMemory(driverObject, ObjectSize);
|
|
|
|
|
driverObject->Type = IO_TYPE_DRIVER;
|
|
|
|
|
driverObject->Size = sizeof(DRIVER_OBJECT);
|
2021-06-10 23:30:40 +00:00
|
|
|
|
|
|
|
|
|
/* Set the legacy flag if this is not a WDM driver */
|
|
|
|
|
if (!(NtHeaders->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_WDM_DRIVER))
|
|
|
|
|
driverObject->Flags |= DRVO_LEGACY_DRIVER;
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
driverObject->DriverSection = ModuleObject;
|
|
|
|
|
driverObject->DriverStart = ModuleObject->DllBase;
|
|
|
|
|
driverObject->DriverSize = ModuleObject->SizeOfImage;
|
|
|
|
|
driverObject->DriverInit = ModuleObject->EntryPoint;
|
|
|
|
|
driverObject->HardwareDatabase = &IopHardwareDatabaseKey;
|
|
|
|
|
driverObject->DriverExtension = (PDRIVER_EXTENSION)(driverObject + 1);
|
|
|
|
|
driverObject->DriverExtension->DriverObject = driverObject;
|
|
|
|
|
|
|
|
|
|
/* Loop all Major Functions */
|
|
|
|
|
for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Invalidate each function */
|
|
|
|
|
driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add the Object and get its handle */
|
|
|
|
|
HANDLE hDriver;
|
|
|
|
|
Status = ObInsertObject(driverObject, NULL, FILE_READ_DATA, 0, NULL, &hDriver);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO);
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now reference it */
|
|
|
|
|
Status = ObReferenceObjectByHandle(hDriver,
|
|
|
|
|
0,
|
|
|
|
|
IoDriverObjectType,
|
|
|
|
|
KernelMode,
|
|
|
|
|
(PVOID*)&driverObject,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* Close the extra handle */
|
|
|
|
|
ZwClose(hDriver);
|
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set up the service key name buffer */
|
|
|
|
|
UNICODE_STRING serviceKeyName;
|
|
|
|
|
serviceKeyName.Length = 0;
|
2021-06-10 19:16:27 +00:00
|
|
|
|
// NULL-terminate for Windows compatibility
|
2020-11-25 00:18:31 +00:00
|
|
|
|
serviceKeyName.MaximumLength = ServiceName.MaximumLength + sizeof(UNICODE_NULL);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
serviceKeyName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
serviceKeyName.MaximumLength,
|
|
|
|
|
TAG_IO);
|
|
|
|
|
if (!serviceKeyName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
ObMakeTemporaryObject(driverObject);
|
|
|
|
|
ObDereferenceObject(driverObject);
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy the name and set it in the driver extension */
|
2020-11-25 00:18:31 +00:00
|
|
|
|
RtlCopyUnicodeString(&serviceKeyName, &ServiceName);
|
2020-11-26 01:39:38 +00:00
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
driverObject->DriverExtension->ServiceKeyName = serviceKeyName;
|
|
|
|
|
|
|
|
|
|
/* Make a copy of the driver name to store in the driver object */
|
|
|
|
|
UNICODE_STRING driverNamePaged;
|
|
|
|
|
driverNamePaged.Length = 0;
|
2021-06-10 19:16:27 +00:00
|
|
|
|
// NULL-terminate for Windows compatibility
|
2020-11-20 14:18:43 +00:00
|
|
|
|
driverNamePaged.MaximumLength = DriverName.MaximumLength + sizeof(UNICODE_NULL);
|
|
|
|
|
driverNamePaged.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
driverNamePaged.MaximumLength,
|
|
|
|
|
TAG_IO);
|
|
|
|
|
if (!driverNamePaged.Buffer)
|
2016-04-14 15:18:53 +00:00
|
|
|
|
{
|
2020-11-20 14:18:43 +00:00
|
|
|
|
ObMakeTemporaryObject(driverObject);
|
|
|
|
|
ObDereferenceObject(driverObject);
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtlCopyUnicodeString(&driverNamePaged, &DriverName);
|
|
|
|
|
driverObject->DriverName = driverNamePaged;
|
|
|
|
|
|
|
|
|
|
/* Finally, call its init function */
|
2020-11-25 00:18:31 +00:00
|
|
|
|
Status = driverObject->DriverInit(driverObject, &RegistryPath);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
*DriverEntryStatus = Status;
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &DriverName, Status);
|
|
|
|
|
// return a special status value in case of failure
|
|
|
|
|
Status = STATUS_FAILED_DRIVER_ENTRY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* HACK: We're going to say if we don't have any DOs from DriverEntry, then we're not legacy.
|
|
|
|
|
* Other parts of the I/O manager depend on this behavior */
|
|
|
|
|
if (!driverObject->DeviceObject)
|
|
|
|
|
{
|
|
|
|
|
driverObject->Flags &= ~DRVO_LEGACY_DRIVER;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 15:17:30 +00:00
|
|
|
|
/* Windows does this fixup, keep it for compatibility */
|
2020-11-20 14:18:43 +00:00
|
|
|
|
for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Make sure the driver didn't set any dispatch entry point to NULL!
|
|
|
|
|
* Doing so is illegal; drivers shouldn't touch entry points they
|
|
|
|
|
* do not implement.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Check if it did so anyway */
|
|
|
|
|
if (!driverObject->MajorFunction[i])
|
|
|
|
|
{
|
|
|
|
|
/* Print a warning in the debug log */
|
|
|
|
|
DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
|
|
|
|
|
&driverObject->DriverName, i);
|
|
|
|
|
|
|
|
|
|
/* Fix it up */
|
|
|
|
|
driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
|
|
|
|
|
}
|
2016-04-14 15:18:53 +00:00
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
// TODO: for legacy drivers, unload the driver if it didn't create any DO
|
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
|
2016-04-14 15:18:53 +00:00
|
|
|
|
RtlFreeUnicodeString(&DriverName);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-20 14:18:43 +00:00
|
|
|
|
// if the driver entry has been failed, clear the object
|
|
|
|
|
ObMakeTemporaryObject(driverObject);
|
|
|
|
|
ObDereferenceObject(driverObject);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
*OutDriverObject = driverObject;
|
2016-11-07 15:51:56 +00:00
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
MmFreeDriverInitialization((PLDR_DATA_TABLE_ENTRY)driverObject->DriverSection);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/* Set the driver as initialized */
|
2020-11-20 14:18:43 +00:00
|
|
|
|
IopReadyDeviceObjects(driverObject);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
if (PnpSystemInit) IopReinitializeDrivers();
|
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2004-03-27 19:41:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-22 18:02:53 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Used for images already loaded (boot drivers)
|
|
|
|
|
//
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2007-02-22 18:02:53 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
LdrProcessDriverModule(PLDR_DATA_TABLE_ENTRY LdrEntry,
|
|
|
|
|
PUNICODE_STRING FileName,
|
|
|
|
|
PLDR_DATA_TABLE_ENTRY *ModuleObject)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
UNICODE_STRING BaseName, BaseDirectory;
|
|
|
|
|
PLOAD_IMPORTS LoadedImports = (PVOID)-2;
|
|
|
|
|
PCHAR MissingApiName, Buffer;
|
|
|
|
|
PWCHAR MissingDriverName;
|
|
|
|
|
PVOID DriverBase = LdrEntry->DllBase;
|
|
|
|
|
|
|
|
|
|
/* Allocate a buffer we'll use for names */
|
2019-04-15 06:25:23 +00:00
|
|
|
|
Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
MAXIMUM_FILENAME_LENGTH,
|
|
|
|
|
TAG_LDR_WSTR);
|
2007-02-22 18:02:53 +00:00
|
|
|
|
if (!Buffer)
|
|
|
|
|
{
|
|
|
|
|
/* Fail */
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for a separator */
|
|
|
|
|
if (FileName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
|
|
|
|
|
{
|
|
|
|
|
PWCHAR p;
|
|
|
|
|
ULONG BaseLength;
|
|
|
|
|
|
|
|
|
|
/* Loop the path until we get to the base name */
|
|
|
|
|
p = &FileName->Buffer[FileName->Length / sizeof(WCHAR)];
|
|
|
|
|
while (*(p - 1) != OBJ_NAME_PATH_SEPARATOR) p--;
|
|
|
|
|
|
|
|
|
|
/* Get the length */
|
|
|
|
|
BaseLength = (ULONG)(&FileName->Buffer[FileName->Length / sizeof(WCHAR)] - p);
|
|
|
|
|
BaseLength *= sizeof(WCHAR);
|
|
|
|
|
|
|
|
|
|
/* Setup the string */
|
|
|
|
|
BaseName.Length = (USHORT)BaseLength;
|
|
|
|
|
BaseName.Buffer = p;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Otherwise, we already have a base name */
|
|
|
|
|
BaseName.Length = FileName->Length;
|
|
|
|
|
BaseName.Buffer = FileName->Buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Setup the maximum length */
|
|
|
|
|
BaseName.MaximumLength = BaseName.Length;
|
|
|
|
|
|
|
|
|
|
/* Now compute the base directory */
|
|
|
|
|
BaseDirectory = *FileName;
|
|
|
|
|
BaseDirectory.Length -= BaseName.Length;
|
|
|
|
|
BaseDirectory.MaximumLength = BaseDirectory.Length;
|
|
|
|
|
|
|
|
|
|
/* Resolve imports */
|
|
|
|
|
MissingApiName = Buffer;
|
|
|
|
|
Status = MiResolveImageReferences(DriverBase,
|
|
|
|
|
&BaseDirectory,
|
|
|
|
|
NULL,
|
|
|
|
|
&MissingApiName,
|
|
|
|
|
&MissingDriverName,
|
|
|
|
|
&LoadedImports);
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
|
|
|
|
/* Free the temporary buffer */
|
|
|
|
|
ExFreePoolWithTag(Buffer, TAG_LDR_WSTR);
|
|
|
|
|
|
|
|
|
|
/* Check the result of the imports resolution */
|
2007-02-28 19:04:27 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2007-02-22 18:02:53 +00:00
|
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
|
*ModuleObject = LdrEntry;
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 00:23:01 +00:00
|
|
|
|
PDEVICE_OBJECT
|
|
|
|
|
IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance);
|
|
|
|
|
|
2003-10-15 17:04:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* IopInitializeBuiltinDriver
|
|
|
|
|
*
|
|
|
|
|
* Initialize a driver that is already loaded in memory.
|
|
|
|
|
*/
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2021-05-11 15:13:14 +00:00
|
|
|
|
static
|
2021-01-13 00:23:01 +00:00
|
|
|
|
BOOLEAN
|
2014-01-17 21:49:43 +00:00
|
|
|
|
IopInitializeBuiltinDriver(IN PLDR_DATA_TABLE_ENTRY BootLdrEntry)
|
2003-10-15 17:04:39 +00:00
|
|
|
|
{
|
2007-02-22 18:02:53 +00:00
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
|
NTSTATUS Status;
|
2017-05-07 18:15:12 +00:00
|
|
|
|
PWCHAR Buffer, FileNameWithoutPath;
|
2017-05-07 18:12:18 +00:00
|
|
|
|
PWSTR FileExtension;
|
2014-01-17 21:49:43 +00:00
|
|
|
|
PUNICODE_STRING ModuleName = &BootLdrEntry->BaseDllName;
|
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
|
|
|
|
PLIST_ENTRY NextEntry;
|
2007-03-22 17:13:14 +00:00
|
|
|
|
UNICODE_STRING ServiceName;
|
2016-04-06 20:00:34 +00:00
|
|
|
|
BOOLEAN Success;
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* Display 'Loading XXX...' message
|
|
|
|
|
*/
|
|
|
|
|
IopDisplayLoadingMessage(ModuleName);
|
|
|
|
|
InbvIndicateProgress();
|
|
|
|
|
|
2017-05-08 06:54:35 +00:00
|
|
|
|
Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
ModuleName->Length + sizeof(UNICODE_NULL),
|
|
|
|
|
TAG_IO);
|
2017-05-08 00:58:45 +00:00
|
|
|
|
if (Buffer == NULL)
|
|
|
|
|
{
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return FALSE;
|
2017-05-08 00:58:45 +00:00
|
|
|
|
}
|
2017-05-07 18:15:12 +00:00
|
|
|
|
|
|
|
|
|
RtlCopyMemory(Buffer, ModuleName->Buffer, ModuleName->Length);
|
|
|
|
|
Buffer[ModuleName->Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* Generate filename without path (not needed by freeldr)
|
|
|
|
|
*/
|
2017-05-07 18:15:12 +00:00
|
|
|
|
FileNameWithoutPath = wcsrchr(Buffer, L'\\');
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (FileNameWithoutPath == NULL)
|
|
|
|
|
{
|
2017-05-07 18:15:12 +00:00
|
|
|
|
FileNameWithoutPath = Buffer;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FileNameWithoutPath++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Strip the file extension from ServiceName
|
|
|
|
|
*/
|
2016-04-06 20:00:34 +00:00
|
|
|
|
Success = RtlCreateUnicodeString(&ServiceName, FileNameWithoutPath);
|
2017-05-08 06:54:35 +00:00
|
|
|
|
ExFreePoolWithTag(Buffer, TAG_IO);
|
2016-04-06 20:00:34 +00:00
|
|
|
|
if (!Success)
|
|
|
|
|
{
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return FALSE;
|
2016-04-06 20:00:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-07 18:12:18 +00:00
|
|
|
|
FileExtension = wcsrchr(ServiceName.Buffer, L'.');
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (FileExtension != NULL)
|
|
|
|
|
{
|
|
|
|
|
ServiceName.Length -= (USHORT)wcslen(FileExtension) * sizeof(WCHAR);
|
2017-05-07 18:15:12 +00:00
|
|
|
|
FileExtension[0] = UNICODE_NULL;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
UNICODE_STRING RegistryPath;
|
|
|
|
|
|
|
|
|
|
// Make the registry path for the driver
|
|
|
|
|
RegistryPath.Length = 0;
|
|
|
|
|
RegistryPath.MaximumLength = sizeof(ServicesKeyName) + ServiceName.Length;
|
|
|
|
|
RegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool, RegistryPath.MaximumLength, TAG_IO);
|
|
|
|
|
if (RegistryPath.Buffer == NULL)
|
|
|
|
|
{
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return FALSE;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
RtlAppendUnicodeToString(&RegistryPath, ServicesKeyName);
|
|
|
|
|
RtlAppendUnicodeStringToString(&RegistryPath, &ServiceName);
|
|
|
|
|
RtlFreeUnicodeString(&ServiceName);
|
|
|
|
|
|
|
|
|
|
HANDLE serviceHandle;
|
|
|
|
|
Status = IopOpenRegistryKeyEx(&serviceHandle, NULL, &RegistryPath, KEY_READ);
|
|
|
|
|
RtlFreeUnicodeString(&RegistryPath);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return FALSE;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
/* Lookup the new Ldr entry in PsLoadedModuleList */
|
2021-06-10 19:16:27 +00:00
|
|
|
|
for (NextEntry = PsLoadedModuleList.Flink;
|
|
|
|
|
NextEntry != &PsLoadedModuleList;
|
|
|
|
|
NextEntry = NextEntry->Flink)
|
2014-10-23 17:59:16 +00:00
|
|
|
|
{
|
|
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry,
|
|
|
|
|
LDR_DATA_TABLE_ENTRY,
|
|
|
|
|
InLoadOrderLinks);
|
|
|
|
|
if (RtlEqualUnicodeString(ModuleName, &LdrEntry->BaseDllName, TRUE))
|
|
|
|
|
{
|
2017-05-07 18:12:18 +00:00
|
|
|
|
break;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-01 01:45:59 +00:00
|
|
|
|
ASSERT(NextEntry != &PsLoadedModuleList);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize the driver
|
|
|
|
|
*/
|
2020-11-20 14:18:43 +00:00
|
|
|
|
NTSTATUS driverEntryStatus;
|
2020-11-15 14:33:42 +00:00
|
|
|
|
Status = IopInitializeDriverModule(LdrEntry,
|
2020-11-25 00:18:31 +00:00
|
|
|
|
serviceHandle,
|
2020-11-20 14:18:43 +00:00
|
|
|
|
&DriverObject,
|
|
|
|
|
&driverEntryStatus);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-15 14:33:42 +00:00
|
|
|
|
DPRINT1("Driver '%wZ' load failed, status (%x)\n", ModuleName, Status);
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return FALSE;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 00:23:01 +00:00
|
|
|
|
// The driver has been loaded, now check if where are any PDOs
|
|
|
|
|
// for that driver, and queue AddDevice call for them.
|
|
|
|
|
// The check is possible because HKLM/SYSTEM/CCS/Services/<ServiceName>/Enum directory
|
|
|
|
|
// is populated upon a new device arrival based on a (critical) device database
|
2021-05-11 15:13:14 +00:00
|
|
|
|
|
2021-01-13 00:23:01 +00:00
|
|
|
|
// Legacy drivers may add devices inside DriverEntry.
|
|
|
|
|
// We're lazy and always assume that they are doing so
|
2021-06-10 19:16:27 +00:00
|
|
|
|
BOOLEAN deviceAdded = !!(DriverObject->Flags & DRVO_LEGACY_DRIVER);
|
2021-01-13 00:23:01 +00:00
|
|
|
|
|
|
|
|
|
HANDLE enumServiceHandle;
|
|
|
|
|
UNICODE_STRING enumName = RTL_CONSTANT_STRING(L"Enum");
|
|
|
|
|
|
|
|
|
|
Status = IopOpenRegistryKeyEx(&enumServiceHandle, serviceHandle, &enumName, KEY_READ);
|
|
|
|
|
ZwClose(serviceHandle);
|
|
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
2021-06-10 19:16:27 +00:00
|
|
|
|
ULONG instanceCount = 0;
|
2021-01-13 00:23:01 +00:00
|
|
|
|
PKEY_VALUE_FULL_INFORMATION kvInfo;
|
|
|
|
|
Status = IopGetRegistryValue(enumServiceHandle, L"Count", &kvInfo);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
goto Cleanup;
|
|
|
|
|
}
|
2021-06-10 19:20:17 +00:00
|
|
|
|
if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
|
2021-01-13 00:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
goto Cleanup;
|
|
|
|
|
}
|
2021-06-16 22:29:58 +00:00
|
|
|
|
|
|
|
|
|
RtlMoveMemory(&instanceCount,
|
|
|
|
|
(PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
|
|
|
|
|
sizeof(ULONG));
|
2021-01-13 00:23:01 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
|
|
|
|
|
DPRINT("Processing %u instances for %wZ module\n", instanceCount, ModuleName);
|
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
for (ULONG i = 0; i < instanceCount; i++)
|
2021-01-13 00:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
WCHAR num[11];
|
|
|
|
|
UNICODE_STRING instancePath;
|
|
|
|
|
RtlStringCchPrintfW(num, sizeof(num), L"%u", i);
|
|
|
|
|
|
|
|
|
|
Status = IopGetRegistryValue(enumServiceHandle, num, &kvInfo);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
|
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 19:20:17 +00:00
|
|
|
|
instancePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
|
2021-06-10 19:16:27 +00:00
|
|
|
|
instancePath.MaximumLength = kvInfo->DataLength;
|
2021-01-13 00:23:01 +00:00
|
|
|
|
instancePath.Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
instancePath.MaximumLength,
|
|
|
|
|
TAG_IO);
|
|
|
|
|
if (instancePath.Buffer)
|
|
|
|
|
{
|
|
|
|
|
RtlMoveMemory(instancePath.Buffer,
|
2021-06-10 19:20:17 +00:00
|
|
|
|
(PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
|
|
|
|
|
instancePath.Length);
|
|
|
|
|
instancePath.Buffer[instancePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
2021-01-13 00:23:01 +00:00
|
|
|
|
|
|
|
|
|
PDEVICE_OBJECT pdo = IopGetDeviceObjectFromDeviceInstance(&instancePath);
|
|
|
|
|
PiQueueDeviceAction(pdo, PiActionAddBootDevices, NULL, NULL);
|
|
|
|
|
ObDereferenceObject(pdo);
|
|
|
|
|
deviceAdded = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 15:13:14 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
2021-01-13 00:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ZwClose(enumServiceHandle);
|
|
|
|
|
}
|
|
|
|
|
Cleanup:
|
2014-10-23 17:59:16 +00:00
|
|
|
|
/* Remove extra reference from IopInitializeDriverModule */
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
|
2021-01-13 00:23:01 +00:00
|
|
|
|
return deviceAdded;
|
2003-10-15 17:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* IopInitializeBootDrivers
|
|
|
|
|
*
|
|
|
|
|
* Initialize boot drivers and free memory for boot files.
|
|
|
|
|
*
|
|
|
|
|
* Parameters
|
|
|
|
|
* None
|
2005-05-09 01:38:29 +00:00
|
|
|
|
*
|
2003-10-15 17:04:39 +00:00
|
|
|
|
* Return Value
|
|
|
|
|
* None
|
|
|
|
|
*/
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2006-10-01 05:05:57 +00:00
|
|
|
|
VOID
|
|
|
|
|
FASTCALL
|
2003-10-15 17:04:39 +00:00
|
|
|
|
IopInitializeBootDrivers(VOID)
|
|
|
|
|
{
|
2010-04-02 17:57:33 +00:00
|
|
|
|
PLIST_ENTRY ListHead, NextEntry, NextEntry2;
|
2006-10-01 05:05:57 +00:00
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
2006-10-18 17:46:55 +00:00
|
|
|
|
NTSTATUS Status;
|
2007-05-28 21:34:49 +00:00
|
|
|
|
UNICODE_STRING DriverName;
|
2010-04-02 17:57:33 +00:00
|
|
|
|
ULONG i, Index;
|
|
|
|
|
PDRIVER_INFORMATION DriverInfo, DriverInfoTag;
|
|
|
|
|
HANDLE KeyHandle;
|
|
|
|
|
PBOOT_DRIVER_LIST_ENTRY BootEntry;
|
2008-03-31 15:58:59 +00:00
|
|
|
|
DPRINT("IopInitializeBootDrivers()\n");
|
2007-06-11 22:02:55 +00:00
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
/* Create the RAW FS built-in driver */
|
|
|
|
|
RtlInitUnicodeString(&DriverName, L"\\FileSystem\\RAW");
|
|
|
|
|
|
|
|
|
|
Status = IoCreateDriver(&DriverName, RawFsDriverEntry);
|
2006-10-18 17:46:55 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* Fail */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Get highest group order index */
|
|
|
|
|
IopGroupIndex = PpInitGetGroupOrderIndex(NULL);
|
2022-10-10 22:39:40 +00:00
|
|
|
|
if (IopGroupIndex == 0xFFFF)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED_DBGBREAK();
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Allocate the group table */
|
|
|
|
|
IopGroupTable = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
IopGroupIndex * sizeof(LIST_ENTRY),
|
|
|
|
|
TAG_IO);
|
2022-10-10 22:39:40 +00:00
|
|
|
|
if (IopGroupTable == NULL)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED_DBGBREAK();
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Initialize the group table lists */
|
|
|
|
|
for (i = 0; i < IopGroupIndex; i++) InitializeListHead(&IopGroupTable[i]);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2006-10-01 05:05:57 +00:00
|
|
|
|
/* Loop the boot modules */
|
|
|
|
|
ListHead = &KeLoaderBlock->LoadOrderListHead;
|
2021-06-10 19:16:27 +00:00
|
|
|
|
for (NextEntry = ListHead->Flink;
|
|
|
|
|
NextEntry != ListHead;
|
|
|
|
|
NextEntry = NextEntry->Flink)
|
2006-10-01 05:05:57 +00:00
|
|
|
|
{
|
|
|
|
|
/* Get the entry */
|
|
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry,
|
|
|
|
|
LDR_DATA_TABLE_ENTRY,
|
|
|
|
|
InLoadOrderLinks);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Check if the DLL needs to be initialized */
|
|
|
|
|
if (LdrEntry->Flags & LDRP_DRIVER_DEPENDENT_DLL)
|
|
|
|
|
{
|
|
|
|
|
/* Call its entrypoint */
|
|
|
|
|
MmCallDllInitialize(LdrEntry, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Loop the boot drivers */
|
|
|
|
|
ListHead = &KeLoaderBlock->BootDriverListHead;
|
2021-06-10 19:16:27 +00:00
|
|
|
|
for (NextEntry = ListHead->Flink;
|
|
|
|
|
NextEntry != ListHead;
|
|
|
|
|
NextEntry = NextEntry->Flink)
|
2010-04-02 17:57:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* Get the entry */
|
|
|
|
|
BootEntry = CONTAINING_RECORD(NextEntry,
|
|
|
|
|
BOOT_DRIVER_LIST_ENTRY,
|
|
|
|
|
Link);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2021-06-10 23:46:50 +00:00
|
|
|
|
// FIXME: TODO: This LdrEntry is to be used in a special handling
|
|
|
|
|
// for SETUPLDR (a similar procedure is done on Windows), where
|
|
|
|
|
// the loader would, under certain conditions, be loaded in the
|
|
|
|
|
// SETUPLDR-specific code block below...
|
|
|
|
|
#if 0
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Get the driver loader entry */
|
|
|
|
|
LdrEntry = BootEntry->LdrEntry;
|
2021-06-10 23:46:50 +00:00
|
|
|
|
#endif
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Allocate our internal accounting structure */
|
|
|
|
|
DriverInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
sizeof(DRIVER_INFORMATION),
|
|
|
|
|
TAG_IO);
|
|
|
|
|
if (DriverInfo)
|
2006-10-01 05:05:57 +00:00
|
|
|
|
{
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Zero it and initialize it */
|
|
|
|
|
RtlZeroMemory(DriverInfo, sizeof(DRIVER_INFORMATION));
|
|
|
|
|
InitializeListHead(&DriverInfo->Link);
|
|
|
|
|
DriverInfo->DataTableEntry = BootEntry;
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Open the registry key */
|
|
|
|
|
Status = IopOpenRegistryKeyEx(&KeyHandle,
|
|
|
|
|
NULL,
|
|
|
|
|
&BootEntry->RegistryPath,
|
|
|
|
|
KEY_READ);
|
2018-10-27 08:04:22 +00:00
|
|
|
|
DPRINT("IopOpenRegistryKeyEx(%wZ) returned 0x%08lx\n", &BootEntry->RegistryPath, Status);
|
2017-06-02 15:49:12 +00:00
|
|
|
|
#if 0
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
#else // Hack still needed...
|
2010-04-02 17:57:33 +00:00
|
|
|
|
if ((NT_SUCCESS(Status)) || /* ReactOS HACK for SETUPLDR */
|
2010-12-21 21:48:29 +00:00
|
|
|
|
((KeLoaderBlock->SetupLdrBlock) && ((KeyHandle = (PVOID)1)))) // yes, it's an assignment!
|
2017-06-02 15:49:12 +00:00
|
|
|
|
#endif
|
2006-10-01 05:05:57 +00:00
|
|
|
|
{
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Save the handle */
|
|
|
|
|
DriverInfo->ServiceHandle = KeyHandle;
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Get the group oder index */
|
|
|
|
|
Index = PpInitGetGroupOrderIndex(KeyHandle);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Get the tag position */
|
|
|
|
|
DriverInfo->TagPosition = PipGetDriverTagPriority(KeyHandle);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Insert it into the list, at the right place */
|
|
|
|
|
ASSERT(Index < IopGroupIndex);
|
|
|
|
|
NextEntry2 = IopGroupTable[Index].Flink;
|
|
|
|
|
while (NextEntry2 != &IopGroupTable[Index])
|
|
|
|
|
{
|
|
|
|
|
/* Get the driver info */
|
|
|
|
|
DriverInfoTag = CONTAINING_RECORD(NextEntry2,
|
|
|
|
|
DRIVER_INFORMATION,
|
|
|
|
|
Link);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Check if we found the right tag position */
|
|
|
|
|
if (DriverInfoTag->TagPosition > DriverInfo->TagPosition)
|
|
|
|
|
{
|
|
|
|
|
/* We're done */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Next entry */
|
|
|
|
|
NextEntry2 = NextEntry2->Flink;
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Insert us right before the next entry */
|
|
|
|
|
NextEntry2 = NextEntry2->Blink;
|
|
|
|
|
InsertHeadList(NextEntry2, &DriverInfo->Link);
|
2006-10-01 05:05:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Loop each group index */
|
|
|
|
|
for (i = 0; i < IopGroupIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Loop each group table */
|
2021-06-10 19:16:27 +00:00
|
|
|
|
for (NextEntry = IopGroupTable[i].Flink;
|
|
|
|
|
NextEntry != &IopGroupTable[i];
|
|
|
|
|
NextEntry = NextEntry->Flink)
|
2010-04-02 17:57:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* Get the entry */
|
|
|
|
|
DriverInfo = CONTAINING_RECORD(NextEntry,
|
|
|
|
|
DRIVER_INFORMATION,
|
|
|
|
|
Link);
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Get the driver loader entry */
|
|
|
|
|
LdrEntry = DriverInfo->DataTableEntry->LdrEntry;
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2010-04-02 17:57:33 +00:00
|
|
|
|
/* Initialize it */
|
2021-01-13 00:23:01 +00:00
|
|
|
|
if (IopInitializeBuiltinDriver(LdrEntry))
|
|
|
|
|
{
|
|
|
|
|
// it does not make sense to enumerate the tree if there are no new devices added
|
|
|
|
|
PiQueueDeviceAction(IopRootDeviceNode->PhysicalDeviceObject,
|
|
|
|
|
PiActionEnumRootDevices,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2021-05-11 15:13:14 +00:00
|
|
|
|
}
|
2010-04-02 17:57:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-21 21:35:04 +00:00
|
|
|
|
|
2020-06-24 16:34:44 +00:00
|
|
|
|
/* HAL Root Bus is being initialized before loading the boot drivers so this may cause issues
|
|
|
|
|
* when some devices are not being initialized with their drivers. This flag is used to delay
|
|
|
|
|
* all actions with devices (except PnP root device) until boot drivers are loaded.
|
|
|
|
|
* See PiQueueDeviceAction function
|
|
|
|
|
*/
|
|
|
|
|
PnPBootDriversLoaded = TRUE;
|
2021-01-13 01:13:22 +00:00
|
|
|
|
|
|
|
|
|
DbgPrint("BOOT DRIVERS LOADED\n");
|
|
|
|
|
|
|
|
|
|
PiQueueDeviceAction(IopRootDeviceNode->PhysicalDeviceObject,
|
|
|
|
|
PiActionEnumDeviceTree,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2003-10-15 17:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2010-04-03 07:44:38 +00:00
|
|
|
|
VOID
|
|
|
|
|
FASTCALL
|
|
|
|
|
IopInitializeSystemDrivers(VOID)
|
|
|
|
|
{
|
|
|
|
|
PUNICODE_STRING *DriverList, *SavedList;
|
2010-12-21 21:48:29 +00:00
|
|
|
|
|
2021-01-13 01:13:22 +00:00
|
|
|
|
PiPerformSyncDeviceAction(IopRootDeviceNode->PhysicalDeviceObject, PiActionEnumDeviceTree);
|
|
|
|
|
|
2010-04-03 07:44:38 +00:00
|
|
|
|
/* No system drivers on the boot cd */
|
2017-06-02 15:49:12 +00:00
|
|
|
|
if (KeLoaderBlock->SetupLdrBlock) return; // ExpInTextModeSetup
|
2010-12-21 21:48:29 +00:00
|
|
|
|
|
2010-04-03 07:44:38 +00:00
|
|
|
|
/* Get the driver list */
|
|
|
|
|
SavedList = DriverList = CmGetSystemDriverList();
|
|
|
|
|
ASSERT(DriverList);
|
2010-12-21 21:48:29 +00:00
|
|
|
|
|
2010-04-03 07:44:38 +00:00
|
|
|
|
/* Loop it */
|
|
|
|
|
while (*DriverList)
|
|
|
|
|
{
|
|
|
|
|
/* Load the driver */
|
|
|
|
|
ZwLoadDriver(*DriverList);
|
2010-12-21 21:48:29 +00:00
|
|
|
|
|
2010-04-03 07:44:38 +00:00
|
|
|
|
/* Free the entry */
|
|
|
|
|
RtlFreeUnicodeString(*DriverList);
|
|
|
|
|
ExFreePool(*DriverList);
|
2010-12-21 21:48:29 +00:00
|
|
|
|
|
2010-04-03 07:44:38 +00:00
|
|
|
|
/* Next entry */
|
|
|
|
|
InbvIndicateProgress();
|
|
|
|
|
DriverList++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the list */
|
|
|
|
|
ExFreePool(SavedList);
|
2021-01-13 01:13:22 +00:00
|
|
|
|
|
|
|
|
|
PiQueueDeviceAction(IopRootDeviceNode->PhysicalDeviceObject,
|
|
|
|
|
PiActionEnumDeviceTree,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2010-04-03 07:44:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-15 17:04:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* IopUnloadDriver
|
|
|
|
|
*
|
|
|
|
|
* Unloads a device driver.
|
|
|
|
|
*
|
|
|
|
|
* Parameters
|
|
|
|
|
* DriverServiceName
|
|
|
|
|
* Name of the service to unload (registry key).
|
2004-03-27 19:41:32 +00:00
|
|
|
|
*
|
2003-10-15 17:04:39 +00:00
|
|
|
|
* UnloadPnpDrivers
|
|
|
|
|
* Whether to unload Plug & Plug or only legacy drivers. If this
|
|
|
|
|
* parameter is set to FALSE, the routine will unload only legacy
|
|
|
|
|
* drivers.
|
2005-05-09 01:38:29 +00:00
|
|
|
|
*
|
2003-10-15 17:04:39 +00:00
|
|
|
|
* Return Value
|
|
|
|
|
* Status
|
|
|
|
|
*
|
|
|
|
|
* To do
|
|
|
|
|
* Guard the whole function by SEH.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-11-29 20:47:48 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2003-10-15 17:04:39 +00:00
|
|
|
|
IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
|
|
|
|
|
{
|
2019-12-29 12:47:40 +00:00
|
|
|
|
UNICODE_STRING Backslash = RTL_CONSTANT_STRING(L"\\");
|
2014-10-23 17:59:16 +00:00
|
|
|
|
RTL_QUERY_REGISTRY_TABLE QueryTable[2];
|
|
|
|
|
UNICODE_STRING ImagePath;
|
|
|
|
|
UNICODE_STRING ServiceName;
|
|
|
|
|
UNICODE_STRING ObjectName;
|
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
|
PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
|
|
|
|
|
NTSTATUS Status;
|
2019-12-29 12:47:40 +00:00
|
|
|
|
USHORT LastBackslash;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
BOOLEAN SafeToUnload = TRUE;
|
2018-12-20 07:49:00 +00:00
|
|
|
|
KPROCESSOR_MODE PreviousMode;
|
|
|
|
|
UNICODE_STRING CapturedServiceName;
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
2018-12-20 07:49:00 +00:00
|
|
|
|
PreviousMode = ExGetPreviousMode();
|
|
|
|
|
|
|
|
|
|
/* Need the appropriate priviliege */
|
|
|
|
|
if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("No unload privilege!\n");
|
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Capture the service name */
|
2020-12-26 23:31:54 +00:00
|
|
|
|
Status = ProbeAndCaptureUnicodeString(&CapturedServiceName,
|
|
|
|
|
PreviousMode,
|
|
|
|
|
DriverServiceName);
|
2018-12-20 07:49:00 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
2020-11-20 15:51:33 +00:00
|
|
|
|
{
|
2018-12-20 07:49:00 +00:00
|
|
|
|
return Status;
|
2020-11-20 15:51:33 +00:00
|
|
|
|
}
|
2018-12-20 07:49:00 +00:00
|
|
|
|
|
|
|
|
|
DPRINT("IopUnloadDriver('%wZ', %u)\n", &CapturedServiceName, UnloadPnpDrivers);
|
|
|
|
|
|
|
|
|
|
/* We need a service name */
|
2020-12-26 23:33:32 +00:00
|
|
|
|
if (CapturedServiceName.Length == 0 || CapturedServiceName.Buffer == NULL)
|
2018-12-20 07:49:00 +00:00
|
|
|
|
{
|
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* Get the service name from the registry key name
|
|
|
|
|
*/
|
2019-12-29 12:47:40 +00:00
|
|
|
|
Status = RtlFindCharInUnicodeString(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END,
|
|
|
|
|
&CapturedServiceName,
|
|
|
|
|
&Backslash,
|
|
|
|
|
&LastBackslash);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
NT_ASSERT(CapturedServiceName.Length >= LastBackslash + sizeof(WCHAR));
|
|
|
|
|
ServiceName.Buffer = &CapturedServiceName.Buffer[LastBackslash / sizeof(WCHAR) + 1];
|
|
|
|
|
ServiceName.Length = CapturedServiceName.Length - LastBackslash - sizeof(WCHAR);
|
|
|
|
|
ServiceName.MaximumLength = CapturedServiceName.MaximumLength - LastBackslash - sizeof(WCHAR);
|
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
else
|
2019-12-29 12:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
ServiceName = CapturedServiceName;
|
|
|
|
|
}
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Construct the driver object name
|
|
|
|
|
*/
|
2019-12-29 12:47:40 +00:00
|
|
|
|
Status = RtlUShortAdd(sizeof(DRIVER_ROOT_NAME),
|
|
|
|
|
ServiceName.Length,
|
|
|
|
|
&ObjectName.MaximumLength);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
ObjectName.Length = 0;
|
2017-05-08 06:54:35 +00:00
|
|
|
|
ObjectName.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
ObjectName.MaximumLength,
|
|
|
|
|
TAG_IO);
|
2018-12-20 07:49:00 +00:00
|
|
|
|
if (!ObjectName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
2019-12-29 12:47:40 +00:00
|
|
|
|
NT_VERIFY(NT_SUCCESS(RtlAppendUnicodeToString(&ObjectName, DRIVER_ROOT_NAME)));
|
|
|
|
|
NT_VERIFY(NT_SUCCESS(RtlAppendUnicodeStringToString(&ObjectName, &ServiceName)));
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find the driver object
|
|
|
|
|
*/
|
|
|
|
|
Status = ObReferenceObjectByName(&ObjectName,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
IoDriverObjectType,
|
|
|
|
|
KernelMode,
|
|
|
|
|
0,
|
|
|
|
|
(PVOID*)&DriverObject);
|
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Can't locate driver object for %wZ\n", &ObjectName);
|
2017-05-08 06:54:35 +00:00
|
|
|
|
ExFreePoolWithTag(ObjectName.Buffer, TAG_IO);
|
2018-12-20 07:49:00 +00:00
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-07 18:12:18 +00:00
|
|
|
|
/* Free the buffer for driver object name */
|
2017-05-08 06:54:35 +00:00
|
|
|
|
ExFreePoolWithTag(ObjectName.Buffer, TAG_IO);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/* Check that driver is not already unloading */
|
|
|
|
|
if (DriverObject->Flags & DRVO_UNLOAD_INVOKED)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Driver deletion pending\n");
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
2018-12-20 07:49:00 +00:00
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
return STATUS_DELETE_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get path of service...
|
|
|
|
|
*/
|
|
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&ImagePath, NULL);
|
|
|
|
|
|
|
|
|
|
QueryTable[0].Name = L"ImagePath";
|
|
|
|
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
|
|
|
|
QueryTable[0].EntryContext = &ImagePath;
|
|
|
|
|
|
|
|
|
|
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
|
2018-12-20 07:49:00 +00:00
|
|
|
|
CapturedServiceName.Buffer,
|
2014-10-23 17:59:16 +00:00
|
|
|
|
QueryTable,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2018-12-20 07:49:00 +00:00
|
|
|
|
/* We no longer need service name */
|
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
|
|
|
|
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("RtlQueryRegistryValues() failed (Status %x)\n", Status);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Normalize the image path for all later processing.
|
|
|
|
|
*/
|
|
|
|
|
Status = IopNormalizeImagePath(&ImagePath, &ServiceName);
|
|
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("IopNormalizeImagePath() failed (Status %x)\n", Status);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-07 18:12:18 +00:00
|
|
|
|
/* Free the service path */
|
2014-10-23 17:59:16 +00:00
|
|
|
|
ExFreePool(ImagePath.Buffer);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Unload the module and release the references to the device object
|
|
|
|
|
*/
|
2004-03-27 19:41:32 +00:00
|
|
|
|
|
2007-10-03 11:54:31 +00:00
|
|
|
|
/* Call the load/unload routine, depending on current process */
|
2014-10-23 17:59:16 +00:00
|
|
|
|
if (DriverObject->DriverUnload && DriverObject->DriverSection &&
|
|
|
|
|
(UnloadPnpDrivers || (DriverObject->Flags & DRVO_LEGACY_DRIVER)))
|
|
|
|
|
{
|
|
|
|
|
/* Loop through each device object of the driver
|
|
|
|
|
and set DOE_UNLOAD_PENDING flag */
|
|
|
|
|
DeviceObject = DriverObject->DeviceObject;
|
|
|
|
|
while (DeviceObject)
|
|
|
|
|
{
|
|
|
|
|
/* Set the unload pending flag for the device */
|
|
|
|
|
DeviceExtension = IoGetDevObjExtension(DeviceObject);
|
|
|
|
|
DeviceExtension->ExtensionFlags |= DOE_UNLOAD_PENDING;
|
|
|
|
|
|
|
|
|
|
/* Make sure there are no attached devices or no reference counts */
|
|
|
|
|
if ((DeviceObject->ReferenceCount) || (DeviceObject->AttachedDevice))
|
|
|
|
|
{
|
|
|
|
|
/* Not safe to unload */
|
|
|
|
|
DPRINT1("Drivers device object is referenced or has attached devices\n");
|
|
|
|
|
|
|
|
|
|
SafeToUnload = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceObject = DeviceObject->NextDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If not safe to unload, then return success */
|
|
|
|
|
if (!SafeToUnload)
|
|
|
|
|
{
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINT1("Unloading driver '%wZ' (manual)\n", &DriverObject->DriverName);
|
|
|
|
|
|
|
|
|
|
/* Set the unload invoked flag and call the unload routine */
|
|
|
|
|
DriverObject->Flags |= DRVO_UNLOAD_INVOKED;
|
2020-11-20 15:51:33 +00:00
|
|
|
|
Status = IopDoLoadUnloadDriver(NULL, &DriverObject);
|
2015-09-01 01:45:59 +00:00
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
2014-10-23 17:59:16 +00:00
|
|
|
|
|
|
|
|
|
/* Mark the driver object temporary, so it could be deleted later */
|
|
|
|
|
ObMakeTemporaryObject(DriverObject);
|
|
|
|
|
|
|
|
|
|
/* Dereference it 2 times */
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("No DriverUnload function! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
|
|
|
|
|
|
|
|
|
|
/* Dereference one time (refd inside this function) */
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
|
|
|
|
|
/* Return unloading failure */
|
|
|
|
|
return STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
|
}
|
2003-10-15 17:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
2004-03-28 09:48:13 +00:00
|
|
|
|
IopReinitializeDrivers(VOID)
|
|
|
|
|
{
|
2006-07-09 02:21:13 +00:00
|
|
|
|
PDRIVER_REINIT_ITEM ReinitItem;
|
|
|
|
|
PLIST_ENTRY Entry;
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Get the first entry and start looping */
|
2004-03-28 09:48:13 +00:00
|
|
|
|
Entry = ExInterlockedRemoveHeadList(&DriverReinitListHead,
|
2006-07-09 02:21:13 +00:00
|
|
|
|
&DriverReinitListLock);
|
|
|
|
|
while (Entry)
|
|
|
|
|
{
|
2016-11-07 15:51:56 +00:00
|
|
|
|
/* Get the item */
|
2006-07-09 02:21:13 +00:00
|
|
|
|
ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Increment reinitialization counter */
|
|
|
|
|
ReinitItem->DriverObject->DriverExtension->Count++;
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Remove the device object flag */
|
|
|
|
|
ReinitItem->DriverObject->Flags &= ~DRVO_REINIT_REGISTERED;
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Call the routine */
|
|
|
|
|
ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
|
|
|
|
|
ReinitItem->Context,
|
|
|
|
|
ReinitItem->DriverObject->
|
|
|
|
|
DriverExtension->Count);
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Free the entry */
|
|
|
|
|
ExFreePool(Entry);
|
2004-03-28 09:48:13 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Move to the next one */
|
|
|
|
|
Entry = ExInterlockedRemoveHeadList(&DriverReinitListHead,
|
|
|
|
|
&DriverReinitListLock);
|
|
|
|
|
}
|
2004-03-28 09:48:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
2006-07-02 18:34:21 +00:00
|
|
|
|
IopReinitializeBootDrivers(VOID)
|
|
|
|
|
{
|
2006-07-09 02:21:13 +00:00
|
|
|
|
PDRIVER_REINIT_ITEM ReinitItem;
|
|
|
|
|
PLIST_ENTRY Entry;
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Get the first entry and start looping */
|
2006-07-02 18:34:21 +00:00
|
|
|
|
Entry = ExInterlockedRemoveHeadList(&DriverBootReinitListHead,
|
2006-07-09 02:21:13 +00:00
|
|
|
|
&DriverBootReinitListLock);
|
|
|
|
|
while (Entry)
|
|
|
|
|
{
|
2016-11-07 15:51:56 +00:00
|
|
|
|
/* Get the item */
|
2006-07-09 02:21:13 +00:00
|
|
|
|
ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Increment reinitialization counter */
|
|
|
|
|
ReinitItem->DriverObject->DriverExtension->Count++;
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Remove the device object flag */
|
|
|
|
|
ReinitItem->DriverObject->Flags &= ~DRVO_BOOTREINIT_REGISTERED;
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Call the routine */
|
|
|
|
|
ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
|
|
|
|
|
ReinitItem->Context,
|
|
|
|
|
ReinitItem->DriverObject->
|
|
|
|
|
DriverExtension->Count);
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Free the entry */
|
|
|
|
|
ExFreePool(Entry);
|
2006-07-02 18:34:21 +00:00
|
|
|
|
|
2006-07-09 02:21:13 +00:00
|
|
|
|
/* Move to the next one */
|
|
|
|
|
Entry = ExInterlockedRemoveHeadList(&DriverBootReinitListHead,
|
|
|
|
|
&DriverBootReinitListLock);
|
|
|
|
|
}
|
2020-06-24 16:34:44 +00:00
|
|
|
|
|
|
|
|
|
/* Wait for all device actions being finished*/
|
|
|
|
|
KeWaitForSingleObject(&PiEnumerationFinished, Executive, KernelMode, FALSE, NULL);
|
2006-07-02 18:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
2004-06-23 21:42:50 +00:00
|
|
|
|
NTSTATUS
|
2006-07-09 00:01:31 +00:00
|
|
|
|
NTAPI
|
2020-11-20 14:18:43 +00:00
|
|
|
|
IoCreateDriver(
|
|
|
|
|
_In_opt_ PUNICODE_STRING DriverName,
|
|
|
|
|
_In_ PDRIVER_INITIALIZE InitializationFunction)
|
2004-06-23 21:42:50 +00:00
|
|
|
|
{
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
WCHAR NameBuffer[100];
|
|
|
|
|
USHORT NameLength;
|
2006-07-09 00:01:31 +00:00
|
|
|
|
UNICODE_STRING LocalDriverName;
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
|
ULONG ObjectSize;
|
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
|
UNICODE_STRING ServiceKeyName;
|
|
|
|
|
HANDLE hDriver;
|
2007-05-25 13:52:58 +00:00
|
|
|
|
ULONG i, RetryCount = 0;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2007-05-25 13:52:58 +00:00
|
|
|
|
try_again:
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* First, create a unique name for the driver if we don't have one */
|
2006-07-09 00:01:31 +00:00
|
|
|
|
if (!DriverName)
|
|
|
|
|
{
|
2016-11-07 15:51:56 +00:00
|
|
|
|
/* Create a random name and set up the string */
|
2007-08-05 11:27:39 +00:00
|
|
|
|
NameLength = (USHORT)swprintf(NameBuffer,
|
2013-08-23 20:03:38 +00:00
|
|
|
|
DRIVER_ROOT_NAME L"%08u",
|
2015-09-23 05:10:58 +00:00
|
|
|
|
KeTickCount.LowPart);
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
LocalDriverName.Length = NameLength * sizeof(WCHAR);
|
|
|
|
|
LocalDriverName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
|
|
|
|
|
LocalDriverName.Buffer = NameBuffer;
|
2006-07-09 00:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* So we can avoid another code path, use a local var */
|
|
|
|
|
LocalDriverName = *DriverName;
|
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Initialize the Attributes */
|
2006-07-09 00:01:31 +00:00
|
|
|
|
ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
|
&LocalDriverName,
|
2015-09-18 14:22:12 +00:00
|
|
|
|
OBJ_PERMANENT | OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Create the Object */
|
|
|
|
|
Status = ObCreateObject(KernelMode,
|
|
|
|
|
IoDriverObjectType,
|
|
|
|
|
&ObjectAttributes,
|
|
|
|
|
KernelMode,
|
|
|
|
|
NULL,
|
|
|
|
|
ObjectSize,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
(PVOID*)&DriverObject);
|
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2007-05-28 21:34:49 +00:00
|
|
|
|
DPRINT("IopCreateDriver(): created DO %p\n", DriverObject);
|
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Set up the Object */
|
|
|
|
|
RtlZeroMemory(DriverObject, ObjectSize);
|
2005-01-01 08:20:47 +00:00
|
|
|
|
DriverObject->Type = IO_TYPE_DRIVER;
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
DriverObject->Size = sizeof(DRIVER_OBJECT);
|
2020-11-20 14:18:43 +00:00
|
|
|
|
DriverObject->Flags = DRVO_BUILTIN_DRIVER;
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
DriverObject->DriverExtension = (PDRIVER_EXTENSION)(DriverObject + 1);
|
|
|
|
|
DriverObject->DriverExtension->DriverObject = DriverObject;
|
|
|
|
|
DriverObject->DriverInit = InitializationFunction;
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Loop all Major Functions */
|
2005-04-17 16:26:44 +00:00
|
|
|
|
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
|
|
|
|
|
{
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Invalidate each function */
|
2005-04-17 16:26:44 +00:00
|
|
|
|
DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
|
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/* Set up the service key name buffer */
|
2020-11-20 14:18:43 +00:00
|
|
|
|
ServiceKeyName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
|
|
|
|
|
ServiceKeyName.Buffer = ExAllocatePoolWithTag(PagedPool, LocalDriverName.MaximumLength, TAG_IO);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
if (!ServiceKeyName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
/* Fail */
|
|
|
|
|
ObMakeTemporaryObject(DriverObject);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
/* For builtin drivers, the ServiceKeyName is equal to DriverName */
|
|
|
|
|
RtlCopyUnicodeString(&ServiceKeyName, &LocalDriverName);
|
|
|
|
|
ServiceKeyName.Buffer[ServiceKeyName.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
2007-03-02 07:23:19 +00:00
|
|
|
|
DriverObject->DriverExtension->ServiceKeyName = ServiceKeyName;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2014-09-27 14:58:40 +00:00
|
|
|
|
/* Make a copy of the driver name to store in the driver object */
|
|
|
|
|
DriverObject->DriverName.MaximumLength = LocalDriverName.Length;
|
|
|
|
|
DriverObject->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
|
DriverObject->DriverName.MaximumLength,
|
|
|
|
|
TAG_IO);
|
|
|
|
|
if (!DriverObject->DriverName.Buffer)
|
|
|
|
|
{
|
|
|
|
|
/* Fail */
|
|
|
|
|
ObMakeTemporaryObject(DriverObject);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 14:18:43 +00:00
|
|
|
|
RtlCopyUnicodeString(&DriverObject->DriverName, &LocalDriverName);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Add the Object and get its handle */
|
|
|
|
|
Status = ObInsertObject(DriverObject,
|
|
|
|
|
NULL,
|
|
|
|
|
FILE_READ_DATA,
|
2008-07-10 11:29:50 +00:00
|
|
|
|
0,
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
NULL,
|
|
|
|
|
&hDriver);
|
2007-05-25 13:52:58 +00:00
|
|
|
|
|
|
|
|
|
/* Eliminate small possibility when this function is called more than
|
|
|
|
|
once in a row, and KeTickCount doesn't get enough time to change */
|
|
|
|
|
if (!DriverName && (Status == STATUS_OBJECT_NAME_COLLISION) && (RetryCount < 100))
|
|
|
|
|
{
|
|
|
|
|
RetryCount++;
|
|
|
|
|
goto try_again;
|
|
|
|
|
}
|
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Now reference it */
|
|
|
|
|
Status = ObReferenceObjectByHandle(hDriver,
|
|
|
|
|
0,
|
|
|
|
|
IoDriverObjectType,
|
|
|
|
|
KernelMode,
|
|
|
|
|
(PVOID*)&DriverObject,
|
|
|
|
|
NULL);
|
2012-02-27 19:31:11 +00:00
|
|
|
|
|
|
|
|
|
/* Close the extra handle */
|
|
|
|
|
ZwClose(hDriver);
|
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
/* Fail */
|
|
|
|
|
ObMakeTemporaryObject(DriverObject);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Finally, call its init function */
|
2007-06-09 20:16:29 +00:00
|
|
|
|
DPRINT("Calling driver entrypoint at %p\n", InitializationFunction);
|
2021-06-10 19:16:27 +00:00
|
|
|
|
Status = InitializationFunction(DriverObject, NULL);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* If it didn't work, then kill the object */
|
2022-11-18 15:17:30 +00:00
|
|
|
|
DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &LocalDriverName, Status);
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
ObMakeTemporaryObject(DriverObject);
|
|
|
|
|
ObDereferenceObject(DriverObject);
|
2012-02-27 19:31:11 +00:00
|
|
|
|
return Status;
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2022-11-18 15:17:30 +00:00
|
|
|
|
/* Windows does this fixup, keep it for compatibility */
|
2009-06-03 09:48:33 +00:00
|
|
|
|
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
|
|
|
|
|
{
|
2009-10-20 16:47:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Make sure the driver didn't set any dispatch entry point to NULL!
|
|
|
|
|
* Doing so is illegal; drivers shouldn't touch entry points they
|
|
|
|
|
* do not implement.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Check if it did so anyway */
|
2010-05-22 16:12:59 +00:00
|
|
|
|
if (!DriverObject->MajorFunction[i])
|
2009-10-20 16:47:01 +00:00
|
|
|
|
{
|
2010-05-22 16:12:59 +00:00
|
|
|
|
/* Print a warning in the debug log */
|
2013-08-31 16:02:13 +00:00
|
|
|
|
DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
|
2010-05-22 16:12:59 +00:00
|
|
|
|
&DriverObject->DriverName, i);
|
|
|
|
|
|
2009-10-20 16:47:01 +00:00
|
|
|
|
/* Fix it up */
|
2009-06-03 09:48:33 +00:00
|
|
|
|
DriverObject->MajorFunction[i] = IopInvalidDeviceRequest;
|
2009-10-20 16:47:01 +00:00
|
|
|
|
}
|
2009-06-03 09:48:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
/* Return the Status */
|
|
|
|
|
return Status;
|
2004-06-23 21:42:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
* @implemented
|
2004-06-23 21:42:50 +00:00
|
|
|
|
*/
|
|
|
|
|
VOID
|
2006-07-09 00:01:31 +00:00
|
|
|
|
NTAPI
|
2022-11-18 15:06:57 +00:00
|
|
|
|
IoDeleteDriver(
|
|
|
|
|
_In_ PDRIVER_OBJECT DriverObject)
|
2004-06-23 21:42:50 +00:00
|
|
|
|
{
|
2008-05-14 20:59:43 +00:00
|
|
|
|
/* Simply dereference the Object */
|
Implemented:
ExSetResourceOwnerPointer, FsRtlDissectDbcs, FsRtlDoesDbcsContainWildCards, FsRtlAcquireFileExclusive, FsRtlReleaseFile, FsRtlGetNextMcbEntry, FsRtlLookupLastMcbEntry, FsRtlLookupMcbEntry, FsRtlRemoveMcbEntry, FsRtlIncrementCcFastReadResourceMiss, FsRtlIncrementCcFastReadNotPossible, FsRtlIncrementCcFastReadWait, FsRtlIncrementCcFastReadNoWait , FsRtlAreNamesEqual, FsRtlDoesNameContainWildCards, IoCreateDriver, IoDeleteDriver
Thanks to Filip for reviewing some of these.
svn path=/trunk/; revision=12408
2004-12-30 18:30:05 +00:00
|
|
|
|
ObDereferenceObject(DriverObject);
|
2004-06-23 21:42:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-09 00:01:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
IoRegisterBootDriverReinitialization(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PDRIVER_REINITIALIZE ReinitRoutine,
|
|
|
|
|
IN PVOID Context)
|
|
|
|
|
{
|
|
|
|
|
PDRIVER_REINIT_ITEM ReinitItem;
|
|
|
|
|
|
|
|
|
|
/* Allocate the entry */
|
|
|
|
|
ReinitItem = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
sizeof(DRIVER_REINIT_ITEM),
|
|
|
|
|
TAG_REINIT);
|
|
|
|
|
if (!ReinitItem) return;
|
|
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
|
ReinitItem->DriverObject = DriverObject;
|
|
|
|
|
ReinitItem->ReinitRoutine = ReinitRoutine;
|
|
|
|
|
ReinitItem->Context = Context;
|
|
|
|
|
|
|
|
|
|
/* Set the Driver Object flag and insert the entry into the list */
|
|
|
|
|
DriverObject->Flags |= DRVO_BOOTREINIT_REGISTERED;
|
|
|
|
|
ExInterlockedInsertTailList(&DriverBootReinitListHead,
|
|
|
|
|
&ReinitItem->ItemEntry,
|
|
|
|
|
&DriverBootReinitListLock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
IoRegisterDriverReinitialization(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PDRIVER_REINITIALIZE ReinitRoutine,
|
|
|
|
|
IN PVOID Context)
|
|
|
|
|
{
|
|
|
|
|
PDRIVER_REINIT_ITEM ReinitItem;
|
|
|
|
|
|
|
|
|
|
/* Allocate the entry */
|
|
|
|
|
ReinitItem = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
sizeof(DRIVER_REINIT_ITEM),
|
|
|
|
|
TAG_REINIT);
|
|
|
|
|
if (!ReinitItem) return;
|
|
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
|
ReinitItem->DriverObject = DriverObject;
|
|
|
|
|
ReinitItem->ReinitRoutine = ReinitRoutine;
|
|
|
|
|
ReinitItem->Context = Context;
|
|
|
|
|
|
|
|
|
|
/* Set the Driver Object flag and insert the entry into the list */
|
|
|
|
|
DriverObject->Flags |= DRVO_REINIT_REGISTERED;
|
|
|
|
|
ExInterlockedInsertTailList(&DriverReinitListHead,
|
|
|
|
|
&ReinitItem->ItemEntry,
|
|
|
|
|
&DriverReinitListLock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PVOID ClientIdentificationAddress,
|
|
|
|
|
IN ULONG DriverObjectExtensionSize,
|
|
|
|
|
OUT PVOID *DriverObjectExtension)
|
|
|
|
|
{
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
PIO_CLIENT_EXTENSION DriverExtensions, NewDriverExtension;
|
|
|
|
|
BOOLEAN Inserted = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Assume failure */
|
|
|
|
|
*DriverObjectExtension = NULL;
|
|
|
|
|
|
|
|
|
|
/* Allocate the extension */
|
|
|
|
|
NewDriverExtension = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
|
sizeof(IO_CLIENT_EXTENSION) +
|
|
|
|
|
DriverObjectExtensionSize,
|
|
|
|
|
TAG_DRIVER_EXTENSION);
|
|
|
|
|
if (!NewDriverExtension) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
|
|
/* Clear the extension for teh caller */
|
|
|
|
|
RtlZeroMemory(NewDriverExtension,
|
|
|
|
|
sizeof(IO_CLIENT_EXTENSION) + DriverObjectExtensionSize);
|
|
|
|
|
|
|
|
|
|
/* Acqure lock */
|
|
|
|
|
OldIrql = KeRaiseIrqlToDpcLevel();
|
|
|
|
|
|
|
|
|
|
/* Fill out the extension */
|
|
|
|
|
NewDriverExtension->ClientIdentificationAddress = ClientIdentificationAddress;
|
|
|
|
|
|
|
|
|
|
/* Loop the current extensions */
|
|
|
|
|
DriverExtensions = IoGetDrvObjExtension(DriverObject)->
|
|
|
|
|
ClientDriverExtension;
|
|
|
|
|
while (DriverExtensions)
|
|
|
|
|
{
|
|
|
|
|
/* Check if the identifier matches */
|
|
|
|
|
if (DriverExtensions->ClientIdentificationAddress ==
|
|
|
|
|
ClientIdentificationAddress)
|
|
|
|
|
{
|
|
|
|
|
/* We have a collision, break out */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Go to the next one */
|
|
|
|
|
DriverExtensions = DriverExtensions->NextExtension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we didn't collide */
|
|
|
|
|
if (!DriverExtensions)
|
|
|
|
|
{
|
|
|
|
|
/* Link this one in */
|
|
|
|
|
NewDriverExtension->NextExtension =
|
|
|
|
|
IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
|
|
|
|
|
IoGetDrvObjExtension(DriverObject)->ClientDriverExtension =
|
|
|
|
|
NewDriverExtension;
|
|
|
|
|
Inserted = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Release the lock */
|
2007-03-26 20:28:13 +00:00
|
|
|
|
KeLowerIrql(OldIrql);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
|
|
|
|
|
/* Check if insertion failed */
|
|
|
|
|
if (!Inserted)
|
|
|
|
|
{
|
|
|
|
|
/* Free the entry and fail */
|
2012-10-06 18:46:13 +00:00
|
|
|
|
ExFreePoolWithTag(NewDriverExtension, TAG_DRIVER_EXTENSION);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
return STATUS_OBJECT_NAME_COLLISION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise, return the pointer */
|
|
|
|
|
*DriverObjectExtension = NewDriverExtension + 1;
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
|
|
|
|
PVOID
|
|
|
|
|
NTAPI
|
|
|
|
|
IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PVOID ClientIdentificationAddress)
|
|
|
|
|
{
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
PIO_CLIENT_EXTENSION DriverExtensions;
|
|
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
|
OldIrql = KeRaiseIrqlToDpcLevel();
|
|
|
|
|
|
|
|
|
|
/* Loop the list until we find the right one */
|
|
|
|
|
DriverExtensions = IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
|
|
|
|
|
while (DriverExtensions)
|
|
|
|
|
{
|
|
|
|
|
/* Check for a match */
|
|
|
|
|
if (DriverExtensions->ClientIdentificationAddress ==
|
|
|
|
|
ClientIdentificationAddress)
|
|
|
|
|
{
|
|
|
|
|
/* Break out */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Keep looping */
|
|
|
|
|
DriverExtensions = DriverExtensions->NextExtension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Release lock */
|
2007-03-26 20:28:13 +00:00
|
|
|
|
KeLowerIrql(OldIrql);
|
2006-07-09 00:01:31 +00:00
|
|
|
|
|
|
|
|
|
/* Return nothing or the extension */
|
|
|
|
|
if (!DriverExtensions) return NULL;
|
|
|
|
|
return DriverExtensions + 1;
|
|
|
|
|
}
|
2004-06-23 21:42:50 +00:00
|
|
|
|
|
2014-10-23 14:37:51 +00:00
|
|
|
|
NTSTATUS
|
2020-11-20 15:51:33 +00:00
|
|
|
|
IopLoadDriver(
|
2020-11-25 00:18:31 +00:00
|
|
|
|
_In_ HANDLE ServiceHandle,
|
|
|
|
|
_Out_ PDRIVER_OBJECT *DriverObject)
|
2003-10-15 17:04:39 +00:00
|
|
|
|
{
|
2013-08-22 19:17:17 +00:00
|
|
|
|
UNICODE_STRING ImagePath;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
PLDR_DATA_TABLE_ENTRY ModuleObject;
|
|
|
|
|
PVOID BaseAddress;
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
PKEY_VALUE_FULL_INFORMATION kvInfo;
|
|
|
|
|
Status = IopGetRegistryValue(ServiceHandle, L"ImagePath", &kvInfo);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
2013-08-22 19:17:17 +00:00
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
if (kvInfo->Type != REG_EXPAND_SZ || kvInfo->DataLength == 0)
|
2013-08-22 19:17:17 +00:00
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
return STATUS_ILL_FORMED_SERVICE_ENTRY;
|
2013-08-22 19:17:17 +00:00
|
|
|
|
}
|
2004-03-27 19:41:32 +00:00
|
|
|
|
|
2021-06-10 19:16:27 +00:00
|
|
|
|
ImagePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
|
|
|
|
|
ImagePath.MaximumLength = kvInfo->DataLength;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ImagePath.Buffer = ExAllocatePoolWithTag(PagedPool, ImagePath.MaximumLength, TAG_RTLREGISTRY);
|
|
|
|
|
if (!ImagePath.Buffer)
|
|
|
|
|
{
|
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
2004-03-27 19:41:32 +00:00
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
RtlMoveMemory(ImagePath.Buffer,
|
|
|
|
|
(PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
|
|
|
|
|
ImagePath.Length);
|
2021-06-10 19:20:17 +00:00
|
|
|
|
ImagePath.Buffer[ImagePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExFreePool(kvInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-08-22 19:17:17 +00:00
|
|
|
|
{
|
2014-10-23 14:37:51 +00:00
|
|
|
|
return Status;
|
2013-08-22 19:17:17 +00:00
|
|
|
|
}
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2013-08-22 19:17:17 +00:00
|
|
|
|
/*
|
2014-10-23 17:59:16 +00:00
|
|
|
|
* Normalize the image path for all later processing.
|
|
|
|
|
*/
|
2020-11-25 00:18:31 +00:00
|
|
|
|
Status = IopNormalizeImagePath(&ImagePath, NULL);
|
2013-08-22 19:17:17 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
|
2014-10-23 14:37:51 +00:00
|
|
|
|
return Status;
|
2013-08-22 19:17:17 +00:00
|
|
|
|
}
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2013-08-22 19:17:17 +00:00
|
|
|
|
DPRINT("FullImagePath: '%wZ'\n", &ImagePath);
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2014-10-24 10:02:14 +00:00
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
ExAcquireResourceExclusiveLite(&IopDriverLoadResource, TRUE);
|
2020-11-25 00:18:31 +00:00
|
|
|
|
|
2013-08-23 20:03:38 +00:00
|
|
|
|
/*
|
2020-11-25 00:18:31 +00:00
|
|
|
|
* Load the driver module
|
2013-08-23 20:03:38 +00:00
|
|
|
|
*/
|
2020-11-25 00:18:31 +00:00
|
|
|
|
DPRINT("Loading module from %wZ\n", &ImagePath);
|
|
|
|
|
Status = MmLoadSystemImage(&ImagePath, NULL, NULL, 0, (PVOID)&ModuleObject, &BaseAddress);
|
|
|
|
|
RtlFreeUnicodeString(&ImagePath);
|
2004-03-27 19:41:32 +00:00
|
|
|
|
|
2013-08-22 19:17:17 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
DPRINT("MmLoadSystemImage() failed (Status %lx)\n", Status);
|
2014-10-24 10:02:14 +00:00
|
|
|
|
ExReleaseResourceLite(&IopDriverLoadResource);
|
|
|
|
|
KeLeaveCriticalRegion();
|
2020-11-25 00:18:31 +00:00
|
|
|
|
return Status;
|
2013-08-22 19:17:17 +00:00
|
|
|
|
}
|
2020-11-25 00:18:31 +00:00
|
|
|
|
|
|
|
|
|
// Display the loading message
|
|
|
|
|
ULONG infoLength;
|
|
|
|
|
Status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
|
|
|
|
|
if (Status == STATUS_BUFFER_TOO_SMALL)
|
2013-08-22 19:17:17 +00:00
|
|
|
|
{
|
2020-11-25 00:18:31 +00:00
|
|
|
|
PKEY_BASIC_INFORMATION servName = ExAllocatePoolWithTag(PagedPool, infoLength, TAG_IO);
|
|
|
|
|
if (servName)
|
|
|
|
|
{
|
|
|
|
|
Status = ZwQueryKey(ServiceHandle,
|
|
|
|
|
KeyBasicInformation,
|
|
|
|
|
servName,
|
|
|
|
|
infoLength,
|
|
|
|
|
&infoLength);
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
UNICODE_STRING serviceName = {
|
|
|
|
|
.Length = servName->NameLength,
|
|
|
|
|
.MaximumLength = servName->NameLength,
|
|
|
|
|
.Buffer = servName->Name
|
|
|
|
|
};
|
2014-10-24 10:02:14 +00:00
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
IopDisplayLoadingMessage(&serviceName);
|
|
|
|
|
}
|
|
|
|
|
ExFreePoolWithTag(servName, TAG_IO);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-10 14:03:01 +00:00
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
NTSTATUS driverEntryStatus;
|
|
|
|
|
Status = IopInitializeDriverModule(ModuleObject,
|
|
|
|
|
ServiceHandle,
|
|
|
|
|
DriverObject,
|
|
|
|
|
&driverEntryStatus);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("IopInitializeDriverModule() failed (Status %lx)\n", Status);
|
2013-08-22 19:17:17 +00:00
|
|
|
|
}
|
2003-10-15 17:04:39 +00:00
|
|
|
|
|
2020-11-25 00:18:31 +00:00
|
|
|
|
ExReleaseResourceLite(&IopDriverLoadResource);
|
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
|
|
2014-10-23 14:37:51 +00:00
|
|
|
|
return Status;
|
2007-10-03 10:17:04 +00:00
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
2020-11-20 15:51:33 +00:00
|
|
|
|
static
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
IopLoadUnloadDriverWorker(
|
|
|
|
|
_Inout_ PVOID Parameter)
|
|
|
|
|
{
|
|
|
|
|
PLOAD_UNLOAD_PARAMS LoadParams = Parameter;
|
|
|
|
|
|
|
|
|
|
ASSERT(PsGetCurrentProcess() == PsInitialSystemProcess);
|
|
|
|
|
|
|
|
|
|
if (LoadParams->DriverObject)
|
|
|
|
|
{
|
|
|
|
|
// unload request
|
|
|
|
|
LoadParams->DriverObject->DriverUnload(LoadParams->DriverObject);
|
|
|
|
|
LoadParams->Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// load request
|
2020-11-25 00:18:31 +00:00
|
|
|
|
HANDLE serviceHandle;
|
|
|
|
|
NTSTATUS status;
|
|
|
|
|
status = IopOpenRegistryKeyEx(&serviceHandle, NULL, LoadParams->RegistryPath, KEY_READ);
|
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
|
{
|
|
|
|
|
LoadParams->Status = status;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoadParams->Status = IopLoadDriver(serviceHandle, &LoadParams->DriverObject);
|
|
|
|
|
ZwClose(serviceHandle);
|
|
|
|
|
}
|
2020-11-20 15:51:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (LoadParams->SetEvent)
|
|
|
|
|
{
|
|
|
|
|
KeSetEvent(&LoadParams->Event, 0, FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Process load and unload driver operations. This is mostly for NtLoadDriver
|
|
|
|
|
* and NtUnloadDriver, because their code should run inside PsInitialSystemProcess
|
|
|
|
|
*
|
|
|
|
|
* @param[in] RegistryPath The registry path
|
|
|
|
|
* @param DriverObject The driver object
|
|
|
|
|
*
|
|
|
|
|
* @return Status of the operation
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
IopDoLoadUnloadDriver(
|
2020-11-25 00:18:31 +00:00
|
|
|
|
_In_opt_ PUNICODE_STRING RegistryPath,
|
2020-11-20 15:51:33 +00:00
|
|
|
|
_Inout_ PDRIVER_OBJECT *DriverObject)
|
|
|
|
|
{
|
|
|
|
|
LOAD_UNLOAD_PARAMS LoadParams;
|
|
|
|
|
|
|
|
|
|
/* Prepare parameters block */
|
|
|
|
|
LoadParams.RegistryPath = RegistryPath;
|
|
|
|
|
LoadParams.DriverObject = *DriverObject;
|
|
|
|
|
|
|
|
|
|
if (PsGetCurrentProcess() != PsInitialSystemProcess)
|
|
|
|
|
{
|
|
|
|
|
LoadParams.SetEvent = TRUE;
|
|
|
|
|
KeInitializeEvent(&LoadParams.Event, NotificationEvent, FALSE);
|
|
|
|
|
|
|
|
|
|
/* Initialize and queue a work item */
|
|
|
|
|
ExInitializeWorkItem(&LoadParams.WorkItem, IopLoadUnloadDriverWorker, &LoadParams);
|
|
|
|
|
ExQueueWorkItem(&LoadParams.WorkItem, DelayedWorkQueue);
|
|
|
|
|
|
|
|
|
|
/* And wait till it completes */
|
|
|
|
|
KeWaitForSingleObject(&LoadParams.Event, UserRequest, KernelMode, FALSE, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If we're already in a system process, call it right here */
|
|
|
|
|
LoadParams.SetEvent = FALSE;
|
|
|
|
|
IopLoadUnloadDriverWorker(&LoadParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LoadParams.Status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 10:17:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* NtLoadDriver
|
|
|
|
|
*
|
|
|
|
|
* Loads a device driver.
|
|
|
|
|
*
|
|
|
|
|
* Parameters
|
|
|
|
|
* DriverServiceName
|
|
|
|
|
* Name of the service to load (registry key).
|
|
|
|
|
*
|
|
|
|
|
* Return Value
|
|
|
|
|
* Status
|
|
|
|
|
*
|
|
|
|
|
* Status
|
|
|
|
|
* implemented
|
|
|
|
|
*/
|
2008-11-29 20:47:48 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2007-10-03 10:17:04 +00:00
|
|
|
|
NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|
|
|
|
{
|
2020-12-26 23:31:54 +00:00
|
|
|
|
UNICODE_STRING CapturedServiceName = { 0, 0, NULL };
|
2007-10-03 10:17:04 +00:00
|
|
|
|
KPROCESSOR_MODE PreviousMode;
|
2014-10-23 14:37:51 +00:00
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
2007-10-03 10:17:04 +00:00
|
|
|
|
NTSTATUS Status;
|
2004-03-27 19:41:32 +00:00
|
|
|
|
|
2007-10-03 10:17:04 +00:00
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
|
|
PreviousMode = KeGetPreviousMode();
|
|
|
|
|
|
2020-12-26 23:31:54 +00:00
|
|
|
|
/* Need the appropriate priviliege */
|
2007-10-03 10:17:04 +00:00
|
|
|
|
if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode))
|
|
|
|
|
{
|
2020-12-26 23:31:54 +00:00
|
|
|
|
DPRINT1("No load privilege!\n");
|
2007-10-03 10:17:04 +00:00
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-26 23:31:54 +00:00
|
|
|
|
/* Capture the service name */
|
|
|
|
|
Status = ProbeAndCaptureUnicodeString(&CapturedServiceName,
|
2007-10-03 10:17:04 +00:00
|
|
|
|
PreviousMode,
|
|
|
|
|
DriverServiceName);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2020-11-20 15:51:33 +00:00
|
|
|
|
{
|
2007-10-03 10:17:04 +00:00
|
|
|
|
return Status;
|
2020-11-20 15:51:33 +00:00
|
|
|
|
}
|
2007-10-03 10:17:04 +00:00
|
|
|
|
|
2020-12-26 23:31:54 +00:00
|
|
|
|
DPRINT("NtLoadDriver('%wZ')\n", &CapturedServiceName);
|
2007-10-03 10:17:04 +00:00
|
|
|
|
|
2020-12-26 23:33:32 +00:00
|
|
|
|
/* We need a service name */
|
|
|
|
|
if (CapturedServiceName.Length == 0 || CapturedServiceName.Buffer == NULL)
|
|
|
|
|
{
|
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 14:37:51 +00:00
|
|
|
|
/* Load driver and call its entry point */
|
|
|
|
|
DriverObject = NULL;
|
2020-11-20 15:51:33 +00:00
|
|
|
|
Status = IopDoLoadUnloadDriver(&CapturedServiceName, &DriverObject);
|
2007-10-03 10:17:04 +00:00
|
|
|
|
|
2020-12-26 23:31:54 +00:00
|
|
|
|
ReleaseCapturedUnicodeString(&CapturedServiceName, PreviousMode);
|
2014-10-23 14:37:51 +00:00
|
|
|
|
return Status;
|
2003-10-15 17:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NtUnloadDriver
|
|
|
|
|
*
|
|
|
|
|
* Unloads a legacy device driver.
|
|
|
|
|
*
|
|
|
|
|
* Parameters
|
|
|
|
|
* DriverServiceName
|
|
|
|
|
* Name of the service to unload (registry key).
|
2005-05-09 01:38:29 +00:00
|
|
|
|
*
|
2003-10-15 17:04:39 +00:00
|
|
|
|
* Return Value
|
|
|
|
|
* Status
|
2004-03-28 09:48:13 +00:00
|
|
|
|
*
|
|
|
|
|
* Status
|
|
|
|
|
* implemented
|
2003-10-15 17:04:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-11-29 20:47:48 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2003-10-15 17:04:39 +00:00
|
|
|
|
NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
|
|
|
|
|
{
|
2014-10-23 17:59:16 +00:00
|
|
|
|
return IopUnloadDriver(DriverServiceName, FALSE);
|
2003-10-15 17:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-06 18:49:50 +00:00
|
|
|
|
/* EOF */
|