Name | Executed | Routines | % | Executed | Lines | % | Unexecuted |
/home/matt/eu/rds/include/std/memconst.e | 5 | 5 | 100.00% | 43 | 43 | 100.00% | 0 |
Routine | Executed | Lines | Unexecuted | |
test_exec() | 3 | 3 | 100.00% | 0 |
test_read() | 3 | 3 | 100.00% | 0 |
test_write() | 3 | 3 | 100.00% | 0 |
valid_memory_protection_constant() | 2 | 2 | 100.00% | 0 |
valid_wordsize() | 2 | 2 | 100.00% | 0 |
# | Executed | |
1 | namespace memconst | |
2 | ||
3 | --**** | |
4 | -- === Microsoft Windows Memory Protection Constants === @[microsoftsmemoryprotectionconstants] | |
5 | -- These constant names are taken right from Microsoft's Memory Protection constants. | |
6 | ||
7 | 101 | ifdef WIN32 then |
8 | --** | |
9 | -- You may run the data in this page | |
10 | public constant PAGE_EXECUTE = #10 | |
11 | ||
12 | --** | |
13 | -- You may read or run the data | |
14 | public constant PAGE_EXECUTE_READ = #20 | |
15 | ||
16 | --** | |
17 | -- You may run, read or write in this page | |
18 | public constant PAGE_EXECUTE_READWRITE = #40 | |
19 | ||
20 | --** | |
21 | -- You may run or write in this page | |
22 | public constant PAGE_EXECUTE_WRITECOPY = #80 | |
23 | ||
24 | --** | |
25 | -- You may write to this page. | |
26 | public constant PAGE_WRITECOPY = #08 | |
27 | ||
28 | --** | |
29 | -- You may read or write in this page. | |
30 | public constant PAGE_READWRITE = #04 | |
31 | ||
32 | --** | |
33 | -- You may only read data in this page | |
34 | public constant PAGE_READONLY = #02 | |
35 | ||
36 | --** | |
37 | -- You have no access to this page | |
38 | public constant PAGE_NOACCESS = #01 | |
39 | ||
40 | ||
41 | elsedef | |
42 | ||
43 | constant | |
44 | 101 | PROT_EXEC = 4, |
45 | 101 | PROT_READ = 1, |
46 | 101 | PROT_WRITE = 2, |
47 | 101 | PROT_NONE = 0 |
48 | ||
49 | 101 | public constant PAGE_EXECUTE = PROT_EXEC, |
50 | 101 | PAGE_EXECUTE_READ = or_bits( PROT_READ, PROT_EXEC ), |
51 | 101 | PAGE_EXECUTE_READWRITE = or_bits( PROT_READ, or_bits( PROT_EXEC, PROT_WRITE ) ), |
52 | 101 | PAGE_EXECUTE_WRITECOPY = or_bits( PROT_READ, or_bits( PROT_EXEC, PROT_WRITE ) ), |
53 | 101 | PAGE_WRITECOPY = or_bits( PROT_READ, PROT_WRITE ), |
54 | 101 | PAGE_READWRITE = or_bits( PROT_READ, PROT_WRITE ), |
55 | 101 | PAGE_READONLY = PROT_READ, |
56 | 101 | PAGE_NOACCESS = PROT_NONE |
57 | ||
58 | end ifdef | |
59 | ||
60 | --**** | |
61 | -- === Standard Library Memory Protection Constants === @[stardardlibrarymemoryprotectionconstants] | |
62 | -- | |
63 | -- | |
64 | -- Memory Protection Constants are the same constants names and meaning | |
65 | -- across all platforms yet possibly of different numeric value. | |
66 | -- They are only necessary for [[:allocate_protect]] | |
67 | -- | |
68 | -- The constant names are created like this: You have four aspects of protection | |
69 | -- READ, WRITE, EXECUTE and COPY. | |
70 | -- You take the word PAGE and you concatonate an underscore and the aspect | |
71 | -- in the order above. For example: PAGE_WRITE_EXECUTE | |
72 | -- The sole exception to this nomenclature is when you will have no acesss to the page the | |
73 | -- constant is called PAGE_NOACCESS. | |
74 | ||
75 | --** | |
76 | -- You have no access to this page | |
77 | -- An alias to PAGE_NOACCESS | |
78 | 101 | public constant PAGE_NONE = PAGE_NOACCESS |
79 | ||
80 | --** | |
81 | -- You may read or run the data | |
82 | -- An alias to PAGE_EXECUTE_READ | |
83 | 101 | public constant PAGE_READ_EXECUTE = PAGE_EXECUTE_READ |
84 | ||
85 | --** | |
86 | -- You may read or write to this page | |
87 | -- An alias to PAGE_READWRITE | |
88 | 101 | public constant PAGE_READ_WRITE = PAGE_READWRITE |
89 | ||
90 | --** | |
91 | -- You may only read to this page | |
92 | -- An alias to PAGE_READONLY | |
93 | 101 | public constant PAGE_READ = PAGE_READONLY |
94 | ||
95 | --** | |
96 | -- You may run, read or write in this page | |
97 | -- An alias to PAGE_EXECUTE_READWRITE | |
98 | 101 | public constant PAGE_READ_WRITE_EXECUTE = PAGE_EXECUTE_READWRITE |
99 | ||
100 | --** | |
101 | -- You may run or write to this page. Data | |
102 | -- will copied for use with other processes when | |
103 | -- you first write to it. | |
104 | 101 | public constant PAGE_WRITE_EXECUTE_COPY = PAGE_EXECUTE_WRITECOPY |
105 | ||
106 | --** | |
107 | -- You may write to this page. Data | |
108 | -- will copied for use with other processes when | |
109 | -- you first write to it. | |
110 | 101 | public constant PAGE_WRITE_COPY = PAGE_WRITECOPY |
111 | ||
112 | ||
113 | ||
114 | ||
115 | 101 | export constant MEMORY_PROTECTION = { |
116 | PAGE_EXECUTE, | |
117 | PAGE_EXECUTE_READ, | |
118 | PAGE_EXECUTE_READWRITE, | |
119 | PAGE_EXECUTE_WRITECOPY, | |
120 | PAGE_WRITECOPY, | |
121 | PAGE_READWRITE, | |
122 | PAGE_READONLY, | |
123 | PAGE_NOACCESS | |
124 | } | |
125 | ||
126 | 130 | |
127 | 130 | return 0 != find( x, MEMORY_PROTECTION ) |
128 | end type | |
129 | ||
130 | ||
131 | 30 | |
132 | -- does this protection allow for reading? | |
133 | 30 | ifdef UNIX then |
134 | -- take advantage of the use of bit fields in UNIX for protections | |
135 | 30 | return and_bits(PROT_READ,protection) != 0 |
136 | elsedef | |
137 | return find( protection, { PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, | |
138 | PAGE_READWRITE, PAGE_READONLY } ) | |
139 | end ifdef | |
140 | end function | |
141 | ||
142 | ||
143 | 30 | |
144 | -- does this protection allow for writing? | |
145 | 30 | ifdef UNIX then |
146 | -- take advantage of the use of bit fields in UNIX for protections | |
147 | 30 | return and_bits(PROT_WRITE,protection) != 0 |
148 | elsedef | |
149 | return find( protection, { PAGE_EXECUTE_READWRITE, | |
150 | PAGE_EXECUTE_WRITECOPY, | |
151 | PAGE_WRITECOPY, | |
152 | PAGE_READWRITE}) | |
153 | end ifdef | |
154 | end function | |
155 | ||
156 | 12 | |
157 | -- does this protection allow for executing? | |
158 | 12 | ifdef UNIX then |
159 | -- take advantage of the use of bit fields in UNIX for protections | |
160 | 12 | return and_bits(PROT_EXEC,protection) != 0 |
161 | elsedef | |
162 | return find(protection,{PAGE_EXECUTE, | |
163 | PAGE_EXECUTE_READ, | |
164 | PAGE_EXECUTE_READWRITE, | |
165 | PAGE_EXECUTE_WRITECOPY}) | |
166 | end ifdef | |
167 | end function | |
168 | ||
169 | ||
170 | 23 | |
171 | 23 | return find(i, {1,2,4})!=0 |
172 | end type | |
173 | ||
174 | 101 | export integer DEP_really_works = 0 |
175 | 101 | export integer use_DEP = 1 |
176 | ||
177 | -- Windows constants | |
178 | 101 | export constant MEM_COMMIT = #1000, |
179 | 101 | MEM_RESERVE = #2000, |
180 | 101 | MEM_RESET = #80000, |
181 | 101 | MEM_RELEASE = #8000 |
182 | ||
183 | export integer FREE_RID | |
184 | ||
185 | 101 | public enum A_READ = 1, A_WRITE = 2, A_EXECUTE = 3 |
186 | ||
187 | export constant | |
188 | 101 | M_ALLOC = 16, |
189 | 101 | M_FREE = 17 |
190 | ||
191 | export atom kernel_dll, memDLL_id, | |
192 | VirtualAlloc_rid, VirtualLock_rid, VirtualUnlock_rid, | |
193 | VirtualProtect_rid, GetLastError_rid, GetSystemInfo_rid |