ReactOS  0.4.15-dev-5112-g22d8c0f
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 
12 void dojump(jmp_buf JumpBuffer, PLONG Counter) {
13  try {
14  try {
15  /* set Counter = 1 */
16  *Counter += 1;
17  RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0);
18  }
19  finally {
20  /* set counter = 2 */
21  *Counter += 1;
22  }
23  endtry
24  }
25  finally {
26  /* set counter = 3 */
27  *Counter += 1;
28  longjmp(JumpBuffer, 1);
29  }
30  endtry
31 }
32 
33 int main() {
34  jmp_buf JumpBuffer;
35  LONG Counter;
36 
37  Counter = 0;
38 
39  if (_setjmp(JumpBuffer) == 0) {
40  try {
41  try {
42  try {
43  try {
44  *(volatile LONG*)&Counter += 1;
45  dojump(JumpBuffer, &Counter);
46  }
47  finally { *(volatile LONG*)&Counter += 1; }
48  endtry
49  }
50  finally {
51  *(volatile LONG*)&Counter += 1;
52  longjmp(JumpBuffer, 1);
53  }
54  endtry
55  }
56  finally { *(volatile LONG*)&Counter += 1; }
57  endtry
58  }
59  except(1)
60  /* EXECUTE HANDLER after unwinding */
61  {
62  *(volatile LONG*)&Counter += 1;
63  }
64  endtry
65  } else {
66  /* set Counter = 4 */ //
67  *(volatile LONG*)&Counter += 1;
68  }
69 
70  if (Counter != 8) {
71  printf("TEST 26 FAILED. Counter = %d\n\r", Counter);
72  return -1;
73  }
74 
75  return 0;
76 }
#define endtry
Definition: seh.h:24
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:321
void dojump(jmp_buf JumpBuffer, PLONG Counter)
Definition: seh0026.c:12
long LONG
Definition: pedump.c:60
#define printf
Definition: freeldr.h:94
char test[]
Definition: seh0026.c:10
#define except(x)
Definition: btrfs_drv.h:136
_JBTYPE jmp_buf[_JBLEN]
Definition: setjmp.h:186
int main()
Definition: seh0026.c:33
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
signed int * PLONG
Definition: retypes.h:5