ReactOS 0.4.16-dev-292-gbbdcc14
NtContinue.c File Reference
#include "precomp.h"
#include <setjmp.h>
#include <time.h>
Include dependency graph for NtContinue.c:

Go to the source code of this file.

Functions

void continuePoint (void)
 
static int initrand (void)
 
static void randbytes (void *p, size_t n)
 
static ULONG randULONG (void)
 
void check (CONTEXT *pContext)
 
 START_TEST (NtContinue)
 

Variables

static jmp_buf jmpbuf
 
static CONTEXT continueContext
 
static unsigned int nRandBytes
 

Function Documentation

◆ check()

void check ( CONTEXT pContext)

Definition at line 72 of file NtContinue.c.

73{
74#ifdef _M_IX86
75 ok(pContext->ContextFlags == CONTEXT_FULL,
76 "ContextFlags=0x%lx\n", pContext->ContextFlags);
77
78 /* Random data segments */
79 ok((pContext->SegGs & NTC_SEGMENT_BITS) ==
80 (continueContext.SegGs & NTC_SEGMENT_BITS),
81 "SegGs=0x%lx / 0x%lx\n", pContext->SegGs, continueContext.SegGs);
82
83 ok((pContext->SegFs & NTC_SEGMENT_BITS) ==
84 (continueContext.SegFs & NTC_SEGMENT_BITS),
85 "SegFs=0x%lx / 0x%lx\n", pContext->SegFs, continueContext.SegFs);
86
87 ok((pContext->SegEs & NTC_SEGMENT_BITS) ==
88 (continueContext.SegEs & NTC_SEGMENT_BITS),
89 "SegEs=0x%lx / 0x%lx\n", pContext->SegEs, continueContext.SegEs);
90
91 ok((pContext->SegDs & NTC_SEGMENT_BITS) ==
92 (continueContext.SegDs & NTC_SEGMENT_BITS),
93 "SegDs=0x%lx / 0x%lx\n", pContext->SegDs, continueContext.SegDs);
94
95 /* Integer registers */
96 ok(pContext->Edi == continueContext.Edi,
97 "Edi: 0x%lx != 0x%lx\n", pContext->Edi, continueContext.Edi);
98 ok(pContext->Esi == continueContext.Esi,
99 "Esi: 0x%lx != 0x%lx\n", pContext->Esi, continueContext.Esi);
100 ok(pContext->Ebx == continueContext.Ebx,
101 "Ebx: 0x%lx != 0x%lx\n", pContext->Ebx, continueContext.Ebx);
102 ok(pContext->Edx == continueContext.Edx,
103 "Edx: 0x%lx != 0x%lx\n", pContext->Edx, continueContext.Edx);
104 ok(pContext->Ecx == continueContext.Ecx,
105 "Ecx: 0x%lx != 0x%lx\n", pContext->Ecx, continueContext.Ecx);
106 ok(pContext->Eax == continueContext.Eax,
107 "Eax: 0x%lx != 0x%lx\n", pContext->Eax, continueContext.Eax);
108
109 /* Control registers and segments */
110 ok(pContext->Ebp == continueContext.Ebp,
111 "Ebp: 0x%lx != 0x%lx\n", pContext->Ebp, continueContext.Ebp);
112 ok(pContext->Eip == continueContext.Eip,
113 "Eip: 0x%lx != 0x%lx\n", pContext->Eip, continueContext.Eip);
114 ok(pContext->Esp == continueContext.Esp,
115 "Esp: 0x%lx != 0x%lx\n", pContext->Esp, continueContext.Esp);
116
117 ok((pContext->SegCs & NTC_SEGMENT_BITS) ==
118 (continueContext.SegCs & NTC_SEGMENT_BITS),
119 "SegCs: 0x%lx != 0x%lx\n", pContext->SegCs, continueContext.SegCs);
120
121 ok((pContext->EFlags & NTC_EFLAGS_BITS) ==
122 (continueContext.EFlags & NTC_EFLAGS_BITS),
123 "EFlags: 0x%lx != 0x%lx\n", pContext->EFlags, continueContext.EFlags);
124
125 ok((pContext->SegSs & NTC_SEGMENT_BITS) ==
126 (continueContext.SegSs & NTC_SEGMENT_BITS),
127 "SegSs: 0x%lx != 0x%lx\n", pContext->SegSs, continueContext.SegSs);
128#else
130 ok_eq_hex(pContext->MxCsr, continueContext.MxCsr);
132 ok_eq_hex(pContext->SegDs, 0x2B);
133 ok_eq_hex(pContext->SegEs, 0x2B);
134 ok_eq_hex(pContext->SegFs, 0x53);
135 ok_eq_hex(pContext->SegGs, 0x2B);
137 ok_eq_hex(pContext->EFlags, (continueContext.EFlags & ~0x1C0000) | 0x202);
138
139 ok_eq_hex64(pContext->Rax, continueContext.Rax);
140 ok_eq_hex64(pContext->Rdx, continueContext.Rdx);
141 ok_eq_hex64(pContext->Rbx, continueContext.Rbx);
142 ok_eq_hex64(pContext->Rsp, continueContext.Rsp);
143 ok_eq_hex64(pContext->Rbp, continueContext.Rbp);
144 ok_eq_hex64(pContext->Rsi, continueContext.Rsi);
145 ok_eq_hex64(pContext->Rdi, continueContext.Rdi);
146 ok_eq_hex64(pContext->R8, continueContext.R8);
147 ok_eq_hex64(pContext->R9, continueContext.R9);
151 ok_eq_hex64(pContext->R13, continueContext.R13);
152 ok_eq_hex64(pContext->R14, continueContext.R14);
153 ok_eq_hex64(pContext->R15, continueContext.R15);
154 ok_eq_xmm(pContext->Xmm0, continueContext.Xmm0);
155 ok_eq_xmm(pContext->Xmm1, continueContext.Xmm1);
156 ok_eq_xmm(pContext->Xmm2, continueContext.Xmm2);
157 ok_eq_xmm(pContext->Xmm3, continueContext.Xmm3);
158 ok_eq_xmm(pContext->Xmm4, continueContext.Xmm4);
159 ok_eq_xmm(pContext->Xmm5, continueContext.Xmm5);
160 ok_eq_xmm(pContext->Xmm6, continueContext.Xmm6);
161 ok_eq_xmm(pContext->Xmm7, continueContext.Xmm7);
162 ok_eq_xmm(pContext->Xmm8, continueContext.Xmm8);
163 ok_eq_xmm(pContext->Xmm9, continueContext.Xmm9);
164 ok_eq_xmm(pContext->Xmm10, continueContext.Xmm10);
165 ok_eq_xmm(pContext->Xmm11, continueContext.Xmm11);
166 ok_eq_xmm(pContext->Xmm12, continueContext.Xmm12);
167 ok_eq_xmm(pContext->Xmm13, continueContext.Xmm13);
168 ok_eq_xmm(pContext->Xmm14, continueContext.Xmm14);
169 ok_eq_xmm(pContext->Xmm15, continueContext.Xmm15);
170
171 // Clear the frame register to prevent unwinding, which is broken
172 ((_JUMP_BUFFER*)&jmpbuf)->Frame = 0;
173#endif
174
175 /* Return where we came from */
176 longjmp(jmpbuf, 1);
177}
static jmp_buf jmpbuf
Definition: NtContinue.c:24
static CONTEXT continueContext
Definition: NtContinue.c:25
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_hex64(value, expected)
Definition: apitest.h:89
#define ok_eq_xmm(value, expected)
Definition: apitest.h:90
#define ok(value,...)
Definition: atltest.h:57
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
#define CONTEXT_FULL
Definition: nt_native.h:1375
ULONG Esp
Definition: nt_native.h:1479
ULONG SegFs
Definition: nt_native.h:1454
ULONG Edx
Definition: nt_native.h:1466
ULONG Esi
Definition: nt_native.h:1464
ULONG Ebp
Definition: nt_native.h:1475
ULONG ContextFlags
Definition: nt_native.h:1426
ULONG R8
Definition: ke.h:263
ULONG SegSs
Definition: nt_native.h:1480
ULONG Ecx
Definition: nt_native.h:1467
ULONG Eip
Definition: nt_native.h:1476
ULONG R12
Definition: ke.h:267
ULONG SegCs
Definition: nt_native.h:1477
ULONG SegDs
Definition: nt_native.h:1456
ULONG R9
Definition: ke.h:264
ULONG EFlags
Definition: nt_native.h:1478
ULONG SegGs
Definition: nt_native.h:1453
ULONG R10
Definition: ke.h:265
ULONG Eax
Definition: nt_native.h:1468
ULONG SegEs
Definition: nt_native.h:1455
ULONG Ebx
Definition: nt_native.h:1465
ULONG Edi
Definition: nt_native.h:1463
ULONG R11
Definition: ke.h:266

◆ continuePoint()

void continuePoint ( void  )

Referenced by START_TEST().

◆ initrand()

static int initrand ( void  )
static

Definition at line 28 of file NtContinue.c.

29{
30 unsigned int nRandMax;
31 unsigned int nRandMaxBits;
32 time_t tLoc;
33
34 nRandMax = RAND_MAX;
35 for(nRandMaxBits = 0; nRandMax != 0; nRandMax >>= 1, ++ nRandMaxBits);
36 nRandBytes = nRandMaxBits / CHAR_BIT;
37 //assert(nRandBytes != 0);
38 srand((unsigned)(time(&tLoc) & UINT_MAX));
39 return 1;
40}
static unsigned int nRandBytes
Definition: NtContinue.c:26
#define CHAR_BIT
Definition: urlcache.c:62
__kernel_time_t time_t
Definition: linux.h:252
void __cdecl srand(_In_ unsigned int _Seed)
#define RAND_MAX
Definition: stdlib.h:87
#define UINT_MAX
Definition: intsafe.h:152
__u16 time
Definition: mkdosfs.c:8

Referenced by START_TEST().

◆ randbytes()

static void randbytes ( void p,
size_t  n 
)
static

Definition at line 42 of file NtContinue.c.

43{
44 unsigned char * b;
45 size_t i;
46 int r = rand();
47
48 b = (unsigned char *)p;
49 for(i = 0; i < n; ++ i)
50 {
51 if(i % nRandBytes == 0)
52 r = rand();
53 b[i] = (unsigned char)(r & UCHAR_MAX);
54 r >>= CHAR_BIT;
55 }
56}
unsigned char
Definition: typeof.h:29
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLfloat GLfloat p
Definition: glext.h:8902
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
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
#define UCHAR_MAX
Definition: limits.h:25
#define b
Definition: ke_i.h:79

Referenced by randULONG().

◆ randULONG()

static ULONG randULONG ( void  )
static

Definition at line 58 of file NtContinue.c.

59{
60 ULONG n;
61 randbytes(&n, sizeof(n));
62 return n;
63}
static void randbytes(void *p, size_t n)
Definition: NtContinue.c:42
uint32_t ULONG
Definition: typedefs.h:59

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( NtContinue  )

Definition at line 179 of file NtContinue.c.

180{
181 initrand();
182
183 RtlFillMemory(&continueContext, sizeof(continueContext), 0xBBBBBBBB);
184
185 /* First time */
186 if(setjmp(jmpbuf) == 0)
187 {
188 CONTEXT bogus[2];
189
190 RtlFillMemory(&bogus, sizeof(bogus), 0xCCCCCCCC);
191
194
195#ifdef _M_IX86
197
198 /* Fill the integer registers with random values */
206
207 /* Randomize all the allowed flags (determined experimentally with WinDbg) */
208 continueContext.EFlags = randULONG() & 0x3C0CD5;
209
210 /* Randomize the stack pointer as much as possible */
211 continueContext.Esp = (ULONG)(((ULONG_PTR)&bogus) & 0xFFFFFFFF) +
212 sizeof(bogus) - (randULONG() & 0xF) * 4;
213
214 /* continuePoint() is implemented in assembler */
216
217 /* Can't do a lot about segments */
218#elif defined(_M_AMD64)
220
221 /* Fill the integer registers with random values */
222 PULONG64 Registers = &continueContext.Rax;
223 for (ULONG i = 0; i < 16; i++)
224 {
225 Registers[i] = randULONG64();
226 }
227
228 /* Fill the XMM registers with random values */
229 Registers = (PULONG64)&continueContext.Xmm0;
230 for (ULONG i = 0; i < 32; i++)
231 {
232 Registers[i] = randULONG64();
233 }
234
235 continueContext.Dr0 = randULONG64() & 0xFFFF;
236 continueContext.Dr1 = randULONG64() & 0xFFFF;
237 continueContext.Dr2 = randULONG64() & 0xFFFF;
238 continueContext.Dr3 = randULONG64() & 0xFFFF;
239 continueContext.Dr6 = randULONG64() & 0xFFFF;
240 continueContext.Dr7 = randULONG64() & 0xFFFF;
241
242 /* Randomize all the allowed flags (determined experimentally with WinDbg) */
243 continueContext.EFlags = randULONG64() & 0x3C0CD5;
244
245 /* Randomize the stack pointer as much as possible */
246 continueContext.Rsp = (((ULONG_PTR)&bogus)) + (randULONG() & 0xF) * 16;
248
249 /* continuePoint() is implemented in assembler */
251#endif
252
254 ok(0, "should never get here\n");
255 }
256
257 /* Second time */
258 return;
259}
#define ALIGN_DOWN_BY(size, align)
void continuePoint(void)
static ULONG randULONG(void)
Definition: NtContinue.c:58
static int initrand(void)
Definition: NtContinue.c:28
#define FALSE
Definition: types.h:117
BOOL WINAPI GetThreadContext(IN HANDLE hThread, OUT LPCONTEXT lpContext)
Definition: thread.c:501
#define ULONG_PTR
Definition: config.h:101
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define for
Definition: utility.h:88
unsigned __int64 * PULONG64
Definition: imports.h:198
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1373
NTSTATUS NTAPI NtContinue(_In_ PCONTEXT Context, _In_ BOOLEAN TestAlert)
Definition: except.c:216
ULONG Dr3
Definition: nt_native.h:1437
ULONG Dr1
Definition: nt_native.h:1435
ULONG Dr6
Definition: nt_native.h:1438
ULONG Dr0
Definition: nt_native.h:1434
ULONG Dr2
Definition: nt_native.h:1436
ULONG Dr7
Definition: nt_native.h:1439
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define setjmp
Definition: setjmp.h:209
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148

Variable Documentation

◆ continueContext

CONTEXT continueContext
static

Definition at line 25 of file NtContinue.c.

Referenced by check(), and START_TEST().

◆ jmpbuf

jmp_buf jmpbuf
static

Definition at line 24 of file NtContinue.c.

Referenced by check(), and START_TEST().

◆ nRandBytes

unsigned int nRandBytes
static

Definition at line 26 of file NtContinue.c.

Referenced by initrand(), and randbytes().