ReactOS 0.4.16-dev-1946-g52006dd
RtlStack.c File Reference
#include <kmt_test.h>
Include dependency graph for RtlStack.c:

Go to the source code of this file.

Macros

#define KMT_EMULATE_KERNEL
 

Functions

static VOID TestStackWalk3 (VOID)
 
static DECLSPEC_NOINLINE VOID TestStackWalk4 (VOID)
 
static DECLSPEC_NOINLINE VOID TestStackWalk2 (VOID)
 
static DECLSPEC_NOINLINE VOID TestStackWalk1 (VOID)
 
 START_TEST (RtlStack)
 

Variables

static PVOID ReturnAddresses [4]
 

Macro Definition Documentation

◆ KMT_EMULATE_KERNEL

#define KMT_EMULATE_KERNEL

Definition at line 8 of file RtlStack.c.

Function Documentation

◆ START_TEST()

START_TEST ( RtlStack  )

Definition at line 205 of file RtlStack.c.

206{
208#ifdef _M_AMD64
209 TestRtlPcToFileHeader();
210#endif // _M_AMD64
211}
static DECLSPEC_NOINLINE VOID TestStackWalk1(VOID)
Definition: RtlStack.c:138

◆ TestStackWalk1()

static DECLSPEC_NOINLINE VOID TestStackWalk1 ( VOID  )
static

Definition at line 138 of file RtlStack.c.

139{
142}
static PVOID ReturnAddresses[4]
Definition: RtlStack.c:11
static DECLSPEC_NOINLINE VOID TestStackWalk2(VOID)
Definition: RtlStack.c:129
#define _ReturnAddress()
Definition: intrin_arm.h:35

Referenced by START_TEST().

◆ TestStackWalk2()

static DECLSPEC_NOINLINE VOID TestStackWalk2 ( VOID  )
static

Definition at line 129 of file RtlStack.c.

130{
133}
static VOID TestStackWalk3(VOID)
Definition: RtlStack.c:120

Referenced by TestStackWalk1().

◆ TestStackWalk3()

static DECLSPEC_NOINLINE VOID TestStackWalk3 ( VOID  )
static

Definition at line 120 of file RtlStack.c.

121{
124}
static DECLSPEC_NOINLINE VOID TestStackWalk4(VOID)
Definition: RtlStack.c:20

Referenced by TestStackWalk2().

◆ TestStackWalk4()

static DECLSPEC_NOINLINE VOID TestStackWalk4 ( VOID  )
static

Definition at line 20 of file RtlStack.c.

21{
22 PVOID Frames[5];
23 ULONG Ret;
24 ULONG Hash;
25 ULONG ExpectedHash;
26 ULONG i;
27 const ULONG FunctionSizeGuess = 0x1000;
28 NTSTATUS ExceptionStatus = STATUS_SUCCESS;
29
31
32 Ret = RtlWalkFrameChain(NULL, 5, 0);
33 ok_eq_ulong(Ret, 0);
34
35 RtlFillMemory(Frames, sizeof(Frames), 0x55);
36 Ret = RtlWalkFrameChain(Frames, 0, 0);
37 ok_eq_ulong(Ret, 0);
38 ok_eq_pointer(Frames[0], (PVOID)(ULONG_PTR)0x5555555555555555);
39
40 RtlFillMemory(Frames, sizeof(Frames), 0x55);
41 Ret = RtlWalkFrameChain(Frames, 5, 0);
42 ok_eq_ulong(Ret, 5);
43 ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
44 ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
45 ok_eq_pointer(Frames[1], ReturnAddresses[3]);
46 ok_eq_pointer(Frames[2], ReturnAddresses[2]);
47 ok_eq_pointer(Frames[3], ReturnAddresses[1]);
48 ok_eq_pointer(Frames[4], ReturnAddresses[0]);
49
50 RtlFillMemory(Frames, sizeof(Frames), 0x55);
51 Ret = RtlWalkFrameChain(Frames, 4, 0);
52 ok_eq_ulong(Ret, 4);
53 ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
54 ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
55 ok_eq_pointer(Frames[1], ReturnAddresses[3]);
56 ok_eq_pointer(Frames[2], ReturnAddresses[2]);
57 ok_eq_pointer(Frames[3], ReturnAddresses[1]);
58 ok_eq_pointer(Frames[4], (PVOID)(ULONG_PTR)0x5555555555555555);
59
61 {
63 }
65 {
66 ExceptionStatus = _SEH2_GetExceptionCode();
67 }
70 ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
71 else
72 ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
73
74 RtlFillMemory(Frames, sizeof(Frames), 0x55);
75 Hash = 0x55555555;
76 Ret = RtlCaptureStackBackTrace(0, 0, Frames, &Hash);
77 ok_eq_ulong(Ret, 0);
78 ok_eq_hex(Hash, 0x55555555);
79 ok_eq_pointer(Frames[0], (PVOID)(ULONG_PTR)0x5555555555555555);
80
81 RtlFillMemory(Frames, sizeof(Frames), 0x55);
82 Hash = 0x55555555;
83 Ret = RtlCaptureStackBackTrace(0, 1, Frames, NULL);
84 ok_eq_ulong(Ret, 1);
85 ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
86 ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
87 ok_eq_pointer(Frames[1], (PVOID)(ULONG_PTR)0x5555555555555555);
88
89 RtlFillMemory(Frames, sizeof(Frames), 0x55);
90 Ret = RtlCaptureStackBackTrace(0, 5, Frames, &Hash);
91 ok_eq_ulong(Ret, 5);
92 ExpectedHash = 0;
93 for (i = 0; i < 5; i++)
94 ExpectedHash += (ULONG)(ULONG_PTR)Frames[i];
95 ok_eq_hex(Hash, ExpectedHash);
96 ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
97 ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
98 ok_eq_pointer(Frames[1], ReturnAddresses[3]);
99 ok_eq_pointer(Frames[2], ReturnAddresses[2]);
100 ok_eq_pointer(Frames[3], ReturnAddresses[1]);
101 ok_eq_pointer(Frames[4], ReturnAddresses[0]);
102
103 RtlFillMemory(Frames, sizeof(Frames), 0x55);
104 Ret = RtlCaptureStackBackTrace(1, 4, Frames, &Hash);
105 ok_eq_ulong(Ret, 4);
106 ExpectedHash = 0;
107 for (i = 0; i < 4; i++)
108 ExpectedHash += (ULONG)(ULONG_PTR)Frames[i];
109 ok_eq_hex(Hash, ExpectedHash);
110 ok_eq_pointer(Frames[0], ReturnAddresses[3]);
111 ok_eq_pointer(Frames[1], ReturnAddresses[2]);
112 ok_eq_pointer(Frames[2], ReturnAddresses[1]);
113 ok_eq_pointer(Frames[3], ReturnAddresses[0]);
114 ok_eq_pointer(Frames[4], (PVOID)(ULONG_PTR)0x5555555555555555);
115}
#define ok_eq_pointer(value, expected)
Definition: apitest.h:116
#define ok_eq_hex(value, expected)
Definition: apitest.h:134
#define ok_eq_ulong(value, expected)
Definition: apitest.h:120
#define GetNTVersion()
Definition: apitest.h:17
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
ULONG NTAPI RtlWalkFrameChain(OUT PVOID *Callers, IN ULONG Count, IN ULONG Flags)
Definition: libsupp.c:229
static int Hash(const char *)
Definition: reader.c:2237
#define ULONG_PTR
Definition: config.h:101
#define STATUS_ACCESS_VIOLATION
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:603
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
NTSYSAPI USHORT WINAPI RtlCaptureStackBackTrace(ULONG, ULONG, void **, ULONG *)
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59

Referenced by TestStackWalk3(), and TestStackWalk4().

Variable Documentation

◆ ReturnAddresses

PVOID ReturnAddresses[4]
static

Definition at line 11 of file RtlStack.c.

Referenced by TestStackWalk1(), TestStackWalk2(), TestStackWalk3(), and TestStackWalk4().