-sigtrap_emulator(CONTEXT *context,
- struct lisp_exception_frame *exception_frame)
-{
- if (*((char *)context->Eip + 1) == trap_ContextRestore) {
- /* This is the cleanup for what is immediately below, and
- * for the generic exception handling further below. We
- * have to memcpy() the original context (emulated sigtrap
- * or normal exception) over our context and resume it. */
- memcpy(context, &exception_frame->context, sizeof(CONTEXT));
- return ExceptionContinueExecution;
-
- } else {
- /* Not a trap_ContextRestore, must be a sigtrap.
- * sigtrap_trampoline is defined in x86-assem.S. */
- extern void sigtrap_trampoline;
-
- /*
- * Unlike some other operating systems, Win32 leaves EIP
- * pointing to the breakpoint instruction.
- */
- context->Eip++;
-
- /* We're not on an alternate stack like we would be in some
- * other operating systems, and we don't want to risk leaking
- * any important resources if we throw out of the sigtrap
- * handler, so we need to copy off our context to a "safe"
- * place and then monkey with the return EIP to point to a
- * trampoline which calls another function which copies the
- * context out to a really-safe place and then calls the real
- * sigtrap handler. When the real sigtrap handler returns, the
- * trampoline then contains another breakpoint with a code of
- * trap_ContextRestore (see above). Essentially the same
- * mechanism is used by the generic exception path. There is
- * a small window of opportunity between us copying the
- * context to the "safe" place and the sigtrap wrapper copying
- * it to the really-safe place (allocated in its stack frame)
- * during which the context can be smashed. The only scenario
- * I can come up with for this, however, involves a stack
- * overflow occuring at just the wrong time (which makes one
- * wonder how stack overflow exceptions even happen, given
- * that we don't switch stacks for exception processing...) */
- memcpy(&exception_frame->context, context, sizeof(CONTEXT));
-
- /* FIXME: Why do we save the old EIP in EAX? The sigtrap_trampoline
- * pushes it into stack, but the sigtrap_wrapper where the trampoline
- * goes ignores it, and after the wrapper we hit the trap_ContextRestore,
- * which nukes the whole context with the original one?
- *
- * Am I misreading this, or is the EAX here and in the
- * trampoline superfluous? --NS 20061024 */
- context->Eax = context->Eip;
- context->Eip = (unsigned long)&sigtrap_trampoline;
-
- /* and return */
- return ExceptionContinueExecution;
- }
-}
-
-void sigtrap_wrapper(void)
-{
- /*
- * This is the wrapper around the sigtrap handler called from
- * the trampoline returned to from the function above.
- *
- * There actually is a point to some of the commented-out code
- * in this function, although it really belongs to the callback
- * wrappers. Once it is installed there, it can probably be
- * removed from here.
- */
- extern void sigtrap_handler(int signal, siginfo_t *info, void *context);
-
-/* volatile struct { */
-/* void *handler[2]; */
- CONTEXT context;
-/* } handler; */
-
- struct lisp_exception_frame *frame = find_our_seh_frame();
-
-/* wos_install_interrupt_handlers(handler); */
-/* handler.handler[0] = get_seh_frame(); */
-/* handler.handler[1] = &handle_exception; */
-/* set_seh_frame(&handler); */
-
- memcpy(&context, &frame->context, sizeof(CONTEXT));
- sigtrap_handler(0, NULL, &context);
- memcpy(&frame->context, &context, sizeof(CONTEXT));
-
-/* set_seh_frame(handler.handler[0]); */
-}
-
-EXCEPTION_DISPOSITION