diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
commit | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch) | |
tree | dc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/samples/seh/sehfix.c | |
parent | 369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff) |
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/samples/seh/sehfix.c')
-rw-r--r-- | winsup/mingw/samples/seh/sehfix.c | 60 |
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");
+}
+
+
|