Author: cgutman
Date: Thu Dec 1 22:31:54 2011
New Revision: 54557
URL:
http://svn.reactos.org/svn/reactos?rev=54557&view=rev
Log:
[NDIS]
- Make NdisMAllocateSharedMemoryAsync and NdisMFreeSharedMemory safe to call at IRQL <=
DISPATCH_LEVEL
Modified:
trunk/reactos/drivers/network/ndis/include/miniport.h
trunk/reactos/drivers/network/ndis/ndis/memory.c
Modified: trunk/reactos/drivers/network/ndis/include/miniport.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/inclu…
==============================================================================
--- trunk/reactos/drivers/network/ndis/include/miniport.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/include/miniport.h [iso-8859-1] Thu Dec 1 22:31:54
2011
@@ -71,7 +71,7 @@
BOOLEAN Cached;
PNDIS_MINIPORT_BLOCK Adapter;
PVOID Context;
- PKEVENT Event;
+ PIO_WORKITEM WorkItem;
} MINIPORT_SHARED_MEMORY, *PMINIPORT_SHARED_MEMORY;
/* A structure of WrapperConfigurationContext (not compatible with the
Modified: trunk/reactos/drivers/network/ndis/ndis/memory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/…
==============================================================================
--- trunk/reactos/drivers/network/ndis/ndis/memory.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/ndis/memory.c [iso-8859-1] Thu Dec 1 22:31:54
2011
@@ -188,6 +188,7 @@
VOID
NTAPI
NdisMFreeSharedMemoryPassive(
+ PDEVICE_OBJECT DeviceObject,
PVOID Context)
/*
* FUNCTION: Free a common buffer
@@ -198,7 +199,6 @@
*/
{
PMINIPORT_SHARED_MEMORY Memory = (PMINIPORT_SHARED_MEMORY)Context;
- PRKEVENT Event = Memory->Event;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
@@ -208,11 +208,8 @@
Memory->AdapterObject, Memory->Length, Memory->PhysicalAddress,
Memory->VirtualAddress, Memory->Cached);
+ IoFreeWorkItem(Memory->WorkItem);
ExFreePool(Memory);
-
- KeSetEvent(Event,
- IO_NO_INCREMENT,
- FALSE);
}
@@ -240,10 +237,8 @@
* Therefore we have to do this in a worker thread.
*/
{
- HANDLE ThreadHandle;
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
PMINIPORT_SHARED_MEMORY Memory;
- KEVENT Event;
NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
@@ -257,8 +252,6 @@
NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
return;
}
-
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
Memory->AdapterObject = Adapter->NdisMiniportBlock.SystemAdapterObject;
Memory->Length = Length;
@@ -266,21 +259,25 @@
Memory->VirtualAddress = VirtualAddress;
Memory->Cached = Cached;
Memory->Adapter = &Adapter->NdisMiniportBlock;
- Memory->Event = &Event;
-
- PsCreateSystemThread(&ThreadHandle, THREAD_ALL_ACCESS, 0, 0, 0,
NdisMFreeSharedMemoryPassive, Memory);
- ZwClose(ThreadHandle);
-
- KeWaitForSingleObject(&Event,
- Executive,
- KernelMode,
- FALSE,
- NULL);
+
+ Memory->WorkItem = IoAllocateWorkItem(Adapter->NdisMiniportBlock.DeviceObject);
+ if (!Memory->WorkItem)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
+ ExFreePool(Memory);
+ return;
+ }
+
+ IoQueueWorkItem(Memory->WorkItem,
+ NdisMFreeSharedMemoryPassive,
+ CriticalWorkQueue,
+ Memory);
}
VOID
NTAPI
NdisMAllocateSharedMemoryPassive(
+ PDEVICE_OBJECT DeviceObject,
PVOID Context)
/*
* FUNCTION: Allocate a common buffer
@@ -304,6 +301,7 @@
Memory->Adapter->MiniportAdapterContext, Memory->VirtualAddress,
&Memory->PhysicalAddress, Memory->Length, Memory->Context);
+ IoFreeWorkItem(Memory->WorkItem);
ExFreePool(Memory);
}
@@ -319,7 +317,6 @@
IN BOOLEAN Cached,
IN PVOID Context)
{
- HANDLE ThreadHandle;
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
PMINIPORT_SHARED_MEMORY Memory;
@@ -342,8 +339,18 @@
Memory->Adapter = &Adapter->NdisMiniportBlock;
Memory->Context = Context;
- PsCreateSystemThread(&ThreadHandle, THREAD_ALL_ACCESS, 0, 0, 0,
NdisMAllocateSharedMemoryPassive, Memory);
- ZwClose(ThreadHandle);
+ Memory->WorkItem = IoAllocateWorkItem(Adapter->NdisMiniportBlock.DeviceObject);
+ if (!Memory->WorkItem)
+ {
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
+ ExFreePool(Memory);
+ return NDIS_STATUS_FAILURE;
+ }
+
+ IoQueueWorkItem(Memory->WorkItem,
+ NdisMAllocateSharedMemoryPassive,
+ DelayedWorkQueue,
+ Memory);
return NDIS_STATUS_PENDING;
}