-reorder InsertXscendingOrder macro argument order and update uses

-start to macrofy list enums in ntoskrnl using LIST_FOR_EACH macros
-use IsListEmpty some places instead of manual coding
-profile.c:KeStartProfile() zero correct buffer in (and not the NULL ptr;-)
-improve LIST_FOR_EACH macros so that the iterator is set to NULL at end of enum
-kthread.c:KiServiceCheck() set the shadowtable before calling the win32k proc/thread init funcs
-apc.c:KiInsertQueueApc() insert special apcs in correct fifo order 
-apc.c:KeFlushQueueApc() simplify 
-timer.c:KiExpireTimers() calling RemoveEntryList on a possibly empty list is not ok

svn path=/trunk/; revision=18113
This commit is contained in:
Gunnar Dalsnes 2005-09-26 22:57:48 +00:00
parent 5b8c6d129b
commit b890e50a9e
17 changed files with 116 additions and 292 deletions

View file

@ -18,17 +18,21 @@
#define EXPORTED __declspec(dllexport) #define EXPORTED __declspec(dllexport)
#define IMPORTED __declspec(dllimport) #define IMPORTED __declspec(dllimport)
/* iterate through the list using a list entry */ /* iterate through the list using a list entry.
* elem is set to NULL if the list is run thru without breaking out or if list is empty.
*/
#define LIST_FOR_EACH(elem, list, type, field) \ #define LIST_FOR_EACH(elem, list, type, field) \
for ((elem) = CONTAINING_RECORD((list)->Flink, type, field); \ for ((elem) = CONTAINING_RECORD((list)->Flink, type, field); \
&(elem)->field != (list); \ &(elem)->field != (list) || (elem = NULL); \
(elem) = CONTAINING_RECORD((elem)->field.Flink, type, field)) (elem) = CONTAINING_RECORD((elem)->field.Flink, type, field))
/* iterate through the list using a list entry, with safety against removal */ /* iterate through the list using a list entry, with safety against removal
* elem is set to NULL if the list is run thru without breaking out or if list is empty.
*/
#define LIST_FOR_EACH_SAFE(cursor, cursor2, list, type, field) \ #define LIST_FOR_EACH_SAFE(cursor, cursor2, list, type, field) \
for ((cursor) = CONTAINING_RECORD((list)->Flink, type, field), \ for ((cursor) = CONTAINING_RECORD((list)->Flink, type, field), \
(cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field); \ (cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field); \
&(cursor)->field != (list); \ &(cursor)->field != (list) || (cursor = NULL); \
(cursor) = (cursor2), \ (cursor) = (cursor2), \
(cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field)) (cursor2) = CONTAINING_RECORD((cursor)->field.Flink, type, field))
@ -55,7 +59,7 @@
#define HOURS_TO_100NS(hours) (((LONGLONG)(hours)) * MINUTES_TO_100NS(60)) #define HOURS_TO_100NS(hours) (((LONGLONG)(hours)) * MINUTES_TO_100NS(60))
#define UNICODIZE1(x) L##x #define UNICODIZE1(x) L##x
#define UNICODIZE(x) UNICODIZE1(x) #define UNICODIZE(x) UNICODIZE1(x)
#define InsertAscendingListFIFO(ListHead, Type, ListEntryField, NewEntry, SortField)\ #define InsertAscendingListFIFO(ListHead, NewEntry, Type, ListEntryField, SortField)\
{\ {\
PLIST_ENTRY current;\ PLIST_ENTRY current;\
\ \
@ -73,7 +77,7 @@
InsertTailList(current, &((NewEntry)->ListEntryField));\ InsertTailList(current, &((NewEntry)->ListEntryField));\
} }
#define InsertDescendingListFIFO(ListHead, Type, ListEntryField, NewEntry, SortField)\ #define InsertDescendingListFIFO(ListHead, NewEntry, Type, ListEntryField, SortField)\
{\ {\
PLIST_ENTRY current;\ PLIST_ENTRY current;\
\ \
@ -91,7 +95,7 @@
InsertTailList(current, &((NewEntry)->ListEntryField));\ InsertTailList(current, &((NewEntry)->ListEntryField));\
} }
#define InsertAscendingList(ListHead, Type, ListEntryField, NewEntry, SortField)\ #define InsertAscendingList(ListHead, NewEntry, Type, ListEntryField, SortField)\
{\ {\
PLIST_ENTRY current;\ PLIST_ENTRY current;\
\ \
@ -109,7 +113,7 @@
InsertTailList(current, &((NewEntry)->ListEntryField));\ InsertTailList(current, &((NewEntry)->ListEntryField));\
} }
#define InsertDescendingList(ListHead, Type, ListEntryField, NewEntry, SortField)\ #define InsertDescendingList(ListHead, NewEntry, Type, ListEntryField, SortField)\
{\ {\
PLIST_ENTRY current;\ PLIST_ENTRY current;\
\ \

View file

@ -33,17 +33,13 @@ VOID
IoShutdownRegisteredDevices(VOID) IoShutdownRegisteredDevices(VOID)
{ {
PSHUTDOWN_ENTRY ShutdownEntry; PSHUTDOWN_ENTRY ShutdownEntry;
PLIST_ENTRY Entry;
IO_STATUS_BLOCK StatusBlock; IO_STATUS_BLOCK StatusBlock;
PIRP Irp; PIRP Irp;
KEVENT Event; KEVENT Event;
NTSTATUS Status; NTSTATUS Status;
Entry = ShutdownListHead.Flink; LIST_FOR_EACH(ShutdownEntry, &ShutdownListHead, SHUTDOWN_ENTRY, ShutdownList)
while (Entry != &ShutdownListHead)
{ {
ShutdownEntry = CONTAINING_RECORD(Entry, SHUTDOWN_ENTRY, ShutdownList);
KeInitializeEvent (&Event, KeInitializeEvent (&Event,
NotificationEvent, NotificationEvent,
FALSE); FALSE);
@ -66,8 +62,6 @@ IoShutdownRegisteredDevices(VOID)
FALSE, FALSE,
NULL); NULL);
} }
Entry = Entry->Flink;
} }
} }
@ -1082,27 +1076,24 @@ VOID
STDCALL STDCALL
IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject) IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
{ {
PSHUTDOWN_ENTRY ShutdownEntry; PSHUTDOWN_ENTRY ShutdownEntry, tmp;
PLIST_ENTRY Entry;
KIRQL oldlvl; KIRQL oldlvl;
Entry = ShutdownListHead.Flink; LIST_FOR_EACH_SAFE(ShutdownEntry, tmp, &ShutdownListHead, SHUTDOWN_ENTRY, ShutdownList)
while (Entry != &ShutdownListHead)
{ {
ShutdownEntry = CONTAINING_RECORD(Entry, SHUTDOWN_ENTRY, ShutdownList);
if (ShutdownEntry->DeviceObject == DeviceObject) if (ShutdownEntry->DeviceObject == DeviceObject)
{ {
DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED; DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
KeAcquireSpinLock(&ShutdownListLock,&oldlvl); KeAcquireSpinLock(&ShutdownListLock,&oldlvl);
RemoveEntryList(Entry); RemoveEntryList(&ShutdownEntry->ShutdownList);
KeReleaseSpinLock(&ShutdownListLock,oldlvl); KeReleaseSpinLock(&ShutdownListLock,oldlvl);
ExFreePool(Entry); ExFreePool(ShutdownEntry);
return; return;
} }
Entry = Entry->Flink;
} }
} }

View file

@ -1118,44 +1118,32 @@ IoCreateDriverList(VOID)
NTSTATUS INIT_FUNCTION NTSTATUS INIT_FUNCTION
IoDestroyDriverList(VOID) IoDestroyDriverList(VOID)
{ {
PLIST_ENTRY GroupEntry; PSERVICE_GROUP CurrentGroup, tmp1;
PLIST_ENTRY ServiceEntry; PSERVICE CurrentService, tmp2;
PSERVICE_GROUP CurrentGroup;
PSERVICE CurrentService;
DPRINT("IoDestroyDriverList() called\n"); DPRINT("IoDestroyDriverList() called\n");
/* Destroy group list */ /* Destroy group list */
GroupEntry = GroupListHead.Flink; LIST_FOR_EACH_SAFE(CurrentGroup, tmp1, &GroupListHead, SERVICE_GROUP, GroupListEntry)
while (GroupEntry != &GroupListHead)
{ {
CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
ExFreePool(CurrentGroup->GroupName.Buffer); ExFreePool(CurrentGroup->GroupName.Buffer);
RemoveEntryList(GroupEntry); RemoveEntryList(&CurrentGroup->GroupListEntry);
if (CurrentGroup->TagArray) if (CurrentGroup->TagArray)
{ {
ExFreePool(CurrentGroup->TagArray); ExFreePool(CurrentGroup->TagArray);
} }
ExFreePool(CurrentGroup); ExFreePool(CurrentGroup);
GroupEntry = GroupListHead.Flink;
} }
/* Destroy service list */ /* Destroy service list */
ServiceEntry = ServiceListHead.Flink; LIST_FOR_EACH_SAFE(CurrentService, tmp2, &ServiceListHead, SERVICE, ServiceListEntry)
while (ServiceEntry != &ServiceListHead)
{ {
CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
ExFreePool(CurrentService->ServiceName.Buffer); ExFreePool(CurrentService->ServiceName.Buffer);
ExFreePool(CurrentService->RegistryPath.Buffer); ExFreePool(CurrentService->RegistryPath.Buffer);
ExFreePool(CurrentService->ServiceGroup.Buffer); ExFreePool(CurrentService->ServiceGroup.Buffer);
ExFreePool(CurrentService->ImagePath.Buffer); ExFreePool(CurrentService->ImagePath.Buffer);
RemoveEntryList(ServiceEntry); RemoveEntryList(&CurrentService->ServiceListEntry);
ExFreePool(CurrentService); ExFreePool(CurrentService);
ServiceEntry = ServiceListHead.Flink;
} }
DPRINT("IoDestroyDriverList() done\n"); DPRINT("IoDestroyDriverList() done\n");
@ -1423,8 +1411,6 @@ IopLoadDriver(PSERVICE Service)
VOID FASTCALL VOID FASTCALL
IopInitializeSystemDrivers(VOID) IopInitializeSystemDrivers(VOID)
{ {
PLIST_ENTRY GroupEntry;
PLIST_ENTRY ServiceEntry;
PSERVICE_GROUP CurrentGroup; PSERVICE_GROUP CurrentGroup;
PSERVICE CurrentService; PSERVICE CurrentService;
NTSTATUS Status; NTSTATUS Status;
@ -1432,21 +1418,15 @@ IopInitializeSystemDrivers(VOID)
DPRINT("IopInitializeSystemDrivers()\n"); DPRINT("IopInitializeSystemDrivers()\n");
GroupEntry = GroupListHead.Flink; LIST_FOR_EACH(CurrentGroup, &GroupListHead, SERVICE_GROUP, GroupListEntry)
while (GroupEntry != &GroupListHead)
{ {
CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
DPRINT("Group: %wZ\n", &CurrentGroup->GroupName); DPRINT("Group: %wZ\n", &CurrentGroup->GroupName);
/* Load all drivers with a valid tag */ /* Load all drivers with a valid tag */
for (i = 0; i < CurrentGroup->TagCount; i++) for (i = 0; i < CurrentGroup->TagCount; i++)
{ {
ServiceEntry = ServiceListHead.Flink; LIST_FOR_EACH(CurrentService, &ServiceListHead, SERVICE, ServiceListEntry)
while (ServiceEntry != &ServiceListHead)
{ {
CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
if ((RtlCompareUnicodeString(&CurrentGroup->GroupName, if ((RtlCompareUnicodeString(&CurrentGroup->GroupName,
&CurrentService->ServiceGroup, TRUE) == 0) && &CurrentService->ServiceGroup, TRUE) == 0) &&
(CurrentService->Start == 1 /*SERVICE_SYSTEM_START*/) && (CurrentService->Start == 1 /*SERVICE_SYSTEM_START*/) &&
@ -1455,15 +1435,12 @@ IopInitializeSystemDrivers(VOID)
DPRINT(" Path: %wZ\n", &CurrentService->RegistryPath); DPRINT(" Path: %wZ\n", &CurrentService->RegistryPath);
Status = IopLoadDriver(CurrentService); Status = IopLoadDriver(CurrentService);
} }
ServiceEntry = ServiceEntry->Flink;
} }
} }
/* Load all drivers without a tag or with an invalid tag */ /* Load all drivers without a tag or with an invalid tag */
ServiceEntry = ServiceListHead.Flink; LIST_FOR_EACH(CurrentService, &ServiceListHead, SERVICE, ServiceListEntry)
while (ServiceEntry != &ServiceListHead)
{ {
CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
if ((RtlCompareUnicodeString(&CurrentGroup->GroupName, if ((RtlCompareUnicodeString(&CurrentGroup->GroupName,
&CurrentService->ServiceGroup, TRUE) == 0) && &CurrentService->ServiceGroup, TRUE) == 0) &&
(CurrentService->Start == 1 /*SERVICE_SYSTEM_START*/)) (CurrentService->Start == 1 /*SERVICE_SYSTEM_START*/))
@ -1481,10 +1458,8 @@ IopInitializeSystemDrivers(VOID)
Status = IopLoadDriver(CurrentService); Status = IopLoadDriver(CurrentService);
} }
} }
ServiceEntry = ServiceEntry->Flink;
} }
GroupEntry = GroupEntry->Flink;
} }
DPRINT("IopInitializeSystemDrivers() done\n"); DPRINT("IopInitializeSystemDrivers() done\n");

View file

@ -1383,7 +1383,6 @@ NtCancelIoFile(IN HANDLE FileHandle,
NTSTATUS Status; NTSTATUS Status;
PFILE_OBJECT FileObject; PFILE_OBJECT FileObject;
PETHREAD Thread; PETHREAD Thread;
PLIST_ENTRY IrpEntry;
PIRP Irp; PIRP Irp;
KIRQL OldIrql; KIRQL OldIrql;
BOOLEAN OurIrpsInList = FALSE; BOOLEAN OurIrpsInList = FALSE;
@ -1408,11 +1407,9 @@ NtCancelIoFile(IN HANDLE FileHandle,
*/ */
Thread = PsGetCurrentThread(); Thread = PsGetCurrentThread();
for (IrpEntry = Thread->IrpList.Flink;
IrpEntry != &Thread->IrpList; LIST_FOR_EACH(Irp, &Thread->IrpList, IRP, ThreadListEntry)
IrpEntry = IrpEntry->Flink)
{ {
Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
if (Irp->Tail.Overlay.OriginalFileObject == FileObject) if (Irp->Tail.Overlay.OriginalFileObject == FileObject)
{ {
IoCancelIrp(Irp); IoCancelIrp(Irp);
@ -1440,11 +1437,8 @@ NtCancelIoFile(IN HANDLE FileHandle,
* forever. * forever.
*/ */
for (IrpEntry = Thread->IrpList.Flink; LIST_FOR_EACH(Irp, &Thread->IrpList, IRP, ThreadListEntry)
IrpEntry != &Thread->IrpList;
IrpEntry = IrpEntry->Flink)
{ {
Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
if (Irp->Tail.Overlay.OriginalFileObject == FileObject) if (Irp->Tail.Overlay.OriginalFileObject == FileObject)
{ {
OurIrpsInList = TRUE; OurIrpsInList = TRUE;

View file

@ -72,7 +72,6 @@ IoInitFileSystemImplementation(VOID)
VOID VOID
IoShutdownRegisteredFileSystems(VOID) IoShutdownRegisteredFileSystems(VOID)
{ {
PLIST_ENTRY current_entry;
FILE_SYSTEM_OBJECT* current; FILE_SYSTEM_OBJECT* current;
PIRP Irp; PIRP Irp;
KEVENT Event; KEVENT Event;
@ -87,11 +86,8 @@ IoShutdownRegisteredFileSystems(VOID)
NotificationEvent, NotificationEvent,
FALSE); FALSE);
current_entry = FileSystemListHead.Flink; LIST_FOR_EACH(current, &FileSystemListHead, FILE_SYSTEM_OBJECT,Entry)
while (current_entry!=(&FileSystemListHead))
{ {
current = CONTAINING_RECORD(current_entry,FILE_SYSTEM_OBJECT,Entry);
/* send IRP_MJ_SHUTDOWN */ /* send IRP_MJ_SHUTDOWN */
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN, Irp = IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN,
current->DeviceObject, current->DeviceObject,
@ -110,8 +106,6 @@ IoShutdownRegisteredFileSystems(VOID)
FALSE, FALSE,
NULL); NULL);
} }
current_entry = current_entry->Flink;
} }
ExReleaseResourceLite(&FileSystemListLock); ExReleaseResourceLite(&FileSystemListLock);
@ -224,8 +218,7 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
* RETURNS: Status * RETURNS: Status
*/ */
{ {
PLIST_ENTRY current_entry; PFILE_SYSTEM_OBJECT current;
FILE_SYSTEM_OBJECT* current;
NTSTATUS Status; NTSTATUS Status;
DEVICE_TYPE MatchingDeviceType; DEVICE_TYPE MatchingDeviceType;
PDEVICE_OBJECT DevObject; PDEVICE_OBJECT DevObject;
@ -262,13 +255,12 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
KeEnterCriticalRegion(); KeEnterCriticalRegion();
ExAcquireResourceSharedLite(&FileSystemListLock,TRUE); ExAcquireResourceSharedLite(&FileSystemListLock,TRUE);
current_entry = FileSystemListHead.Flink;
while (current_entry!=(&FileSystemListHead)) restart:
LIST_FOR_EACH(current,&FileSystemListHead, FILE_SYSTEM_OBJECT, Entry)
{ {
current = CONTAINING_RECORD(current_entry,FILE_SYSTEM_OBJECT,Entry);
if (current->DeviceObject->DeviceType != MatchingDeviceType) if (current->DeviceObject->DeviceType != MatchingDeviceType)
{ {
current_entry = current_entry->Flink;
continue; continue;
} }
/* If we are not allowed to mount this volume as a raw filesystem volume /* If we are not allowed to mount this volume as a raw filesystem volume
@ -294,8 +286,7 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
return(Status); return(Status);
} }
ExAcquireResourceSharedLite(&FileSystemListLock,TRUE); ExAcquireResourceSharedLite(&FileSystemListLock,TRUE);
current_entry = FileSystemListHead.Flink; goto restart;
continue;
case STATUS_SUCCESS: case STATUS_SUCCESS:
DeviceObject->Vpb->Flags = DeviceObject->Vpb->Flags | DeviceObject->Vpb->Flags = DeviceObject->Vpb->Flags |
@ -306,7 +297,8 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
case STATUS_UNRECOGNIZED_VOLUME: case STATUS_UNRECOGNIZED_VOLUME:
default: default:
current_entry = current_entry->Flink; /* do nothing */
break;
} }
} }
ExReleaseResourceLite(&FileSystemListLock); ExReleaseResourceLite(&FileSystemListLock);
@ -504,28 +496,26 @@ IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
VOID STDCALL VOID STDCALL
IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject) IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
{ {
PLIST_ENTRY current_entry;
PFILE_SYSTEM_OBJECT current; PFILE_SYSTEM_OBJECT current;
DPRINT("IoUnregisterFileSystem(DeviceObject 0x%p)\n", DeviceObject); DPRINT("IoUnregisterFileSystem(DeviceObject 0x%p)\n", DeviceObject);
KeEnterCriticalRegion(); KeEnterCriticalRegion();
ExAcquireResourceExclusiveLite(&FileSystemListLock, TRUE); ExAcquireResourceExclusiveLite(&FileSystemListLock, TRUE);
current_entry = FileSystemListHead.Flink;
while (current_entry!=(&FileSystemListHead)) LIST_FOR_EACH(current,&FileSystemListHead, FILE_SYSTEM_OBJECT,Entry)
{ {
current = CONTAINING_RECORD(current_entry,FILE_SYSTEM_OBJECT,Entry);
if (current->DeviceObject == DeviceObject) if (current->DeviceObject == DeviceObject)
{ {
RemoveEntryList(current_entry); RemoveEntryList(&current->Entry);
ExFreePoolWithTag(current, TAG_FILE_SYSTEM); ExFreePoolWithTag(current, TAG_FILE_SYSTEM);
ExReleaseResourceLite(&FileSystemListLock); ExReleaseResourceLite(&FileSystemListLock);
KeLeaveCriticalRegion(); KeLeaveCriticalRegion();
IopNotifyFileSystemChange(DeviceObject, FALSE); IopNotifyFileSystemChange(DeviceObject, FALSE);
return; return;
} }
current_entry = current_entry->Flink;
} }
ExReleaseResourceLite(&FileSystemListLock); ExReleaseResourceLite(&FileSystemListLock);
KeLeaveCriticalRegion(); KeLeaveCriticalRegion();
} }
@ -595,17 +585,11 @@ IopNotifyFileSystemChange(PDEVICE_OBJECT DeviceObject,
BOOLEAN DriverActive) BOOLEAN DriverActive)
{ {
PFS_CHANGE_NOTIFY_ENTRY ChangeEntry; PFS_CHANGE_NOTIFY_ENTRY ChangeEntry;
PLIST_ENTRY Entry;
KeAcquireGuardedMutex(&FsChangeNotifyListLock); KeAcquireGuardedMutex(&FsChangeNotifyListLock);
Entry = FsChangeNotifyListHead.Flink; LIST_FOR_EACH(ChangeEntry, &FsChangeNotifyListHead,FS_CHANGE_NOTIFY_ENTRY, FsChangeNotifyList)
while (Entry != &FsChangeNotifyListHead)
{ {
ChangeEntry = CONTAINING_RECORD(Entry, FS_CHANGE_NOTIFY_ENTRY, FsChangeNotifyList);
(ChangeEntry->FSDNotificationProc)(DeviceObject, DriverActive); (ChangeEntry->FSDNotificationProc)(DeviceObject, DriverActive);
Entry = Entry->Flink;
} }
KeReleaseGuardedMutex(&FsChangeNotifyListLock); KeReleaseGuardedMutex(&FsChangeNotifyListLock);
} }
@ -646,24 +630,20 @@ IoUnregisterFsRegistrationChange(IN PDRIVER_OBJECT DriverObject,
IN PDRIVER_FS_NOTIFICATION FSDNotificationProc) IN PDRIVER_FS_NOTIFICATION FSDNotificationProc)
{ {
PFS_CHANGE_NOTIFY_ENTRY ChangeEntry; PFS_CHANGE_NOTIFY_ENTRY ChangeEntry;
PLIST_ENTRY Entry;
Entry = FsChangeNotifyListHead.Flink; LIST_FOR_EACH(ChangeEntry, &FsChangeNotifyListHead, FS_CHANGE_NOTIFY_ENTRY, FsChangeNotifyList)
while (Entry != &FsChangeNotifyListHead)
{ {
ChangeEntry = CONTAINING_RECORD(Entry, FS_CHANGE_NOTIFY_ENTRY, FsChangeNotifyList);
if (ChangeEntry->DriverObject == DriverObject && if (ChangeEntry->DriverObject == DriverObject &&
ChangeEntry->FSDNotificationProc == FSDNotificationProc) ChangeEntry->FSDNotificationProc == FSDNotificationProc)
{ {
KeAcquireGuardedMutex(&FsChangeNotifyListLock); KeAcquireGuardedMutex(&FsChangeNotifyListLock);
RemoveEntryList(Entry); RemoveEntryList(&ChangeEntry->FsChangeNotifyList);
KeReleaseGuardedMutex(&FsChangeNotifyListLock); KeReleaseGuardedMutex(&FsChangeNotifyListLock);
ExFreePoolWithTag(Entry, TAG_FS_CHANGE_NOTIFY); ExFreePoolWithTag(ChangeEntry, TAG_FS_CHANGE_NOTIFY);
return; return;
} }
Entry = Entry->Flink;
} }
} }

View file

@ -962,7 +962,6 @@ VOID
STDCALL STDCALL
IoCancelThreadIo(PETHREAD Thread) IoCancelThreadIo(PETHREAD Thread)
{ {
PLIST_ENTRY IrpEntry;
PIRP Irp; PIRP Irp;
KIRQL OldIrql; KIRQL OldIrql;
ULONG Retries = 3000; ULONG Retries = 3000;
@ -972,13 +971,8 @@ IoCancelThreadIo(PETHREAD Thread)
OldIrql = KfRaiseIrql(APC_LEVEL); OldIrql = KfRaiseIrql(APC_LEVEL);
/* Start by cancelling all the IRPs in the current thread queue. */ /* Start by cancelling all the IRPs in the current thread queue. */
for (IrpEntry = Thread->IrpList.Flink; LIST_FOR_EACH(Irp, &Thread->IrpList, IRP, ThreadListEntry)
IrpEntry != &Thread->IrpList;
IrpEntry = IrpEntry->Flink)
{ {
/* Get the IRP */
Irp = CONTAINING_RECORD(IrpEntry, IRP, ThreadListEntry);
/* Cancel it */ /* Cancel it */
IoCancelIrp(Irp); IoCancelIrp(Irp);
} }

View file

@ -184,7 +184,6 @@ IopNotifyPlugPlayNotification(
IN PVOID EventCategoryData2) IN PVOID EventCategoryData2)
{ {
PPNP_NOTIFY_ENTRY ChangeEntry; PPNP_NOTIFY_ENTRY ChangeEntry;
PLIST_ENTRY Entry;
PVOID NotificationStructure; PVOID NotificationStructure;
BOOLEAN CallCurrentEntry; BOOLEAN CallCurrentEntry;
@ -249,10 +248,8 @@ IopNotifyPlugPlayNotification(
* list to find those that meet some criteria. * list to find those that meet some criteria.
*/ */
Entry = PnpNotifyListHead.Flink; LIST_FOR_EACH(ChangeEntry,&PnpNotifyListHead, PNP_NOTIFY_ENTRY, PnpNotifyList)
while (Entry != &PnpNotifyListHead)
{ {
ChangeEntry = CONTAINING_RECORD(Entry, PNP_NOTIFY_ENTRY, PnpNotifyList);
CallCurrentEntry = FALSE; CallCurrentEntry = FALSE;
switch (EventCategory) switch (EventCategory)
@ -294,7 +291,6 @@ IopNotifyPlugPlayNotification(
ChangeEntry->Context); ChangeEntry->Context);
} }
Entry = Entry->Flink;
} }
KeReleaseGuardedMutex(&PnpNotifyListLock); KeReleaseGuardedMutex(&PnpNotifyListLock);
ExFreePoolWithTag(NotificationStructure, TAG_PNP_NOTIFY); ExFreePoolWithTag(NotificationStructure, TAG_PNP_NOTIFY);

View file

@ -766,7 +766,6 @@ PnpRootQueryBusRelations(
PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension; PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension;
PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension; PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
PDEVICE_RELATIONS Relations; PDEVICE_RELATIONS Relations;
PLIST_ENTRY CurrentEntry;
PPNPROOT_DEVICE Device; PPNPROOT_DEVICE Device;
NTSTATUS Status; NTSTATUS Status;
ULONG Size; ULONG Size;
@ -796,11 +795,8 @@ PnpRootQueryBusRelations(
Relations->Count = DeviceExtension->DeviceListCount; Relations->Count = DeviceExtension->DeviceListCount;
i = 0; i = 0;
CurrentEntry = DeviceExtension->DeviceListHead.Flink; LIST_FOR_EACH(Device,&DeviceExtension->DeviceListHead,PNPROOT_DEVICE, ListEntry)
while (CurrentEntry != &DeviceExtension->DeviceListHead)
{ {
Device = CONTAINING_RECORD(CurrentEntry, PNPROOT_DEVICE, ListEntry);
if (!Device->Pdo) if (!Device->Pdo)
{ {
/* Create a physical device object for the /* Create a physical device object for the
@ -894,8 +890,6 @@ PnpRootQueryBusRelations(
Relations->Objects[i] = Device->Pdo; Relations->Objects[i] = Device->Pdo;
i++; i++;
CurrentEntry = CurrentEntry->Flink;
} }
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))

View file

@ -254,8 +254,6 @@ KiInsertQueueApc(PKAPC Apc,
KPRIORITY PriorityBoost) KPRIORITY PriorityBoost)
{ {
PKTHREAD Thread = Apc->Thread; PKTHREAD Thread = Apc->Thread;
PLIST_ENTRY ApcListEntry;
PKAPC QueuedApc;
KeAcquireSpinLockAtDpcLevel(&Thread->ApcQueueLock); KeAcquireSpinLockAtDpcLevel(&Thread->ApcQueueLock);
@ -282,17 +280,14 @@ KiInsertQueueApc(PKAPC Apc,
DPRINT("Inserting Special APC %x for '%.16s' into the Queue\n", Apc, ((PETHREAD)Thread)->ThreadsProcess->ImageFileName); DPRINT("Inserting Special APC %x for '%.16s' into the Queue\n", Apc, ((PETHREAD)Thread)->ThreadsProcess->ImageFileName);
for (ApcListEntry = Thread->ApcStatePointer[(int)Apc->ApcStateIndex]->ApcListHead[(int)Apc->ApcMode].Flink; /* insert special apc before normal apcs (if any) but after the last special apc (fifo) */
ApcListEntry != &Thread->ApcStatePointer[(int)Apc->ApcStateIndex]->ApcListHead[(int)Apc->ApcMode]; InsertAscendingListFIFO(
ApcListEntry = ApcListEntry->Flink) { &Thread->ApcStatePointer[(int)Apc->ApcStateIndex]->ApcListHead[(int)Apc->ApcMode],
Apc,
QueuedApc = CONTAINING_RECORD(ApcListEntry, KAPC, ApcListEntry); KAPC,
if (Apc->NormalRoutine != NULL) break; ApcListEntry,
} NormalRoutine /* sort field */
);
/* We found the first "Normal" APC, so write right before it */
ApcListEntry = ApcListEntry->Blink;
InsertHeadList(ApcListEntry, &Apc->ApcListEntry);
} else { } else {
@ -469,25 +464,23 @@ KeFlushQueueApc(IN PKTHREAD Thread,
{ {
KIRQL OldIrql; KIRQL OldIrql;
PKAPC Apc; PKAPC Apc;
PLIST_ENTRY FirstEntry, CurrentEntry; PLIST_ENTRY FirstEntry = NULL;
/* Lock the Dispatcher Database and APC Queue */ /* Lock the Dispatcher Database and APC Queue */
OldIrql = KeAcquireDispatcherDatabaseLock(); OldIrql = KeAcquireDispatcherDatabaseLock();
KeAcquireSpinLockAtDpcLevel(&Thread->ApcQueueLock); KeAcquireSpinLockAtDpcLevel(&Thread->ApcQueueLock);
if (IsListEmpty(&Thread->ApcState.ApcListHead[PreviousMode])) { /* mark all apcs as not-inserted */
FirstEntry = NULL; LIST_FOR_EACH(Apc, &Thread->ApcState.ApcListHead[PreviousMode], KAPC, ApcListEntry) {
} else { Apc->Inserted = FALSE;
FirstEntry = Thread->ApcState.ApcListHead[PreviousMode].Flink;
RemoveEntryList(&Thread->ApcState.ApcListHead[PreviousMode]);
CurrentEntry = FirstEntry;
do {
Apc = CONTAINING_RECORD(CurrentEntry, KAPC, ApcListEntry);
Apc->Inserted = FALSE;
CurrentEntry = CurrentEntry->Flink;
} while (CurrentEntry != FirstEntry);
} }
if (!IsListEmpty(&Thread->ApcState.ApcListHead[PreviousMode])) {
FirstEntry = Thread->ApcState.ApcListHead[PreviousMode].Flink;
/* unlink list head from the rest of the list */
RemoveEntryList(&Thread->ApcState.ApcListHead[PreviousMode]);
}
/* Release the locks */ /* Release the locks */
KeReleaseSpinLockFromDpcLevel(&Thread->ApcQueueLock); KeReleaseSpinLockFromDpcLevel(&Thread->ApcQueueLock);
KeReleaseDispatcherDatabaseLock(OldIrql); KeReleaseDispatcherDatabaseLock(OldIrql);

View file

@ -252,7 +252,6 @@ KiDoBugCheckCallbacks(VOID)
{ {
PKBUGCHECK_CALLBACK_RECORD CurrentRecord; PKBUGCHECK_CALLBACK_RECORD CurrentRecord;
PLIST_ENTRY ListHead; PLIST_ENTRY ListHead;
PLIST_ENTRY NextEntry;
/* FIXME: Check Checksum and add support for WithReason Callbacks */ /* FIXME: Check Checksum and add support for WithReason Callbacks */
@ -261,14 +260,8 @@ KiDoBugCheckCallbacks(VOID)
if (ListHead->Flink && ListHead->Blink) { if (ListHead->Flink && ListHead->Blink) {
/* Loop the list */ /* Loop the list */
NextEntry = ListHead->Flink; LIST_FOR_EACH(CurrentRecord, ListHead, KBUGCHECK_CALLBACK_RECORD, Entry)
while (NextEntry != ListHead) { {
/* Get the Callback Record */
CurrentRecord = CONTAINING_RECORD(NextEntry,
KBUGCHECK_CALLBACK_RECORD,
Entry);
/* Make sure it's inserted */ /* Make sure it's inserted */
if (CurrentRecord->State == BufferInserted) { if (CurrentRecord->State == BufferInserted) {
@ -278,9 +271,6 @@ KiDoBugCheckCallbacks(VOID)
CurrentRecord->Length); CurrentRecord->Length);
CurrentRecord->State = BufferFinished; CurrentRecord->State = BufferFinished;
} }
/* Move to next Entry */
NextEntry = NextEntry->Flink;
} }
} }
} }
@ -297,7 +287,6 @@ KeBugCheckWithTf(ULONG BugCheckCode,
KIRQL OldIrql; KIRQL OldIrql;
BOOLEAN GotExtendedCrashInfo = FALSE; BOOLEAN GotExtendedCrashInfo = FALSE;
PVOID Address = 0; PVOID Address = 0;
PLIST_ENTRY CurrentEntry;
PLDR_DATA_TABLE_ENTRY CurrentModule = NULL; PLDR_DATA_TABLE_ENTRY CurrentModule = NULL;
extern LIST_ENTRY ModuleListHead; extern LIST_ENTRY ModuleListHead;
#if 0 #if 0
@ -322,14 +311,8 @@ KeBugCheckWithTf(ULONG BugCheckCode,
Address = (PVOID)Tf->Eip; Address = (PVOID)Tf->Eip;
/* Try to get information on the module */ /* Try to get information on the module */
CurrentEntry = ModuleListHead.Flink; LIST_FOR_EACH(CurrentModule, &ModuleListHead, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList)
while (CurrentEntry != &ModuleListHead)
{ {
/* Get the current Section */
CurrentModule = CONTAINING_RECORD(CurrentEntry,
LDR_DATA_TABLE_ENTRY,
InLoadOrderModuleList);
/* Check if this is the right one */ /* Check if this is the right one */
if ((Address != NULL && (Address >= (PVOID)CurrentModule->DllBase && if ((Address != NULL && (Address >= (PVOID)CurrentModule->DllBase &&
Address < (PVOID)((ULONG_PTR)CurrentModule->DllBase + CurrentModule->SizeOfImage)))) Address < (PVOID)((ULONG_PTR)CurrentModule->DllBase + CurrentModule->SizeOfImage))))
@ -338,9 +321,6 @@ KeBugCheckWithTf(ULONG BugCheckCode,
GotExtendedCrashInfo = TRUE; GotExtendedCrashInfo = TRUE;
break; break;
} }
/* Loop again */
CurrentEntry = CurrentEntry->Flink;
} }
} }

View file

@ -118,9 +118,9 @@ KeInsertByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,
/* Insert new entry after the last entry with SortKey less or equal to passed-in SortKey */ /* Insert new entry after the last entry with SortKey less or equal to passed-in SortKey */
InsertAscendingListFIFO(&DeviceQueue->DeviceListHead, InsertAscendingListFIFO(&DeviceQueue->DeviceListHead,
DeviceQueueEntry,
KDEVICE_QUEUE_ENTRY, KDEVICE_QUEUE_ENTRY,
DeviceListEntry, DeviceListEntry,
DeviceQueueEntry,
SortKey); SortKey);
Inserted = TRUE; Inserted = TRUE;
} }
@ -204,34 +204,25 @@ KeRemoveByKeyDeviceQueue (IN PKDEVICE_QUEUE DeviceQueue,
} else { } else {
/* Find entry with SortKey greater than or equal to the passed-in SortKey */ /* Find entry with SortKey greater than or equal to the passed-in SortKey */
ListEntry = DeviceQueue->DeviceListHead.Flink; LIST_FOR_EACH(ReturnEntry, &DeviceQueue->DeviceListHead, KDEVICE_QUEUE_ENTRY, DeviceListEntry)
while (ListEntry != &DeviceQueue->DeviceListHead) { {
/* Get Entry */
ReturnEntry = CONTAINING_RECORD(ListEntry,
KDEVICE_QUEUE_ENTRY,
DeviceListEntry);
/* Check if keys match */ /* Check if keys match */
if (ReturnEntry->SortKey >= SortKey) break; if (ReturnEntry->SortKey >= SortKey) {
/* We found it, so just remove it */
/* Move to next item */ RemoveEntryList(&ReturnEntry->DeviceListEntry);
ListEntry = ListEntry->Flink; break;
}
} }
/* Check if we found something */ /* Check if we found something */
if (ListEntry == &DeviceQueue->DeviceListHead) { if (!ReturnEntry) {
/* Not found, return the first entry */ /* Not found, return the first entry */
ListEntry = RemoveHeadList(&DeviceQueue->DeviceListHead); ListEntry = RemoveHeadList(&DeviceQueue->DeviceListHead);
ReturnEntry = CONTAINING_RECORD(ListEntry, ReturnEntry = CONTAINING_RECORD(ListEntry,
KDEVICE_QUEUE_ENTRY, KDEVICE_QUEUE_ENTRY,
DeviceListEntry); DeviceListEntry);
} else { }
/* We found it, so just remove it */
RemoveEntryList(&ReturnEntry->DeviceListEntry);
}
/* Set it as non-inserted */ /* Set it as non-inserted */
ReturnEntry->Inserted = FALSE; ReturnEntry->Inserted = FALSE;

View file

@ -76,7 +76,6 @@ PKTHREAD
KiScanThreadList(KPRIORITY Priority, KiScanThreadList(KPRIORITY Priority,
KAFFINITY Affinity) KAFFINITY Affinity)
{ {
PLIST_ENTRY current_entry;
PKTHREAD current; PKTHREAD current;
ULONG Mask; ULONG Mask;
@ -84,11 +83,7 @@ KiScanThreadList(KPRIORITY Priority,
if (PriorityListMask & Mask) { if (PriorityListMask & Mask) {
current_entry = PriorityListHead[Priority].Flink; LIST_FOR_EACH(current, &PriorityListHead[Priority], KTHREAD, WaitListEntry) {
while (current_entry != &PriorityListHead[Priority]) {
current = CONTAINING_RECORD(current_entry, KTHREAD, WaitListEntry);
if (current->State != Ready) { if (current->State != Ready) {
@ -102,8 +97,6 @@ KiScanThreadList(KPRIORITY Priority,
KiRemoveFromThreadList(current); KiRemoveFromThreadList(current);
return(current); return(current);
} }
current_entry = current_entry->Flink;
} }
} }
@ -548,7 +541,6 @@ STDCALL
KeFreezeAllThreads(PKPROCESS Process) KeFreezeAllThreads(PKPROCESS Process)
{ {
KIRQL OldIrql; KIRQL OldIrql;
PLIST_ENTRY CurrentEntry;
PKTHREAD Current; PKTHREAD Current;
PKTHREAD CurrentThread = KeGetCurrentThread(); PKTHREAD CurrentThread = KeGetCurrentThread();
@ -556,12 +548,8 @@ KeFreezeAllThreads(PKPROCESS Process)
OldIrql = KeAcquireDispatcherDatabaseLock(); OldIrql = KeAcquireDispatcherDatabaseLock();
/* Loop the Process's Threads */ /* Loop the Process's Threads */
CurrentEntry = Process->ThreadListHead.Flink; LIST_FOR_EACH(Current, &Process->ThreadListHead, KTHREAD, ThreadListEntry)
while (CurrentEntry != &Process->ThreadListHead)
{ {
/* Get the Thread */
Current = CONTAINING_RECORD(CurrentEntry, KTHREAD, ThreadListEntry);
/* Make sure it's not ours */ /* Make sure it's not ours */
if (Current == CurrentThread) continue; if (Current == CurrentThread) continue;
@ -575,8 +563,6 @@ KeFreezeAllThreads(PKPROCESS Process)
Current->SuspendSemaphore.Header.SignalState--; Current->SuspendSemaphore.Header.SignalState--;
} }
} }
CurrentEntry = CurrentEntry->Flink;
} }
/* Release the lock */ /* Release the lock */
@ -1456,8 +1442,8 @@ KiServiceCheck (VOID)
if (Thread->ServiceTable != KeServiceDescriptorTableShadow) { if (Thread->ServiceTable != KeServiceDescriptorTableShadow) {
/* We do. Initialize it and save the new table */ /* We do. Initialize it and save the new table */
PsInitWin32Thread((PETHREAD)Thread);
Thread->ServiceTable = KeServiceDescriptorTableShadow; Thread->ServiceTable = KeServiceDescriptorTableShadow;
PsInitWin32Thread((PETHREAD)Thread);
} }
} }

View file

@ -53,17 +53,15 @@ KeStartProfile(PKPROFILE Profile,
{ {
KIRQL OldIrql; KIRQL OldIrql;
PKPROFILE_SOURCE_OBJECT SourceBuffer; PKPROFILE_SOURCE_OBJECT SourceBuffer;
PKPROFILE_SOURCE_OBJECT Source = NULL;
PKPROFILE_SOURCE_OBJECT CurrentSource; PKPROFILE_SOURCE_OBJECT CurrentSource;
BOOLEAN FreeBuffer = TRUE; BOOLEAN FreeBuffer = TRUE;
PKPROCESS ProfileProcess; PKPROCESS ProfileProcess;
PLIST_ENTRY ListEntry;
/* Allocate a buffer first, before we raise IRQL */ /* Allocate a buffer first, before we raise IRQL */
SourceBuffer = ExAllocatePoolWithTag(NonPagedPool, SourceBuffer = ExAllocatePoolWithTag(NonPagedPool,
sizeof(KPROFILE_SOURCE_OBJECT), sizeof(KPROFILE_SOURCE_OBJECT),
TAG('P', 'r', 'o', 'f')); TAG('P', 'r', 'o', 'f'));
RtlZeroMemory(Source, sizeof(KPROFILE_SOURCE_OBJECT)); RtlZeroMemory(SourceBuffer, sizeof(KPROFILE_SOURCE_OBJECT));
/* Raise to PROFILE_LEVEL */ /* Raise to PROFILE_LEVEL */
KeRaiseIrql(PROFILE_LEVEL, &OldIrql); KeRaiseIrql(PROFILE_LEVEL, &OldIrql);
@ -90,32 +88,23 @@ KeStartProfile(PKPROFILE Profile,
} }
/* Check if this type of profile (source) is already running */ /* Check if this type of profile (source) is already running */
for (ListEntry = KiProfileSourceListHead.Flink; LIST_FOR_EACH(CurrentSource, &KiProfileSourceListHead, KPROFILE_SOURCE_OBJECT, ListEntry)
ListEntry != &KiProfileSourceListHead; {
ListEntry = ListEntry->Flink) {
/* Get the Source Object */
CurrentSource = CONTAINING_RECORD(ListEntry,
KPROFILE_SOURCE_OBJECT,
ListEntry);
/* Check if it's the same as the one being requested now */ /* Check if it's the same as the one being requested now */
if (CurrentSource->Source == Profile->Source) { if (CurrentSource->Source == Profile->Source) {
Source = CurrentSource;
break; break;
} }
} }
/* See if the loop found something */ /* See if the loop found something */
if (!Source) { if (!CurrentSource) {
/* Nothing found, use our allocated buffer */ /* Nothing found, use our allocated buffer */
Source = SourceBuffer; CurrentSource = SourceBuffer;
/* Set up the Source Object */ /* Set up the Source Object */
Source->Source = Profile->Source; CurrentSource->Source = Profile->Source;
InsertHeadList(&KiProfileSourceListHead, &Source->ListEntry); InsertHeadList(&KiProfileSourceListHead, &CurrentSource->ListEntry);
/* Don't free the pool later on */ /* Don't free the pool later on */
FreeBuffer = FALSE; FreeBuffer = FALSE;
@ -138,7 +127,6 @@ STDCALL
KeStopProfile(PKPROFILE Profile) KeStopProfile(PKPROFILE Profile)
{ {
KIRQL OldIrql; KIRQL OldIrql;
PLIST_ENTRY ListEntry;
PKPROFILE_SOURCE_OBJECT CurrentSource = NULL; PKPROFILE_SOURCE_OBJECT CurrentSource = NULL;
/* Raise to PROFILE_LEVEL and acquire spinlock */ /* Raise to PROFILE_LEVEL and acquire spinlock */
@ -153,18 +141,15 @@ KeStopProfile(PKPROFILE Profile)
Profile->Active = FALSE; Profile->Active = FALSE;
/* Find the Source Object */ /* Find the Source Object */
for (ListEntry = KiProfileSourceListHead.Flink; LIST_FOR_EACH(CurrentSource, &KiProfileSourceListHead, KPROFILE_SOURCE_OBJECT, ListEntry)
CurrentSource->Source != Profile->Source; {
ListEntry = ListEntry->Flink) { if (CurrentSource->Source == Profile->Source) {
/* Remove it */
/* Get the Source Object */ RemoveEntryList(&CurrentSource->ListEntry);
CurrentSource = CONTAINING_RECORD(ListEntry, break;
KPROFILE_SOURCE_OBJECT, }
ListEntry);
} }
/* Remove it */
RemoveEntryList(&CurrentSource->ListEntry);
} }
/* Lower IRQL */ /* Lower IRQL */
@ -240,14 +225,10 @@ KiParseProfileList(IN PKTRAP_FRAME TrapFrame,
{ {
PULONG BucketValue; PULONG BucketValue;
PKPROFILE Profile; PKPROFILE Profile;
PLIST_ENTRY NextEntry;
/* Loop the List */ /* Loop the List */
for (NextEntry = ListHead->Flink; NextEntry != ListHead; NextEntry = NextEntry->Flink) { LIST_FOR_EACH(Profile, ListHead, KPROFILE, ListEntry)
{
/* Get the Current Profile in the List */
Profile = CONTAINING_RECORD(NextEntry, KPROFILE, ListEntry);
/* Check if the source is good, and if it's within the range */ /* Check if the source is good, and if it's within the range */
if ((Profile->Source != Source) || if ((Profile->Source != Source) ||
(TrapFrame->Eip < (ULONG_PTR)Profile->RegionStart) || (TrapFrame->Eip < (ULONG_PTR)Profile->RegionStart) ||

View file

@ -182,17 +182,14 @@ KeRemoveQueue(IN PKQUEUE Queue,
/* Loop until the queue is processed */ /* Loop until the queue is processed */
while (TRUE) { while (TRUE) {
/* Get the Entry */
ListEntry = Queue->EntryListHead.Flink;
/* Check if the counts are valid and if there is still a queued entry */ /* Check if the counts are valid and if there is still a queued entry */
if ((Queue->CurrentCount < Queue->MaximumCount) && if ((Queue->CurrentCount < Queue->MaximumCount) &&
(ListEntry != &Queue->EntryListHead)) { !IsListEmpty(&Queue->EntryListHead)) {
/* Remove the Entry and Save it */ /* Remove the Entry and Save it */
DPRINT("Removing Queue Entry. CurrentCount: %d, Maximum Count: %d\n", DPRINT("Removing Queue Entry. CurrentCount: %d, Maximum Count: %d\n",
Queue->CurrentCount, Queue->MaximumCount); Queue->CurrentCount, Queue->MaximumCount);
ListEntry = RemoveHeadList(&Queue->EntryListHead); ListEntry = Queue->EntryListHead.Flink;
/* Decrease the number of entries */ /* Decrease the number of entries */
Queue->Header.SignalState--; Queue->Header.SignalState--;
@ -328,7 +325,7 @@ STDCALL
KeRundownQueue(IN PKQUEUE Queue) KeRundownQueue(IN PKQUEUE Queue)
{ {
PLIST_ENTRY EnumEntry; PLIST_ENTRY EnumEntry;
PLIST_ENTRY FirstEntry; PLIST_ENTRY FirstEntry = NULL;
PKTHREAD Thread; PKTHREAD Thread;
KIRQL OldIrql; KIRQL OldIrql;
@ -337,19 +334,11 @@ KeRundownQueue(IN PKQUEUE Queue)
/* Get the Dispatcher Lock */ /* Get the Dispatcher Lock */
OldIrql = KeAcquireDispatcherDatabaseLock(); OldIrql = KeAcquireDispatcherDatabaseLock();
/* Get the First Empty Entry */
FirstEntry = Queue->EntryListHead.Flink;
/* Make sure the list is not empty */ /* Make sure the list is not empty */
if (FirstEntry == &Queue->EntryListHead) { if (!IsListEmpty(&Queue->EntryListHead))
{
/* It is, so don't return anything */
FirstEntry = NULL;
} else {
/* Remove it */ /* Remove it */
RemoveEntryList(&Queue->EntryListHead); FirstEntry = RemoveHeadList(&Queue->EntryListHead);
} }
/* Unlink threads and clear their Thread->Queue */ /* Unlink threads and clear their Thread->Queue */

View file

@ -217,7 +217,7 @@ KiExpireTimers(PKDPC Dpc,
PVOID SystemArgument1, PVOID SystemArgument1,
PVOID SystemArgument2) PVOID SystemArgument2)
{ {
PKTIMER Timer; PKTIMER Timer, tmp;
ULONGLONG InterruptTime; ULONGLONG InterruptTime;
LIST_ENTRY ExpiredTimerList; LIST_ENTRY ExpiredTimerList;
PLIST_ENTRY CurrentEntry = NULL; PLIST_ENTRY CurrentEntry = NULL;
@ -235,25 +235,22 @@ KiExpireTimers(PKDPC Dpc,
InterruptTime = KeQueryInterruptTime(); InterruptTime = KeQueryInterruptTime();
/* Loop through the Timer List and remove Expired Timers. Insert them into the Expired Listhead */ /* Loop through the Timer List and remove Expired Timers. Insert them into the Expired Listhead */
CurrentEntry = KiTimerListHead.Flink; LIST_FOR_EACH_SAFE(Timer, tmp, &KiTimerListHead, KTIMER, TimerListEntry)
while (CurrentEntry != &KiTimerListHead) { {
/* Get the Current Timer */
Timer = CONTAINING_RECORD(CurrentEntry, KTIMER, TimerListEntry);
DPRINT("Looping for Timer: %x. Duetime: %I64d. InterruptTime %I64d \n", Timer, Timer->DueTime.QuadPart, InterruptTime); DPRINT("Looping for Timer: %x. Duetime: %I64d. InterruptTime %I64d \n", Timer, Timer->DueTime.QuadPart, InterruptTime);
/* Check if we have to Expire it */ /* Check if we have to Expire it */
if (InterruptTime < Timer->DueTime.QuadPart) break; if (InterruptTime < Timer->DueTime.QuadPart) break;
CurrentEntry = CurrentEntry->Flink;
/* Remove it from the Timer List, add it to the Expired List */ /* Remove it from the Timer List, add it to the Expired List */
RemoveEntryList(&Timer->TimerListEntry); RemoveEntryList(&Timer->TimerListEntry);
InsertTailList(&ExpiredTimerList, &Timer->TimerListEntry); InsertTailList(&ExpiredTimerList, &Timer->TimerListEntry);
} }
/* Expire the Timers */ /* Expire the Timers */
while ((CurrentEntry = RemoveHeadList(&ExpiredTimerList)) != &ExpiredTimerList) { while (!IsListEmpty(&ExpiredTimerList)) {
CurrentEntry = RemoveHeadList(&ExpiredTimerList);
/* Get the Timer */ /* Get the Timer */
Timer = CONTAINING_RECORD(CurrentEntry, KTIMER, TimerListEntry); Timer = CONTAINING_RECORD(CurrentEntry, KTIMER, TimerListEntry);
@ -373,9 +370,9 @@ KiInsertTimer(PKTIMER Timer,
/* Now insert it into the Timer List */ /* Now insert it into the Timer List */
DPRINT("Inserting Timer into list\n"); DPRINT("Inserting Timer into list\n");
InsertAscendingList(&KiTimerListHead, InsertAscendingList(&KiTimerListHead,
Timer,
KTIMER, KTIMER,
TimerListEntry, TimerListEntry,
Timer,
DueTime.QuadPart); DueTime.QuadPart);
return TRUE; return TRUE;

View file

@ -838,7 +838,7 @@ AddDiskToList (HANDLE FileHandle,
GetDriverName (DiskEntry); GetDriverName (DiskEntry);
InsertAscendingList(&List->DiskListHead, DISKENTRY, ListEntry, DiskEntry, BiosDiskNumber); InsertAscendingList(&List->DiskListHead, DiskEntry, DISKENTRY, ListEntry, BiosDiskNumber);
LayoutBuffer = (DRIVE_LAYOUT_INFORMATION*)RtlAllocateHeap (ProcessHeap, LayoutBuffer = (DRIVE_LAYOUT_INFORMATION*)RtlAllocateHeap (ProcessHeap,
0, 0,
@ -1225,7 +1225,6 @@ PrintDiskData (PPARTLIST List,
PDISKENTRY DiskEntry) PDISKENTRY DiskEntry)
{ {
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PLIST_ENTRY Entry;
CHAR LineBuffer[128]; CHAR LineBuffer[128];
COORD coPos; COORD coPos;
ULONG Written; ULONG Written;
@ -1305,17 +1304,12 @@ PrintDiskData (PPARTLIST List,
PrintEmptyLine (List); PrintEmptyLine (List);
/* Print partition lines*/ /* Print partition lines*/
Entry = DiskEntry->PartListHead.Flink; LIST_FOR_EACH(PartEntry, &DiskEntry->PartListHead, PARTENTRY, ListEntry)
while (Entry != &DiskEntry->PartListHead)
{ {
PartEntry = CONTAINING_RECORD (Entry, PARTENTRY, ListEntry);
/* Print disk entry */ /* Print disk entry */
PrintPartitionData (List, PrintPartitionData (List,
DiskEntry, DiskEntry,
PartEntry); PartEntry);
Entry = Entry->Flink;
} }
/* Print separator line */ /* Print separator line */
@ -1507,16 +1501,11 @@ DrawPartitionList (PPARTLIST List)
/* print list entries */ /* print list entries */
List->Line = - List->Offset; List->Line = - List->Offset;
Entry = List->DiskListHead.Flink; LIST_FOR_EACH(DiskEntry, &List->DiskListHead, DISKENTRY, ListEntry)
while (Entry != &List->DiskListHead)
{ {
DiskEntry = CONTAINING_RECORD (Entry, DISKENTRY, ListEntry);
/* Print disk entry */ /* Print disk entry */
PrintDiskData (List, PrintDiskData (List,
DiskEntry); DiskEntry);
Entry = Entry->Flink;
} }
} }

View file

@ -615,16 +615,6 @@ NtUserUnregisterClass(
RETURN(FALSE); RETURN(FALSE);
} }
/* this was probably ment to prevent sysclass dereg
Seems wrong. Any class can have NULL hInst, not only sysclasses
*/
// if (Class->hInstance && Class->hInstance != hInstance)
// {
// SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST);
// RETURN( FALSE);
// }
if (Class->refs) if (Class->refs)
{ {
/* NOTE: the class will not be freed when its refs become 0 ie. no more /* NOTE: the class will not be freed when its refs become 0 ie. no more