ReactOS  0.4.13-dev-257-gfabbd7c
misc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  INTENG_ENTER_LEAVE_TAG
 

Macros

#define ExInitializePushLock   _ExInitializePushLock
 

Typedefs

typedef struct INTENG_ENTER_LEAVE_TAG INTENG_ENTER_LEAVE
 
typedef struct INTENG_ENTER_LEAVE_TAGPINTENG_ENTER_LEAVE
 
typedef struct _GDI_POOLPGDI_POOL
 

Functions

BOOL APIENTRY IntEngEnter (PINTENG_ENTER_LEAVE EnterLeave, SURFOBJ *DestObj, RECTL *DestRect, BOOL ReadOnly, POINTL *Translate, SURFOBJ **OutputObj)
 
BOOL APIENTRY IntEngLeave (PINTENG_ENTER_LEAVE EnterLeave)
 
SHORT FASTCALL UserGetLanguageID (VOID)
 
PVOID APIENTRY HackSecureVirtualMemory (IN PVOID, IN SIZE_T, IN ULONG, OUT PVOID *)
 
VOID APIENTRY HackUnsecureVirtualMemory (IN PVOID)
 
NTSTATUS NTAPI RegOpenKey (LPCWSTR pwszKeyName, PHKEY phkey)
 
NTSTATUS NTAPI RegQueryValue (IN HKEY hkey, IN PCWSTR pwszValueName, IN ULONG ulType, OUT PVOID pvData, IN OUT PULONG pcbValue)
 
VOID NTAPI RegWriteSZ (HKEY hkey, PWSTR pwszValue, PWSTR pwszData)
 
VOID NTAPI RegWriteDWORD (HKEY hkey, PWSTR pwszValue, DWORD dwData)
 
BOOL NTAPI RegReadDWORD (HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
 
VOID FASTCALL SetLastNtError (NTSTATUS Status)
 
PGDI_POOL NTAPI GdiPoolCreate (ULONG cjAllocSize, ULONG ulTag)
 
VOID NTAPI GdiPoolDestroy (PGDI_POOL pPool)
 
PVOID NTAPI GdiPoolAllocate (PGDI_POOL pPool)
 
VOID NTAPI GdiPoolFree (PGDI_POOL pPool, PVOID pvAlloc)
 
FORCEINLINE VOID ExAcquirePushLockExclusive (PEX_PUSH_LOCK PushLock)
 
FORCEINLINE BOOLEAN ExTryAcquirePushLockExclusive (PEX_PUSH_LOCK PushLock)
 
FORCEINLINE VOID ExReleasePushLockExclusive (PEX_PUSH_LOCK PushLock)
 
FORCEINLINE VOID _ExInitializePushLock (PEX_PUSH_LOCK Lock)
 
NTSTATUS FASTCALL IntSafeCopyUnicodeString (PUNICODE_STRING Dest, PUNICODE_STRING Source)
 
NTSTATUS FASTCALL IntSafeCopyUnicodeStringTerminateNULL (PUNICODE_STRING Dest, PUNICODE_STRING Source)
 
HBITMAP NTAPI UserLoadImage (PCWSTR)
 
BOOL NTAPI W32kDosPathNameToNtPathName (PCWSTR, PUNICODE_STRING)
 

Variables

HGDIOBJ StockObjects []
 
SHORT gusLanguageID
 

Macro Definition Documentation

◆ ExInitializePushLock

#define ExInitializePushLock   _ExInitializePushLock

Definition at line 127 of file misc.h.

Typedef Documentation

◆ INTENG_ENTER_LEAVE

◆ PGDI_POOL

Definition at line 61 of file misc.h.

◆ PINTENG_ENTER_LEAVE

Function Documentation

◆ _ExInitializePushLock()

FORCEINLINE VOID _ExInitializePushLock ( PEX_PUSH_LOCK  Lock)

Definition at line 123 of file misc.h.

124 {
125  *(PULONG_PTR)Lock = 0;
126 }
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
uint32_t * PULONG_PTR
Definition: typedefs.h:63

◆ ExAcquirePushLockExclusive()

FORCEINLINE VOID ExAcquirePushLockExclusive ( PEX_PUSH_LOCK  PushLock)

Definition at line 86 of file misc.h.

87 {
88  /* Try acquiring the lock */
90  {
91  /* Someone changed it, use the slow path */
93  }
94 }
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
VOID FASTCALL ExfAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:471
#define EX_PUSH_LOCK_LOCK_V
Definition: Object.c:28
signed int * PLONG
Definition: retypes.h:5

◆ ExReleasePushLockExclusive()

FORCEINLINE VOID ExReleasePushLockExclusive ( PEX_PUSH_LOCK  PushLock)

Definition at line 106 of file misc.h.

107 {
108  EX_PUSH_LOCK OldValue;
109 
110  /* Unlock the pushlock */
111  OldValue.Value = InterlockedExchangeAddSizeT((PSIZE_T)PushLock,
113  /* Check if anyone is waiting on it and it's not already waking */
114  if ((OldValue.Waiting) && !(OldValue.Waking))
115  {
116  /* Wake it up */
117  ExfTryToWakePushLock(PushLock);
118  }
119 }
ULONG_PTR Value
Definition: extypes.h:465
LONG_PTR SSIZE_T
Definition: basetsd.h:183
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
ULONG_PTR Waiting
Definition: extypes.h:460
ULONG_PTR Waking
Definition: extypes.h:461
#define EX_PUSH_LOCK_LOCK
Definition: Object.c:29
#define InterlockedExchangeAddSizeT(a, b)
Definition: interlocked.h:196
VOID FASTCALL ExfTryToWakePushLock(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:1165

◆ ExTryAcquirePushLockExclusive()

FORCEINLINE BOOLEAN ExTryAcquirePushLockExclusive ( PEX_PUSH_LOCK  PushLock)

Definition at line 98 of file misc.h.

99 {
100  /* Try acquiring the lock */
102 }
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define EX_PUSH_LOCK_LOCK_V
Definition: Object.c:28
signed int * PLONG
Definition: retypes.h:5

Referenced by GDIOBJ_TryLockObject().

◆ GdiPoolAllocate()

PVOID NTAPI GdiPoolAllocate ( PGDI_POOL  pPool)

Definition at line 122 of file gdipool.c.

124 {
125  PGDI_POOL_SECTION pSection;
126  ULONG ulIndex, cjOffset, ulPageBit;
127  PLIST_ENTRY ple;
128  PVOID pvAlloc, pvBaseAddress;
129  SIZE_T cjSize;
131 
132  /* Disable APCs and acquire the pool lock */
135 
136  /* Check if we have a ready section */
137  if (!IsListEmpty(&pPool->leReadyList))
138  {
139  /* Get a free section */
140  ple = pPool->leReadyList.Flink;
141  pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leReadyLink);
142  if (pSection->cAllocCount >= pPool->cSlotsPerSection)
143  {
144  DPRINT1("pSection->cAllocCount=%lu, pPool->cSlotsPerSection=%lu\n",
145  pSection->cAllocCount, pPool->cSlotsPerSection);
146  DBG_DUMP_EVENT_LIST(&pPool->slhLog);
147  ASSERT(FALSE);
148  }
149  ASSERT(pSection->cAllocCount < pPool->cSlotsPerSection);
150  }
151  else
152  {
153  /* No, check if we have something on the empty list */
154  if (!IsListEmpty(&pPool->leEmptyList))
155  {
156  /* Yes, remove it from the empty list */
157  ple = RemoveHeadList(&pPool->leEmptyList);
158  pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink);
159  pPool->cEmptySections--;
160  ASSERT(pSection->cAllocCount == 0);
161  }
162  else
163  {
164  /* No, allocate a new section */
165  pSection = GdiPoolAllocateSection(pPool);
166  if (!pSection)
167  {
168  DPRINT1("Couldn't allocate a section\n");
169  pvAlloc = NULL;
170  goto done;
171  }
172  }
173 
174  /* Insert it into the in-use and ready list */
175  InsertHeadList(&pPool->leInUseList, &pSection->leInUseLink);
176  InsertHeadList(&pPool->leReadyList, &pSection->leReadyLink);
177  }
178 
179  /* Find and set a single bit */
180  ulIndex = RtlFindClearBitsAndSet(&pSection->bitmap, 1, 0);
181  ASSERT(ulIndex != MAXULONG);
182 
183  /* Calculate the allocation address */
184  cjOffset = ulIndex * pPool->cjAllocSize;
185  pvAlloc = (PVOID)((ULONG_PTR)pSection->pvBaseAddress + cjOffset);
186 
187  /* Check if memory is comitted */
188  ulPageBit = 1 << (cjOffset / PAGE_SIZE);
189  ulPageBit |= 1 << ((cjOffset + pPool->cjAllocSize - 1) / PAGE_SIZE);
190  if ((pSection->ulCommitBitmap & ulPageBit) != ulPageBit)
191  {
192  /* Commit the pages */
193  pvBaseAddress = PAGE_ALIGN(pvAlloc);
195  status = ZwAllocateVirtualMemory(NtCurrentProcess(),
196  &pvBaseAddress,
197  0,
198  &cjSize,
199  MEM_COMMIT,
201  if (!NT_SUCCESS(status))
202  {
203  pvAlloc = NULL;
204  goto done;
205  }
206 
207  pSection->ulCommitBitmap |= ulPageBit;
208  }
209 
210  /* Increase alloc count */
211  pSection->cAllocCount++;
212  ASSERT(RtlNumberOfSetBits(&pSection->bitmap) == pSection->cAllocCount);
213  DBG_LOGEVENT(&pPool->slhLog, EVENT_ALLOCATE, pvAlloc);
214 
215  /* Check if section is now busy */
216  if (pSection->cAllocCount == pPool->cSlotsPerSection)
217  {
218  /* Remove the section from the ready list */
219  RemoveEntryList(&pSection->leReadyLink);
220  }
221 
222 done:
223  /* Release the pool lock and enable APCs */
226 
227  DPRINT("GdiPoolallocate: %p\n", pvAlloc);
228  return pvAlloc;
229 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
RTL_BITMAP bitmap
Definition: gdipool.c:25
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
ULONG cSlotsPerSection
Definition: gdipool.c:34
ULONG cjAllocSize
Definition: gdipool.c:32
ULONG cAllocCount
Definition: gdipool.c:23
#define MEM_COMMIT
Definition: nt_native.h:1313
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
NTSYSAPI ULONG WINAPI RtlNumberOfSetBits(PCRTL_BITMAP)
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
EX_PUSH_LOCK pushlock
Definition: gdipool.c:36
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
LIST_ENTRY leEmptyList
Definition: gdipool.c:42
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1238
LIST_ENTRY leReadyLink
Definition: gdipool.c:18
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY leInUseLink
Definition: gdipool.c:17
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define NtCurrentProcess()
Definition: nt_native.h:1657
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID pvBaseAddress
Definition: gdipool.c:20
#define PAGE_ALIGN(Va)
LIST_ENTRY leInUseList
Definition: gdipool.c:41
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DBG_DUMP_EVENT_LIST(pslh)
Definition: gdidebug.h:111
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
#define MAXULONG
Definition: typedefs.h:250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
ULONG ulIndex
Definition: symbols.c:92
ULONG ulCommitBitmap
Definition: gdipool.c:22
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
LIST_ENTRY leReadyList
Definition: gdipool.c:43
#define DPRINT1
Definition: precomp.h:8
ULONG cEmptySections
Definition: gdipool.c:35
static PGDI_POOL_SECTION GdiPoolAllocateSection(PGDI_POOL pPool)
Definition: gdipool.c:50
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
static SERVICE_STATUS status
Definition: service.c:31
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: ps.c:97

Referenced by BRUSH::bAllocateBrushAttr(), DC_bAllocDcAttr(), and REGION_bAllocRgnAttr().

◆ GdiPoolCreate()

PGDI_POOL NTAPI GdiPoolCreate ( ULONG  cjAllocSize,
ULONG  ulTag 
)

Definition at line 316 of file gdipool.c.

319 {
320  PGDI_POOL pPool;
321 
322  /* Allocate a pool object */
323  pPool = EngAllocMem(0, sizeof(GDI_POOL), 'lopG');
324  if (!pPool) return NULL;
325 
326  /* Initialize the object */
331  pPool->cEmptySections = 0;
332  pPool->cjAllocSize = cjAllocSize;
333  pPool->ulTag = ulTag;
335  pPool->cSlotsPerSection = pPool->cjSectionSize / cjAllocSize;
336  DBG_INITLOG(&pPool->slhLog);
337 
338  return pPool;
339 }
#define DBG_INITLOG(pslh)
Definition: gdidebug.h:110
#define GDI_POOL_ALLOCATION_GRANULARITY
Definition: gdipool.c:46
ULONG cSlotsPerSection
Definition: gdipool.c:34
ULONG cjAllocSize
Definition: gdipool.c:32
EX_PUSH_LOCK pushlock
Definition: gdipool.c:36
LIST_ENTRY leEmptyList
Definition: gdipool.c:42
smooth NULL
Definition: ftsmooth.c:416
#define ExInitializePushLock
Definition: ex.h:999
ULONG ulTag
Definition: gdipool.c:31
LIST_ENTRY leInUseList
Definition: gdipool.c:41
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
ULONG cjSectionSize
Definition: gdipool.c:33
_In_ ULONG _In_ ULONG ulTag
Definition: winddi.h:3941
LIST_ENTRY leReadyList
Definition: gdipool.c:43
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG cEmptySections
Definition: gdipool.c:35

Referenced by GdiProcessCreate().

◆ GdiPoolDestroy()

VOID NTAPI GdiPoolDestroy ( PGDI_POOL  pPool)

Definition at line 343 of file gdipool.c.

344 {
345  PGDI_POOL_SECTION pSection;
346  PLIST_ENTRY ple;
347 
348  /* Loop all empty sections, removing them */
349  while (!IsListEmpty(&pPool->leEmptyList))
350  {
351  /* Delete the section */
352  ple = RemoveHeadList(&pPool->leEmptyList);
353  pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink);
354  GdiPoolDeleteSection(pPool, pSection);
355  }
356 
357  /* Loop all ready sections, removing them */
358  while (!IsListEmpty(&pPool->leInUseList))
359  {
360  /* Delete the section */
361  ple = RemoveHeadList(&pPool->leInUseList);
362  pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink);
363  GdiPoolDeleteSection(pPool, pSection);
364  }
365 
366  DBG_CLEANUP_EVENT_LIST(&pPool->slhLog);
367 
368  EngFreeMem(pPool);
369 }
#define EngFreeMem
Definition: polytest.cpp:56
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY leEmptyList
Definition: gdipool.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY leInUseList
Definition: gdipool.c:41
Definition: typedefs.h:117
#define DBG_CLEANUP_EVENT_LIST(pslh)
Definition: gdidebug.h:112
static VOID GdiPoolDeleteSection(PGDI_POOL pPool, PGDI_POOL_SECTION pSection)
Definition: gdipool.c:95

Referenced by GdiProcessDestroy().

◆ GdiPoolFree()

VOID NTAPI GdiPoolFree ( PGDI_POOL  pPool,
PVOID  pvAlloc 
)

Definition at line 233 of file gdipool.c.

236 {
237  PLIST_ENTRY ple;
238  PGDI_POOL_SECTION pSection = NULL;
239  ULONG_PTR cjOffset;
240  ULONG ulIndex;
241  DPRINT("GdiPoolFree: %p\n", pvAlloc);
242 
243  /* Disable APCs and acquire the pool lock */
246 
247  /* Loop all used sections */
248  for (ple = pPool->leInUseList.Flink;
249  ple != &pPool->leInUseList;
250  ple = ple->Flink)
251  {
252  /* Get the pointer to the section */
253  pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink);
254 
255  /* Calculate offset */
256  cjOffset = (ULONG_PTR)pvAlloc - (ULONG_PTR)pSection->pvBaseAddress;
257 
258  /* Check if the allocation is from this section */
259  if (cjOffset < pPool->cjSectionSize)
260  {
261  /* Calculate the index of the allocation */
262  ulIndex = cjOffset / pPool->cjAllocSize;
263 
264  /* Mark it as free */
265  ASSERT(RtlTestBit(&pSection->bitmap, ulIndex) == TRUE);
266  RtlClearBit(&pSection->bitmap, ulIndex);
267 
268  /* Decrease allocation count */
269  pSection->cAllocCount--;
270  ASSERT(RtlNumberOfSetBits(&pSection->bitmap) == pSection->cAllocCount);
271  DBG_LOGEVENT(&pPool->slhLog, EVENT_FREE, pvAlloc);
272 
273  /* Check if the section got valid now */
274  if (pSection->cAllocCount == pPool->cSlotsPerSection - 1)
275  {
276  /* Insert it into the ready list */
277  InsertTailList(&pPool->leReadyList, &pSection->leReadyLink);
278  }
279  /* Check if it got empty now */
280  else if (pSection->cAllocCount == 0)
281  {
282  /* Remove the section from the lists */
283  RemoveEntryList(&pSection->leInUseLink);
284  RemoveEntryList(&pSection->leReadyLink);
285 
286  if (pPool->cEmptySections >= 1)
287  {
288  /* Delete the section */
289  GdiPoolDeleteSection(pPool, pSection);
290  }
291  else
292  {
293  /* Insert it into the empty list */
294  InsertHeadList(&pPool->leEmptyList, &pSection->leInUseLink);
295  pPool->cEmptySections++;
296  }
297  }
298 
299  goto done;
300  }
301  }
302 
303  DbgPrint("failed to free. pvAlloc=%p, base=%p, size=%lx\n",
304  pvAlloc, pSection ? pSection->pvBaseAddress : NULL, pPool->cjSectionSize);
305  ASSERT(FALSE);
306  // KeBugCheck()
307 
308 done:
309  /* Release the pool lock and enable APCs */
312 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
RTL_BITMAP bitmap
Definition: gdipool.c:25
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG cSlotsPerSection
Definition: gdipool.c:34
ULONG cjAllocSize
Definition: gdipool.c:32
ULONG cAllocCount
Definition: gdipool.c:23
#define InsertTailList(ListHead, Entry)
NTSYSAPI ULONG WINAPI RtlNumberOfSetBits(PCRTL_BITMAP)
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
EX_PUSH_LOCK pushlock
Definition: gdipool.c:36
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
LIST_ENTRY leEmptyList
Definition: gdipool.c:42
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1238
LIST_ENTRY leReadyLink
Definition: gdipool.c:18
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY leInUseLink
Definition: gdipool.c:17
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
PVOID pvBaseAddress
Definition: gdipool.c:20
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434
LIST_ENTRY leInUseList
Definition: gdipool.c:41
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
ULONG cjSectionSize
Definition: gdipool.c:33
Definition: typedefs.h:117
ULONG ulIndex
Definition: symbols.c:92
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
LIST_ENTRY leReadyList
Definition: gdipool.c:43
ULONG cEmptySections
Definition: gdipool.c:35
unsigned int ULONG
Definition: retypes.h:1
static VOID GdiPoolDeleteSection(PGDI_POOL pPool, PGDI_POOL_SECTION pSection)
Definition: gdipool.c:95
#define ULONG_PTR
Definition: config.h:101

Referenced by DC_vFreeDcAttr(), IntGdiSetRegionOwner(), REGION_vCleanup(), and BRUSH::~BRUSH().

◆ HackSecureVirtualMemory()

PVOID APIENTRY HackSecureVirtualMemory ( IN  PVOID,
IN  SIZE_T,
IN  ULONG,
OUT PVOID  
)

Definition at line 113 of file mem.c.

118 {
120  PMDL pmdl;
122 
125  else return NULL;
126 
128  if (pmdl == NULL)
129  {
130  return NULL;
131  }
132 
133  _SEH2_TRY
134  {
136  }
138  {
140  }
141  _SEH2_END
142 
143  if (!NT_SUCCESS(Status))
144  {
145  IoFreeMdl(pmdl);
146  return NULL;
147  }
148 
149  *SafeAddress = MmGetSystemAddressForMdlSafe(pmdl, NormalPagePriority);
150 
151  if(!*SafeAddress)
152  {
153  MmUnlockPages(pmdl);
154  IoFreeMdl(pmdl);
155  return NULL;
156  }
157 
158  return pmdl;
159 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ _In_ ULONG ProbeMode
Definition: mmfuncs.h:562
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
enum _LOCK_OPERATION LOCK_OPERATION
#define PAGE_READONLY
Definition: compat.h:127
unsigned int ULONG
Definition: retypes.h:1
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ HackUnsecureVirtualMemory()

VOID APIENTRY HackUnsecureVirtualMemory ( IN  PVOID)

Definition at line 163 of file mem.c.

165 {
166  PMDL pmdl = (PMDL)SecureHandle;
167 
168  MmUnlockPages(pmdl);
169  IoFreeMdl(pmdl);
170 }
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
PVOID PMDL
Definition: usb.h:39
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146

◆ IntEngEnter()

BOOL APIENTRY IntEngEnter ( PINTENG_ENTER_LEAVE  EnterLeave,
SURFOBJ DestObj,
RECTL DestRect,
BOOL  ReadOnly,
POINTL Translate,
SURFOBJ **  OutputObj 
)

Definition at line 15 of file engmisc.c.

21 {
22  LONG Exchange;
23  SIZEL BitmapSize;
24  POINTL SrcPoint;
25  LONG Width;
26  RECTL ClippedDestRect;
27 
28  /* Normalize */
29  if (DestRect->right < DestRect->left)
30  {
31  Exchange = DestRect->left;
32  DestRect->left = DestRect->right;
33  DestRect->right = Exchange;
34  }
35  if (DestRect->bottom < DestRect->top)
36  {
37  Exchange = DestRect->top;
38  DestRect->top = DestRect->bottom;
39  DestRect->bottom = Exchange;
40  }
41 
42  if (NULL != psoDest && STYPE_BITMAP != psoDest->iType &&
43  (NULL == psoDest->pvScan0 || 0 == psoDest->lDelta))
44  {
45  /* Driver needs to support DrvCopyBits, else we can't do anything */
46  SURFACE *psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
47  if (!(psurfDest->flags & HOOK_COPYBITS))
48  {
49  return FALSE;
50  }
51 
52  /* Allocate a temporary bitmap */
53  BitmapSize.cx = DestRect->right - DestRect->left;
54  BitmapSize.cy = DestRect->bottom - DestRect->top;
55  Width = WIDTH_BYTES_ALIGN32(BitmapSize.cx, BitsPerFormat(psoDest->iBitmapFormat));
56  EnterLeave->OutputBitmap = EngCreateBitmap(BitmapSize, Width,
57  psoDest->iBitmapFormat,
59 
60  if (!EnterLeave->OutputBitmap)
61  {
62  DPRINT1("EngCreateBitmap() failed\n");
63  return FALSE;
64  }
65 
66  *ppsoOutput = EngLockSurface((HSURF)EnterLeave->OutputBitmap);
67  if (*ppsoOutput == NULL)
68  {
69  EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
70  return FALSE;
71  }
72 
73  EnterLeave->DestRect.left = 0;
74  EnterLeave->DestRect.top = 0;
75  EnterLeave->DestRect.right = BitmapSize.cx;
76  EnterLeave->DestRect.bottom = BitmapSize.cy;
77  SrcPoint.x = DestRect->left;
78  SrcPoint.y = DestRect->top;
79  ClippedDestRect = EnterLeave->DestRect;
80  if (SrcPoint.x < 0)
81  {
82  ClippedDestRect.left -= SrcPoint.x;
83  SrcPoint.x = 0;
84  }
85  if (psoDest->sizlBitmap.cx < SrcPoint.x + ClippedDestRect.right - ClippedDestRect.left)
86  {
87  ClippedDestRect.right = ClippedDestRect.left + psoDest->sizlBitmap.cx - SrcPoint.x;
88  }
89  if (SrcPoint.y < 0)
90  {
91  ClippedDestRect.top -= SrcPoint.y;
92  SrcPoint.y = 0;
93  }
94  if (psoDest->sizlBitmap.cy < SrcPoint.y + ClippedDestRect.bottom - ClippedDestRect.top)
95  {
96  ClippedDestRect.bottom = ClippedDestRect.top + psoDest->sizlBitmap.cy - SrcPoint.y;
97  }
98  EnterLeave->TrivialClipObj = EngCreateClip();
99  if (EnterLeave->TrivialClipObj == NULL)
100  {
101  EngUnlockSurface(*ppsoOutput);
102  EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
103  return FALSE;
104  }
105  EnterLeave->TrivialClipObj->iDComplexity = DC_TRIVIAL;
106  if (ClippedDestRect.left < (*ppsoOutput)->sizlBitmap.cx &&
107  0 <= ClippedDestRect.right &&
108  SrcPoint.x < psoDest->sizlBitmap.cx &&
109  ClippedDestRect.top <= (*ppsoOutput)->sizlBitmap.cy &&
110  0 <= ClippedDestRect.bottom &&
111  SrcPoint.y < psoDest->sizlBitmap.cy &&
112  ! GDIDEVFUNCS(psoDest).CopyBits(
113  *ppsoOutput, psoDest,
114  EnterLeave->TrivialClipObj, NULL,
115  &ClippedDestRect, &SrcPoint))
116  {
117  EngDeleteClip(EnterLeave->TrivialClipObj);
118  EngUnlockSurface(*ppsoOutput);
119  EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
120  return FALSE;
121  }
122  EnterLeave->DestRect.left = DestRect->left;
123  EnterLeave->DestRect.top = DestRect->top;
124  EnterLeave->DestRect.right = DestRect->right;
125  EnterLeave->DestRect.bottom = DestRect->bottom;
126  Translate->x = - DestRect->left;
127  Translate->y = - DestRect->top;
128  }
129  else
130  {
131  Translate->x = 0;
132  Translate->y = 0;
133  *ppsoOutput = psoDest;
134  }
135 
136  if (NULL != *ppsoOutput)
137  {
138  SURFACE* psurfOutput = CONTAINING_RECORD(*ppsoOutput, SURFACE, SurfObj);
139  if (0 != (psurfOutput->flags & HOOK_SYNCHRONIZE))
140  {
141  if (NULL != GDIDEVFUNCS(*ppsoOutput).SynchronizeSurface)
142  {
143  GDIDEVFUNCS(*ppsoOutput).SynchronizeSurface(*ppsoOutput, DestRect, 0);
144  }
145  else if (STYPE_BITMAP == (*ppsoOutput)->iType
146  && NULL != GDIDEVFUNCS(*ppsoOutput).Synchronize)
147  {
148  GDIDEVFUNCS(*ppsoOutput).Synchronize((*ppsoOutput)->dhpdev, DestRect);
149  }
150  }
151  }
152  else return FALSE;
153 
154  EnterLeave->DestObj = psoDest;
155  EnterLeave->OutputObj = *ppsoOutput;
156  EnterLeave->ReadOnly = ReadOnly;
157 
158  return TRUE;
159 }
SURFOBJ * OutputObj
Definition: misc.h:7
#define TRUE
Definition: types.h:120
ENGAPI BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:564
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
#define STYPE_BITMAP
Definition: winddi.h:1175
#define BitsPerFormat(Format)
Definition: surface.h:109
Definition: arc.h:80
#define DC_TRIVIAL
Definition: winddi.h:259
#define BMF_TOPDOWN
Definition: winddi.h:1180
long bottom
Definition: polytest.cpp:53
ENGAPI CLIPOBJ *APIENTRY EngCreateClip(VOID)
Definition: clip.c:222
SURFOBJ * DestObj
Definition: misc.h:6
LONG y
Definition: windef.h:315
long right
Definition: polytest.cpp:53
long LONG
Definition: pedump.c:60
long top
Definition: polytest.cpp:53
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
long left
Definition: polytest.cpp:53
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
#define GDIDEVFUNCS(SurfObj)
Definition: surface.h:106
LONG x
Definition: windef.h:314
ENGAPI SURFOBJ *APIENTRY EngLockSurface(_In_ HSURF hsurf)
Definition: surface.c:604
#define BMF_NOZEROINIT
Definition: winddi.h:1181
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
#define HOOK_COPYBITS
Definition: winddi.h:1429
BYTE iDComplexity
Definition: winddi.h:278
FLONG flags
Definition: surface.h:10
ENGAPI VOID APIENTRY EngUnlockSurface(_In_ _Post_ptr_invalid_ SURFOBJ *pso)
Definition: surface.c:625
CLIPOBJ * TrivialClipObj
Definition: misc.h:9
HBITMAP OutputBitmap
Definition: misc.h:8
#define DPRINT1
Definition: precomp.h:8
ENGAPI VOID APIENTRY EngDeleteClip(_In_ _Post_ptr_invalid_ CLIPOBJ *pco)
Definition: clip.c:241
LONG cy
Definition: windef.h:320
ENGAPI HBITMAP APIENTRY EngCreateBitmap(_In_ SIZEL sizl, _In_ LONG lWidth, _In_ ULONG iFormat, _In_ FLONG fl, _In_opt_ PVOID pvBits)

Referenced by EngAlphaBlend(), EngLineTo(), EngMaskBitBlt(), EngStretchBltROP(), EngTransparentBlt(), IntEngGradientFillRect(), and IntEngGradientFillTriangle().

◆ IntEngLeave()

BOOL APIENTRY IntEngLeave ( PINTENG_ENTER_LEAVE  EnterLeave)

Definition at line 162 of file engmisc.c.

163 {
164  POINTL SrcPoint;
165  BOOL Result = TRUE;
166 
167  if (EnterLeave->OutputObj != EnterLeave->DestObj && NULL != EnterLeave->OutputObj)
168  {
169  if (! EnterLeave->ReadOnly)
170  {
171  SrcPoint.x = 0;
172  SrcPoint.y = 0;
173  if (EnterLeave->DestRect.left < 0)
174  {
175  SrcPoint.x = - EnterLeave->DestRect.left;
176  EnterLeave->DestRect.left = 0;
177  }
178  if (EnterLeave->DestObj->sizlBitmap.cx < EnterLeave->DestRect.right)
179  {
180  EnterLeave->DestRect.right = EnterLeave->DestObj->sizlBitmap.cx;
181  }
182  if (EnterLeave->DestRect.top < 0)
183  {
184  SrcPoint.y = - EnterLeave->DestRect.top;
185  EnterLeave->DestRect.top = 0;
186  }
187  if (EnterLeave->DestObj->sizlBitmap.cy < EnterLeave->DestRect.bottom)
188  {
189  EnterLeave->DestRect.bottom = EnterLeave->DestObj->sizlBitmap.cy;
190  }
191  if (SrcPoint.x < EnterLeave->OutputObj->sizlBitmap.cx &&
192  EnterLeave->DestRect.left <= EnterLeave->DestRect.right &&
193  EnterLeave->DestRect.left < EnterLeave->DestObj->sizlBitmap.cx &&
194  SrcPoint.y < EnterLeave->OutputObj->sizlBitmap.cy &&
195  EnterLeave->DestRect.top <= EnterLeave->DestRect.bottom &&
196  EnterLeave->DestRect.top < EnterLeave->DestObj->sizlBitmap.cy)
197  {
198  Result = GDIDEVFUNCS(EnterLeave->DestObj).CopyBits(
199  EnterLeave->DestObj,
200  EnterLeave->OutputObj,
201  EnterLeave->TrivialClipObj, NULL,
202  &EnterLeave->DestRect, &SrcPoint);
203  }
204  else
205  {
206  Result = TRUE;
207  }
208  }
209  EngUnlockSurface(EnterLeave->OutputObj);
210  EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
211  EngDeleteClip(EnterLeave->TrivialClipObj);
212  }
213  else
214  {
215  Result = TRUE;
216  }
217 
218  return Result;
219 }
SURFOBJ * OutputObj
Definition: misc.h:7
#define TRUE
Definition: types.h:120
SIZEL sizlBitmap
Definition: winddi.h:1209
ENGAPI BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:564
long bottom
Definition: polytest.cpp:53
SURFOBJ * DestObj
Definition: misc.h:6
LONG y
Definition: windef.h:315
long right
Definition: polytest.cpp:53
unsigned int BOOL
Definition: ntddk_ex.h:94
long top
Definition: polytest.cpp:53
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LONG cx
Definition: windef.h:319
long left
Definition: polytest.cpp:53
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
#define GDIDEVFUNCS(SurfObj)
Definition: surface.h:106
LONG x
Definition: windef.h:314
ENGAPI VOID APIENTRY EngUnlockSurface(_In_ _Post_ptr_invalid_ SURFOBJ *pso)
Definition: surface.c:625
CLIPOBJ * TrivialClipObj
Definition: misc.h:9
HBITMAP OutputBitmap
Definition: misc.h:8
ENGAPI VOID APIENTRY EngDeleteClip(_In_ _Post_ptr_invalid_ CLIPOBJ *pco)
Definition: clip.c:241
LONG cy
Definition: windef.h:320

Referenced by EngAlphaBlend(), EngLineTo(), EngMaskBitBlt(), EngStretchBltROP(), EngTransparentBlt(), IntEngGradientFillRect(), and IntEngGradientFillTriangle().

◆ IntSafeCopyUnicodeString()

NTSTATUS FASTCALL IntSafeCopyUnicodeString ( PUNICODE_STRING  Dest,
PUNICODE_STRING  Source 
)

Definition at line 611 of file misc.c.

613 {
615  PWSTR Src;
616 
617  Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING));
618  if(!NT_SUCCESS(Status))
619  {
620  return Status;
621  }
622 
623  if(Dest->Length > 0x4000)
624  {
625  return STATUS_UNSUCCESSFUL;
626  }
627 
628  Src = Dest->Buffer;
629  Dest->Buffer = NULL;
630  Dest->MaximumLength = Dest->Length;
631 
632  if(Dest->Length > 0 && Src)
633  {
635  if(!Dest->Buffer)
636  {
637  return STATUS_NO_MEMORY;
638  }
639 
640  Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
641  if(!NT_SUCCESS(Status))
642  {
644  Dest->Buffer = NULL;
645  return Status;
646  }
647 
648 
649  return STATUS_SUCCESS;
650  }
651 
652  /* String is empty */
653  return STATUS_SUCCESS;
654 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_STRING
Definition: oslist.c:24
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
#define MmCopyFromCaller
Definition: polytest.cpp:29
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ IntSafeCopyUnicodeStringTerminateNULL()

NTSTATUS FASTCALL IntSafeCopyUnicodeStringTerminateNULL ( PUNICODE_STRING  Dest,
PUNICODE_STRING  Source 
)

Definition at line 657 of file misc.c.

659 {
661  PWSTR Src;
662 
663  Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING));
664  if(!NT_SUCCESS(Status))
665  {
666  return Status;
667  }
668 
669  if(Dest->Length > 0x4000)
670  {
671  return STATUS_UNSUCCESSFUL;
672  }
673 
674  Src = Dest->Buffer;
675  Dest->Buffer = NULL;
676  Dest->MaximumLength = 0;
677 
678  if(Dest->Length > 0 && Src)
679  {
680  Dest->MaximumLength = Dest->Length + sizeof(WCHAR);
682  if(!Dest->Buffer)
683  {
684  return STATUS_NO_MEMORY;
685  }
686 
687  Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
688  if(!NT_SUCCESS(Status))
689  {
691  Dest->Buffer = NULL;
692  return Status;
693  }
694 
695  /* Make sure the string is null-terminated */
696  Src = (PWSTR)((PBYTE)Dest->Buffer + Dest->Length);
697  *Src = L'\0';
698 
699  return STATUS_SUCCESS;
700  }
701 
702  /* String is empty */
703  return STATUS_SUCCESS;
704 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_STRING
Definition: oslist.c:24
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
#define MmCopyFromCaller
Definition: polytest.cpp:29
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2745
BYTE * PBYTE
Definition: pedump.c:66

Referenced by InitThreadCallback(), and NtUserRegisterWindowMessage().

◆ RegOpenKey()

NTSTATUS NTAPI RegOpenKey ( LPCWSTR  pwszKeyName,
PHKEY  phkey 
)

Definition at line 16 of file registry.c.

19 {
22  UNICODE_STRING ustrKeyName;
23  HKEY hkey;
24 
25  /* Initialize the key name */
26  RtlInitUnicodeString(&ustrKeyName, pwszKeyName);
27 
28  /* Initialize object attributes */
30  &ustrKeyName,
32  NULL,
33  NULL);
34 
35  /* Open the key */
36  Status = ZwOpenKey((PHANDLE)&hkey, KEY_READ, &ObjectAttributes);
37  if (NT_SUCCESS(Status))
38  {
39  *phkey = hkey;
40  }
41 
42  return Status;
43 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
Status
Definition: gdiplustypes.h:24
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

◆ RegQueryValue()

NTSTATUS NTAPI RegQueryValue ( IN HKEY  hkey,
IN PCWSTR  pwszValueName,
IN ULONG  ulType,
OUT PVOID  pvData,
IN OUT PULONG  pcbValue 
)

Definition at line 47 of file registry.c.

53 {
55  UNICODE_STRING ustrValueName;
56  BYTE ajBuffer[100];
58  ULONG cbInfoSize, cbDataSize;
59 
60  /* Check if the local buffer is sufficient */
61  cbInfoSize = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[*pcbValue]);
62  if (cbInfoSize <= sizeof(ajBuffer))
63  {
64  pInfo = (PVOID)ajBuffer;
65  }
66  else
67  {
68  /* It's not, allocate a sufficient buffer */
69  pInfo = ExAllocatePoolWithTag(PagedPool, cbInfoSize, TAG_TEMP);
70  if (!pInfo)
71  {
73  }
74  }
75 
76  /* Query the value */
77  RtlInitUnicodeString(&ustrValueName, pwszValueName);
78  Status = ZwQueryValueKey(hkey,
79  &ustrValueName,
81  (PVOID)pInfo,
82  cbInfoSize,
83  &cbInfoSize);
84 
85  /* Note: STATUS_BUFFER_OVERFLOW is not a success */
86  if (NT_SUCCESS(Status))
87  {
88  cbDataSize = pInfo->DataLength;
89 
90  /* Did we get the right type */
91  if (pInfo->Type != ulType)
92  {
94  }
95  else if (cbDataSize > *pcbValue)
96  {
98  }
99  else
100  {
101  /* Copy the contents to the caller */
102  RtlCopyMemory(pvData, pInfo->Data, cbDataSize);
103  }
104  }
106  {
107  _PRAGMA_WARNING_SUPPRESS(6102); /* cbInfoSize is initialized here! */
108  cbDataSize = cbInfoSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
109  }
110  else
111  {
112  cbDataSize = 0;
113  }
114 
115  /* Return the data size to the caller */
116  *pcbValue = cbDataSize;
117 
118  /* Cleanup */
119  if (pInfo != (PVOID)ajBuffer)
120  ExFreePoolWithTag(pInfo, TAG_TEMP);
121 
122  return Status;
123 
124 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
static PVOID
Definition: registry.c:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:259
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_z_ PCWSTR pwszValueName
Definition: ntuser.h:36
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_In_z_ PCWSTR _In_ ULONG ulType
Definition: ntuser.h:36
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TAG_TEMP
Definition: tags.h:43
#define _PRAGMA_WARNING_SUPPRESS(x)
Definition: suppress.h:28

◆ RegReadDWORD()

BOOL NTAPI RegReadDWORD ( HKEY  hkey,
PWSTR  pwszValue,
PDWORD  pdwData 
)

Definition at line 150 of file registry.c.

151 {
153  ULONG cbSize = sizeof(DWORD);
154  Status = RegQueryValue(hkey, pwszValue, REG_DWORD, pdwData, &cbSize);
155  return NT_SUCCESS(Status);
156 }
static DWORD
Definition: registry.c:44
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
LONG RegQueryValue(_In_ HKEY Key, _In_z_ PCWSTR ValueName, _Out_opt_ ULONG *Type, _Out_opt_ PUCHAR Data, _Inout_opt_ ULONG *DataSize)
Definition: registry.c:435
unsigned int ULONG
Definition: retypes.h:1
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by InitMetrics(), InitUserImpl(), and InitVideo().

◆ RegWriteDWORD()

VOID NTAPI RegWriteDWORD ( HKEY  hkey,
PWSTR  pwszValue,
DWORD  dwData 
)

Definition at line 140 of file registry.c.

141 {
142  UNICODE_STRING ustrValue;
143 
144  RtlInitUnicodeString(&ustrValue, pwszValue);
145  ZwSetValueKey(hkey, &ustrValue, 0, REG_DWORD, &dwData, sizeof(DWORD));
146 }
static HANDLE ULONG_PTR dwData
Definition: file.c:35
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by RegWriteDisplaySettings().

◆ RegWriteSZ()

VOID NTAPI RegWriteSZ ( HKEY  hkey,
PWSTR  pwszValue,
PWSTR  pwszData 
)

Definition at line 128 of file registry.c.

129 {
130  UNICODE_STRING ustrValue;
131  UNICODE_STRING ustrData;
132 
133  RtlInitUnicodeString(&ustrValue, pwszValue);
134  RtlInitUnicodeString(&ustrData, pwszData);
135  ZwSetValueKey(hkey, &ustrValue, 0, REG_SZ, &ustrData, ustrData.Length + sizeof(WCHAR));
136 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_SZ
Definition: layer.c:22

◆ SetLastNtError()

VOID FASTCALL SetLastNtError ( NTSTATUS  Status)

Definition at line 36 of file error.c.

37 {
39 }
VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
Status
Definition: gdiplustypes.h:24
ULONG NTAPI RtlNtStatusToDosError(IN NTSTATUS Status)
Definition: error.c:96

Referenced by _Success_(), co_IntSendMessageTimeoutSingle(), co_IntWaitMessage(), ftGdiGetTextMetricsW(), IntAddAtom(), IntCreateClass(), IntCreateDesktop(), IntCreateWindow(), IntCreateWindowStation(), IntGetAtomName(), IntGetMenuItemInfo(), IntGetWinStaForCbAccess(), IntRegisterClassAtom(), IntResolveDesktop(), IntSetClassMenuName(), IntSetMenuItemInfo(), IntSetThreadDesktop(), IntValidateDesktopHandle(), IntValidateWindowStationHandle(), NtGdiCreateColorSpace(), NtGdiCreateDIBitmapInternal(), NtGdiCreateDIBSection(), NtGdiExtCreatePen(), NtGdiExtCreateRegion(), NtGdiExtEscape(), NtGdiGetCharABCWidthsW(), NtGdiGetDCDword(), NtGdiGetDeviceGammaRamp(), NtGdiGetFontResourceInfoInternalW(), NtGdiGetPath(), NtGdiGetRasterizerCaps(), NtGdiGetRealizationInfo(), NtGdiGetTextCharsetInfo(), NtGdiGetTextExtentExW(), NtGdiGetTextFaceW(), NtGdiGetTextMetricsW(), NtGdiGradientFill(), NtGdiOffsetViewportOrgEx(), NtGdiOffsetWindowOrgEx(), NtGdiOpenDCW(), NtGdiPolyDraw(), NtGdiPolyPatBlt(), NtGdiRectVisible(), NtGdiScaleViewportExtEx(), NtGdiScaleWindowExtEx(), NtGdiSetDeviceGammaRamp(), NtGdiSetMiterLimit(), NtGdiSetViewportOrgEx(), NtGdiSetWindowOrgEx(), NtUserBeginPaint(), NtUserBuildHwndList(), NtUserCallOneParam(), NtUserChangeDisplaySettings(), NtUserCloseDesktop(), NtUserCloseWindowStation(), NtUserCopyAcceleratorTable(), NtUserCreateAcceleratorTable(), NtUserCreateWindowEx(), NtUserCreateWindowStation(), NtUserDefSetText(), NtUserDispatchMessage(), NtUserDrawCaptionTemp(), NtUserDrawMenuBarTemp(), NtUserEnumDisplayMonitors(), NtUserFindWindowEx(), NtUserFlashWindowEx(), NtUserGetCaretPos(), NtUserGetClassInfo(), NtUserGetClassName(), NtUserGetClipboardData(), NtUserGetClipboardFormatName(), NtUserGetClipCursor(), NtUserGetComboBoxInfo(), NtUserGetCursorFrameInfo(), NtUserGetCursorInfo(), NtUserGetGuiResources(), NtUserGetGUIThreadInfo(), NtUserGetIconSize(), NtUserGetInternalWindowPos(), NtUserGetKeyboardLayoutList(), NtUserGetKeyboardLayoutName(), NtUserGetKeyboardState(), NtUserGetKeyNameText(), NtUserGetLayeredWindowAttributes(), NtUserGetListBoxInfo(), NtUserGetMenuBarInfo(), NtUserGetMenuItemRect(), NtUserGetMessage(), NtUserGetMonitorInfo(), NtUserGetMouseMovePointsEx(), NtUserGetObjectInformation(), NtUserGetPriorityClipboardFormat(), NtUserGetScrollBarInfo(), NtUserGetWindowPlacement(), NtUserGetWOWClass(), NtUserInitializeClientPfnArrays(), NtUserInternalGetWindowText(), NtUserLoadKeyboardLayoutEx(), NtUserLockWindowStation(), NtUserMonitorFromRect(), NtUserOpenDesktop(), NtUserOpenWindowStation(), NtUserPeekMessage(), NtUserPostThreadMessage(), NtUserProcessConnect(), NtUserRegisterClassExWOW(), NtUserRegisterWindowMessage(), NtUserSBGetParms(), NtUserScrollDC(), NtUserScrollWindowEx(), NtUserSendInput(), NtUserSetClassLong(), NtUserSetClipboardData(), NtUserSetCursorIconData(), NtUserSetInternalWindowPos(), NtUserSetKeyboardState(), NtUserSetObjectInformation(), NtUserSetScrollBarInfo(), NtUserSetScrollInfo(), NtUserSetShellWindowEx(), NtUserSetSysColors(), NtUserSetWindowPlacement(), NtUserSetWindowsHookEx(), NtUserThunkedMenuItemInfo(), NtUserToUnicodeEx(), NtUserTrackMouseEvent(), NtUserTranslateAccelerator(), NtUserTranslateMessage(), NtUserUnlockWindowStation(), NtUserUnregisterClass(), NtUserWaitForInputIdle(), SpiMemCopy(), UserCreateHeap(), UserCreateMenu(), UserFreeHandle(), UserGetClassName(), UserGetShellWindow(), UserInsertMenuItem(), UserMenuInfo(), UserMenuItemInfo(), UserObjectInDestroy(), UserOpenInputDesktop(), UserSetProcessWindowStation(), W32kCreateFileSection(), W32kMapViewOfSection(), and W32kOpenFile().

◆ UserGetLanguageID()

SHORT FASTCALL UserGetLanguageID ( VOID  )

Definition at line 96 of file misc.c.

97 {
99  OBJECT_ATTRIBUTES ObAttr;
100 // http://support.microsoft.com/kb/324097
104  UNICODE_STRING Language;
105 
106  RtlInitUnicodeString( &Language,
107  L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\Language");
108 
110  &Language,
112  NULL,
113  NULL);
114 
115  if ( NT_SUCCESS(ZwOpenKey(&KeyHandle, KEY_READ, &ObAttr)))
116  {
118  if ( pKeyInfo )
119  {
120  RtlInitUnicodeString(&Language, L"Default");
121 
122  if ( NT_SUCCESS(ZwQueryValueKey( KeyHandle,
123  &Language,
125  pKeyInfo,
126  Size,
127  &Size)) )
128  {
129  RtlInitUnicodeString(&Language, (PWSTR)pKeyInfo->Data);
130  if (!NT_SUCCESS(RtlUnicodeStringToInteger(&Language, 16, &Ret)))
131  {
133  }
134  }
135  ExFreePoolWithTag(pKeyInfo, TAG_STRING);
136  }
138  }
139  TRACE("Language ID = %x\n",Ret);
140  return (SHORT) Ret;
141 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define TAG_STRING
Definition: oslist.c:24
uint16_t * PWSTR
Definition: typedefs.h:54
#define SUBLANG_DEFAULT
Definition: nls.h:168
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define LANG_ENGLISH
Definition: nls.h:52
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
unsigned int ULONG
Definition: retypes.h:1
#define MAKELANGID(p, s)
Definition: nls.h:15
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by DriverEntry().

◆ UserLoadImage()

HBITMAP NTAPI UserLoadImage ( PCWSTR  )

Definition at line 155 of file file.c.

156 {
159  BITMAPFILEHEADER *pbmfh;
161  PVOID pvBits;
162  HBITMAP hbmp = 0;
163 
164  DPRINT("Enter UserLoadImage(%ls)\n", pwszName);
165 
166  /* Open the file */
167  hFile = W32kOpenFile(pwszName, FILE_READ_DATA);
168  if (!hFile)
169  {
170  return NULL;
171  }
172 
173  /* Create a section */
175  ZwClose(hFile);
176  if (!hSection)
177  {
178  return NULL;
179  }
180 
181  /* Map the section */
183  ZwClose(hSection);
184  if (!pbmfh)
185  {
186  return NULL;
187  }
188 
189  /* Get a pointer to the BITMAPINFO */
190  pbmi = (LPBITMAPINFO)(pbmfh + 1);
191 
192  _SEH2_TRY
193  {
194  ProbeForRead(&pbmfh->bfSize, sizeof(DWORD), 1);
195  ProbeForRead(pbmfh, pbmfh->bfSize, 1);
196  }
198  {
200  }
201  _SEH2_END
202 
203  if(!NT_SUCCESS(Status))
204  {
205  DPRINT1("Bad File?\n");
206  goto leave;
207  }
208 
209  if (pbmfh->bfType == 0x4D42 /* 'BM' */)
210  {
211  /* Could be BITMAPCOREINFO */
212  BITMAPINFO* pConvertedInfo;
213  HDC hdc;
214 
215  pvBits = (PVOID)((PCHAR)pbmfh + pbmfh->bfOffBits);
216 
217  pConvertedInfo = DIB_ConvertBitmapInfo(pbmi, DIB_RGB_COLORS);
218  if(!pConvertedInfo)
219  {
220  DPRINT1("Unable to convert the bitmap Info\n");
221  goto leave;
222  }
223 
225 
227  pConvertedInfo->bmiHeader.biWidth,
228  pConvertedInfo->bmiHeader.biHeight,
229  CBM_INIT,
230  pvBits,
231  pConvertedInfo,
233  0,
234  pbmfh->bfSize - pbmfh->bfOffBits,
235  0);
236 
238  DIB_FreeConvertedBitmapInfo(pConvertedInfo, pbmi, -1);
239  }
240  else
241  {
242  DPRINT1("Unknown file type!\n");
243  }
244 
245 leave:
246  /* Unmap our section, we don't need it anymore */
247  ZwUnmapViewOfSection(NtCurrentProcess(), pbmfh);
248 
249  DPRINT("Leaving UserLoadImage, hbmp = %p\n", hbmp);
250  return hbmp;
251 }
signed char * PCHAR
Definition: retypes.h:7
VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO *converted, BITMAPINFO *orig, DWORD Usage)
Definition: dibobj.c:2116
HANDLE NTAPI W32kCreateFileSection(HANDLE hFile, ULONG flAllocation, DWORD flPageProtection, ULONGLONG ullMaxSize)
Definition: file.c:80
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1454
static PVOID
Definition: file.c:43
struct tagBITMAPINFO * LPBITMAPINFO
PVOID NTAPI W32kMapViewOfSection(HANDLE hSection, DWORD dwPageProtect, ULONG_PTR ulSectionOffset)
Definition: file.c:121
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
LONG NTSTATUS
Definition: precomp.h:26
static HDC
Definition: imagelist.c:92
_SEH2_TRY
Definition: create.c:4250
#define CBM_INIT
Definition: wingdi.h:364
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FILE_READ_DATA
Definition: nt_native.h:628
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NtCurrentProcess()
Definition: nt_native.h:1657
HBITMAP hbmp
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
HBITMAP NTAPI GreCreateDIBitmapInternal(IN HDC hDc, IN INT cx, IN INT cy, IN DWORD fInit, IN OPTIONAL LPBYTE pjInit, IN OPTIONAL PBITMAPINFO pbmi, IN DWORD iUsage, IN FLONG fl, IN UINT cjMaxBits, IN HANDLE hcmXform)
Definition: dibobj.c:1531
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
HDC hdc
Definition: main.c:9
_In_ HANDLE hFile
Definition: mswsock.h:90
Status
Definition: gdiplustypes.h:24
HANDLE NTAPI W32kOpenFile(PCWSTR pwszFileName, DWORD dwDesiredAccess)
Definition: file.c:43
_SEH2_END
Definition: create.c:4424
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1043
#define PAGE_READONLY
Definition: compat.h:127
#define DPRINT1
Definition: precomp.h:8
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO *bmi, DWORD Usage)
Definition: dibobj.c:2052
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define DIB_RGB_COLORS
Definition: wingdi.h:366
return STATUS_SUCCESS
Definition: btrfs.c:2745
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3217

Referenced by SpiSetWallpaper().

◆ W32kDosPathNameToNtPathName()

BOOL NTAPI W32kDosPathNameToNtPathName ( PCWSTR  ,
PUNICODE_STRING   
)

Referenced by SpiSetWallpaper().

Variable Documentation

◆ gusLanguageID

◆ StockObjects