Ignore:
Timestamp:
Aug 11, 2000, 12:56:27 PM (25 years ago)
Author:
sandervl
Message:

Updates for fake system dll headers

File:
1 edited

Legend:

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

    r3854 r3993  
    1 /* $Id: windlllx.cpp,v 1.11 2000-07-18 18:37:29 sandervl Exp $ */
     1/* $Id: windlllx.cpp,v 1.12 2000-08-11 10:56:18 sandervl Exp $ */
    22
    33/*
     
    4242//Create LX Dll object and send process attach message
    4343//System dlls set EntryPoint to 0
     44//Parameters:
     45//  HINSTANCE hInstance         - OS/2 module handle
     46//  WIN32DLLENTRY EntryPoint    - Win32 dll entrypoint address
     47//  PVOID pResData              - pointer to win32 resource data
     48//  DWORD MajorImageVersion     - major image/os version (for fake win32 header)
     49//  DWORD MinorImageVersion     - minor image/os version (for fake win32 header)
     50//  DWORD Subsystem             - subsystem type (for fake win32 header)
     51//                                (IMAGE_SUBSYSTEM_WINDOWS_CUI/IMAGE_SUBSYSTEM_WINDOWS_GUI)
     52//
    4453//Returns: Odin32 module handle
    4554//******************************************************************************
    4655DWORD WIN32API RegisterLxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint,
    47                              PVOID pResData)
    48 {
    49  Win32LxDll *windll;
     56                             PVOID pResData,
     57                             DWORD MajorImageVersion,
     58                             DWORD MinorImageVersion,
     59                             DWORD Subsystem)
     60{
     61 APIRET        rc;
     62 Win32LxDll    *windll;
    5063 Win32DllBase *windlldep;
    51 
    52    windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
    53    if(windll) {
    54         char *name = OSLibGetDllName(hInstance);
    55         dprintf(("RegisterLxDll: Register existing dll %x %s", hInstance, name));
    56         return FALSE;
    57    }
    58    windll = new Win32LxDll(hInstance, EntryPoint, pResData);
     64 char          szFileName[CCHMAXPATH], szErrName[CCHMAXPATH];
     65
     66   if(OSLibGetDllName(hInstance, szFileName, sizeof(szFileName)) == FALSE) {
     67        dprintf(("ERROR: RegisterLxDll: OSLibGetDllName %x failed!!", hInstance));
     68        return 0;
     69   }
     70   //Make sure DosLoadModule is called at least
     71   //once for a dll (to make sure OS/2 doesn't unload the dll when it's
     72   //still needed)
     73   rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hInstance);
     74   if(rc != 0) {
     75        dprintf(("ERROR: RegisterLxDll: DosLoadModule %s failed (rc=%d)!!", szFileName, rc));
     76        return 0;
     77   }
     78   windll = new Win32LxDll(hInstance, EntryPoint, pResData, MajorImageVersion,
     79                           MinorImageVersion, Subsystem);
    5980   if(windll == NULL) {
    6081        dprintf(("RegisterLxDll: windll == NULL!!!"));
    61         return FALSE;
     82        return 0;
    6283   }
    6384   if(!fPeLoader) {
     
    7495   char             modulename[CCHMAXPATH];
    7596   char             modsize;
    76    APIRET           rc;
    7797   int              i;
    7898
     
    118138BOOL WIN32API UnregisterLxDll(HINSTANCE hInstance)
    119139{
    120  Win32LxDll *windll;
     140 Win32DllBase *windll;
    121141
    122142   //Don't proceed for pe2lx/win32k (os/2 dll unload dependency bug)
     
    125145        return TRUE;
    126146
    127    windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
     147   windll = Win32DllBase::findModule(hInstance);
    128148   if(!windll) {
    129149        dprintf(("UnregisterLxDll: Can't find dll with handle %x (already deleted)", hInstance));
     
    137157//******************************************************************************
    138158//******************************************************************************
    139 Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData)
     159Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData,
     160                       DWORD MajorImageVersion, DWORD MinorImageVersion,
     161                       DWORD Subsystem)
    140162                : Win32ImageBase(hInstance),
    141163                  Win32LxImage(hInstance, pResData),
     
    146168        fAttachedToProcess = TRUE;
    147169  }
     170  hinstanceOS2 = hInstance;
     171  //new win32 instance handle must be pointer to PE header
     172  hinstance = (HINSTANCE)buildHeader(MajorImageVersion, MinorImageVersion,
     173                                     Subsystem);
    148174}
    149175//******************************************************************************
     
    151177Win32LxDll::~Win32LxDll()
    152178{
    153 }
    154 //******************************************************************************
    155 //Load it again so OS/2 takes care of the reference count (to make sure
    156 //a dll isn't unloaded when the win32 app still needs it)
    157 //******************************************************************************
    158 void Win32LxDll::loadLibrary()
    159 {
    160  char   szModuleFailure[CCHMAXPATH] = "";
    161  ULONG  hInstanceNewDll;
    162  APIRET rc;
    163 
    164   if(fLoadLibrary) {
    165         DebugInt3();
    166         return;
    167   }
    168 
    169   dprintf(("Win32LxDll::loadLibrary %s", getModuleName()));
    170   rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), getFullPath(), (HMODULE *)&hInstanceNewDll);
    171   if(rc) {
    172         dprintf(("DosLoadModule returned %X for %s\n", rc, szModuleFailure));
    173         DebugInt3(); //should NEVER happen
    174         return;
    175   }
    176   //only do this once, so set the fLoadLibrary flag to true
    177   setLoadLibrary();
    178179}
    179180//******************************************************************************
     
    227228 ULONG     ret;
    228229 APIRET    rc;
    229  BOOL      fLoadLib = fLoadLibrary;
    230 
    231   if(fDisableUnload) {//only set for kernel32.dll
    232         fLoadLib = FALSE;
    233   }
    234   hinst = hinstance;
     230
     231  hinst = hinstanceOS2;
    235232  ret = Win32DllBase::Release();
    236   if(ret == 0 && fLoadLib) {
     233  if(ret == 0 && !fDisableUnload) {//only set for kernel32.dll (fDisableUnload)
    237234        //DosFreeModule sends a termination message to the dll.
    238235        //The LX dll informs us when it's removed (UnregisterDll call)
     
    252249//******************************************************************************
    253250//******************************************************************************
     251void Win32LxDll::setDllHandleOS2(HINSTANCE hInstanceOS2)
     252{
     253  //Loaded with LoadLibrary(Ex); no need for a 2nd DosLoadModule
     254  //Dlls that are indirectly loaded (i.e. GDI32->KERNEL32 dependancy) need
     255  //this additional DosLoadModule (and setDllHandleOS2 isn't called for those)
     256  if(this->hinstanceOS2) {
     257        DosFreeModule(this->hinstanceOS2);
     258  }
     259  this->hinstanceOS2 = hInstanceOS2;
     260}
     261//******************************************************************************
     262//******************************************************************************
     263Win32LxDll *Win32LxDll::findModuleByOS2Handle(HINSTANCE hinstance)
     264{
     265   dlllistmutex.enter();
     266
     267   Win32LxDll *mod = (Win32LxDll*)Win32DllBase::head;
     268   while(mod != NULL) {
     269        dbgCheckObj(mod);
     270        if(mod->isLxDll() && mod->hinstanceOS2 == hinstance) {
     271                dlllistmutex.leave();
     272                return(mod);
     273        }
     274        mod = (Win32LxDll*)mod->next;
     275   }
     276   dlllistmutex.leave();
     277   return(NULL);
     278}
     279//******************************************************************************
     280//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.