ReactOS 0.4.15-dev-5865-g640e228
ddhmg.c File Reference
#include <dxg_int.h>
Include dependency graph for ddhmg.c:

Go to the source code of this file.

Functions

BOOL FASTCALL VerifyObjectOwner (PDD_ENTRY pEntry)
 
BOOL FASTCALL DdHmgCreate (VOID)
 
BOOL FASTCALL DdHmgDestroy (VOID)
 
PVOID FASTCALL DdHmgLock (HANDLE DdHandle, UCHAR ObjectType, BOOLEAN LockOwned)
 
PVOID FASTCALL DdAllocateObject (ULONG objSize, UCHAR objType, BOOLEAN objZeroMemory)
 
VOID FASTCALL DdFreeObject (PVOID pObject)
 
HANDLE FASTCALL DdGetFreeHandle (UCHAR objType)
 
HANDLE FASTCALL DdHmgAlloc (ULONG objSize, CHAR objType, BOOLEAN objLock)
 
VOID FASTCALL DdHmgFree (HANDLE DdHandle)
 

Variables

ULONG gcSizeDdHmgr = 1024
 
PDD_ENTRY gpentDdHmgr = NULL
 
ULONG gcMaxDdHmgr = 0
 
PDD_ENTRY gpentDdHmgrLast = NULL
 
ULONG ghFreeDdHmgr = 0
 
HSEMAPHORE ghsemHmgr = NULL
 

Function Documentation

◆ DdAllocateObject()

PVOID FASTCALL DdAllocateObject ( ULONG  objSize,
UCHAR  objType,
BOOLEAN  objZeroMemory 
)

Definition at line 203 of file ddhmg.c.

204{
206
207 if (objZeroMemory)
208 pObject = EngAllocMem(FL_ZERO_MEMORY, objSize, ((ULONG)objType << 24) + TAG_DH_0);
209 else
210 pObject = EngAllocMem(0, objSize, ((ULONG)objType << 24) + TAG_DH_0);
211
212 if (!pObject)
213 {
215 }
216
217 return pObject;
218}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
FxObject * pObject
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_DH_0
Definition: tags.h:6
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by DdHmgAlloc().

◆ DdFreeObject()

VOID FASTCALL DdFreeObject ( PVOID  pObject)

Definition at line 235 of file ddhmg.c.

236{
238}
#define EngFreeMem
Definition: polytest.cpp:56

Referenced by DdHmgAlloc(), and DdHmgFree().

◆ DdGetFreeHandle()

HANDLE FASTCALL DdGetFreeHandle ( UCHAR  objType)

Definition at line 259 of file ddhmg.c.

260{
261 PVOID mAllocMem = NULL;
262 ULONG mAllocEntries = 0;
264 ULONG_PTR retVal;
265 ULONG index;
266
267 // check if memory is allocated
268 if (!gpentDdHmgr)
269 return 0;
270
271 // check if we reached maximum handle index
273 return 0;
274
275 // check if we have free handle to reuse
276 if (ghFreeDdHmgr)
277 {
279 pEntry = (PDD_ENTRY)((PBYTE)gpentDdHmgr + (sizeof(DD_ENTRY) * index));
280
281 // put next free index to our global variable
282 ghFreeDdHmgr = pEntry->NextFree;
283
284 // build handle
285 pEntry->FullUnique = objType | 8;
286 retVal = (pEntry->FullUnique << 21) | index;
287 return (HANDLE)retVal;
288 }
289
290 // if all pre-allocated memory is already used then allocate more
292 {
293 // allocate buffer for next 1024 handles
294 mAllocEntries = gcSizeDdHmgr + 1024;
295 mAllocMem = EngAllocMem(FL_ZERO_MEMORY, sizeof(DD_ENTRY) * (mAllocEntries), TAG_THDD);
296 if (!mAllocMem)
297 return 0;
298
299 memmove(&mAllocMem, gpentDdHmgr, sizeof(DD_ENTRY) * gcSizeDdHmgr);
300 gcSizeDdHmgr = mAllocEntries;
303 gpentDdHmgr = mAllocMem;
304 }
305
307
308 // build handle
309 pEntry->FullUnique = objType | 8;
310 retVal = (pEntry->FullUnique << 21) | gcMaxDdHmgr;
312
313 return (HANDLE)retVal;
314}
#define index(s, c)
Definition: various.h:29
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
ULONG gcMaxDdHmgr
Definition: ddhmg.c:18
ULONG ghFreeDdHmgr
Definition: ddhmg.c:22
PDD_ENTRY gpentDdHmgrLast
Definition: ddhmg.c:19
ULONG gcSizeDdHmgr
Definition: ddhmg.c:15
#define DDHMG_HANDLE_LIMIT
Definition: dxg_int.h:13
struct _DD_ENTRY * PDD_ENTRY
struct _DD_ENTRY DD_ENTRY
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
GLuint index
Definition: glext.h:6031
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
BYTE * PBYTE
Definition: pedump.c:66
Definition: dxg_int.h:63
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define TAG_THDD
Definition: tags.h:1

Referenced by DdHmgAlloc().

◆ DdHmgAlloc()

HANDLE FASTCALL DdHmgAlloc ( ULONG  objSize,
CHAR  objType,
BOOLEAN  objLock 
)

Definition at line 340 of file ddhmg.c.

341{
343 HANDLE DdHandle = NULL;
345 DWORD Index;
346
347 pObject = DdAllocateObject(objSize, objType, TRUE);
348 if (!pObject)
349 return 0;
350
352
353 /* Get next free handle */
354 DdHandle = DdGetFreeHandle(objType);
355
356 if (DdHandle)
357 {
358 Index = DDHMG_HTOI(DdHandle);
359
360 pEntry = (PDD_ENTRY)((PBYTE)gpentDdHmgr + (sizeof(DD_ENTRY) * Index));
361
362 pEntry->pobj = pObject;
363 pEntry->Objt = objType;
364
365 pEntry->Pid = (HANDLE)(((ULONG_PTR)PsGetCurrentProcessId() & 0xFFFFFFFC) | ((ULONG_PTR)(pEntry->Pid) & 1));
366
367 if (objLock)
368 {
369 InterlockedIncrement((VOID*)&pEntry->pobj->cExclusiveLock);
370 pEntry->pobj->Tid = KeGetCurrentThread();
371 }
372 pEntry->pobj->hHmgr = DdHandle;
373
375
376 /* Return handle if object not locked */
377 if (!objLock)
378 return DdHandle;
379
380 return (HANDLE)pEntry;
381 }
382
385 return 0;
386}
#define InterlockedIncrement
Definition: armddk.h:53
VOID FASTCALL DdFreeObject(PVOID pObject)
Definition: ddhmg.c:235
PVOID FASTCALL DdAllocateObject(ULONG objSize, UCHAR objType, BOOLEAN objZeroMemory)
Definition: ddhmg.c:203
HANDLE FASTCALL DdGetFreeHandle(UCHAR objType)
Definition: ddhmg.c:259
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
#define TRUE
Definition: types.h:120
#define DDHMG_HTOI(DdHandle)
Definition: dxg_int.h:14
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
#define KeGetCurrentThread
Definition: hal.h:55
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
PVOID HANDLE
Definition: typedefs.h:73
_In_ WDFCOLLECTION _In_ ULONG Index
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)

Referenced by intDdCreateDirectDrawLocal(), and intDdCreateNewSurfaceObject().

◆ DdHmgCreate()

BOOL FASTCALL DdHmgCreate ( VOID  )

Definition at line 49 of file ddhmg.c.

50{
52 ghFreeDdHmgr = 0;
53 gcMaxDdHmgr = 1;
54
55 if (gpentDdHmgr)
56 {
58
59 if (ghsemHmgr)
60 {
62
64 {
66 return TRUE;
67 }
68
71 }
72
75 }
76
77 return FALSE;
78}
#define FALSE
Definition: types.h:117
PLARGE_INTEGER gpLockShortDelay
Definition: main.c:18
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
#define TAG_GINI
Definition: tags.h:2
_Requires_lock_not_held_ hsem ENGAPI VOID APIENTRY EngDeleteSemaphore(_Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
Definition: semaphor.c:106
#define FL_NONPAGED_MEMORY
Definition: winddi.h:1359

Referenced by DxDdStartupDxGraphics().

◆ DdHmgDestroy()

BOOL FASTCALL DdHmgDestroy ( VOID  )

Definition at line 95 of file ddhmg.c.

96{
97 gcMaxDdHmgr = 0;
98 gcSizeDdHmgr = 0;
99 ghFreeDdHmgr = 0;
101
102 if (gpentDdHmgr)
103 {
106 }
107
108 if (ghsemHmgr)
109 {
111 ghsemHmgr = NULL;
112 }
113
114 return TRUE;
115}

Referenced by DxDdCleanupDxGraphics(), and DxDdStartupDxGraphics().

◆ DdHmgFree()

VOID FASTCALL DdHmgFree ( HANDLE  DdHandle)

Definition at line 403 of file ddhmg.c.

404{
406
407 DWORD Index = DDHMG_HTOI(DdHandle);
408
410
411 pEntry = (PDD_ENTRY)((PBYTE)gpentDdHmgr + (sizeof(DD_ENTRY) * Index));
412
413 // check if we have object that should be freed
414 if (pEntry->pobj)
415 DdFreeObject(pEntry->pobj);
416
417 pEntry->NextFree = ghFreeDdHmgr;
418
419 // reset process ID
420 pEntry->Pid = (HANDLE)((DWORD_PTR)pEntry->Pid & 1);
422
424}
uint32_t DWORD_PTR
Definition: typedefs.h:65

◆ DdHmgLock()

PVOID FASTCALL DdHmgLock ( HANDLE  DdHandle,
UCHAR  ObjectType,
BOOLEAN  LockOwned 
)

Definition at line 147 of file ddhmg.c.

148{
149 DWORD Index = DDHMG_HTOI(DdHandle);
150
152 PVOID Object = NULL;
153
154 if ( !LockOwned )
155 {
157 }
158
159 if ( Index < gcMaxDdHmgr )
160 {
161 pEntry = (PDD_ENTRY)((PBYTE)gpentDdHmgr + (sizeof(DD_ENTRY) * Index));
162
164 {
165 if ( ( pEntry->Objt == ObjectType ) &&
166 ( pEntry->FullUnique == (((ULONG_PTR)DdHandle >> 21) & 0x7FF) ) &&
167 ( !pEntry->pobj->cExclusiveLock ) )
168 {
169 InterlockedIncrement((VOID*)&pEntry->pobj->cExclusiveLock);
170 pEntry->pobj->Tid = KeGetCurrentThread();
171 Object = pEntry->pobj;
172 }
173 }
174 }
175
176 if ( !LockOwned )
177 {
179 }
180
181 return Object;
182}
BOOL FASTCALL VerifyObjectOwner(PDD_ENTRY pEntry)
Definition: ddhmg.c:27
#define ULONG_PTR
Definition: config.h:101
ObjectType
Definition: metafile.c:81
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by DxDdCanCreateD3DBuffer(), DxDdCanCreateSurface(), DxDdCreateSurfaceObject(), DxDdGetDriverInfo(), DxDdLock(), DxDdLockDirectDrawSurface(), DxDdQueryDirectDrawObject(), DxDdReenableDirectDrawObject(), intDdCreateNewSurfaceObject(), and intDdCreateSurfaceOrBuffer().

◆ VerifyObjectOwner()

BOOL FASTCALL VerifyObjectOwner ( PDD_ENTRY  pEntry)

Definition at line 27 of file ddhmg.c.

28{
29 DWORD Pid = (DWORD)(DWORD_PTR)PsGetCurrentProcessId() & 0xFFFFFFFC;
30 DWORD check = (DWORD_PTR)pEntry->Pid & 0xFFFFFFFE;
31 return ( (check == Pid) || (!check));
32}
return
Definition: dirsup.c:529
#define check(expected, result)
Definition: dplayx.c:32
#define DWORD
Definition: nt_native.h:44
#define DWORD_PTR
Definition: treelist.c:76

Referenced by DdHmgLock().

Variable Documentation

◆ gcMaxDdHmgr

ULONG gcMaxDdHmgr = 0

Definition at line 18 of file ddhmg.c.

Referenced by DdGetFreeHandle(), DdHmgCreate(), DdHmgDestroy(), and DdHmgLock().

◆ gcSizeDdHmgr

ULONG gcSizeDdHmgr = 1024

Definition at line 15 of file ddhmg.c.

Referenced by DdGetFreeHandle(), DdHmgCreate(), and DdHmgDestroy().

◆ ghFreeDdHmgr

ULONG ghFreeDdHmgr = 0

Definition at line 22 of file ddhmg.c.

Referenced by DdGetFreeHandle(), DdHmgCreate(), DdHmgDestroy(), and DdHmgFree().

◆ ghsemHmgr

HSEMAPHORE ghsemHmgr = NULL

Definition at line 23 of file ddhmg.c.

Referenced by DdHmgAlloc(), DdHmgCreate(), DdHmgDestroy(), DdHmgFree(), and DdHmgLock().

◆ gpentDdHmgr

PDD_ENTRY gpentDdHmgr = NULL

Definition at line 16 of file ddhmg.c.

Referenced by DdGetFreeHandle(), DdHmgAlloc(), DdHmgCreate(), DdHmgDestroy(), DdHmgFree(), and DdHmgLock().

◆ gpentDdHmgrLast

PDD_ENTRY gpentDdHmgrLast = NULL

Definition at line 19 of file ddhmg.c.

Referenced by DdGetFreeHandle(), and DdHmgDestroy().