/******************************************************************* * * File : util.cxx * Author : Eyal Schwartz * Copyrights : Microsoft Corp (C) 1996 * Date : 7/21/1998 * Description : * * Revisions : *******************************************************************/ #ifndef UTIL_CXX #define UTIL_CXX // include // #include "common.h" #include "util.hxx" // defines // #define DNSEXT_CUSTOMER_CODE 0xD0000000 #define STACK_OVERFLOW STATUS_STACK_OVERFLOW | DNSEXT_CUSTOMER_CODE // types // // global variables // PVOID gAllocationStack[MAXLIST]; // local variables // static INT iStackSize=0; // prototypes // PVOID ReadMemory( IN PVOID pvAddr, IN DWORD dwSize); VOID FreeMemory( IN PVOID pv); // functions // PVOID PushMemory( IN PVOID pvAddr, IN DWORD dwSize) /*++ Routine Description: Shells on read memory to remember the pointer in a local stack Arguments: pvAddr - Address of memory block to read in the address space of the process being debugged. dwSize - Count of bytes to read/allocate/copy. Return Value: Pointer to debugger local memory. --*/ { if(iStackSize == MAXLIST-1){ Printf("Exception: No more allocation stack memory\n"); RaiseException(STACK_OVERFLOW, 0, 0, NULL); } PVOID pv = ReadMemory(pvAddr, dwSize); if(!pv){ Printf("Exception: No memory\n"); RaiseException(STACK_OVERFLOW, 0, 0, NULL); } return gAllocationStack[iStackSize++] = pv; } VOID PopMemory( IN PVOID pv) /*++ Routine Description: Frees memory returned by PushMemory. Arguments: pv - Address of debugger local memory to free. Return Value: None. --*/ { FreeMemory(pv); if(0 == iStackSize){ Printf("Exception: Invalid stack operation (iStackSize == 0).\n"); RaiseException(STACK_OVERFLOW, 0, 0, NULL); } gAllocationStack[iStackSize--] = NULL; } VOID CleanMemory( VOID) /*++ Routine Description: Frees all stack memory returned by PushMemory. Arguments: Return Value: None. --*/ { for (INT i=0; i ( DWORD ) cRead ) ? dwSize - ( DWORD ) cRead : ( DWORD ) cRead - dwSize ); return(NULL); } return(pv); } VOID FreeMemory( IN PVOID pv) /*++ Routine Description: Frees memory returned by ReadMemory. Arguments: pv - Address of debugger local memory to free. Return Value: None. --*/ { DEBUG1("HeapFree(%p)\n", pv); if ( NULL != pv ) { if ( !HeapFree(GetProcessHeap(), 0, pv) ) { Printf("Error %x freeing memory at %p\n", GetLastError(), pv); } } } #endif /******************* EOF *********************/