[Openmcl-cvs-notifications] r10921 - /trunk/source/lisp-kernel/x86-exceptions.c
gb at clozure.com
gb at clozure.com
Tue Sep 30 07:07:45 EDT 2008
Author: gb
Date: Tue Sep 30 07:07:45 2008
New Revision: 10921
Log:
In windows_arbstack_exception_handler: insist that we're running on
some stack other than the C stack when the exception occurs (in general,
we aren't going to be able to do much about exceptions that happen on
the C stack, anyway.) Always build a (copy of) the exception context/
info on the foreign stack; don't switch to the foreign stack from the
handler, but setup the exception context we were called with to enter
the higher-level exception handler when it's resumed, and tell the OS
to resume execution. (While we're at it, arrange that the higher-level
handler gets the TCR as an argument, to avoid having to look it up again.)
This allows the Windows runtime to clean up after itself after
returning from the low-level handler (releasing locks, etc.), and has
the effect of calling our higher-level handler on the foreign stack
with a copy of the original exception context/info.
(If there was ever any reason to, we could do the stack switch the
same way on other platforms. On non-Mach systems, I think that the
handler is called directly from the kernel and on Darwin we generally
fake things using Mach exception-handling futilities, so there doesn't
seem to be any need for this elsewhere.)
Modified:
trunk/source/lisp-kernel/x86-exceptions.c
Modified: trunk/source/lisp-kernel/x86-exceptions.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/source/lisp-kernel/x86-exceptions.c (original)
+++ trunk/source/lisp-kernel/x86-exceptions.c Tue Sep 30 07:07:45 2008
@@ -1746,9 +1746,8 @@
=
=
LONG
-windows_exception_handler(EXCEPTION_POINTERS *exception_pointers)
-{
- TCR *tcr =3D get_tcr(false);
+windows_exception_handler(EXCEPTION_POINTERS *exception_pointers, TCR *tcr)
+{
DWORD code =3D exception_pointers->ExceptionRecord->ExceptionCode;
int old_valence, signal_number;
ExceptionInformation *context =3D exception_pointers->ContextRecord;
@@ -1774,13 +1773,37 @@
return restore_windows_context(context, tcr, old_valence);
}
=
-LONG windows_switch_to_foreign_stack(LispObj, void*, void*);
-
-LONG
-handle_windows_exception_on_foreign_stack(TCR *tcr,
- CONTEXT *context,
- void *handler,
- EXCEPTION_POINTERS *original_ep)
+void
+setup_exception_handler_call(CONTEXT *context,
+ LispObj new_sp,
+ void *handler,
+ EXCEPTION_POINTERS *new_ep,
+ TCR *tcr)
+{
+ extern void windows_halt(void);
+ LispObj *p =3D (LispObj *)new_sp;
+#ifdef WIN_64
+ p-=3D4; /* win64 abi argsave nonsense */
+ *(--p) =3D (LispObj)windows_halt;
+ context->Rsp =3D (DWORD64)p;
+ context->Rip =3D (DWORD64)handler;
+ context->Rcx =3D (DWORD64)new_ep;
+ context->Rdx =3D (DWORD64)tcr;
+#else
+ p-=3D4; /* args on stack, stack aligned */
+ p[0] =3D (LispObj)new_ep;
+ p[1] =3D (LispObj)tcr;
+ *(--p) =3D (LispObj)windows_halt;
+ context->Esp =3D (DWORD)p;
+ context->Eip =3D (DWORD)handler;
+#endif
+}
+
+void
+prepare_to_handle_windows_exception_on_foreign_stack(TCR *tcr,
+ CONTEXT *context,
+ void *handler,
+ EXCEPTION_POINTERS *o=
riginal_ep)
{
LispObj foreign_rsp =3D =
(LispObj) find_foreign_rsp(xpGPR(context,Isp), tcr->cs_area, tcr);
@@ -1798,7 +1821,7 @@
foreign_rsp =3D (LispObj)new_ep & ~15;
new_ep->ContextRecord =3D new_context;
new_ep->ExceptionRecord =3D new_info;
- return windows_switch_to_foreign_stack(foreign_rsp,handler,new_ep);
+ setup_exception_handler_call(context,foreign_rsp,handler,new_ep, tcr);
}
=
LONG CALLBACK
@@ -1810,19 +1833,20 @@
return EXCEPTION_CONTINUE_SEARCH;
} else {
TCR *tcr =3D get_interrupt_tcr(false);
- area *vs =3D tcr->vs_area;
+ area *cs =3D tcr->cs_area;
BytePtr current_sp =3D (BytePtr) current_stack_pointer();
- struct _TEB *teb =3D NtCurrentTeb();
+ CONTEXT *context =3D exception_pointers->ContextRecord;
=
- if ((current_sp >=3D vs->low) &&
- (current_sp < vs->high)) {
- return
- handle_windows_exception_on_foreign_stack(tcr,
- exception_pointers->Cont=
extRecord,
- windows_exception_handle=
r,
- exception_pointers);
- }
- return windows_exception_handler(exception_pointers);
+ if ((current_sp >=3D cs->low) &&
+ (current_sp < cs->high)) {
+ FBug(context, "Exception on foreign stack\n");
+ }
+
+ prepare_to_handle_windows_exception_on_foreign_stack(tcr,
+ context,
+ windows_exception=
_handler,
+ exception_pointer=
s);
+ return EXCEPTION_CONTINUE_EXECUTION;
}
}
=
More information about the Openmcl-cvs-notifications
mailing list