ReactOS  0.4.14-dev-115-g4576127
RtlStack.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Runtime library stack trace test
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #define KMT_EMULATE_KERNEL
9 #include <kmt_test.h>
10 
12 
13 static
14 VOID
16 
18 static
19 VOID
21 {
22  PVOID Frames[5];
23  ULONG Ret;
24  ULONG Hash;
25  ULONG ExpectedHash;
26  ULONG i;
27  const ULONG FunctionSizeGuess = 0x1000;
28 
30 
31  Ret = RtlWalkFrameChain(NULL, 5, 0);
32  ok_eq_ulong(Ret, 0);
33 
34  RtlFillMemory(Frames, sizeof(Frames), 0x55);
35  Ret = RtlWalkFrameChain(Frames, 0, 0);
36  ok_eq_ulong(Ret, 0);
37  ok_eq_pointer(Frames[0], (PVOID)(ULONG_PTR)0x5555555555555555);
38 
39  RtlFillMemory(Frames, sizeof(Frames), 0x55);
40  Ret = RtlWalkFrameChain(Frames, 5, 0);
41  ok_eq_ulong(Ret, 5);
42  ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
43  ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
44  ok_eq_pointer(Frames[1], ReturnAddresses[3]);
45  ok_eq_pointer(Frames[2], ReturnAddresses[2]);
46  ok_eq_pointer(Frames[3], ReturnAddresses[1]);
47  ok_eq_pointer(Frames[4], ReturnAddresses[0]);
48 
49  RtlFillMemory(Frames, sizeof(Frames), 0x55);
50  Ret = RtlWalkFrameChain(Frames, 4, 0);
51  ok_eq_ulong(Ret, 4);
52  ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
53  ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
54  ok_eq_pointer(Frames[1], ReturnAddresses[3]);
55  ok_eq_pointer(Frames[2], ReturnAddresses[2]);
56  ok_eq_pointer(Frames[3], ReturnAddresses[1]);
57  ok_eq_pointer(Frames[4], (PVOID)(ULONG_PTR)0x5555555555555555);
58 
59  KmtStartSeh()
62 
63  RtlFillMemory(Frames, sizeof(Frames), 0x55);
64  Hash = 0x55555555;
65  Ret = RtlCaptureStackBackTrace(0, 0, Frames, &Hash);
66  ok_eq_ulong(Ret, 0);
67  ok_eq_hex(Hash, 0x55555555);
68  ok_eq_pointer(Frames[0], (PVOID)(ULONG_PTR)0x5555555555555555);
69 
70  RtlFillMemory(Frames, sizeof(Frames), 0x55);
71  Hash = 0x55555555;
72  Ret = RtlCaptureStackBackTrace(0, 1, Frames, NULL);
73  ok_eq_ulong(Ret, 1);
74  ok((ULONG_PTR)Frames[0] > (ULONG_PTR)TestStackWalk4, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
75  ok((ULONG_PTR)Frames[0] < (ULONG_PTR)TestStackWalk4 + FunctionSizeGuess, "Frame is %p, function is %p\n", Frames[0], TestStackWalk4);
76  ok_eq_pointer(Frames[1], (PVOID)(ULONG_PTR)0x5555555555555555);
77 
78  RtlFillMemory(Frames, sizeof(Frames), 0x55);
79  Ret = RtlCaptureStackBackTrace(0, 5, Frames, &Hash);
80  ok_eq_ulong(Ret, 5);
81  ExpectedHash = 0;
82  for (i = 0; i < 5; i++)
83  ExpectedHash += (ULONG)(ULONG_PTR)Frames[i];
84  ok_eq_hex(Hash, ExpectedHash);
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], ReturnAddresses[3]);
88  ok_eq_pointer(Frames[2], ReturnAddresses[2]);
89  ok_eq_pointer(Frames[3], ReturnAddresses[1]);
90  ok_eq_pointer(Frames[4], ReturnAddresses[0]);
91 
92  RtlFillMemory(Frames, sizeof(Frames), 0x55);
93  Ret = RtlCaptureStackBackTrace(1, 4, Frames, &Hash);
94  ok_eq_ulong(Ret, 4);
95  ExpectedHash = 0;
96  for (i = 0; i < 4; i++)
97  ExpectedHash += (ULONG)(ULONG_PTR)Frames[i];
98  ok_eq_hex(Hash, ExpectedHash);
99  ok_eq_pointer(Frames[0], ReturnAddresses[3]);
100  ok_eq_pointer(Frames[1], ReturnAddresses[2]);
101  ok_eq_pointer(Frames[2], ReturnAddresses[1]);
102  ok_eq_pointer(Frames[3], ReturnAddresses[0]);
103  ok_eq_pointer(Frames[4], (PVOID)(ULONG_PTR)0x5555555555555555);
104 }
105 
107 static
108 VOID
110 {
112  TestStackWalk4();
113 }
114 
116 static
117 VOID
119 {
121  TestStackWalk3();
122 }
123 
125 static
126 VOID
128 {
130  TestStackWalk2();
131 }
132 
133 START_TEST(RtlStack)
134 {
135  TestStackWalk1();
136 }
static int Hash(const char *)
Definition: reader.c:2257
static DECLSPEC_NOINLINE VOID TestStackWalk4(VOID)
Definition: RtlStack.c:20
#define ok_eq_ulong(value, expected)
#define ok_eq_pointer(value, expected)
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
static PVOID ReturnAddresses[4]
Definition: RtlStack.c:11
START_TEST(RtlStack)
Definition: RtlStack.c:133
static VOID TestStackWalk3(VOID)
Definition: RtlStack.c:109
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
static DECLSPEC_NOINLINE VOID TestStackWalk2(VOID)
Definition: RtlStack.c:118
smooth NULL
Definition: ftsmooth.c:416
#define KmtStartSeh()
Definition: kmt_test.h:277
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
ULONG NTAPI RtlWalkFrameChain(OUT PVOID *Callers, IN ULONG Count, IN ULONG Flags)
Definition: libsupp.c:227
#define ok(value,...)
Definition: atltest.h:57
static DECLSPEC_NOINLINE VOID TestStackWalk1(VOID)
Definition: RtlStack.c:127
void * _ReturnAddress(void)
NTSYSAPI USHORT NTAPI RtlCaptureStackBackTrace(_In_ ULONG FramesToSkip, _In_ ULONG FramesToCapture, _Out_writes_to_(FramesToCapture, return) PVOID *BackTrace, _Out_opt_ PULONG BackTraceHash)
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define ok_eq_hex(value, expected)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define DECLSPEC_NOINLINE
Definition: ntbasedef.h:231