Incorrect exceptions processing
Original Reporter info from Mantis: Bishop
-
Reporter name: Emelyanov Roman
Original Reporter info from Mantis: Bishop
- Reporter name: Emelyanov Roman
Description:
Win64 use very specific exception mechanism called SEH64. It required from compiler to make specific section in exe-file with information about exception handling. This information for pascal function generated automatically, but not for assembler functions.
Below i show example of the problem. There are two question:
- Is it possible to generate this information automatically?
- And if not, how to specific it manually for functions that wrote in Intel assembler syntax?
Steps to reproduce:
Program App;
{$MODE OBJFPC}
Procedure PasException; Begin{$IFDEF CRTL}PWord8{$ELSE}PByte{$ENDIF}(0)^ := 0; End;
{ASMMODE ATT}<br/> Procedure ATTAsmException; Assembler; NoStackFrame;<br/> Asm<br/> .seh_endprologue<br/> XORQ %RAX, %RAX; MOVB %AL, (%RAX)<br/> .seh_handler {IFDEF CRTL}__FPC_specific_handler{ELSE}__FPC_default_handler{ENDIF}
End;
Procedure ATTAsmProxy; Begin ATTAsmException; End;
Procedure ATTAsmException2; Assembler; NoStackFrame;
Asm
subq $80, %rsp
.seh_stackalloc 80
.seh_endprologue
XORQ %RAX, %RAX; MOVB %AL, (%RAX)
addq 80, %rsp<br/> .seh_handler {IFDEF CRTL}__FPC_specific_handler{ELSE}__FPC_default_handler{ENDIF}
End;
Procedure ATTAsmProxy2; Begin ATTAsmException2; End;
{$ASMMODE INTEL}
Procedure IntelAsmException; Assembler; NoStackFrame;
Asm
XOR RAX, RAX; MOV [RAX], AL
End;
Procedure InterAsmProxy; Begin IntelAsmException; End;
Procedure IntelAsmException2; Assembler; NoStackFrame;
Asm
SUB RSP, 128
XOR RAX, RAX; MOV [RAX], AL
ADD RSP, 128
End;
Procedure InterAsmProxy2; Begin IntelAsmException2; End;
BEGIN
Try Write('Raising exception from pas-code...'); PasException Except WriteLn('exception catched') End;
Try Write('Raising exception from AT&T asm-code..'); ATTAsmException Except WriteLn('exception catched') End;
Try Write('Raising exception from AT&T asm-code with RSP change..'); ATTAsmException2 Except WriteLn('exception catched') End;
Try Write('Raising exception from proxy to AT&T asm-code..'); ATTAsmProxy Except WriteLn('exception catched') End;
Try Write('Raising exception from proxy to AT&T asm-code with RSP change..'); ATTAsmProxy2 Except WriteLn('exception catched') End;
Try Write('Raising exception from intel asm-code..'); IntelAsmException Except WriteLn('exception catched') End;
Try Write('Raising exception from intel asm-code with RSP change..'); IntelAsmException2 Except WriteLn('exception catched') End;
Try Write('Raising exception from proxy to intel asm-code..'); InterAsmProxy Except WriteLn('exception catched') End;
Try Write('Raising exception from proxy to intel asm-code with RSP change..'); InterAsmProxy2 Except WriteLn('exception catched') End;
END.
Additional information:
In standard RTL example fail on calling PasException with code 216. In my project i use my own RTL, so it work correct until calling InterAsmProxy2.
Mantis conversion info:
- Mantis ID: 26056
- OS: Windows
- OS Build: 7
- Build: 27633
- Platform: x86_64
- Version: 2.7.1
- Monitored by: » Bishop (Emelyanov Roman)