Ignore:
Timestamp:
Nov 21, 2000, 12:36:09 PM (25 years ago)
Author:
sandervl
Message:

Updates for TEB changes

File:
1 edited

Legend:

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

    r4555 r4658  
    1 /* $Id: wprocess.cpp,v 1.107 2000-11-05 13:40:47 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.108 2000-11-21 11:35:09 sandervl Exp $ */
    22
    33/*
     
    7171
    7272//list of thread database structures
    73 static THDB     *threadList = 0;
     73static TEB      *threadList = 0;
    7474static VMutex    threadListMutex;
    7575
     
    100100//******************************************************************************
    101101//******************************************************************************
    102 THDB *WIN32API GetThreadTHDB()
    103 {
    104  TEB  *winteb;
    105  THDB *thdb;
    106 
    107     if(TIBFlatPtr == NULL)
    108         return 0;
    109 
    110     winteb = (TEB *)*TIBFlatPtr;
    111     if(winteb == NULL) {
    112         return NULL;
    113     }
    114     thdb = (THDB *)(winteb+1);
    115 
    116     return thdb;
    117 }
    118 //******************************************************************************
    119 //******************************************************************************
    120 THDB *WIN32API GetTHDBFromThreadId(ULONG threadId)
    121 {
    122  THDB *thdb = threadList;
     102TEB *WIN32API GetTEBFromThreadId(ULONG threadId)
     103{
     104 TEB *teb = threadList;
    123105
    124106    threadListMutex.enter();
    125     while(thdb) {
    126         if(thdb->threadId == threadId) {
     107    while(teb) {
     108        if(teb->o.odin.threadId == threadId) {
    127109            break;
    128110        }
    129         thdb = thdb->next;
     111        teb = teb->o.odin.next;
    130112    }
    131113    threadListMutex.leave();
    132     return thdb;
    133 }
    134 //******************************************************************************
    135 //******************************************************************************
    136 THDB *WIN32API GetTHDBFromThreadHandle(HANDLE hThread)
    137 {
    138  THDB *thdb = threadList;
     114    return teb;
     115}
     116//******************************************************************************
     117//******************************************************************************
     118TEB *WIN32API GetTEBFromThreadHandle(HANDLE hThread)
     119{
     120 TEB *teb = threadList;
    139121
    140122    threadListMutex.enter();
    141     while(thdb) {
    142         if(thdb->hThread == hThread) {
     123    while(teb) {
     124        if(teb->o.odin.hThread == hThread) {
    143125            break;
    144126        }
    145         thdb = thdb->next;
     127        teb = teb->o.odin.next;
    146128    }
    147129    threadListMutex.leave();
    148     return thdb;
     130    return teb;
    149131}
    150132//******************************************************************************
     
    154136{
    155137  TEB   *winteb;
    156   THDB  *thdb;
    157138  ULONG  hThreadMain;
    158139  USHORT tibsel;
     
    170151        hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, TRUE);
    171152    }
    172     if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE)
     153    if(OSLibAllocSel(sizeof(TEB), &tibsel) == FALSE)
    173154    {
    174155        dprintf(("InitializeTIB: selector alloc failed!!"));
     
    183164        return NULL;
    184165    }
    185     memset(winteb, 0, PAGE_SIZE);
    186     thdb       = (THDB *)(winteb+1);
     166    memset(winteb, 0, sizeof(TEB));
    187167    *TIBFlatPtr = (DWORD)winteb;
    188168
     
    195175    winteb->flags       = TEBF_WIN32;              /* 1c Flags */
    196176    winteb->queue       = 0;                       /* 28 Message queue */
    197     winteb->tls_ptr     = &thdb->tls_array[0];     /* 2c Pointer to TLS array */
     177    winteb->tls_ptr     = &winteb->tls_array[0];   /* 2c Pointer to TLS array */
    198178    winteb->process     = &ProcessPDB;             /* 30 owning process (used by NT3.51 applets)*/
    199179
    200     memcpy(&thdb->teb, winteb, sizeof(TEB));
    201     thdb->process         = &ProcessPDB;
    202     thdb->exit_code       = 0x103; /* STILL_ACTIVE */
    203     thdb->teb_sel         = tibsel;
    204     thdb->OrgTIBSel       = GetFS();
    205     thdb->pWsockData      = NULL;
    206     thdb->threadId        = GetCurrentThreadId();
     180    winteb->process         = &ProcessPDB;
     181    winteb->exit_code       = 0x103; /* STILL_ACTIVE */
     182    winteb->teb_sel         = tibsel;
     183    winteb->o.odin.OrgTIBSel       = GetFS();
     184    winteb->o.odin.pWsockData      = NULL;
     185    winteb->o.odin.threadId        = GetCurrentThreadId();
    207186    if(fMainThread) {
    208         thdb->hThread     = hThreadMain;
    209     }
    210     else thdb->hThread    = GetCurrentThread();
    211     thdb->lcid            = GetUserDefaultLCID();
     187         winteb->o.odin.hThread     = hThreadMain;
     188    }
     189    else winteb->o.odin.hThread    = GetCurrentThread();
     190    winteb->o.odin.lcid            = GetUserDefaultLCID();
    212191
    213192    threadListMutex.enter();
    214     THDB *thdblast        = threadList;
    215     if(!thdblast) {
    216         threadList = thdb;
     193    TEB *teblast        = threadList;
     194    if(!teblast) {
     195        threadList = winteb;
    217196    }
    218197    else {
    219         while(thdblast->next) {
    220             thdblast = thdblast->next;
    221         }
    222         thdblast->next   = thdb;
    223     }
    224     thdb->next            = NULL;
     198        while(teblast->o.odin.next) {
     199            teblast = teblast->o.odin.next;
     200        }
     201        teblast->o.odin.next = winteb;
     202    }
     203    winteb->o.odin.next        = NULL;
    225204    threadListMutex.leave();
    226205
    227206    if(OSLibGetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
    228207    {
    229         thdb->flags      = 0;  //todo gui
    230     }
    231     else thdb->flags      = 0;  //todo textmode
     208         winteb->flags      = 0;  //todo gui
     209    }
     210    else winteb->flags      = 0;  //todo textmode
    232211
    233212    //Initialize thread security objects (TODO: Not complete)
     
    240219    }
    241220    SID_IDENTIFIER_AUTHORITY sidIdAuth = {0};
    242     thdb->threadinfo.dwType = SECTYPE_PROCESS | SECTYPE_INITIALIZED;
    243     RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &thdb->threadinfo.SidUser.User.Sid);
    244     thdb->threadinfo.SidUser.User.Attributes = 0; //?????????
    245 
    246     thdb->threadinfo.pTokenGroups = (TOKEN_GROUPS*)malloc(sizeof(TOKEN_GROUPS));
    247     thdb->threadinfo.pTokenGroups->GroupCount = 1;
    248     RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &thdb->threadinfo.PrimaryGroup.PrimaryGroup);
    249     thdb->threadinfo.pTokenGroups->Groups[0].Sid = thdb->threadinfo.PrimaryGroup.PrimaryGroup;
    250     thdb->threadinfo.pTokenGroups->Groups[0].Attributes = 0; //????
     221    winteb->o.odin.threadinfo.dwType = SECTYPE_PROCESS | SECTYPE_INITIALIZED;
     222    RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &winteb->o.odin.threadinfo.SidUser.User.Sid);
     223    winteb->o.odin.threadinfo.SidUser.User.Attributes = 0; //?????????
     224
     225    winteb->o.odin.threadinfo.pTokenGroups = (TOKEN_GROUPS*)malloc(sizeof(TOKEN_GROUPS));
     226    winteb->o.odin.threadinfo.pTokenGroups->GroupCount = 1;
     227    RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &winteb->o.odin.threadinfo.PrimaryGroup.PrimaryGroup);
     228    winteb->o.odin.threadinfo.pTokenGroups->Groups[0].Sid = winteb->o.odin.threadinfo.PrimaryGroup.PrimaryGroup;
     229    winteb->o.odin.threadinfo.pTokenGroups->Groups[0].Attributes = 0; //????
    251230//        pPrivilegeSet   = NULL;
    252231//        pTokenPrivileges= NULL;
     
    254233//        DefaultDACL     = {0};
    255234//        TokenSource     = {0};
    256     thdb->threadinfo.TokenType = TokenPrimary;
     235    winteb->o.odin.threadinfo.TokenType = TokenPrimary;
    257236
    258237    if(fMainThread)
     
    293272 SHORT  orgtibsel;
    294273 TEB   *winteb;
    295  THDB  *thdb;
    296274
    297275    dprintf(("DestroyTIB: FS     = %x", GetFS()));
     
    300278    winteb = (TEB *)*TIBFlatPtr;
    301279    if(winteb) {
    302         thdb = (THDB *)(winteb+1);
    303         orgtibsel = thdb->OrgTIBSel;
     280        orgtibsel = winteb->o.odin.OrgTIBSel;
     281
     282        dprintf(("DestroyTIB: OSLibFreeSel %x", winteb->teb_sel));
    304283
    305284        threadListMutex.enter();
    306         THDB *curthdb        = threadList;
    307         if(curthdb == thdb) {
    308             threadList = thdb->next;
     285        TEB *curteb        = threadList;
     286        if(curteb == winteb) {
     287            threadList = winteb->o.odin.next;
    309288        }
    310289        else {
    311             while(curthdb->next != thdb) {
    312                 curthdb = curthdb->next;
    313                 if(curthdb == NULL) {
    314                     dprintf(("DestroyTIB: couldn't find thdb %x", thdb));
     290            while(curteb->o.odin.next != winteb) {
     291                curteb = curteb->o.odin.next;
     292                if(curteb == NULL) {
     293                    dprintf(("DestroyTIB: couldn't find teb %x", winteb));
    315294                    DebugInt3();
    316295                    break;
    317296                }
    318297            }
    319             if(curthdb) {
    320                 curthdb->next = thdb->next;
     298            if(curteb) {
     299                curteb->o.odin.next = winteb->o.odin.next;
    321300            }
    322301        }
     
    327306
    328307        //And free our own
    329         OSLibFreeSel(thdb->teb_sel);
     308        OSLibFreeSel(winteb->teb_sel);
    330309
    331310        *TIBFlatPtr = 0;
     
    348327 SHORT  orgtibsel;
    349328 TEB   *winteb;
    350  THDB  *thdb;
    351329
    352330   //If we're running an Odin32 OS/2 application (not converted!), then we
     
    358336    winteb = (TEB *)*TIBFlatPtr;
    359337    if(winteb) {
    360         thdb = (THDB *)(winteb+1);
    361         orgtibsel = thdb->OrgTIBSel;
     338        orgtibsel = winteb->o.odin.OrgTIBSel;
    362339
    363340        //Restore our original FS selector
     
    371348 SHORT  win32tibsel;
    372349 TEB   *winteb;
    373  THDB  *thdb;
    374350
    375351    //If we're running an Odin32 OS/2 application (not converted!), then we
     
    381357    winteb = (TEB *)*TIBFlatPtr;
    382358    if(winteb) {
    383         thdb = (THDB *)(winteb+1);
    384         win32tibsel = thdb->teb_sel;
     359        win32tibsel = winteb->teb_sel;
    385360
    386361        //Restore our win32 FS selector
     
    395370            return GetFS();
    396371        }
    397         thdb = (THDB *)(winteb+1);
    398         win32tibsel = thdb->teb_sel;
     372        win32tibsel = winteb->teb_sel;
    399373
    400374        //Restore our win32 FS selector
     
    15381512                            LPPROCESS_INFORMATION lpProcessInfo )
    15391513{
    1540  THDB *pThreadDB = (THDB*)GetThreadTHDB();
     1514 TEB *pThreadDB = (TEB*)GetThreadTEB();
    15411515 char *cmdline = NULL;
    15421516 BOOL  rc;
     
    15571531      if (dwCreationFlags & DEBUG_PROCESS && pThreadDB != NULL)
    15581532      {
    1559         if(pThreadDB->pidDebuggee != 0)
     1533        if(pThreadDB->o.odin.pidDebuggee != 0)
    15601534        {
    15611535          // TODO: handle this
     
    15641538        else
    15651539        {
    1566           pThreadDB->pidDebuggee = lpProcessInfo->dwProcessId;
    1567           OSLibStartDebugger((ULONG*)&pThreadDB->pidDebuggee);
     1540          pThreadDB->o.odin.pidDebuggee = lpProcessInfo->dwProcessId;
     1541          OSLibStartDebugger((ULONG*)&pThreadDB->o.odin.pidDebuggee);
    15681542        }
    15691543      }
    1570       else pThreadDB->pidDebuggee = 0;
     1544      else pThreadDB->o.odin.pidDebuggee = 0;
    15711545
    15721546      return(TRUE);
     
    16481622      if (dwCreationFlags & DEBUG_PROCESS && pThreadDB != NULL)
    16491623      {
    1650         if(pThreadDB->pidDebuggee != 0)
     1624        if(pThreadDB->o.odin.pidDebuggee != 0)
    16511625        {
    16521626          // TODO: handle this
     
    16551629        else
    16561630        {
    1657           pThreadDB->pidDebuggee = lpProcessInfo->dwProcessId;
    1658           OSLibStartDebugger((ULONG*)&pThreadDB->pidDebuggee);
     1631          pThreadDB->o.odin.pidDebuggee = lpProcessInfo->dwProcessId;
     1632          OSLibStartDebugger((ULONG*)&pThreadDB->o.odin.pidDebuggee);
    16591633        }
    16601634      }
    16611635      else
    1662         pThreadDB->pidDebuggee = 0;
     1636        pThreadDB->o.odin.pidDebuggee = 0;
    16631637    }
    16641638    if(cmdline)
Note: See TracChangeset for help on using the changeset viewer.