- Timestamp:
- Mar 6, 2003, 11:22:27 AM (22 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/critsection.cpp
r7854 r9910 1 /* $Id: critsection.cpp,v 1. 8 2002-02-09 17:27:30sandervl Exp $ */1 /* $Id: critsection.cpp,v 1.9 2003-03-06 10:22:26 sandervl Exp $ */ 2 2 /* 3 3 * Win32 critical sections … … 14 14 #include <assert.h> 15 15 #include <stdio.h> 16 #include "debugtools.h"17 #include < misc.h>16 #include <dbglog.h> 17 #include <debugtools.h> 18 18 #include <odinwrap.h> 19 #include <wprocess.h> 19 20 20 21 #define DBG_LOCALLOG DBG_critsection … … 22 23 23 24 DECLARE_DEBUG_CHANNEL(relay) 25 24 26 25 27 … … 34 36 crit->OwningThread = 0; 35 37 crit->LockSemaphore = CreateSemaphoreA( NULL, 0, 1, NULL ); 36 crit->Reserved = GetCurrentProcessId();38 crit->Reserved = ODIN_GetCurrentProcessId(); 37 39 } 38 40 … … 75 77 if (InterlockedIncrement( &crit->LockCount )) 76 78 { 77 if (crit->OwningThread == GetCurrentThreadId())79 if (crit->OwningThread == ODIN_GetCurrentThreadId()) 78 80 { 79 81 crit->RecursionCount++; … … 112 114 } 113 115 } 114 crit->OwningThread = GetCurrentThreadId();116 crit->OwningThread = ODIN_GetCurrentThreadId(); 115 117 crit->RecursionCount = 1; 116 118 } … … 125 127 if (InterlockedIncrement( &crit->LockCount )) 126 128 { 127 if (crit->OwningThread == GetCurrentThreadId())129 if (crit->OwningThread == ODIN_GetCurrentThreadId()) 128 130 { 129 131 crit->RecursionCount++; … … 134 136 return FALSE; 135 137 } 136 crit->OwningThread = GetCurrentThreadId();138 crit->OwningThread = ODIN_GetCurrentThreadId(); 137 139 crit->RecursionCount = 1; 138 140 return TRUE; … … 146 148 { 147 149 dprintf2(("LeaveCriticalSection %x", crit)); 148 if (crit->OwningThread != GetCurrentThreadId()) return;150 if (crit->OwningThread != ODIN_GetCurrentThreadId()) return; 149 151 150 152 if (--crit->RecursionCount) … … 183 185 InitializeCriticalSection( crit ); 184 186 185 else if ( crit->Reserved && crit->Reserved != GetCurrentProcessId() )187 else if ( crit->Reserved && crit->Reserved != ODIN_GetCurrentProcessId() ) 186 188 { 187 189 dprintf(("(%p) called for %08lx first, %08lx now: making global\n", 188 crit, crit->Reserved, GetCurrentProcessId() ));190 crit, crit->Reserved, ODIN_GetCurrentProcessId() )); 189 191 190 192 MakeCriticalSectionGlobal( crit ); … … 205 207 else 206 208 dprintf(("(%p) for %08lx: Crst is global, don't know whether to delete\n", 207 crit, GetCurrentProcessId() ));208 } 209 } 210 209 crit, ODIN_GetCurrentProcessId() )); 210 } 211 } 212 -
trunk/src/kernel32/dbglog.cpp
r9806 r9910 1 /* $Id: dbglog.cpp,v 1. 7 2003-02-14 13:24:48sandervl Exp $ */1 /* $Id: dbglog.cpp,v 1.8 2003-03-06 10:22:26 sandervl Exp $ */ 2 2 3 3 /* … … 309 309 #ifdef WIN32_IP_LOGGING 310 310 char *logserver = getenv("WIN32LOG_IPSERVER"); 311 if(logserver ) {311 if(logserver && loadNr == 0) { 312 312 sock_init(); 313 313 … … 320 320 } 321 321 #endif 322 char logname[CCHMAXPATH]; 323 324 sprintf(logname, "odin32_%d.log", loadNr); 325 flog = fopen(logname, "w"); 326 if(flog == NULL) {//probably running exe on readonly device 327 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr); 328 flog = fopen(logname, "w"); 322 char szLogFile[CCHMAXPATH]; 323 const char *pszLogBase = getenv("WIN32LOG_FILEBASE"); 324 if (!pszLogBase) 325 pszLogBase = "odin32_"; 326 327 sprintf(szLogFile, "%s%d.log", pszLogBase, loadNr); 328 flog = fopen(szLogFile, "w"); 329 if(flog == NULL) 330 {//probably running exe on readonly device 331 sprintf(szLogFile, "%sodin32_%d.log", kernel32Path, loadNr); 332 flog = fopen(szLogFile, "w"); 329 333 } 330 334 oldcrtmsghandle = _set_crt_msg_handle(fileno(flog)); … … 333 337 fLogging = FALSE; 334 338 335 if(getenv("DISABLE_THREAD1")) { 336 fDisableThread[0] = TRUE; 337 } 338 if(getenv("DISABLE_THREAD2")) { 339 fDisableThread[1] = TRUE; 340 } 341 if(getenv("DISABLE_THREAD3")) { 342 fDisableThread[2] = TRUE; 343 } 344 if(getenv("DISABLE_THREAD4")) { 345 fDisableThread[3] = TRUE; 346 } 347 if(getenv("DISABLE_THREAD5")) { 348 fDisableThread[4] = TRUE; 349 } 339 fDisableThread[0] = getenv("DISABLE_THREAD1") != NULL; 340 fDisableThread[1] = getenv("DISABLE_THREAD2") != NULL; 341 fDisableThread[2] = getenv("DISABLE_THREAD3") != NULL; 342 fDisableThread[3] = getenv("DISABLE_THREAD4") != NULL; 343 fDisableThread[4] = getenv("DISABLE_THREAD5") != NULL; 350 344 } 351 345 … … 443 437 ulCallDepth = 0; 444 438 #endif 439 #ifdef LOG_TIME 440 if(sel == 0x150b && fSwitchTIBSel) 441 sprintf(logbuffer, "t%02d (%3d): %x (FS=150B) ", 442 LOWORD(teb->o.odin.threadId), ulCallDepth, GetTickCount()); 443 else 444 sprintf(logbuffer, "t%02d (%3d): %x ", 445 LOWORD(teb->o.odin.threadId), ulCallDepth, GetTickCount()); 446 #else 445 447 if(sel == 0x150b && fSwitchTIBSel) 446 448 sprintf(logbuffer, "t%02d (%3d): (FS=150B) ", … … 449 451 sprintf(logbuffer, "t%02d (%3d): ", 450 452 LOWORD(teb->o.odin.threadId), ulCallDepth); 453 #endif 451 454 prefixlen = strlen(logbuffer); 452 455 } -
trunk/src/kernel32/exceptions.cpp
r9893 r9910 1 /* $Id: exceptions.cpp,v 1.7 1 2003-03-03 16:41:03sandervl Exp $ */1 /* $Id: exceptions.cpp,v 1.72 2003-03-06 10:22:26 sandervl Exp $ */ 2 2 3 3 /* … … 610 610 szModName, iObj, offObj); 611 611 } 612 612 613 613 /* This is very dangerous. Can hang PM. 614 614 rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, message, "Application Error", … … 715 715 char szLineException[128]; 716 716 char szLineExceptionType[128]; 717 717 718 718 szLineException[0] = 0; /* initialize */ 719 719 szLineExceptionType[0] = 0; /* initialize */ … … 813 813 case XCPT_DATATYPE_MISALIGNMENT: 814 814 strcpy(szLineException, "Datatype Misalignment"); 815 sprintf(szLineExceptionType, "R/W %08x alignment %08x at %08x.", pERepRec->ExceptionInfo[0], 815 sprintf(szLineExceptionType, "R/W %08x alignment %08x at %08x.", pERepRec->ExceptionInfo[0], 816 816 pERepRec->ExceptionInfo[1], pERepRec->ExceptionInfo[2]); 817 817 break; … … 914 914 } 915 915 916 sprintf(szTrapDump, "---[Exception Information]------------\n %s", szLineException); 917 918 strcat(szTrapDump, " ("); 916 sprintf(szTrapDump, "---[Exception Information]------------\n %s (", szLineException); 919 917 920 918 if (fExcptSoftware == TRUE) /* software or hardware generated ? */ … … 935 933 strcat(szTrapDump, ")\n"); /* add trailing brace */ 936 934 935 if (szLineExceptionType[0]) 936 sprintf(szTrapDump + strlen(szTrapDump), " %s\n", szLineExceptionType); 937 937 938 938 rc = DosQueryModFromEIP(&ulModule, &ulObject, sizeof(szModule), … … 947 947 strcat(szTrapDump, szLineException); 948 948 } 949 else 949 else 950 950 { /* fault in DosAllocMem allocated memory, hence PE loader.. */ 951 951 Win32ImageBase * pMod; … … 1007 1007 1008 1008 sprintf(szLineException, " Env[0]=%08x Env[1]=%08x Env[2]=%08x Env[3]=%08x\n", 1009 pCtxRec->ctx_env[0], pCtxRec->ctx_env[1], 1009 pCtxRec->ctx_env[0], pCtxRec->ctx_env[1], 1010 1010 pCtxRec->ctx_env[2], pCtxRec->ctx_env[3]); 1011 1011 strcat(szTrapDump, szLineException); … … 1053 1053 //Override filename of exception log (expects full path) 1054 1054 //***************************************************************************** 1055 void WIN32API SetCustomExceptionLog(LPSTR lpszLogName) 1055 void WIN32API SetCustomExceptionLog(LPSTR lpszLogName) 1056 1056 { 1057 1057 strcpy(szExceptionLogFileName, lpszLogName); … … 1059 1059 //***************************************************************************** 1060 1060 //***************************************************************************** 1061 void WIN32API SetExceptionLogging(BOOL fEnable) 1061 void WIN32API SetExceptionLogging(BOOL fEnable) 1062 1062 { 1063 1063 fExceptionLoggging = fEnable; … … 1088 1088 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 1089 1089 0L); /* No extended attribute */ 1090 1090 1091 1091 if(rc == NO_ERROR) { 1092 1092 DosSetFilePtr(hFile, 0, FILE_END, &ulBytesWritten); … … 1095 1095 1096 1096 lpszExeName = WinExe->getModuleName(); 1097 1097 1098 1098 if(lpszExeName) { 1099 1099 DosWrite(hFile, "\n", 2, &ulBytesWritten); … … 1340 1340 1341 1341 dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n")); 1342 1342 1343 1343 pCtxRec->ctx_RegEip = (ULONG)KillWin32Process; 1344 1344 pCtxRec->ctx_RegEsp = pCtxRec->ctx_RegEsp + 0x10; … … 1351 1351 { 1352 1352 //NOTE:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1353 //Don't print anything here -> fatal hang if exception occurred 1353 //Don't print anything here -> fatal hang if exception occurred 1354 1354 //inside fprintf 1355 1355 //NOTE:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1356 1356 1357 Win32MemMap *map; 1358 BOOL fWriteAccess = FALSE, ret; 1359 ULONG offset, accessflag; 1360 1361 switch(pERepRec->ExceptionInfo[0]) { 1362 case XCPT_READ_ACCESS: 1363 accessflag = MEMMAP_ACCESS_READ; 1364 break; 1365 case XCPT_WRITE_ACCESS: 1366 accessflag = MEMMAP_ACCESS_WRITE; 1367 fWriteAccess = TRUE; 1368 break; 1369 default: 1370 goto continueGuardException; 1371 } 1372 1373 map = Win32MemMapView::findMapByView(pERepRec->ExceptionInfo[1], &offset, accessflag); 1374 if(map == NULL) { 1375 goto continueGuardException; 1376 } 1377 ret = map->commitGuardPage(pERepRec->ExceptionInfo[1], offset, fWriteAccess); 1378 map->Release(); 1379 if(ret == TRUE) 1380 goto continueexecution; 1381 1382 continueGuardException: 1357 1383 goto continuesearch; 1358 1384 } -
trunk/src/kernel32/kernel32.mak
r9895 r9910 1 # $Id: kernel32.mak,v 1.4 0 2003-03-03 16:49:54sandervl Exp $1 # $Id: kernel32.mak,v 1.41 2003-03-06 10:22:27 sandervl Exp $ 2 2 3 3 # … … 100 100 $(OBJDIR)\time.obj \ 101 101 $(OBJDIR)\mmap.obj \ 102 $(OBJDIR)\mmapview.obj \ 103 $(OBJDIR)\mmapdup.obj \ 102 104 $(OBJDIR)\winimagepe2lx.obj \ 103 105 $(OBJDIR)\winimagepeldr.obj \ … … 110 112 $(OBJDIR)\winexedummy.obj \ 111 113 $(OBJDIR)\critsection.obj \ 114 $(OBJDIR)\fastinfoblocksa.obj \ 115 $(OBJDIR)\fastinfoblocks.obj \ 112 116 $(OBJDIR)\pefile.obj \ 113 117 $(OBJDIR)\winimgres.obj \ -
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.