Skip to content
Tcl Source Code Attachment Details
Login

Attachment Details

Overview

Artifact ID: df0661e47a963f442d515efb36b177a78fc4863e
Ticket: 525746ffffffffffffffffffffffffffffffffff
Date: 2002-03-08 07:46:40
User: mdejong
Artifact Attached: 8a613e833aa0e915b73922502308555317d1fc86
Filename:handler.c
Description:example of jumping back into function
Content:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
#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;
}