ReactOS 0.4.15-dev-7674-gc0b4db1
misc.c File Reference
#include "ndisuio.h"
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NDIS_STATUS AllocateAndChainBuffer (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDIS_PACKET Packet, PVOID Buffer, ULONG BufferSize, BOOLEAN Front)
 
PNDIS_PACKET CreatePacketFromPoolBuffer (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PVOID Buffer, ULONG BufferSize)
 
VOID CleanupAndFreePacket (PNDIS_PACKET Packet, BOOLEAN FreePool)
 
PNDISUIO_ADAPTER_CONTEXT FindAdapterContextByName (PNDIS_STRING DeviceName)
 
VOID ReferenceAdapterContext (PNDISUIO_ADAPTER_CONTEXT AdapterContext)
 
VOID DereferenceAdapterContextWithOpenEntry (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDISUIO_OPEN_ENTRY OpenEntry)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file misc.c.

Function Documentation

◆ AllocateAndChainBuffer()

NDIS_STATUS AllocateAndChainBuffer ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PNDIS_PACKET  Packet,
PVOID  Buffer,
ULONG  BufferSize,
BOOLEAN  Front 
)

Definition at line 15 of file misc.c.

20{
22 PNDIS_BUFFER NdisBuffer;
23
24 /* Allocate the NDIS buffer mapping the pool */
26 &NdisBuffer,
27 AdapterContext->BufferPoolHandle,
28 Buffer,
31 {
32 DPRINT1("No free buffer descriptors\n");
33 return Status;
34 }
35
36 if (Front)
37 {
38 /* Chain the buffer to front */
39 NdisChainBufferAtFront(Packet, NdisBuffer);
40 }
41 else
42 {
43 /* Chain the buffer to back */
44 NdisChainBufferAtBack(Packet, NdisBuffer);
45 }
46
47 /* Return success */
49}
#define DPRINT1
Definition: precomp.h:8
Definition: bufpool.h:45
VOID EXPORT NdisAllocateBuffer(OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: buffer.c:336
Status
Definition: gdiplustypes.h:25
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NdisChainBufferAtBack(Packet, Buffer)
Definition: ndis.h:3128
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
int NDIS_STATUS
Definition: ntddndis.h:475
NDIS_HANDLE BufferPoolHandle
Definition: ndisuio.h:34
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by CreatePacketFromPoolBuffer().

◆ CleanupAndFreePacket()

VOID CleanupAndFreePacket ( PNDIS_PACKET  Packet,
BOOLEAN  FreePool 
)

Definition at line 83 of file misc.c.

84{
86 PVOID Data;
88
89 /* Free each buffer and its backing pool memory */
90 while (TRUE)
91 {
92 /* Unchain each buffer */
94 if (!Buffer)
95 break;
96
97 /* Get the backing memory */
99
100 /* Free the buffer */
102
103 if (FreePool)
104 {
105 /* Free the backing memory */
107 }
108 }
109
110 /* Free the packet descriptor */
112}
#define TRUE
Definition: types.h:120
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:828
VOID EXPORT NdisUnchainBufferAtFront(IN OUT PNDIS_PACKET Packet, OUT PNDIS_BUFFER *Buffer)
Definition: buffer.c:1069
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define FreePool(P)
Definition: mntmgr.h:154
#define NdisFreeBuffer
Definition: ndis.h:2895
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint32_t ULONG
Definition: typedefs.h:59

Referenced by NduDispatchWrite(), and NduReceive().

◆ CreatePacketFromPoolBuffer()

PNDIS_PACKET CreatePacketFromPoolBuffer ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PVOID  Buffer,
ULONG  BufferSize 
)

Definition at line 52 of file misc.c.

55{
58
59 /* Allocate a packet descriptor */
61 &Packet,
62 AdapterContext->PacketPoolHandle);
64 {
65 DPRINT1("No free packet descriptors\n");
66 return NULL;
67 }
68
69 /* Use the helper to chain the buffer */
70 Status = AllocateAndChainBuffer(AdapterContext, Packet,
73 {
75 return NULL;
76 }
77
78 /* Return the packet */
79 return Packet;
80}
#define NULL
Definition: types.h:112
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:394
NDIS_STATUS AllocateAndChainBuffer(PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDIS_PACKET Packet, PVOID Buffer, ULONG BufferSize, BOOLEAN Front)
Definition: misc.c:15
NDIS_HANDLE PacketPoolHandle
Definition: ndisuio.h:33

Referenced by NduDispatchWrite(), and NduReceive().

◆ DereferenceAdapterContextWithOpenEntry()

VOID DereferenceAdapterContextWithOpenEntry ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PNDISUIO_OPEN_ENTRY  OpenEntry 
)

Definition at line 149 of file misc.c.

151{
153
154 /* Lock the adapter context */
155 KeAcquireSpinLock(&AdapterContext->Spinlock, &OldIrql);
156
157 /* Decrement the open count */
158 AdapterContext->OpenCount--;
159
160 /* Cleanup the open entry if we were given one */
161 if (OpenEntry != NULL)
162 {
163 /* Remove the open entry */
164 RemoveEntryList(&OpenEntry->ListEntry);
165
166 /* Invalidate the FO */
167 OpenEntry->FileObject->FsContext = NULL;
168 OpenEntry->FileObject->FsContext2 = NULL;
169
170 /* Free the open entry */
171 ExFreePool(OpenEntry);
172 }
173
174 /* Release the adapter context lock */
175 KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
176}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK Spinlock
Definition: ndisuio.h:50
LIST_ENTRY ListEntry
Definition: ndisuio.h:62
PFILE_OBJECT FileObject
Definition: ndisuio.h:56
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by NduDispatchClose(), and OpenDeviceReadWrite().

◆ FindAdapterContextByName()

PNDISUIO_ADAPTER_CONTEXT FindAdapterContextByName ( PNDIS_STRING  DeviceName)

Definition at line 115 of file misc.c.

116{
118 PLIST_ENTRY CurrentEntry;
119 PNDISUIO_ADAPTER_CONTEXT AdapterContext;
120
122 CurrentEntry = GlobalAdapterList.Flink;
123 while (CurrentEntry != &GlobalAdapterList)
124 {
125 AdapterContext = CONTAINING_RECORD(CurrentEntry, NDISUIO_ADAPTER_CONTEXT, ListEntry);
126
127 /* Check if the device name matches */
128 if (RtlEqualUnicodeString(&AdapterContext->DeviceName, DeviceName, TRUE))
129 {
131 return AdapterContext;
132 }
133
134 CurrentEntry = CurrentEntry->Flink;
135 }
137
138 return NULL;
139}
LIST_ENTRY GlobalAdapterList
Definition: main.c:17
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UNICODE_STRING DeviceName
Definition: ndisuio.h:44
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

Referenced by OpenDeviceReadWrite().

◆ ReferenceAdapterContext()

VOID ReferenceAdapterContext ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext)

Definition at line 142 of file misc.c.

143{
144 /* Increment the open count */
145 AdapterContext->OpenCount++;
146}

Referenced by OpenDeviceReadWrite().