uint32_t GameSystem::Run() { stop_running_ = false; updatedTime = g_timer.GetElapsedTime(); #ifdef __GNUC__ while (__builtin_expect(x, 0)) #else while (!stop_running_) #endif { if (reqStruct.change_state_ == true) { ProcessStateChange(); } window_.ClearBuffer(); //timer shit should be within the game state? or each world? const uint64_t current_time = g_timer.GetElapsedTime(); while (current_time - updatedTime > 33333) { state_machine_.current_state_->Update(33333); updatedTime += 33333; //33.333 milliseconds ie. 33333 microseconds } state_machine_.current_state_->Render(); window_.Display(); } stop_running_ = false; Shutdown(); return 0; }
// Called on the worker thread. nsresult BackgroundFileSaver::ProcessAttention() { nsresult rv; // This function is called whenever the attention of the worker thread has // been requested. This may happen in these cases: // * We are about to start the copy for the first time. In this case, we are // called from an event posted on the worker thread from the control thread // by GetWorkerThreadAttention, and mAsyncCopyContext is null. // * We have interrupted the copy for some reason. In this case, we are // called by AsyncCopyCallback, and mAsyncCopyContext is null. // * We are currently executing ProcessStateChange, and attention is requested // by the control thread, for example because SetTarget or Finish have been // called. In this case, we are called from from an event posted through // GetWorkerThreadAttention. While mAsyncCopyContext was always null when // the event was posted, at this point mAsyncCopyContext may not be null // anymore, because ProcessStateChange may have started the copy before the // event that called this function was processed on the worker thread. // If mAsyncCopyContext is not null, we interrupt the copy and re-enter // through AsyncCopyCallback. This allows us to check if, for instance, we // should rename the target file. We will then restart the copy if needed. if (mAsyncCopyContext) { NS_CancelAsyncCopy(mAsyncCopyContext, NS_ERROR_ABORT); return NS_OK; } // Use the current shared state to determine the next operation to execute. rv = ProcessStateChange(); if (NS_FAILED(rv)) { // If something failed while processing, terminate the operation now. { MutexAutoLock lock(mLock); if (NS_SUCCEEDED(mStatus)) { mStatus = rv; } } // Ensure we notify completion now that the operation failed. CheckCompletion(); } return NS_OK; }
void _CRTAPI1 main ( int Argc, PUCHAR *Argv ) { NTSTATUS st; PUCHAR pszExceptCode; PUCHAR Switch; int Index; DBGKD_CONTROL_SET ControlSet; extern PUCHAR Version_String; BOOLEAN Connected; ULONG SymOptions = SYMOPT_CASE_INSENSITIVE | SYMOPT_UNDNAME | SYMOPT_NO_CPP; #if !defined (_X86_) ControlSet = 0L; // All but X86 define this as a DWORD/ULONG for now #endif DebuggerName = "KD"; ConsoleInputHandle = GetStdHandle( STD_INPUT_HANDLE ); ConsoleOutputHandle = GetStdHandle( STD_ERROR_HANDLE ); dprintf(Version_String); pageSize = 512; // general value for kernel debugger ProcessKernel.pProcessNext = NULL; ProcessKernel.pImageHead = NULL; ProcessKernel.hProcess = KD_SYM_HANDLE; #if defined(i386) InitSelCache(); #endif if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL)) { fprintf(stderr, "Set Priority of main thread failed ... Continue.\n"); } SwitchProcessor = NtsdCurrentProcessor = DefaultProcessor = 0; NtsdCurrentProcessor = DefaultProcessor = 0; if (Argc != 1) { // // Process -h, -v, -m, -r, -b, -x, -n, and -l switches. These switches // common across x86 and ARC systems. // for (Index = 1; Index < Argc; Index++ ) { Switch = Argv[Index]; if (*Switch == '-') { if (*(Switch+1) == '?') { OutCommandHelp(); } else if (_stricmp(Switch+1, "myob") == 0) { MYOB = TRUE; } else if (*(Switch+1) == 'm' || *(Switch+1) == 'M') { KdModemControl = TRUE; } else if (*(Switch+1) == 'c' || *(Switch+1) == 'C') { SendInitialConnect = TRUE; } else if (*(Switch+1) == 'v' || *(Switch+1) == 'V') { KdVerbose = TRUE; } else if (*(Switch+1) == 'z' || *(Switch+1) == 'Z') { Index += 1; if (Index < Argc) { CrashFileName = Argv[Index]; } } else if (*(Switch+1) == 'y' || *(Switch+1) == 'Y') { Index += 1; if (Index < Argc) { char *s = malloc(strlen(Argv[Index])+MAX_PATH); if ( s ) { strcpy(s,Argv[Index]); free(SymbolSearchPath); SymbolSearchPath = s; } } } else if (*(Switch+1) == 'r' || *(Switch+1) == 'R') { fOutputRegs = (BOOLEAN)!fOutputRegs; } else if (*(Switch+1) == 'b' || *(Switch+1) == 'B') { InitialBreak = TRUE; } else if (*(Switch+1) == 'x' || *(Switch+1) == 'X') { InitialBreak = TRUE; InitialCommand = "eb nt!NtGlobalFlag 9;g"; } else if (*(Switch+1) == 's' || *(Switch+1) == 'S') { fLazyLoad = FALSE; BaseOfKernel = 0L; } else { break; } } else { break; } } } if (fLazyLoad) { SymOptions |= SYMOPT_DEFERRED_LOADS; } SymSetOptions( SymOptions ); sym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); sym->MaxNameLength = MAX_SYMNAME_SIZE; symStart->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); symStart->MaxNameLength = MAX_SYMNAME_SIZE; SymInitialize( pProcessCurrent->hProcess, NULL, FALSE ); SymRegisterCallback( pProcessCurrent->hProcess, SymbolCallbackFunction, NULL ); SetSymbolSearchPath(TRUE); // // Check environment variables for configuration settings // if (getenv("KDQUIET")) { NotStupid = TRUE; } LogFileName = getenv("_NT_DEBUG_CACHE_SIZE"); if (LogFileName) { KdMaxCacheSize = atol(LogFileName); } // // Check environment variables to determine if any logfile needs to be // opened. // LogFileName = getenv("_NT_DEBUG_LOG_FILE_APPEND"); if (LogFileName) { loghandle = _open(LogFileName, O_APPEND | O_CREAT | O_RDWR, S_IREAD | S_IWRITE); fLogAppend = TRUE; if (loghandle == -1) { fprintf(stderr, "log file could not be opened\n"); } } else { LogFileName = getenv("_NT_DEBUG_LOG_FILE_OPEN"); if (LogFileName) { loghandle = _open(LogFileName, O_APPEND | O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); if (loghandle == -1) { fprintf(stderr, "log file could not be opened\n"); } } } if (restart = (BOOLEAN)setjmp(reboot)) { dprintf("%s: Shutdown occurred...unloading all symbol tables.\n", DebuggerName); DelImages(); InitialBreak = RememberInitialBreak; #if defined(i386) || defined(ALPHA) || defined(_PPC_) contextState = CONTEXTFIR; #endif if (!CrashFileName) { dprintf("%s: waiting to reconnect...\n", DebuggerName); } } else { if (!CrashFileName) { dprintf("%s: waiting to reconnect...\n", DebuggerName); } } if (CrashFileName) { if( CreatePipe( &PipeRead, &PipeWrite, NULL, (1024-32)) == FALSE ) { fprintf(stderr, "Failed to create anonymous pipe in KdpStartThreads\n"); fprintf(stderr, "Error code %lx\n", GetLastError()); exit(1); } if (!DmpInitialize( CrashFileName, &CrashContext, &CrashException, &DmpHeader )) { dprintf( "kd: could not initialize dump file [%s]\n", CrashFileName ); exit(1); } dprintf( "kd: crash dump initialized [%s]\n", CrashFileName ); Connected = FALSE; InitNtCmd(); } else { Connected = FALSE; InitNtCmd(); st = DbgKdConnectAndInitialize(0L, NULL, (PUSHORT)&loghandle); if (!NT_SUCCESS(st)) { dprintf("kd: DbgKdConnectAndInitialize failed: %08lx\n", st); exit(1); } } SetConsoleCtrlHandler(waitHandler, TRUE); // add the waitHandler... if ((RememberInitialBreak = InitialBreak) && (!CrashFileName)) { DbgKdSendBreakIn(); } if (setjmp(main_return) != 0) { ; } // // We have to reset command state if the control is transfered by // long jmp. // cmdState = 'i'; if (CrashFileName) { LIST_ENTRY List; PLDR_DATA_TABLE_ENTRY DataTable; LDR_DATA_TABLE_ENTRY DataTableBuffer; BOOLEAN vsave; // // initialize the statechange object // STATECHANGE.NewState = DbgKdExceptionStateChange; STATECHANGE.ProcessorLevel = (USHORT)0; // We don't really care STATECHANGE.Processor = 0; STATECHANGE.NumberProcessors = DmpHeader->NumberProcessors; STATECHANGE.Thread = NULL; STATECHANGE.ProgramCounter = (PVOID)REGPC(CrashContext); ZeroMemory( &STATECHANGE.ControlReport, sizeof(DBGKD_CONTROL_REPORT) ); STATECHANGE.ControlReport.InstructionCount = 0; memcpy( &STATECHANGE.Context, CrashContext, sizeof(CONTEXT) ); memcpy( &STATECHANGE.u.Exception.ExceptionRecord, &CrashException, sizeof(EXCEPTION_RECORD) ); STATECHANGE.u.Exception.FirstChance = 0; #if defined(i386) STATECHANGE.ControlReport.ReportFlags |= REPORT_INCLUDES_SEGS; STATECHANGE.ControlReport.Dr6 = CrashContext->Dr6; STATECHANGE.ControlReport.Dr7 = CrashContext->Dr7; STATECHANGE.ControlReport.SegCs = (USHORT)CrashContext->SegCs; STATECHANGE.ControlReport.SegDs = (USHORT)CrashContext->SegDs; STATECHANGE.ControlReport.SegEs = (USHORT)CrashContext->SegEs; STATECHANGE.ControlReport.SegFs = (USHORT)CrashContext->SegFs; STATECHANGE.ControlReport.EFlags = CrashContext->EFlags; #endif // // setup some expected globals // NtsdCurrentProcessor = STATECHANGE.Processor; NumberProcessors = STATECHANGE.NumberProcessors; NtsdCurrentEThread = STATECHANGE.Thread; // // generate a modload for the kernel // strcpy( Buffer, KERNEL_IMAGE_NAME ); if (!DmpReadMemory( (PVOID)DmpHeader->PsLoadedModuleList, (PVOID)&List, sizeof(LIST_ENTRY))) { dprintf( "could not read the psloadedmodulelist\n" ); exit(1); } DataTable = CONTAINING_RECORD( List.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks ); if (!DmpReadMemory( (PVOID)DataTable, (PVOID)&DataTableBuffer, sizeof(LDR_DATA_TABLE_ENTRY))) { dprintf( "could not read the psloadedmodulelist\n" ); exit(1); } // // setup the version packet // vs.MajorVersion = (USHORT)DmpHeader->MajorVersion; vs.MinorVersion = (USHORT)DmpHeader->MinorVersion; vs.KernBase = (ULONG)DataTableBuffer.DllBase; vs.PsLoadedModuleList = (DWORD)DmpHeader->PsLoadedModuleList; AddImage( Buffer, DataTableBuffer.DllBase, DataTableBuffer.SizeOfImage, DataTableBuffer.CheckSum, 0, NULL, FALSE ); // // read the contents of the KiProcessorBlock // #if 0 //#if defined(ALPHA) if (!GetOffsetFromSym("KiPcrBaseAddress", &KiPcrBaseAddress, 0)) { dprintf( "could not get the KiProcessorBlock address\n" ); exit(1); } #endif if (!GetOffsetFromSym("KiProcessorBlock", &KiProcessorBlockAddr, 0)) { dprintf( "could not get the KiProcessorBlock address\n" ); exit(1); } DmpReadMemory( (PVOID)KiProcessorBlockAddr, &KiProcessors, sizeof(KiProcessors) ); STATECHANGE.Processor = DmpGetCurrentProcessor(); if (STATECHANGE.Processor == (USHORT)-1) { dprintf( "cound not determine the current processor, using zero\n" ); STATECHANGE.Processor = 0; } // // print some status information // dprintf( "Kernel Version %d", DmpHeader->MinorVersion ); if (DmpHeader->MajorVersion == 0xC) { dprintf( " Checked" ); } else if (DmpHeader->MajorVersion == 0xF) { dprintf( " Free" ); } dprintf( " loaded @ 0x%08x\n", DataTableBuffer.DllBase ); if (DmpHeader->NumberProcessors > 1) { dprintf( "Processor count = %d\n", DmpHeader->NumberProcessors ); } dprintf( "Bugcheck %08x : %08x %08x %08x %08x\n", DmpHeader->BugCheckCode, DmpHeader->BugCheckParameter1, DmpHeader->BugCheckParameter2, DmpHeader->BugCheckParameter3, DmpHeader->BugCheckParameter4 ); if (DmpHeader->BugCheckCode == 0x69696969) { dprintf( "****-> this system was crashed manually with crash.exe\n" ); } // // reload all symbols // dprintf( "re-loading all kernel symbols\n" ); vsave = fVerboseOutput; fVerboseOutput = TRUE; bangReload(""); fVerboseOutput = vsave; dprintf( "finished re-loading all kernel symbols\n" ); // // process the state change, commands, etc // Buffer[0] = 0; ProcessStateChange( EXCEPTIONPC, &EXCEPTIONREPORT,(PCHAR)Buffer ); SymCleanup( pProcessCurrent->hProcess ); // // end the debugger // return; } while (TRUE) { st = DbgKdWaitStateChange(&STATECHANGE, Buffer, sizeof(Buffer) - 2); if (!Connected) { Connected = TRUE; dprintf("%s: Kernel Debugger connection established.%s\n", DebuggerName, RememberInitialBreak ? " (Initial Breakpoint requested)" : "" ); VerifyKernelBase (TRUE, TRUE, TRUE); } if (!NT_SUCCESS(st)) { dprintf("kd: DbgKdWaitStateChange failed: %08lx\n", st); exit(1); } NtsdCurrentProcessor = STATECHANGE.Processor; NumberProcessors = STATECHANGE.NumberProcessors; NtsdCurrentEThread = STATECHANGE.Thread; if (STATECHANGE.NewState == DbgKdExceptionStateChange) { if (EXCEPTION_CODE == STATUS_BREAKPOINT || EXCEPTION_CODE == STATUS_SINGLE_STEP ) pszExceptCode = NULL; else if (EXCEPTION_CODE == STATUS_DATATYPE_MISALIGNMENT) pszExceptCode = "Data Misaligned"; else if (EXCEPTION_CODE == STATUS_INVALID_SYSTEM_SERVICE) pszExceptCode = "Invalid System Call"; else if (EXCEPTION_CODE == STATUS_ILLEGAL_INSTRUCTION) pszExceptCode = "Illegal Instruction"; else if (EXCEPTION_CODE == STATUS_INTEGER_OVERFLOW) pszExceptCode = "Integer Overflow"; else if (EXCEPTION_CODE == STATUS_INVALID_LOCK_SEQUENCE) pszExceptCode = "Invalid Lock Sequence"; else if (EXCEPTION_CODE == STATUS_ACCESS_VIOLATION) pszExceptCode = "Access Violation"; else if (EXCEPTION_CODE == STATUS_WAKE_SYSTEM_DEBUGGER) pszExceptCode = "Wake KD"; else pszExceptCode = "Unknown Exception"; if (!pszExceptCode) { WatchCount++; ProcessStateChange(EXCEPTIONPC, &EXCEPTIONREPORT,(PCHAR)Buffer); st = DBG_EXCEPTION_HANDLED; } else { cmdState = 'i'; dprintf("%s - code: %08lx (%s chance)", pszExceptCode, EXCEPTION_CODE, FIRST_CHANCE? "first" : "second" ); ProcessStateChange(EXCEPTIONPC, &EXCEPTIONREPORT,(PCHAR)Buffer); st = GetContinueStatus(FIRST_CHANCE, FALSE); } #ifdef i386 ControlSet.TraceFlag = GetTraceFlag(); ControlSet.Dr7 = GetDregValue(7); if (!Watching && BeginCurFunc != 1) { ControlSet.CurrentSymbolStart = 0; ControlSet.CurrentSymbolEnd = 0; } else { ControlSet.CurrentSymbolStart = BeginCurFunc; ControlSet.CurrentSymbolEnd = EndCurFunc; } #endif } else if (STATECHANGE.NewState == DbgKdLoadSymbolsStateChange) { if (STATECHANGE.u.LoadSymbols.UnloadSymbols) { if (STATECHANGE.u.LoadSymbols.PathNameLength == 0 && STATECHANGE.u.LoadSymbols.BaseOfDll == (PVOID)-1 && STATECHANGE.u.LoadSymbols.ProcessId == 0 ) { DbgKdContinue(DBG_CONTINUE); longjmp(reboot, 1); // ...and wait for event } DelImage(Buffer, STATECHANGE.u.LoadSymbols.BaseOfDll, STATECHANGE.u.LoadSymbols.ProcessId); } else { PIMAGE_INFO pImage = pProcessCurrent->pImageHead; CHAR fname[_MAX_FNAME]; CHAR ext[_MAX_EXT]; CHAR ImageName[256]; CHAR ModName[256]; LPSTR p; ModName[0] = '\0'; _splitpath( Buffer, NULL, NULL, fname, ext ); sprintf( ImageName, "%s%s", fname, ext ); if (_stricmp(ext,".sys")==0) { while (pImage) { if (_stricmp(ImageName,pImage->szImagePath)==0) { ModName[0] = 'c'; strcpy( &ModName[1], ImageName ); p = strchr( ModName, '.' ); if (p) { *p = '\0'; } ModName[8] = '\0'; break; } pImage = pImage->pImageNext; } } AddImage( ImageName, STATECHANGE.u.LoadSymbols.BaseOfDll, STATECHANGE.u.LoadSymbols.SizeOfImage, STATECHANGE.u.LoadSymbols.CheckSum, STATECHANGE.u.LoadSymbols.ProcessId, ModName[0] ? ModName : NULL, FALSE ); //////////////////////////////////////////////////////////// if (fLoadDllBreak) { ProcessStateChange(EXCEPTIONPC, &EXCEPTIONREPORT,(PCHAR)Buffer); } } #ifdef i386 ControlSet.TraceFlag = FALSE; ControlSet.Dr7 = EXCEPTIONDR7; if (!Watching && BeginCurFunc != 1) { ControlSet.CurrentSymbolStart = 0; ControlSet.CurrentSymbolEnd = 0; } else { ControlSet.CurrentSymbolStart = BeginCurFunc; ControlSet.CurrentSymbolEnd = EndCurFunc; } #endif st = DBG_CONTINUE; } else { // // BUGBUG - invalid NewState in state change record. // #ifdef i386 ControlSet.TraceFlag = FALSE; ControlSet.Dr7 = EXCEPTIONDR7; if (!Watching && BeginCurFunc != 1) { ControlSet.CurrentSymbolStart = 0; ControlSet.CurrentSymbolEnd = 0; } else { ControlSet.CurrentSymbolStart = BeginCurFunc; ControlSet.CurrentSymbolEnd = EndCurFunc; } #endif st = DBG_CONTINUE; } if (SwitchProcessor) { DbgKdSwitchActiveProcessor (SwitchProcessor - 1); SwitchProcessor = 0; } else { st = DbgKdContinue2(st, ControlSet); if (!NT_SUCCESS(st)) { dprintf("kd: DbgKdContinue failed: %08lx\n", st); exit(1); } } } SymCleanup( KD_SYM_HANDLE ); }