Changeset 36
- Timestamp:
- Nov 5, 2011, 1:45:20 PM (12 years ago)
- Location:
- trunk/Utilities/VirtualHeapPtr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.cpp
r34 r36 72 72 _ATLTRY 73 73 { 74 p[-1] = n ;74 p[-1] = n + 1; 75 75 } 76 76 _ATLCATCHALL() … … 88 88 _ATLTRY 89 89 { 90 p[2] = n ;90 p[2] = n + 1; 91 91 } 92 92 _ATLCATCHALL() -
trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.h
r35 r36 7 7 #pragma once 8 8 9 #include <psapi.h>10 11 #pragma comment(lib, "psapi.lib")12 13 9 //////////////////////////////////////////////////////////// 14 10 // CGlobalVirtualAllocator … … 24 20 m_nPageSize(4 << 10) // 4L 25 21 { 26 PERFORMANCE_INFORMATION Information; 27 ZeroMemory(&Information, sizeof Information); 28 ATLVERIFY(GetPerformanceInfo(&Information, sizeof Information)); 29 m_nPageSize = Information.PageSize; 22 SYSTEM_INFO Information; 23 GetSystemInfo(&Information); 24 m_nPageSize = Information.dwPageSize; 30 25 ATLASSERT(m_nPageSize); 31 26 ATLASSERT(!(m_nPageSize & (m_nPageSize - 1))); … … 171 166 VOID* m_pvData; 172 167 SIZE_T m_nDataSize; 168 VOID* m_pvPaddingData; 169 SIZE_T m_nPaddingDataSize; 173 170 174 171 public: … … 178 175 ATLASSERT(nDataSize > 0); 179 176 const SIZE_T nPageSize = g_GlobalVirtualAllocator.GetPageSize(); 177 const SIZE_T nAlignedDataSize = g_GlobalVirtualAllocator.Align(nDataSize); 180 178 const SIZE_T nAllocationSize = 181 179 g_GlobalVirtualAllocator.Align(sizeof (CDescriptor)) + 182 180 CTraits::g_nHeadSanityPageCount * nPageSize + 183 g_GlobalVirtualAllocator.Align(nDataSize)+181 nAlignedDataSize + 184 182 CTraits::g_nTailSanityPageCount * nPageSize + 185 183 0; … … 189 187 DWORD nCurrentProtection; 190 188 ATLVERIFY(VirtualProtect(pDescriptor, sizeof *pDescriptor, PAGE_READWRITE, &nCurrentProtection)); 191 pDescriptor->Initialize(nAllocationSize, nDataSize); 189 pDescriptor->m_nAllocationSize = nAllocationSize; 190 pDescriptor->m_pvData = (BYTE*) pDescriptor + g_GlobalVirtualAllocator.Align(sizeof *pDescriptor) + CTraits::g_nHeadSanityPageCount * nPageSize; 191 pDescriptor->m_nDataSize = nDataSize; 192 pDescriptor->m_nPaddingDataSize = nAlignedDataSize - nDataSize; 193 pDescriptor->m_pvPaddingData = (BYTE*) pDescriptor->m_pvData + nAlignedDataSize - pDescriptor->m_nPaddingDataSize; 194 ATLVERIFY(VirtualProtect(pDescriptor->m_pvData, pDescriptor->m_nDataSize, PAGE_READWRITE, &nCurrentProtection)); 195 memset(pDescriptor->m_pvPaddingData, 0x77, pDescriptor->m_nPaddingDataSize); 196 ATLVERIFY(VirtualProtect(pDescriptor, sizeof *pDescriptor, PAGE_READONLY, &nCurrentProtection)); 192 197 return pDescriptor; 193 198 } … … 198 203 return pDescriptor; 199 204 } 200 VOID Initialize(SIZE_T nAllocationSize, SIZE_T nDataSize) 201 { 202 const SIZE_T nPageSize = g_GlobalVirtualAllocator.GetPageSize(); 203 m_nAllocationSize = nAllocationSize; 204 m_pvData = (BYTE*) this + g_GlobalVirtualAllocator.Align(sizeof *this) + CTraits::g_nHeadSanityPageCount * nPageSize; 205 m_nDataSize = nDataSize; 206 DWORD nCurrentProtection; 207 ATLVERIFY(VirtualProtect(m_pvData, m_nDataSize, PAGE_READWRITE, &nCurrentProtection)); 208 //ATLASSERT(!IsBadWritePtr(m_pvData, m_nDataSize)); 209 ATLVERIFY(VirtualProtect(this, sizeof *this, PAGE_READONLY, &nCurrentProtection)); 210 } 205 //VOID Initialize() 211 206 VOID Terminate() 212 207 { 208 _ATLTRY 209 { 210 ATLENSURE_THROW(IsPaddingValid(), HRESULT_FROM_WIN32(ERROR_INVALID_DATA)); 211 } 212 _ATLCATCHALL() 213 { 214 } 213 215 ATLVERIFY(VirtualFree(this, 0, MEM_RELEASE)); 214 216 } … … 220 222 { 221 223 return m_nDataSize; 224 } 225 BOOL IsPaddingValid() const throw() 226 { 227 BYTE* pnPaddingData = (BYTE*) m_pvPaddingData; 228 for(SIZE_T nIndex = m_nPaddingDataSize; nIndex > 0; nIndex--, pnPaddingData++) 229 if(*pnPaddingData != 0x77) 230 return FALSE; 231 return TRUE; 222 232 } 223 233 };
Note: See TracChangeset
for help on using the changeset viewer.