Changeset 281 for trunk/src


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)

Location:
trunk/src
Files:
1 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r263 r281  
    1 ; $Id: KERNEL32.DEF,v 1.15 1999-07-04 11:44:03 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.16 1999-07-07 08:11:09 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    932932
    933933;Used by tibfix page in exe (change ordinal in lx.cpp too!!)
    934     RegisterResourceUsage         = _RegisterResourceUsage@20      @1203
     934    RegisterExe                   = _RegisterExe@48                @1203
    935935;VMutex
    936936   enter__6VMutexFUl                                               @1204
     
    939939   __dt__6VMutexFv                                                 @1207
    940940;Used by tibfix page in dll (change ordinal in lx.cpp too!!)
    941     DLLExitList                   = _DLLExitList@4                 @1208
    942     RegisterDll                   = _RegisterDll@20                @1209
     941;;;    DLLExitList                   = _DLLExitList@4                 @1208
     942    RegisterDll                   = _RegisterDll@48                @1209
    943943;Unicode
    944944   UnicodeToAsciiString = _UnicodeToAsciiString@4                  @1210
  • trunk/src/kernel32/except.asm

    r223 r281  
    1 ; $Id: except.asm,v 1.5 1999-06-26 18:24:50 sandervl Exp $
     1; $Id: except.asm,v 1.6 1999-07-07 08:11:09 sandervl Exp $
    22
    33;/*
     
    175175SetFS   endp
    176176
     177        PUBLIC SetReturnFS
     178SetReturnFS proc near
     179        push    fs
     180        mov     eax, [esp+8]
     181        mov     fs, eax
     182        pop     eax
     183        ret
     184SetReturnFS endp
     185
    177186        PUBLIC getSS
    178187getSS   proc near
  • trunk/src/kernel32/makefile

    r278 r281  
    1 # $Id: makefile,v 1.11 1999-07-06 15:48:48 phaller Exp $
     1# $Id: makefile,v 1.12 1999-07-07 08:11:10 sandervl Exp $
    22
    33#
     
    6969       pefile.OBJ \
    7070       winimgres.OBJ \
    71        tls.obj \
     71       wintls.obj \
    7272       async.OBJ \
    7373       fileio.obj \
     
    125125    $(PDWIN32_INCLUDE)\unicode.h
    126126
    127 tls.obj: tls.cpp
     127wintls.obj: wintls.cpp $(PDWIN32_INCLUDE)\winimage.h $(PDWIN32_INCLUDE)\winexe.h $(PDWIN32_INCLUDE)\windll.h
    128128
    129129fileio.obj: fileio.cpp \
     
    133133    .\thread.cpp \
    134134    $(PDWIN32_INCLUDE)\wprocess.h \
     135    $(PDWIN32_INCLUDE)\winimage.h $(PDWIN32_INCLUDE)\winexe.h $(PDWIN32_INCLUDE)\windll.h \
    135136    thread.h
    136137
  • trunk/src/kernel32/thread.cpp

    r126 r281  
    1 /* $Id: thread.cpp,v 1.6 1999-06-20 10:55:36 sandervl Exp $ */
     1/* $Id: thread.cpp,v 1.7 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    1414#include "thread.h"
    1515#include "except.h"
    16 #include "misc.h"
     16#include <misc.h>
    1717#include <wprocess.h>
     18#include <windll.h>
     19#include <winexe.h>
    1820
    1921static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
     
    4648DWORD WIN32API GetCurrentThreadId()
    4749{
    48   dprintf(("GetCurrentThreadId\n"));
    49 
     50////  dprintf(("GetCurrentThreadId\n"));
    5051  return(O32_GetCurrentThreadId());
    5152}
     
    121122           exitcode));
    122123
    123 #ifdef WIN32_TIBSEL
     124  Win32Dll::detachThreadFromAllDlls();  //send DLL_THREAD_DETACH message to all dlls
     125  Win32Dll::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
     126  WinExe->tlsDetachThread();                    //destroy TLS structure of main exe
    124127  DestroyTIB();
    125 #endif
    126128  O32_ExitThread(exitcode);
    127129}
     
    153155 WIN32THREADPROC  winthread = me->pCallback;
    154156 LPVOID           userdata  = me->lpUserData;
     157 DWORD            rc;
    155158
    156159  delete me;    //only called once
     
    158161  dprintf(("Win32ThreadProc %d\n", GetCurrentThreadId()));
    159162
    160 #ifdef WIN32_TIBSEL
    161163  TEB *winteb = (TEB *)InitializeTIB();
    162164  if(winteb == NULL) {
     
    170172  thdb->entry_point = (void *)winthread;
    171173  thdb->entry_arg   = (void *)userdata;
     174
    172175  SetWin32TIB();
    173 #else
    174   ReplaceExceptionHandler();
    175 #endif
    176   return(winthread(userdata));
     176  WinExe->tlsAttachThread();              //setup TLS structure of main exe
     177  Win32Dll::tlsAttachThreadToAllDlls(); //setup TLS structures of all dlls
     178  Win32Dll::attachThreadToAllDlls();      //send DLL_THREAD_ATTACH message to all dlls
     179
     180  rc = winthread(userdata);
     181
     182  Win32Dll::detachThreadFromAllDlls();  //send DLL_THREAD_DETACH message to all dlls
     183  Win32Dll::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
     184  WinExe->tlsDetachThread();              //destroy TLS structure of main exe
     185  DestroyTIB();
     186  return rc;
    177187}
    178188//******************************************************************************
  • 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//******************************************************************************
  • trunk/src/kernel32/winexe.cpp

    r126 r281  
    1 /* $Id: winexe.cpp,v 1.7 1999-06-20 10:55:36 sandervl Exp $ */
     1/* $Id: winexe.cpp,v 1.8 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    8787
    8888  fExeStarted  = TRUE;
     89
     90  //Allocate TLS index for this module
     91  tlsAlloc();
     92  tlsAttachThread();    //setup TLS (main thread)
     93
    8994  SetWin32TIB();
    9095  rc = ((WIN32EXEENTRY)entryPoint)();
  • trunk/src/kernel32/winimage.cpp

    r120 r281  
    1 /* $Id: winimage.cpp,v 1.4 1999-06-19 10:54:43 sandervl Exp $ */
     1/* $Id: winimage.cpp,v 1.5 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    6060    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    6161    szFileName(NULL), NameTable(NULL), Win32Table(NULL), fullpath(NULL),
     62    tlsAddress(0), tlsIndexAddr(0), tlsInitSize(0), tlsTotalSize(0), tlsCallBackAddr(0), tlsIndex(-1),
    6263    pResSection(NULL), pResDir(NULL), winres(NULL), VersionId(-1)
    6364{
     
    8485    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    8586    szFileName(NULL), NameTable(NULL), Win32Table(NULL), fullpath(NULL),
     87    tlsAddress(0), tlsIndexAddr(0), tlsInitSize(0), tlsTotalSize(0), tlsCallBackAddr(0), tlsIndex(-1),
    8688    pResSection(NULL), pResDir(NULL), winres(NULL)
    8789{
  • 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)
  • trunk/src/pe2lx/LX.CPP

    r97 r281  
    1 /* $Id: LX.CPP,v 1.3 1999-06-10 17:08:51 phaller Exp $ */
     1/* $Id: LX.CPP,v 1.4 1999-07-07 08:11:10 sandervl Exp $ */
    22
    33/*
     
    5959//Register module in kernel32 (resource managment)
    6060// EXE:
    61 //push  [esp+4]                 ;instance handle
     61//push  [esp+8]                 ;reserved (to use same startup code as dll)
     62//push  [esp+8]                 ;instance handle
    6263//push  internal pe2lx version
    6364//push  version resource id
    6465//push  name_lookup_tableid
    6566//push  orgres_lookup_tableid
     67//push  tib_object_address
     68//push  tib_object_size
     69//push  tib_index_address
     70//push  tib_callback_address
     71//push  original_entrypoint
    6672//mov   ecx, KERNEL32:RegisterResourceInfo (stdcall)
    6773//call  ecx
    68 //
    69 //call  original_entrypoint
    7074//ret
    7175//
    7276// DLL:
    73 //cmp   [esp+8], 1
    74 //je    detach
    75 //push  [esp+4]                 ;instance handle
     77//push  [esp+8]                 ;attach or detach
     78//push  [esp+8]                 ;instance handle
    7679//push  internal pe2lx version
    7780//push  version resource id
    7881//push  name_lookup_tableid
    7982//push  orgres_lookup_tableid
     83//push  tib_object_address
     84//push  tib_index_address
     85//push  tib_callback_address
    8086//mov   ecx, KERNEL32:RegisterDll (stdcall)
     87//push  original_entrypoint
    8188//call  ecx
    82 ///DLL entrypoint:
    83 /// BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
    84 //push  0
    85 //mov   ecx, [esp+12]
    86 //xor   ecx, 1          //0 -> 1, 1 -> 0
    87 //push  ecx             //push entry type (1 = attach process, 0 = detach process)
    88 //push  [esp+12]        //push module handle
    89 //call  testje
    9089//ret
    91 //detach:
    92 //push  [esp+4]         //instance handle
    93 //call  KERNEL32:DllExitList
    94 //ret
    95 
    96 #define EXE_OFF_ENTRYFIX    (1+19+2+10)
    97 #define EXE_OFF_TIBCALL     (EXE_OFF_ENTRYFIX-1)
    98 #define EXE_OFF_NAMETABLE   (3+2+10)
     90
    9991//SvL: 18-7-'98: offsets for internal pe2lx version & version resource id
    100 #define EXE_OFF_PE2LXVER    (5)
    101 #define EXE_OFF_VERRESID    (10)
    102 #define EXE_TIBSIZE         sizeof(szEXETIBFix)
    103 #define EXE_OFF_KERIMP      (EXE_OFF_NAMETABLE+10)
    104 
    105 #define DLL_OFF_ENTRYFIX    (15+28+10)
    106 //#define DLL_OFF_ENTRYFIX   (16+28+10)
    107 #define DLL_OFF_TIBCALL     (DLL_OFF_ENTRYFIX-1)
    108 //SvL: 18-7-'98: offsets for internal pe2lx version & version resource id
    109 #define DLL_OFF_PE2LXVER    (12)
    110 #define DLL_OFF_VERRESID    (17)
    111 #define DLL_OFF_NAMETABLE   (12+10)
    112 //#define DLL_OFF_NAMETABLE   12+1+10
    113 #define DLL_TIBSIZE         sizeof(szDLLTIBFix)
    114 #define DLL_OFF_KERIMP      (DLL_OFF_NAMETABLE+10)
    115 #define DLL_OFF_KERIMP2     (sizeof(szDLLTIBFix)-5)
     92#define EXE_OFF_PE2LXVER     (9)
     93#define EXE_OFF_VERRESID     (14)
     94#define EXE_OFF_NAMETABLE    (19)
     95#define EXE_OFF_ORGRESTABLE  (24)
     96#define EXE_OFF_TIBOBJ_ADDR  (29)
     97#define EXE_OFF_TIBINIT_SIZE (34)
     98#define EXE_OFF_TIBOBJ_SIZE  (39)
     99#define EXE_OFF_TIB_INDEX    (44)
     100#define EXE_OFF_TIB_CALLBACK_ADDR  (49)
     101#define EXE_OFF_ENTRYPOINT   (54)
     102#define EXE_OFF_ENTRYFIX     (59)
     103#define EXE_TIB_SIZE         sizeof(szEXETIBFix)
    116104
    117105#define SIZE_TIBCALL         5
    118106
    119 #define EXTRA_FIXUPS         2  //extra kernel32 imports
     107#define EXTRA_FIXUPS         1  //extra kernel32 import
     108#define EXTRA_TLS_FIXUPS     3  //3 data fixups for TLS support (start, index & callback)
    120109
    121110static unsigned char szEXETIBFix[] = {
    122 //push [esp+4]
    123         0xFF, 0x74, 0x24, 0x04,
     111//push  [esp+8]
     112        0xFF, 0x74, 0x24, 0x08,
     113//push  [esp+4]
     114        0xFF, 0x74, 0x24, 0x08,
    124115//SvL: 18-7-'98: push internal pe2lx version
    125116        0x68, 0x00, 0x00, 0x00, 0x00,
    126117//SvL: 18-7-'98: push version resource id (-1 = no version resource present)
    127118        0x68, 0xFF, 0xFF, 0xFF, 0xFF,
    128 //push [table id1] (kernel32 proc depends on 0x77777777 & 0x88888888!!)
     119//push  [table id1] (kernel32 proc depends on 0x77777777 & 0x88888888!!)
    129120//Svl: So does void LXHeader::SaveConvertedNames()!
    130121        0x68, 0x77, 0x77, 0x77, 0x77,
    131 //push [table id1]
     122//push  [table id1]
    132123        0x68, 0x88, 0x88, 0x88, 0x88,
    133 //mov  ecx, KERNEL32:RegisterResourceInfo (stdcall)
     124//push  tib_object_address
     125        0x68, 0x00, 0x00, 0x00, 0x00,
     126//push  tib_initialized_size
     127        0x68, 0x00, 0x00, 0x00, 0x00,
     128//push  tib_object_size
     129        0x68, 0x00, 0x00, 0x00, 0x00,
     130//push  tib_index_address
     131        0x68, 0x00, 0x00, 0x00, 0x00,
     132//push  tib_callback_address
     133        0x68, 0x00, 0x00, 0x00, 0x00,
     134//push  original_entrypoint
     135        0x68, 0x00, 0x00, 0x00, 0x00,
     136//mov   ecx, KERNEL32:RegisterResourceInfo (stdcall)
    134137        0xB9, 0x99, 0x99, 0x99, 0x99,
    135 //call ecx
     138//call  ecx
    136139        0xFF, 0xD1,
    137 //call entrypoint
    138         0xE8, 0x8C, 0xFF, 0xFF, 0xFF,
    139 //ret
    140         0xC3};
    141 
    142 //WARNING: Kernel32.dll depends on this layout (offsets of dllexitlist &
    143 //         entry point call are hardcoded! (both calculated in RegisterDll)
    144 static unsigned char szDLLTIBFix[] = {
    145 //cmp [esp+8], 1
    146 //      0xCC, 0x80, 0x7C, 0x24, 0x08, 0x01,
    147         0x80, 0x7C, 0x24, 0x08, 0x01,
    148 //je detach
    149         0x74, 0x33,
    150 //push [esp+4]
    151         0xFF, 0x74, 0x24, 0x04,
    152 //SvL: 18-7-'98: push internal pe2lx version
    153         0x68, 0x00, 0x00, 0x00, 0x00,
    154 //SvL: 18-7-'98: push version resource id (-1 = no version resource present)
    155         0x68, 0xFF, 0xFF, 0xFF, 0xFF,
    156 //push [table id1] (kernel32 proc depends on 0x77777777 & 0x88888888!!)
    157 //Svl: So does void LXHeader::SaveConvertedNames()!
    158         0x68, 0x77, 0x77, 0x77, 0x77,
    159 //push [table id1]
    160         0x68, 0x88, 0x88, 0x88, 0x88,
    161 //mov  ecx, KERNEL32:RegisterDll (stdcall)
    162         0xB9, 0x99, 0x99, 0x99, 0x99,
    163 //call ecx
    164         0xFF, 0xD1,
    165 //push 0
    166         0x6A, 0x00,
    167         0x8B, 0x4C, 0x24, 0x0C,
    168         0x83, 0xF1, 0x01,
    169         0x51, 0xFF, 0x74, 0x24, 0x0C,
    170 //call entrypoint
    171         0xE8, 0x80, 0xFF, 0xFF, 0xFF,
    172 //ret
    173         0xC3,
    174 //detach:
    175 //push [esp+4]
    176         0xFF, 0x74, 0x24, 0x04,
    177 //call KERNEL32:DllExitList (stdcall)
    178         0xE8, 0x00, 0x00, 0x00, 0x00,
    179140//ret
    180141        0xC3};
     
    191152                       cvtname(NULL), curcvtname(0), nrcvtnames(0), datapage(NULL),
    192153                       cvtnametableid(0), orgrestableid(0), orgrestable(NULL), nrorgres(0),
    193                        kernel32Object(-1), TIBOffKerImport(0), fConsole(FALSE),
     154                       kernel32Object(-1), fConsole(FALSE),
     155                       tlsAddress(0), tlsIndexAddr(0), tlsInitSize(0), tlsTotalSize(0), tlsCallBackAddr(0),
    194156                       VersionResourceId(-1), impnamesize(0), impmodulesize(0)
    195157{
     
    214176  ZERO(ResSection);
    215177  memset(&PESection[0], 0, sizeof(PESection));
    216 
    217   szTIBFix    = &szEXETIBFix[0];
    218   TIBSize     = EXE_TIBSIZE;
    219   TIBOffEntry = EXE_OFF_ENTRYFIX;
    220   TIBOffCall  = EXE_OFF_TIBCALL;
    221   TIBOffName  = EXE_OFF_NAMETABLE;
    222   //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets
    223   TIBOffPe2lxVer = EXE_OFF_PE2LXVER;
    224   TIBOffVerResId = EXE_OFF_VERRESID;
    225178}
    226179//******************************************************************************
     
    252205  this->IsEXE = IsEXE;
    253206  if(IsEXE) {
    254         szTIBFix          = &szEXETIBFix[0];
    255         TIBSize           = EXE_TIBSIZE;
    256         TIBOffEntry       = EXE_OFF_ENTRYFIX;
    257         TIBOffCall        = EXE_OFF_TIBCALL;
    258         TIBOffName        = EXE_OFF_NAMETABLE;
    259         TIBOffKerImport   = EXE_OFF_KERIMP;
    260         //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets
    261         TIBOffPe2lxVer    = EXE_OFF_PE2LXVER;
    262         TIBOffVerResId    = EXE_OFF_VERRESID;
    263         LXHdr.e32_mflags |= E32MODEXE;
     207        LXHdr.e32_mflags |= E32MODEXE;
    264208  }
    265209  else {//Assuming per process initialization/termination...
    266         szTIBFix          = &szDLLTIBFix[0];
    267         TIBSize           = DLL_TIBSIZE;
    268         TIBOffEntry       = DLL_OFF_ENTRYFIX;
    269         TIBOffCall        = DLL_OFF_TIBCALL;
    270         TIBOffName        = DLL_OFF_NAMETABLE;
    271         TIBOffKerImport   = DLL_OFF_KERIMP;
    272         //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets
    273         TIBOffPe2lxVer    = DLL_OFF_PE2LXVER;
    274         TIBOffVerResId    = DLL_OFF_VERRESID;
    275210        LXHdr.e32_mflags |= E32LIBINIT | E32LIBTERM | E32MODDLL;
    276211  }
     
    437372  rawsize = CombinedData.rawsize;
    438373
    439   datapage[0].size  = TIBSize;
     374  datapage[0].size  = EXE_TIB_SIZE;
    440375  datapage[0].flags = 0;
    441376  idx               = 1;
     
    616551void LXHeader::SetNrOff32Fixups(int nr)
    617552{
    618   intfixuprec = (intfixup *)malloc(nr*sizeof(intfixup));
    619   memset(intfixuprec, 0, nr*sizeof(intfixup));
    620 }
    621 //******************************************************************************
    622 //******************************************************************************
    623 void LXHeader::AddOff32Fixup(int address)
     553  intfixuprec = (intfixup *)malloc((nr+EXTRA_TLS_FIXUPS)*sizeof(intfixup));
     554  memset(intfixuprec, 0, (nr+EXTRA_TLS_FIXUPS)*sizeof(intfixup));
     555}
     556//******************************************************************************
     557//SvL: TLS Section support
     558//Add three interal fixups. One for start of TLS section, one for DWORD that
     559//receives the TLS index and one for the array of TLS callbacks
     560//Also one for the entrypoint address.
     561//******************************************************************************
     562void LXHeader::AddExtraFixups()
     563{
     564  *(ULONG *)&szEXETIBFix[EXE_OFF_TIBOBJ_ADDR] = tlsAddress;
     565  *(ULONG *)&szEXETIBFix[EXE_OFF_TIBINIT_SIZE] = tlsInitSize;
     566  *(ULONG *)&szEXETIBFix[EXE_OFF_TIBOBJ_SIZE] = tlsTotalSize;
     567  *(ULONG *)&szEXETIBFix[EXE_OFF_TIB_INDEX]   = tlsIndexAddr;
     568  *(ULONG *)&szEXETIBFix[EXE_OFF_TIB_CALLBACK_ADDR] = tlsCallBackAddr;
     569  *(ULONG *)&szEXETIBFix[EXE_OFF_ENTRYPOINT] = EntryAddress;
     570
     571  if(LXHdr.e32_mflags & E32NOINTFIX)
     572        return;         //no internal fixups, so we don't have to add them either
     573
     574  AddOff32Fixup(PESection[0].address + EXE_OFF_ENTRYPOINT, TRUE);
     575
     576  if(tlsAddress == 0)
     577        return; //no TLS section in this image
     578
     579  AddOff32Fixup(PESection[0].address + EXE_OFF_TIBOBJ_ADDR, TRUE);
     580  AddOff32Fixup(PESection[0].address + EXE_OFF_TIB_INDEX, TRUE);
     581  AddOff32Fixup(PESection[0].address + EXE_OFF_TIB_CALLBACK_ADDR, TRUE);
     582
     583  return; 
     584}
     585//******************************************************************************
     586//SvL: if fLookatStartupCode is set to true, we'll read the szEXETIBFix
     587//     fixup addresses instead of those in the section
     588//     (section 0 is main code section which doesn't include szEXETIBFix)
     589//******************************************************************************
     590void LXHeader::AddOff32Fixup(int address, BOOL fLookatStartupCode)
    624591{
    625592 static intfixup  crossedpage;
     
    654621  if(type == 0) { // +1 for tibfix page
    655622        assert(PESection[type].type & SECTION_CODE);
    656         targetaddr = *(int *)(PESection[type].rawdata + (address - (PESection[type].address + (PESection[type].nrinvalidpages+1)*PAGE_SIZE)));
     623        if(fLookatStartupCode)
     624        {
     625                targetaddr = *(int *)(&szEXETIBFix[0] + (address & 0xFF));
     626        }
     627        else {
     628                targetaddr = *(int *)(PESection[type].rawdata + (address - (PESection[type].address + (PESection[type].nrinvalidpages+1)*PAGE_SIZE)));
     629        }
    657630  }
    658631  else  targetaddr = *(int *)(PESection[type].rawdata + (address - (PESection[type].address + PESection[type].nrinvalidpages*PAGE_SIZE)));
     
    836809                dest += size-4;
    837810        }
     811#if 0
     812        else
     813        if(strcmp(dest, "OLE32") == 0) {//SvL: Name conflict with Lotus OLE32 dll
     814              strcpy(dest, "OLE32OS2");
     815              dest[-1] = 8;   //change module name length
     816              dest    += 8;
     817        }
     818#endif
    838819        else {
    839820                if(strcmp(dest, "KERNEL32") == 0) {
     
    1018999                        if(PESection[i].type == SECTION_COMBINEDDATA) {
    10191000                                if(j == PESection[i].nrinvalidpages) {
    1020                                         objpage[idx].o32_pagesize        = (USHORT)(TIBSize);
     1001                                        objpage[idx].o32_pagesize        = (USHORT)(EXE_TIB_SIZE);
    10211002                                        objpage[idx].o32_pageflags       = 0;
    1022                                         pagedataoffset                  += TIBSize;
     1003                                        pagedataoffset                  += EXE_TIB_SIZE;
    10231004                                        LXHdr.e32_mpages++;
    1024                                         //Modify entry point address, and write original to TIBFix code
    1025                                         *(LONG *)&szTIBFix[TIBOffEntry]  = LXHdr.e32_eip + PAGE_SIZE - TIBOffCall - SIZE_TIBCALL;
    10261005                                        LXHdr.e32_eip                    = PAGE_SIZE*PESection[i].nrinvalidpages;
    10271006                                        objtable.o32_size                = objtable.o32_mapsize*PAGE_SIZE;
     
    10441023                        else //take care of TIBFix code!
    10451024                        if(fFirstCode == FALSE && PESection[i].type & SECTION_CODE && j == PESection[i].nrinvalidpages) {
    1046                                 objpage[idx].o32_pagesize        = (USHORT)TIBSize;
     1025                                objpage[idx].o32_pagesize        = (USHORT)EXE_TIB_SIZE;
    10471026                                objpage[idx].o32_pageflags       = 0;
    1048                                 pagedataoffset                  += TIBSize;
     1027                                pagedataoffset                  += EXE_TIB_SIZE;
    10491028                                LXHdr.e32_mpages++;
    1050                                 //Modify entry point address, and write original to TIBFix code
    1051                                 *(LONG *)&szTIBFix[TIBOffEntry]  = LXHdr.e32_eip + PAGE_SIZE - TIBOffCall - SIZE_TIBCALL;
    10521029
    10531030                                LXHdr.e32_eip                    = PAGE_SIZE*PESection[i].nrinvalidpages;
     
    11971174                kerord->nr_stype   = 0x07;              //32 bits offset
    11981175                kerord->nr_flags   = 0x01 | 0x40;       //import by ordinal + mod offset = 16 bits
    1199                 kerord->r32_soff   = TIBOffKerImport;
     1176                kerord->r32_soff   = EXE_OFF_ENTRYFIX;
    12001177                kerord->r32_objmod = kernel32Object + 1;
    12011178                if(IsEXE)
     
    12041181
    12051182                currealrec = (realintfixup *)((int)currealrec + sizeof(realnamefixup));
    1206                 if(!IsEXE) {
    1207                         kerord = (realordfixup *)currealrec;
    1208                         kerord->nr_stype   = 0x08;              //32 bits self referencing offset
    1209                         kerord->nr_flags   = 0x01 | 0x40;       //import by ordinal + mod offset = 16 bits
    1210                         kerord->r32_soff   = DLL_OFF_KERIMP2;
    1211                         kerord->r32_objmod = kernel32Object + 1;
    1212                         kerord->ord        = ORD_KERNEL32DLLEXITLIST;
    1213                         currealrec = (realintfixup *)((int)currealrec + sizeof(realnamefixup));
    1214                 }
    12151183        }
    12161184        //SvL: 16-9-'97, for multiple import pages
     
    12331201
    12341202  //Add extra kernel32 imports
    1235   if(IsEXE)
    1236         nrimpfixups++;
    1237   else  nrimpfixups += EXTRA_FIXUPS;
     1203  nrimpfixups += EXTRA_FIXUPS;
    12381204
    12391205  //Write fixup page table
     
    12581224  //Write Import Procedure Name array
    12591225  if(impnamesize) {
    1260   DosWrite(win32handle, impnames, impnamesize, &ulWrite);
     1226        DosWrite(win32handle, impnames, impnamesize, &ulWrite);
    12611227  }
    12621228
     
    12701236                //Put our special TIB fix to code section first! (SvL: 30-7-'97)
    12711237                if(PESection[i].type & SECTION_CODE && fFirstCode == FALSE) {
    1272                         DosWrite(win32handle, szTIBFix, TIBSize, &ulWrite);
     1238                        DosWrite(win32handle, szEXETIBFix, EXE_TIB_SIZE, &ulWrite);
    12731239                        fFirstCode = TRUE;
    12741240                }
     
    15961562
    15971563        //fill in parameter for RegisterResourceInfo
    1598         *(LONG *)&szTIBFix[TIBOffName] = cvtnametableid;
     1564        *(LONG *)&szEXETIBFix[EXE_OFF_NAMETABLE] = cvtnametableid;
    15991565
    16001566        StoreResource(cvtnametableid, RT_RCDATA, (int)curcvtname - (int)cvtname, (char *)cvtname);
     
    16061572
    16071573        //fill in parameter for RegisterResourceInfo
    1608         *(LONG *)&szTIBFix[TIBOffName+5] = (fConsole << 24) | orgrestableid;
     1574        *(LONG *)&szEXETIBFix[EXE_OFF_ORGRESTABLE] = (fConsole << 24) | orgrestableid;
    16091575
    16101576        StoreResource(orgrestableid, RT_RCDATA, (nrorgres+1)*sizeof(ULONG), (char *)orgrestable);
    16111577  }
    16121578  else {
    1613         *(LONG *)&szTIBFix[TIBOffName+5] = (fConsole << 24) | 0x888888;
     1579        *(LONG *)&szEXETIBFix[EXE_OFF_ORGRESTABLE] = (fConsole << 24) | 0x888888;
    16141580  }
    16151581  //SvL: 18-7-'98: Store internal pe2lx version and version resource id
    1616   *(LONG *)&szTIBFix[TIBOffPe2lxVer] = PE2LX_VERSION;
    1617   *(LONG *)&szTIBFix[TIBOffVerResId] = VersionResourceId;
     1582  *(LONG *)&szEXETIBFix[EXE_OFF_PE2LXVER] = PE2LX_VERSION;
     1583  *(LONG *)&szEXETIBFix[EXE_OFF_VERRESID] = VersionResourceId;
    16181584}
    16191585/******************************************************************************/
  • trunk/src/pe2lx/LX.H

    r97 r281  
    1 /* $Id: LX.H,v 1.3 1999-06-10 17:08:51 phaller Exp $ */
     1/* $Id: LX.H,v 1.4 1999-07-07 08:11:11 sandervl Exp $ */
    22
    33/*
     
    145145               ~LXHeader();
    146146
    147        void SetEntryAddress(int address);
     147       void SetEntryAddress(int address);       //relative
     148
     149       void SetEntryPoint(int address) { EntryAddress = address; }; //absolute virtual address
     150
    148151       void SetExeType(BOOL IsEXE);
    149152       void SetNoFixups();
     
    159162       BOOL SaveNewExeFile(char *filename);
    160163       void SetModuleType(int type);
    161        void AddOff32Fixup(int address);
     164       void AddOff32Fixup(int address, BOOL fLookatStartupCode = FALSE);
    162165       void SetNrOff32Fixups(int nr);
    163166       void AddNameExport(int address, char *name, int ordinal);
     
    178181       //SvL: 18-7-'98: Set version resource id
    179182       void SetVersionResourceId(int id) { VersionResourceId = id; };
     183
     184       void SetTLSAddress(ULONG dwTlsAddress)           { tlsAddress = dwTlsAddress; };
     185       void SetTLSIndexAddress(ULONG dwTlsIndexAddr)    { tlsIndexAddr = dwTlsIndexAddr; };
     186       void SetTLSInitSize(ULONG dwTlsSize)             { tlsInitSize = dwTlsSize; };
     187       void SetTLSTotalSize(ULONG dwTlsSize)            { tlsTotalSize = dwTlsSize; };
     188       void SetTLSCallBackAddr(ULONG dwTlsCallBackAddr) { tlsCallBackAddr = dwTlsCallBackAddr; };
     189
     190       void AddExtraFixups();
    180191
    181192private:
     
    240251  ULONG          VersionResourceId;
    241252
    242   unsigned char *szTIBFix;
    243   int        TIBSize;
    244   int        TIBOffEntry;
    245   int        TIBOffCall;
    246   int            TIBOffName;
    247   int            TIBOffKerImport;
    248   //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets
    249   int            TIBOffPe2lxVer;
    250   int            TIBOffVerResId;
     253  ULONG         tlsAddress;             //address of TLS data
     254  ULONG         tlsIndexAddr;           //address of DWORD that receives the TLS index
     255  ULONG         tlsInitSize;            //size of initialized TLS memory block
     256  ULONG         tlsTotalSize;           //size of TLS memory block
     257  ULONG         tlsCallBackAddr;        //ptr to TLS callback array
    251258};
    252259
  • trunk/src/pe2lx/pe.cpp

    r275 r281  
    1 /* $Id: pe.cpp,v 1.5 1999-07-06 08:50:11 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.6 1999-07-07 08:11:11 sandervl Exp $ */
    22
    33/*
     
    230230  else  OS2Exe.SetModuleName(os2file);
    231231
     232  OS2Exe.SetEntryPoint(oh.AddressOfEntryPoint+oh.ImageBase);
     233
    232234  nSections = NR_SECTIONS(win32file);
    233235
     
    276278                        continue;
    277279                }
     280                if(strcmp(psh[i].Name, ".tls") == 0)
     281                {
     282                  IMAGE_TLS_DIRECTORY *tlsDir;
     283
     284                        tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS);
     285                        if(tlsDir) {
     286                                cout << "TLS Directory" << endl;
     287                                cout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
     288                                cout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
     289                                cout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
     290                                cout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
     291                                OS2Exe.SetTLSAddress(tlsDir->StartAddressOfRawData);
     292                                OS2Exe.SetTLSIndexAddress((ULONG)tlsDir->AddressOfIndex);
     293                                OS2Exe.SetTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
     294                                OS2Exe.SetTLSTotalSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData + tlsDir->SizeOfZeroFill);
     295                                OS2Exe.SetTLSCallBackAddr((ULONG)tlsDir->AddressOfCallBacks);
     296                        }
     297                }
    278298
    279299                if ((psh[i].Characteristics & IMAGE_SCN_CNT_CODE)
     
    287307                                OS2Exe.SetEntryAddress(oh.AddressOfEntryPoint - oh.BaseOfCode);
    288308                        else    OS2Exe.SetEntryAddress(oh.AddressOfEntryPoint-psh[i].VirtualAddress);
     309
    289310                        OS2Exe.StoreSection((char *)win32file+psh[i].PointerToRawData,
    290311                                            psh[i].SizeOfRawData, psh[i].Misc.VirtualSize,
     
    332353  prel = (PIMAGE_BASE_RELOCATION) ImageDirectoryOffset (win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC);
    333354  OS2Exe.SetNrOff32Fixups((prel) ? oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size/2 : 0);
     355
     356  //SvL: Add EntryPoint & TLS fixups (if required)
     357  OS2Exe.AddExtraFixups();
    334358
    335359  if(prel) {
Note: See TracChangeset for help on using the changeset viewer.