test: dbgctrl.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# dbgctrl.c File Reference

`#include "exp.h"`
`#include "kdp.h"`

Go to the source code of this file.

## Functions

NTSTATUS | NtSystemDebugControl (IN SYSDBG_COMMAND Command, IN PVOID InputBuffer, IN ULONG InputBufferLength, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength, OUT PULONG ReturnLength OPTIONAL)

## Function Documentation

NTSTATUS NtSystemDebugControl | ( | IN SYSDBG_COMMAND | Command,
|  | IN PVOID | InputBuffer,
|  | IN ULONG | InputBufferLength,
|  | OUT PVOID | OutputBuffer,
|  | IN ULONG | OutputBufferLength,
|  | OUT PULONG ReturnLength | OPTIONAL
| ) |

Definition at line 36 of file dbgctrl.c.

References EXCEPTION_EXECUTE_HANDLER, ExReleaseResource, FALSE, KdClearSpecialCalls(), KdDebuggerEnabled, KdQuerySpecialCalls(), KdSetSpecialCall(), KeLeaveCriticalRegion, KernelMode, KPROCESSOR_MODE, NTSTATUS(), NULL, ProbeForRead, ProbeForWrite(), ProbeForWriteUlong, PsLoadedModuleResource, SeDebugPrivilege, and SeSinglePrivilegeCheck().

    00047                    :
    00048
    00049     This function controls the system debugger.
    00050
    00051 Arguments:
    00052
    00053     Command - The command to be executed.  One of the following:
    00054
    00055         SysDbgQueryTraceInformation
    00056         SysDbgSetTracepoint
    00057         SysDbgSetSpecialCall
    00058         SysDbgClearSpecialCalls
    00059         SysDbgQuerySpecialCalls
    00060
    00061     InputBuffer - A pointer to a buffer describing the input data for
    00062         the request, if any.  The structure of this buffer varies
    00063         depending upon Command.
    00064
    00065     InputBufferLength - The length in bytes of InputBuffer.
    00066
    00067     OutputBuffer - A pointer to a buffer that is to receive the output
    00068         data for the request, if any.  The structure of this buffer
    00069         varies depending upon Command.
    00070
    00071     OutputBufferLength - The length in bytes of OutputBuffer.
    00072
    00073     ReturnLength - A optional pointer to a ULONG that is to receive the
    00074         output data length for the request.
    00075
    00076 Return Value:
    00077
    00078     Returns one of the following status codes:
    00079
    00080         STATUS_SUCCESS - normal, successful completion.
    00081
    00082         STATUS_INVALID_INFO_CLASS - The Command parameter did not
    00083             specify a valid value.
    00084
    00085         STATUS_INFO_LENGTH_MISMATCH - The value of the Length field in the
    00086             Parameters buffer was not correct.
    00087
    00088         STATUS_ACCESS_VIOLATION - Either the Parameters buffer pointer
    00089             or a pointer within the Parameters buffer specified an
    00090             invalid address.
    00091
    00092         STATUS_INSUFFICIENT_RESOURCES - Insufficient system resources exist
    00093             for this request to complete.
    00094
    00095 --*/
    00096
    00097 {
    00098     NTSTATUS status = STATUS_SUCCESS;
    00099     BOOLEAN releaseModuleResoure = FALSE;
    00100     ULONG length = 0;
    00101     KPROCESSOR_MODE PreviousMode;
    00102
    00103     PreviousMode = KeGetPreviousMode();
    00104
    00105     if (!SeSinglePrivilegeCheck( SeDebugPrivilege, PreviousMode)) {
    00106         return STATUS_ACCESS_DENIED;
    00107     }
    00108
    00109     //
    00110     // Operate within a try block in order to catch errors.
    00111     //
    00112
    00113     try {
    00114
    00115         //
    00116         // Probe input and output buffers, if previous mode is not
    00117         // kernel.
    00118         //
    00119
    00120         if ( PreviousMode != KernelMode ) {
    00121
    00122             if ( InputBufferLength != 0 ) {
    00123                 ProbeForRead( InputBuffer, InputBufferLength, sizeof(ULONG) );
    00124             }
    00125
    00126             if ( OutputBufferLength != 0 ) {
    00127                 ProbeForWrite( OutputBuffer, OutputBufferLength, sizeof(ULONG) );
    00128             }
    00129
    00130             if ( ARGUMENT_PRESENT(ReturnLength) ) {
    00131                 ProbeForWriteUlong( ReturnLength );
    00132             }
    00133         }
    00134
    00135         //
    00136         // Switch on the command code.
    00137         //
    00138
    00139         switch ( Command ) {
    00140
    00141 #if i386
    00142
    00143         case SysDbgQueryTraceInformation:
    00144
    00145             status = KdGetTraceInformation(
    00146                         OutputBuffer,
    00147                         OutputBufferLength,
    00148                         &length
    00149                         );
    00150
    00151             break;
    00152
    00153         case SysDbgSetTracepoint:
    00154
    00155             if ( InputBufferLength != sizeof(DBGKD_MANIPULATE_STATE64) ) {
    00156                 return STATUS_INFO_LENGTH_MISMATCH;
    00157             }
    00158
    00159             KdSetInternalBreakpoint( InputBuffer );
    00160
    00161             break;
    00162
    00163         case SysDbgSetSpecialCall:
    00164
    00165             if ( InputBufferLength != sizeof(PVOID) ) {
    00166                 return STATUS_INFO_LENGTH_MISMATCH;
    00167             }
    00168
    00169             KdSetSpecialCall( InputBuffer, NULL );
    00170
    00171             break;
    00172
    00173         case SysDbgClearSpecialCalls:
    00174
    00175             KdClearSpecialCalls( );
    00176
    00177             break;
    00178
    00179         case SysDbgQuerySpecialCalls:
    00180
    00181             status = KdQuerySpecialCalls(
    00182                         OutputBuffer,
    00183                         OutputBufferLength,
    00184                         &length
    00185                         );
    00186
    00187             break;
    00188
    00189 #endif
    00190
    00191         case SysDbgBreakPoint:
    00192             if (KdDebuggerEnabled) {
    00193                 DbgBreakPointWithStatus(DBG_STATUS_DEBUG_CONTROL);
    00194             } else {
    00195                 status = STATUS_UNSUCCESSFUL;
    00196             }
    00197             break;
    00198
    00199         default:
    00200
    00201             //
    00202             // Invalid Command.
    00203             //
    00204
    00205             status = STATUS_INVALID_INFO_CLASS;
    00206         }
    00207
    00208         if ( ARGUMENT_PRESENT(ReturnLength) ) {
    00209             *ReturnLength = length;
    00210         }
    00211     }
    00212
    00213     except ( EXCEPTION_EXECUTE_HANDLER ) {
    00214
    00215         if ( releaseModuleResoure ) {
    00216             ExReleaseResource( &PsLoadedModuleResource );
    00217             KeLeaveCriticalRegion();
    00218         }
    00219
    00220         status = GetExceptionCode();
    00221
    00222     }
    00223
    00224     return status;
    00225
    00226 } // NtSystemDebugControl
    } // NtSystemDebugControl