VOID RtlAssert( IN PVOID FailedAssertion, IN PVOID FileName, IN ULONG LineNumber, IN PCHAR Message OPTIONAL ) { #if DBG || RTL_ASSERT_ALWAYS_ENABLED char Response[ 2 ]; CONTEXT Context; #ifndef BLDR_KERNEL_RUNTIME RtlCaptureContext( &Context ); #endif while (TRUE) { DbgPrint( "\n*** Assertion failed: %s%s\n*** Source File: %s, line %ld\n\n", Message ? Message : "", FailedAssertion, FileName, LineNumber ); DbgPrompt( "Break, Ignore, Terminate Process or Terminate Thread (bipt)? ", Response, sizeof( Response ) ); switch (Response[0]) { case 'B': case 'b': DbgPrint( "Execute '!cxr %p' to dump context\n", &Context); DbgBreakPoint(); break; case 'I': case 'i': return; case 'P': case 'p': ZwTerminateProcess( NtCurrentProcess(), STATUS_UNSUCCESSFUL ); break; case 'T': case 't': ZwTerminateThread( NtCurrentThread(), STATUS_UNSUCCESSFUL ); break; } } DbgBreakPoint(); ZwTerminateProcess( NtCurrentProcess(), STATUS_UNSUCCESSFUL ); #endif }
VOID NTAPI PspCatchCriticalBreak(IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName) { CHAR Action[2]; BOOLEAN Handled = FALSE; PAGED_CODE(); /* Check if a debugger is enabled */ if (KdDebuggerEnabled) { /* Print out the message */ DbgPrint(Message, ProcessOrThread, ImageName); do { /* If a debugger isn't present, don't prompt */ if (KdDebuggerNotPresent) break; /* A debuger is active, prompt for action */ DbgPrompt("Break, or Ignore (bi)?", Action, sizeof(Action)); switch (Action[0]) { /* Break */ case 'B': case 'b': /* Do a breakpoint */ DbgBreakPoint(); /* Ignore */ case 'I': case 'i': /* Handle it */ Handled = TRUE; /* Unrecognized */ default: break; } } while (!Handled); } /* Did we ultimately handle this? */ if (!Handled) { /* We didn't, bugcheck */ KeBugCheckEx(CRITICAL_OBJECT_TERMINATION, ((PKPROCESS)ProcessOrThread)->Header.Type, (ULONG_PTR)ProcessOrThread, (ULONG_PTR)ImageName, (ULONG_PTR)Message); } }
int _RosLogDebug ( ULONG Level ) { static PCSTR levelDescriptions[] = { "[%s]", // TRACE_LEVEL_NONE "critical error", // TRACE_LEVEL_CRITICAL "noncritical error", // TRACE_LEVEL_ERROR "warning", // TRACE_LEVEL_WARNING "information", // TRACE_LEVEL_INFORMATION "trace" // TRACE_LEVEL_VERBOSE }; // levelDescriptions volatile void* returnAddress = _ReturnAddress(); volatile PCSTR levelDescriptionSz = levelDescriptions[(Level < ARRAYSIZE(levelDescriptions)) ? Level : 0]; DbgPrintEx( DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "\n*** ROSDOD %s detected @%p.\n", levelDescriptionSz, returnAddress); if (!rosLogIsDebuggerPresent(false)) return 1; for (;;) { char response[2] = {0}; DbgPrompt( "Break to debug, Ignore, ignore All (bi)? ", response, sizeof(response)); if ((response[0] == 'B') || (response[0] == 'b')) { DbgBreakPoint(); break; } else if ((response[0] == 'I') || (response[0] == 'i')) { break; } // iff } // for (;;) return 1; } // _RosLogDebug (...)
/* * @implemented */ VOID NTAPI RtlAssert(IN PVOID FailedAssertion, IN PVOID FileName, IN ULONG LineNumber, IN PCHAR Message OPTIONAL) { CHAR Action[2]; CONTEXT Context; /* Capture caller's context for the debugger */ RtlCaptureContext(&Context); /* Enter prompt loop */ for (;;) { /* Print the assertion */ DbgPrint("\n*** Assertion failed: %s%s\n" "*** Source File: %s, line %lu\n\n", Message != NULL ? Message : "", (PSTR)FailedAssertion, (PSTR)FileName, LineNumber); /* Prompt for action */ DbgPrompt("Break repeatedly, break Once, Ignore," " terminate Process or terminate Thread (boipt)? ", Action, sizeof(Action)); switch (Action[0]) { /* Break repeatedly */ case 'B': case 'b': /* Do a breakpoint, then prompt again */ DbgPrint("Execute '.cxr %p' to dump context\n", &Context); DbgBreakPoint(); break; /* Ignore */ case 'I': case 'i': /* Return to caller */ return; /* Break once */ case 'O': case 'o': /* Do a breakpoint and return */ DbgPrint("Execute '.cxr %p' to dump context\n", &Context); DbgBreakPoint(); return; /* Terminate process*/ case 'P': case 'p': /* Terminate us */ ZwTerminateProcess(ZwCurrentProcess(), STATUS_UNSUCCESSFUL); break; /* Terminate thread */ case 'T': case 't': /* Terminate us */ ZwTerminateThread(ZwCurrentThread(), STATUS_UNSUCCESSFUL); break; /* Unrecognized */ default: /* Prompt again */ break; } } /* Shouldn't get here */ DbgBreakPoint(); ZwTerminateProcess(ZwCurrentProcess(), STATUS_UNSUCCESSFUL); }
VOID FormatSomeTracks ( CHAR DeviceId ) { HANDLE FileHandle; OBJECT_ATTRIBUTES ObjectAttributes; STRING NameString; UNICODE_STRING UnicodeString; IO_STATUS_BLOCK IoStatus; NTSTATUS Status; PCHAR DeviceName; FORMAT_PARAMETERS FormatParameters; BAD_TRACK_NUMBER BadTracks[80]; ULONG i; if (DeviceId == '1') { DeviceName = &DriveA[0]; } else if (DeviceId == '2') { DeviceName = &DriveB[0]; } else { DbgPrint( "Format: invalid drive id '%c'\n", DeviceId ); return; } GetMediaTypes( NULL ); Zero( &Buffer[0], 10 ); DbgPrompt( "Enter media type code: ", Buffer, 10 ); FormatParameters.MediaType = (MEDIA_TYPE) atoi( &Buffer[0] ); Zero( &Buffer[0], 10 ); DbgPrompt( "Enter start cylinder: ", Buffer, 10 ); FormatParameters.StartCylinderNumber = (ULONG) atoi( &Buffer[0] ); Zero( &Buffer[0], 10 ); DbgPrompt( "Enter end cylinder: ", Buffer, 10 ); FormatParameters.EndCylinderNumber = (ULONG) atoi( &Buffer[0] ); Zero( &Buffer[0], 10 ); DbgPrompt( "Enter start head: ", Buffer, 10 ); FormatParameters.StartHeadNumber = (ULONG) atoi( &Buffer[0] ); Zero( &Buffer[0], 10 ); DbgPrompt( "Enter end head: ", Buffer, 10 ); FormatParameters.EndHeadNumber = (ULONG) atoi( &Buffer[0] ); RtlInitString( &NameString, DeviceName ); Status = RtlAnsiStringToUnicodeString( &UnicodeString, &NameString, TRUE ); ASSERT( NT_SUCCESS( Status ) ); // // Open the device. // InitializeObjectAttributes( &ObjectAttributes, &UnicodeString, OBJ_CASE_INSENSITIVE, (HANDLE) NULL, (PSECURITY_DESCRIPTOR) NULL ); Status = NtOpenFile( &FileHandle, FILE_WRITE_DATA | FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE, &ObjectAttributes, &IoStatus, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT ); RtlFreeUnicodeString( &UnicodeString ); if (!NT_SUCCESS( Status )) { DbgPrint( "format: error opening %s for input; error %X\n", DeviceName, Status ); return; } DbgPrompt( "\nInsert diskette and press RETURN when ready ", Buffer, 256 ); // // Issue the format command. // Status = NtDeviceIoControlFile( FileHandle, (HANDLE) NULL, (PIO_APC_ROUTINE) NULL, (PVOID) NULL, &IoStatus, IOCTL_DISK_FORMAT_TRACKS, &FormatParameters, (ULONG) sizeof( FormatParameters ), &BadTracks[0], (ULONG) sizeof( BadTracks ) ); if (!NT_SUCCESS( Status )) { DbgPrint( "format: error on NtDeviceIoControlFile; error %X\n", Status ); } else if (Status != STATUS_SUCCESS) { Status = NtWaitForSingleObject( FileHandle, TRUE, NULL ); if (Status == STATUS_SUCCESS) { if (!NT_SUCCESS( IoStatus.Status )) { if (IoStatus.Status == STATUS_NOT_IMPLEMENTED) { DbgPrint( "format: control function not implemented\n" ); } if (IoStatus.Status == STATUS_MEDIA_WRITE_PROTECTED) { DbgPrint( "format: media is write protected\n" ); } else if (IoStatus.Status == STATUS_DEVICE_NOT_READY) { DbgPrint( "format: device not ready\n" ); } else { DbgPrint( "format: error %X\n", IoStatus.Status ); } } } } else { if (IoStatus.Information) { // // Found some bad tracks. // i = 0; DbgPrint( "Bad tracks: " ); while (IoStatus.Information >= sizeof( BAD_TRACK_NUMBER )) { DbgPrint( "%d ", BadTracks[i++] ); IoStatus.Information -= sizeof( BAD_TRACK_NUMBER ); } DbgPrint( " \n" ); } } // // Close the file. // (VOID) NtClose( FileHandle ); return; }
VOID TuneFifoDelay() { HANDLE FileHandle; OBJECT_ATTRIBUTES ObjectAttributes; STRING NameString; UNICODE_STRING UnicodeString; IO_STATUS_BLOCK IoStatus; NTSTATUS Status; PCHAR DeviceName; ULONG Delay; Zero( &Buffer[0], 10 ); DbgPrompt( "Enter number of cycles: ", Buffer, 9 ); Delay = (ULONG) atoi( &(Buffer[0]) ); DeviceName = &DriveA[0]; RtlInitString( &NameString, DeviceName ); Status = RtlAnsiStringToUnicodeString( &UnicodeString, &NameString, TRUE ); ASSERT( NT_SUCCESS( Status ) ); // // Open the device. // InitializeObjectAttributes( &ObjectAttributes, &UnicodeString, OBJ_CASE_INSENSITIVE, (HANDLE) NULL, (PSECURITY_DESCRIPTOR) NULL ); Status = NtOpenFile( &FileHandle, FILE_WRITE_DATA | FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE, &ObjectAttributes, &IoStatus, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT ); RtlFreeUnicodeString( &UnicodeString ); if (!NT_SUCCESS( Status )) { DbgPrint( "control: error opening %s for input; error %X\n", DeviceName, Status ); return; } // // Issue the I/O control command // Status = NtDeviceIoControlFile( FileHandle, (HANDLE) NULL, (PIO_APC_ROUTINE) NULL, (PVOID) NULL, &IoStatus, IOCTL_DISK_DBG_FIFO_TUNING, &Delay, (ULONG) sizeof( Delay ), NULL, 0L ); if (!NT_SUCCESS( Status )) { DbgPrint( "control: error on NtDeviceIoControlFile; error %X\n", Status ); } else if (Status != STATUS_SUCCESS) { Status = NtWaitForSingleObject( FileHandle, TRUE, NULL ); if (Status == STATUS_SUCCESS) { if (!NT_SUCCESS( IoStatus.Status )) { if (IoStatus.Status == STATUS_NOT_IMPLEMENTED) { DbgPrint( "control: control function not implemented\n" ); } else { DbgPrint( "control: error %X\n", IoStatus.Status ); } } } } // // Close the file. // (VOID) NtClose( FileHandle ); return; }
VOID main( // IN ULONG argc, // IN PCHAR argv[], // IN PCHAR envp[] ) /*++ Routine Description: This is the main routine of the floppy test. Arguments: None Return Value: None. --*/ { CHAR Device[256]; while (1) { DbgPrint( "Test program for the floppy driver.\n\n\n" ); DbgPrint( " 0 - Exit\n\n" ); DbgPrint( " 1 - Read statistics\n\n" ); DbgPrint( " 2 - Tune FIFO delay\n\n" ); DbgPrint( " 3 - Get supported media types\n\n" ); DbgPrint( " 4 - Format some tracks\n\n" ); DbgPrint( " 5 - Test power failure recovery\n\n" ); DbgPrint( " 6 - Unload driver\n\n" ); DbgPrompt( "Select: ", Buffer, 256 ); if (Buffer[0] == '0') { break; } switch(Buffer[0]) { case '1': GetStatistics(); break; case '2': TuneFifoDelay(); break; case '3': GetMediaTypes( NULL ); break; case '4': Device[0] = '\0'; DbgPrompt( "Enter device id (1 = \\A:, 2 = \\B:): ", &(Device[0]), 256); if (Device[0] != '\0') { FormatSomeTracks( Device[0] ); } break; case '5': PowerTest(); break; case '6': UnloadDriver(); break; default: break; } } }