source: trunk/Utilities/VirtualHeapPtr/VirtualHeapPtr.cpp @ 42

Last change on this file since 42 was 41, checked in by roman, 12 years ago
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2011
3// Created by Roman Ryltsov roman@alax.info
4//
5// $Id: VirtualHeapPtr.cpp 41 2011-11-19 17:20:45Z roman $
6
7#include "stdafx.h"
8#include "VirtualHeapPtr.h"
9
10////////////////////////////////////////////////////////////
11// Main
12
13int _tmain(int argc, _TCHAR* argv[])
14{
15        _tprintf(_T("g_GlobalVirtualAllocator.GetPageSize() %d\n\n"), g_GlobalVirtualAllocator.GetPageSize());
16        CDebugHeapPtr<BYTE> p;
17        p.Allocate(1);
18        p[0] = 0x01;
19        _tprintf(_T("p[0] 0x%02X\n"), p[0]);
20        ATLVERIFY(p.Reallocate(2));
21        p[1] = 0x02;
22        _tprintf(_T("p[0] 0x%02X, p[1] 0x%02X\n"), p[0], p[1]);
23        p[0] = 0x03;
24        _tprintf(_T("p[0] 0x%02X, p[1] 0x%02X\n"), p[0], p[1]);
25        #pragma region PAGE_READONLY
26        //if(FALSE)
27        {
28                p.SetProtection(PAGE_READONLY);
29                _ATLTRY
30                {
31                        p[1] = 0x04;
32                        _tprintf(_T("p[0] 0x%02X, p[1] 0x%02X\n"), p[0], p[1]);
33                }
34                _ATLCATCHALL()
35                {
36                        _tprintf(_T("Oopsie in line %d (Failed to write to PAGE_READONLY memory)\n"), __LINE__);
37                }
38                p.SetProtection(PAGE_READWRITE);
39                p[1] = 0x05;
40                _tprintf(_T("p[0] 0x%02X, p[1] 0x%02X\n"), p[0], p[1]);
41        }
42        #pragma endregion
43        volatile BYTE n;
44        //if(FALSE)
45        {
46                p.SetProtection(PAGE_READWRITE | PAGE_GUARD);
47                #pragma region PAGE_GUARD
48                _ATLTRY
49                {
50                        n = p[0];
51                }
52                _ATLCATCHALL()
53                {
54                        _tprintf(_T("Oopsie in line %d (First PAGE_GUARD access)\n"), __LINE__);
55                }
56                _ATLTRY
57                {
58                        n = p[1];
59                }
60                _ATLCATCHALL()
61                {
62                        _tprintf(_T("Oopsie in line %d (Second PAGE_GUARD access)\n"), __LINE__);
63                }
64        }
65        #pragma endregion
66        #pragma region Invalid Index
67        _ATLTRY
68        {
69                n = p[-1];
70        }
71        _ATLCATCHALL()
72        {
73                _tprintf(_T("Oopsie in line %d (Reading with a too small index)\n"), __LINE__);
74        }
75        _ATLTRY
76        {
77                p[-1] = n + 1;
78        }
79        _ATLCATCHALL()
80        {
81                _tprintf(_T("Oopsie in line %d (Writing with a too small index)\n"), __LINE__);
82        }
83        _ATLTRY
84        {
85                n = p[2];
86        }
87        _ATLCATCHALL()
88        {
89                _tprintf(_T("Oopsie in line %d (Reading with a too large index)\n"), __LINE__);
90        }
91        _ATLTRY
92        {
93                p[2] = n + 1;
94        }
95        _ATLCATCHALL()
96        {
97                _tprintf(_T("Oopsie in line %d (Writing with a too large index)\n"), __LINE__);
98        }
99        #pragma endregion
100        return 0;
101}
102
Note: See TracBrowser for help on using the repository browser.