ReactOS  0.4.14-dev-315-gbb6fece
SetUnhandledExceptionFilter.c File Reference
#include "precomp.h"
#include <xmmintrin.h>
Include dependency graph for SetUnhandledExceptionFilter.c:

Go to the source code of this file.

Functions

LONG WINAPI Filter1 (LPEXCEPTION_POINTERS p)
 
LONG WINAPI Filter2 (LPEXCEPTION_POINTERS p)
 
static VOID TestSetUnhandledExceptionFilter (VOID)
 
static LONG WINAPI ExceptionFilterSSESupport (LPEXCEPTION_POINTERS exp)
 
static LONG WINAPI ExceptionFilterSSEException (LPEXCEPTION_POINTERS exp)
 
static VOID TestSSEExceptions (VOID)
 
 START_TEST (SetUnhandledExceptionFilter)
 

Variables

static BOOL ExceptionCaught = FALSE
 

Function Documentation

◆ ExceptionFilterSSEException()

static LONG WINAPI ExceptionFilterSSEException ( LPEXCEPTION_POINTERS  exp)
static

Definition at line 64 of file SetUnhandledExceptionFilter.c.

65 {
66  PEXCEPTION_RECORD rec = exp->ExceptionRecord;
67  PCONTEXT ctx = exp->ContextRecord;
68 
69  trace("Exception raised while dividing by 0.\n");
70 
71  ok(rec->ExceptionCode == STATUS_FLOAT_MULTIPLE_TRAPS, "Exception code is 0x%08x.\n", (unsigned int)rec->ExceptionCode);
72 
74  {
75  trace("Unexpected exception code, terminating!\n");
77  }
78 
79  ok((ctx->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL, "Context does not contain control register.\n");
80 
82 
83  ctx->Eip += 3;
84 
86 }
#define TRUE
Definition: types.h:120
ULONG Eip
Definition: nt_native.h:1476
static BOOL ExceptionCaught
DWORD ExceptionCode
Definition: compat.h:196
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG ContextFlags
Definition: compat.h:331
#define CONTEXT_CONTROL
Definition: compat.h:265
#define trace
Definition: atltest.h:70
#define STATUS_FLOAT_MULTIPLE_TRAPS
Definition: ntstatus.h:794
#define ok(value,...)
Definition: atltest.h:57
DWORD exp
Definition: msg.c:15681
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by TestSSEExceptions().

◆ ExceptionFilterSSESupport()

static LONG WINAPI ExceptionFilterSSESupport ( LPEXCEPTION_POINTERS  exp)
static

Definition at line 40 of file SetUnhandledExceptionFilter.c.

41 {
42  PEXCEPTION_RECORD rec = exp->ExceptionRecord;
43  PCONTEXT ctx = exp->ContextRecord;
44 
45  trace("Exception raised while using SSE instructions.\n");
46 
47  ok(rec->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION, "Exception code is 0x%08x.\n", (unsigned int)rec->ExceptionCode);
48 
50  {
51  trace("Unexpected exception code, terminating!\n");
53  }
54 
55  ok((ctx->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL, "Context does not contain control register.\n");
56 
57  ctx->Eip += 3;
58 
60 }
ULONG Eip
Definition: nt_native.h:1476
DWORD ExceptionCode
Definition: compat.h:196
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG ContextFlags
Definition: compat.h:331
#define CONTEXT_CONTROL
Definition: compat.h:265
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
DWORD exp
Definition: msg.c:15681
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:324
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by TestSSEExceptions().

◆ Filter1()

Definition at line 16 of file SetUnhandledExceptionFilter.c.

16 { return 0; }

Referenced by TestSetUnhandledExceptionFilter().

◆ Filter2()

Definition at line 17 of file SetUnhandledExceptionFilter.c.

17 { return 1; }

Referenced by TestSetUnhandledExceptionFilter().

◆ START_TEST()

START_TEST ( SetUnhandledExceptionFilter  )

Definition at line 170 of file SetUnhandledExceptionFilter.c.

171 {
174 }
static VOID TestSetUnhandledExceptionFilter(VOID)
static VOID TestSSEExceptions(VOID)

◆ TestSetUnhandledExceptionFilter()

static VOID TestSetUnhandledExceptionFilter ( VOID  )
static

Definition at line 26 of file SetUnhandledExceptionFilter.c.

27 {
31  ok(p1 != Filter1, "SetUnhandledExceptionFilter returned what was set, not prev\n");
32  ok(p2 != Filter2, "SetUnhandledExceptionFilter returned what was set, not prev\n");
33  ok(p2 == Filter1, "SetUnhandledExceptionFilter didn't return previous filter\n");
34  ok(p1 != p2, "SetUnhandledExceptionFilter seems to return random stuff\n");
35 
37  ok(p1 == Filter2, "SetUnhandledExceptionFilter didn't return previous filter\n");
38 }
LONG WINAPI Filter1(LPEXCEPTION_POINTERS p)
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI DECLSPEC_HOTPATCH SetUnhandledExceptionFilter(IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
Definition: except.c:792
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI Filter2(LPEXCEPTION_POINTERS p)
PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER
Definition: winbase.h:1413
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ TestSSEExceptions()

static VOID TestSSEExceptions ( VOID  )
static

Definition at line 89 of file SetUnhandledExceptionFilter.c.

90 {
92  BOOL supportsSSE = FALSE;
93  unsigned int csr;
94 
95  /* Test SSE support for the CPU */
97  ok(p == NULL, "Previous filter should be NULL\n");
98 #ifdef _MSC_VER
99  __asm
100  {
101  xorps xmm0, xmm0
102  mov supportsSSE, 0x1
103  }
104 #else
105  __asm__(
106  "xorps %%xmm0, %%xmm0\n"
107  "movl $1, %0\n"
108  : "=r"(supportsSSE)
109  );
110 #endif /* _MSC_VER */
111  if(!supportsSSE)
112  {
113  skip("CPU doesn't support SSE instructions.\n");
115  return;
116  }
117  /* Deliberately throw a divide by 0 exception */
119  ok(p == ExceptionFilterSSESupport, "Unexpected old filter : 0x%p", p);
120 
121  /* Unmask divide by 0 exception */
122  csr = _mm_getcsr();
123  _mm_setcsr(csr & 0xFFFFFDFF);
124 
125  /* We can't use _mm_div_ps, as it masks the exception before performing anything*/
126 #if defined(_MSC_VER)
127  __asm
128  {
129  xorps xmm0, xmm0
130  push 0x3f800000
131  push 0x3f800000
132  push 0x3f800000
133  push 0x3f800000
134 
135  movups xmm1, [esp]
136 
137  /* Divide by 0 */
138  divps xmm1, xmm0
139 
140  /* Clean up */
141  add esp, 16
142  }
143 #else
144  __asm__ (
145  "xorps %%xmm0, %%xmm0\n"
146  "pushl $0x3f800000\n"
147  "pushl $0x3f800000\n"
148  "pushl $0x3f800000\n"
149  "pushl $0x3f800000\n"
150  "movups (%%esp), %%xmm1\n"
151 
152  /* Divide by 0 */
153  "divps %%xmm0, %%xmm1\n"
154 
155  /* Clean up */
156  "addl $16, %%esp\n"
157  :
158  );
159 #endif /* _MSC_VER */
160 
161  /* Restore mxcsr */
162  _mm_setcsr(csr);
163 
164  ok(ExceptionCaught, "The exception was not caught.\n");
165 
167  ok(p == ExceptionFilterSSEException, "Unexpected old filter : 0x%p", p);
168 }
int add
Definition: i386-dis.c:3122
static LONG WINAPI ExceptionFilterSSESupport(LPEXCEPTION_POINTERS exp)
static BOOL ExceptionCaught
__INTRIN_INLINE void _mm_setcsr(unsigned int val)
Definition: xmmintrin.h:62
unsigned int BOOL
Definition: ntddk_ex.h:94
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI DECLSPEC_HOTPATCH SetUnhandledExceptionFilter(IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
Definition: except.c:792
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
smooth NULL
Definition: ftsmooth.c:416
__INTRIN_INLINE unsigned int _mm_getcsr(void)
Definition: xmmintrin.h:55
PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER
Definition: winbase.h:1413
static LONG WINAPI ExceptionFilterSSEException(LPEXCEPTION_POINTERS exp)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
GLfloat GLfloat p
Definition: glext.h:8902
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113

Referenced by START_TEST().

Variable Documentation

◆ ExceptionCaught

BOOL ExceptionCaught = FALSE
static

Definition at line 62 of file SetUnhandledExceptionFilter.c.

Referenced by ExceptionFilterSSEException(), and TestSSEExceptions().