Commit 0a45ada0 authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard

Do not relocate the pointers in the IMAGE_THREAD_LOCAL_STORAGE

directory, for they seem to be relocated by the standard relocating mechanism. (Explicitly checked one program using it)
parent e1ab22da
...@@ -939,6 +939,13 @@ void PE_InitDLL(WINE_MODREF *wm, DWORD type, LPVOID lpReserved) ...@@ -939,6 +939,13 @@ void PE_InitDLL(WINE_MODREF *wm, DWORD type, LPVOID lpReserved)
} }
} }
/************************************************************************
* PE_InitTls (internal)
*
* If included, initialises the thread local storages of modules.
* Pointers in those structs are not RVAs but real pointers which have been
* relocated by do_relocations() already.
*/
void PE_InitTls(THDB *thdb) void PE_InitTls(THDB *thdb)
{ {
WINE_MODREF *wm; WINE_MODREF *wm;
...@@ -958,33 +965,28 @@ void PE_InitTls(THDB *thdb) ...@@ -958,33 +965,28 @@ void PE_InitTls(THDB *thdb)
delta = wm->module - peh->OptionalHeader.ImageBase; delta = wm->module - peh->OptionalHeader.ImageBase;
if (!peh->OptionalHeader.DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress) if (!peh->OptionalHeader.DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress)
continue; continue;
FIXME(win32,"%s has TLS directory.\n",wm->longname);
pdir = (LPVOID)(wm->module + peh->OptionalHeader. pdir = (LPVOID)(wm->module + peh->OptionalHeader.
DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress); DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress);
if (!(pem->flags & PE_MODREF_TLS_ALLOCED)) { if (!(pem->flags & PE_MODREF_TLS_ALLOCED)) {
pem->tlsindex = THREAD_TlsAlloc(thdb); pem->tlsindex = THREAD_TlsAlloc(thdb);
*(LPDWORD)AdjustPtr(pdir->AddressOfIndex,delta) *pdir->AddressOfIndex=pem->tlsindex;
=pem->tlsindex;
} }
pem->flags |= PE_MODREF_TLS_ALLOCED; pem->flags |= PE_MODREF_TLS_ALLOCED;
datasize= pdir->EndAddressOfRawData-pdir->StartAddressOfRawData; datasize= pdir->EndAddressOfRawData-pdir->StartAddressOfRawData;
size = datasize + pdir->SizeOfZeroFill; size = datasize + pdir->SizeOfZeroFill;
mem=VirtualAlloc(0,size,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); mem=VirtualAlloc(0,size,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
memcpy(mem, memcpy(mem,(LPVOID)pdir->StartAddressOfRawData,datasize);
AdjustPtr(pdir->StartAddressOfRawData,delta),
datasize);
/* don't use TlsSetValue, we are in the wrong thread */
if (pdir->AddressOfCallBacks) { if (pdir->AddressOfCallBacks) {
PIMAGE_TLS_CALLBACK *cbs = PIMAGE_TLS_CALLBACK *cbs =
(PIMAGE_TLS_CALLBACK *) (PIMAGE_TLS_CALLBACK *)pdir->AddressOfCallBacks;
AdjustPtr(pdir->AddressOfCallBacks, delta);
if (*cbs) { if (*cbs)
FIXME(win32, "TLS Callbacks aren't going to be called\n"); FIXME(win32, "TLS Callbacks aren't going to be called\n");
} }
} /* Don't use TlsSetValue, we are in the wrong thread */
thdb->tls_array[pem->tlsindex] = mem; thdb->tls_array[pem->tlsindex] = mem;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment