#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <excpt.h>

void *ESP,*EBP;

int main()
{
    __asm__ __volatile__ (
             "movl %esp, _ESP" "\n\t"
             "movl %ebp, _EBP");

    __asm__ __volatile__ (
             "pushl $__except_handler" "\n\t"
             "pushl %fs:0" "\n\t"
             "mov %esp, %fs:0");

    *(PDWORD) 0 = 0;

    __asm__ __volatile__ (
             "main_reentry:" "\n\t"
             "movl _ESP, %esp" "\n\t"
             "movl _EBP, %ebp");

    __asm__ __volatile__ (
             "mov (%esp), %eax" "\n\t"
             "mov %eax, %fs:0" "\n\t"
             "add $8, %esp");

    printf( "Hello from handler\n" );
    return 0;
}

EXCEPTION_DISPOSITION
_except_handler(
    struct _EXCEPTION_RECORD *ExceptionRecord,
    void * EstablisherFrame,
    struct _CONTEXT *ContextRecord,
    void * DispatcherContext )
{
    // Indicate that we made it to our exception handler
    printf( "Hello from handler function\n" );

    __asm__ __volatile__ (
             "jmp main_reentry");

    return 0;
}

