ReactOS 0.4.16-dev-251-ga17b6e9
clientobj.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WIN32 subsystem
4 * PURPOSE: Support functions for GDI client objects
5 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
6 */
7
8#include <precomp.h>
9
12
13typedef struct _CLIENTOBJLINK
14{
19
21
22BOOL
26 _In_ PVOID pvObject)
27{
28 PCLIENTOBJLINK pcol;
29 ULONG iHashIndex;
30
31 /* Allocate a link structure */
32 pcol = HeapAlloc(GetProcessHeap(), 0, sizeof(*pcol));
33 if (pcol == NULL)
34 {
35 return FALSE;
36 }
37
38 /* Setup the link structure */
39 pcol->hobj = hobj;
40 pcol->pvObj = pvObject;
41
42 /* Calculate the hash index */
43 iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
44
45 /* Enter the critical section */
47
48 /* Insert the link structure */
49 pcol->pcolNext = gapcolHashTable[iHashIndex];
50 gapcolHashTable[iHashIndex] = pcol;
52
53 /* Leave the critical section */
55
56 return TRUE;
57}
58
63{
64 ULONG iHashIndex;
65 PCLIENTOBJLINK pcol;
66 PVOID pvObject = NULL;
67
68 /* Calculate the hash index */
69 iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
70
71 /* Enter the critical section */
73
74 /* Loop the link entries in this hash bucket */
75 pcol = gapcolHashTable[iHashIndex];
76 while (pcol != NULL)
77 {
78 /* Check if this is the object we want */
79 if (pcol->hobj == hobj)
80 {
81 /* Get the object pointer and bail out */
82 pvObject = pcol->pvObj;
83 break;
84 }
85
86 /* Go to the next entry */
87 pcol = pcol->pcolNext;
88 }
89
90 /* Leave the critical section */
92
93 return pvObject;
94}
95
100{
101 PCLIENTOBJLINK pcol, *ppcol;
102 ULONG iHashIndex;
103 PVOID pvObject = NULL;
104
105 /* Calculate the hash index */
106 iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
107
108 /* Enter the critical section */
110
111 /* Loop the link entries in this hash bucket */
112 ppcol = &gapcolHashTable[iHashIndex];
113 while (*ppcol != NULL)
114 {
115 /* Get the current client object link */
116 pcol = *ppcol;
117
118 /* Check if this is the one we want */
119 if (pcol->hobj == hobj)
120 {
121 /* Update the link pointer, removing this link */
122 *ppcol = pcol->pcolNext;
123 gcClientObj--;
124
125 /* Get the object pointer */
126 pvObject = pcol->pvObj;
127
128 /* Free the link structure */
129 HeapFree(GetProcessHeap(), 0, pcol);
130
131 /* We're done */
132 break;
133 }
134
135 /* Go to the next link pointer */
136 ppcol = &(pcol->pcolNext);
137 }
138
139 /* Leave the critical section */
141
142 /* Return the object pointer, or NULL if we did not find it */
143 return pvObject;
144}
145
147WINAPI
149 _In_ PVOID pvObject,
150 _In_ GDILOOBJTYPE eObjType)
151{
153
154 /* Call win32k to create a client object handle */
155 hobj = NtGdiCreateClientObj(eObjType);
156 if (hobj == NULL)
157 {
158 return NULL;
159 }
160
161 /* Create the client object link */
162 if (!GdiCreateClientObjLink(hobj, pvObject))
163 {
165 return NULL;
166 }
167
168 return hobj;
169}
170
171PVOID
172WINAPI
175{
176 PVOID pvObject;
177
178 /* Remove the client object link */
179 pvObject = GdiRemoveClientObjLink(hobj);
180 if (pvObject == NULL)
181 {
182 return NULL;
183 }
184
185 /* Call win32k to delete the handle */
187 {
188 ASSERT(FALSE);
189 }
190
191 return pvObject;
192}
HGDIOBJ WINAPI GdiCreateClientObj(_In_ PVOID pvObject, _In_ GDILOOBJTYPE eObjType)
Definition: clientobj.c:148
ULONG gcClientObj
Definition: clientobj.c:11
PCLIENTOBJLINK gapcolHashTable[127]
Definition: clientobj.c:20
BOOL WINAPI GdiCreateClientObjLink(_In_ HGDIOBJ hobj, _In_ PVOID pvObject)
Definition: clientobj.c:24
CRITICAL_SECTION gcsClientObjLinks
Definition: clientobj.c:10
PVOID WINAPI GdiGetClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:61
struct _CLIENTOBJLINK CLIENTOBJLINK
PVOID WINAPI GdiDeleteClientObj(_In_ HGDIOBJ hobj)
Definition: clientobj.c:173
struct _CLIENTOBJLINK * PCLIENTOBJLINK
PVOID WINAPI GdiRemoveClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:98
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
enum GDILoObjType GDILOOBJTYPE
#define ASSERT(a)
Definition: mode.c:44
#define _In_
Definition: no_sal2.h:158
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiCreateClientObj(_In_ ULONG ulType)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteClientObj(_In_ HANDLE h)
#define _countof(array)
Definition: sndvol32.h:70
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6