ReactOS  0.4.14-dev-49-gfb4591c
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 {
205  PVOID pObject = NULL;
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
smooth NULL
Definition: ftsmooth.c:416
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
#define TAG_DH_0
Definition: tags.h:6
unsigned int ULONG
Definition: retypes.h:1
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

Referenced by DdHmgAlloc().

◆ DdFreeObject()

VOID FASTCALL DdFreeObject ( PVOID  pObject)

Definition at line 235 of file ddhmg.c.

236 {
237  EngFreeMem(pObject);
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;
263  PDD_ENTRY pEntry = NULL;
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
291  if (gcSizeDdHmgr == gcMaxDdHmgr)
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 
306  pEntry = (PDD_ENTRY)((PBYTE)gpentDdHmgr + (sizeof(DD_ENTRY) * gcMaxDdHmgr));
307 
308  // build handle
309  pEntry->FullUnique = objType | 8;
310  retVal = (pEntry->FullUnique << 21) | gcMaxDdHmgr;
311  gcMaxDdHmgr = gcMaxDdHmgr + 1;
312 
313  return (HANDLE)retVal;
314 }
PDD_ENTRY gpentDdHmgrLast
Definition: ddhmg.c:19
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
Definition: dxg_int.h:62
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
#define EngFreeMem
Definition: polytest.cpp:56
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
ULONG NextFree
Definition: dxg_int.h:67
USHORT FullUnique
Definition: dxg_int.h:70
GLuint index
Definition: glext.h:6031
ULONG gcMaxDdHmgr
Definition: ddhmg.c:18
struct _DD_ENTRY DD_ENTRY
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define index(s, c)
Definition: various.h:29
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
ULONG ghFreeDdHmgr
Definition: ddhmg.c:22
#define TAG_THDD
Definition: tags.h:1
ULONG gcSizeDdHmgr
Definition: ddhmg.c:15
unsigned int ULONG
Definition: retypes.h:1
struct _DD_ENTRY * PDD_ENTRY
BYTE * PBYTE
Definition: pedump.c:66
#define DDHMG_HANDLE_LIMIT
Definition: dxg_int.h:13

Referenced by DdHmgAlloc().

◆ DdHmgAlloc()

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

Definition at line 340 of file ddhmg.c.

341 {
342  PVOID pObject = NULL;
343  HANDLE DdHandle = NULL;
344  PDD_ENTRY pEntry = 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  {
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 
384  DdFreeObject(pObject);
385  return 0;
386 }
PW32THREAD Tid
Definition: dxg_int.h:41
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
Definition: dxg_int.h:62
#define TRUE
Definition: types.h:120
#define DDHMG_HTOI(DdHandle)
Definition: dxg_int.h:14
UCHAR Objt
Definition: dxg_int.h:71
VOID FASTCALL DdFreeObject(PVOID pObject)
Definition: ddhmg.c:235
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
USHORT cExclusiveLock
Definition: dxg_int.h:39
uint32_t ULONG_PTR
Definition: typedefs.h:63
PDD_BASEOBJECT pobj
Definition: dxg_int.h:66
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
PVOID FASTCALL DdAllocateObject(ULONG objSize, UCHAR objType, BOOLEAN objZeroMemory)
Definition: ddhmg.c:203
static const UCHAR Index[8]
Definition: usbohci.c:18
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _DD_ENTRY DD_ENTRY
#define InterlockedIncrement
Definition: armddk.h:53
HGDIOBJ hHmgr
Definition: dxg_int.h:37
HANDLE Pid
Definition: dxg_int.h:69
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
HANDLE FASTCALL DdGetFreeHandle(UCHAR objType)
Definition: ddhmg.c:259
struct _DD_ENTRY * PDD_ENTRY
#define KeGetCurrentThread
Definition: hal.h:44
BYTE * PBYTE
Definition: pedump.c:66

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 
63  if (gpLockShortDelay)
64  {
66  return TRUE;
67  }
68 
70  ghsemHmgr = NULL;
71  }
72 
74  gpentDdHmgr = NULL;
75  }
76 
77  return FALSE;
78 }
Definition: dxg_int.h:62
#define TRUE
Definition: types.h:120
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
#define EngFreeMem
Definition: polytest.cpp:56
_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
smooth NULL
Definition: ftsmooth.c:416
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
ULONG gcMaxDdHmgr
Definition: ddhmg.c:18
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
ULONG ghFreeDdHmgr
Definition: ddhmg.c:22
#define TAG_GINI
Definition: tags.h:2
#define TAG_THDD
Definition: tags.h:1
ULONG gcSizeDdHmgr
Definition: ddhmg.c:15
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
PLARGE_INTEGER gpLockShortDelay
Definition: main.c:18

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  {
105  gpentDdHmgr = NULL;
106  }
107 
108  if (ghsemHmgr)
109  {
111  ghsemHmgr = NULL;
112  }
113 
114  return TRUE;
115 }
PDD_ENTRY gpentDdHmgrLast
Definition: ddhmg.c:19
#define TRUE
Definition: types.h:120
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
#define EngFreeMem
Definition: polytest.cpp:56
_Requires_lock_not_held_ hsem ENGAPI VOID APIENTRY EngDeleteSemaphore(_Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
Definition: semaphor.c:106
smooth NULL
Definition: ftsmooth.c:416
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
ULONG gcMaxDdHmgr
Definition: ddhmg.c:18
ULONG ghFreeDdHmgr
Definition: ddhmg.c:22
ULONG gcSizeDdHmgr
Definition: ddhmg.c:15

Referenced by DxDdCleanupDxGraphics(), and DxDdStartupDxGraphics().

◆ DdHmgFree()

VOID FASTCALL DdHmgFree ( HANDLE  DdHandle)

Definition at line 403 of file ddhmg.c.

404 {
405  PDD_ENTRY pEntry = NULL;
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 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
Definition: dxg_int.h:62
#define DDHMG_HTOI(DdHandle)
Definition: dxg_int.h:14
VOID FASTCALL DdFreeObject(PVOID pObject)
Definition: ddhmg.c:235
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
PDD_BASEOBJECT pobj
Definition: dxg_int.h:66
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
ULONG NextFree
Definition: dxg_int.h:67
static const UCHAR Index[8]
Definition: usbohci.c:18
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _DD_ENTRY DD_ENTRY
ULONG ghFreeDdHmgr
Definition: ddhmg.c:22
uint32_t DWORD_PTR
Definition: typedefs.h:63
HANDLE Pid
Definition: dxg_int.h:69
struct _DD_ENTRY * PDD_ENTRY
BYTE * PBYTE
Definition: pedump.c:66

◆ 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 
151  PDD_ENTRY pEntry = NULL;
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 
163  if ( VerifyObjectOwner(pEntry) )
164  {
165  if ( ( pEntry->Objt == ObjectType ) &&
166  ( pEntry->FullUnique == (((ULONG_PTR)DdHandle >> 21) & 0x7FF) ) &&
167  ( !pEntry->pobj->cExclusiveLock ) )
168  {
170  pEntry->pobj->Tid = KeGetCurrentThread();
171  Object = pEntry->pobj;
172  }
173  }
174  }
175 
176  if ( !LockOwned )
177  {
179  }
180 
181  return Object;
182 }
PW32THREAD Tid
Definition: dxg_int.h:41
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
ObjectType
Definition: metafile.c:80
Definition: dxg_int.h:62
#define DDHMG_HTOI(DdHandle)
Definition: dxg_int.h:14
UCHAR Objt
Definition: dxg_int.h:71
PDD_ENTRY gpentDdHmgr
Definition: ddhmg.c:16
USHORT cExclusiveLock
Definition: dxg_int.h:39
PDD_BASEOBJECT pobj
Definition: dxg_int.h:66
BOOL FASTCALL VerifyObjectOwner(PDD_ENTRY pEntry)
Definition: ddhmg.c:27
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
HSEMAPHORE ghsemHmgr
Definition: ddhmg.c:23
USHORT FullUnique
Definition: dxg_int.h:70
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG gcMaxDdHmgr
Definition: ddhmg.c:18
struct _DD_ENTRY DD_ENTRY
static IUnknown Object
Definition: main.c:512
#define InterlockedIncrement
Definition: armddk.h:53
#define ULONG_PTR
Definition: config.h:101
struct _DD_ENTRY * PDD_ENTRY
#define KeGetCurrentThread
Definition: hal.h:44
BYTE * PBYTE
Definition: pedump.c:66

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 DWORD_PTR
Definition: treelist.c:76
#define DWORD
Definition: nt_native.h:44
unsigned long DWORD
Definition: ntddk_ex.h:95
void check(CONTEXT *pContext)
Definition: NtContinue.c:61
uint32_t DWORD_PTR
Definition: typedefs.h:63
HANDLE Pid
Definition: dxg_int.h:69
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123

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