Changeset 4523 for trunk/src


Ignore:
Timestamp:
Oct 23, 2000, 3:42:47 PM (25 years ago)
Author:
sandervl
Message:

Vio fix for high memory + fixes&updates for dll name lookup with extension

Location:
trunk/src/kernel32
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/conbuffervio.cpp

    r4502 r4523  
    1 /* $Id: conbuffervio.cpp,v 1.1 2000-10-20 11:46:45 sandervl Exp $ */
     1/* $Id: conbuffervio.cpp,v 1.2 2000-10-23 13:42:40 sandervl Exp $ */
    22
    33/*
     
    100100  PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
    101101           ULONG ulCounter;                 /* counter for the byte transfer */
    102            PSZ   pszBuffer = (PSZ)lpBuffer;
     102           PSZ   pszBuffer;
    103103           char  filler[4] = {' ', 0x07, ' ', 0x07};
    104104  register UCHAR ucChar;
     
    125125
    126126  dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
     127
     128  if(nNumberOfBytesToWrite > 1024)
     129  {
     130    int  tmp = 0;
     131    BOOL retcode;
     132
     133    while(nNumberOfBytesToWrite) {
     134        *lpNumberOfBytesWritten = 0;
     135        retcode = WriteFile(pHMHandleData, lpBuffer,
     136                            min(nNumberOfBytesToWrite, 512), lpNumberOfBytesWritten,
     137                            lpOverlapped);
     138        if(retcode != TRUE)     break;
     139
     140        tmp                   += *lpNumberOfBytesWritten;
     141        nNumberOfBytesToWrite -= *lpNumberOfBytesWritten;
     142        lpBuffer               = (LPCVOID)((char *)lpBuffer + *lpNumberOfBytesWritten);
     143    }
     144    *lpNumberOfBytesWritten = tmp;
     145    return retcode;
     146  }
     147  pszBuffer = (PSZ)alloca(nNumberOfBytesToWrite);
     148  if(pszBuffer == NULL) {
     149    DebugInt3();
     150    return FALSE;
     151  }
     152  memcpy(pszBuffer, lpBuffer, nNumberOfBytesToWrite);
    127153
    128154  ulCounter = 0;
  • trunk/src/kernel32/windllbase.cpp

    r4474 r4523  
    1 /* $Id: windllbase.cpp,v 1.18 2000-10-10 17:14:06 sandervl Exp $ */
     1/* $Id: windllbase.cpp,v 1.19 2000-10-23 13:42:42 sandervl Exp $ */
    22
    33/*
    44 * Win32 Dll base class
    55 *
    6  * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
    77 *
    88 * Unloading of a dll always happens in order of dependency (taking nr of
     
    1010 * Unloading of dynamically loaded dll (with LoadLibrary) in deleteAll
    1111 * is done in LIFO order (NT exhibits the same behaviour)
    12  *           
     12 *
    1313 * RemoveCircularDependency: TODO: Send process detach message here??
    1414 *
     
    2222#define INCL_DOSMISC             /* DOS Miscellanous values  */
    2323#define INCL_WIN
    24 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
     24#include <os2wrap.h>    //Odin32 OS/2 api wrappers
    2525#include <stdio.h>
    2626#include <string.h>
     
    4141#include "profile.h"
    4242
    43 #define DBG_LOCALLOG    DBG_windllbase
     43#define DBG_LOCALLOG    DBG_windllbase
    4444#include "dbglocal.h"
    4545
     
    4848//******************************************************************************
    4949//******************************************************************************
    50 Win32DllBase::Win32DllBase(HINSTANCE hinstance, WIN32DLLENTRY DllEntryPoint, 
     50Win32DllBase::Win32DllBase(HINSTANCE hinstance, WIN32DLLENTRY DllEntryPoint,
    5151                           Win32ImageBase *parent)
    5252                 : Win32ImageBase(hinstance),
    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));
     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));
    6262}
    6363//******************************************************************************
     
    6565Win32DllBase::~Win32DllBase()
    6666{
    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 {
     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 {
    7979        Win32DllBase *dll = head;
    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();
     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();
    9191}
    9292//******************************************************************************
    9393//******************************************************************************
    9494void Win32DllBase::incDynamicLib()
    95 { 
    96   if(nrDynamicLibRef == 0) {
     95{
     96    if(nrDynamicLibRef == 0) {
    9797        //NOTE:
    9898        //Must be called *after* attachprocess, since attachprocess may also
     
    103103        //     this means that in ExitProcess, PNRS3260 needs to be removed
    104104        //     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++;
    111110}
    112111//******************************************************************************
    113112//******************************************************************************
    114113void Win32DllBase::decDynamicLib()
    115 { 
    116   nrDynamicLibRef--;
    117   if(nrDynamicLibRef == 0) {
    118         dlllistmutex.enter();
    119         loadLibDlls.Remove((ULONG)this);
    120         dlllistmutex.leave();
    121   }
     114{
     115    nrDynamicLibRef--;
     116    if(nrDynamicLibRef == 0) {
     117        dlllistmutex.enter();
     118        loadLibDlls.Remove((ULONG)this);
     119        dlllistmutex.leave();
     120    }
    122121}
    123122//******************************************************************************
    124123//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
    127126//******************************************************************************
    128127void Win32DllBase::setUnloadOrder(Win32ImageBase *parent)
     
    131130 Win32DllBase *parentdll = NULL;
    132131
    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();
    203200}
    204201//******************************************************************************
     
    209206ULONG Win32DllBase::AddRef()
    210207#endif
    211 { 
     208{
    212209 Win32DllBase *dll;
    213210
    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;
    216213#ifdef DEBUG
    217   if(referenced == 1) {
     214    if(referenced == 1) {
    218215#ifdef DEBUG_ENABLELOG_LEVEL2
    219         printListOfDlls();
     216        printListOfDlls();
    220217#endif
    221         //printDependencies(NULL);
    222   }
     218        //printDependencies(NULL);
     219    }
    223220#endif
    224 
    225   return referenced;
     221    return referenced;
    226222}
    227223//******************************************************************************
     
    234230 LONG          ret;
    235231
    236   dprintf(("Win32DllBase::Release %s %d", getModuleName(), referenced-1));
    237 
    238   ret = --referenced;
    239   if(ret <= 0) {
    240         //make copy of linked list of dependencies
    241         queue = loadedDlls;
    242 
    243         //remove any circular dependencies on this dll that might be present
    244         item = queue.Head();
    245         while(item) {
    246                 dll = (Win32DllBase *)queue.getItem(item);
    247                 if(dll == NULL) {
    248                         dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
    249                         DebugInt3();
    250                         return -1;
    251                 }
    252                 dll->RemoveCircularDependency(this);
    253                 item = queue.getNext(item);
    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        }
    255251#ifdef DEBUG
    256         //printDependencies(NULL);
     252        //printDependencies(NULL);
    257253#endif
    258         dprintf(("Win32DllBase::Release %s referenced == 0", getModuleName()));
    259 
    260         //delete dll object
    261         delete this;
    262 
    263         //unreference all of it's dependencies
    264         item = queue.Head();
    265         while(item) {
    266                 dll = (Win32DllBase *)queue.getItem(item);
    267                 if(dll == NULL) {
    268                         dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
    269                         DebugInt3();
    270                         return -1;
    271                 }
    272                 dll->Release();
    273                 item = queue.getNext(item);
    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);
    277273}
    278274//******************************************************************************
     
    286282 BOOL          ret = FALSE;
    287283
    288   //remove any circular dependencies on this dll that might be present
    289   item = loadedDlls.Head();
    290   while(item) {
    291         dll = (Win32DllBase *)loadedDlls.getItem(item);
    292         if(dll == NULL) {
    293                 dprintf(("ERROR: Win32DllBase::Release: dll item == NULL!!"));
    294                 DebugInt3();
    295                 return FALSE;
    296         }
    297         tmp = loadedDlls.getNext(item);
    298         if(dll == parent) {
    299                 dprintf(("Removing CIRCULAR dependency %s->%s", parent->getModuleName(), dll->getModuleName()));
    300                 loadedDlls.Remove(item);
    301                 ret = TRUE;
    302         }
    303 ////    else    ret |= dll->RemoveCircularDependency(parent);
    304         item = tmp;
    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.
    311307//example: gdi32 is loaded -> depends on kernel32 (which is already loaded)
    312308//         kernel32's reference count isn't updated
     
    321317 Win32DllBase *dll, *depdll;
    322318 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();
    350345}
    351346//******************************************************************************
     
    358353 ULONG         ret;
    359354
    360   dprintf(("Dependency list: %s->%s %d", parent, getModuleName(), referenced));
    361   item = loadedDlls.Head();
    362   while(item) {
    363         dll = (Win32DllBase *)loadedDlls.getItem(item);
    364         if(dll == NULL) {
    365                 return;
    366         }
    367         dll->printDependencies(getModuleName());
    368         item = loadedDlls.getNext(item);
    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    }
    370365}
    371366//******************************************************************************
     
    376371 Win32DllBase *dll;
    377372
    378   dll = head;
    379 
    380   dprintf2(("Win32DllBase::Win32DllBase: List of loaded dlls:"));
    381   while(dll) {
    382         dprintf2(("DLL %s %d", dll->szModule, dll->referenced));
    383         dll = dll->next;
    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    }
    385380}
    386381#endif
     
    395390 BOOL rc, fSetExceptionHandler;
    396391
    397   if(fAttachedToProcess || fSkipEntryCalls)
    398         return TRUE;
    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 same
    406   //      in OS/2
    407   if(fSetExceptionHandler) {
    408         OS2SetExceptionHandler((void *)&exceptFrame);
    409         sel = SetWin32TIB();
    410   }
    411 
    412   //Allocate TLS index for this module
    413   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) {
    417412        dprintf(("attachProcess not required for dll %s", szModule));
    418         if(fSetExceptionHandler) {
    419                 SetFS(sel);
    420                 OS2UnsetExceptionHandler((void *)&exceptFrame);
    421         }
    422         return(TRUE);
    423   }
    424 
    425   dprintf(("attachProcess to dll %s", szModule));
    426  
    427   // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL
    428   // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads
    429   //   and non-NULL for static loads.
    430   // same goes for process termination
    431   LPVOID lpvReserved;
    432  
    433   if (isDynamicLib())
    434     lpvReserved = NULL;
    435   else
    436     lpvReserved = (LPVOID)0xdeadface; // some arbitrary value
    437  
    438   rc = dllEntryPoint(hinstance, DLL_PROCESS_ATTACH, lpvReserved);
    439 
    440   dprintf(("attachProcess to dll %s DONE", szModule));
    441 
    442   if(fSetExceptionHandler) {
    443         SetFS(sel);
    444         OS2UnsetExceptionHandler((void *)&exceptFrame);
    445   }
    446   else
    447   if(thdb) {
    448         if(thdb->teb_sel != GetFS()) {
    449                 dprintf(("Win32DllBase::attachProcess: FS was changed by dll entrypoint!!!!"));
    450                 DebugInt3();
    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;
    454449}
    455450//******************************************************************************
     
    461456 BOOL rc;
    462457
    463   if(fSkipEntryCalls) {
    464         fUnloaded = TRUE;
    465         return TRUE;
    466   }
    467 
    468   if(dllEntryPoint == NULL) {
    469         tlsDetachThread();      //destroy TLS (main thread)
    470         fUnloaded = TRUE;
    471         return(TRUE);
    472   }
    473 
    474   dprintf(("detachProcess from dll %s", szModule));
    475 
    476   //Note: The Win32 exception structure references by FS:[0] is the same
    477   //      in OS/2
    478   OS2SetExceptionHandler((void *)&exceptFrame);
    479 
    480   fUnloaded = TRUE;
    481   sel = SetWin32TIB();
    482  
    483   // @@@PH 2000/06/13 lpvReserved, Starcraft STORM.DLL
    484   // if DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads
    485   //   and non-NULL for static loads.
    486   // same goes for process termination
    487   LPVOID lpvReserved;
    488  
    489   if (isDynamicLib())
    490     lpvReserved = NULL;
    491   else
    492     lpvReserved = (LPVOID)0xdeadface; // some arbitrary value
    493  
    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;
    503498}
    504499//******************************************************************************
     
    509504 BOOL               rc;
    510505
    511   if(fSkipThreadEntryCalls || dllEntryPoint == NULL)
    512         return(TRUE);
    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;
    521516}
    522517//******************************************************************************
     
    527522 BOOL               rc;
    528523
    529   if(fSkipThreadEntryCalls || dllEntryPoint == NULL)
    530         return(TRUE);
    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;
    536531}
    537532//******************************************************************************
     
    540535void Win32DllBase::attachThreadToAllDlls()
    541536{
    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//******************************************************************************
     548void Win32DllBase::detachThreadFromAllDlls()
     549{
     550    dlllistmutex.enter();
     551    Win32DllBase *dll = Win32DllBase::head;
     552    while(dll) {
     553        dll->detachThread();
     554        dll = dll->getNext();
     555    }
    548556  dlllistmutex.leave();
    549557}
    550558//******************************************************************************
    551 //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
    552 //******************************************************************************
    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 //******************************************************************************
    564559//Setup TLS structure for all dlls for a new thread
    565560//******************************************************************************
    566561void Win32DllBase::tlsAttachThreadToAllDlls()
    567562{
    568   dlllistmutex.enter();
    569   Win32DllBase *dll = Win32DllBase::head;
    570   while(dll) {
    571         dll->tlsAttachThread();
    572         dll = dll->getNext();
    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();
    575570}
    576571//******************************************************************************
     
    579574void Win32DllBase::tlsDetachThreadFromAllDlls()
    580575{
    581   dlllistmutex.enter();
    582   Win32DllBase *dll = Win32DllBase::head;
    583   while(dll) {
    584         dll->tlsDetachThread();
    585         dll = dll->getNext();
    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();
    588583}
    589584//******************************************************************************
     
    593588 Win32DllBase *dll = Win32DllBase::head;
    594589
    595   dprintf(("Win32DllBase::deleteAll"));
     590    dprintf(("Win32DllBase::deleteAll"));
    596591
    597592#ifdef DEBUG_ENABLELOG_LEVEL2
    598   if(dll) dll->printListOfDlls();
     593    if(dll) dll->printListOfDlls();
    599594#endif
    600595
    601   dlllistmutex.enter();
    602   while(dll) {
    603         dll->Release();
    604         dll = Win32DllBase::head;
    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!"));
    608603}
    609604//******************************************************************************
     
    615610 QueueItem    *item;
    616611
    617   dprintf(("Win32DllBase::deleteDynamicLibs"));
     612    dprintf(("Win32DllBase::deleteDynamicLibs"));
    618613#ifdef DEBUG_ENABLELOG_LEVEL2
    619   if(dll) dll->printListOfDlls();
     614    if(dll) dll->printListOfDlls();
    620615#endif
    621616
    622   dlllistmutex.enter();
    623 
    624   item = loadLibDlls.Head();
    625   while(item) {
    626         dll = (Win32DllBase *)loadLibDlls.getItem(item);
    627         int dynref = dll->nrDynamicLibRef;
    628         if(dynref) {
    629                 while(dynref) {
    630                         dynref--;
    631                         dll->decDynamicLib();
    632                         dll->Release();
    633                 }
    634         }
    635         else    DebugInt3();
    636         item = loadLibDlls.Head(); //queue could have been changed, so start from the beginning
    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"));
    641636}
    642637//******************************************************************************
     
    644639Win32DllBase *Win32DllBase::getFirst()
    645640{
    646   return head;
     641    return head;
    647642}
    648643//******************************************************************************
     
    654649 char renameddll[CCHMAXPATH];
    655650
    656   if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "", renameddll,
    657                                    sizeof(renameddll)-1) <= 1)
    658   {
    659         PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLE32", "OLE32OS2");
    660         PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLE32OS2", "OLE32");
    661   }
    662   if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "", renameddll,
    663                                    sizeof(renameddll)-1) <= 1)
    664   {
    665         PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "OLEAUT32", "OLAUTOS2");
    666         PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "OLAUTOS2", "OLEAUT32");
    667   }
    668   if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "", renameddll,
    669                                    sizeof(renameddll)-1) <= 1)
    670   {
    671         PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "NETAPI32", "WNETAP32");
    672         PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "WNETAP32", "NETAPI32");
    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    }
    674669}
    675670//******************************************************************************
     
    686681 char *sectionname;
    687682
    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;
    713711}
    714712//******************************************************************************
     
    722720////  dprintf2(("findModule %s", dllname));
    723721
    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);
    747740}
    748741//******************************************************************************
     
    750743Win32DllBase *Win32DllBase::findModule(WIN32DLLENTRY DllEntryPoint)
    751744{
    752    dprintf2(("findModule %X", DllEntryPoint));
    753 
    754    dlllistmutex.enter();
    755    Win32DllBase *mod = Win32DllBase::head;
    756    while(mod != NULL) {
    757         dbgCheckObj(mod);
    758         if(mod->dllEntryPoint == DllEntryPoint) {
    759                 dlllistmutex.leave();
    760                 return(mod);
    761         }
    762         mod = mod->next;
    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);
    766759}
    767760//******************************************************************************
     
    769762Win32DllBase *Win32DllBase::findModule(HINSTANCE hinstance)
    770763{
    771    dlllistmutex.enter();
    772 
    773    Win32DllBase *mod = Win32DllBase::head;
    774    while(mod != NULL) {
    775         dbgCheckObj(mod);
    776         if(mod->hinstance == hinstance) {
    777                 dlllistmutex.leave();
    778                 return(mod);
    779         }
    780         mod = mod->next;
    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);
    784777}
    785778//******************************************************************************
     
    787780Win32DllBase *Win32DllBase::findModuleByAddr(ULONG address)
    788781{
    789    dlllistmutex.enter();
    790 
    791    Win32DllBase *mod = Win32DllBase::head;
    792    while(mod != NULL) {
    793         dbgCheckObj(mod);
    794         if(mod->insideModule(address)) {
    795                 dlllistmutex.leave();
    796                 return(mod);
    797         }
    798         mod = mod->next;
    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);
    802795}
    803796//******************************************************************************
     
    805798BOOL Win32DllBase::isDll()
    806799{
    807   return TRUE;
     800    return TRUE;
    808801}
    809802//******************************************************************************
  • trunk/src/kernel32/windllbase.h

    r4474 r4523  
    1 /* $Id: windllbase.h,v 1.6 2000-10-10 17:14:06 sandervl Exp $ */
     1/* $Id: windllbase.h,v 1.7 2000-10-23 13:42:43 sandervl Exp $ */
    22
    33/*
     
    2929#define LOAD_LIBRARY_AS_DATAFILE        0x00000002
    3030#define LOAD_WITH_ALTERED_SEARCH_PATH   0x00000008
     31
     32#define DLL_EXTENSION           ".DLL"
    3133
    3234//odin.ini section names to lookup renamed dlls
  • trunk/src/kernel32/windllpeldr.cpp

    r3615 r4523  
    1 /* $Id: windllpeldr.cpp,v 1.7 2000-05-27 11:30:35 sandervl Exp $ */
     1/* $Id: windllpeldr.cpp,v 1.8 2000-10-23 13:42:44 sandervl Exp $ */
    22
    33/*
     
    6363  strupr(szFileName);
    6464  if(!strchr(szFileName, (int)'.')) {
    65         strcat(szFileName,".DLL");
     65        strcat(szFileName, DLL_EXTENSION);
    6666  }
    6767  dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
  • trunk/src/kernel32/winimagebase.cpp

    r4474 r4523  
    1 /* $Id: winimagebase.cpp,v 1.29 2000-10-10 17:14:07 sandervl Exp $ */
     1/* $Id: winimagebase.cpp,v 1.30 2000-10-23 13:42:44 sandervl Exp $ */
    22
    33/*
     
    6464    name = strrchr(szFileName, '\\')+1;
    6565    strcpy(szModule, name);
    66 
    67     char *dot = strrchr(szModule, '.');
    68     if(dot)
    69         *dot = 0;
    7066  }
    7167  else {
     
    154150 char  *imagepath;
    155151
    156   strcpy(szFullName, szFileName);
    157   strupr(szFullName);
    158   if(!strchr(szFullName, (int)'.')) {
    159         strcat(szFullName,".DLL");
    160   }
    161 
    162   //search order:
    163   //1) exe dir
    164   //2) current dir
    165   //3) windows system dir (kernel32 path)
    166   //4) windows dir
    167   //5) path
    168   if(WinExe) {
    169     strcpy(modname, WinExe->getFullPath());
    170     //remove file name from full path
    171     imagepath = modname + strlen(modname) - 1;
    172     while(*imagepath != '\\') imagepath--;
    173     imagepath[1] = 0;
    174     strcat(modname, szFullName);
    175     dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    176   }
    177   if(dllfile == NULL) {
    178     strcpy(modname, szFullName);
    179     dllfile = OSLibDosOpen(szFullName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    180     if(dllfile == NULL) {
     152    strcpy(szFullName, szFileName);
     153    strupr(szFullName);
     154    if(!strchr(szFullName, (int)'.')) {
     155        strcat(szFullName, DLL_EXTENSION);
     156    }
     157
     158    //search order:
     159    //1) exe dir
     160    //2) current dir
     161    //3) windows system dir (kernel32 path)
     162    //4) windows dir
     163    //5) path
     164    if(WinExe) {
     165        strcpy(modname, WinExe->getFullPath());
     166        //remove file name from full path
     167        imagepath = modname + strlen(modname) - 1;
     168        while(*imagepath != '\\')
     169            imagepath--;
     170        imagepath[1] = 0;
     171        strcat(modname, szFullName);
     172        dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
     173    }
     174    if(dllfile == NULL)
     175    {
     176        strcpy(modname, szFullName);
     177        dllfile = OSLibDosOpen(szFullName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
     178        if(dllfile == NULL)
     179        {
    181180            strcpy(modname, InternalGetSystemDirectoryA());
    182         strcat(modname, "\\");
     181            strcat(modname, "\\");
    183182            strcat(modname, szFullName);
    184         dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    185         if(dllfile == NULL) {
    186             strcpy(modname, InternalGetWindowsDirectoryA());
    187             strcat(modname, "\\");
     183            dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
     184            if(dllfile == NULL)
     185            {
     186                strcpy(modname, InternalGetWindowsDirectoryA());
     187                strcat(modname, "\\");
    188188                strcat(modname, szFullName);
    189             dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    190             if(dllfile == NULL) {
    191                 if(OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", szFullName, modname, sizeof(modname)) == 0) {
    192                     return FALSE;
     189                dllfile = OSLibDosOpen(modname, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
     190                if(dllfile == NULL) {
     191                    if(OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", szFullName, modname, sizeof(modname)) == 0)
     192                        return FALSE;
    193193                }
    194194            }
    195195        }
    196196    }
    197   }
    198   strcpy(szFullName, modname);
    199   if(dllfile) OSLibDosClose(dllfile);
    200   return TRUE;
     197    strcpy(szFullName, modname);
     198    if(dllfile) OSLibDosClose(dllfile);
     199    return TRUE;
    201200}
    202201
     
    254253  rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead);
    255254  if(rc != NO_ERROR || ulRead != sizeof(IMAGE_DOS_HEADER)) {
    256     free(pdoshdr);
     255        free(pdoshdr);
    257256        DosClose(win32handle);                /* Close the file */
    258257        return ERROR_INVALID_EXE_SIGNATURE_W;
    259258  }
    260259  if(pdoshdr->e_magic != IMAGE_DOS_SIGNATURE) {
    261     free(pdoshdr);
     260        free(pdoshdr);
    262261        DosClose(win32handle);                /* Close the file */
    263262        return ERROR_INVALID_EXE_SIGNATURE_W;
     
    294293  }
    295294  if(Characteristics) {
    296         *Characteristics = fh.Characteristics;
     295        *Characteristics = fh.Characteristics;
    297296  }
    298297  DosClose(win32handle);
     
    346345 * @remark      Just a clarification:
    347346 *              A module name is the filename of a executable image without
    348  *              path and without extention.
     347 *              path, but *with* extention.
    349348 */
    350349BOOL Win32ImageBase::matchModName(const char *pszFilename) const
     
    365364           )
    366365    {
    367         if (ch == '.' && pszModNameEnd == NULL)
    368             pszModNameEnd = pszModName;
    369366        pszModName--;
    370367    }
    371368    pszModName++;
    372    
     369
    373370    /** @sketch
    374371     * Compare the names caseinsensitivly.
    375372     */
    376     if (pszModNameEnd)
    377         return strnicmp(pszModName, szModule, pszModNameEnd - pszModName) == 0;
    378373    return stricmp(pszModName, szModule) == 0;
    379374}
  • trunk/src/kernel32/winimagepeldr.cpp

    r4489 r4523  
    1 /* $Id: winimagepeldr.cpp,v 1.62 2000-10-16 19:15:16 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.63 2000-10-23 13:42:45 sandervl Exp $ */
    22
    33/*
     
    111111 HFILE  dllfile;
    112112
    113   strcpy(szFileName, pszFileName);
    114   strupr(szFileName);
    115   if(isExe) {
    116     if(!strchr(szFileName, '.')) {
    117         strcat(szFileName,".EXE");
    118     }
    119     dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    120     if(dllfile == NULL) {
    121         if(!strstr(szFileName, ".EXE")) {
     113    strcpy(szFileName, pszFileName);
     114    strupr(szFileName);
     115    if(isExe) {
     116        if(!strchr(szFileName, '.')) {
    122117            strcat(szFileName,".EXE");
    123118        }
    124119        dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
    125120        if(dllfile == NULL) {
    126             OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", szFileName, szFileName, sizeof(szFileName));
    127         }
    128     }
    129     else    OSLibDosClose(dllfile);
    130   }
    131   else {
    132     findDll(szFileName, szModule, sizeof(szModule));
    133     strcpy(szFileName, szModule);
    134   }
    135   strcpy(szModule, OSLibStripPath(szFileName));
    136   strupr(szModule);
    137   char *dot = strstr(szModule, ".");
    138   while(dot) {
    139     char *newdot = strstr(dot+1, ".");
    140     if(newdot == NULL)  break;
    141     dot = newdot;
    142   }
    143   if(dot)
    144     *dot = 0;
     121            if(!strstr(szFileName, ".EXE")) {
     122                strcat(szFileName,".EXE");
     123            }
     124            dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
     125            if(dllfile == NULL) {
     126                OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", szFileName, szFileName, sizeof(szFileName));
     127            }
     128        }
     129        else    OSLibDosClose(dllfile);
     130    }
     131    else {
     132        findDll(szFileName, szModule, sizeof(szModule));
     133        strcpy(szFileName, szModule);
     134    }
     135    strcpy(szModule, OSLibStripPath(szFileName));
     136    strupr(szModule);
    145137}
    146138//******************************************************************************
     
    13251317 int           forwardord;
    13261318
    1327   forwarddll = strdup(forward);
    1328   if(forwarddll == NULL) {
    1329     return FALSE;
    1330   }
    1331   forwardapi = strchr(forwarddll, '.');
    1332   if(forwardapi == NULL) {
    1333     goto fail;
    1334   }
    1335   *forwardapi++ = 0;
    1336   if(strlen(forwarddll) == 0 || strlen(forwardapi) == 0) {
    1337     goto fail;
    1338   }
    1339   WinDll = Win32DllBase::findModule(forwarddll);
    1340   if(WinDll == NULL) {
    1341     WinDll = loadDll(forwarddll);
     1319    forwarddll = strdup(forward);
     1320    if(forwarddll == NULL) {
     1321        return FALSE;
     1322    }
     1323    forwardapi = strchr(forwarddll, '.');
     1324    if(forwardapi == NULL) {
     1325        goto fail;
     1326    }
     1327    *forwardapi++ = 0;
     1328    if(strlen(forwarddll) == 0 || strlen(forwardapi) == 0) {
     1329        goto fail;
     1330    }
     1331    WinDll = Win32DllBase::findModule(forwarddll);
    13421332    if(WinDll == NULL) {
    1343         dprintf((LOG, "ERROR: couldn't find forwarder %s.%s", forwarddll, forwardapi));
    1344         goto fail;
    1345     }
    1346   }
    1347   //check if name or ordinal forwarder
    1348   forwardord = 0;
    1349   if(*forwardapi >= '0' && *forwardapi <= '9') {
    1350     forwardord = atoi(forwardapi);
    1351   }
    1352   if(forwardord != 0 || (strlen(forwardapi) == 1 && *forwardapi == '0')) {
    1353     exportaddr = WinDll->getApi(forwardord);
    1354   }
    1355   else  exportaddr = WinDll->getApi(forwardapi);
    1356 
    1357   if(apiname) {
     1333        WinDll = loadDll(forwarddll);
     1334        if(WinDll == NULL) {
     1335            dprintf((LOG, "ERROR: couldn't find forwarder %s.%s", forwarddll, forwardapi));
     1336            goto fail;
     1337        }
     1338    }
     1339    //check if name or ordinal forwarder
     1340    forwardord = 0;
     1341    if(*forwardapi >= '0' && *forwardapi <= '9') {
     1342        forwardord = atoi(forwardapi);
     1343    }
     1344    if(forwardord != 0 || (strlen(forwardapi) == 1 && *forwardapi == '0')) {
     1345        exportaddr = WinDll->getApi(forwardord);
     1346    }
     1347    else  exportaddr = WinDll->getApi(forwardapi);
     1348
     1349    if(apiname) {
    13581350        dprintf((LOG, "address 0x%x %s @%d (0x%08x) forwarder %s.%s", virtaddr - oh.ImageBase, apiname, ordinal, virtaddr, forwarddll, forwardapi));
    1359     AddNameExport(exportaddr, apiname, ordinal, TRUE);
    1360   }
    1361   else {
     1351        AddNameExport(exportaddr, apiname, ordinal, TRUE);
     1352    }
     1353    else {
    13621354        dprintf((LOG, "address 0x%x @%d (0x%08x) forwarder %s.%s", virtaddr - oh.ImageBase, ordinal, virtaddr, forwarddll, forwardapi));
    1363         AddOrdExport(exportaddr, ordinal, TRUE);
    1364   }
    1365   free(forwarddll);
    1366   return TRUE;
     1355         AddOrdExport(exportaddr, ordinal, TRUE);
     1356    }
     1357    free(forwarddll);
     1358    return TRUE;
    13671359
    13681360fail:
     
    13781370
    13791371    strcpy(modname, pszCurModule);
     1372
    13801373    //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
    13811374    Win32DllBase::renameDll(modname);
     1375
     1376    char szModName2[CCHMAXPATH];
     1377    strcpy(szModName2, modname);
     1378    if (!Win32ImageBase::findDll(szModName2, modname, sizeof(modname)))
     1379    {
     1380            dprintf((LOG, "Module %s not found!", modname));
     1381            sprintf(szErrorModule, "%s", modname);
     1382            errorState = 2;
     1383            return NULL;
     1384    }
    13821385
    13831386    if(isPEImage(modname) != ERROR_SUCCESS_W)
     
    13861389        char   szModuleFailure[CCHMAXPATH] = "";
    13871390        ULONG  hInstanceNewDll;
    1388                 Win32LxDll *lxdll;
     1391        Win32LxDll *lxdll;
    13891392
    13901393        char *dot = strchr(modname, '.');
    1391         if(dot) {
    1392             *dot = 0;
    1393         }
    1394         strcat(modname, ".DLL");
     1394        if(dot == NULL) {
     1395            strcat(modname, DLL_EXTENSION);
     1396        }
    13951397        rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), modname, (HMODULE *)&hInstanceNewDll);
    13961398        if(rc) {
    1397             dprintf((LOG, "DosLoadModule returned %X for %s\n", rc, szModuleFailure));
    1398             sprintf(szErrorModule, "%s.DLL", szModuleFailure);
     1399            dprintf((LOG, "DosLoadModule returned %X for %s", rc, szModuleFailure));
     1400            sprintf(szErrorModule, "%s", szModuleFailure);
    13991401            errorState = rc;
    14001402            return NULL;
     
    14131415            return NULL;
    14141416        }
    1415                 WinDll = (Win32DllBase*)lxdll;
     1417        WinDll = (Win32DllBase*)lxdll;
    14161418    }
    14171419    else {
     
    14231425                WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    14241426                errorState = ERROR_INTERNAL;
    1425             return NULL;
     1427                return NULL;
    14261428            }
    14271429            dprintf((LOG, "**********************************************************************" ));
     
    14301432            if(pedll->init(0) == FALSE) {
    14311433                dprintf((LOG, "Internal WinDll error ", pedll->getError() ));
    1432             delete pedll;
    1433             return NULL;
     1434                delete pedll;
     1435                return NULL;
    14341436            }
    14351437#ifdef DEBUG
     
    14401442            if(pedll->attachProcess() == FALSE) {
    14411443                dprintf((LOG, "attachProcess failed!" ));
    1442             delete pedll;
     1444                delete pedll;
    14431445                errorState = ERROR_INTERNAL;
    1444             return NULL;
     1446                return NULL;
    14451447            }
    14461448        WinDll = (Win32DllBase*)pedll;
     
    14491451    dprintf((LOG, "**********************************************************************" ));
    14501452    dprintf((LOG, "**********************  Finished Loading Module %s ", modname ));
    1451         dprintf((LOG, "**********************************************************************" ));
     1453    dprintf((LOG, "**********************************************************************" ));
    14521454
    14531455    return WinDll;
     
    16001602    if(WinDll == NULL)
    16011603    {  //not found, so load it
    1602     WinDll = loadDll(pszCurModule);
    1603     if(WinDll == NULL) {
    1604         return FALSE;
    1605     }
     1604        WinDll = loadDll(pszCurModule);
     1605        if(WinDll == NULL) {
     1606            return FALSE;
     1607        }
    16061608    }
    16071609    else {
    1608     WinDll->AddRef();
    1609 
    1610     dprintf((LOG, "Already found ", pszCurModule));
     1610        WinDll->AddRef();
     1611        dprintf((LOG, "Already found ", pszCurModule));
    16111612    }
    16121613    //add the dll we just loaded to dependency list for this image
  • trunk/src/kernel32/wprocess.cpp

    r4496 r4523  
    1 /* $Id: wprocess.cpp,v 1.105 2000-10-18 17:09:34 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.106 2000-10-23 13:42:47 sandervl Exp $ */
    22
    33/*
     
    679679    ULONG           fPE;                /* isPEImage return value. */
    680680    DWORD           Characteristics;    //file header's Characteristics
    681     BOOL            fDllModule;         //file type
     681    char           *dot;
    682682
    683683    /** @sketch
     
    709709    /** @sketch
    710710     *  First we'll see if the module is allready loaded - either as the EXE or as DLL.
    711      *  IF NOT dll AND Executable present AND libfile matches the modname of the executable THEN
     711     *  IF Executable present AND libfile matches the modname of the executable THEN
    712712     *      RETURN instance handle of executable.
    713713     *  Endif
     
    721721     *  Endif
    722722     */
    723     if(strstr(lpszLibFile, ".DLL")) {
    724         fDllModule = TRUE;
     723    strcpy(szModname, lpszLibFile);
     724    strupr(szModname);
     725    dot = strchr(szModname, '.');
     726    if(dot == NULL) {
     727        //if there's no extension or trainling dot, we
     728        //assume it's a dll (see Win32 SDK docs)
     729        strcat(szModname, DLL_EXTENSION);
    725730    }
    726731    else {
    727         if(!strstr(lpszLibFile, ".")) {
    728             //if there's no extension or trainling dot, we
    729             //assume it's a dll (see Win32 SDK docs)
    730             fDllModule = TRUE;
    731         }
    732     }
    733 
    734     //todo: the entire exe name probably needs to be identical (path + extension)
    735     //      -> check in NT
    736     if (!fDllModule && WinExe != NULL && WinExe->matchModName(lpszLibFile))
     732        if(dot[1] == 0) {
     733            //a trailing dot means the module has no extension (SDK docs)
     734            *dot = 0;
     735        }
     736    }
     737    if (WinExe != NULL && WinExe->matchModName(szModname))
    737738        return WinExe->getInstanceHandle();
    738739
    739     pModule = Win32DllBase::findModule((LPSTR)lpszLibFile);
     740    pModule = Win32DllBase::findModule((LPSTR)szModname);
    740741    if (pModule)
    741742    {
     
    743744        pModule->AddRef();
    744745        dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x. Dll found %s",
    745                  lpszLibFile, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath()));
     746                 szModname, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath()));
    746747        return pModule->getInstanceHandle();
    747748    }
     
    758759     *  Endif
    759760     */
    760     fPath = strchr(lpszLibFile, '\\') || strchr(lpszLibFile, '/');
    761     strcpy(szModname, lpszLibFile);
     761    fPath = strchr(szModname, '\\') || strchr(szModname, '/');
    762762    Win32DllBase::renameDll(szModname);
    763     strupr(szModname);
    764763
    765764    if (!fPath)
    766765    {
    767         char    szModName2[CCHMAXPATH];
     766        char szModName2[CCHMAXPATH];
    768767        strcpy(szModName2, szModname);
    769768        if (!Win32ImageBase::findDll(szModName2, szModname, sizeof(szModname)))
     
    11251124            return ERROR_NOT_ENOUGH_MEMORY;
    11261125        }
    1127     strcpy((char *)pszCmdLineA, pszPeExe);
     1126        strcpy((char *)pszCmdLineA, pszPeExe);
    11281127
    11291128        rc = NO_ERROR;
     
    14641463//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
    14651464//      very.weird.exe)
     1465//
     1466//      hinst = LoadLibrary("WINSPOOL.DRV");      -> succeeds
     1467//          hinst2 = GetModuleHandle("WINSPOOL.DRV"); -> succeeds
     1468//      hinst3 = GetModuleHandle("WINSPOOL.");    -> fails
     1469//      hinst4 = GetModuleHandle("WINSPOOL");     -> fails
     1470//      hinst = LoadLibrary("KERNEL32.DLL");      -> succeeds
     1471//          hinst2 = GetModuleHandle("KERNEL32.DLL"); -> succeeds
     1472//      hinst3 = GetModuleHandle("KERNEL32.");    -> fails
     1473//      hinst4 = GetModuleHandle("KERNEL32");     -> succeeds
     1474//      Same behaviour as observed in NT4, SP6
    14661475//******************************************************************************
    14671476HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
     
    14701479 Win32DllBase *windll;
    14711480 char      szModule[CCHMAXPATH];
    1472  BOOL      fDllModule = FALSE;
    1473 
    1474   if(lpszModule == NULL) {
    1475     if(WinExe)
     1481 char     *dot;
     1482
     1483    if(lpszModule == NULL)
     1484    {
     1485        if(WinExe)
     1486                hMod = WinExe->getInstanceHandle();
     1487        else    hMod = -1;
     1488    }
     1489    else
     1490    {
     1491        strcpy(szModule, OSLibStripPath((char *)lpszModule));
     1492        strupr(szModule);
     1493        dot = strchr(szModule, '.');
     1494        if(dot == NULL) {
     1495            //if no extension -> add .DLL (see SDK docs)
     1496            strcat(szModule, DLL_EXTENSION);
     1497        }
     1498        else {
     1499            if(dot[1] == 0) {
     1500                //a trailing dot means the module has no extension (SDK docs)
     1501                *dot = 0;
     1502            }
     1503        }
     1504        if(WinExe && WinExe->matchModName(szModule)) {
    14761505            hMod = WinExe->getInstanceHandle();
    1477     else    hMod = -1;
    1478   }
    1479   else
    1480   {
    1481     strcpy(szModule, OSLibStripPath((char *)lpszModule));
    1482     strupr(szModule);
    1483     if(strstr(szModule, ".DLL")) {
    1484         fDllModule = TRUE;
    1485     }
    1486     else {
    1487         if(!strstr(szModule, ".")) {
    1488             //if there's no extension or trainling dot, we
    1489             //assume it's a dll (see Win32 SDK docs)
    1490             fDllModule = TRUE;
    1491         }
    1492     }
    1493     char *dot = strstr(szModule, ".");
    1494     if(dot)
    1495         *dot = 0;
    1496 
    1497     if(!fDllModule && WinExe && WinExe->matchModName(szModule)) {
    1498         hMod = WinExe->getInstanceHandle();
    1499     }
    1500     else {
    1501         windll = Win32DllBase::findModule(szModule);
    1502         if(windll) {
    1503               hMod = windll->getInstanceHandle();
    1504         }
    1505     }
    1506   }
    1507 
    1508   dprintf(("KERNEL32:  GetModuleHandle %s returned %X\n", lpszModule, hMod));
    1509   return(hMod);
     1506        }
     1507        else {
     1508            windll = Win32DllBase::findModule(szModule);
     1509            if(windll) {
     1510                  hMod = windll->getInstanceHandle();
     1511            }
     1512        }
     1513    }
     1514    dprintf(("KERNEL32:  GetModuleHandle %s returned %X\n", lpszModule, hMod));
     1515    return(hMod);
    15101516}
    15111517//******************************************************************************
     
    16051611    }
    16061612    if(szAppName[0] == '"') {
    1607      exename = &szAppName[1];
     1613        exename = &szAppName[1];
    16081614    }
    16091615    else exename = szAppName;
    16101616
    16111617    if(GetFileAttributesA(exename) == -1) {
    1612     dprintf(("CreateProcess: can't find executable!"));
    1613     SetLastError(ERROR_FILE_NOT_FOUND);
    1614     return FALSE;
     1618        dprintf(("CreateProcess: can't find executable!"));
     1619        SetLastError(ERROR_FILE_NOT_FOUND);
     1620        return FALSE;
    16151621    }
    16161622    dprintf(("KERNEL32:  CreateProcess %s\n", cmdline));
     
    16191625    //     lpCurrentDirectory ourselves. (Open32 ignores it!)
    16201626    if(lpCurrentDirectory) {
    1621     char *newcmdline;
    1622 
    1623     newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
    1624     sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline);
    1625     free(cmdline);
    1626     cmdline = newcmdline;
     1627        char *newcmdline;
     1628
     1629        newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
     1630        sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline);
     1631        free(cmdline);
     1632        cmdline = newcmdline;
    16271633    }
    16281634    else {
    1629     char *newcmdline;
    1630 
    1631     newcmdline = (char *)malloc(strlen(cmdline) + 16);
    1632     sprintf(newcmdline, "PE.EXE %s", cmdline);
    1633     free(cmdline);
    1634     cmdline = newcmdline;
     1635        char *newcmdline;
     1636
     1637        newcmdline = (char *)malloc(strlen(cmdline) + 16);
     1638        sprintf(newcmdline, "PE.EXE %s", cmdline);
     1639        free(cmdline);
     1640        cmdline = newcmdline;
    16351641    }
    16361642    rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes,
     
    18281834 Win32ImageBase *winimage;
    18291835 HINSTANCE hDll;
    1830 
    1831   dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength));
    1832   if(verstruct == NULL) {
    1833     SetLastError(ERROR_INVALID_PARAMETER);
    1834     return FALSE;
    1835   }
    1836   if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName))
    1837   {
    1838         winimage = (Win32ImageBase *)WinExe;
    1839   }
    1840   else
    1841   {
    1842         winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    1843         if(winimage == NULL)
    1844         {
    1845           char modname[CCHMAXPATH];
    1846 
    1847           strcpy(modname, lpszModName);
    1848           //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
    1849           Win32DllBase::renameDll(modname);
    1850 
    1851           if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
    1852           {
    1853             HINSTANCE hInstance;
    1854 
    1855               //must be an LX dll, just load it (app will probably load it anyway)
    1856               hInstance = LoadLibraryA(modname);
    1857               if(hInstance == 0)
    1858                   return 0;
    1859 
    1860               winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
    1861               if(winimage) {
    1862                    return winimage->getVersionStruct(verstruct, bufLength);
    1863               }
    1864           dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname));
    1865               return 0;
    1866           }
    1867           BOOL rc = FALSE;
    1868 
    1869           hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
    1870           if(hDll == 0)
    1871               return 0;
    1872 
    1873           winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    1874           if(winimage != NULL) {
    1875             rc = winimage->getVersionStruct(verstruct, bufLength);
    1876       }
    1877           else  dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
    1878       FreeLibrary(hDll);
    1879           return rc;
    1880         }
    1881   }
    1882   return winimage->getVersionStruct(verstruct, bufLength);
     1836 BOOL rc = FALSE;
     1837
     1838    dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength));
     1839    if(verstruct == NULL) {
     1840        SetLastError(ERROR_INVALID_PARAMETER);
     1841        return FALSE;
     1842    }
     1843    if (WinExe != NULL && WinExe->matchModName(lpszModName)) {
     1844        return WinExe->getVersionStruct(verstruct, bufLength);
     1845    }
     1846    hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
     1847    if(hDll == 0) {
     1848        dprintf(("ERROR: GetVersionStruct: Unable to load module!!"));
     1849        return 0;
     1850    }
     1851    winimage = (Win32ImageBase *)Win32DllBase::findModule(hDll);
     1852    if(winimage != NULL) {
     1853        rc = winimage->getVersionStruct(verstruct, bufLength);
     1854    }
     1855    else {
     1856        dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", lpszModName));
     1857        DebugInt3();
     1858    }
     1859    FreeLibrary(hDll);
     1860    return rc;
    18831861}
    18841862//******************************************************************************
     
    18881866 Win32ImageBase *winimage;
    18891867 HINSTANCE hDll;
    1890 
    1891   dprintf(("GetVersionSize of %s\n", lpszModName));
    1892 
    1893   if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
    1894         winimage = (Win32ImageBase *)WinExe;
    1895   }
    1896   else {
    1897         winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    1898         if(winimage == NULL)
    1899         {
    1900           char modname[CCHMAXPATH];
    1901 
    1902           strcpy(modname, lpszModName);
    1903           //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
    1904           Win32DllBase::renameDll(modname);
    1905 
    1906           if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
    1907           {
    1908             HINSTANCE hInstance;
    1909 
    1910             //must be an LX dll, just load it (app will probably load it anyway)
    1911             hInstance = LoadLibraryA(modname);
    1912             if(hInstance == 0)
    1913                 return 0;
    1914 
    1915             winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
    1916             if(winimage) {
    1917                 return winimage->getVersionSize();
    1918             }
    1919         dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname));
    1920             return 0;
    1921         }
    1922         int size = 0;
    1923 
    1924         hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
    1925         if(hDll == 0)
    1926             return 0;
    1927 
    1928         winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    1929         if(winimage != NULL) {
    1930             size = winimage->getVersionSize();
    1931     }
    1932         else    dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1868 ULONG size = 0;
     1869
     1870    dprintf(("GetVersionSize of %s", lpszModName));
     1871    if (WinExe != NULL && WinExe->matchModName(lpszModName)) {
     1872        return WinExe->getVersionSize();
     1873    }
     1874
     1875    hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
     1876    if(hDll == 0) {
     1877        dprintf(("ERROR: GetVersionStruct: Unable to load module!!"));
     1878        return 0;
     1879    }
     1880    winimage = (Win32ImageBase *)Win32DllBase::findModule(hDll);
     1881    if(winimage != NULL) {
     1882        size = winimage->getVersionSize();
     1883    }
     1884    else {
     1885        dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1886        DebugInt3();
     1887    }
    19331888    FreeLibrary(hDll);
    1934         return size;
    1935       }
    1936   }
    1937   return winimage->getVersionSize();
     1889    return size;
    19381890}
    19391891//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.