Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sehfix.c « seh « samples « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a414e649e0682d5ce07c0b3cef16efd634607d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * sehfix.c
 *
 * A test program involving an exception handler that fixes the exception
 * causing condition.
 *
 * In this code we install an exception handler my_handler and then a piece
 * of inline assembly attempts to write at the address marked in eax, after
 * setting eax to 10. This should produce an exception. The handler then
 * changes the eax register of the exception context to be the address of
 * a static variable and restarts the code. This should allow everything
 * to continue.
 */

#include <windows.h>
#include <excpt.h>

#include "exutil.h"

int	x;

EXCEPTION_DISPOSITION
my_handler (
	struct _EXCEPTION_RECORD* pExceptionRec,
	void* pEstablisherFrame,
	struct _CONTEXT* pContextRecord,
	void* pDispatcherContext
	)
{
	printf ("In my exception handler!\n");
	DumpExceptionRecord (pExceptionRec);
	pContextRecord->Eax = (DWORD) &x;
	return ExceptionContinueExecution;
}

main ()
{
	x = 2;

	printf ("x = %d\n", x);

	WalkExceptionHandlers();

	__try1(my_handler)

	WalkExceptionHandlers();

	/* This assembly code should produce an exception. */
	__asm__("movl $10,%%eax;movl $1,(%%eax);" : : : "%eax");

	__except1

	WalkExceptionHandlers();

	printf ("x = %d\n", x);

	printf ("Finished!\n");
}