c33f0561a6d7e6c3fded4916c50c54dda15643dc
[reactos.git] / rostests / kmtests / rtl / RtlMemory.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Runtime library memory functions test
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6 */
7
8 #include <stddef.h>
9 __declspec(dllimport) void __stdcall RtlMoveMemory(void *, const void *, size_t);
10 __declspec(dllimport) void __stdcall RtlFillMemory(void *, size_t, unsigned char);
11
12 #define KMT_EMULATE_KERNEL
13 #include <kmt_test.h>
14
15 #ifdef __GNUC__
16 #pragma GCC diagnostic ignored "-Wnonnull"
17 #endif /* defined __GNUC__ */
18
19 static
20 VOID
21 MakeBuffer(
22 OUT PVOID Buffer,
23 ...)
24 {
25 PUCHAR OutBuffer = Buffer;
26 INT Count;
27 INT Value;
28 va_list Arguments;
29
30 va_start(Arguments, Buffer);
31
32 while (1)
33 {
34 Count = va_arg(Arguments, INT);
35 if (!Count)
36 break;
37 ASSERT(Count > 0);
38
39 Value = va_arg(Arguments, INT);
40 while (Count--)
41 *OutBuffer++ = Value;
42 }
43
44 va_end(Arguments);
45 }
46
47 static
48 BOOLEAN
49 CheckBuffer(
50 IN const VOID *Buffer,
51 ...)
52 {
53 PCUCHAR OutBuffer = Buffer;
54 INT Count;
55 INT Value;
56 va_list Arguments;
57
58 va_start(Arguments, Buffer);
59
60 while (1)
61 {
62 Count = va_arg(Arguments, INT);
63 if (!Count)
64 break;
65 ASSERT(Count > 0);
66
67 Value = va_arg(Arguments, INT);
68 while (Count--)
69 if (*OutBuffer++ != Value)
70 {
71 --OutBuffer;
72 trace("CheckBuffer failed at offset %d, value %x, expected %x\n", OutBuffer - (PCUCHAR)Buffer, *OutBuffer, Value);
73 return FALSE;
74 }
75 }
76
77 va_end(Arguments);
78 return TRUE;
79 }
80
81 static
82 VOID
83 MakePattern(
84 OUT PVOID Buffer,
85 ...)
86 {
87 PUCHAR OutBuffer = Buffer;
88 INT Count, Repeat, i;
89 INT Values[16];
90 va_list Arguments;
91
92 va_start(Arguments, Buffer);
93
94 while (1)
95 {
96 Count = va_arg(Arguments, INT);
97 if (!Count)
98 break;
99 ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
100
101 Repeat = va_arg(Arguments, INT);
102 ASSERT(Repeat > 0);
103
104 for (i = 0; i < Count; ++i)
105 Values[i] = va_arg(Arguments, INT);
106
107 while (Repeat--)
108 for (i = 0; i < Count; ++i)
109 *OutBuffer++ = Values[i];
110 }
111
112 va_end(Arguments);
113 }
114
115 static
116 BOOLEAN
117 CheckPattern(
118 IN const VOID *Buffer,
119 ...)
120 {
121 PCUCHAR OutBuffer = Buffer;
122 INT Count, Repeat, i;
123 INT Values[16];
124 va_list Arguments;
125
126 va_start(Arguments, Buffer);
127
128 while (1)
129 {
130 Count = va_arg(Arguments, INT);
131 if (!Count)
132 break;
133 ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
134
135 Repeat = va_arg(Arguments, INT);
136 ASSERT(Repeat > 0);
137
138 for (i = 0; i < Count; ++i)
139 Values[i] = va_arg(Arguments, INT);
140
141 while (Repeat--)
142 for (i = 0; i < Count; ++i)
143 if (*OutBuffer++ != Values[i])
144 {
145 --OutBuffer;
146 trace("CheckPattern failed at offset %d, value %x, expected %x\n", OutBuffer - (PCUCHAR)Buffer, *OutBuffer, Values[i]);
147 return FALSE;
148 }
149 }
150
151 va_end(Arguments);
152 return TRUE;
153 }
154
155 START_TEST(RtlMemory)
156 {
157 NTSTATUS Status;
158 UCHAR Buffer[513];
159 const SIZE_T Size = 512;
160 const SIZE_T HalfSize = Size / 2;
161 SIZE_T RetSize;
162 KIRQL Irql;
163 ULONG i;
164
165 KeRaiseIrql(HIGH_LEVEL, &Irql);
166 /* zero everything behind 'Size'. Tests will check that this wasn't changed.
167 * TODO: use guarded memory for this! */
168 MakeBuffer(Buffer + Size, sizeof Buffer - Size, 0, 0);
169
170 /* test our helper functions first */
171 MakeBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 0);
172 for (i = 0; i < HalfSize; ++i)
173 ok_eq_uint(Buffer[i], 0x55);
174 for (i = HalfSize; i < Size; ++i)
175 ok_eq_uint(Buffer[i], 0xAA);
176 ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
177
178 MakePattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0);
179 for (i = 0; i < 60; i += 3)
180 {
181 ok_eq_uint(Buffer[i+0], 0x11);
182 ok_eq_uint(Buffer[i+1], 0x22);
183 ok_eq_uint(Buffer[i+2], 0x33);
184 }
185 for (i = 60; i < 64; ++i)
186 ok_eq_uint(Buffer[i], 0x44);
187 for (i = 64; i < HalfSize; ++i)
188 ok_eq_uint(Buffer[i], 0x55);
189 for (i = HalfSize; i < Size; ++i)
190 ok_eq_uint(Buffer[i], 0xAA);
191 ok_bool_true(CheckPattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0), "CheckPattern");
192
193 /* RtlMoveMemory */
194 MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
195 RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
196 ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
197
198 MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
199 RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
200 ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
201
202 KeLowerIrql(Irql);
203 Status = STATUS_SUCCESS;
204 _SEH2_TRY {
205 RtlMoveMemory(NULL, NULL, 0);
206 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
207 Status = _SEH2_GetExceptionCode();
208 } _SEH2_END;
209 ok_eq_hex(Status, STATUS_SUCCESS);
210 KeRaiseIrql(HIGH_LEVEL, &Irql);
211
212 #undef RtlMoveMemory
213 /* RtlMoveMemory export */
214 MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
215 RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
216 ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
217
218 MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
219 RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
220 ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
221
222 KeLowerIrql(Irql);
223 Status = STATUS_SUCCESS;
224 _SEH2_TRY {
225 RtlMoveMemory(NULL, NULL, 0);
226 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
227 Status = _SEH2_GetExceptionCode();
228 } _SEH2_END;
229 ok_eq_hex(Status, STATUS_SUCCESS);
230 KeRaiseIrql(HIGH_LEVEL, &Irql);
231
232 /* RtlCopyMemory */
233 MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
234 RtlCopyMemory(Buffer + 13, Buffer + 62, 95);
235 ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
236
237 MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
238 RtlCopyMemory(Buffer + 78, Buffer + 43, 107);
239 ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
240
241 KeLowerIrql(Irql);
242 Status = STATUS_SUCCESS;
243 _SEH2_TRY {
244 RtlCopyMemory(NULL, NULL, 0);
245 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
246 Status = _SEH2_GetExceptionCode();
247 } _SEH2_END;
248 ok_eq_hex(Status, STATUS_SUCCESS);
249 KeRaiseIrql(HIGH_LEVEL, &Irql);
250
251 /* RtlCopyMemoryNonTemporal */
252 MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
253 RtlCopyMemoryNonTemporal(Buffer + 13, Buffer + 62, 95);
254 ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
255
256 MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
257 RtlCopyMemoryNonTemporal(Buffer + 78, Buffer + 43, 107);
258 ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
259
260 KeLowerIrql(Irql);
261 Status = STATUS_SUCCESS;
262 _SEH2_TRY {
263 RtlCopyMemoryNonTemporal(NULL, NULL, 0);
264 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
265 Status = _SEH2_GetExceptionCode();
266 } _SEH2_END;
267 ok_eq_hex(Status, STATUS_SUCCESS);
268 KeRaiseIrql(HIGH_LEVEL, &Irql);
269
270 /* RtlCopyBytes */
271 MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
272 RtlCopyBytes(Buffer + 13, Buffer + 62, 95);
273 ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
274
275 MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
276 RtlCopyBytes(Buffer + 78, Buffer + 43, 107);
277 ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
278
279 KeLowerIrql(Irql);
280 Status = STATUS_SUCCESS;
281 _SEH2_TRY {
282 RtlCopyBytes(NULL, NULL, 0);
283 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
284 Status = _SEH2_GetExceptionCode();
285 } _SEH2_END;
286 ok_eq_hex(Status, STATUS_SUCCESS);
287 KeRaiseIrql(HIGH_LEVEL, &Irql);
288
289 /* RtlEqualMemory */
290 /* TODO: where is memcmp? */
291
292 /* RtlCompareMemory */
293 MakePattern(Buffer, 8, HalfSize / 8 - 1, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
294 1, 1, 0x12,
295 8, HalfSize / 8, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
296 1, 7, 0x12, 0);
297
298 RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8);
299 ok_eq_size(RetSize, HalfSize - 8);
300 RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 1);
301 ok_eq_size(RetSize, HalfSize - 8 + 1);
302 RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 2);
303 ok_eq_size(RetSize, HalfSize - 8 + 1);
304
305 KeLowerIrql(Irql);
306 Status = STATUS_SUCCESS;
307 _SEH2_TRY {
308 RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, SIZE_MAX);
309 ok_eq_size(RetSize, HalfSize - 8 + 1);
310 RetSize = RtlCompareMemory(NULL, NULL, 0);
311 ok_eq_size(RetSize, 0);
312 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
313 Status = _SEH2_GetExceptionCode();
314 } _SEH2_END;
315 ok_eq_hex(Status, STATUS_SUCCESS);
316 KeRaiseIrql(HIGH_LEVEL, &Irql);
317
318 /* RtlCompareMemoryUlong */
319 MakeBuffer(Buffer, 8, 0x55, Size - 4, 0, 0);
320 RetSize = RtlCompareMemoryUlong(Buffer, sizeof(ULONG), 0x55555555LU);
321 ok_eq_size(RetSize, 4);
322 RetSize = RtlCompareMemoryUlong(Buffer + 1, sizeof(ULONG), 0x55555555LU);
323 ok_eq_size(RetSize, 4);
324 RetSize = RtlCompareMemoryUlong(Buffer + 2, sizeof(ULONG), 0x55555555LU);
325 ok_eq_size(RetSize, 4);
326 RetSize = RtlCompareMemoryUlong(Buffer + 3, sizeof(ULONG), 0x55555555LU);
327 ok_eq_size(RetSize, 4);
328 RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x55555555LU);
329 ok_eq_size(RetSize, 0);
330 RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x00555555LU);
331 ok_eq_size(RetSize, 4);
332 RetSize = RtlCompareMemoryUlong(Buffer, 1, 0x55555555LU);
333 ok_eq_size(RetSize, 0);
334 RetSize = RtlCompareMemoryUlong(Buffer, 2, 0x55555555LU);
335 ok_eq_size(RetSize, 0);
336 RetSize = RtlCompareMemoryUlong(Buffer, 3, 0x55555555LU);
337 ok_eq_size(RetSize, 0);
338 RetSize = RtlCompareMemoryUlong(Buffer, 5, 0x55555555LU);
339 ok_eq_size(RetSize, 4);
340
341 KeLowerIrql(Irql);
342 Status = STATUS_SUCCESS;
343 _SEH2_TRY {
344 RetSize = RtlCompareMemoryUlong(NULL, 0, 0x55555555LU);
345 ok_eq_size(RetSize, 0);
346 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
347 Status = _SEH2_GetExceptionCode();
348 } _SEH2_END;
349 ok_eq_hex(Status, STATUS_SUCCESS);
350 KeRaiseIrql(HIGH_LEVEL, &Irql);
351
352 /* RtlZeroMemory */
353 MakeBuffer(Buffer, Size, 0x11, 0);
354 RtlZeroMemory(Buffer, 1);
355 ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
356 Buffer[0] = 0x11;
357 RtlZeroMemory(Buffer, Size - 1);
358 ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
359
360 KeLowerIrql(Irql);
361 Status = STATUS_SUCCESS;
362 _SEH2_TRY {
363 RtlZeroMemory(NULL, 0);
364 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
365 Status = _SEH2_GetExceptionCode();
366 } _SEH2_END;
367 ok_eq_hex(Status, STATUS_SUCCESS);
368 KeRaiseIrql(HIGH_LEVEL, &Irql);
369
370 /* RtlSecureZeroMemory */
371 MakeBuffer(Buffer, Size, 0x11, 0);
372 RtlSecureZeroMemory(Buffer, 1);
373 ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
374 Buffer[0] = 0x11;
375 RtlSecureZeroMemory(Buffer, Size - 1);
376 ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
377
378 KeLowerIrql(Irql);
379 Status = STATUS_SUCCESS;
380 _SEH2_TRY {
381 RtlSecureZeroMemory(NULL, 0);
382 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
383 Status = _SEH2_GetExceptionCode();
384 } _SEH2_END;
385 ok_eq_hex(Status, STATUS_SUCCESS);
386 KeRaiseIrql(HIGH_LEVEL, &Irql);
387
388 /* RtlZeroBytes */
389 MakeBuffer(Buffer, Size, 0x11, 0);
390 RtlZeroBytes(Buffer, 1);
391 ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
392 Buffer[0] = 0x11;
393 RtlZeroBytes(Buffer, Size - 1);
394 ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
395
396 KeLowerIrql(Irql);
397 Status = STATUS_SUCCESS;
398 _SEH2_TRY {
399 RtlZeroBytes(NULL, 0);
400 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
401 Status = _SEH2_GetExceptionCode();
402 } _SEH2_END;
403 ok_eq_hex(Status, STATUS_SUCCESS);
404 KeRaiseIrql(HIGH_LEVEL, &Irql);
405
406 /* RtlFillMemory */
407 MakeBuffer(Buffer, Size, 0, 0);
408 RtlFillMemory(Buffer, HalfSize, 0x55);
409 RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
410 ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
411 RtlFillMemory(Buffer + 3, 7, 0x88);
412 ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
413
414 KeLowerIrql(Irql);
415 Status = STATUS_SUCCESS;
416 _SEH2_TRY {
417 RtlFillMemory(NULL, 0, 0x55);
418 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
419 Status = _SEH2_GetExceptionCode();
420 } _SEH2_END;
421 ok_eq_hex(Status, STATUS_SUCCESS);
422 KeRaiseIrql(HIGH_LEVEL, &Irql);
423
424 #undef RtlFillMemory
425 /* RtlFillMemory export */
426 MakeBuffer(Buffer, Size, 0, 0);
427 RtlFillMemory(Buffer, HalfSize, 0x55);
428 RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
429 ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
430 RtlFillMemory(Buffer + 3, 7, 0x88);
431 ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
432
433 KeLowerIrql(Irql);
434 Status = STATUS_SUCCESS;
435 _SEH2_TRY {
436 RtlFillMemory(NULL, 0, 0x55);
437 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
438 Status = _SEH2_GetExceptionCode();
439 } _SEH2_END;
440 ok_eq_hex(Status, STATUS_SUCCESS);
441 KeRaiseIrql(HIGH_LEVEL, &Irql);
442
443 /* TODO: fix NDK. This should work! */
444 #if !defined _M_AMD64 || defined KMT_KERNEL_MODE
445 /* RtlFillMemoryUlong */
446 MakeBuffer(Buffer, Size, 0, 0);
447 RtlFillMemoryUlong(Buffer, HalfSize, 0x01234567LU);
448 RtlFillMemoryUlong(Buffer + HalfSize, HalfSize, 0x89ABCDEFLU);
449 ok_bool_true(CheckPattern(Buffer, 4, HalfSize / 4, 0x67, 0x45, 0x23, 0x01, 4, HalfSize / 4, 0xEF, 0xCD, 0xAB, 0x89, 1, 1, 0, 0), "CheckPattern");
450
451 KeLowerIrql(Irql);
452 Status = STATUS_SUCCESS;
453 _SEH2_TRY {
454 MakeBuffer(Buffer, Size, 0, 0);
455 RtlFillMemoryUlong(Buffer + 1, sizeof(ULONG), 0xAAAAAAAALU);
456 ok_bool_true(CheckBuffer(Buffer, 1, 0, sizeof(ULONG), 0xAA, Size - sizeof(ULONG) - 1, 0, 1, 0, 0), "CheckBuffer");
457
458 RtlFillMemoryUlong(NULL, 0, 0x55555555LU);
459 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
460 Status = _SEH2_GetExceptionCode();
461 } _SEH2_END;
462 ok_eq_hex(Status, STATUS_SUCCESS);
463 KeRaiseIrql(HIGH_LEVEL, &Irql);
464 #endif
465
466 /* RtlFillMemoryUlonglong */
467 /* TODO: this function doesn't exist in 2k3/x86? wdm.h error? */
468
469 /* RtlFillBytes */
470 MakeBuffer(Buffer, Size, 0, 0);
471 RtlFillBytes(Buffer, HalfSize, 0x55);
472 RtlFillBytes(Buffer + HalfSize, HalfSize, 0xAA);
473 ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
474 RtlFillBytes(Buffer + 3, 7, 0x88);
475 ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
476
477 KeLowerIrql(Irql);
478 Status = STATUS_SUCCESS;
479 _SEH2_TRY {
480 RtlFillBytes(NULL, 0, 0x55);
481 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
482 Status = _SEH2_GetExceptionCode();
483 } _SEH2_END;
484 ok_eq_hex(Status, STATUS_SUCCESS);
485 KeRaiseIrql(HIGH_LEVEL, &Irql);
486
487 /* RtlPrefetchMemoryNonTemporal */
488 RtlPrefetchMemoryNonTemporal(Buffer, Size);
489
490 KeLowerIrql(Irql);
491 Status = STATUS_SUCCESS;
492 _SEH2_TRY {
493 RtlPrefetchMemoryNonTemporal(NULL, 0);
494 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
495 Status = _SEH2_GetExceptionCode();
496 } _SEH2_END;
497 ok_eq_hex(Status, STATUS_SUCCESS);
498 KeRaiseIrql(HIGH_LEVEL, &Irql);
499
500 KeLowerIrql(Irql);
501 }