Ignore:
Timestamp:
Jul 7, 1999, 10:11:58 AM (26 years ago)
Author:
sandervl
Message:

Major changes in PE2LX/KERNEL32 for TLS support. DLL VERSION INCREASED TO 3 AS THIS CHANGE MAKES IT INCOMPATIBLE WITH APPS CONVERTED WITH PREVIOUS VERSION OF PE2LX (OR WIN32K)

File:
1 edited

Legend:

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

    r135 r281  
    1 /* $Id: windll.cpp,v 1.6 1999-06-20 17:54:53 sandervl Exp $ */
     1/* $Id: windll.cpp,v 1.7 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    2222#include <iostream.h>
    2323#include <fstream.h>
    24 #include "misc.h"
    25 #include "nameid.h"
    26 #include "win32type.h"
    27 #include "pefile.h"
    28 #include "windll.h"
     24#include <misc.h>
     25#include <nameid.h>
     26#include <win32type.h>
     27#include <pefile.h>
     28#include <windll.h>
     29#include <wprocess.h>
    2930#include "cio.h"
    3031#include "os2util.h"
     
    131132  if(errorState == NO_ERROR && !fUnloaded)
    132133  {
    133         if(!fSystemDll) {
    134                 detachProcess();
    135         }       
     134        detachProcess();
    136135  }
    137136}
     
    304303BOOL Win32Dll::attachProcess()
    305304{
    306   if(fSystemDll || fSkipEntryCalls || !fNativePEImage)
     305 BOOL rc;
     306 USHORT sel;
     307
     308  //Allocate TLS index for this module
     309  tlsAlloc();
     310  tlsAttachThread();    //setup TLS (main thread)
     311
     312  if(fSystemDll || fSkipEntryCalls) {
     313        dprintf(("attachProcess not required for dll %s", szModule));
    307314        return(TRUE);
    308 
    309   if(getenv("WIN32_IOPL2")) {
    310         io_init1();
    311   }
    312   return dllEntryPoint((ULONG)this, DLL_PROCESS_ATTACH, 0);
     315  }
     316
     317  dprintf(("attachProcess to dll %s", szModule));
     318
     319  sel = SetWin32TIB();
     320  rc = dllEntryPoint(hinstance, DLL_PROCESS_ATTACH, 0);
     321  SetFS(sel);
     322  return rc;
    313323}
    314324//******************************************************************************
    315325//******************************************************************************
    316326BOOL Win32Dll::detachProcess()
     327{
     328 BOOL   rc;
     329 USHORT sel;
     330
     331  if(fSystemDll || fSkipEntryCalls) {
     332        tlsDetachThread();      //destroy TLS (main thread)
     333        return(TRUE);
     334  }
     335
     336  dprintf(("detachProcess from dll %s", szModule));
     337
     338  fUnloaded = TRUE;
     339  sel = SetWin32TIB();
     340  rc = dllEntryPoint(hinstance, DLL_PROCESS_DETACH, 0);
     341  SetFS(sel);
     342  tlsDetachThread();    //destroy TLS (main thread)
     343  return rc;
     344}
     345//******************************************************************************
     346//******************************************************************************
     347BOOL Win32Dll::attachThread()
    317348{
    318349  if(fSystemDll || fSkipEntryCalls)
    319350        return(TRUE);
    320351
    321   if(fNativePEImage)
    322         return dllEntryPoint((ULONG)this, DLL_PROCESS_DETACH, 0);
    323   else  return dllEntryPoint((ULONG)this, DLL_PROCESS_ATTACH, 0);  //reversed in converted code
    324 }
    325 //******************************************************************************
    326 //******************************************************************************
    327 BOOL Win32Dll::attachThread()
     352  dprintf(("attachThread to dll %s", szModule));
     353  return dllEntryPoint(hinstance, DLL_THREAD_ATTACH, 0);
     354}
     355//******************************************************************************
     356//******************************************************************************
     357BOOL Win32Dll::detachThread()
    328358{
    329359  if(fSystemDll || fSkipEntryCalls)
    330360        return(TRUE);
    331361
    332   return dllEntryPoint((ULONG)this, DLL_THREAD_ATTACH, 0);
    333 }
    334 //******************************************************************************
    335 //******************************************************************************
    336 BOOL Win32Dll::detachThread()
    337 {
    338   if(fSystemDll || fSkipEntryCalls)
    339         return(TRUE);
    340 
    341   return dllEntryPoint((ULONG)this, DLL_THREAD_DETACH, 0);
     362  dprintf(("attachThread from dll %s", szModule));
     363  return dllEntryPoint(hinstance, DLL_THREAD_DETACH, 0);
     364}
     365//******************************************************************************
     366//Send DLL_THREAD_ATTACH message to all dlls for a new thread
     367//******************************************************************************
     368void Win32Dll::attachThreadToAllDlls()
     369{
     370 Win32Dll *dll = Win32Dll::head;
     371
     372  while(dll) {
     373        dll->attachThread();
     374        dll = dll->getNext();
     375  }
     376}
     377//******************************************************************************
     378//Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
     379//******************************************************************************
     380void Win32Dll::detachThreadFromAllDlls()
     381{
     382 Win32Dll *dll = Win32Dll::head;
     383
     384  while(dll) {
     385        dll->detachThread();
     386        dll = dll->getNext();
     387  }
     388}
     389//******************************************************************************
     390//Setup TLS structure for all dlls for a new thread
     391//******************************************************************************
     392void Win32Dll::tlsAttachThreadToAllDlls()
     393{
     394 Win32Dll *dll = Win32Dll::head;
     395
     396  while(dll) {
     397        dll->tlsAttachThread();
     398        dll = dll->getNext();
     399  }
     400}
     401//******************************************************************************
     402//Destroy TLS structure for all dlls for a thread that's about to die
     403//******************************************************************************
     404void Win32Dll::tlsDetachThreadFromAllDlls()
     405{
     406 Win32Dll *dll = Win32Dll::head;
     407
     408  while(dll) {
     409        dll->tlsDetachThread();
     410        dll = dll->getNext();
     411  }
    342412}
    343413//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.