/* | |
* Copyright (c) 2011 Nokia and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Nokia - Initial API and implementation | |
*/ | |
/* WinHWPageProtMgr.h | |
* | |
* Created on: Aug 23, 2011 | |
* Author: bkirk | |
*/ | |
#ifndef WINHWPAGEPROTMGR_H_ | |
#define WINHWPAGEPROTMGR_H_ | |
#include <map> | |
#include "TCFContext.h" | |
#define MAX_HWBP 4 | |
struct TBreakpoint; | |
class WinHWPageProtMgr { | |
friend class WinProcess; | |
friend class WinThread; | |
WinHWPageProtMgr(); | |
int SetPageProtectWatchpoint(TBreakpoint*); | |
int ClearPageProtectWatchpoint(TBreakpoint*); | |
struct ProtectedPage { | |
LPVOID baseAddr; | |
DWORD size; | |
DWORD origProtectMode; | |
DWORD protectMode; | |
unsigned char refCount; | |
ProtectedPage(const LPVOID& inBaseAddr, const DWORD& inSize, | |
const DWORD& inOrigProtect, const DWORD& newProtect) | |
: baseAddr(inBaseAddr), size(inSize), origProtectMode(inOrigProtect), | |
protectMode(newProtect), refCount(1) | |
{} | |
inline void AddRef() { ++refCount; } | |
inline unsigned char DecRef() { return --refCount; } | |
}; | |
bool IsAddressInProtectedPage(const ContextAddress& addr); | |
TBreakpoint* FindWatchpointForAddress(const HANDLE& procH, | |
const ContextAddress&); | |
int ProtectPageForWatchpointAddress(const HANDLE& procHandle, | |
const ContextAddress&, const size_t, const DWORD mode); | |
int UnProtectPageForWatchpoint(const TBreakpoint*); | |
int ChangePageProtection(const HANDLE& procH, const TBreakpoint*, | |
ProtectedPage&); | |
int EnableForPagesContainingAddress(const HANDLE& procH, | |
const ContextAddress&, const DWORD size = 0, | |
const DWORD mode = PAGE_NOACCESS); | |
int DisableForPagesContainingAddress(const HANDLE& procH, | |
const ContextAddress&, const DWORD size = 0, | |
const DWORD mode = PAGE_NOACCESS); | |
typedef std::map<ContextAddress, ProtectedPage> ProtectedPages; | |
typedef std::map<ContextAddress, TBreakpoint*> ProtectedPageWatchpoints; | |
typedef std::pair<ContextAddress, ProtectedPage> AddressPagePair; | |
typedef std::pair<ContextAddress, TBreakpoint*> AddressWatchpointPair; | |
ProtectedPages protectedPages; | |
ProtectedPageWatchpoints watchpoints; | |
static DWORD sPageProtModeMap(unsigned char i); | |
}; | |
#endif /* WINHWPAGEPROTMGR_H_ */ |