ReactOS  0.4.15-dev-1070-ge1a01de
kdapi.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdapi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI PspDumpThreads (BOOLEAN SystemThreads)
 
VOID NTAPI KdpMoveMemory (_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
 
VOID NTAPI KdpZeroMemory (_In_ PVOID Destination, _In_ SIZE_T Length)
 
NTSTATUS NTAPI KdpCopyMemoryChunks (_In_ ULONG64 Address, _In_ PVOID Buffer, _In_ ULONG TotalSize, _In_ ULONG ChunkSize, _In_ ULONG Flags, _Out_opt_ PULONG ActualSize)
 
NTSTATUS NTAPI NtQueryDebugFilterState (_In_ ULONG ComponentId, _In_ ULONG Level)
 
NTSTATUS NTAPI NtSetDebugFilterState (_In_ ULONG ComponentId, _In_ ULONG Level, _In_ BOOLEAN State)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file kdapi.c.

Function Documentation

◆ KdpCopyMemoryChunks()

NTSTATUS NTAPI KdpCopyMemoryChunks ( _In_ ULONG64  Address,
_In_ PVOID  Buffer,
_In_ ULONG  TotalSize,
_In_ ULONG  ChunkSize,
_In_ ULONG  Flags,
_Out_opt_ PULONG  ActualSize 
)

Definition at line 50 of file kdapi.c.

57 {
59  ULONG RemainingLength, CopyChunk;
60 
61  /* Check if we didn't get a chunk size or if it is too big */
62  if (ChunkSize == 0)
63  {
64  /* Default to 4 byte chunks */
65  ChunkSize = 4;
66  }
67  else if (ChunkSize > MMDBG_COPY_MAX_SIZE)
68  {
69  /* Normalize to maximum size */
71  }
72 
73  /* Copy the whole range in aligned chunks */
74  RemainingLength = TotalSize;
75  CopyChunk = 1;
76  while (RemainingLength > 0)
77  {
78  /*
79  * Determine the best chunk size for this round.
80  * The ideal size is aligned, isn't larger than the
81  * the remaining length and respects the chunk limit.
82  */
83  while (((CopyChunk * 2) <= RemainingLength) &&
84  (CopyChunk < ChunkSize) &&
85  ((Address & ((CopyChunk * 2) - 1)) == 0))
86  {
87  /* Increase it */
88  CopyChunk *= 2;
89  }
90 
91  /*
92  * The chunk size can be larger than the remaining size if this
93  * isn't the first round, so check if we need to shrink it back.
94  */
95  while (CopyChunk > RemainingLength)
96  {
97  /* Shrink it */
98  CopyChunk /= 2;
99  }
100 
101  /* Do the copy */
102  Status = MmDbgCopyMemory(Address, Buffer, CopyChunk, Flags);
103  if (!NT_SUCCESS(Status))
104  {
105  /* Copy failed, break out */
106  break;
107  }
108 
109  /* Update pointers and length for the next run */
110  Address = Address + CopyChunk;
111  Buffer = (PVOID)((ULONG_PTR)Buffer + CopyChunk);
112  RemainingLength = RemainingLength - CopyChunk;
113  }
114 
115  /* We may have modified executable code, flush the instruction cache */
116  KeSweepICache((PVOID)(ULONG_PTR)Address, TotalSize);
117 
118  /*
119  * Return the size we managed to copy and return
120  * success if we could copy the whole range.
121  */
122  if (ActualSize) *ActualSize = TotalSize - RemainingLength;
123  return RemainingLength == 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
124 }
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI MmDbgCopyMemory(IN ULONG64 Address, IN PVOID Buffer, IN ULONG Size, IN ULONG Flags)
Definition: mmdbg.c:126
#define MMDBG_COPY_MAX_SIZE
Definition: mm.h:63
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
FORCEINLINE VOID KeSweepICache(IN PVOID BaseAddress, IN SIZE_T FlushSize)
Definition: ke.h:217

Referenced by GspReadMemSafe(), GspWriteMemSafe(), KdbpSafeReadMemory(), KdbpSafeWriteMemory(), KdpAddBreakpoint(), KdpLowRestoreBreakpoint(), KdpLowWriteContent(), KdpSysReadControlSpace(), KdpSysWriteControlSpace(), and KdSetOwedBreakpoints().

◆ KdpMoveMemory()

VOID NTAPI KdpMoveMemory ( _In_ PVOID  Destination,
_In_ PVOID  Source,
_In_ SIZE_T  Length 
)

Definition at line 22 of file kdapi.c.

26 {
27  PCHAR DestinationBytes, SourceBytes;
28 
29  /* Copy the buffers 1 byte at a time */
30  DestinationBytes = Destination;
31  SourceBytes = Source;
32  while (Length--) *DestinationBytes++ = *SourceBytes++;
33 }
signed char * PCHAR
Definition: retypes.h:7
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by KdpEnterDebuggerException(), KdpPrint(), KdpPrompt(), and KdpReport().

◆ KdpZeroMemory()

VOID NTAPI KdpZeroMemory ( _In_ PVOID  Destination,
_In_ SIZE_T  Length 
)

Definition at line 37 of file kdapi.c.

40 {
41  PCHAR DestinationBytes;
42 
43  /* Zero the buffer 1 byte at a time */
44  DestinationBytes = Destination;
45  while (Length--) *DestinationBytes++ = 0;
46 }
signed char * PCHAR
Definition: retypes.h:7
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101

◆ NtQueryDebugFilterState()

NTSTATUS NTAPI NtQueryDebugFilterState ( _In_ ULONG  ComponentId,
_In_ ULONG  Level 
)

Definition at line 2334 of file kdapi.c.

2337 {
2338  PULONG Mask;
2339 
2340  /* Check if the ID fits in the component table */
2342  {
2343  /* It does, so get the mask from there */
2344  Mask = KdComponentTable[ComponentId];
2345  }
2346  else if (ComponentId == MAXULONG)
2347  {
2348  /*
2349  * This is the internal ID used for DbgPrint messages without ID
2350  * and Level. Use the system-wide mask for those.
2351  */
2352  Mask = &Kd_WIN2000_Mask;
2353  }
2354  else
2355  {
2356 #if (NTDDI_VERSION >= NTDDI_VISTA)
2357  /* Use the default component ID */
2358  Mask = &Kd_DEFAULT_Mask;
2359  // Level = DPFLTR_INFO_LEVEL; // Override the Level.
2360 #else
2361  /* Invalid ID, fail */
2363 #endif
2364  }
2365 
2366  /* Convert Level to bit field if required */
2367  if (Level < 32) Level = 1 << Level;
2368  Level &= ~DPFLTR_MASK;
2369 
2370  /* Determine if this Level is filtered out */
2371  if ((Kd_WIN2000_Mask & Level) || (*Mask & Level))
2372  {
2373  /* This mask will get through to the debugger */
2374  return (NTSTATUS)TRUE;
2375  }
2376  else
2377  {
2378  /* This mask is filtered out */
2379  return (NTSTATUS)FALSE;
2380  }
2381 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
ULONG KdComponentTableSize
Definition: kddata.c:488
#define DPFLTR_MASK
Definition: kdtypes.h:34
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
#define FALSE
Definition: types.h:117
ULONG Kd_WIN2000_Mask
Definition: kddata.c:147
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:318
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define MAXULONG
Definition: typedefs.h:251
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:249
unsigned int * PULONG
Definition: retypes.h:1

Referenced by DbgQueryDebugFilterState(), KdpPrint(), and vDbgPrintExWithPrefixInternal().

◆ NtSetDebugFilterState()

NTSTATUS NTAPI NtSetDebugFilterState ( _In_ ULONG  ComponentId,
_In_ ULONG  Level,
_In_ BOOLEAN  State 
)

Definition at line 2388 of file kdapi.c.

2392 {
2393  PULONG Mask;
2394 
2395  /* Modifying debug filters requires the debug privilege */
2397  {
2398  /* Fail */
2399  return STATUS_ACCESS_DENIED;
2400  }
2401 
2402  /* Check if the ID fits in the component table */
2404  {
2405  /* It does, so get the mask from there */
2406  Mask = KdComponentTable[ComponentId];
2407  }
2408  else if (ComponentId == MAXULONG)
2409  {
2410  /*
2411  * This is the internal ID used for DbgPrint messages without ID
2412  * and Level. Use the system-wide mask for those.
2413  */
2414  Mask = &Kd_WIN2000_Mask;
2415  }
2416  else
2417  {
2418 #if (NTDDI_VERSION >= NTDDI_VISTA)
2419  /* Use the default component ID */
2420  Mask = &Kd_DEFAULT_Mask;
2421 #else
2422  /* Invalid ID, fail */
2424 #endif
2425  }
2426 
2427  /* Convert Level to bit field if required */
2428  if (Level < 32) Level = 1 << Level;
2429  Level &= ~DPFLTR_MASK;
2430 
2431  /* Set or remove the Level */
2432  if (State)
2433  *Mask |= Level;
2434  else
2435  *Mask &= ~Level;
2436 
2437  return STATUS_SUCCESS;
2438 }
const LUID SeDebugPrivilege
Definition: priv.c:41
ULONG KdComponentTableSize
Definition: kddata.c:488
#define DPFLTR_MASK
Definition: kdtypes.h:34
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
ULONG Kd_WIN2000_Mask
Definition: kddata.c:147
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:318
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define MAXULONG
Definition: typedefs.h:251
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:249
unsigned int * PULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by DbgSetDebugFilterState(), and KdbpCmdFilter().

◆ PspDumpThreads()

VOID NTAPI PspDumpThreads ( BOOLEAN  SystemThreads)