ReactOS  0.4.13-dev-698-g77671f0
mockbuffer.c File Reference
#include "precomp.h"
Include dependency graph for mockbuffer.c:

Go to the source code of this file.

Functions

VOID XNdisGetFirstBufferFromPacket (PNDIS_PACKET Packet, PNDIS_BUFFER *FirstBuffer, PVOID *FirstBufferVA, PUINT FirstBufferLength, PUINT TotalBufferLength)
 
VOID XNdisQueryBuffer (PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
 
__inline INT SkipToOffset (PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
 
UINT CopyBufferToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PCHAR SrcData, UINT Length)
 
UINT CopyBufferChainToBuffer (PCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBuffer (PCHAR DstData, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 
PVOID AdjustPacket (PNDIS_PACKET Packet, UINT Available, UINT Needed)
 
UINT ResizePacket (PNDIS_PACKET Packet, UINT Size)
 
NDIS_STATUS PrependPacket (PNDIS_PACKET Packet, PCHAR Data, UINT Length, BOOLEAN Copy)
 
void GetDataPtr (PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
 
NDIS_STATUS AllocatePacketWithBufferX (PNDIS_PACKET *NdisPacket, PCHAR Data, UINT Len, PCHAR File, UINT Line)
 
VOID FreeNdisPacketX (PNDIS_PACKET Packet, PCHAR File, UINT Line)
 

Function Documentation

◆ AdjustPacket()

PVOID AdjustPacket ( PNDIS_PACKET  Packet,
UINT  Available,
UINT  Needed 
)

Definition at line 334 of file mockbuffer.c.

347 {
348  PNDIS_BUFFER NdisBuffer;
349  INT Adjust;
350 
351  TI_DbgPrint(DEBUG_PBUFFER, ("Available = %d, Needed = %d.\n", Available, Needed));
352 
353  Adjust = Available - Needed;
354 
355  NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
356 
357  /* If Adjust is zero there is no need to adjust this packet as
358  there is no additional space at start the of first buffer */
359  if (Adjust != 0) {
360  NdisBuffer->MappedSystemVa = (PVOID) ((ULONG_PTR)(NdisBuffer->MappedSystemVa) + Adjust);
361  NdisBuffer->ByteOffset += Adjust;
362  NdisBuffer->ByteCount -= Adjust;
363  }
364 
365  return NdisBuffer->MappedSystemVa;
366 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
static LONGLONG Adjust(LONGLONG value, const LONGLONG *pModifier, DWORD dwFlags)
Definition: seeking.c:201
int32_t INT
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define DEBUG_PBUFFER
Definition: debug.h:20
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593

◆ AllocatePacketWithBufferX()

NDIS_STATUS AllocatePacketWithBufferX ( PNDIS_PACKET NdisPacket,
PCHAR  Data,
UINT  Len,
PCHAR  File,
UINT  Line 
)

Definition at line 425 of file mockbuffer.c.

427  {
431  PCHAR NewData;
432 
433  NewData = exAllocatePool( NonPagedPool, Len );
434  if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
435 
436  if( Data )
437  RtlCopyMemory(NewData, Data, Len);
438 
440  if( Status != NDIS_STATUS_SUCCESS ) {
441  exFreePool( NewData );
442  return Status;
443  }
445 
447  if( Status != NDIS_STATUS_SUCCESS ) {
448  exFreePool( NewData );
450  }
452 
454  *NdisPacket = Packet;
455 
456  return NDIS_STATUS_SUCCESS;
457 }
signed char * PCHAR
Definition: retypes.h:7
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:392
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define FreeNdisPacket(x)
Definition: memtrack.h:8
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
#define NDIS_BUFFER_TAG
Definition: lan.h:22
int NDIS_STATUS
Definition: ntddndis.h:445
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:334
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define Len
Definition: deflate.h:82
Definition: ncftp.h:79
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
#define exAllocatePool(x, y)
Definition: memtrack.h:17
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
Status
Definition: gdiplustypes.h:24
#define NDIS_PACKET_TAG
Definition: lan.h:23
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ CopyBufferChainToBuffer()

UINT CopyBufferChainToBuffer ( PCHAR  DstData,
PNDIS_BUFFER  SrcBuffer,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 157 of file mockbuffer.c.

175 {
176  UINT BytesCopied, BytesToCopy, SrcSize;
177  PCHAR SrcData;
178 
179  TI_DbgPrint(DEBUG_PBUFFER, ("DstData 0x%X SrcBuffer 0x%X SrcOffset 0x%X Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
180 
181  /* Skip SrcOffset bytes in the source buffer chain */
182  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
183  return 0;
184 
185  /* Start copying the data */
186  BytesCopied = 0;
187  for (;;) {
188  BytesToCopy = MIN(SrcSize, Length);
189 
190  TI_DbgPrint(DEBUG_PBUFFER, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
191 
192  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
194  DstData = (PCHAR)((ULONG_PTR)DstData + BytesToCopy);
195 
196  Length -= BytesToCopy;
197  if (Length == 0)
198  break;
199 
200  SrcSize -= BytesToCopy;
201  if (SrcSize == 0) {
202  /* No more bytes in source buffer. Proceed to
203  the next buffer in the source buffer chain */
204  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
205  if (!SrcBuffer)
206  break;
207 
208  XNdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
209  }
210  }
211 
212  return BytesCopied;
213 }
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: mockbuffer.c:58
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
#define PCHAR
Definition: match.c:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
unsigned int UINT
Definition: ndis.h:50
VOID XNdisQueryBuffer(PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
Definition: mockbuffer.c:40

Referenced by CopyPacketToBuffer().

◆ CopyBufferToBufferChain()

UINT CopyBufferToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PCHAR  SrcData,
UINT  Length 
)

Definition at line 100 of file mockbuffer.c.

118 {
119  UINT BytesCopied, BytesToCopy, DstSize;
120  PCHAR DstData;
121 
122  TI_DbgPrint(DEBUG_PBUFFER, ("DstBuffer (0x%X) DstOffset (0x%X) SrcData (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
123 
124  /* Skip DstOffset bytes in the destination buffer chain */
125  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
126  return 0;
127 
128  /* Start copying the data */
129  BytesCopied = 0;
130  for (;;) {
131  BytesToCopy = MIN(DstSize, Length);
132 
133  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
135  SrcData = (PCHAR)((ULONG_PTR)SrcData + BytesToCopy);
136 
137  Length -= BytesToCopy;
138  if (Length == 0)
139  break;
140 
141  DstSize -= BytesToCopy;
142  if (DstSize == 0) {
143  /* No more bytes in destination buffer. Proceed to
144  the next buffer in the destination buffer chain */
145  NdisGetNextBuffer(DstBuffer, &DstBuffer);
146  if (!DstBuffer)
147  break;
148 
149  XNdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
150  }
151  }
152 
153  return BytesCopied;
154 }
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: mockbuffer.c:58
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
#define PCHAR
Definition: match.c:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
unsigned int UINT
Definition: ndis.h:50
VOID XNdisQueryBuffer(PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
Definition: mockbuffer.c:40

◆ CopyPacketToBuffer()

UINT CopyPacketToBuffer ( PCHAR  DstData,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 216 of file mockbuffer.c.

234 {
235  PNDIS_BUFFER FirstBuffer;
236  PVOID Address;
237  UINT FirstLength;
239 
240  TI_DbgPrint(DEBUG_PBUFFER, ("DstData (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
241 
243  &FirstBuffer,
244  &Address,
245  &FirstLength,
246  &TotalLength);
247 
248  return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
249 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID XNdisGetFirstBufferFromPacket(PNDIS_PACKET Packet, PNDIS_BUFFER *FirstBuffer, PVOID *FirstBufferVA, PUINT FirstBufferLength, PUINT TotalBufferLength)
Definition: mockbuffer.c:13
MDL * PNDIS_BUFFER
Definition: ndis.h:343
UINT CopyBufferChainToBuffer(PCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
Definition: mockbuffer.c:157
_In_ ULONG TotalLength
Definition: usbdlib.h:145
static WCHAR Address[46]
Definition: ping.c:68
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
unsigned int UINT
Definition: ndis.h:50

◆ CopyPacketToBufferChain()

UINT CopyPacketToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 252 of file mockbuffer.c.

272 {
273  PNDIS_BUFFER SrcBuffer;
274  PCHAR DstData, SrcData;
275  UINT DstSize, SrcSize;
276  UINT Count, Total;
277 
278  TI_DbgPrint(DEBUG_PBUFFER, ("DstBuffer (0x%X) DstOffset (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
279 
280  /* Skip DstOffset bytes in the destination buffer chain */
281  XNdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
282  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
283  return 0;
284 
285  /* Skip SrcOffset bytes in the source packet */
286  XNdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, (PVOID *)&SrcData, &SrcSize, &Total);
287  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
288  return 0;
289 
290  /* Copy the data */
291  for (Total = 0;;) {
292  /* Find out how many bytes we can copy at one time */
293  if (Length < SrcSize)
294  Count = Length;
295  else
296  Count = SrcSize;
297  if (DstSize < Count)
298  Count = DstSize;
299 
300  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
301 
302  Total += Count;
303  Length -= Count;
304  if (Length == 0)
305  break;
306 
307  DstSize -= Count;
308  if (DstSize == 0) {
309  /* No more bytes in destination buffer. Proceed to
310  the next buffer in the destination buffer chain */
311  NdisGetNextBuffer(DstBuffer, &DstBuffer);
312  if (!DstBuffer)
313  break;
314 
315  XNdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
316  }
317 
318  SrcSize -= Count;
319  if (SrcSize == 0) {
320  /* No more bytes in source buffer. Proceed to
321  the next buffer in the source buffer chain */
322  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
323  if (!SrcBuffer)
324  break;
325 
326  XNdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
327  }
328  }
329 
330  return Total;
331 }
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID XNdisGetFirstBufferFromPacket(PNDIS_PACKET Packet, PNDIS_BUFFER *FirstBuffer, PVOID *FirstBufferVA, PUINT FirstBufferLength, PUINT TotalBufferLength)
Definition: mockbuffer.c:13
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: mockbuffer.c:58
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
unsigned int UINT
Definition: ndis.h:50
VOID XNdisQueryBuffer(PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
Definition: mockbuffer.c:40

◆ FreeNdisPacketX()

VOID FreeNdisPacketX ( PNDIS_PACKET  Packet,
PCHAR  File,
UINT  Line 
)

Definition at line 461 of file mockbuffer.c.

469 {
470  PNDIS_BUFFER Buffer, NextBuffer;
471 
472  TI_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
473 
474  /* Free all the buffers in the packet first */
476  for (; Buffer != NULL; Buffer = NextBuffer) {
477  PVOID Data;
478  UINT Length;
479 
480  NdisGetNextBuffer(Buffer, &NextBuffer);
484  exFreePool(Data);
485  }
486 
487  /* Finally free the NDIS packet descriptor */
490 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
VOID EXPORT NdisFreeBuffer(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:809
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
Definition: bufpool.h:45
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:826
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
Definition: ncftp.h:79
unsigned int UINT
Definition: ndis.h:50
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
VOID XNdisQueryBuffer(PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
Definition: mockbuffer.c:40
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ GetDataPtr()

void GetDataPtr ( PNDIS_PACKET  Packet,
UINT  Offset,
PCHAR DataOut,
PUINT  Size 
)

Definition at line 414 of file mockbuffer.c.

417  {
419 
421  if( !Buffer ) return;
422  SkipToOffset( Buffer, Offset, DataOut, Size );
423 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: mockbuffer.c:58
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by AddGenericHeaderIPv4(), LANTransmit(), LANTransmitInternal(), LoopTransmit(), PrepareARPPacket(), PrepareICMPPacket(), ProtocolReceive(), SendFragments(), SendPacket(), and TCPSendDataCallback().

◆ PrependPacket()

NDIS_STATUS PrependPacket ( PNDIS_PACKET  Packet,
PCHAR  Data,
UINT  Length,
BOOLEAN  Copy 
)

Definition at line 394 of file mockbuffer.c.

395  {
398  PCHAR NewBuf;
399 
400  if( Copy ) {
401  NewBuf = PoolAllocateBuffer( Length );
402  if( !NewBuf ) return STATUS_NO_MEMORY;
403  RtlCopyMemory( NewBuf, Data, Length );
404  } else NewBuf = Data;
405 
407  if( Status != NDIS_STATUS_SUCCESS ) return Status;
408 
410 
411  return STATUS_SUCCESS;
412 }
signed char * PCHAR
Definition: retypes.h:7
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
PVOID PoolAllocateBuffer(ULONG Size)
Definition: mockpool.c:13
int NDIS_STATUS
Definition: ntddndis.h:445
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
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:334
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
Status
Definition: gdiplustypes.h:24
VOID Copy(PVOID Src, PVOID Dst, ULONG NumBytes)
Definition: mmixer.c:131
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2777

◆ ResizePacket()

UINT ResizePacket ( PNDIS_PACKET  Packet,
UINT  Size 
)

Definition at line 369 of file mockbuffer.c.

380 {
381  PNDIS_BUFFER NdisBuffer;
382  UINT OldSize;
383 
384  NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
385 
386  OldSize = NdisBuffer->ByteCount;
387 
388  if (Size != OldSize)
389  NdisBuffer->ByteCount = Size;
390 
391  return OldSize;
392 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
smooth NULL
Definition: ftsmooth.c:416
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
unsigned int UINT
Definition: ndis.h:50
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593

◆ SkipToOffset()

__inline INT SkipToOffset ( PNDIS_BUFFER  Buffer,
UINT  Offset,
PCHAR Data,
PUINT  Size 
)

Definition at line 58 of file mockbuffer.c.

77 {
78  for (;;) {
79 
80  if (!Buffer)
81  return -1;
82 
84 
85  if (Offset < *Size) {
86  *Data = (PCHAR)((ULONG_PTR) *Data + Offset);
87  *Size -= Offset;
88  break;
89  }
90 
91  Offset -= *Size;
92 
94  }
95 
96  return Offset;
97 }
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
#define PCHAR
Definition: match.c:90
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
VOID XNdisQueryBuffer(PNDIS_BUFFER Buffer, PVOID *VirtualAddress, PUINT Length)
Definition: mockbuffer.c:40

Referenced by CopyBufferChainToBuffer(), CopyBufferToBufferChain(), CopyPacketToBufferChain(), and GetDataPtr().

◆ XNdisGetFirstBufferFromPacket()

VOID XNdisGetFirstBufferFromPacket ( PNDIS_PACKET  Packet,
PNDIS_BUFFER FirstBuffer,
PVOID FirstBufferVA,
PUINT  FirstBufferLength,
PUINT  TotalBufferLength 
)

Definition at line 13 of file mockbuffer.c.

18 {
19  PNDIS_BUFFER _Buffer;
20 
21  _Buffer = (Packet)->Private.Head;
22  *(FirstBuffer) = _Buffer;
23  *(FirstBufferVA) = MmGetMdlVirtualAddress(_Buffer);
24  if (_Buffer != NULL) {
25  *(FirstBufferLength) = MmGetMdlByteCount(_Buffer);
26  _Buffer = _Buffer->Next;
27  } else
28  *(FirstBufferLength) = 0;
29  *(TotalBufferLength) = *(FirstBufferLength);
30  while (_Buffer != NULL) {
31  *(TotalBufferLength) += MmGetMdlByteCount(_Buffer);
32  _Buffer = _Buffer->Next;
33  }
34 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define MmGetMdlVirtualAddress(_Mdl)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
smooth NULL
Definition: ftsmooth.c:416
#define MmGetMdlByteCount(_Mdl)

Referenced by CopyPacketToBuffer(), and CopyPacketToBufferChain().

◆ XNdisQueryBuffer()

VOID XNdisQueryBuffer ( PNDIS_BUFFER  Buffer,
PVOID VirtualAddress,
PUINT  Length 
)

Definition at line 40 of file mockbuffer.c.

51 {
52  if (VirtualAddress != NULL)
53  *(PVOID*)VirtualAddress = Buffer->MappedSystemVa;
54 
55  *Length = ((PMDL)Buffer)->ByteCount;
56 }
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1060
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CopyBufferChainToBuffer(), CopyBufferToBufferChain(), CopyPacketToBufferChain(), FreeNdisPacketX(), and SkipToOffset().