ReactOS  0.4.11-dev-721-g95bc44e
gdikdbgext.c File Reference
#include <win32k.h>
Include dependency graph for gdikdbgext.c:

Go to the source code of this file.

Functions

BOOLEAN KdbIsMemoryValid (PVOID pvBase, ULONG cjSize)
 
static BOOL KdbGetHexNumber (char *pszNum, ULONG_PTR *pulValue)
 
static VOID KdbCommand_Gdi_help (VOID)
 
static VOID KdbCommand_Gdi_dumpht (ULONG argc, char *argv[])
 
static VOID KdbCommand_Gdi_handle (char *argv)
 
static VOID KdbCommand_Gdi_entry (char *argv)
 
static VOID KdbCommand_Gdi_baseobject (char *argv)
 
BOOLEAN NTAPI DbgGdiKdbgCliCallback (IN PCHAR pszCommand, IN ULONG argc, IN PCH argv[])
 

Variables

PENTRY gpentHmgr
 
PULONG gpaulRefCount
 
ULONG gulFirstUnused
 
static const chargpszObjectTypes []
 

Function Documentation

BOOLEAN NTAPI DbgGdiKdbgCliCallback ( IN PCHAR  pszCommand,
IN ULONG  argc,
IN PCH  argv[] 
)

Definition at line 324 of file gdikdbgext.c.

Referenced by InitProcessCallback().

328 {
329 
330  if (stricmp(argv[0], "!gdi.help") == 0)
331  {
333  }
334  else if (stricmp(argv[0], "!gdi.dumpht") == 0)
335  {
336  KdbCommand_Gdi_dumpht(argc - 1, argv + 1);
337  }
338  else if (stricmp(argv[0], "!gdi.handle") == 0)
339  {
341  }
342  else if (stricmp(argv[0], "!gdi.entry") == 0)
343  {
345  }
346  else if (stricmp(argv[0], "!gdi.baseobject") == 0)
347  {
349  }
350 #if DBG_ENABLE_EVENT_LOGGING
351  else if (stricmp(argv[0], "!gdi.eventlist") == 0)
352  {
353  KdbCommand_Gdi_eventlist(argv[1]);
354  }
355 #endif
356  else
357  {
358  /* Not handled */
359  return FALSE;
360  }
361 
362  return TRUE;
363 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
static char ** argv
Definition: ServiceArgs.c:11
#define FALSE
Definition: types.h:117
static VOID KdbCommand_Gdi_entry(char *argv)
Definition: gdikdbgext.c:231
_Check_return_ _CRTIMP int __cdecl stricmp(_In_z_ const char *_Str1, _In_z_ const char *_Str2)
static VOID KdbCommand_Gdi_handle(char *argv)
Definition: gdikdbgext.c:181
static VOID KdbCommand_Gdi_dumpht(ULONG argc, char *argv[])
Definition: gdikdbgext.c:80
static VOID KdbCommand_Gdi_help(VOID)
Definition: gdikdbgext.c:64
static VOID KdbCommand_Gdi_baseobject(char *argv)
Definition: gdikdbgext.c:277
static VOID KdbCommand_Gdi_baseobject ( char argv)
static

Definition at line 277 of file gdikdbgext.c.

Referenced by DbgGdiKdbgCliCallback().

278 {
279 }
static VOID KdbCommand_Gdi_dumpht ( ULONG  argc,
char argv[] 
)
static

Definition at line 80 of file gdikdbgext.c.

Referenced by DbgGdiKdbgCliCallback().

81 {
82  ULONG i;
83  UCHAR Objt, jReqestedType;
84  PENTRY pentry;
85  POBJ pobj;
87  ULONG_PTR ulArg;
88 
89  /* No CSRSS, no handle table */
90  if (!gpepCSRSS) return;
91  KeStackAttachProcess(&gpepCSRSS->Pcb, &ApcState);
92 
93  if (argc == 0)
94  {
96 
97  /* Loop all possibly used entries in the handle table */
98  for (i = RESERVE_ENTRIES_COUNT; i < gulFirstUnused; i++)
99  {
100  if (KdbIsMemoryValid(&gpentHmgr[i], sizeof(ENTRY)))
101  {
102  Objt = gpentHmgr[i].Objt & 0x1F;
103  Counts[Objt]++;
104  }
105  }
106 
107  DbgPrint("Type Count\n");
108  DbgPrint("-------------------\n");
109  for (i = 0; i <= GDIObjType_MAX_TYPE; i++)
110  {
111  DbgPrint("%02x %-9s %d\n",
112  i, gpszObjectTypes[i], Counts[i]);
113  }
114  DbgPrint("\n");
115  }
116  else
117  {
118  /* Loop all object types */
119  for (i = 0; i <= GDIObjType_MAX_TYPE + 1; i++)
120  {
121  /* Check if this object type was requested */
122  if (stricmp(argv[0], gpszObjectTypes[i]) == 0) break;
123  }
124 
125  /* Check if we didn't find it yet */
126  if (i > GDIObjType_MAX_TYPE + 1)
127  {
128  /* Try if it's a number */
129  if (!KdbGetHexNumber(argv[0], &ulArg))
130  {
131  DbgPrint("Invalid parameter: %s\n", argv[0]);
132  return;
133  }
134 
135  /* Check if it's inside the allowed range */
136  if (i > GDIObjType_MAX_TYPE)
137  {
138  DbgPrint("Unknown object type: %s\n", argv[0]);
139  goto leave;
140  }
141  }
142 
143  jReqestedType = i;
144 
145  /* Print header */
146  DbgPrint("Index Handle Type pObject ThreadId cLocks ulRefCount\n");
147  DbgPrint("---------------------------------------------------------------\n");
148 
149  /* Loop all possibly used entries in the handle table */
150  for (i = RESERVE_ENTRIES_COUNT; i < gulFirstUnused; i++)
151  {
152  /* Get the entry and the object */
153  pentry = &gpentHmgr[i];
154 
155  if (!MmIsAddressValid(pentry)) continue;
156 
157  pobj = pentry->einfo.pobj;
158  Objt = pentry->Objt & 0x1F;
159 
160  /* Check if ALL objects are requested, or the object type matches */
161  if ((jReqestedType == GDIObjType_MAX_TYPE + 1) ||
162  (Objt == jReqestedType))
163  {
164  DbgPrint("%04lx %p %-9s 0x%p 0x%06lx %-6ld ",
165  i, pobj->hHmgr, gpszObjectTypes[Objt], pobj,
166  pobj->dwThreadId, pobj->cExclusiveLock);
168  DbgPrint("0x%08lx\n", gpaulRefCount[i]);
169  else
170  DbgPrint("??????????\n");
171  }
172  }
173  }
174 
175 leave:
176  KeUnstackDetachProcess(&ApcState);
177 }
static BOOL KdbGetHexNumber(char *pszNum, ULONG_PTR *pulValue)
Definition: gdikdbgext.c:48
static int argc
Definition: ServiceArgs.c:12
KAPC_STATE
Definition: ketypes.h:1273
#define DbgPrint
Definition: loader.c:25
UCHAR Objt
Definition: ntgdihdl.h:245
PEPROCESS gpepCSRSS
Definition: csr.c:15
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:230
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
PENTRY gpentHmgr
Definition: gdiobj.c:147
static char ** argv
Definition: ServiceArgs.c:11
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
_Check_return_ _CRTIMP int __cdecl stricmp(_In_z_ const char *_Str1, _In_z_ const char *_Str2)
static COUNTS Counts
Definition: ObType.c:60
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
unsigned char UCHAR
Definition: xmlstorage.h:181
KPROCESS Pcb
Definition: pstypes.h:1193
static const unsigned RESERVE_ENTRIES_COUNT
Definition: gdiobj.h:11
PULONG gpaulRefCount
Definition: gdiobj.c:148
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
ULONG gulFirstUnused
Definition: gdiobj.c:150
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
static const char * gpszObjectTypes[]
Definition: gdikdbgext.c:20
unsigned int ULONG
Definition: retypes.h:1
Definition: ntgdihdl.h:226
BOOLEAN KdbIsMemoryValid(PVOID pvBase, ULONG cjSize)
Definition: gdikdbgext.c:31
static VOID KdbCommand_Gdi_entry ( char argv)
static

Definition at line 231 of file gdikdbgext.c.

Referenced by DbgGdiKdbgCliCallback().

232 {
233  ULONG_PTR ulValue;
234  PENTRY pentry;
236 
237  /* Convert the parameter into a number */
238  if (!KdbGetHexNumber(argv, &ulValue))
239  {
240  DbgPrint("Invalid parameter: %s\n", argv);
241  return;
242  }
243 
244  /* No CSRSS, no handle table */
245  if (!gpepCSRSS) return;
246  KeStackAttachProcess(&gpepCSRSS->Pcb, &ApcState);
247 
248  /* If the parameter is smaller than 0x10000, it's an index */
249  pentry = (ulValue <= 0xFFFF) ? &gpentHmgr[ulValue] : (PENTRY)ulValue;
250 
251  /* Check if the address is readable */
252  if (!MmIsAddressValid(pentry))
253  {
254  DbgPrint("Cannot access entry at %p\n", pentry);
255  goto cleanup;
256  }
257 
258  /* print the entry */
259  DbgPrint("Dumping ENTRY #%ld, @%p:\n", (pentry - gpentHmgr), pentry);
260  if (pentry->Objt != 0)
261  DbgPrint(" pobj = 0x%p\n", pentry->einfo.pobj);
262  else
263  DbgPrint(" hFree = 0x%p\n", pentry->einfo.hFree);
264  DbgPrint(" ObjectOwner = 0x%p\n", pentry->ObjectOwner.ulObj);
265  DbgPrint(" FullUnique = 0x%x\n", pentry->FullUnique);
266  DbgPrint(" Objt = 0x%x (%s)\n", pentry->Objt,
267  pentry->Objt <= 0x1E ? gpszObjectTypes[pentry->Objt] : "invalid");
268  DbgPrint(" Flags = 0x%x\n", pentry->Flags);
269  DbgPrint(" pUser = 0x%p\n", pentry->pUser);
270 
271 cleanup:
272  KeUnstackDetachProcess(&ApcState);
273 }
static BOOL KdbGetHexNumber(char *pszNum, ULONG_PTR *pulValue)
Definition: gdikdbgext.c:48
KAPC_STATE
Definition: ketypes.h:1273
PVOID pUser
Definition: ntgdihdl.h:247
#define DbgPrint
Definition: loader.c:25
UCHAR Objt
Definition: ntgdihdl.h:245
PEPROCESS gpepCSRSS
Definition: csr.c:15
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:230
UCHAR Flags
Definition: ntgdihdl.h:246
PENTRY gpentHmgr
Definition: gdiobj.c:147
static char ** argv
Definition: ServiceArgs.c:11
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
ULONG ulObj
Definition: ntgdihdl.h:241
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
KPROCESS Pcb
Definition: pstypes.h:1193
HGDIOBJ hFree
Definition: ntgdihdl.h:231
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
USHORT FullUnique
Definition: ntgdihdl.h:244
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
static const char * gpszObjectTypes[]
Definition: gdikdbgext.c:20
char * cleanup(char *str)
Definition: wpickclick.c:99
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:226
static VOID KdbCommand_Gdi_handle ( char argv)
static

Definition at line 181 of file gdikdbgext.c.

Referenced by DbgGdiKdbgCliCallback().

182 {
183  ULONG_PTR ulObject;
184  BASEOBJECT *pobj;
185  ENTRY *pentry;
186  USHORT usIndex;
188 
189  /* Convert the parameter into a number */
190  if (!KdbGetHexNumber(argv, &ulObject))
191  {
192  DbgPrint("Invalid parameter: %s\n", argv);
193  return;
194  }
195 
196  /* No CSRSS, no handle table */
197  if (!gpepCSRSS) return;
198  KeStackAttachProcess(&gpepCSRSS->Pcb, &ApcState);
199 
200  usIndex = ulObject & 0xFFFF;
201  pentry = &gpentHmgr[usIndex];
202 
203  if (MmIsAddressValid(pentry))
204  {
205  pobj = pentry->einfo.pobj;
206 
207  DbgPrint("GDI handle=%p, type=%s, index=0x%lx, pentry=%p.\n",
208  ulObject, gpszObjectTypes[(ulObject >> 16) & 0x1f],
209  usIndex, pentry);
210  DbgPrint(" ENTRY = {.pobj = %p, ObjectOwner = 0x%lx, FullUnique = 0x%04x,\n"
211  " Objt=0x%02x, Flags = 0x%02x, pUser = 0x%p}\n",
212  pentry->einfo.pobj, pentry->ObjectOwner.ulObj, pentry->FullUnique,
213  pentry->Objt, pentry->Flags, pentry->pUser);
214  DbgPrint(" BASEOBJECT = {hHmgr = %p, dwThreadId = 0x%lx,\n"
215  " cExclusiveLock = %ld, BaseFlags = 0x%lx}\n",
216  pobj->hHmgr, pobj->dwThreadId,
217  pobj->cExclusiveLock, pobj->BaseFlags);
218  if (MmIsAddressValid(&gpaulRefCount[usIndex]))
219  DbgPrint(" gpaulRefCount[idx] = %ld\n", gpaulRefCount[usIndex]);
220  }
221  else
222  {
223  DbgPrint("Coudn't access ENTRY. Probably paged out.\n");
224  }
225 
226  KeUnstackDetachProcess(&ApcState);
227 }
static BOOL KdbGetHexNumber(char *pszNum, ULONG_PTR *pulValue)
Definition: gdikdbgext.c:48
KAPC_STATE
Definition: ketypes.h:1273
#define DbgPrint
Definition: loader.c:25
PEPROCESS gpepCSRSS
Definition: csr.c:15
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
UINT Flags
Definition: PathResolve.cpp:71
PENTRY gpentHmgr
Definition: gdiobj.c:147
static char ** argv
Definition: ServiceArgs.c:11
USHORT BaseFlags
Definition: gdiobj.h:46
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
KPROCESS Pcb
Definition: pstypes.h:1193
PULONG gpaulRefCount
Definition: gdiobj.c:148
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
static const char * gpszObjectTypes[]
Definition: gdikdbgext.c:20
static VOID KdbCommand_Gdi_help ( VOID  )
static

Definition at line 64 of file gdikdbgext.c.

Referenced by DbgGdiKdbgCliCallback().

65 {
66  DbgPrint("GDI KDBG extension.\nAvailable commands:\n"
67  "- help - Displays this screen.\n"
68  "- dumpht [<type>] - Dumps all handles of <type> or lists all types\n"
69  "- handle <handle> - Displays information about a handle\n"
70  "- entry <entry> - Displays an ENTRY, <entry> can be a pointer or index\n"
71  "- baseobject <object> - Displays a BASEOBJECT\n"
73  "- eventlist <object> - Displays the eventlist for an object\n"
74 #endif
75  );
76 }
#define DbgPrint
Definition: loader.c:25
#define DBG_ENABLE_EVENT_LOGGING
Definition: win32kp.h:24
static BOOL KdbGetHexNumber ( char pszNum,
ULONG_PTR pulValue 
)
static

Definition at line 48 of file gdikdbgext.c.

Referenced by KdbCommand_Gdi_dumpht(), KdbCommand_Gdi_entry(), and KdbCommand_Gdi_handle().

49 {
50  char *endptr;
51 
52  /* Skip optional '0x' prefix */
53  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
54  pszNum += 2;
55 
56  /* Make a number from the string (hex) */
57  *pulValue = strtoul(pszNum, &endptr, 16);
58 
59  return (*endptr == '\0');
60 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
BOOLEAN KdbIsMemoryValid ( PVOID  pvBase,
ULONG  cjSize 
)

Definition at line 31 of file gdikdbgext.c.

Referenced by KdbCommand_Gdi_dumpht().

32 {
33  PUCHAR pjAddress;
34 
35  pjAddress = ALIGN_DOWN_POINTER_BY(pvBase, PAGE_SIZE);
36 
37  while (pjAddress < (PUCHAR)pvBase + cjSize)
38  {
39  if (!MmIsAddressValid(pjAddress)) return FALSE;
40  pjAddress += PAGE_SIZE;
41  }
42 
43  return TRUE;
44 }
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ ULONG cjSize
Definition: winddi.h:3634
#define ALIGN_DOWN_POINTER_BY(ptr, align)
Definition: umtypes.h:82

Variable Documentation

PULONG gpaulRefCount

Definition at line 148 of file gdiobj.c.

Referenced by KdbCommand_Gdi_dumpht(), and KdbCommand_Gdi_handle().

PENTRY gpentHmgr

Definition at line 147 of file gdiobj.c.

Referenced by ENTRY_hInsertObject(), and ENTRY_vPushFreeEntry().

const char* gpszObjectTypes[]
static
Initial value:
=
{
"FREE", "DC", "UNUSED1", "UNUSED2", "RGN", "SURF", "CLIENTOBJ", "PATH",
"PAL", "ICMLCS", "LFONT", "RFONT", "PFE", "PFT", "ICMCXF", "SPRITE",
"BRUSH", "UMPD", "UNUSED4", "SPACE", "UNUSED5", "META", "EFSTATE",
"BMFD", "VTFD", "TTFD", "RC", "TEMP", "DRVOBJ", "DCIOBJ", "SPOOL",
"RESERVED", "ALL"
}

Definition at line 20 of file gdikdbgext.c.

Referenced by KdbCommand_Gdi_dumpht(), KdbCommand_Gdi_entry(), and KdbCommand_Gdi_handle().

ULONG gulFirstUnused

Definition at line 150 of file gdiobj.c.

Referenced by GDI_CleanupForProcess(), and KdbCommand_Gdi_dumpht().