lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Alien msvc rtl dll messing with the fpu?


From: Greg Chicares
Subject: Re: [lmi] Alien msvc rtl dll messing with the fpu?
Date: Fri, 13 Jan 2006 03:24:07 +0000
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

On 2006-1-13 3:12 UTC, Greg Chicares wrote:

[snip discussion and tests]

Here's another test that is similarly incapable of inducing the problem.
It tests whether a dll can affect an application's fpu control word.
I find that it can, of course. The DllMain() hook has no effect on the
parent's control word when I run this; that's probably because MinGW's
application startup code sets the control word itself.

So this test looks like another dead end. Yet two people have observed
the problem independently, even though I can't reproduce it myself.
My best guess is that some privileged process (not the msvc rtl dll)
is messing with the control word in a way that bleeds through to lmi.
I'll try surrounding the CreateProcess() code with calls to save and
restore the fpu state, and see if the problem can still be reproduced.

// file fpu_cw_dll.cpp
// $/MinGW-20050120/bin/g++ -shared -I /lmi/src/lmi fpu_cw_dll.cpp -o 
fpu_cw_dll.dll

#include "fenv_lmi_x86.hpp"

#include <windows.h> // HINSTANCE etc.

#include <iomanip>
#include <iostream>
#include <ostream>

extern "C" int __declspec(dllexport) __stdcall DllMain
    (HINSTANCE
    ,DWORD reason
    ,LPVOID
    )
{
    switch(reason)
        {
        case DLL_PROCESS_ATTACH:
            {
            x87_control_word(0x0040);
            std::cout
                << "DllEntryPoint() called with DLL_PROCESS_ATTACH\n"
                << "control word in dll: " << std::hex << x87_control_word()
                << std::endl;
                ;
            }
            break;
        case DLL_PROCESS_DETACH:
            {
            x87_control_word(0x0041);
            std::cout
                << "DllEntryPoint() called with DLL_PROCESS_DETACH\n"
                << "control word in dll: " << std::hex << x87_control_word()
                << std::endl;
                ;
            }
            break;
        default:
            ;   // do nothing
        }
    return true;
}

int __declspec(dllexport) foo()
{
    x87_control_word(0x004f);
    std::cout
        << "dll: foo() called\n"
        << "control word in dll: " << std::hex << x87_control_word()
        << std::endl
        ;
}

// file fpu_cw_dll_test.cpp
// $/MinGW-20050120/bin/g++ -I /lmi/src/lmi fpu_cw_dll_test.cpp fpu_cw_dll.dll 
-o fpu_cw_dll_test

#include "fenv_lmi_x86.hpp"

#include <iomanip>
#include <iostream>
#include <ostream>

#include <windows.h>

int __declspec(dllimport) foo();

int main()
{
    std::cout << "app: " << std::hex << x87_control_word() << std::endl;
    x87_control_word(0x027f);
    std::cout << "app: " << std::hex << x87_control_word() << std::endl;
    ::LoadLibrary("fpu_cw_dll.dll"); // Superfluous due to link command.
    std::cout << "app: " << std::hex << x87_control_word() << std::endl;
    foo();
    std::cout << "app: " << std::hex << x87_control_word() << std::endl;
}

Output [annotations in square brackets]:

  $./fpu_cw_dll_test
  DllEntryPoint() called with DLL_PROCESS_ATTACH
  control word in dll: 40
  app: 37f [set by MinGW startup code]
  app: 27f
  app: 27f
  dll: foo() called
  control word in dll: 4f
  app: 4f
  DllEntryPoint() called with DLL_PROCESS_DETACH
  control word in dll: 41 [occurs after last line of main()]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]