ReactOS 0.4.15-dev-8235-gcd88a97
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

◆ DbgGdiKdbgCliCallback()

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

Definition at line 324 of file gdikdbgext.c.

328{
329
330 if (stricmp(argv[0], "!gdi.help") == 0)
331 {
333 }
334 else if (stricmp(argv[0], "!gdi.dumpht") == 0)
335 {
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
#define FALSE
Definition: types.h:117
#define stricmp(_String1, _String2)
Definition: compat.h:24
static VOID KdbCommand_Gdi_entry(char *argv)
Definition: gdikdbgext.c:231
static VOID KdbCommand_Gdi_handle(char *argv)
Definition: gdikdbgext.c:181
static VOID KdbCommand_Gdi_baseobject(char *argv)
Definition: gdikdbgext.c:277
static VOID KdbCommand_Gdi_dumpht(ULONG argc, char *argv[])
Definition: gdikdbgext.c:80
static VOID KdbCommand_Gdi_help(VOID)
Definition: gdikdbgext.c:64
#define argv
Definition: mplay32.c:18

Referenced by InitProcessCallback().

◆ KdbCommand_Gdi_baseobject()

static VOID KdbCommand_Gdi_baseobject ( char argv)
static

Definition at line 277 of file gdikdbgext.c.

278{
279}

Referenced by DbgGdiKdbgCliCallback().

◆ KdbCommand_Gdi_dumpht()

static VOID KdbCommand_Gdi_dumpht ( ULONG  argc,
char argv[] 
)
static

Definition at line 80 of file gdikdbgext.c.

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;
92
93 if (argc == 0)
94 {
96
97 /* Loop all possibly used entries in the handle table */
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",
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 */
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 */
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
175leave:
177}
static COUNTS Counts
Definition: ObType.c:60
#define leave
Definition: btrfs_drv.h:138
PEPROCESS gpepCSRSS
Definition: csr.c:15
static const char * gpszObjectTypes[]
Definition: gdikdbgext.c:20
BOOLEAN KdbIsMemoryValid(PVOID pvBase, ULONG cjSize)
Definition: gdikdbgext.c:31
static BOOL KdbGetHexNumber(char *pszNum, ULONG_PTR *pulValue)
Definition: gdikdbgext.c:48
PENTRY gpentHmgr
Definition: gdiobj.c:149
PULONG gpaulRefCount
Definition: gdiobj.c:150
ULONG gulFirstUnused
Definition: gdiobj.c:152
static const unsigned RESERVE_ENTRIES_COUNT
Definition: gdiobj.h:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgPrint
Definition: hal.h:12
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
@ GDIObjType_MAX_TYPE
Definition: ntgdityp.h:151
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1765
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:704
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:756
Definition: DelNode.c:62
HGDIOBJ hHmgr
Definition: gdiobj.h:40
USHORT cExclusiveLock
Definition: gdiobj.h:45
DWORD dwThreadId
Definition: gdiobj.h:43
Definition: ntgdihdl.h:218
UCHAR Objt
Definition: ntgdihdl.h:236
union _ENTRY::_EINFO einfo
KPROCESS Pcb
Definition: pstypes.h:1262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:221
KAPC_STATE
Definition: ketypes.h:1409
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DbgGdiKdbgCliCallback().

◆ KdbCommand_Gdi_entry()

static VOID KdbCommand_Gdi_entry ( char argv)
static

Definition at line 231 of file gdikdbgext.c.

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;
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
271cleanup:
273}
static void cleanup(void)
Definition: main.c:1335
union _ENTRY::_OBJECTOWNER ObjectOwner
PVOID pUser
Definition: ntgdihdl.h:238
UCHAR Flags
Definition: ntgdihdl.h:237
USHORT FullUnique
Definition: ntgdihdl.h:235
HGDIOBJ hFree
Definition: ntgdihdl.h:222
ULONG ulObj
Definition: ntgdihdl.h:232

Referenced by DbgGdiKdbgCliCallback().

◆ KdbCommand_Gdi_handle()

static VOID KdbCommand_Gdi_handle ( char argv)
static

Definition at line 181 of file gdikdbgext.c.

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;
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
227}
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
USHORT BaseFlags
Definition: gdiobj.h:46

Referenced by DbgGdiKdbgCliCallback().

◆ KdbCommand_Gdi_help()

static VOID KdbCommand_Gdi_help ( VOID  )
static

Definition at line 64 of file gdikdbgext.c.

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 DBG_ENABLE_EVENT_LOGGING
Definition: win32kp.h:16

Referenced by DbgGdiKdbgCliCallback().

◆ KdbGetHexNumber()

static BOOL KdbGetHexNumber ( char pszNum,
ULONG_PTR pulValue 
)
static

Definition at line 48 of file gdikdbgext.c.

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

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

◆ KdbIsMemoryValid()

BOOLEAN KdbIsMemoryValid ( PVOID  pvBase,
ULONG  cjSize 
)

Definition at line 31 of file gdikdbgext.c.

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 PAGE_SIZE
Definition: env_spec_w32.h:49
unsigned char * PUCHAR
Definition: typedefs.h:53
#define ALIGN_DOWN_POINTER_BY(ptr, align)
Definition: umtypes.h:82
_In_ ULONG cjSize
Definition: winddi.h:3634

Referenced by KdbCommand_Gdi_dumpht().

Variable Documentation

◆ gpaulRefCount

◆ gpentHmgr

◆ gpszObjectTypes

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().

◆ gulFirstUnused

ULONG gulFirstUnused
extern