+ Win64 SEH: install a top-level exception handler around thread functions. This was a missing puzzle piece of SEH support. Now behavior of unhandled exceptions in non-main threads is consistent with that of main thread, and, in general, behavior of SEH-enabled RTL is consistent with one without SEH.

git-svn-id: trunk@23482 -
This commit is contained in:
sergei 2013-01-21 17:16:15 +00:00
parent 40c510403f
commit 6788fd6433
2 changed files with 20 additions and 13 deletions

View File

@ -225,7 +225,12 @@ var
{$ifdef DEBUG_MT}
writeln('Jumping to thread function of thread ',Win32GetCurrentThreadId);
{$endif DEBUG_MT}
{$ifdef FPC_USE_WIN64_SEH}
{ use special 'top-level' exception handler around the thread function }
ThreadMain:=main_wrapper(ti.p,pointer(ti.f));
{$else FPC_USE_WIN64_SEH}
ThreadMain:=ti.f(ti.p);
{$endif FPC_USE_WIN64_SEH}
end;

View File

@ -125,6 +125,19 @@ implementation
var
SysInstance : qword;public;
{$ifdef FPC_USE_WIN64_SEH}
function main_wrapper(arg: Pointer; proc: Pointer): ptrint; assembler; nostackframe;
asm
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call %rdx { "arg" is passed in %rcx }
nop { this nop is critical for exception handling }
addq $40, %rsp
.seh_handler __FPC_default_handler,@except,@unwind
end;
{$endif FPC_USE_WIN64_SEH}
{ include system independent routines }
{$I system.inc}
@ -179,18 +192,6 @@ var
to check if the call stack can be written on exceptions }
_SS : Cardinal;
{$ifdef FPC_USE_WIN64_SEH}
procedure main_wrapper(p: TProcedure); assembler; nostackframe;
asm
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call %rcx
nop { this nop is critical for exception handling }
addq $40, %rsp
.seh_handler __FPC_default_handler,@except,@unwind
end;
{$endif FPC_USE_WIN64_SEH}
procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
@ -209,7 +210,8 @@ procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
movq %rbp,%rsi
xorq %rbp,%rbp
{$ifdef FPC_USE_WIN64_SEH}
lea PASCALMAIN(%rip),%rcx
xor %rcx,%rcx
lea PASCALMAIN(%rip),%rdx
call main_wrapper
{$else FPC_USE_WIN64_SEH}
call PASCALMAIN