flat assembler
Message board for the users of flat assembler.

Index > Windows > Win64 Exception handling

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 344
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
I added exception handling by:

AddVectoredExceptionHandler(1,@Handler);

How to tell if an exception was generated by hardware or by RaiseException() ?
Code:
var
  ExceptionHex:LongInt;
  ExceptionPtr:Pointer = nil;

procedure ShowExc;
begin
  WriteLn(WideString('Exception 0x'+Hex8(ExceptionHex)+' at 0x'+HexI(Int64(ExceptionPtr))));
  Halt;
end;

function Handler(Excep:PExceptionPointers):LongInt;
asm
        MOV     RAX,[RCX+8]
        MOV     RAX,[RAX+Context64.&RIP]
        CMP     [RAX].Byte,$CC
        JNZ     @Print
        MOV     RAX,[RCX+8]
        INC     [RAX+Context64.&RIP]
        JMP     @Quits
@Exits: XOR     EAX,EAX // EXCEPTION_CONTINUE_SEARCH
        RET
@Print: //
        CMP     [ExceptionPtr],0
        JNZ     @Exits
        MOV     RAX,[RCX+0]
        MOV     EAX,[RAX]
        MOV     [ExceptionHex],EAX
        LEA     RDX,[ShowExc]
        MOV     RAX,[RCX+8]
        XCHG    RDX,[RAX+Context64.&RIP]
        MOV     [ExceptionPtr],RDX
        //
@Quits: MOV     EAX,-1  // EXCEPTION_CONTINUE_EXECUTION
end;

procedure AddException; inline;
begin
  if not IsDebuggerPresent then
    AddVectoredExceptionHandler(1,@Handler);
end;    

_________________
smaller is better
Post 26 Aug 2021, 09:21
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3386
Location: vpcmipstrm
bitRAKE
Custom error code, or unique parameter(s) passed by RaiseException().
Post 26 Aug 2021, 17:27
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.