Changeset 3975 for trunk/src/kernel32/wintls.cpp
- Timestamp:
- Aug 9, 2000, 8:59:03 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wintls.cpp
r3615 r3975 1 /* $Id: wintls.cpp,v 1.1 0 2000-05-27 11:30:36sandervl Exp $ */1 /* $Id: wintls.cpp,v 1.11 2000-08-09 18:59:03 sandervl Exp $ */ 2 2 /* 3 3 * Win32 TLS API functions 4 4 * 5 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) 6 * 5 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) 6 * 7 * TODO: correct errors set for Tls* apis? (verify in NT) 7 8 * 8 9 * Project Odin Software License can be found in LICENSE.TXT … … 54 55 void Win32ImageBase::tlsAttachThread() //setup TLS structures for new thread 55 56 { 56 EXCEPTION_FRAME exceptFrame;57 EXCEPTION_FRAME exceptFrame; 57 58 PIMAGE_TLS_CALLBACK *pCallback; 58 TEB *winteb; 59 char *tibmem; 59 LPVOID tibmem; 60 60 61 61 if(!tlsAddress) … … 75 75 dprintf(("tlsCallbackAddr %x", tlsCallBackAddr)); 76 76 dprintf(("*tlsCallbackAddr %x", (tlsCallBackAddr) ? *tlsCallBackAddr : 0)); 77 tibmem = (char *)VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);77 tibmem = VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); 78 78 if(tibmem == NULL) { 79 79 dprintf(("tlsAttachThread: tibmem == NULL!!!!")); … … 84 84 memcpy(tibmem, tlsAddress, tlsInitSize); 85 85 86 winteb = (TEB *)*TIBFlatPtr; 87 winteb->tls_ptr[tlsIndex] = tibmem; 86 TlsSetValue(tlsIndex, tibmem); 88 87 *tlsIndexAddr = tlsIndex; 89 88 … … 105 104 void Win32ImageBase::tlsDetachThread() //destroy TLS structures 106 105 { 107 EXCEPTION_FRAME exceptFrame;106 EXCEPTION_FRAME exceptFrame; 108 107 PIMAGE_TLS_CALLBACK *pCallback; 109 TEB *winteb;108 LPVOID tlsmem; 110 109 111 110 if(!tlsAddress) … … 125 124 } 126 125 } 127 winteb = (TEB *)*TIBFlatPtr; 128 VirtualFree(winteb->tls_ptr[tlsIndex], tlsTotalSize, MEM_RELEASE); 129 winteb->tls_ptr[tlsIndex] = 0; 126 tlsmem = TlsGetValue(tlsIndex); 127 if(tlsmem) { 128 VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE); 129 } 130 else { 131 dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!")); 132 } 133 TlsFree(tlsIndex); 130 134 } 131 135 //****************************************************************************** … … 136 140 DWORD WIN32API TlsAlloc() 137 141 { 138 DWORD index; 139 142 DWORD index = -1; 143 144 #if 1 145 THDB *thdb; 146 PDB *pdb; 147 DWORD mask, tibidx; 148 int i; 149 150 thdb = GetThreadTHDB(); 151 pdb = PROCESS_Current(); 152 153 EnterCriticalSection(&pdb->crit_section); 154 tibidx = 0; 155 if(pdb->tls_bits[0] == 0xFFFFFFFF) { 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 } 163 for(i=0;i<32;i++) { 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 } 171 LeaveCriticalSection(&pdb->crit_section); 172 thdb->tls_array[index] = 0; 173 #else 140 174 index = O32_TlsAlloc(); 175 #endif 141 176 dprintf(("KERNEL32: TlsAlloc returned %d", index)); 142 177 return index; … … 147 182 { 148 183 dprintf(("KERNEL32: TlsFree %d", index)); 184 #if 1 185 THDB *thdb; 186 PDB *pdb; 187 int tlsidx; 188 DWORD mask; 189 190 if(index >= TLS_MINIMUM_AVAILABLE) 191 { 192 SetLastError(ERROR_INVALID_PARAMETER); 193 return NULL; 194 } 195 196 thdb = GetThreadTHDB(); 197 pdb = PROCESS_Current(); 198 199 EnterCriticalSection(&pdb->crit_section); 200 tlsidx = 0; 201 if(index > 32) { 202 tlsidx++; 203 } 204 mask = (1 << index); 205 if(pdb->tls_bits[tlsidx] & mask) { 206 LeaveCriticalSection(&pdb->crit_section); 207 pdb->tls_bits[tlsidx] &= ~mask; 208 thdb->tls_array[index] = 0; 209 SetLastError(ERROR_SUCCESS); 210 return TRUE; 211 } 212 LeaveCriticalSection(&pdb->crit_section); 213 SetLastError(ERROR_INVALID_PARAMETER); //TODO: correct error? (does NT even change the last error?) 214 return FALSE; 215 #else 149 216 return(O32_TlsFree(index)); 217 #endif 150 218 } 151 219 //****************************************************************************** … … 155 223 LPVOID rc; 156 224 225 if(index >= TLS_MINIMUM_AVAILABLE) 226 { 227 SetLastError(ERROR_INVALID_PARAMETER); 228 return NULL; 229 } 230 SetLastError(ERROR_SUCCESS); 231 232 #if 1 233 THDB *thdb; 234 235 thdb = GetThreadTHDB(); 236 rc = thdb->tls_array[index]; 237 #else 157 238 rc = O32_TlsGetValue(index); 158 dprintf2(("KERNEL32: TlsGetValue %d returned %X\n", index, rc)); 239 #endif 240 dprintf2(("KERNEL32: TlsGetValue %d returned %X\n", index, rc)); 159 241 return(rc); 160 242 } … … 163 245 BOOL WIN32API TlsSetValue(DWORD index, LPVOID val) 164 246 { 165 dprintf2(("KERNEL32: TlsSetValue\n")); 247 dprintf2(("KERNEL32: TlsSetValue %d %x", index, val)); 248 if(index >= TLS_MINIMUM_AVAILABLE) 249 { 250 SetLastError(ERROR_INVALID_PARAMETER); 251 return FALSE; 252 } 253 SetLastError(ERROR_SUCCESS); 254 #if 1 255 THDB *thdb; 256 257 thdb = GetThreadTHDB(); 258 thdb->tls_array[index] = val; 259 return TRUE; 260 #else 166 261 return(O32_TlsSetValue(index, val)); 167 } 168 //****************************************************************************** 169 //****************************************************************************** 262 #endif 263 } 264 //****************************************************************************** 265 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.