[10590] | 1 | /* $Id: windllbase.cpp,v 1.36 2004-04-27 08:25:43 sandervl Exp $ */
|
---|
[956] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Win32 Dll base class
|
---|
| 5 | *
|
---|
[4523] | 6 | * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
[10397] | 7 | * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
|
---|
[956] | 8 | *
|
---|
[3059] | 9 | * Unloading of a dll always happens in order of dependency (taking nr of
|
---|
| 10 | * loads into account)
|
---|
| 11 | * Unloading of dynamically loaded dll (with LoadLibrary) in deleteAll
|
---|
| 12 | * is done in LIFO order (NT exhibits the same behaviour)
|
---|
[4523] | 13 | *
|
---|
[3059] | 14 | * RemoveCircularDependency: TODO: Send process detach message here??
|
---|
[956] | 15 | *
|
---|
| 16 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 17 | *
|
---|
| 18 | */
|
---|
| 19 | #define INCL_DOSFILEMGR /* File Manager values */
|
---|
| 20 | #define INCL_DOSERRORS /* DOS Error values */
|
---|
| 21 | #define INCL_DOSPROCESS /* DOS Process values */
|
---|
| 22 | #define INCL_DOSMODULEMGR
|
---|
| 23 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
---|
| 24 | #define INCL_WIN
|
---|
[4523] | 25 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
[956] | 26 | #include <stdio.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <stdlib.h>
|
---|
[21916] | 29 | #ifndef __GNUC__
|
---|
[956] | 30 | #include <iostream.h>
|
---|
| 31 | #include <fstream.h>
|
---|
[21916] | 32 | #endif
|
---|
[956] | 33 | #include <misc.h>
|
---|
[3059] | 34 | #include <win32api.h>
|
---|
[956] | 35 | #include <pefile.h>
|
---|
[21916] | 36 | #include "windllbase.h"
|
---|
| 37 | #include "winimagepe2lx.h"
|
---|
| 38 | #include "windllpe2lx.h"
|
---|
| 39 | #include "winimagelx.h"
|
---|
| 40 | #include "windlllx.h"
|
---|
[956] | 41 | #include <wprocess.h>
|
---|
| 42 | #include "exceptions.h"
|
---|
| 43 | #include "exceptutil.h"
|
---|
| 44 | #include "vmutex.h"
|
---|
| 45 | #include "oslibmisc.h"
|
---|
| 46 | #include "oslibdos.h"
|
---|
[1663] | 47 | #include "profile.h"
|
---|
[956] | 48 |
|
---|
[4523] | 49 | #define DBG_LOCALLOG DBG_windllbase
|
---|
[2802] | 50 | #include "dbglocal.h"
|
---|
| 51 |
|
---|
[956] | 52 | VMutex dlllistmutex; //protects linked lists of heaps
|
---|
| 53 |
|
---|
| 54 | //******************************************************************************
|
---|
| 55 | //******************************************************************************
|
---|
[4523] | 56 | Win32DllBase::Win32DllBase(HINSTANCE hinstance, WIN32DLLENTRY DllEntryPoint,
|
---|
[2069] | 57 | Win32ImageBase *parent)
|
---|
[956] | 58 | : Win32ImageBase(hinstance),
|
---|
[4523] | 59 | referenced(0), fSkipThreadEntryCalls(FALSE), next(NULL), fInserted(FALSE),
|
---|
| 60 | fAttachedToProcess(FALSE), fUnloaded(FALSE),
|
---|
| 61 | nrDynamicLibRef(0), fDisableUnload(FALSE), fSkipEntryCalls(FALSE)
|
---|
[956] | 62 | {
|
---|
[4523] | 63 | dllEntryPoint = DllEntryPoint;
|
---|
[956] | 64 |
|
---|
[4523] | 65 | setUnloadOrder(parent);
|
---|
| 66 |
|
---|
| 67 | dprintf(("Win32DllBase::Win32DllBase %x %s", hinstance, szModule));
|
---|
[956] | 68 | }
|
---|
| 69 | //******************************************************************************
|
---|
| 70 | //******************************************************************************
|
---|
| 71 | Win32DllBase::~Win32DllBase()
|
---|
| 72 | {
|
---|
[4523] | 73 | dprintf(("Win32DllBase::~Win32DllBase %s", szModule));
|
---|
[956] | 74 |
|
---|
[4523] | 75 | if(errorState == NO_ERROR && !fUnloaded)
|
---|
| 76 | {
|
---|
| 77 | detachProcess();
|
---|
| 78 | }
|
---|
[956] | 79 |
|
---|
[4523] | 80 | dlllistmutex.enter();
|
---|
| 81 | if(head == this) {
|
---|
| 82 | head = next;
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
[3005] | 85 | Win32DllBase *dll = head;
|
---|
[4523] | 86 | while(dll && dll->next != this) {
|
---|
| 87 | dll = dll->next;
|
---|
[956] | 88 | }
|
---|
[4523] | 89 | if(dll == NULL) {
|
---|
| 90 | dprintf(("~Win32DllBase: Can't find dll!\n"));
|
---|
| 91 | dlllistmutex.leave();
|
---|
| 92 | return;
|
---|
| 93 | }
|
---|
| 94 | dll->next = next;
|
---|
| 95 | }
|
---|
| 96 | dlllistmutex.leave();
|
---|
[956] | 97 | }
|
---|
| 98 | //******************************************************************************
|
---|
| 99 | //******************************************************************************
|
---|
[3059] | 100 | void Win32DllBase::incDynamicLib()
|
---|
[4523] | 101 | {
|
---|
| 102 | if(nrDynamicLibRef == 0) {
|
---|
[3854] | 103 | //NOTE:
|
---|
| 104 | //Must be called *after* attachprocess, since attachprocess may also
|
---|
| 105 | //trigger LoadLibrary calls
|
---|
| 106 | //Those dlls must not be put in front of this dll in the dynamic
|
---|
| 107 | //dll list; or else the unload order is wrong:
|
---|
| 108 | //i.e. RPAP3260 loads PNRS3260 in DLL_PROCESS_ATTACH
|
---|
| 109 | // this means that in ExitProcess, PNRS3260 needs to be removed
|
---|
| 110 | // first since RPAP3260 depends on it
|
---|
[4523] | 111 | dlllistmutex.enter();
|
---|
| 112 | loadLibDlls.Push((ULONG)this);
|
---|
| 113 | dlllistmutex.leave();
|
---|
| 114 | }
|
---|
| 115 | nrDynamicLibRef++;
|
---|
[3059] | 116 | }
|
---|
| 117 | //******************************************************************************
|
---|
| 118 | //******************************************************************************
|
---|
| 119 | void Win32DllBase::decDynamicLib()
|
---|
[4523] | 120 | {
|
---|
| 121 | nrDynamicLibRef--;
|
---|
| 122 | if(nrDynamicLibRef == 0) {
|
---|
| 123 | dlllistmutex.enter();
|
---|
| 124 | loadLibDlls.Remove((ULONG)this);
|
---|
| 125 | dlllistmutex.leave();
|
---|
| 126 | }
|
---|
[3059] | 127 | }
|
---|
| 128 | //******************************************************************************
|
---|
| 129 | //unload of dlls needs to be done in reverse order of dependencies
|
---|
[4523] | 130 | //Note: Only necessary for pe loader; the OS/2 loader takes care of this
|
---|
| 131 | //for win32k/pe2lx
|
---|
[3059] | 132 | //******************************************************************************
|
---|
| 133 | void Win32DllBase::setUnloadOrder(Win32ImageBase *parent)
|
---|
| 134 | {
|
---|
| 135 | Win32DllBase *dll;
|
---|
| 136 | Win32DllBase *parentdll = NULL;
|
---|
| 137 |
|
---|
[4523] | 138 | dlllistmutex.enter();
|
---|
| 139 | if(parent) {
|
---|
| 140 | dll = head;
|
---|
| 141 | while(dll) {
|
---|
| 142 | if(dll->getInstanceHandle() == parent->getInstanceHandle()) {
|
---|
| 143 | parentdll = dll;
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | dll = dll->next;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
[3059] | 149 |
|
---|
[4523] | 150 | //first check if this dll is already at a lower position (further down the list)
|
---|
| 151 | //than the parent
|
---|
| 152 | if(parentdll && fInserted) {//already in the list?
|
---|
| 153 | dll = parentdll->next;
|
---|
| 154 | while(dll) {
|
---|
| 155 | if(dll->getInstanceHandle() == getInstanceHandle()) {
|
---|
| 156 | dlllistmutex.leave();
|
---|
| 157 | return; //it's at a lower position, so no need to change anything
|
---|
| 158 | }
|
---|
| 159 | dll = dll->next;
|
---|
| 160 | }
|
---|
[3059] | 161 |
|
---|
[4523] | 162 | //it's already in the list but not at the right position; remove it now
|
---|
| 163 | if(head == this) {
|
---|
| 164 | head = next;
|
---|
| 165 | }
|
---|
| 166 | else {
|
---|
| 167 | dll = head;
|
---|
| 168 | while(dll->next) {
|
---|
| 169 | if(dll->next == this) {
|
---|
| 170 | dll->next = next;
|
---|
| 171 | break;
|
---|
| 172 | }
|
---|
| 173 | dll = dll->next;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | else
|
---|
| 178 | if(fInserted) {//already in the list?
|
---|
| 179 | dlllistmutex.leave();
|
---|
| 180 | return;
|
---|
| 181 | }
|
---|
| 182 | //(re)insert it in the list after it's parent
|
---|
| 183 | if(parentdll) {
|
---|
| 184 | next = parentdll->next;
|
---|
| 185 | parentdll->next = this;
|
---|
| 186 | }
|
---|
| 187 | else {//no parent or exe, just add it at the start of the list
|
---|
| 188 | next = head;
|
---|
| 189 | head = this;
|
---|
| 190 | }
|
---|
| 191 | fInserted = TRUE;
|
---|
[3059] | 192 |
|
---|
[4523] | 193 | //Now do the same thing for the child dependencies
|
---|
| 194 | QueueItem *item;
|
---|
[3059] | 195 |
|
---|
[4523] | 196 | item = loadedDlls.Head();
|
---|
| 197 | while(item) {
|
---|
| 198 | dll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
| 199 | //Check for circular dependencies (i.e. in Lotus Notes)
|
---|
| 200 | if(dll != parentdll) {
|
---|
| 201 | dll->setUnloadOrder(this);
|
---|
| 202 | }
|
---|
| 203 | item = loadedDlls.getNext(item);
|
---|
| 204 | }
|
---|
| 205 | dlllistmutex.leave();
|
---|
[3059] | 206 | }
|
---|
| 207 | //******************************************************************************
|
---|
| 208 | //******************************************************************************
|
---|
| 209 | #ifdef DEBUG
|
---|
| 210 | ULONG Win32DllBase::AddRef(char *parentname)
|
---|
| 211 | #else
|
---|
| 212 | ULONG Win32DllBase::AddRef()
|
---|
| 213 | #endif
|
---|
[4523] | 214 | {
|
---|
[3059] | 215 | Win32DllBase *dll;
|
---|
| 216 |
|
---|
[10433] | 217 | #ifdef DEBUG
|
---|
[4523] | 218 | dprintf(("Win32DllBase::AddRef %s->%s %d", parentname, getModuleName(), referenced+1));
|
---|
[10433] | 219 | #endif
|
---|
[4523] | 220 | ++referenced;
|
---|
[3059] | 221 | #ifdef DEBUG
|
---|
[4523] | 222 | if(referenced == 1) {
|
---|
| 223 | printListOfDlls();
|
---|
| 224 | //printDependencies(NULL);
|
---|
| 225 | }
|
---|
[3059] | 226 | #endif
|
---|
[4523] | 227 | return referenced;
|
---|
[3059] | 228 | }
|
---|
| 229 | //******************************************************************************
|
---|
| 230 | //******************************************************************************
|
---|
[956] | 231 | ULONG Win32DllBase::Release()
|
---|
[1134] | 232 | {
|
---|
[3059] | 233 | Queue queue;
|
---|
| 234 | QueueItem *item;
|
---|
| 235 | Win32DllBase *dll;
|
---|
| 236 | LONG ret;
|
---|
[8609] | 237 | char szModuleName[256];
|
---|
[956] | 238 |
|
---|
[4523] | 239 | dprintf(("Win32DllBase::Release %s %d", getModuleName(), referenced-1));
|
---|
[3059] | 240 |
|
---|
[4523] | 241 | ret = --referenced;
|
---|
| 242 | if(ret <= 0) {
|
---|
| 243 | //make copy of linked list of dependencies
|
---|
| 244 | queue = loadedDlls;
|
---|
[3059] | 245 |
|
---|
[4523] | 246 | //remove any circular dependencies on this dll that might be present
|
---|
| 247 | item = queue.Head();
|
---|
| 248 | while(item) {
|
---|
| 249 | dll = (Win32DllBase *)queue.getItem(item);
|
---|
| 250 | if(dll == NULL) {
|
---|
| 251 | dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
|
---|
| 252 | DebugInt3();
|
---|
| 253 | return -1;
|
---|
| 254 | }
|
---|
| 255 | dll->RemoveCircularDependency(this);
|
---|
| 256 | item = queue.getNext(item);
|
---|
| 257 | }
|
---|
[3059] | 258 | #ifdef DEBUG
|
---|
[8609] | 259 | // printDependencies(getName());
|
---|
[3059] | 260 | #endif
|
---|
[5782] | 261 |
|
---|
[4523] | 262 | dprintf(("Win32DllBase::Release %s referenced == 0", getModuleName()));
|
---|
[8609] | 263 | strncpy(szModuleName, getModuleName(), sizeof(szModuleName));
|
---|
[3059] | 264 |
|
---|
[4523] | 265 | //delete dll object
|
---|
| 266 | delete this;
|
---|
[3059] | 267 |
|
---|
[4523] | 268 | //unreference all of it's dependencies
|
---|
| 269 | item = queue.Head();
|
---|
| 270 | while(item) {
|
---|
| 271 | dll = (Win32DllBase *)queue.getItem(item);
|
---|
| 272 | if(dll == NULL) {
|
---|
| 273 | dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
|
---|
| 274 | DebugInt3();
|
---|
| 275 | return -1;
|
---|
| 276 | }
|
---|
[8609] | 277 | dprintf(("Remove %s->%s dependency", szModuleName, dll->getName()));
|
---|
[4523] | 278 | dll->Release();
|
---|
| 279 | item = queue.getNext(item);
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | return(ret);
|
---|
[956] | 283 | }
|
---|
| 284 | //******************************************************************************
|
---|
[3059] | 285 | //Lotus Notes has several ugly circular dependencies in it's dlls.
|
---|
| 286 | //Remove them before they cause problems.
|
---|
[956] | 287 | //******************************************************************************
|
---|
[3059] | 288 | BOOL Win32DllBase::RemoveCircularDependency(Win32DllBase *parent)
|
---|
| 289 | {
|
---|
| 290 | QueueItem *item, *tmp;
|
---|
| 291 | Win32DllBase *dll;
|
---|
| 292 | BOOL ret = FALSE;
|
---|
| 293 |
|
---|
[4523] | 294 | //remove any circular dependencies on this dll that might be present
|
---|
| 295 | item = loadedDlls.Head();
|
---|
| 296 | while(item) {
|
---|
| 297 | dll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
| 298 | if(dll == NULL) {
|
---|
| 299 | dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
|
---|
| 300 | DebugInt3();
|
---|
| 301 | return FALSE;
|
---|
| 302 | }
|
---|
| 303 | tmp = loadedDlls.getNext(item);
|
---|
| 304 | if(dll == parent) {
|
---|
| 305 | dprintf(("Removing CIRCULAR dependency %s->%s", parent->getModuleName(), dll->getModuleName()));
|
---|
| 306 | loadedDlls.Remove(item);
|
---|
| 307 | ret = TRUE;
|
---|
| 308 | }
|
---|
| 309 | //// else ret |= dll->RemoveCircularDependency(parent);
|
---|
| 310 | item = tmp;
|
---|
| 311 | }
|
---|
| 312 | //TODO: Send process detach message here??
|
---|
| 313 | return ret;
|
---|
[3059] | 314 | }
|
---|
| 315 | //******************************************************************************
|
---|
[4523] | 316 | //There's a slight problem with our dependency procedure.
|
---|
[3059] | 317 | //example: gdi32 is loaded -> depends on kernel32 (which is already loaded)
|
---|
| 318 | // kernel32's reference count isn't updated
|
---|
| 319 | // (when we load gdi32, we don't know which dlls it depends on and which
|
---|
| 320 | // of those are already loaded and which aren't)
|
---|
| 321 | //-> solution: Determine reference counts of dependant lx dlls and update those
|
---|
| 322 | // reference counts
|
---|
| 323 | //******************************************************************************
|
---|
| 324 | void Win32DllBase::updateDependencies()
|
---|
| 325 | {
|
---|
| 326 | QueueItem *item;
|
---|
| 327 | Win32DllBase *dll, *depdll;
|
---|
| 328 | ULONG refcount;
|
---|
| 329 |
|
---|
[4523] | 330 | dlllistmutex.enter();
|
---|
| 331 | item = loadedDlls.Head();
|
---|
| 332 | while(item) {
|
---|
| 333 | depdll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
| 334 | if(depdll == NULL) {
|
---|
| 335 | dprintf(("updateDependencies: depdll == NULL!!"));
|
---|
| 336 | DebugInt3();
|
---|
| 337 | return;
|
---|
| 338 | }
|
---|
| 339 | refcount = 0;
|
---|
| 340 | dll = head;
|
---|
[3059] | 341 |
|
---|
[4523] | 342 | while(dll) {
|
---|
| 343 | if(dll->dependsOn(depdll)) {
|
---|
| 344 | refcount++;
|
---|
| 345 | }
|
---|
| 346 | dll = dll->getNext();
|
---|
| 347 | }
|
---|
| 348 | if(refcount > depdll->referenced) {
|
---|
| 349 | dprintf(("Win32DllBase::updateDependencies changing refcount of %s to %d (old=%d)", depdll->getModuleName(), refcount, depdll->referenced));
|
---|
| 350 | depdll->referenced = refcount;
|
---|
| 351 | }
|
---|
| 352 | item = loadedDlls.getNext(item);
|
---|
| 353 | }
|
---|
| 354 | dlllistmutex.leave();
|
---|
[3059] | 355 | }
|
---|
| 356 | //******************************************************************************
|
---|
| 357 | //******************************************************************************
|
---|
| 358 | #ifdef DEBUG
|
---|
| 359 | void Win32DllBase::printDependencies(char *parent)
|
---|
| 360 | {
|
---|
| 361 | QueueItem *item;
|
---|
| 362 | Win32DllBase *dll;
|
---|
| 363 | ULONG ret;
|
---|
| 364 |
|
---|
[4523] | 365 | dprintf(("Dependency list: %s->%s %d", parent, getModuleName(), referenced));
|
---|
| 366 | item = loadedDlls.Head();
|
---|
| 367 | while(item) {
|
---|
| 368 | dll = (Win32DllBase *)loadedDlls.getItem(item);
|
---|
| 369 | if(dll == NULL) {
|
---|
| 370 | return;
|
---|
| 371 | }
|
---|
| 372 | dll->printDependencies(getModuleName());
|
---|
| 373 | item = loadedDlls.getNext(item);
|
---|
| 374 | }
|
---|
[3059] | 375 | }
|
---|
| 376 | //******************************************************************************
|
---|
| 377 | //******************************************************************************
|
---|
| 378 | void Win32DllBase::printListOfDlls()
|
---|
| 379 | {
|
---|
| 380 | Win32DllBase *dll;
|
---|
| 381 |
|
---|
[4523] | 382 | dll = head;
|
---|
[3059] | 383 |
|
---|
[4523] | 384 | dprintf2(("Win32DllBase::Win32DllBase: List of loaded dlls:"));
|
---|
| 385 | while(dll) {
|
---|
| 386 | dprintf2(("DLL %s %d", dll->szModule, dll->referenced));
|
---|
| 387 | dll = dll->next;
|
---|
| 388 | }
|
---|
[3059] | 389 | }
|
---|
| 390 | #endif
|
---|
| 391 | //******************************************************************************
|
---|
| 392 | //******************************************************************************
|
---|
[956] | 393 | BOOL Win32DllBase::attachProcess()
|
---|
| 394 | {
|
---|
| 395 | WINEXCEPTION_FRAME exceptFrame;
|
---|
| 396 | USHORT sel;
|
---|
[4658] | 397 | TEB *teb;
|
---|
[1670] | 398 | BOOL rc, fSetExceptionHandler;
|
---|
[956] | 399 |
|
---|
[4523] | 400 | if(fAttachedToProcess || fSkipEntryCalls)
|
---|
| 401 | return TRUE;
|
---|
[1134] | 402 |
|
---|
[4523] | 403 | fAttachedToProcess = TRUE;
|
---|
[956] | 404 |
|
---|
[4658] | 405 | teb = GetThreadTEB();
|
---|
| 406 | fSetExceptionHandler = (!teb || teb->teb_sel != GetFS());
|
---|
[1670] | 407 |
|
---|
[4523] | 408 | //Note: The Win32 exception structure references by FS:[0] is the same
|
---|
| 409 | // in OS/2
|
---|
| 410 | if(fSetExceptionHandler) {
|
---|
| 411 | OS2SetExceptionHandler((void *)&exceptFrame);
|
---|
[7811] | 412 | sel = SetWin32TIB(isPEImage() ? TIB_SWITCH_FORCE_WIN32 : TIB_SWITCH_DEFAULT);
|
---|
[4523] | 413 | }
|
---|
[1670] | 414 |
|
---|
[4523] | 415 | if(dllEntryPoint == NULL) {
|
---|
[956] | 416 | dprintf(("attachProcess not required for dll %s", szModule));
|
---|
[4523] | 417 | if(fSetExceptionHandler) {
|
---|
| 418 | SetFS(sel);
|
---|
| 419 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
| 420 | }
|
---|
| 421 | return(TRUE);
|
---|
| 422 | }
|
---|
[956] | 423 |
|
---|
[4523] | 424 | // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL
|
---|
| 425 | // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads
|
---|
| 426 | // and non-NULL for static loads.
|
---|
| 427 | // same goes for process termination
|
---|
| 428 | LPVOID lpvReserved;
|
---|
[956] | 429 |
|
---|
[4523] | 430 | if (isDynamicLib())
|
---|
| 431 | lpvReserved = NULL;
|
---|
| 432 | else
|
---|
| 433 | lpvReserved = (LPVOID)0xdeadface; // some arbitrary value
|
---|
| 434 |
|
---|
[5782] | 435 | #ifdef DEBUG
|
---|
| 436 | int time1, time2;
|
---|
[8609] | 437 | dprintf(("attachProcess to dll %s (%x)", szModule, dllEntryPoint));
|
---|
[5782] | 438 | time1 = GetTickCount();
|
---|
| 439 | #endif
|
---|
| 440 |
|
---|
[4523] | 441 | rc = dllEntryPoint(hinstance, DLL_PROCESS_ATTACH, lpvReserved);
|
---|
| 442 |
|
---|
[5782] | 443 | #ifdef DEBUG
|
---|
| 444 | time2 = GetTickCount();
|
---|
[10397] | 445 | dprintf(("attachProcess to dll %s DONE in %x msec rc %d", szModule, time2-time1, rc));
|
---|
[5782] | 446 | #endif
|
---|
[4523] | 447 |
|
---|
| 448 | if(fSetExceptionHandler) {
|
---|
| 449 | SetFS(sel);
|
---|
| 450 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
| 451 | }
|
---|
| 452 | else
|
---|
[4658] | 453 | if(teb) {
|
---|
| 454 | if(teb->teb_sel != GetFS()) {
|
---|
[4523] | 455 | dprintf(("Win32DllBase::attachProcess: FS was changed by dll entrypoint!!!!"));
|
---|
| 456 | DebugInt3();
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 | return rc;
|
---|
[956] | 460 | }
|
---|
| 461 | //******************************************************************************
|
---|
| 462 | //******************************************************************************
|
---|
| 463 | BOOL Win32DllBase::detachProcess()
|
---|
| 464 | {
|
---|
| 465 | WINEXCEPTION_FRAME exceptFrame;
|
---|
| 466 | USHORT sel;
|
---|
| 467 | BOOL rc;
|
---|
| 468 |
|
---|
[4523] | 469 | if(fSkipEntryCalls) {
|
---|
| 470 | fUnloaded = TRUE;
|
---|
| 471 | return TRUE;
|
---|
| 472 | }
|
---|
[4474] | 473 |
|
---|
[4523] | 474 | if(dllEntryPoint == NULL) {
|
---|
| 475 | tlsDetachThread(); //destroy TLS (main thread)
|
---|
| 476 | fUnloaded = TRUE;
|
---|
| 477 | return(TRUE);
|
---|
| 478 | }
|
---|
[956] | 479 |
|
---|
[8609] | 480 | dprintf(("detachProcess from dll %s (%x)", szModule, dllEntryPoint));
|
---|
[956] | 481 |
|
---|
[4523] | 482 | //Note: The Win32 exception structure references by FS:[0] is the same
|
---|
| 483 | // in OS/2
|
---|
| 484 | OS2SetExceptionHandler((void *)&exceptFrame);
|
---|
[956] | 485 |
|
---|
[4523] | 486 | fUnloaded = TRUE;
|
---|
[7811] | 487 | sel = SetWin32TIB(isPEImage() ? TIB_SWITCH_FORCE_WIN32 : TIB_SWITCH_DEFAULT);
|
---|
[956] | 488 |
|
---|
[4523] | 489 | // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL
|
---|
| 490 | // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads
|
---|
| 491 | // and non-NULL for static loads.
|
---|
| 492 | // same goes for process termination
|
---|
| 493 | LPVOID lpvReserved;
|
---|
[956] | 494 |
|
---|
[4523] | 495 | if (isDynamicLib())
|
---|
| 496 | lpvReserved = NULL;
|
---|
| 497 | else
|
---|
| 498 | lpvReserved = (LPVOID)0xdeadface; // some arbitrary value
|
---|
| 499 |
|
---|
| 500 | rc = dllEntryPoint(hinstance, DLL_PROCESS_DETACH, lpvReserved);
|
---|
| 501 |
|
---|
[7811] | 502 | SetFS(sel); //restore FS
|
---|
[4523] | 503 | tlsDetachThread(); //destroy TLS (main thread)
|
---|
| 504 | tlsDelete();
|
---|
| 505 |
|
---|
| 506 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
| 507 |
|
---|
| 508 | return rc;
|
---|
[956] | 509 | }
|
---|
| 510 | //******************************************************************************
|
---|
| 511 | //******************************************************************************
|
---|
| 512 | BOOL Win32DllBase::attachThread()
|
---|
| 513 | {
|
---|
| 514 | WINEXCEPTION_FRAME exceptFrame;
|
---|
| 515 | BOOL rc;
|
---|
| 516 |
|
---|
[4523] | 517 | if(fSkipThreadEntryCalls || dllEntryPoint == NULL)
|
---|
| 518 | return(TRUE);
|
---|
[956] | 519 |
|
---|
[4523] | 520 | dprintf(("attachThread to dll %s", szModule));
|
---|
[956] | 521 |
|
---|
[4523] | 522 | rc = dllEntryPoint(hinstance, DLL_THREAD_ATTACH, 0);
|
---|
[1670] | 523 |
|
---|
[4523] | 524 | dprintf(("attachThread to dll %s DONE", szModule));
|
---|
| 525 |
|
---|
| 526 | return rc;
|
---|
[956] | 527 | }
|
---|
| 528 | //******************************************************************************
|
---|
| 529 | //******************************************************************************
|
---|
| 530 | BOOL Win32DllBase::detachThread()
|
---|
| 531 | {
|
---|
| 532 | WINEXCEPTION_FRAME exceptFrame;
|
---|
| 533 | BOOL rc;
|
---|
| 534 |
|
---|
[4523] | 535 | if(fSkipThreadEntryCalls || dllEntryPoint == NULL)
|
---|
| 536 | return(TRUE);
|
---|
[956] | 537 |
|
---|
[4523] | 538 | dprintf(("detachThread from dll %s", szModule));
|
---|
| 539 |
|
---|
| 540 | rc = dllEntryPoint(hinstance, DLL_THREAD_DETACH, 0);
|
---|
| 541 | return rc;
|
---|
[956] | 542 | }
|
---|
| 543 | //******************************************************************************
|
---|
| 544 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
|
---|
| 545 | //******************************************************************************
|
---|
| 546 | void Win32DllBase::attachThreadToAllDlls()
|
---|
| 547 | {
|
---|
[4523] | 548 | dlllistmutex.enter();
|
---|
| 549 | Win32DllBase *dll = Win32DllBase::head;
|
---|
| 550 | while(dll) {
|
---|
| 551 | dll->attachThread();
|
---|
| 552 | dll = dll->getNext();
|
---|
| 553 | }
|
---|
| 554 | dlllistmutex.leave();
|
---|
[956] | 555 | }
|
---|
| 556 | //******************************************************************************
|
---|
| 557 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
|
---|
| 558 | //******************************************************************************
|
---|
| 559 | void Win32DllBase::detachThreadFromAllDlls()
|
---|
| 560 | {
|
---|
[4523] | 561 | dlllistmutex.enter();
|
---|
| 562 | Win32DllBase *dll = Win32DllBase::head;
|
---|
| 563 | while(dll) {
|
---|
| 564 | dll->detachThread();
|
---|
| 565 | dll = dll->getNext();
|
---|
| 566 | }
|
---|
[8923] | 567 | dlllistmutex.leave();
|
---|
[956] | 568 | }
|
---|
| 569 | //******************************************************************************
|
---|
[8923] | 570 | //Send DLL_PROCESS_DETACH message to all dlls for process that's about to end
|
---|
| 571 | //******************************************************************************
|
---|
| 572 | void Win32DllBase::detachProcessFromAllDlls()
|
---|
| 573 | {
|
---|
| 574 | dlllistmutex.enter();
|
---|
| 575 | Win32DllBase *dll = Win32DllBase::head;
|
---|
| 576 | while(dll) {
|
---|
| 577 | dll->detachProcess();
|
---|
| 578 | dll = dll->getNext();
|
---|
| 579 | }
|
---|
| 580 | dlllistmutex.leave();
|
---|
| 581 | }
|
---|
| 582 | //******************************************************************************
|
---|
[956] | 583 | //Setup TLS structure for all dlls for a new thread
|
---|
| 584 | //******************************************************************************
|
---|
| 585 | void Win32DllBase::tlsAttachThreadToAllDlls()
|
---|
| 586 | {
|
---|
[4523] | 587 | dlllistmutex.enter();
|
---|
| 588 | Win32DllBase *dll = Win32DllBase::head;
|
---|
| 589 | while(dll) {
|
---|
| 590 | dll->tlsAttachThread();
|
---|
| 591 | dll = dll->getNext();
|
---|
| 592 | }
|
---|
| 593 | dlllistmutex.leave();
|
---|
[956] | 594 | }
|
---|
| 595 | //******************************************************************************
|
---|
| 596 | //Destroy TLS structure for all dlls for a thread that's about to die
|
---|
| 597 | //******************************************************************************
|
---|
| 598 | void Win32DllBase::tlsDetachThreadFromAllDlls()
|
---|
| 599 | {
|
---|
[4523] | 600 | dlllistmutex.enter();
|
---|
| 601 | Win32DllBase *dll = Win32DllBase::head;
|
---|
| 602 | while(dll) {
|
---|
| 603 | dll->tlsDetachThread();
|
---|
| 604 | dll = dll->getNext();
|
---|
| 605 | }
|
---|
| 606 | dlllistmutex.leave();
|
---|
[956] | 607 | }
|
---|
| 608 | //******************************************************************************
|
---|
| 609 | //******************************************************************************
|
---|
[3059] | 610 | void Win32DllBase::deleteAll()
|
---|
[956] | 611 | {
|
---|
[3059] | 612 | Win32DllBase *dll = Win32DllBase::head;
|
---|
[3005] | 613 |
|
---|
[4523] | 614 | dprintf(("Win32DllBase::deleteAll"));
|
---|
[3059] | 615 |
|
---|
[8609] | 616 | #ifdef DEBUG
|
---|
[4523] | 617 | if(dll) dll->printListOfDlls();
|
---|
[3059] | 618 | #endif
|
---|
| 619 |
|
---|
[4523] | 620 | dlllistmutex.enter();
|
---|
| 621 | while(dll) {
|
---|
| 622 | dll->Release();
|
---|
| 623 | dll = Win32DllBase::head;
|
---|
| 624 | }
|
---|
| 625 | dlllistmutex.leave();
|
---|
| 626 | dprintf(("Win32DllBase::deleteAll Done!"));
|
---|
[3059] | 627 | }
|
---|
| 628 | //******************************************************************************
|
---|
| 629 | //Delete dlls loaded by LoadLibrary(Ex) in LIFO order
|
---|
| 630 | //******************************************************************************
|
---|
| 631 | void Win32DllBase::deleteDynamicLibs()
|
---|
| 632 | {
|
---|
| 633 | Win32DllBase *dll = head;
|
---|
| 634 | QueueItem *item;
|
---|
| 635 |
|
---|
[4523] | 636 | dprintf(("Win32DllBase::deleteDynamicLibs"));
|
---|
[8609] | 637 | #ifdef DEBUG
|
---|
[4523] | 638 | if(dll) dll->printListOfDlls();
|
---|
[956] | 639 | #endif
|
---|
| 640 |
|
---|
[4523] | 641 | dlllistmutex.enter();
|
---|
[3059] | 642 |
|
---|
[4523] | 643 | item = loadLibDlls.Head();
|
---|
| 644 | while(item) {
|
---|
| 645 | dll = (Win32DllBase *)loadLibDlls.getItem(item);
|
---|
| 646 | int dynref = dll->nrDynamicLibRef;
|
---|
| 647 | if(dynref) {
|
---|
[8609] | 648 | dprintf(("delete dynamic library references for %s", dll->getName()));
|
---|
[4523] | 649 | while(dynref) {
|
---|
| 650 | dynref--;
|
---|
| 651 | dll->decDynamicLib();
|
---|
| 652 | dll->Release();
|
---|
| 653 | }
|
---|
| 654 | }
|
---|
| 655 | else DebugInt3();
|
---|
| 656 | item = loadLibDlls.Head(); //queue could have been changed, so start from the beginning
|
---|
| 657 | }
|
---|
[3059] | 658 |
|
---|
[4523] | 659 | dlllistmutex.leave();
|
---|
| 660 | dprintf(("Win32DllBase::deleteDynamicLibs end"));
|
---|
[956] | 661 | }
|
---|
| 662 | //******************************************************************************
|
---|
[3059] | 663 | //******************************************************************************
|
---|
| 664 | Win32DllBase *Win32DllBase::getFirst()
|
---|
| 665 | {
|
---|
[4523] | 666 | return head;
|
---|
[3059] | 667 | }
|
---|
| 668 | //******************************************************************************
|
---|
[1811] | 669 | //Add renaming profile strings for ole32 & netapi32 to odin.ini if they aren't
|
---|
| 670 | //already there
|
---|
| 671 | //******************************************************************************
|
---|
| 672 | void Win32DllBase::setDefaultRenaming()
|
---|
| 673 | {
|
---|
| 674 | char renameddll[CCHMAXPATH];
|
---|
| 675 |
|
---|
[4523] | 676 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "", renameddll,
|
---|
| 677 | sizeof(renameddll)-1) <= 1)
|
---|
| 678 | {
|
---|
| 679 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "OLE32OS2");
|
---|
| 680 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLE32OS2", "OLE32");
|
---|
| 681 | }
|
---|
| 682 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "", renameddll,
|
---|
| 683 | sizeof(renameddll)-1) <= 1)
|
---|
| 684 | {
|
---|
| 685 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "OLAUTOS2");
|
---|
| 686 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLAUTOS2", "OLEAUT32");
|
---|
| 687 | }
|
---|
| 688 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "", renameddll,
|
---|
| 689 | sizeof(renameddll)-1) <= 1)
|
---|
| 690 | {
|
---|
| 691 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "WNETAP32");
|
---|
| 692 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "WNETAP32", "NETAPI32");
|
---|
| 693 | }
|
---|
[4526] | 694 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "WINSPOOL", "", renameddll,
|
---|
| 695 | sizeof(renameddll)-1) <= 1)
|
---|
| 696 | {
|
---|
[10054] | 697 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "WINSPOOL.DRV", "WINSPOOL.DLL");
|
---|
[4526] | 698 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "WINSPOOL", "WINSPOOL.DRV");
|
---|
| 699 | }
|
---|
[4739] | 700 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "MCICDA", "", renameddll,
|
---|
| 701 | sizeof(renameddll)-1) <= 1)
|
---|
| 702 | {
|
---|
[10054] | 703 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "MCICDA.DRV", "MCICDA.DLL");
|
---|
[4739] | 704 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "MCICDA", "MCICDA.DRV");
|
---|
| 705 | }
|
---|
[6249] | 706 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "CRTDLL", "", renameddll,
|
---|
| 707 | sizeof(renameddll)-1) <= 1)
|
---|
| 708 | {
|
---|
| 709 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "CRTDLL", "CRTDLL32");
|
---|
| 710 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "CRTDLL32", "CRTDLL");
|
---|
| 711 | }
|
---|
[21308] | 712 | if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "IMM32", "", renameddll,
|
---|
| 713 | sizeof(renameddll)-1) <= 1)
|
---|
| 714 | {
|
---|
| 715 | PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "IMM32", "IMM32OS2");
|
---|
| 716 | PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "IMM32OS2", "IMM32");
|
---|
| 717 | }
|
---|
[1811] | 718 | }
|
---|
| 719 | //******************************************************************************
|
---|
[1663] | 720 | //rename dll if necessary:
|
---|
| 721 | // Win32 to OS/2 : (i.e. OLE32 -> OLE32OS2)
|
---|
| 722 | // or
|
---|
| 723 | // OS/2 to Win32 : (i.e. OLE32OS2 -> OLE32)
|
---|
[956] | 724 | //******************************************************************************
|
---|
[1663] | 725 | void Win32DllBase::renameDll(char *dllname, BOOL fWinToOS2)
|
---|
| 726 | {
|
---|
| 727 | char modname[CCHMAXPATH];
|
---|
| 728 | char renameddll[CCHMAXPATH];
|
---|
| 729 | char *namestart;
|
---|
[21916] | 730 | const char *sectionname;
|
---|
[1663] | 731 |
|
---|
[4523] | 732 | if(fWinToOS2) {
|
---|
| 733 | sectionname = DLLRENAMEWIN_SECTION;
|
---|
| 734 | }
|
---|
| 735 | else {
|
---|
| 736 | sectionname = DLLRENAMEOS2_SECTION;
|
---|
| 737 | }
|
---|
| 738 | namestart = OSLibStripPath(dllname);
|
---|
| 739 | strcpy(modname, namestart);
|
---|
| 740 | char *dot = strrchr(modname, '.');
|
---|
[10054] | 741 |
|
---|
| 742 | if((dot) && !(stricmp(dot,".DLL")))
|
---|
[4523] | 743 | *dot = 0;
|
---|
[10054] | 744 |
|
---|
[4523] | 745 | strupr(modname);
|
---|
| 746 | if(PROFILE_GetOdinIniString(sectionname, modname, "", renameddll,
|
---|
| 747 | sizeof(renameddll)-1) > 1)
|
---|
| 748 | {
|
---|
| 749 | if(namestart == dllname) {
|
---|
| 750 | strcpy(dllname, renameddll);
|
---|
| 751 | }
|
---|
| 752 | else {
|
---|
| 753 | *namestart = 0;
|
---|
| 754 | strcat(dllname, renameddll);
|
---|
| 755 | }
|
---|
| 756 | if(!strchr(dllname, '.')) {
|
---|
| 757 | strcat(dllname, DLL_EXTENSION);
|
---|
| 758 | }
|
---|
| 759 | strupr(dllname);
|
---|
| 760 | }
|
---|
| 761 | return;
|
---|
[1663] | 762 | }
|
---|
| 763 | //******************************************************************************
|
---|
| 764 | //******************************************************************************
|
---|
[3059] | 765 | Win32DllBase *Win32DllBase::findModule(char *dllname, BOOL fRenameFirst)
|
---|
[956] | 766 | {
|
---|
| 767 | Win32DllBase *dll;
|
---|
| 768 | char szDllName[CCHMAXPATH];
|
---|
| 769 | char *dot, *temp;
|
---|
| 770 |
|
---|
[3059] | 771 | //// dprintf2(("findModule %s", dllname));
|
---|
[956] | 772 |
|
---|
[4523] | 773 | strcpy(szDllName, OSLibStripPath(dllname));
|
---|
| 774 | strupr(szDllName);
|
---|
[3059] | 775 |
|
---|
[4523] | 776 | if(fRenameFirst) {
|
---|
| 777 | renameDll(szDllName, FALSE);
|
---|
| 778 | }
|
---|
[4545] | 779 | dot = strstr(szDllName, ".");
|
---|
| 780 | if(dot == NULL) {
|
---|
| 781 | //if there's no extension or trainling dot, we
|
---|
| 782 | //assume it's a dll (see Win32 SDK docs)
|
---|
| 783 | strcat(szDllName, DLL_EXTENSION);
|
---|
| 784 | }
|
---|
| 785 | else {
|
---|
| 786 | if(dot[1] == 0) {
|
---|
| 787 | //a trailing dot means the module has no extension (SDK docs)
|
---|
| 788 | *dot = 0;
|
---|
| 789 | }
|
---|
| 790 | }
|
---|
[3059] | 791 |
|
---|
[4523] | 792 | dlllistmutex.enter();
|
---|
| 793 | dll = head;
|
---|
| 794 | while(dll) {
|
---|
[21916] | 795 | if(stricmp(szDllName, dll->szModule) == 0) {
|
---|
[4523] | 796 | dlllistmutex.leave();
|
---|
| 797 | return(dll);
|
---|
[956] | 798 | }
|
---|
[4523] | 799 | dll = dll->next;
|
---|
| 800 | }
|
---|
| 801 | dlllistmutex.leave();
|
---|
| 802 | return(NULL);
|
---|
[956] | 803 | }
|
---|
| 804 | //******************************************************************************
|
---|
| 805 | //******************************************************************************
|
---|
| 806 | Win32DllBase *Win32DllBase::findModule(WIN32DLLENTRY DllEntryPoint)
|
---|
| 807 | {
|
---|
[4523] | 808 | dprintf2(("findModule %X", DllEntryPoint));
|
---|
[956] | 809 |
|
---|
[4523] | 810 | dlllistmutex.enter();
|
---|
| 811 | Win32DllBase *mod = Win32DllBase::head;
|
---|
| 812 | while(mod != NULL) {
|
---|
| 813 | dbgCheckObj(mod);
|
---|
| 814 | if(mod->dllEntryPoint == DllEntryPoint) {
|
---|
| 815 | dlllistmutex.leave();
|
---|
| 816 | return(mod);
|
---|
[956] | 817 | }
|
---|
[4523] | 818 | mod = mod->next;
|
---|
| 819 | }
|
---|
| 820 | dlllistmutex.leave();
|
---|
| 821 | return(NULL);
|
---|
[956] | 822 | }
|
---|
| 823 | //******************************************************************************
|
---|
| 824 | //******************************************************************************
|
---|
| 825 | Win32DllBase *Win32DllBase::findModule(HINSTANCE hinstance)
|
---|
| 826 | {
|
---|
[4523] | 827 | dlllistmutex.enter();
|
---|
[956] | 828 |
|
---|
[4523] | 829 | Win32DllBase *mod = Win32DllBase::head;
|
---|
| 830 | while(mod != NULL) {
|
---|
| 831 | dbgCheckObj(mod);
|
---|
| 832 | if(mod->hinstance == hinstance) {
|
---|
| 833 | dlllistmutex.leave();
|
---|
| 834 | return(mod);
|
---|
[956] | 835 | }
|
---|
[4523] | 836 | mod = mod->next;
|
---|
| 837 | }
|
---|
| 838 | dlllistmutex.leave();
|
---|
| 839 | return(NULL);
|
---|
[956] | 840 | }
|
---|
| 841 | //******************************************************************************
|
---|
| 842 | //******************************************************************************
|
---|
[3483] | 843 | Win32DllBase *Win32DllBase::findModuleByAddr(ULONG address)
|
---|
| 844 | {
|
---|
[4523] | 845 | dlllistmutex.enter();
|
---|
[3483] | 846 |
|
---|
[4523] | 847 | Win32DllBase *mod = Win32DllBase::head;
|
---|
| 848 | while(mod != NULL) {
|
---|
| 849 | dbgCheckObj(mod);
|
---|
| 850 | if(mod->insideModule(address)) {
|
---|
| 851 | dlllistmutex.leave();
|
---|
| 852 | return(mod);
|
---|
[3483] | 853 | }
|
---|
[4523] | 854 | mod = mod->next;
|
---|
| 855 | }
|
---|
| 856 | dlllistmutex.leave();
|
---|
| 857 | return(NULL);
|
---|
[3483] | 858 | }
|
---|
| 859 | //******************************************************************************
|
---|
| 860 | //******************************************************************************
|
---|
[6015] | 861 | Win32DllBase *Win32DllBase::findModuleByOS2Handle(HINSTANCE hinstance)
|
---|
| 862 | {
|
---|
| 863 | dlllistmutex.enter();
|
---|
| 864 |
|
---|
| 865 | for (Win32DllBase *pMod = Win32DllBase::getFirst(); pMod; pMod = pMod->getNext())
|
---|
| 866 | {
|
---|
| 867 | if (pMod->isLxDll())
|
---|
| 868 | {
|
---|
| 869 | if (((Win32LxDll *)pMod)->getHMOD() == hinstance)
|
---|
| 870 | {
|
---|
| 871 | dlllistmutex.leave();
|
---|
| 872 | return(pMod);
|
---|
| 873 | }
|
---|
| 874 | }
|
---|
| 875 | else if (pMod->isPe2LxDll())
|
---|
| 876 | {
|
---|
| 877 | if (((Win32Pe2LxDll *)pMod)->getHMOD() == hinstance)
|
---|
| 878 | {
|
---|
| 879 | dlllistmutex.leave();
|
---|
| 880 | return(pMod);
|
---|
| 881 | }
|
---|
| 882 | }
|
---|
| 883 | }
|
---|
| 884 |
|
---|
| 885 | dlllistmutex.leave();
|
---|
| 886 | return(NULL);
|
---|
| 887 | }
|
---|
| 888 | //******************************************************************************
|
---|
| 889 | //******************************************************************************
|
---|
[956] | 890 | BOOL Win32DllBase::isDll()
|
---|
| 891 | {
|
---|
[4523] | 892 | return TRUE;
|
---|
[956] | 893 | }
|
---|
| 894 | //******************************************************************************
|
---|
| 895 | //******************************************************************************
|
---|
[10397] | 896 | int Win32DllBase::enumDlls(HMODULE *lphModule, int countMax)
|
---|
| 897 | {
|
---|
| 898 | int count = 0;
|
---|
| 899 | HMODULE hModule;
|
---|
| 900 |
|
---|
| 901 | dlllistmutex.enter();
|
---|
| 902 |
|
---|
| 903 | Win32DllBase *mod = Win32DllBase::head;
|
---|
| 904 | while(mod != NULL) {
|
---|
| 905 | dbgCheckObj(mod);
|
---|
| 906 |
|
---|
| 907 | hModule = mod->getInstanceHandle();
|
---|
| 908 | if ( count < countMax )
|
---|
| 909 | lphModule[count] = hModule;
|
---|
| 910 | count++;
|
---|
| 911 |
|
---|
| 912 | mod = mod->next;
|
---|
| 913 | }
|
---|
| 914 | dlllistmutex.leave();
|
---|
| 915 | return count;
|
---|
| 916 | }
|
---|
| 917 | //******************************************************************************
|
---|
| 918 | //******************************************************************************
|
---|
[956] | 919 | Win32DllBase *Win32DllBase::head = NULL;
|
---|
[3059] | 920 | Queue Win32DllBase::loadLibDlls;
|
---|