Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Exceptions    [ Add a report in this area ]  
Report #:  107209   Status: Open
An external exception raised inside a DLL may modify the FPU control word
Project:  Delphi Build #:  16.0.4504.48759
Version:    16.4 Submitted By:   Pierre le Riche
Report Type:  Crash / Data loss / Total failure Date Reported:  7/18/2012 12:31:15 PM
Severity:    Serious / Highly visible problem Last Updated: 7/19/2012 12:46:02 AM
Platform:    All platforms Internal Tracking #:   30115
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 20
Description
If an external exception is raised inside a DLL, then the FPU control word may be modified.  This is because of the calls to _FpuInit inside the exception processing code in system.pas and the fact that the value of Default8087CW in the DLL may not be the same as the Default8087CW in the main application.

See the attached test case for an example.
Steps to Reproduce:
1) Compile the test DLL
2) Compile and run the two test applications (static and dynamic loading)

Expected:  Both tests pass
Actual: Both tests fail

[TestDLL.dpr]
------------------------------
library TestDLL;

uses
  SysUtils,
  Classes;

{$R *.res}

procedure DLLTestProc;
begin
  try
    PInteger(0)^ := 0;
  except
  end;
end;

exports
  DLLTestProc;

begin
end.
------------------------------

[StaticLoadTest.dpr]
------------------------------
program StaticLoadTest;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  DLLName = 'TestDLL.dll';
  DLLTestProcName = 'DLLTestProc';

procedure DLLTestProc; external DLLName name DLLTestProcName;

function RunTest: Boolean;
var
  LOldCW, LNewCW: Word;
begin
  LOldCW := Get8087CW;
  DLLTestProc;
  LNewCW := Get8087CW;

  Result := LOldCW = LNewCW;
end;

begin
  if RunTest then
    WriteLn('PASS')
  else
    WriteLn('FAIL');
end.
------------------------------
Workarounds
None
Attachment
QC107209.zip
Comments

Tomohiro Takahashi at 7/19/2012 5:52:26 PM -
This report was opened with valid Internal Tracking Number.
Thanks.

Server Response from: ETNACODE01