Changeset 9910 for trunk/src/kernel32/thread.cpp
- Timestamp:
- Mar 6, 2003, 11:22:27 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/thread.cpp
r9748 r9910 1 /* $Id: thread.cpp,v 1.5 0 2003-02-04 11:29:03sandervl Exp $ */1 /* $Id: thread.cpp,v 1.51 2003-03-06 10:22:27 sandervl Exp $ */ 2 2 3 3 /* … … 35 35 #include <codepage.h> 36 36 37 #include <FastInfoBlocks.h> 38 37 39 #define DBG_LOCALLOG DBG_thread 38 40 #include "dbglocal.h" … … 48 50 // check cached identifier 49 51 TEB *teb = GetThreadTEB(); 50 if(teb != NULL && teb->o.odin.threadId != 0xFFFFFFFF) 52 if(teb != NULL && teb->o.odin.threadId != 0xFFFFFFFF) 51 53 { 52 54 // this is set in InitializeTIB() already. 53 55 return teb->o.odin.threadId; 54 56 } 55 57 56 58 //// dprintf(("GetCurrentThreadId\n")); 57 59 return MAKE_THREADID(O32_GetCurrentProcessId(), O32_GetCurrentThreadId()); … … 66 68 if(teb == 0) { 67 69 DebugInt3(); 68 SetLastError(ERROR_INVALID_HANDLE); //todo 70 SetLastError(ERROR_INVALID_HANDLE); //todo 69 71 return 0; 70 72 } … … 111 113 #ifdef DEBUG 112 114 TEB *teb; 113 115 114 116 // embedded dbg_IncThreadCallDepth 115 117 teb = GetThreadTEB(); 116 118 if(teb == NULL) 117 119 return; 118 120 119 121 // add caller name to call stack trace 120 122 int iIndex = teb->o.odin.dbgCallDepth; 121 123 122 124 // allocate callstack on demand 123 125 if (teb->o.odin.arrstrCallStack == NULL) 124 126 teb->o.odin.arrstrCallStack = (PVOID*)malloc( sizeof(LPSTR) * MAX_CALLSTACK_SIZE); 125 127 126 128 // insert entry 127 129 if (iIndex < MAX_CALLSTACK_SIZE) … … 151 153 #ifdef DEBUG 152 154 TEB *teb; 153 155 154 156 // embedded dbg_DecThreadCallDepth 155 157 teb = GetThreadTEB(); 156 158 if(teb == NULL) 157 159 return; 158 160 159 161 --(teb->o.odin.dbgCallDepth); 160 162 161 163 // add caller name to call stack trace 162 164 int iIndex = teb->o.odin.dbgCallDepth; 163 165 164 166 // insert entry 165 167 if (teb->o.odin.arrstrCallStack) … … 175 177 // retrieve last caller name from stack 176 178 TEB *teb; 177 179 178 180 // embedded dbg_DecThreadCallDepth 179 181 teb = GetThreadTEB(); … … 188 190 } 189 191 #endif 190 192 191 193 return NULL; 192 194 } … … 323 325 OS2SetExceptionHandler((void *)&exceptFrame); 324 326 winteb->o.odin.exceptFrame = (ULONG)&exceptFrame; 325 327 326 328 //Determine if thread callback is inside a PE dll; if true, then force 327 329 //switch to win32 TIB (FS selector) … … 367 369 //****************************************************************************** 368 370 //****************************************************************************** 371 372 /** 373 * Enter odin context with this thread. 374 * 375 * Is called when an OS/2 process is calling into an Odin32 DLL. 376 * This may be called also in a nested fashion and supports that. 377 * The conterpart of ODIN_ThreadLeaveOdinContext(). 378 * 379 * @returns The old FS selector. 380 * @returns 0 if TEB creation failed. 381 * @param pExceptionRegRec OS/2 Exception Registration Record (2 ULONGs) 382 * must be located on the callers stack. 383 * @param fForceFSSwitch If set we will force switching to Odin32 FS selector. 384 * If clear it depends on defaults. 385 */ 386 USHORT WIN32API ODIN_ThreadEnterOdinContext(void *pExceptionRegRec, BOOL fForceFSSwitch) 387 { 388 USHORT selFSOld = 0; 389 390 /* 391 * Get TEB pointer, create it if necessary. 392 * @todo Check if this really is the thread which the TEB was created 393 * for. If not create the TEB. 394 */ 395 TEB *pTeb = GetThreadTEB(); 396 if (!pTeb) 397 { 398 BOOL fMainThread = fibGetTid() == 1; 399 HANDLE hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, fMainThread); 400 pTeb = CreateTEB(hThreadMain, fibGetTid()); 401 if (!pTeb || InitializeThread(pTeb, fMainThread) == FALSE) 402 { 403 dprintf(("ODIN_ThreadEnterOdinContext: Failed to create TEB!")); 404 } 405 } 406 407 /* 408 * Install the Odin32 exception handler. 409 * Note: The Win32 exception structure referenced by FS:[0] is the same in OS/2 410 */ 411 if (pExceptionRegRec) 412 OS2SetExceptionHandler(pExceptionRegRec); 413 if ( pTeb 414 && !pTeb->o.odin.exceptFrame) /* if allready present, we'll keep the first one. */ 415 pTeb->o.odin.exceptFrame = (ULONG)pExceptionRegRec; 416 417 /* 418 * Switch Selector if TIB was created. 419 */ 420 if (pTeb) 421 selFSOld = SetWin32TIB(fForceFSSwitch ? TIB_SWITCH_FORCE_WIN32 : TIB_SWITCH_DEFAULT); 422 423 return selFSOld; 424 } 425 426 427 /** 428 * Leave odin context with this thread. 429 * 430 * Is called when an OS/2 process is returning from an Odin32 DLL. 431 * This may be called also in a nested fashion and supports that. 432 * The conterpart of ODIN_ThreadEnterOdinContext(). 433 * 434 * @returns The old FS selector. 435 * @returns 0 if TEB creation failed. 436 * @param pExceptionRegRec OS/2 Exception Registration Record (2 ULONGs) 437 * must be located on the callers stack. 438 * @param fForceFSSwitch If set we will force switching to Odin32 FS selector. 439 * If clear it depends on defaults. 440 */ 441 void WIN32API ODIN_ThreadLeaveOdinContext(void *pExceptionRegRec, USHORT selFSOld) 442 { 443 /* 444 * Install the Odin32 exception handler. 445 * Note: The Win32 exception structure referenced by FS:[0] is the same in OS/2 446 */ 447 if (pExceptionRegRec) 448 OS2UnsetExceptionHandler(pExceptionRegRec); 449 TEB *pTeb = GetThreadTEB(); 450 if ( pTeb 451 && pTeb->o.odin.exceptFrame == (ULONG)pExceptionRegRec) 452 pTeb->o.odin.exceptFrame = 0; 453 454 /* 455 * Switch Back FS Selector. 456 */ 457 if (selFSOld) 458 SetFS(selFSOld); 459 } 460 461 462 /** 463 * Leave odin context to call back into OS/2 code. 464 * 465 * Is called when and Odin32 Dll/Exe calls back into the OS/2 code. 466 * The conterpart of ODIN_ThreadEnterOdinContextNested(). 467 * 468 * @returns The old FS selector. 469 * @returns 0 on failure. 470 * @param pExceptionRegRec New OS/2 exception handler frame which are to be registered 471 * before the Odin handler in the chain. 472 * Must be located on the callers stack. 473 * @param fRemoveOdinExcpt Remove the odin exception handler. 474 */ 475 USHORT WIN32API ODIN_ThreadLeaveOdinContextNested(void *pExceptionRegRec, BOOL fRemoveOdinExcpt) 476 { 477 /* 478 * Set OS/2 FS Selector. 479 */ 480 USHORT selFSOld = RestoreOS2FS(); 481 482 /* 483 * Remove the Odin exception handler (if requested). 484 */ 485 if (fRemoveOdinExcpt) 486 { 487 TEB *pTeb = GetThreadTEB(); 488 if (pTeb) 489 OS2UnsetExceptionHandler((void*)pTeb->o.odin.exceptFrame); 490 /* else: no TEB created propbably no exception handler to remove. */ 491 } 492 493 /* 494 * Change exception handler if required. 495 */ 496 if (pExceptionRegRec) 497 { 498 extern unsigned long _System DosSetExceptionHandler(void *); 499 DosSetExceptionHandler(pExceptionRegRec); 500 } 501 502 return selFSOld; 503 } 504 505 506 /** 507 * Re-enter Odin context after being back in OS/2 code. 508 * 509 * Is called when returning to Odin from OS/2 code. 510 * The conterpart of ODIN_ThreadLeaveOdinContextNested(). 511 * 512 * @param pExceptionRegRec The exception registration record for the OS/2 513 * exception handler used with Nested Leave. NULL 514 * if not used. 515 * @param fRestoreOdinExcpt Restore the Odin exception handler. 516 * This flag must not be set unless fRemoveOdinExcpt 517 * was set when leaving the Odin context! 518 * @param selFSOld The Odin FS selector returned by the Nested Leave api. 519 * 520 */ 521 void WIN32API ODIN_ThreadEnterOdinContextNested(void *pExceptionRegRec, BOOL fRestoreOdinExcpt, USHORT selFSOld) 522 { 523 /* 524 * Remove the exception handler registered in ODIN_ThreadLeaveOdinContextNested 525 */ 526 if (pExceptionRegRec) 527 OS2UnsetExceptionHandler(pExceptionRegRec); 528 529 /* 530 * Restore Odin exception handler (if requested). 531 */ 532 if (fRestoreOdinExcpt) 533 { 534 TEB *pTeb = GetThreadTEB(); 535 if (pTeb) 536 OS2SetExceptionHandler((void*)pTeb->o.odin.exceptFrame); 537 } 538 539 /* 540 * Switch Back FS Selector. 541 */ 542 if (selFSOld) 543 SetFS(selFSOld); 544 } 545 546
Note:
See TracChangeset
for help on using the changeset viewer.