Changeset 123 for trunk/src


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

Changes for Win32 TIB allocation (not activated)

Location:
trunk/src/kernel32
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/except.asm

    r100 r123  
    1 ; $Id: except.asm,v 1.3 1999-06-10 20:47:58 phaller Exp $
     1; $Id: except.asm,v 1.4 1999-06-19 13:57:51 sandervl Exp $
    22
    33;/*
     
    175175SetFS   endp
    176176
     177        PUBLIC getSS
     178getSS   proc near
     179        mov     ax, ss
     180        ret
     181getSS   endp
     182
    177183CODE32          ENDS
    178184
  • trunk/src/kernel32/except.h

    r99 r123  
    1 /* $Id: except.h,v 1.3 1999-06-10 19:11:30 phaller Exp $ */
     1/* $Id: except.h,v 1.4 1999-06-19 13:57:51 sandervl Exp $ */
    22
    33/*
     
    2020ULONG GetDllEntryPoint();
    2121
    22 ULONG getEAX();
    23 ULONG getEBX();
     22ULONG  getEAX();
     23ULONG  getEBX();
     24USHORT getSS();
    2425
    2526#ifdef __cplusplus
  • trunk/src/kernel32/initterm.cpp

    r120 r123  
    1 /* $Id: initterm.cpp,v 1.3 1999-06-19 10:54:41 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.4 1999-06-19 13:57:51 sandervl Exp $ */
    22
    33/*
     
    3333#include <string.h>
    3434#include <misc.h>
     35#include <wprocess.h>
    3536
    3637extern "C" {
     
    128129            else   flAllocMem = 0;        // no high memory support
    129130
     131            InitializeTIB(TRUE);
    130132            break;
    131133        case 1 :
     
    146148    dprintf(("kernel32 exit\n"));
    147149    _dump_allocated(10);    /*PLF Wed  98-03-18 23:55:07*/
     150    DestroyTIB();
    148151    _ctordtorTerm();
    149152    CRT_term();
  • trunk/src/kernel32/os2util.cpp

    r120 r123  
    1 /* $Id: os2util.cpp,v 1.3 1999-06-19 10:54:42 sandervl Exp $ */
     1/* $Id: os2util.cpp,v 1.4 1999-06-19 13:57:51 sandervl Exp $ */
    22
    33/*
     
    1414#define INCL_BASE
    1515#define INCL_DOSPROCESS
     16#define INCL_DOSSEL
    1617#include <os2wrap.h>    //Odin32 OS/2 api wrappers
    1718#include <string.h>
     
    207208}
    208209
    209 
    210 
    211 
    212210void  OS2Wait(ULONG msec)
    213211{
    214212   DosSleep(msec);
    215213}
     214
     215//******************************************************************************
     216//Wrapper for Dos16AllocSeg
     217//******************************************************************************
     218BOOL OS2AllocSel(ULONG size, USHORT *selector)
     219{
     220   return (Dos16AllocSeg(size, selector, SEG_NONSHARED) == 0);
     221}
     222//******************************************************************************
     223//Wrapper for Dos16FreeSeg
     224//******************************************************************************
     225BOOL OS2FreeSel(USHORT selector)
     226{
     227   return (Dos16FreeSeg(selector) == 0);
     228}
     229//******************************************************************************
     230//Wrapper for Dos32SelToFlat
     231//******************************************************************************
     232PVOID OS2SelToFlat(USHORT selector)
     233{
     234   return (PVOID)DosSelToFlat(selector << 16);
     235}
     236//******************************************************************************
     237//Get TIB data
     238//******************************************************************************
     239ULONG OS2GetTIB(int tiboff)
     240{
     241 PTIB   ptib;
     242 PPIB   ppib;
     243 APIRET rc;
     244
     245   rc = DosGetInfoBlocks(&ptib, &ppib);
     246   if(rc) {
     247        return 0;
     248   }
     249   switch(tiboff)
     250   {
     251        case TIB_STACKTOP:
     252                return (ULONG)ptib->tib_pstack;
     253        case TIB_STACKLOW:
     254                return (ULONG)ptib->tib_pstacklimit;
     255        default:
     256                return 0;
     257   }
     258}
     259//******************************************************************************
     260//Get PIB data
     261//******************************************************************************
     262ULONG OS2GetPIB(int piboff)
     263{
     264 PTIB   ptib;
     265 PPIB   ppib;
     266 APIRET rc;
     267
     268   rc = DosGetInfoBlocks(&ptib, &ppib);
     269   if(rc) {
     270        return 0;
     271   }
     272   switch(piboff)
     273   {
     274        case PIB_TASKHNDL:
     275                return ppib->pib_hmte;
     276        case PIB_TASKTYPE:
     277                if(ppib->pib_ultype == 3) {
     278                        return TASKTYPE_PM;
     279                }
     280                else    return TASKTYPE_VIO;
     281        default:
     282                return 0;
     283   }
     284}
     285//******************************************************************************
     286//******************************************************************************
  • trunk/src/kernel32/os2util.h

    r99 r123  
    1 /* $Id: os2util.h,v 1.3 1999-06-10 19:11:31 phaller Exp $ */
     1/* $Id: os2util.h,v 1.4 1999-06-19 13:57:51 sandervl Exp $ */
    22
    33/*
     
    4141void  OS2Wait(ULONG msec);
    4242
     43
     44BOOL  OS2AllocSel(ULONG size, USHORT *selector);
     45BOOL  OS2FreeSel(USHORT selector);
     46PVOID OS2SelToFlat(USHORT selector);
     47
     48#define TIB_STACKTOP    0
     49#define TIB_STACKLOW    1
     50
     51ULONG OS2GetTIB(int tiboff);
     52
     53#define PIB_TASKHNDL    0
     54#define PIB_TASKTYPE    1
     55
     56#define TASKTYPE_PM     0
     57#define TASKTYPE_VIO    1
     58
     59ULONG OS2GetPIB(int piboff);
     60
    4361#ifdef __cplusplus
    4462      }
  • 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.