Ignore:
Timestamp:
Aug 23, 1999, 7:04:14 PM (26 years ago)
Author:
sandervl
Message:

Dll load order bugfix

File:
1 edited

Legend:

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

    r634 r651  
    1 /* $Id: windll.cpp,v 1.13 1999-08-22 22:11:22 sandervl Exp $ */
     1/* $Id: windll.cpp,v 1.14 1999-08-23 17:02:35 sandervl Exp $ */
    22
    33/*
     
    3131#include "exceptutil.h"
    3232#include "cio.h"
     33#include "vmutex.h"
     34
     35VMutex dlllistmutex;   //protects linked lists of heaps
    3336
    3437/***********************************
     
    4043//******************************************************************************
    4144//******************************************************************************
    42 Win32Dll::Win32Dll(char *szDllName) : Win32Image(szDllName), referenced(0),
    43                                       fSkipEntryCalls(FALSE), fSystemDll(FALSE)
     45Win32Dll::Win32Dll(char *szDllName, Win32Image *parentImage)
     46                : Win32Image(szDllName), referenced(0),
     47                  fSkipEntryCalls(FALSE), fSystemDll(FALSE),
     48                  fAttachedToProcess(FALSE)
    4449{
    4550  fSystemDll   = isSystemDll(szFileName);
    4651  fUnloaded    = FALSE;
    47   next = head;
    48   head = this;
     52
     53  dlllistmutex.enter();
     54  if(head == NULL || parentImage == NULL || parentImage->isDll() == FALSE) { //does the head dll depend on this one?
     55        next = head;
     56        head = this;
     57  }
     58  else {
     59        //If we have a parent, we must make sure it is deleted before we are!
     60        //(inserted after the parent)
     61        if(head == parentImage) {
     62                next = head->next;
     63                head->next = this;
     64        }
     65        else {
     66                Win32Dll *cur = head;
     67                while(cur) {
     68                        if(cur == parentImage) {
     69                                break;
     70                        }
     71                        cur = cur->next;
     72                }
     73                next = cur->next;
     74                cur->next = this;
     75        }
     76  }
     77  dlllistmutex.leave();
    4978
    5079  dllEntryPoint = 0;
    5180
    52   dprintf(("Win32Dll::Win32Dll %s %s", szFileName, szModule));
     81  dprintf(("Win32Dll::Win32Dll %s %s loaded by %s", szFileName, szModule,
     82          (parentImage) ? parentImage->getModuleName() : "Unknown"));
    5383}
    5484//******************************************************************************
     
    5787                   WIN32DLLENTRY DllEntryPoint) :
    5888                        Win32Image(hinstance, NameTableId, Win32TableId),
    59                         referenced(0), fSkipEntryCalls(FALSE), fSystemDll(FALSE)
     89                        referenced(0), fSkipEntryCalls(FALSE), fSystemDll(FALSE),
     90                        fAttachedToProcess(FALSE)
    6091{
    6192  dllEntryPoint = DllEntryPoint;
    6293  fUnloaded     = FALSE;
     94
     95  dlllistmutex.enter();
    6396  next = head;
    6497  head = this;
     98  dlllistmutex.leave();
    6599
    66100  dprintf(("Win32Dll::Win32Dll %s", szModule));
     
    86120  //first remove it from the linked list so converted win32 dlls won't
    87121  //be deleted twice (as DosFreeModule results in a call to DllExitList (wprocess.cpp)
     122  dlllistmutex.enter();
    88123  if(head == this) {
    89124        head = next;
     
    95130        if(dll == NULL) {
    96131                dprintf(("~Win32Dll: Can't find dll!\n"));
     132                dlllistmutex.leave();
    97133                return;
    98134        }
    99135        dll->next = next;
    100136  }
     137  dlllistmutex.leave();
    101138  if(errorState == NO_ERROR && !fUnloaded)
    102139  {
     
    281318 BOOL rc;
    282319
     320  if(fAttachedToProcess)
     321        return TRUE;
     322 
     323  fAttachedToProcess = TRUE;
     324
    283325  //Allocate TLS index for this module
    284326  tlsAlloc();
     
    380422void Win32Dll::attachThreadToAllDlls()
    381423{
    382  Win32Dll *dll = Win32Dll::head;
    383 
     424  Win32Dll *dll = Win32Dll::head;
    384425  while(dll) {
    385426        dll->attachThread();
     
    392433void Win32Dll::detachThreadFromAllDlls()
    393434{
    394  Win32Dll *dll = Win32Dll::head;
    395 
     435  Win32Dll *dll = Win32Dll::head;
    396436  while(dll) {
    397437        dll->detachThread();
     
    404444void Win32Dll::tlsAttachThreadToAllDlls()
    405445{
    406  Win32Dll *dll = Win32Dll::head;
    407 
     446  Win32Dll *dll = Win32Dll::head;
    408447  while(dll) {
    409448        dll->tlsAttachThread();
     
    416455void Win32Dll::tlsDetachThreadFromAllDlls()
    417456{
    418  Win32Dll *dll = Win32Dll::head;
    419 
     457  Win32Dll *dll = Win32Dll::head;
    420458  while(dll) {
    421459        dll->tlsDetachThread();
     
    427465void Win32Dll::deleteAll()
    428466{
    429   //LIFO removal
     467#ifdef DEBUG
     468  dlllistmutex.enter();
     469  Win32Dll *dll = head;
     470
     471  dprintf(("Win32Dll::deleteAll: List of loaded dlls:"));
     472  while(dll) {
     473        dprintf(("DLL %s", dll->szModule));
     474        dll = dll->next;
     475  }
     476  dlllistmutex.leave();
     477#endif
     478
    430479  while(Win32Dll::head) {
    431480        delete Win32Dll::head;
     
    436485Win32Dll *Win32Dll::findModule(char *dllname)
    437486{
    438  Win32Dll *dll = head;
     487 Win32Dll *dll;
    439488 char szDllName[CCHMAXPATH];
    440489 char *dot, *temp;
     
    448497        *dot = 0;
    449498
     499  dlllistmutex.enter();
     500  dll = head;
    450501  while(dll) {
    451         if(strcmpi(szDllName, dll->szModule) == 0)
     502        if(strcmpi(szDllName, dll->szModule) == 0) {
     503                dlllistmutex.leave();
    452504                return(dll);
     505        }
    453506
    454507        dll = dll->next;
    455508  }
     509  dlllistmutex.leave();
    456510  return(NULL);
    457511}
     
    460514Win32Dll *Win32Dll::findModule(WIN32DLLENTRY DllEntryPoint)
    461515{
    462  Win32Dll *mod = Win32Dll::head;
    463 
    464516   dprintf(("findModule %X", DllEntryPoint));
     517
     518   dlllistmutex.enter();
     519   Win32Dll *mod = Win32Dll::head;
    465520   while(mod != NULL) {
    466521        dbgCheckObj(mod);
    467         if(mod->dllEntryPoint == DllEntryPoint)
     522        if(mod->dllEntryPoint == DllEntryPoint) {
     523                dlllistmutex.leave();
    468524                return(mod);
     525        }
    469526        mod = mod->next;
    470527   }
     528   dlllistmutex.leave();
    471529   return(NULL);
    472530}
     
    475533Win32Dll *Win32Dll::findModule(HINSTANCE hinstance)
    476534{
    477  Win32Dll *mod = Win32Dll::head;
    478 
    479 //   eprintf(("findModule inst %X", hinstance));
     535   dlllistmutex.enter();
     536
     537   Win32Dll *mod = Win32Dll::head;
    480538   while(mod != NULL) {
    481539        dbgCheckObj(mod);
    482         if(mod->hinstance == hinstance)
     540        if(mod->hinstance == hinstance) {
     541                dlllistmutex.leave();
    483542                return(mod);
     543        }
    484544        mod = mod->next;
    485545   }
     546   dlllistmutex.leave();
    486547   return(NULL);
    487548}
Note: See TracChangeset for help on using the changeset viewer.