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/wprocess.cpp

    r130 r281  
    1 /* $Id: wprocess.cpp,v 1.12 1999-06-20 12:46:09 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.13 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    4545TEB *InitializeTIB(BOOL fMainThread)
    4646{
    47 #ifdef WIN32_TIBSEL
    4847  TEB   *winteb;
    4948  THDB  *thdb;
     
    108107   dprintf(("InitializeTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
    109108   return winteb;
    110 #else
    111    return 0;
    112 #endif
    113109}
    114110//******************************************************************************
     
    117113void DestroyTIB()
    118114{
    119 #ifdef WIN32_TIBSEL
    120115 SHORT  orgtibsel;
    121116 TEB   *winteb;
     
    141136   TIBFlatPtr = NULL;
    142137   return;
    143 #endif
    144138}
    145139/******************************************************************************/
     
    147141void WIN32API RestoreOS2TIB()
    148142{
    149 #ifdef WIN32_TIBSEL
    150143 SHORT  orgtibsel;
    151144 TEB   *winteb;
     
    160153        SetFS(orgtibsel);
    161154   }
    162 #endif
    163155}
    164156/******************************************************************************/
    165157/******************************************************************************/
    166 void WIN32API SetWin32TIB()
    167 {
    168 #ifdef WIN32_TIBSEL
     158USHORT WIN32API SetWin32TIB()
     159{
    169160 SHORT  win32tibsel;
    170161 TEB   *winteb;
     
    177168
    178169        //Restore our win32 FS selector
    179         SetFS(win32tibsel);
     170        return SetReturnFS(win32tibsel);
    180171   }
    181172   else DebugInt3();
    182 #endif
     173
     174   return 0;
    183175}
    184176/******************************************************************************/
    185 //SvL: 4-10-'98: Put in separate procedure, as ICC changes FS:0 when there
    186 //               are new or delete calls present.
    187 //******************************************************************************
    188 void RegisterExe(LONG Win32TableId, LONG NameTableId, LONG VersionResId,
    189                  LONG Pe2lxVersion, HINSTANCE hinstance)
     177//******************************************************************************
     178void WIN32API RegisterExe(WIN32EXEENTRY EntryPoint, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
     179                          LPDWORD TlsIndexAddr, ULONG TlsInitSize,
     180                          ULONG TlsTotalSize, LPVOID TlsAddress,
     181                          LONG Win32TableId, LONG NameTableId, LONG VersionResId,
     182                          LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwReserved)
    190183{
    191184  if(WinExe != NULL) //should never happen
    192185    delete(WinExe);
    193186
     187  CheckVersion(Pe2lxVersion, OS2GetDllName(hinstance));
     188
     189  if(getenv("WIN32_IOPL2")) {
     190    io_init1();
     191  }
     192
    194193  //SvL: Use 0 instead of the real instance handle (for resource lookup)
    195194  Win32Exe *winexe = new Win32Exe(0, NameTableId, Win32TableId);
     195
    196196  if(winexe) {
    197     winexe->setVersionId(VersionResId);
    198     winexe->setOS2InstanceHandle(hinstance);
     197        dprintf(("RegisterExe Win32TableId = %x", Win32TableId));
     198        dprintf(("RegisterExe NameTableId  = %x", NameTableId));
     199        dprintf(("RegisterExe VersionResId = %x", VersionResId));
     200        dprintf(("RegisterExe Pe2lxVersion = %x", Pe2lxVersion));
     201
     202        winexe->setVersionId(VersionResId);
     203        winexe->setOS2InstanceHandle(hinstance);
     204        winexe->setEntryPoint((ULONG)EntryPoint);
     205        winexe->setTLSAddress(TlsAddress);
     206        winexe->setTLSInitSize(TlsInitSize);
     207        winexe->setTLSTotalSize(TlsTotalSize);
     208        winexe->setTLSIndexAddr(TlsIndexAddr);
     209        winexe->setTLSCallBackAddr(TlsCallbackAddr);
     210
     211        char *modname = getenv("WIN32MODULE");
     212
     213        if(modname != NULL)
     214        {
     215                dprintf(("Set full path for exe to %s", modname));
     216                winexe->setFullPath(modname);
     217        }
     218        winexe->start();
    199219  }
    200220  else {
    201     eprintf(("Win32Exe creation failed!\n"));
    202     DebugInt3();
    203   }
    204 
    205   char *modname = getenv("WIN32MODULE");
    206 
    207   if(modname != NULL)
    208   {
    209     dprintf(("Set full path for exe to %s", modname));
    210     winexe->setFullPath(modname);
    211   }
    212 
    213   fExeStarted  = TRUE;
    214 }
    215 //******************************************************************************
    216 //******************************************************************************
    217 VOID WIN32API RegisterResourceUsage(LONG Win32TableId, LONG NameTableId,
    218                     LONG VersionResId, LONG Pe2lxVersion,
    219                     HINSTANCE hinstance)
    220 {
    221   SetWin32TIB();
    222 
    223   if(getenv("WIN32_IOPL2")) {
    224     io_init1();
    225   }
    226   dprintf(("RegisterResourceUsage %X resid = %d\n", hinstance, VersionResId));
    227 
    228   CheckVersion(Pe2lxVersion, OS2GetDllName(hinstance));
    229 
    230   RegisterExe(Win32TableId, NameTableId, VersionResId, Pe2lxVersion, hinstance);
    231 
    232   dprintf(("RegisterResourceUsage: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
    233 }
    234 //******************************************************************************
    235 //******************************************************************************
    236 void CreateDll(LONG Win32TableId, LONG NameTableId, LONG VersionResId,
    237                HINSTANCE hinstance, WIN32DLLENTRY pfnDllEntry)
    238 {
     221        eprintf(("Win32Exe creation failed!\n"));
     222        DebugInt3();
     223        return;
     224  }
     225}
     226//******************************************************************************
     227//******************************************************************************
     228ULONG WIN32API RegisterDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
     229                           LPDWORD TlsIndexAddr, ULONG TlsInitSize,
     230                           ULONG TlsTotalSize, LPVOID TlsAddress,
     231                           LONG Win32TableId, LONG NameTableId, LONG VersionResId,
     232                           LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)
     233{
     234 char *name;
     235
    239236  Win32Dll *winmod = Win32Dll::findModule(hinstance);
    240 
    241   if(winmod != NULL) {
    242     //dll manually loaded by PE loader (Win32Dll::init)
    243     winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);
    244     return;
    245   }
    246 
    247   //converted win32 dll loaded by OS/2 loader
    248   winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
    249   if(winmod == NULL) {
    250     eprintf(("Failed to allocate module object!\n"));
    251     DebugInt3();
    252     return;
    253   }
    254   //SvL: 19-8-'98
    255   winmod->AddRef();
    256   winmod->setVersionId(VersionResId);
    257 }
    258 //******************************************************************************
    259 //******************************************************************************
    260 VOID WIN32API RegisterDll(LONG Win32TableId, LONG NameTableId,
    261                           LONG VersionResId, LONG Pe2lxVersion,
    262                           HINSTANCE hinstance)
    263 {
    264  WIN32DLLENTRY  pfnDllEntry;
    265  char *name;
    266 
    267   pfnDllEntry = (WIN32DLLENTRY)GetDllEntryPoint();  //== return address
    268 
    269   if(getenv("WIN32_IOPL2")) {
    270     io_init1();
    271   }
    272   name = OS2GetDllName(hinstance);
    273   CheckVersion(Pe2lxVersion, name);
    274 
    275   dprintf(("RegisterDll %X %s\n", hinstance, name));
    276 
    277   CreateDll(Win32TableId, NameTableId, VersionResId, hinstance, pfnDllEntry);
    278 
    279   /* @@@PH 1998/03/17 console devices initialization */
    280   iConsoleDevicesRegister();
    281 
    282   SetWin32TIB();
    283   dprintf(("RegisterDll: FS = %x", GetFS()));
     237  if(dwAttachType == 0)
     238  { //Process attach
     239        if(getenv("WIN32_IOPL2")) {
     240                io_init1();
     241        }
     242        name = OS2GetDllName(hinstance);
     243        CheckVersion(Pe2lxVersion, name);
     244
     245        dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));
     246        dprintf(("RegisterDll Win32TableId = %x", Win32TableId));
     247        dprintf(("RegisterDll NameTableId  = %x", NameTableId));
     248        dprintf(("RegisterDll VersionResId = %x", VersionResId));
     249        dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));
     250
     251        if(winmod != NULL) {
     252                //dll manually loaded by PE loader (Win32Dll::init)
     253                winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);
     254        }
     255        else {
     256                //converted win32 dll loaded by OS/2 loader
     257                winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
     258                if(winmod == NULL) {
     259                        eprintf(("Failed to allocate module object!\n"));
     260                        DebugInt3();
     261                        return 0;       //fail dll load
     262                }
     263        }
     264        winmod->setTLSAddress(TlsAddress);
     265        winmod->setTLSInitSize(TlsInitSize);
     266        winmod->setTLSTotalSize(TlsTotalSize);
     267        winmod->setTLSIndexAddr(TlsIndexAddr);
     268        winmod->setTLSCallBackAddr(TlsCallbackAddr);
     269
     270        /* @@@PH 1998/03/17 console devices initialization */
     271        iConsoleDevicesRegister();
     272
     273        //SvL: 19-8-'98
     274        winmod->AddRef();
     275        winmod->setVersionId(VersionResId);
     276
     277        winmod->attachProcess();
     278   }
     279   else {//process detach
     280        if(winmod != NULL && !fFreeLibrary) {
     281                return 0;       //don't unload (OS/2 dll unload bug)
     282        }
     283//Runtime environment could already be gone, so don't do this
     284//      dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
     285   }
     286   return 1;    //success
    284287}
    285288//******************************************************************************
     
    294297  }
    295298  return;
    296 }
    297 //******************************************************************************
    298 //Called when a dll is detached (either at process exit or when FreeLibrary is called)
    299 //******************************************************************************
    300 BOOL WIN32API DLLExitList(HINSTANCE hInstance)
    301 {
    302 //  dprintf(("DLLExitList"));
    303   Win32Dll *winmod = Win32Dll::findModule(hInstance);
    304 
    305   if(winmod == NULL) {//probably called after we manually unloaded it in ExitProcess
    306     return(1);  //remove it from memory
    307   }
    308   dprintf(("DllExitList for %s (%X)\n", OS2GetDllName(winmod->getInstanceHandle()), winmod->getInstanceHandle()));
    309   delete(winmod);
    310 
    311   if(fFreeLibrary) {
    312     dprintf(("KERNEL32: DLLExitList Ditched by FreeLibrary\n"));
    313     return(1);  //remove it as we no longer need it
    314   }
    315   return(0);    //don't remove it (OS/2 can unload them at process exit in the wrong order!)
    316299}
    317300//******************************************************************************
     
    513496
    514497  dprintf(("KERNEL32:  GetCommandLine %s\n", cmdline));
    515 #ifdef WIN32_TIBSEL
    516498  dprintf(("KERNEL32:  FS = %x\n", GetFS()));
    517 #else
    518   //SvL: Replace original startup code exception handler
    519   ReplaceExceptionHandler();
    520 #endif
    521499  return(cmdline);
    522500}
     
    528506         char *asciicmdline = NULL;
    529507
    530 #ifdef WIN32_TIBSEL
    531508    dprintf(("KERNEL32:  FS = %x\n", GetFS()));
    532 #else
    533     //SvL: Replace original startup code exception handler
    534     ReplaceExceptionHandler();
    535 #endif
    536509
    537510    if(UnicodeCmdLine)
Note: See TracChangeset for help on using the changeset viewer.