珞珈山水BBS电脑网络程序人生 → 单文区文章阅读

单文区文章阅读 [返回]
发信人: buttcher (不是屠夫⊙网者归来), 信区: Programm
标  题: Re: 问一下啥编译器支持内联的汇编函数
发信站: 珞珈山水BBS站 (Tue Dec 13 22:01:17 2005), 转信

//==================================================
// MYSEH - Matt Pietrek 1997
// Microsoft Systems Journal, January 1997
// file: MYSEH.CPP
// To compile: CL MYSEH.CPP
//==================================================
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

DWORD  scratch;

EXCEPTION_DISPOSITION
__cdecl
_except_handler(
    struct _EXCEPTION_RECORD *ExceptionRecord,
    void * EstablisherFrame,
    struct _CONTEXT *ContextRecord,
    void * DispatcherContext )
{
    unsigned i;

    // Indicate that we made it to our exception handler
    printf( "Hello from an exception handler\n" );

    // Change EAX in the context record so that it points to someplace
    // where we can successfully write
    ContextRecord->Eax = (DWORD)&scratch;

    // Tell the OS to restart the faulting instruction
    return ExceptionContinueExecution;
}

int main()
{
    DWORD handler = (DWORD)_except_handler;

    __asm
    {                           // Build EXCEPTION_REGISTRATION record:
        push    handler         // Address of handler function
        push    FS:[0]          // Address of previous handler
        mov     FS:[0],ESP      // Install new EXECEPTION_REGISTRATION
    }

    __asm
    {
        mov     eax,0           // Zero out EAX
        mov     [eax], 1        // Write to EAX to deliberately cause a fault
    }

    printf( "After writing!\n" );

    __asm
    {                           // Remove our EXECEPTION_REGISTRATION record
        mov     eax,[ESP]       // Get pointer to previous record
        mov     FS:[0], EAX     // Install previous record
        add     esp, 8          // Clean our EXECEPTION_REGISTRATION off stack
    }

    return 0;
}

【 在 simple (只爱株株★孤独的人会迷失自我★E.I.S☆) 的大作中提到: 】
: 好像vc不支持……


--
       ───────────╮  ╭──╮╭──╮───────────╮
 
      _                     ╰╮│2208││6711│                      ╰╮
 
  │ |_  _ .  _  _  _|  _  _| │╰──\ ╰──\┌──┐                 │
 
  │ |  |  | (╯(│(_| (╯(_| │           │  ╲╱buttcher@163.com 
 
  ╰╮                       有 朋 友 的 人╰╮└──┘                   
 
    ╰────────────               ╰────────────


※ 来源:·珞珈山水BBS站 bbs.whu.edu.cn·[FROM: 218.81.235.*]
[返回单文区目录]

武汉大学BBS 珞珈山水站 All rights reserved.
wForum , 页面执行时间:14.051毫秒