Ignore:
Timestamp:
Jun 19, 1999, 3:57:51 PM (26 years ago)
Author:
sandervl
Message:

Changes for Win32 TIB allocation (not activated)

File:
1 edited

Legend:

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

    r115 r123  
    1 /* $Id: wprocess.cpp,v 1.8 1999-06-17 22:06:10 phaller Exp $ */
    2 
    3 /*
    4  *
    5  * Project Odin Software License can be found in LICENSE.TXT
    6  *
    7  */
     1/* $Id: wprocess.cpp,v 1.9 1999-06-19 13:57:51 sandervl Exp $ */
     2
    83/*
    94 * Win32 process functions
    105 *
    116 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     7 *
     8 *
     9 * Project Odin Software License can be found in LICENSE.TXT
    1210 *
    1311 */
     
    3129#include "versionos2.h"    /*PLF Wed  98-03-18 02:36:51*/
    3230
     31#include <winprocess.h>
     32#include <thread.h>
     33
    3334BOOL      fExeStarted = FALSE;
    3435BOOL      fFreeLibrary = FALSE;
    3536
     37//Process database
     38PDB       ProcessPDB = {0}; 
     39USHORT    ProcessTIBSel = 0;
     40USHORT    OS2Selector   = 0;
     41
     42//#define WIN32_TIBSEL
     43//******************************************************************************
     44// Set up the TIB selector and memory for the current thread
     45//******************************************************************************
     46void InitializeTIB(BOOL fMainThread)
     47{
     48#ifdef WIN32_TIBSEL
     49  TEB   *winteb;
     50  THDB  *thdb;
     51
     52  USHORT tibsel;
     53
     54   if(OS2AllocSel(PAGE_SIZE, &tibsel) == FALSE)
     55   {
     56        dprintf(("InitializeTIB: selector alloc failed!!"));
     57        DebugInt3();
     58        return;
     59   }
     60   winteb = (TEB *)OS2SelToFlat(tibsel);
     61   if(winteb == NULL)
     62   {
     63        dprintf(("InitializeTIB: DosSelToFlat failed!!"));
     64        DebugInt3();
     65        return;
     66   }
     67   memset(winteb, 0, PAGE_SIZE);
     68   thdb = (THDB *)(winteb+1);
     69
     70   winteb->except      = (PVOID)-1;               /* 00 Head of exception handling chain */
     71   winteb->stack_top   = (PVOID)OS2GetTIB(TIB_STACKTOP); /* 04 Top of thread stack */
     72   winteb->stack_low   = (PVOID)OS2GetTIB(TIB_STACKLOW); /* 08 Stack low-water mark */
     73   winteb->htask16     = (USHORT)OS2GetPIB(PIB_TASKHNDL); /* 0c Win16 task handle */
     74   winteb->stack_sel   = getSS();                 /* 0e 16-bit stack selector */
     75   winteb->self        = winteb;                  /* 18 Pointer to this structure */
     76   winteb->flags       = TEBF_WIN32;              /* 1c Flags */
     77   winteb->queue       = 0;                       /* 28 Message queue */
     78   winteb->tls_ptr     = &thdb->tls_array[0];     /* 2c Pointer to TLS array */
     79   winteb->process     = &ProcessPDB;             /* 30 owning process (used by NT3.51 applets)*/
     80
     81   memcpy(&thdb->teb, winteb, sizeof(TEB));
     82   thdb->process         = &ProcessPDB;
     83   thdb->exit_code       = 0x103; /* STILL_ACTIVE */
     84   thdb->teb_sel         = tibsel;
     85
     86   if(OS2GetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
     87   {
     88        thdb->flags      = 0;  //todo gui
     89   }
     90   else thdb->flags      = 0;  //todo textmode
     91
     92   if(fMainThread)
     93   {
     94        //todo initialize PDB during process creation
     95        //todo: initialize TLS array if required
     96        //TLS in executable always TLS index 0?
     97        ProcessTIBSel = tibsel;
     98        OS2Selector   = GetFS();        //0x150b
     99   }
     100   SetFS(tibsel);
     101   dprintf(("InitializeTIB set up TEB with selector %x", tibsel));
     102   return;
     103#endif
     104}
     105//******************************************************************************
     106// Destroy the TIB selector and memory for the current thread
     107//******************************************************************************
     108void DestroyTIB()
     109{
     110   dprintf(("DestroyTIB: FS = %x", GetFS()));
     111#ifdef WIN32_TIBSEL
     112   OS2FreeSel(ProcessTIBSel);
     113   return;
     114#endif
     115}
    36116/******************************************************************************/
    37117//SvL: 4-10-'98: Put in separate procedure, as ICC changes FS:0 when there
     
    71151                    HINSTANCE hinstance)
    72152{
     153#ifdef WIN32_TIBSEL
     154  SetFS(ProcessTIBSel);
     155#endif
     156
    73157  if(getenv("WIN32_IOPL2")) {
    74158    io_init1();
     
    80164  RegisterExe(Win32TableId, NameTableId, VersionResId, Pe2lxVersion, hinstance);
    81165
    82   //NOTE: Breaks Quake 2 if enabled
    83   if(getenv("WIN32_NOEXCEPTION")) {
    84     ChangeTIBStack();   //disable exceptions
    85   }
     166  dprintf(("RegisterResourceUsage: FS = %x", GetFS()));
    86167}
    87168//******************************************************************************
     
    171252  dprintf(("KERNEL32:  ExitProcess %d\n", exitcode));
    172253
     254#ifdef WIN32_TIBSEL
     255  //Restore original OS/2 TIB selector
     256  SetFS(OS2Selector);
     257#endif
     258
    173259  //avoid crashes since win32 & OS/2 exception handler aren't identical
    174260  //(terminate process generates two exceptions)
     
    183269    dprintf(("dll exitlist exception\n"));
    184270  }
     271
     272#ifndef WIN32_TIBSEL
    185273  SetExceptionChain((ULONG)-1);
     274#endif
    186275  O32_ExitProcess(exitcode);
    187276}
     
    363452
    364453  dprintf(("KERNEL32:  GetCommandLine %s\n", cmdline));
     454#ifdef WIN32_TIBSEL
     455  dprintf(("KERNEL32:  FS = %x\n", GetFS()));
     456#else
    365457  //SvL: Replace original startup code exception handler
    366458  ReplaceExceptionHandler();
     459#endif
    367460  return(cmdline);
    368461}
     
    374467         char *asciicmdline = NULL;
    375468
     469#ifdef WIN32_TIBSEL
     470    dprintf(("KERNEL32:  FS = %x\n", GetFS()));
     471#else
    376472    //SvL: Replace original startup code exception handler
    377473    ReplaceExceptionHandler();
     474#endif
    378475
    379476    if(UnicodeCmdLine)
     
    381478
    382479    if(WinExe) {
    383     asciicmdline = WinExe->getCommandLine();
     480        asciicmdline = WinExe->getCommandLine();
    384481    }
    385482    if(asciicmdline == NULL) //not used for converted exes
    386     asciicmdline = O32_GetCommandLine();
     483        asciicmdline = O32_GetCommandLine();
    387484
    388485    if(asciicmdline) {
Note: See TracChangeset for help on using the changeset viewer.