www.pudn.com > PPPOE.rar > memory.h


 
//******************************************************************** 
//	ÈÕÆÚ:	2004/08/24 - 24:8:2004   18:14 
//	Ãûǰ:	tiamo 
//	ÃèÊö:	memory manager 
//********************************************************************* 
 
#pragma once 
 
#ifdef DBG 
	// memory block sig 
	#define MEMORY_BLOCK_SIG					MAKE_SIG('M','B','H','D') 
 
	// memory block header 
	typedef struct __tagMemoryCookie 
	{ 
		LIST_ENTRY								m_ltMemoryBlockAnchor;			// list anchor 
		ULONG									m_ulMemorySig;					// our sig 
		union 
		{ 
			ULONG								m_ulFileName;					// file name 
			UCHAR								m_ucFileName[4]; 
		}; 
		 
		ULONG									m_ulLine;						// line 
		ULONG									m_ulSize;						// size 
		ULONG									m_ulSig;						// sig 
	}MEMORY_BLOCK_HEADER,*PMEMORY_BLOCK_HEADER; 
 
	// public routine 
	extern "C" 
	{ 
		// init memory system,IRQL <= DISPATCH_LEVEL 
		VOID InitializeMemorySystem(); 
 
		// shut down memory system,IRQL <= DISPATCH_LEVEL 
		VOID ShutdownMemorySystem(); 
	} 
 
	// private routine 
	extern "C" 
	{ 
		// helper routine to allocate memory,IRQL <= DISPATCH_LEVEL 
		NDIS_STATUS DebugAllocMemory(PVOID *pVirtualAddress,ULONG ulSize,ULONG ulSig,ULONG ulFile,ULONG ulLine); 
 
		// free memory IRQL <= DISPATCH_LEVEL 
		VOID DebugFreeMemory(PVOID pVirtualAddress,ULONG ulSize); 
	 
		// dump leak, IRQL <= DISPATCH_LEVEL 
		VOID DumpLeak(); 
	} 
 
	// memory block list head 
	extern LIST_ENTRY g_ltMemoryBlocksHead; 
 
	// memory lock 
	extern NDIS_SPIN_LOCK g_lockMemory; 
 
	#define AllocateMemory(out,size,sig)			DebugAllocMemory(out,size,sig,__ulFILE__,__LINE__) 
	#define FreeMemory(p,size)						DebugFreeMemory(p,size) 
#else 
	#define AllocateMemory(out,size,sig)			NdisAllocateMemoryWithTag(out,size,sig) 
	#define FreeMemory(p,size)						NdisFreeMemory(p,size,0) 
#endif