Changeset 4523 for trunk/src/kernel32/windllbase.cpp
- Timestamp:
- Oct 23, 2000, 3:42:47 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/windllbase.cpp
r4474 r4523 1 /* $Id: windllbase.cpp,v 1.1 8 2000-10-10 17:14:06sandervl Exp $ */1 /* $Id: windllbase.cpp,v 1.19 2000-10-23 13:42:42 sandervl Exp $ */ 2 2 3 3 /* 4 4 * Win32 Dll base class 5 5 * 6 * Copyright 1998- 1999Sander van Leeuwen (sandervl@xs4all.nl)6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 8 * Unloading of a dll always happens in order of dependency (taking nr of … … 10 10 * Unloading of dynamically loaded dll (with LoadLibrary) in deleteAll 11 11 * is done in LIFO order (NT exhibits the same behaviour) 12 * 12 * 13 13 * RemoveCircularDependency: TODO: Send process detach message here?? 14 14 * … … 22 22 #define INCL_DOSMISC /* DOS Miscellanous values */ 23 23 #define INCL_WIN 24 #include <os2wrap.h> 24 #include <os2wrap.h> //Odin32 OS/2 api wrappers 25 25 #include <stdio.h> 26 26 #include <string.h> … … 41 41 #include "profile.h" 42 42 43 #define DBG_LOCALLOG 43 #define DBG_LOCALLOG DBG_windllbase 44 44 #include "dbglocal.h" 45 45 … … 48 48 //****************************************************************************** 49 49 //****************************************************************************** 50 Win32DllBase::Win32DllBase(HINSTANCE hinstance, WIN32DLLENTRY DllEntryPoint, 50 Win32DllBase::Win32DllBase(HINSTANCE hinstance, WIN32DLLENTRY DllEntryPoint, 51 51 Win32ImageBase *parent) 52 52 : Win32ImageBase(hinstance), 53 54 fAttachedToProcess(FALSE), fUnloaded(FALSE),55 nrDynamicLibRef(0), fDisableUnload(FALSE), fSkipEntryCalls(FALSE)56 { 57 dllEntryPoint = DllEntryPoint;58 59 setUnloadOrder(parent);60 61 dprintf(("Win32DllBase::Win32DllBase %x %s", hinstance, szModule));53 referenced(0), fSkipThreadEntryCalls(FALSE), next(NULL), fInserted(FALSE), 54 fAttachedToProcess(FALSE), fUnloaded(FALSE), 55 nrDynamicLibRef(0), fDisableUnload(FALSE), fSkipEntryCalls(FALSE) 56 { 57 dllEntryPoint = DllEntryPoint; 58 59 setUnloadOrder(parent); 60 61 dprintf(("Win32DllBase::Win32DllBase %x %s", hinstance, szModule)); 62 62 } 63 63 //****************************************************************************** … … 65 65 Win32DllBase::~Win32DllBase() 66 66 { 67 dprintf(("Win32DllBase::~Win32DllBase %s", szModule));68 69 if(errorState == NO_ERROR && !fUnloaded)70 {71 72 }73 74 dlllistmutex.enter();75 if(head == this) {76 77 }78 else {67 dprintf(("Win32DllBase::~Win32DllBase %s", szModule)); 68 69 if(errorState == NO_ERROR && !fUnloaded) 70 { 71 detachProcess(); 72 } 73 74 dlllistmutex.enter(); 75 if(head == this) { 76 head = next; 77 } 78 else { 79 79 Win32DllBase *dll = head; 80 81 82 } 83 84 85 86 87 88 89 }90 dlllistmutex.leave();80 while(dll && dll->next != this) { 81 dll = dll->next; 82 } 83 if(dll == NULL) { 84 dprintf(("~Win32DllBase: Can't find dll!\n")); 85 dlllistmutex.leave(); 86 return; 87 } 88 dll->next = next; 89 } 90 dlllistmutex.leave(); 91 91 } 92 92 //****************************************************************************** 93 93 //****************************************************************************** 94 94 void Win32DllBase::incDynamicLib() 95 { 96 if(nrDynamicLibRef == 0) {95 { 96 if(nrDynamicLibRef == 0) { 97 97 //NOTE: 98 98 //Must be called *after* attachprocess, since attachprocess may also … … 103 103 // this means that in ExitProcess, PNRS3260 needs to be removed 104 104 // first since RPAP3260 depends on it 105 106 dlllistmutex.enter(); 107 loadLibDlls.Push((ULONG)this); 108 dlllistmutex.leave(); 109 } 110 nrDynamicLibRef++; 105 dlllistmutex.enter(); 106 loadLibDlls.Push((ULONG)this); 107 dlllistmutex.leave(); 108 } 109 nrDynamicLibRef++; 111 110 } 112 111 //****************************************************************************** 113 112 //****************************************************************************** 114 113 void Win32DllBase::decDynamicLib() 115 { 116 nrDynamicLibRef--;117 if(nrDynamicLibRef == 0) {118 119 120 121 }114 { 115 nrDynamicLibRef--; 116 if(nrDynamicLibRef == 0) { 117 dlllistmutex.enter(); 118 loadLibDlls.Remove((ULONG)this); 119 dlllistmutex.leave(); 120 } 122 121 } 123 122 //****************************************************************************** 124 123 //unload of dlls needs to be done in reverse order of dependencies 125 //Note: Only necessary for pe loader; the OS/2 loader takes care of this 126 //for win32k/pe2lx 124 //Note: Only necessary for pe loader; the OS/2 loader takes care of this 125 //for win32k/pe2lx 127 126 //****************************************************************************** 128 127 void Win32DllBase::setUnloadOrder(Win32ImageBase *parent) … … 131 130 Win32DllBase *parentdll = NULL; 132 131 133 dlllistmutex.enter(); 134 if(parent) { 135 dll = head; 136 while(dll) { 137 if(dll->getInstanceHandle() == parent->getInstanceHandle()) { 138 parentdll = dll; 139 break; 140 } 141 dll = dll->next; 142 } 143 } 144 145 //first check if this dll is already at a lower position (further down the list) 146 //than the parent 147 if(parentdll && fInserted) {//already in the list? 148 dll = parentdll->next; 149 while(dll) { 150 if(dll->getInstanceHandle() == getInstanceHandle()) { 151 dlllistmutex.leave(); 152 return; //it's at a lower position, so no need to change anything 153 } 154 dll = dll->next; 155 } 156 157 //it's already in the list but not at the right position; remove it now 158 if(head == this) { 159 head = next; 160 } 161 else { 162 dll = head; 163 while(dll->next) { 164 if(dll->next == this) { 165 dll->next = next; 166 break; 167 } 168 dll = dll->next; 169 } 170 } 171 } 172 else 173 if(fInserted) {//already in the list? 174 dlllistmutex.leave(); 175 return; 176 } 177 //(re)insert it in the list after it's parent 178 if(parentdll) { 179 next = parentdll->next; 180 parentdll->next = this; 181 } 182 else {//no parent or exe, just add it at the start of the list 183 next = head; 184 head = this; 185 } 186 fInserted = TRUE; 187 188 //Now do the same thing for the child dependencies 189 QueueItem *item; 190 191 item = loadedDlls.Head(); 192 while(item) { 193 dll = (Win32DllBase *)loadedDlls.getItem(item); 194 //Check for circular dependencies (i.e. in Lotus Notes) 195 if(dll != parentdll) { 196 dll->setUnloadOrder(this); 197 } 198 199 item = loadedDlls.getNext(item); 200 } 201 202 dlllistmutex.leave(); 132 dlllistmutex.enter(); 133 if(parent) { 134 dll = head; 135 while(dll) { 136 if(dll->getInstanceHandle() == parent->getInstanceHandle()) { 137 parentdll = dll; 138 break; 139 } 140 dll = dll->next; 141 } 142 } 143 144 //first check if this dll is already at a lower position (further down the list) 145 //than the parent 146 if(parentdll && fInserted) {//already in the list? 147 dll = parentdll->next; 148 while(dll) { 149 if(dll->getInstanceHandle() == getInstanceHandle()) { 150 dlllistmutex.leave(); 151 return; //it's at a lower position, so no need to change anything 152 } 153 dll = dll->next; 154 } 155 156 //it's already in the list but not at the right position; remove it now 157 if(head == this) { 158 head = next; 159 } 160 else { 161 dll = head; 162 while(dll->next) { 163 if(dll->next == this) { 164 dll->next = next; 165 break; 166 } 167 dll = dll->next; 168 } 169 } 170 } 171 else 172 if(fInserted) {//already in the list? 173 dlllistmutex.leave(); 174 return; 175 } 176 //(re)insert it in the list after it's parent 177 if(parentdll) { 178 next = parentdll->next; 179 parentdll->next = this; 180 } 181 else {//no parent or exe, just add it at the start of the list 182 next = head; 183 head = this; 184 } 185 fInserted = TRUE; 186 187 //Now do the same thing for the child dependencies 188 QueueItem *item; 189 190 item = loadedDlls.Head(); 191 while(item) { 192 dll = (Win32DllBase *)loadedDlls.getItem(item); 193 //Check for circular dependencies (i.e. in Lotus Notes) 194 if(dll != parentdll) { 195 dll->setUnloadOrder(this); 196 } 197 item = loadedDlls.getNext(item); 198 } 199 dlllistmutex.leave(); 203 200 } 204 201 //****************************************************************************** … … 209 206 ULONG Win32DllBase::AddRef() 210 207 #endif 211 { 208 { 212 209 Win32DllBase *dll; 213 210 214 dprintf(("Win32DllBase::AddRef %s->%s %d", parentname, getModuleName(), referenced+1));215 ++referenced;211 dprintf(("Win32DllBase::AddRef %s->%s %d", parentname, getModuleName(), referenced+1)); 212 ++referenced; 216 213 #ifdef DEBUG 217 if(referenced == 1) {214 if(referenced == 1) { 218 215 #ifdef DEBUG_ENABLELOG_LEVEL2 219 216 printListOfDlls(); 220 217 #endif 221 222 }218 //printDependencies(NULL); 219 } 223 220 #endif 224 225 return referenced; 221 return referenced; 226 222 } 227 223 //****************************************************************************** … … 234 230 LONG ret; 235 231 236 dprintf(("Win32DllBase::Release %s %d", getModuleName(), referenced-1));237 238 ret = --referenced;239 if(ret <= 0) {240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 232 dprintf(("Win32DllBase::Release %s %d", getModuleName(), referenced-1)); 233 234 ret = --referenced; 235 if(ret <= 0) { 236 //make copy of linked list of dependencies 237 queue = loadedDlls; 238 239 //remove any circular dependencies on this dll that might be present 240 item = queue.Head(); 241 while(item) { 242 dll = (Win32DllBase *)queue.getItem(item); 243 if(dll == NULL) { 244 dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!")); 245 DebugInt3(); 246 return -1; 247 } 248 dll->RemoveCircularDependency(this); 249 item = queue.getNext(item); 250 } 255 251 #ifdef DEBUG 256 252 //printDependencies(NULL); 257 253 #endif 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 }276 return(ret);254 dprintf(("Win32DllBase::Release %s referenced == 0", getModuleName())); 255 256 //delete dll object 257 delete this; 258 259 //unreference all of it's dependencies 260 item = queue.Head(); 261 while(item) { 262 dll = (Win32DllBase *)queue.getItem(item); 263 if(dll == NULL) { 264 dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!")); 265 DebugInt3(); 266 return -1; 267 } 268 dll->Release(); 269 item = queue.getNext(item); 270 } 271 } 272 return(ret); 277 273 } 278 274 //****************************************************************************** … … 286 282 BOOL ret = FALSE; 287 283 288 //remove any circular dependencies on this dll that might be present289 item = loadedDlls.Head();290 while(item) {291 292 293 294 295 296 297 298 299 300 301 302 303 //// elseret |= dll->RemoveCircularDependency(parent);304 305 }306 //TODO: Send process detach message here??307 return ret;308 } 309 //****************************************************************************** 310 //There's a slight problem with our dependency procedure. 284 //remove any circular dependencies on this dll that might be present 285 item = loadedDlls.Head(); 286 while(item) { 287 dll = (Win32DllBase *)loadedDlls.getItem(item); 288 if(dll == NULL) { 289 dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!")); 290 DebugInt3(); 291 return FALSE; 292 } 293 tmp = loadedDlls.getNext(item); 294 if(dll == parent) { 295 dprintf(("Removing CIRCULAR dependency %s->%s", parent->getModuleName(), dll->getModuleName())); 296 loadedDlls.Remove(item); 297 ret = TRUE; 298 } 299 //// else ret |= dll->RemoveCircularDependency(parent); 300 item = tmp; 301 } 302 //TODO: Send process detach message here?? 303 return ret; 304 } 305 //****************************************************************************** 306 //There's a slight problem with our dependency procedure. 311 307 //example: gdi32 is loaded -> depends on kernel32 (which is already loaded) 312 308 // kernel32's reference count isn't updated … … 321 317 Win32DllBase *dll, *depdll; 322 318 ULONG refcount; 323 324 dlllistmutex.enter(); 325 item = loadedDlls.Head(); 326 while(item) { 327 depdll = (Win32DllBase *)loadedDlls.getItem(item); 328 if(depdll == NULL) { 329 dprintf(("updateDependencies: depdll == NULL!!")); 330 DebugInt3(); 331 return; 332 } 333 refcount = 0; 334 dll = head; 335 336 while(dll) { 337 if(dll->dependsOn(depdll)) { 338 refcount++; 339 } 340 dll = dll->getNext(); 341 } 342 if(refcount > depdll->referenced) { 343 dprintf(("Win32DllBase::updateDependencies changing refcount of %s to %d (old=%d)", depdll->getModuleName(), refcount, depdll->referenced)); 344 depdll->referenced = refcount; 345 } 346 347 item = loadedDlls.getNext(item); 348 } 349 dlllistmutex.leave(); 319 320 dlllistmutex.enter(); 321 item = loadedDlls.Head(); 322 while(item) { 323 depdll = (Win32DllBase *)loadedDlls.getItem(item); 324 if(depdll == NULL) { 325 dprintf(("updateDependencies: depdll == NULL!!")); 326 DebugInt3(); 327 return; 328 } 329 refcount = 0; 330 dll = head; 331 332 while(dll) { 333 if(dll->dependsOn(depdll)) { 334 refcount++; 335 } 336 dll = dll->getNext(); 337 } 338 if(refcount > depdll->referenced) { 339 dprintf(("Win32DllBase::updateDependencies changing refcount of %s to %d (old=%d)", depdll->getModuleName(), refcount, depdll->referenced)); 340 depdll->referenced = refcount; 341 } 342 item = loadedDlls.getNext(item); 343 } 344 dlllistmutex.leave(); 350 345 } 351 346 //****************************************************************************** … … 358 353 ULONG ret; 359 354 360 dprintf(("Dependency list: %s->%s %d", parent, getModuleName(), referenced));361 item = loadedDlls.Head();362 while(item) {363 364 365 366 367 368 369 }355 dprintf(("Dependency list: %s->%s %d", parent, getModuleName(), referenced)); 356 item = loadedDlls.Head(); 357 while(item) { 358 dll = (Win32DllBase *)loadedDlls.getItem(item); 359 if(dll == NULL) { 360 return; 361 } 362 dll->printDependencies(getModuleName()); 363 item = loadedDlls.getNext(item); 364 } 370 365 } 371 366 //****************************************************************************** … … 376 371 Win32DllBase *dll; 377 372 378 dll = head;379 380 dprintf2(("Win32DllBase::Win32DllBase: List of loaded dlls:"));381 while(dll) {382 383 384 }373 dll = head; 374 375 dprintf2(("Win32DllBase::Win32DllBase: List of loaded dlls:")); 376 while(dll) { 377 dprintf2(("DLL %s %d", dll->szModule, dll->referenced)); 378 dll = dll->next; 379 } 385 380 } 386 381 #endif … … 395 390 BOOL rc, fSetExceptionHandler; 396 391 397 if(fAttachedToProcess || fSkipEntryCalls)398 399 400 fAttachedToProcess = TRUE;401 402 thdb = GetThreadTHDB();403 fSetExceptionHandler = (!thdb || thdb->teb_sel != GetFS());404 405 //Note: The Win32 exception structure references by FS:[0] is the same406 // in OS/2407 if(fSetExceptionHandler) {408 409 410 }411 412 //Allocate TLS index for this module413 tlsAlloc();414 tlsAttachThread();//setup TLS (main thread)415 416 if(dllEntryPoint == NULL) {392 if(fAttachedToProcess || fSkipEntryCalls) 393 return TRUE; 394 395 fAttachedToProcess = TRUE; 396 397 thdb = GetThreadTHDB(); 398 fSetExceptionHandler = (!thdb || thdb->teb_sel != GetFS()); 399 400 //Note: The Win32 exception structure references by FS:[0] is the same 401 // in OS/2 402 if(fSetExceptionHandler) { 403 OS2SetExceptionHandler((void *)&exceptFrame); 404 sel = SetWin32TIB(); 405 } 406 407 //Allocate TLS index for this module 408 tlsAlloc(); 409 tlsAttachThread(); //setup TLS (main thread) 410 411 if(dllEntryPoint == NULL) { 417 412 dprintf(("attachProcess not required for dll %s", szModule)); 418 419 420 421 422 423 }424 425 dprintf(("attachProcess to dll %s", szModule));426 427 // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL428 // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads429 // and non-NULL for static loads.430 // same goes for process termination431 LPVOID lpvReserved;432 433 if (isDynamicLib())434 lpvReserved = NULL;435 else436 lpvReserved = (LPVOID)0xdeadface; // some arbitrary value437 438 rc = dllEntryPoint(hinstance, DLL_PROCESS_ATTACH, lpvReserved);439 440 dprintf(("attachProcess to dll %s DONE", szModule));441 442 if(fSetExceptionHandler) {443 444 445 }446 else447 if(thdb) {448 449 450 451 452 }453 return rc;413 if(fSetExceptionHandler) { 414 SetFS(sel); 415 OS2UnsetExceptionHandler((void *)&exceptFrame); 416 } 417 return(TRUE); 418 } 419 420 dprintf(("attachProcess to dll %s", szModule)); 421 422 // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL 423 // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads 424 // and non-NULL for static loads. 425 // same goes for process termination 426 LPVOID lpvReserved; 427 428 if (isDynamicLib()) 429 lpvReserved = NULL; 430 else 431 lpvReserved = (LPVOID)0xdeadface; // some arbitrary value 432 433 rc = dllEntryPoint(hinstance, DLL_PROCESS_ATTACH, lpvReserved); 434 435 dprintf(("attachProcess to dll %s DONE", szModule)); 436 437 if(fSetExceptionHandler) { 438 SetFS(sel); 439 OS2UnsetExceptionHandler((void *)&exceptFrame); 440 } 441 else 442 if(thdb) { 443 if(thdb->teb_sel != GetFS()) { 444 dprintf(("Win32DllBase::attachProcess: FS was changed by dll entrypoint!!!!")); 445 DebugInt3(); 446 } 447 } 448 return rc; 454 449 } 455 450 //****************************************************************************** … … 461 456 BOOL rc; 462 457 463 if(fSkipEntryCalls) {464 465 466 }467 468 if(dllEntryPoint == NULL) {469 tlsDetachThread(); 470 471 472 }473 474 dprintf(("detachProcess from dll %s", szModule));475 476 //Note: The Win32 exception structure references by FS:[0] is the same477 // in OS/2478 OS2SetExceptionHandler((void *)&exceptFrame);479 480 fUnloaded = TRUE;481 sel = SetWin32TIB();482 483 // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL484 // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads485 // and non-NULL for static loads.486 // same goes for process termination487 LPVOID lpvReserved;488 489 if (isDynamicLib())490 lpvReserved = NULL;491 else492 lpvReserved = (LPVOID)0xdeadface; // some arbitrary value493 494 rc = dllEntryPoint(hinstance, DLL_PROCESS_DETACH, lpvReserved);495 496 SetFS(sel);497 tlsDetachThread();//destroy TLS (main thread)498 tlsDelete();499 500 OS2UnsetExceptionHandler((void *)&exceptFrame);501 502 return rc;458 if(fSkipEntryCalls) { 459 fUnloaded = TRUE; 460 return TRUE; 461 } 462 463 if(dllEntryPoint == NULL) { 464 tlsDetachThread(); //destroy TLS (main thread) 465 fUnloaded = TRUE; 466 return(TRUE); 467 } 468 469 dprintf(("detachProcess from dll %s", szModule)); 470 471 //Note: The Win32 exception structure references by FS:[0] is the same 472 // in OS/2 473 OS2SetExceptionHandler((void *)&exceptFrame); 474 475 fUnloaded = TRUE; 476 sel = SetWin32TIB(); 477 478 // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL 479 // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads 480 // and non-NULL for static loads. 481 // same goes for process termination 482 LPVOID lpvReserved; 483 484 if (isDynamicLib()) 485 lpvReserved = NULL; 486 else 487 lpvReserved = (LPVOID)0xdeadface; // some arbitrary value 488 489 rc = dllEntryPoint(hinstance, DLL_PROCESS_DETACH, lpvReserved); 490 491 SetFS(sel); 492 tlsDetachThread(); //destroy TLS (main thread) 493 tlsDelete(); 494 495 OS2UnsetExceptionHandler((void *)&exceptFrame); 496 497 return rc; 503 498 } 504 499 //****************************************************************************** … … 509 504 BOOL rc; 510 505 511 if(fSkipThreadEntryCalls || dllEntryPoint == NULL)512 513 514 dprintf(("attachThread to dll %s", szModule));515 516 rc = dllEntryPoint(hinstance, DLL_THREAD_ATTACH, 0);517 518 dprintf(("attachThread to dll %s DONE", szModule));519 520 return rc;506 if(fSkipThreadEntryCalls || dllEntryPoint == NULL) 507 return(TRUE); 508 509 dprintf(("attachThread to dll %s", szModule)); 510 511 rc = dllEntryPoint(hinstance, DLL_THREAD_ATTACH, 0); 512 513 dprintf(("attachThread to dll %s DONE", szModule)); 514 515 return rc; 521 516 } 522 517 //****************************************************************************** … … 527 522 BOOL rc; 528 523 529 if(fSkipThreadEntryCalls || dllEntryPoint == NULL)530 531 532 dprintf(("detachThread from dll %s", szModule));533 534 rc =dllEntryPoint(hinstance, DLL_THREAD_DETACH, 0);535 return rc;524 if(fSkipThreadEntryCalls || dllEntryPoint == NULL) 525 return(TRUE); 526 527 dprintf(("detachThread from dll %s", szModule)); 528 529 rc = dllEntryPoint(hinstance, DLL_THREAD_DETACH, 0); 530 return rc; 536 531 } 537 532 //****************************************************************************** … … 540 535 void Win32DllBase::attachThreadToAllDlls() 541 536 { 542 dlllistmutex.enter(); 543 Win32DllBase *dll = Win32DllBase::head; 544 while(dll) { 545 dll->attachThread(); 546 dll = dll->getNext(); 547 } 537 dlllistmutex.enter(); 538 Win32DllBase *dll = Win32DllBase::head; 539 while(dll) { 540 dll->attachThread(); 541 dll = dll->getNext(); 542 } 543 dlllistmutex.leave(); 544 } 545 //****************************************************************************** 546 //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die 547 //****************************************************************************** 548 void Win32DllBase::detachThreadFromAllDlls() 549 { 550 dlllistmutex.enter(); 551 Win32DllBase *dll = Win32DllBase::head; 552 while(dll) { 553 dll->detachThread(); 554 dll = dll->getNext(); 555 } 548 556 dlllistmutex.leave(); 549 557 } 550 558 //****************************************************************************** 551 //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die552 //******************************************************************************553 void Win32DllBase::detachThreadFromAllDlls()554 {555 dlllistmutex.enter();556 Win32DllBase *dll = Win32DllBase::head;557 while(dll) {558 dll->detachThread();559 dll = dll->getNext();560 }561 dlllistmutex.leave();562 }563 //******************************************************************************564 559 //Setup TLS structure for all dlls for a new thread 565 560 //****************************************************************************** 566 561 void Win32DllBase::tlsAttachThreadToAllDlls() 567 562 { 568 dlllistmutex.enter();569 Win32DllBase *dll = Win32DllBase::head;570 while(dll) {571 572 573 }574 dlllistmutex.leave();563 dlllistmutex.enter(); 564 Win32DllBase *dll = Win32DllBase::head; 565 while(dll) { 566 dll->tlsAttachThread(); 567 dll = dll->getNext(); 568 } 569 dlllistmutex.leave(); 575 570 } 576 571 //****************************************************************************** … … 579 574 void Win32DllBase::tlsDetachThreadFromAllDlls() 580 575 { 581 dlllistmutex.enter();582 Win32DllBase *dll = Win32DllBase::head;583 while(dll) {584 585 586 }587 dlllistmutex.leave();576 dlllistmutex.enter(); 577 Win32DllBase *dll = Win32DllBase::head; 578 while(dll) { 579 dll->tlsDetachThread(); 580 dll = dll->getNext(); 581 } 582 dlllistmutex.leave(); 588 583 } 589 584 //****************************************************************************** … … 593 588 Win32DllBase *dll = Win32DllBase::head; 594 589 595 dprintf(("Win32DllBase::deleteAll"));590 dprintf(("Win32DllBase::deleteAll")); 596 591 597 592 #ifdef DEBUG_ENABLELOG_LEVEL2 598 if(dll) dll->printListOfDlls();593 if(dll) dll->printListOfDlls(); 599 594 #endif 600 595 601 dlllistmutex.enter();602 while(dll) {603 604 605 }606 dlllistmutex.leave();607 dprintf(("Win32DllBase::deleteAll Done!"));596 dlllistmutex.enter(); 597 while(dll) { 598 dll->Release(); 599 dll = Win32DllBase::head; 600 } 601 dlllistmutex.leave(); 602 dprintf(("Win32DllBase::deleteAll Done!")); 608 603 } 609 604 //****************************************************************************** … … 615 610 QueueItem *item; 616 611 617 dprintf(("Win32DllBase::deleteDynamicLibs"));612 dprintf(("Win32DllBase::deleteDynamicLibs")); 618 613 #ifdef DEBUG_ENABLELOG_LEVEL2 619 if(dll) dll->printListOfDlls();614 if(dll) dll->printListOfDlls(); 620 615 #endif 621 616 622 dlllistmutex.enter();623 624 item = loadLibDlls.Head();625 while(item) {626 627 628 629 630 631 632 633 634 635 elseDebugInt3();636 637 }638 639 dlllistmutex.leave();640 dprintf(("Win32DllBase::deleteDynamicLibs end"));617 dlllistmutex.enter(); 618 619 item = loadLibDlls.Head(); 620 while(item) { 621 dll = (Win32DllBase *)loadLibDlls.getItem(item); 622 int dynref = dll->nrDynamicLibRef; 623 if(dynref) { 624 while(dynref) { 625 dynref--; 626 dll->decDynamicLib(); 627 dll->Release(); 628 } 629 } 630 else DebugInt3(); 631 item = loadLibDlls.Head(); //queue could have been changed, so start from the beginning 632 } 633 634 dlllistmutex.leave(); 635 dprintf(("Win32DllBase::deleteDynamicLibs end")); 641 636 } 642 637 //****************************************************************************** … … 644 639 Win32DllBase *Win32DllBase::getFirst() 645 640 { 646 return head;641 return head; 647 642 } 648 643 //****************************************************************************** … … 654 649 char renameddll[CCHMAXPATH]; 655 650 656 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "", renameddll,657 sizeof(renameddll)-1) <= 1)658 {659 660 661 }662 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "", renameddll,663 sizeof(renameddll)-1) <= 1)664 {665 666 667 }668 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "", renameddll,669 sizeof(renameddll)-1) <= 1)670 {671 672 673 }651 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "", renameddll, 652 sizeof(renameddll)-1) <= 1) 653 { 654 PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "OLE32OS2"); 655 PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLE32OS2", "OLE32"); 656 } 657 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "", renameddll, 658 sizeof(renameddll)-1) <= 1) 659 { 660 PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "OLAUTOS2"); 661 PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLAUTOS2", "OLEAUT32"); 662 } 663 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "", renameddll, 664 sizeof(renameddll)-1) <= 1) 665 { 666 PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "WNETAP32"); 667 PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "WNETAP32", "NETAPI32"); 668 } 674 669 } 675 670 //****************************************************************************** … … 686 681 char *sectionname; 687 682 688 if(fWinToOS2) { 689 sectionname = DLLRENAMEWIN_SECTION; 690 } 691 else { 692 sectionname = DLLRENAMEOS2_SECTION; 693 } 694 namestart = OSLibStripPath(dllname); 695 strcpy(modname, namestart); 696 char *dot = strrchr(modname, '.'); 697 if(dot) 698 *dot = 0; 699 strupr(modname); 700 if(PROFILE_GetOdinIniString(sectionname, modname, "", renameddll, 701 sizeof(renameddll)-1) > 1) 702 { 703 if(namestart == dllname) { 704 strcpy(dllname, renameddll); 705 } 706 else { 707 *namestart = 0; 708 strcat(dllname, renameddll); 709 } 710 strcat(dllname, ".dll"); 711 } 712 return; 683 if(fWinToOS2) { 684 sectionname = DLLRENAMEWIN_SECTION; 685 } 686 else { 687 sectionname = DLLRENAMEOS2_SECTION; 688 } 689 namestart = OSLibStripPath(dllname); 690 strcpy(modname, namestart); 691 char *dot = strrchr(modname, '.'); 692 if(dot) 693 *dot = 0; 694 strupr(modname); 695 if(PROFILE_GetOdinIniString(sectionname, modname, "", renameddll, 696 sizeof(renameddll)-1) > 1) 697 { 698 if(namestart == dllname) { 699 strcpy(dllname, renameddll); 700 } 701 else { 702 *namestart = 0; 703 strcat(dllname, renameddll); 704 } 705 if(!strchr(dllname, '.')) { 706 strcat(dllname, DLL_EXTENSION); 707 } 708 strupr(dllname); 709 } 710 return; 713 711 } 714 712 //****************************************************************************** … … 722 720 //// dprintf2(("findModule %s", dllname)); 723 721 724 strcpy(szDllName, OSLibStripPath(dllname)); 725 strupr(szDllName); 726 727 if(fRenameFirst) { 728 renameDll(szDllName, FALSE); 729 } 730 731 dot = strstr(szDllName, "."); 732 if(dot) 733 *dot = 0; 734 735 dlllistmutex.enter(); 736 dll = head; 737 while(dll) { 738 if(strcmpi(szDllName, dll->szModule) == 0) { 739 dlllistmutex.leave(); 740 return(dll); 741 } 742 743 dll = dll->next; 744 } 745 dlllistmutex.leave(); 746 return(NULL); 722 strcpy(szDllName, OSLibStripPath(dllname)); 723 strupr(szDllName); 724 725 if(fRenameFirst) { 726 renameDll(szDllName, FALSE); 727 } 728 729 dlllistmutex.enter(); 730 dll = head; 731 while(dll) { 732 if(strcmpi(szDllName, dll->szModule) == 0) { 733 dlllistmutex.leave(); 734 return(dll); 735 } 736 dll = dll->next; 737 } 738 dlllistmutex.leave(); 739 return(NULL); 747 740 } 748 741 //****************************************************************************** … … 750 743 Win32DllBase *Win32DllBase::findModule(WIN32DLLENTRY DllEntryPoint) 751 744 { 752 dprintf2(("findModule %X", DllEntryPoint));753 754 dlllistmutex.enter();755 Win32DllBase *mod = Win32DllBase::head;756 while(mod != NULL) {757 758 759 760 761 } 762 763 }764 dlllistmutex.leave();765 return(NULL);745 dprintf2(("findModule %X", DllEntryPoint)); 746 747 dlllistmutex.enter(); 748 Win32DllBase *mod = Win32DllBase::head; 749 while(mod != NULL) { 750 dbgCheckObj(mod); 751 if(mod->dllEntryPoint == DllEntryPoint) { 752 dlllistmutex.leave(); 753 return(mod); 754 } 755 mod = mod->next; 756 } 757 dlllistmutex.leave(); 758 return(NULL); 766 759 } 767 760 //****************************************************************************** … … 769 762 Win32DllBase *Win32DllBase::findModule(HINSTANCE hinstance) 770 763 { 771 dlllistmutex.enter();772 773 Win32DllBase *mod = Win32DllBase::head;774 while(mod != NULL) {775 776 777 778 779 } 780 781 }782 dlllistmutex.leave();783 return(NULL);764 dlllistmutex.enter(); 765 766 Win32DllBase *mod = Win32DllBase::head; 767 while(mod != NULL) { 768 dbgCheckObj(mod); 769 if(mod->hinstance == hinstance) { 770 dlllistmutex.leave(); 771 return(mod); 772 } 773 mod = mod->next; 774 } 775 dlllistmutex.leave(); 776 return(NULL); 784 777 } 785 778 //****************************************************************************** … … 787 780 Win32DllBase *Win32DllBase::findModuleByAddr(ULONG address) 788 781 { 789 dlllistmutex.enter();790 791 Win32DllBase *mod = Win32DllBase::head;792 while(mod != NULL) {793 794 795 796 797 } 798 799 }800 dlllistmutex.leave();801 return(NULL);782 dlllistmutex.enter(); 783 784 Win32DllBase *mod = Win32DllBase::head; 785 while(mod != NULL) { 786 dbgCheckObj(mod); 787 if(mod->insideModule(address)) { 788 dlllistmutex.leave(); 789 return(mod); 790 } 791 mod = mod->next; 792 } 793 dlllistmutex.leave(); 794 return(NULL); 802 795 } 803 796 //****************************************************************************** … … 805 798 BOOL Win32DllBase::isDll() 806 799 { 807 return TRUE;800 return TRUE; 808 801 } 809 802 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.