2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Guarded Memory example test
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
11 #pragma GCC diagnostic ignored "-Wnonnull"
12 #endif /* defined __GNUC__ */
14 START_TEST(GuardedMemory
)
20 /* access some invalid memory to test SEH */
21 Status
= STATUS_SUCCESS
;
24 RtlFillMemory(NULL
, 1, 0);
26 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
28 Status
= _SEH2_GetExceptionCode();
30 ok_eq_hex(Status
, STATUS_ACCESS_VIOLATION
);
33 Buffer
= KmtAllocateGuarded(Size
);
35 if (skip(Buffer
!= NULL
, "Failed to allocate guarded memory\n"))
38 /* access to guarded mem should be fine */
39 Status
= STATUS_SUCCESS
;
42 RtlFillMemory(Buffer
, Size
, 0);
44 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
46 Status
= _SEH2_GetExceptionCode();
48 ok_eq_hex(Status
, STATUS_SUCCESS
);
50 /* access one byte behind guarded mem must cause an access violation! */
51 Status
= STATUS_SUCCESS
;
54 RtlFillMemory(Buffer
+ Size
, 1, 0);
56 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
58 Status
= _SEH2_GetExceptionCode();
60 ok_eq_hex(Status
, STATUS_ACCESS_VIOLATION
);
62 KmtFreeGuarded(Buffer
);