ReactOS  0.4.15-dev-1200-gc3b3fcd
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 68 of file NtContinue.c.

69 {
70 #ifdef _M_IX86
71  ok(pContext->ContextFlags == CONTEXT_FULL,
72  "ContextFlags=0x%lx\n", pContext->ContextFlags);
73 
74  /* Random data segments */
75  ok((pContext->SegGs & NTC_SEGMENT_BITS) ==
76  (continueContext.SegGs & NTC_SEGMENT_BITS),
77  "SegGs=0x%lx / 0x%lx\n", pContext->SegGs, continueContext.SegGs);
78 
79  ok((pContext->SegFs & NTC_SEGMENT_BITS) ==
80  (continueContext.SegFs & NTC_SEGMENT_BITS),
81  "SegFs=0x%lx / 0x%lx\n", pContext->SegFs, continueContext.SegFs);
82 
83  ok((pContext->SegEs & NTC_SEGMENT_BITS) ==
84  (continueContext.SegEs & NTC_SEGMENT_BITS),
85  "SegEs=0x%lx / 0x%lx\n", pContext->SegEs, continueContext.SegEs);
86 
87  ok((pContext->SegDs & NTC_SEGMENT_BITS) ==
88  (continueContext.SegDs & NTC_SEGMENT_BITS),
89  "SegDs=0x%lx / 0x%lx\n", pContext->SegDs, continueContext.SegDs);
90 
91  /* Integer registers */
92  ok(pContext->Edi == continueContext.Edi,
93  "Edi: 0x%lx != 0x%lx\n", pContext->Edi, continueContext.Edi);
94  ok(pContext->Esi == continueContext.Esi,
95  "Esi: 0x%lx != 0x%lx\n", pContext->Esi, continueContext.Esi);
96  ok(pContext->Ebx == continueContext.Ebx,
97  "Ebx: 0x%lx != 0x%lx\n", pContext->Ebx, continueContext.Ebx);
98  ok(pContext->Edx == continueContext.Edx,
99  "Edx: 0x%lx != 0x%lx\n", pContext->Edx, continueContext.Edx);
100  ok(pContext->Ecx == continueContext.Ecx,
101  "Ecx: 0x%lx != 0x%lx\n", pContext->Ecx, continueContext.Ecx);
102  ok(pContext->Eax == continueContext.Eax,
103  "Eax: 0x%lx != 0x%lx\n", pContext->Eax, continueContext.Eax);
104 
105  /* Control registers and segments */
106  ok(pContext->Ebp == continueContext.Ebp,
107  "Ebp: 0x%lx != 0x%lx\n", pContext->Ebp, continueContext.Ebp);
108  ok(pContext->Eip == continueContext.Eip,
109  "Eip: 0x%lx != 0x%lx\n", pContext->Eip, continueContext.Eip);
110  ok(pContext->Esp == continueContext.Esp,
111  "Esp: 0x%lx != 0x%lx\n", pContext->Esp, continueContext.Esp);
112 
113  ok((pContext->SegCs & NTC_SEGMENT_BITS) ==
114  (continueContext.SegCs & NTC_SEGMENT_BITS),
115  "SegCs: 0x%lx != 0x%lx\n", pContext->SegCs, continueContext.SegCs);
116 
117  ok((pContext->EFlags & NTC_EFLAGS_BITS) ==
118  (continueContext.EFlags & NTC_EFLAGS_BITS),
119  "EFlags: 0x%lx != 0x%lx\n", pContext->EFlags, continueContext.EFlags);
120 
121  ok((pContext->SegSs & NTC_SEGMENT_BITS) ==
122  (continueContext.SegSs & NTC_SEGMENT_BITS),
123  "SegSs: 0x%lx != 0x%lx\n", pContext->SegSs, continueContext.SegSs);
124 #endif
125 
126  /* Return where we came from */
127  longjmp(jmpbuf, 1);
128 }
ULONG Esp
Definition: nt_native.h:1479
ULONG Eip
Definition: nt_native.h:1476
ULONG Ecx
Definition: nt_native.h:1467
ULONG SegGs
Definition: nt_native.h:1453
ULONG SegFs
Definition: nt_native.h:1454
ULONG SegDs
Definition: nt_native.h:1456
ULONG SegEs
Definition: nt_native.h:1455
ULONG Esi
Definition: nt_native.h:1464
ULONG SegCs
Definition: nt_native.h:1477
ULONG Edx
Definition: nt_native.h:1466
ULONG EFlags
Definition: nt_native.h:1478
ULONG Ebx
Definition: nt_native.h:1465
int longjmp(jmp_buf buf, int retval)
ULONG ContextFlags
Definition: nt_native.h:1426
#define CONTEXT_FULL
Definition: nt_native.h:1375
static CONTEXT continueContext
Definition: NtContinue.c:21
ULONG Eax
Definition: nt_native.h:1468
ULONG SegSs
Definition: nt_native.h:1480
#define ok(value,...)
Definition: atltest.h:57
static jmp_buf jmpbuf
Definition: NtContinue.c:20
ULONG Ebp
Definition: nt_native.h:1475
ULONG Edi
Definition: nt_native.h:1463

Referenced by _BitScanReverse(), _find_font_for_range(), cache_basic_authorization(), check_admin_rights(), check_format(), check_reg_dword(), check_reg_str(), checkChainPolicyStatus(), CheckMenuRadioItem(), ComputeNormal(), CRYPT_CheckRestrictedRoot(), DocumentMgr_Push(), enum_stream_names(), ext4_ext_space_block(), ext4_ext_space_block_idx(), ext4_ext_space_root(), ext4_ext_space_root_idx(), get_cluster_size(), getwinmetafilebits(), inflateValidate(), isCmd(), isCmdWithArg(), IsOpt(), ITERATE_FindRelatedProducts(), KeystrokeMgr_AdviseKeyEventSink(), KeystrokeMgr_UnadviseKeyEventSink(), licence_process_issue(), msi_set_sourcedir_props(), np_enum(), parse_consonant_syllable(), save_mfpict(), ScriptCPtoX(), CListView::SetCheckState(), test_pbo_functionality(), test_texture_qi(), ThreadMgr_SetFocus(), VerifyObjectOwner(), wWinMain(), xmlParseConditionalSections(), xmlParseExternalSubset(), xmlParseInternalSubset(), xsltCheckRead(), xsltCheckWrite(), and xsltCheckWritePath().

◆ continuePoint()

void continuePoint ( void  )

Referenced by START_TEST().

◆ initrand()

static int initrand ( void  )
static

Definition at line 24 of file NtContinue.c.

25 {
26  unsigned int nRandMax;
27  unsigned int nRandMaxBits;
28  time_t tLoc;
29 
30  nRandMax = RAND_MAX;
31  for(nRandMaxBits = 0; nRandMax != 0; nRandMax >>= 1, ++ nRandMaxBits);
32  nRandBytes = nRandMaxBits / CHAR_BIT;
33  //assert(nRandBytes != 0);
34  srand((unsigned)(time(&tLoc) & UINT_MAX));
35  return 1;
36 }
static unsigned int nRandBytes
Definition: NtContinue.c:22
void __cdecl srand(_In_ unsigned int _Seed)
#define CHAR_BIT
Definition: urlcache.c:58
__u16 time
Definition: mkdosfs.c:366
#define RAND_MAX
Definition: stdlib.h:99
#define UINT_MAX
Definition: limits.h:41
__kernel_time_t time_t
Definition: linux.h:252

Referenced by START_TEST().

◆ randbytes()

static void randbytes ( void p,
size_t  n 
)
static

Definition at line 38 of file NtContinue.c.

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

Referenced by randULONG().

◆ randULONG()

static ULONG randULONG ( void  )
static

Definition at line 54 of file NtContinue.c.

55 {
56  ULONG n;
57  randbytes(&n, sizeof(n));
58  return n;
59 }
GLdouble n
Definition: glext.h:7729
unsigned int ULONG
Definition: retypes.h:1
static void randbytes(void *p, size_t n)
Definition: NtContinue.c:38

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( NtContinue  )

Definition at line 130 of file NtContinue.c.

131 {
132 #ifdef __RUNTIME_CHECKS__
133  skip("This test breaks MSVC runtime checks!\n");
134  return;
135 #endif /* __RUNTIME_CHECKS__ */
136  initrand();
137 
138  /* First time */
139  if(setjmp(jmpbuf) == 0)
140  {
141  CONTEXT bogus;
142 
145 
146 #ifdef _M_IX86
148 
149  /* Fill the integer registers with random values */
157 
158  /* Randomize all the allowed flags (determined experimentally with WinDbg) */
159  continueContext.EFlags = randULONG() & 0x3C0CD5;
160 
161  /* Randomize the stack pointer as much as possible */
162  continueContext.Esp = (ULONG)(((ULONG_PTR)&bogus) & 0xFFFFFFFF) +
163  sizeof(bogus) - (randULONG() & 0xF) * 4;
164 
165  /* continuePoint() is implemented in assembler */
166  continueContext.Eip = (ULONG)((ULONG_PTR)continuePoint & 0xFFFFFFF);
167 
168  /* Can't do a lot about segments */
169 #elif defined(_M_AMD64)
171 
172  /* Fill the integer registers with random values */
173  continueContext.Rdi = randULONG64();
174  continueContext.Rsi = randULONG64();
175  continueContext.Rbx = randULONG64();
176  continueContext.Rdx = randULONG64();
177  continueContext.Rcx = randULONG64();
178  continueContext.Rax = randULONG64();
179  continueContext.Rbp = randULONG64();
180 
181  /* Randomize all the allowed flags (determined experimentally with WinDbg) */
182  continueContext.EFlags = randULONG64() & 0x3C0CD5;
183 
184  /* Randomize the stack pointer as much as possible */
185  continueContext.Rsp = (((ULONG_PTR)&bogus)) +
186  sizeof(bogus) - (randULONG() & 0xF) * 4;
187 
188  /* continuePoint() is implemented in assembler */
189  //continueContext.Rip = ((ULONG_PTR)continuePoint);
190  skip("NtContinue test does not yet work on x64.");
191  return;
192 #endif
193 
195  ok(0, "should never get here\n");
196  }
197 
198  /* Second time */
199  return;
200 }
ULONG Esp
Definition: nt_native.h:1479
ULONG Eip
Definition: nt_native.h:1476
ULONG Ecx
Definition: nt_native.h:1467
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOL WINAPI GetThreadContext(IN HANDLE hThread, OUT LPCONTEXT lpContext)
Definition: thread.c:500
#define FALSE
Definition: types.h:117
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
NTSTATUS NTAPI NtContinue(IN PCONTEXT Context, IN BOOLEAN TestAlert)
Definition: except.c:212
ULONG Esi
Definition: nt_native.h:1464
ULONG Edx
Definition: nt_native.h:1466
ULONG EFlags
Definition: nt_native.h:1478
ULONG Ebx
Definition: nt_native.h:1465
ULONG ContextFlags
Definition: nt_native.h:1426
#define CONTEXT_FULL
Definition: nt_native.h:1375
static CONTEXT continueContext
Definition: NtContinue.c:21
static ULONG randULONG(void)
Definition: NtContinue.c:54
void continuePoint(void)
ULONG Eax
Definition: nt_native.h:1468
static int initrand(void)
Definition: NtContinue.c:24
#define ok(value,...)
Definition: atltest.h:57
#define setjmp
Definition: setjmp.h:183
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static jmp_buf jmpbuf
Definition: NtContinue.c:20
ULONG Ebp
Definition: nt_native.h:1475
ULONG Edi
Definition: nt_native.h:1463

Variable Documentation

◆ continueContext

CONTEXT continueContext
static

Definition at line 21 of file NtContinue.c.

Referenced by check(), and START_TEST().

◆ jmpbuf

jmp_buf jmpbuf
static

Definition at line 20 of file NtContinue.c.

Referenced by check(), and START_TEST().

◆ nRandBytes

unsigned int nRandBytes
static

Definition at line 22 of file NtContinue.c.

Referenced by initrand(), and randbytes().