mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
IoDestroyDriverList(): Free memory of group and service entries.
IopCreateServiceListEntry(): simplified function and reduced memory consumption. svn path=/trunk/; revision=3116
This commit is contained in:
parent
b29a9b85b9
commit
9fb8f57561
1 changed files with 63 additions and 107 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: driver.c,v 1.6 2002/06/16 11:44:13 ekohl Exp $
|
/* $Id: driver.c,v 1.7 2002/06/18 07:11:44 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -131,7 +131,6 @@ NTSTATUS STDCALL
|
||||||
NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
||||||
{
|
{
|
||||||
RTL_QUERY_REGISTRY_TABLE QueryTable[3];
|
RTL_QUERY_REGISTRY_TABLE QueryTable[3];
|
||||||
WCHAR ImagePathBuffer[MAX_PATH];
|
|
||||||
WCHAR FullImagePathBuffer[MAX_PATH];
|
WCHAR FullImagePathBuffer[MAX_PATH];
|
||||||
UNICODE_STRING ImagePath;
|
UNICODE_STRING ImagePath;
|
||||||
UNICODE_STRING FullImagePath;
|
UNICODE_STRING FullImagePath;
|
||||||
|
@ -141,13 +140,9 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
||||||
PMODULE_OBJECT ModuleObject;
|
PMODULE_OBJECT ModuleObject;
|
||||||
LPWSTR Start;
|
LPWSTR Start;
|
||||||
|
|
||||||
DPRINT("DriverServiceName: '%wZ'\n", DriverServiceName);
|
DPRINT("NtLoadDriver(%wZ) called\n", DriverServiceName);
|
||||||
|
|
||||||
ImagePath.Length = 0;
|
RtlInitUnicodeString(&ImagePath, NULL);
|
||||||
ImagePath.MaximumLength = MAX_PATH * sizeof(WCHAR);
|
|
||||||
ImagePath.Buffer = ImagePathBuffer;
|
|
||||||
RtlZeroMemory(ImagePathBuffer,
|
|
||||||
MAX_PATH * sizeof(WCHAR));
|
|
||||||
|
|
||||||
/* Get service data */
|
/* Get service data */
|
||||||
RtlZeroMemory(&QueryTable,
|
RtlZeroMemory(&QueryTable,
|
||||||
|
@ -169,21 +164,27 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
|
DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
|
||||||
|
RtlFreeUnicodeString(&ImagePath);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImagePath.Length == 0)
|
if (ImagePath.Length == 0)
|
||||||
{
|
{
|
||||||
wcscpy(FullImagePathBuffer, L"\\SystemRoot\\system32\\drivers");
|
wcscpy(FullImagePathBuffer, L"\\SystemRoot\\system32\\drivers");
|
||||||
wcscat(ImagePathBuffer, wcsrchr(DriverServiceName->Buffer, L'\\'));
|
wcscat(FullImagePathBuffer, wcsrchr(DriverServiceName->Buffer, L'\\'));
|
||||||
wcscat(ImagePathBuffer, L".sys");
|
wcscat(FullImagePathBuffer, L".sys");
|
||||||
|
}
|
||||||
|
else if (ImagePath.Buffer[0] != L'\\')
|
||||||
|
{
|
||||||
|
wcscpy(FullImagePathBuffer, L"\\SystemRoot\\");
|
||||||
|
wcscat(FullImagePathBuffer, ImagePath.Buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wcscpy(FullImagePathBuffer, L"\\SystemRoot\\");
|
wcscpy(FullImagePathBuffer, ImagePath.Buffer);
|
||||||
wcscat(FullImagePathBuffer, ImagePathBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlFreeUnicodeString(&ImagePath);
|
||||||
RtlInitUnicodeString(&FullImagePath, FullImagePathBuffer);
|
RtlInitUnicodeString(&FullImagePath, FullImagePathBuffer);
|
||||||
|
|
||||||
DPRINT("FullImagePath: '%S'\n", FullImagePathBuffer);
|
DPRINT("FullImagePath: '%S'\n", FullImagePathBuffer);
|
||||||
|
@ -193,6 +194,7 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
||||||
Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
|
Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
DPRINT1("IopCreateDeviceNode() failed (Status %lx)\n", Status);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +219,7 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
||||||
(Type == 2 || Type == 8));
|
(Type == 2 || Type == 8));
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("IopInitializeDriver() failed (Status %lx)\n", Status);
|
DPRINT1("IopInitializeDriver() failed (Status %lx)\n", Status);
|
||||||
LdrUnloadModule(ModuleObject);
|
LdrUnloadModule(ModuleObject);
|
||||||
IopFreeDeviceNode(DeviceNode);
|
IopFreeDeviceNode(DeviceNode);
|
||||||
}
|
}
|
||||||
|
@ -277,65 +279,11 @@ static NTSTATUS STDCALL
|
||||||
IopCreateServiceListEntry(PUNICODE_STRING ServiceName)
|
IopCreateServiceListEntry(PUNICODE_STRING ServiceName)
|
||||||
{
|
{
|
||||||
RTL_QUERY_REGISTRY_TABLE QueryTable[6];
|
RTL_QUERY_REGISTRY_TABLE QueryTable[6];
|
||||||
WCHAR ServiceGroupBuffer[MAX_PATH];
|
|
||||||
WCHAR ImagePathBuffer[MAX_PATH];
|
|
||||||
UNICODE_STRING ServiceGroup;
|
|
||||||
UNICODE_STRING ImagePath;
|
|
||||||
PSERVICE Service;
|
PSERVICE Service;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG Start, Type, ErrorControl;
|
|
||||||
|
|
||||||
DPRINT("ServiceName: '%wZ'\n", ServiceName);
|
DPRINT("ServiceName: '%wZ'\n", ServiceName);
|
||||||
|
|
||||||
ServiceGroup.Length = 0;
|
|
||||||
ServiceGroup.MaximumLength = MAX_PATH * sizeof(WCHAR);
|
|
||||||
ServiceGroup.Buffer = ServiceGroupBuffer;
|
|
||||||
RtlZeroMemory(ServiceGroupBuffer,
|
|
||||||
MAX_PATH * sizeof(WCHAR));
|
|
||||||
|
|
||||||
ImagePath.Length = 0;
|
|
||||||
ImagePath.MaximumLength = MAX_PATH * sizeof(WCHAR);
|
|
||||||
ImagePath.Buffer = ImagePathBuffer;
|
|
||||||
RtlZeroMemory(ImagePathBuffer,
|
|
||||||
MAX_PATH * sizeof(WCHAR));
|
|
||||||
|
|
||||||
/* Get service data */
|
|
||||||
RtlZeroMemory(&QueryTable,
|
|
||||||
sizeof(QueryTable));
|
|
||||||
|
|
||||||
QueryTable[0].Name = L"Start";
|
|
||||||
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
|
||||||
QueryTable[0].EntryContext = &Start;
|
|
||||||
|
|
||||||
QueryTable[1].Name = L"Type";
|
|
||||||
QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
|
||||||
QueryTable[1].EntryContext = &Type;
|
|
||||||
|
|
||||||
QueryTable[2].Name = L"ErrorControl";
|
|
||||||
QueryTable[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
|
||||||
QueryTable[2].EntryContext = &ErrorControl;
|
|
||||||
|
|
||||||
QueryTable[3].Name = L"Group";
|
|
||||||
QueryTable[3].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
|
||||||
QueryTable[3].EntryContext = &ServiceGroup;
|
|
||||||
|
|
||||||
QueryTable[4].Name = L"ImagePath";
|
|
||||||
QueryTable[4].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
|
||||||
QueryTable[4].EntryContext = &ImagePath;
|
|
||||||
|
|
||||||
Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
|
|
||||||
ServiceName->Buffer,
|
|
||||||
QueryTable,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Start < 2)
|
|
||||||
{
|
|
||||||
/* Allocate service entry */
|
/* Allocate service entry */
|
||||||
Service = (PSERVICE)ExAllocatePool(NonPagedPool, sizeof(SERVICE));
|
Service = (PSERVICE)ExAllocatePool(NonPagedPool, sizeof(SERVICE));
|
||||||
if (Service == NULL)
|
if (Service == NULL)
|
||||||
|
@ -345,6 +293,43 @@ IopCreateServiceListEntry(PUNICODE_STRING ServiceName)
|
||||||
}
|
}
|
||||||
RtlZeroMemory(Service, sizeof(SERVICE));
|
RtlZeroMemory(Service, sizeof(SERVICE));
|
||||||
|
|
||||||
|
/* Get service data */
|
||||||
|
RtlZeroMemory(&QueryTable,
|
||||||
|
sizeof(QueryTable));
|
||||||
|
|
||||||
|
QueryTable[0].Name = L"Start";
|
||||||
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
||||||
|
QueryTable[0].EntryContext = &Service->Start;
|
||||||
|
|
||||||
|
QueryTable[1].Name = L"Type";
|
||||||
|
QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
||||||
|
QueryTable[1].EntryContext = &Service->Type;
|
||||||
|
|
||||||
|
QueryTable[2].Name = L"ErrorControl";
|
||||||
|
QueryTable[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
|
||||||
|
QueryTable[2].EntryContext = &Service->ErrorControl;
|
||||||
|
|
||||||
|
QueryTable[3].Name = L"Group";
|
||||||
|
QueryTable[3].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
||||||
|
QueryTable[3].EntryContext = &Service->ServiceGroup;
|
||||||
|
|
||||||
|
QueryTable[4].Name = L"ImagePath";
|
||||||
|
QueryTable[4].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
||||||
|
QueryTable[4].EntryContext = &Service->ImagePath;
|
||||||
|
|
||||||
|
Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
|
||||||
|
ServiceName->Buffer,
|
||||||
|
QueryTable,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (!NT_SUCCESS(Status) || Service->Start > 1)
|
||||||
|
{
|
||||||
|
RtlFreeUnicodeString(&Service->ServiceGroup);
|
||||||
|
RtlFreeUnicodeString(&Service->ImagePath);
|
||||||
|
ExFreePool(Service);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy service name */
|
/* Copy service name */
|
||||||
Service->ServiceName.Length = ServiceName->Length;
|
Service->ServiceName.Length = ServiceName->Length;
|
||||||
Service->ServiceName.MaximumLength = ServiceName->Length + sizeof(WCHAR);
|
Service->ServiceName.MaximumLength = ServiceName->Length + sizeof(WCHAR);
|
||||||
|
@ -365,36 +350,6 @@ IopCreateServiceListEntry(PUNICODE_STRING ServiceName)
|
||||||
Service->ServiceName.Buffer);
|
Service->ServiceName.Buffer);
|
||||||
Service->RegistryPath.Length = wcslen(Service->RegistryPath.Buffer) * sizeof(WCHAR);
|
Service->RegistryPath.Length = wcslen(Service->RegistryPath.Buffer) * sizeof(WCHAR);
|
||||||
|
|
||||||
/* Copy service group */
|
|
||||||
if (ServiceGroup.Length > 0)
|
|
||||||
{
|
|
||||||
Service->ServiceGroup.Length = ServiceGroup.Length;
|
|
||||||
Service->ServiceGroup.MaximumLength = ServiceGroup.Length + sizeof(WCHAR);
|
|
||||||
Service->ServiceGroup.Buffer = ExAllocatePool(NonPagedPool,
|
|
||||||
ServiceGroup.Length + sizeof(WCHAR));
|
|
||||||
RtlCopyMemory(Service->ServiceGroup.Buffer,
|
|
||||||
ServiceGroup.Buffer,
|
|
||||||
ServiceGroup.Length);
|
|
||||||
Service->ServiceGroup.Buffer[ServiceGroup.Length / sizeof(WCHAR)] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy image path */
|
|
||||||
if (ImagePath.Length > 0)
|
|
||||||
{
|
|
||||||
Service->ImagePath.Length = ImagePath.Length;
|
|
||||||
Service->ImagePath.MaximumLength = ImagePath.Length + sizeof(WCHAR);
|
|
||||||
Service->ImagePath.Buffer = ExAllocatePool(NonPagedPool,
|
|
||||||
ImagePath.Length + sizeof(WCHAR));
|
|
||||||
RtlCopyMemory(Service->ImagePath.Buffer,
|
|
||||||
ImagePath.Buffer,
|
|
||||||
ImagePath.Length);
|
|
||||||
Service->ImagePath.Buffer[ImagePath.Length / sizeof(WCHAR)] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Service->Start = Start;
|
|
||||||
Service->Type = Type;
|
|
||||||
Service->ErrorControl = ErrorControl;
|
|
||||||
|
|
||||||
DPRINT("ServiceName: '%wZ'\n", &Service->ServiceName);
|
DPRINT("ServiceName: '%wZ'\n", &Service->ServiceName);
|
||||||
DPRINT("RegistryPath: '%wZ'\n", &Service->RegistryPath);
|
DPRINT("RegistryPath: '%wZ'\n", &Service->RegistryPath);
|
||||||
DPRINT("ServiceGroup: '%wZ'\n", &Service->ServiceGroup);
|
DPRINT("ServiceGroup: '%wZ'\n", &Service->ServiceGroup);
|
||||||
|
@ -405,7 +360,6 @@ IopCreateServiceListEntry(PUNICODE_STRING ServiceName)
|
||||||
/* Append service entry */
|
/* Append service entry */
|
||||||
InsertTailList(&ServiceListHead,
|
InsertTailList(&ServiceListHead,
|
||||||
&Service->ServiceListEntry);
|
&Service->ServiceListEntry);
|
||||||
}
|
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -641,8 +595,9 @@ IoDestroyDriverList(VOID)
|
||||||
CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
|
CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&CurrentGroup->GroupName);
|
RtlFreeUnicodeString(&CurrentGroup->GroupName);
|
||||||
|
|
||||||
RemoveEntryList(GroupEntry);
|
RemoveEntryList(GroupEntry);
|
||||||
|
ExFreePool(CurrentGroup);
|
||||||
|
|
||||||
GroupEntry = GroupListHead.Flink;
|
GroupEntry = GroupListHead.Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,8 +611,9 @@ IoDestroyDriverList(VOID)
|
||||||
RtlFreeUnicodeString(&CurrentService->RegistryPath);
|
RtlFreeUnicodeString(&CurrentService->RegistryPath);
|
||||||
RtlFreeUnicodeString(&CurrentService->ServiceGroup);
|
RtlFreeUnicodeString(&CurrentService->ServiceGroup);
|
||||||
RtlFreeUnicodeString(&CurrentService->ImagePath);
|
RtlFreeUnicodeString(&CurrentService->ImagePath);
|
||||||
|
|
||||||
RemoveEntryList(ServiceEntry);
|
RemoveEntryList(ServiceEntry);
|
||||||
|
ExFreePool(CurrentService);
|
||||||
|
|
||||||
ServiceEntry = ServiceListHead.Flink;
|
ServiceEntry = ServiceListHead.Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue