Changeset 4285 for trunk/src/kernel32/wintls.cpp
- Timestamp:
- Sep 20, 2000, 11:32:58 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wintls.cpp
r3975 r4285 1 /* $Id: wintls.cpp,v 1.1 1 2000-08-09 18:59:03 sandervlExp $ */1 /* $Id: wintls.cpp,v 1.12 2000-09-20 21:32:54 hugh Exp $ */ 2 2 /* 3 3 * Win32 TLS API functions … … 17 17 #include "exceptutil.h" 18 18 19 #define DBG_LOCALLOG 19 #define DBG_LOCALLOG DBG_wintls 20 20 #include "dbglocal.h" 21 21 22 22 //****************************************************************************** 23 23 //****************************************************************************** 24 void Win32ImageBase::tlsAlloc() 25 { 26 if(!tlsAddress) 27 24 void Win32ImageBase::tlsAlloc() //Allocate TLS index for this module 25 { 26 if(!tlsAddress) 27 return; 28 28 29 29 tlsIndex = TlsAlloc(); 30 30 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) { 31 32 33 return; 31 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex)); 32 DebugInt3(); 33 return; 34 34 } 35 35 dprintf(("Win32ImageBase::tlsAlloc (%d) for module %x", tlsIndex, hinstance)); … … 37 37 //****************************************************************************** 38 38 //****************************************************************************** 39 void Win32ImageBase::tlsDelete() 40 { 41 if(!tlsAddress) 42 39 void Win32ImageBase::tlsDelete() //Free TLS index for this module 40 { 41 if(!tlsAddress) 42 return; 43 43 44 44 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) { 45 46 47 return; 45 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex)); 46 DebugInt3(); 47 return; 48 48 } 49 49 dprintf(("Win32ImageBase::tlsDestroy (%d) for module %x", tlsIndex, hinstance)); … … 53 53 //****************************************************************************** 54 54 //****************************************************************************** 55 void Win32ImageBase::tlsAttachThread() 55 void Win32ImageBase::tlsAttachThread() //setup TLS structures for new thread 56 56 { 57 57 EXCEPTION_FRAME exceptFrame; … … 59 59 LPVOID tibmem; 60 60 61 if(!tlsAddress) 62 61 if(!tlsAddress) 62 return; 63 63 64 64 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) { 65 66 67 return; 65 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex)); 66 DebugInt3(); 67 return; 68 68 } 69 69 … … 77 77 tibmem = VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); 78 78 if(tibmem == NULL) { 79 80 81 79 dprintf(("tlsAttachThread: tibmem == NULL!!!!")); 80 DebugInt3(); 81 return; 82 82 } 83 83 memset(tibmem, 0, tlsTotalSize); … … 88 88 89 89 if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) { 90 91 92 93 94 95 96 97 98 90 pCallback = tlsCallBackAddr; 91 while(*pCallback) { 92 dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback)); 93 94 (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0); 95 96 dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback)); 97 *pCallback++; 98 } 99 99 } 100 100 return; … … 102 102 //****************************************************************************** 103 103 //****************************************************************************** 104 void Win32ImageBase::tlsDetachThread() 104 void Win32ImageBase::tlsDetachThread() //destroy TLS structures 105 105 { 106 106 EXCEPTION_FRAME exceptFrame; … … 108 108 LPVOID tlsmem; 109 109 110 if(!tlsAddress) 111 110 if(!tlsAddress) 111 return; 112 112 113 113 dprintf(("Win32ImageBase::tlsDetachThread for module %x, thread id %x", hinstance, GetCurrentThreadId())); 114 114 115 115 if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) { 116 117 118 119 120 121 122 123 124 116 pCallback = tlsCallBackAddr; 117 while(*pCallback) { 118 dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback)); 119 120 (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0); 121 122 dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback)); 123 *pCallback++; 124 } 125 125 } 126 126 tlsmem = TlsGetValue(tlsIndex); 127 127 if(tlsmem) { 128 128 VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE); 129 129 } 130 130 else { 131 131 dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!")); 132 132 } 133 133 TlsFree(tlsIndex); … … 154 154 tibidx = 0; 155 155 if(pdb->tls_bits[0] == 0xFFFFFFFF) { 156 157 158 159 160 161 156 if(pdb->tls_bits[1] == 0xFFFFFFFF) { 157 LeaveCriticalSection(&pdb->crit_section); 158 SetLastError(ERROR_NO_MORE_ITEMS); //TODO: correct error? 159 return -1; 160 } 161 tibidx = 1; 162 162 } 163 163 for(i=0;i<32;i++) { 164 165 166 167 168 169 164 mask = (1 << i); 165 if((pdb->tls_bits[tibidx] & mask) == 0) { 166 pdb->tls_bits[tibidx] |= mask; 167 index = (tibidx*32) + i; 168 break; 169 } 170 170 } 171 171 LeaveCriticalSection(&pdb->crit_section); … … 200 200 tlsidx = 0; 201 201 if(index > 32) { 202 202 tlsidx++; 203 203 } 204 204 mask = (1 << index); 205 205 if(pdb->tls_bits[tlsidx] & mask) { 206 206 LeaveCriticalSection(&pdb->crit_section); 207 207 pdb->tls_bits[tlsidx] &= ~mask; 208 208 thdb->tls_array[index] = 0; 209 209 SetLastError(ERROR_SUCCESS); 210 210 return TRUE; 211 211 } 212 212 LeaveCriticalSection(&pdb->crit_section);
Note:
See TracChangeset
for help on using the changeset viewer.