www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3342] New: TLS on dynamically loaded DLLs fails on Windows earlier than Vista

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342

           Summary: TLS on dynamically loaded DLLs fails on Windows
                    earlier than Vista
           Product: D
           Version: 2.034
          Platform: Other
               URL: http://www.nynaeve.net/?p=187
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla digitalmars.com


--- Comment #0 from Walter Bright <bugzilla digitalmars.com> 2009-09-24
23:02:40 PDT ---
A full description of the problem: http://www.nynaeve.net/?p=187

The symptom of the problem is erratic memory corruption.

The only known workaround at the moment is to not use TLS on dynamically loaded
DLLs for machines running Windows XP or earlier. Use __gshared instead.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|normal                      |blocker


--- Comment #1 from Don <clugdbug yahoo.com.au> 2009-10-26 02:18:58 PDT ---
Marking as blocker, since this prevents me from using D2 professionally. It's
currently not possible to avoid using TLS (even if you completely avoid
Phobos), since druntime uses it.

Note that this problem only applies to _implicit_ TLS. Explicit TLS, using
TlsGetValue() and TlsSetValue(), still works.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de


--- Comment #2 from Rainer Schuetze <r.sagitario gmx.de> 2010-03-06 08:42:18
PST ---
I've posted a patch for multi-threading support for DLLs here in bug #3885.
This includes a fix for implicite TLS on XP.

It needs to access some global data in ntdll.dll, and the way to get there is
not really obvious, but seems to be valid for all the ntdll-versions I have
found on my system: SP2, one inbetween and SP3.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 06 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342



--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2010-03-09
23:11:09 PST ---
I've been looking at the patch, it's an impressive piece of work!

But I'd like it to detect the Windows version, and not do anything if it is
Vista or newer, as those systems don't have the TLS bug. If we don't do this
check, since the patch relies on undocumented ntdll internals, D apps are
vulnerable to breaking with Windows updates.

Also, skywing has some code to deal with this at
http://www.nynaeve.net/Code/VistaImplicitTls.cpp

Can you check it to see if anything was missed?

Thanks!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342



--- Comment #4 from Rainer Schuetze <r.sagitario gmx.de> 2010-03-10 01:32:28
PST ---
There is a detection whether _tls_index is set and the tls-data-array contains
a valid pointer (thinking about it the latter might be flawed), so this should
cover any situation where the OS did not setup TLS correctly (when loaded at
process init time, TLS is correct on XP, too).

Do you think, that an explicite version check is better? What about
applications that are configured to pretend running under a different windows
version?

As much as I can see, the referenced code contains two things not in the patch:

- it keeps track of used tls-indexes in a bitmap, but XP does not have this.
That's why the patch prevents unloading of the DLL.
- it uses ExReleaseRundownProtection before accessing some TEB data, but this
seems to be an (undocumented) kernel function, and I think we should be safe
with our operations as the nt-loader holds a lock that disallows reentrence
into DllMain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3342


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Don <clugdbug yahoo.com.au> 2010-04-09 19:36:55 PDT ---
Fixed DMD2.042, documentation fixed in 2.043.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2010