2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
5 * PURPOSE: Memory management routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/08-2000 Created
18 NdisAllocateMemoryWithTag(
19 OUT PVOID
*VirtualAddress
,
23 * FUNCTION: Allocates a block of memory, with a 32-bit tag
25 * VirtualAddress = a pointer to the returned memory block
26 * Length = the number of requested bytes
27 * Tag = 32-bit pool tag
34 /* Plain nonpaged memory with tag */
35 Block
= ExAllocatePoolWithTag(NonPagedPool
, Length
, Tag
);
36 *VirtualAddress
= Block
;
38 return NDIS_STATUS_FAILURE
;
40 return NDIS_STATUS_SUCCESS
;
49 NdisCreateLookaheadBufferFromSharedMemory(
50 IN PVOID pSharedMemory
,
51 IN UINT LookaheadLength
,
52 OUT PVOID
*pLookaheadBuffer
)
63 NdisDestroyLookaheadBufferFromSharedMemory(
64 IN PVOID pLookaheadBuffer
)
75 NdisMoveFromMappedMemory(
76 OUT PVOID Destination
,
90 OUT PVOID Destination
,
94 RtlCopyMemory(Destination
,Source
,Length
);
103 NdisMoveToMappedMemory(
104 OUT PVOID Destination
,
117 NdisMUpdateSharedMemory(
118 IN NDIS_HANDLE MiniportAdapterHandle
,
120 IN PVOID VirtualAddress
,
121 IN NDIS_PHYSICAL_ADDRESS PhysicalAddress
)
133 OUT PVOID
*VirtualAddress
,
136 IN NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress
)
138 * FUNCTION: Allocates a block of memory
140 * VirtualAddress = Address of buffer to place virtual
141 * address of the allocated memory
142 * Length = Size of the memory block to allocate
143 * MemoryFlags = Flags to specify special restrictions
144 * HighestAcceptableAddress = Specifies -1
147 if (MemoryFlags
& NDIS_MEMORY_NONCACHED
)
149 *VirtualAddress
= MmAllocateNonCachedMemory(Length
);
151 return NDIS_STATUS_FAILURE
;
153 return NDIS_STATUS_SUCCESS
;
156 if (MemoryFlags
& NDIS_MEMORY_CONTIGUOUS
)
158 *VirtualAddress
= MmAllocateContiguousMemory(Length
, HighestAcceptableAddress
);
160 return NDIS_STATUS_FAILURE
;
162 return NDIS_STATUS_SUCCESS
;
165 /* Plain nonpaged memory */
166 *VirtualAddress
= ExAllocatePool(NonPagedPool
, Length
);
167 if (!*VirtualAddress
)
168 return NDIS_STATUS_FAILURE
;
170 return NDIS_STATUS_SUCCESS
;
180 IN PVOID VirtualAddress
,
184 * FUNCTION: Frees a memory block allocated with NdisAllocateMemory
186 * VirtualAddress = Pointer to the base virtual address of the allocated memory
187 * Length = Size of the allocated memory block as passed to NdisAllocateMemory
188 * MemoryFlags = Memory flags passed to NdisAllocateMemory
191 if (MemoryFlags
& NDIS_MEMORY_NONCACHED
)
193 MmFreeNonCachedMemory(VirtualAddress
, Length
);
197 if (MemoryFlags
& NDIS_MEMORY_CONTIGUOUS
)
199 MmFreeContiguousMemory(VirtualAddress
);
203 ExFreePool(VirtualAddress
);
212 NdisImmediateReadSharedMemory(
213 IN NDIS_HANDLE WrapperConfigurationContext
,
214 IN ULONG SharedMemoryAddress
,
227 NdisImmediateWriteSharedMemory(
228 IN NDIS_HANDLE WrapperConfigurationContext
,
229 IN ULONG SharedMemoryAddress
,
242 NdisMAllocateSharedMemory(
243 IN NDIS_HANDLE MiniportAdapterHandle
,
246 OUT PVOID
*VirtualAddress
,
247 OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress
)
258 NdisMAllocateSharedMemoryAsync(
259 IN NDIS_HANDLE MiniportAdapterHandle
,
266 return NDIS_STATUS_FAILURE
;
275 NdisMFreeSharedMemory(
276 IN NDIS_HANDLE MiniportAdapterHandle
,
279 IN PVOID VirtualAddress
,
280 IN NDIS_PHYSICAL_ADDRESS PhysicalAddress
)