ReactOS  0.4.15-dev-2703-g05fb0f1
seh0026.c
Go to the documentation of this file.
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for
3 // full license information.
4 
5 #include <windows.h>
6 #include <setjmp.h>
7 
8 #include "seh.h"
9 
10 char test[] = "SEH0026.c";
11 int perfect;
12 
13 void dojump(jmp_buf JumpBuffer, PLONG Counter) {
14  try {
15  try {
16  /* set Counter = 1 */
17  *Counter += 1;
18  RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0);
19  }
20  finally {
21  /* set counter = 2 */
22  *Counter += 1;
23  }
24  endtry
25  }
26  finally {
27  /* set counter = 3 */
28  *Counter += 1;
29  longjmp(JumpBuffer, 1);
30  }
31  endtry
32 }
33 
34 int main() {
35  jmp_buf JumpBuffer;
36  LONG Counter;
37 
38  Counter = 0;
39 
40  if (_setjmp(JumpBuffer) == 0) {
41  try {
42  try {
43  try {
44  try {
45  *(volatile LONG*)&Counter += 1;
46  dojump(JumpBuffer, &Counter);
47  }
48  finally { *(volatile LONG*)&Counter += 1; }
49  endtry
50  }
51  finally {
52  *(volatile LONG*)&Counter += 1;
53  longjmp(JumpBuffer, 1);
54  }
55  endtry
56  }
57  finally { *(volatile LONG*)&Counter += 1; }
58  endtry
59  }
60  except(1)
61  /* EXECUTE HANDLER after unwinding */
62  {
63  *(volatile LONG*)&Counter += 1;
64  }
65  endtry
66  } else {
67  /* set Counter = 4 */ //
68  *(volatile LONG*)&Counter += 1;
69  }
70 
71  if (Counter != 8) {
72  printf("TEST 26 FAILED. Counter = %d\n\r", Counter);
73  return -1;
74  }
75 
76  return 0;
77 }
#define endtry
Definition: seh.h:24
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:321
void dojump(jmp_buf JumpBuffer, PLONG Counter)
Definition: seh0026.c:13
long LONG
Definition: pedump.c:60
int longjmp(jmp_buf buf, int retval)
char test[]
Definition: seh0026.c:10
#define except(x)
Definition: btrfs_drv.h:139
int perfect
Definition: seh0026.c:11
int main()
Definition: seh0026.c:34
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:700
static LARGE_INTEGER Counter
Definition: clock.c:43
long jmp_buf[100]
Definition: of.h:11
signed int * PLONG
Definition: retypes.h:5
#define printf
Definition: config.h:203