Browse Source

* RtlUnwind destroys register, so save and restore them afterwards

florian 4 months ago
parent
commit
fb126e32f9
1 changed files with 18 additions and 0 deletions
  1. 18 0
      rtl/win32/seh32.inc

+ 18 - 0
rtl/win32/seh32.inc

@@ -275,6 +275,8 @@ procedure CommonHandler(
 var
 var
   Exc: TExceptObject;
   Exc: TExceptObject;
   code: Longint;
   code: Longint;
+  _oldebx,_oldedi,_oldesi,
+  _ebx,_edi,_esi: dword;
 begin
 begin
   if rec.ExceptionCode<>FPC_EXCEPTION_CODE then
   if rec.ExceptionCode<>FPC_EXCEPTION_CODE then
   begin
   begin
@@ -297,7 +299,20 @@ begin
     Exc.Frames:=rec.ExceptionInformation[3];
     Exc.Frames:=rec.ExceptionInformation[3];
   end;
   end;
 
 
+  asm
+    movl %ebx,_oldebx
+    movl %esi,_oldesi
+    movl %edi,_oldedi
+  end;
   RtlUnwind(@frame,nil,@rec,nil);
   RtlUnwind(@frame,nil,@rec,nil);
+  asm
+    movl %ebx,_ebx
+    movl %esi,_esi
+    movl %edi,_edi
+    movl _oldebx,%ebx
+    movl _oldesi,%esi
+    movl _oldedi,%edi
+  end;
 
 
   Exc.Refcount:=0;
   Exc.Refcount:=0;
   Exc.SEHFrame:=@frame;
   Exc.SEHFrame:=@frame;
@@ -312,6 +327,9 @@ begin
       movl   Exc.FObject,%eax
       movl   Exc.FObject,%eax
       movl   frame,%edx
       movl   frame,%edx
       movl   TargetAddr,%ecx              // load ebp-based var before changing ebp
       movl   TargetAddr,%ecx              // load ebp-based var before changing ebp
+      movl   _ebx,%ebx
+      movl   _esi,%esi
+      movl   _edi,%edi
       movl   TSEHFrame._EBP(%edx),%ebp
       movl   TSEHFrame._EBP(%edx),%ebp
       jmpl   *%ecx
       jmpl   *%ecx
   end;
   end;