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

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/mingw/samples/seh/sehfix.c')
-rw-r--r--winsup/mingw/samples/seh/sehfix.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/winsup/mingw/samples/seh/sehfix.c b/winsup/mingw/samples/seh/sehfix.c
new file mode 100644
index 000000000..1a414e649
--- /dev/null
+++ b/winsup/mingw/samples/seh/sehfix.c
@@ -0,0 +1,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");
+}
+
+