ReactOS  0.4.12-dev-934-g9a4676f
ldevobj.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for ldevobj.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define RVA_TO_ADDR(Base, Rva)   ((PVOID)(((ULONG_PTR)(Base)) + (Rva)))
 

Functions

 DBG_DEFAULT_CHANNEL (EngLDev)
 
INIT_FUNCTION NTSTATUS NTAPI InitLDEVImpl (VOID)
 
static PLDEVOBJ LDEVOBJ_AllocLDEV (_In_ LDEVTYPE ldevtype)
 
static VOID LDEVOBJ_vFreeLDEV (_In_ _Post_ptr_invalid_ PLDEVOBJ pldev)
 
PDEVMODEINFO NTAPI LDEVOBJ_pdmiGetModes (_In_ PLDEVOBJ pldev, _In_ HANDLE hDriver)
 
static BOOL LDEVOBJ_bLoadImage (_Inout_ PLDEVOBJ pldev, _In_ PUNICODE_STRING pustrPathName)
 
static VOID LDEVOBJ_vUnloadImage (_Inout_ PLDEVOBJ pldev)
 
static BOOL LDEVOBJ_bEnableDriver (_Inout_ PLDEVOBJ pldev)
 
static PVOID LDEVOBJ_pvFindImageProcAddress (_In_ PLDEVOBJ pldev, _In_z_ LPSTR pszProcName)
 
PLDEVOBJ NTAPI EngLoadImageEx (_In_z_ LPWSTR pwszDriverName, _In_ ULONG ldevtype)
 
HANDLE APIENTRY EngLoadImage (_In_ LPWSTR pwszDriverName)
 
VOID APIENTRY EngUnloadImage (_In_ HANDLE hModule)
 
PVOID APIENTRY EngFindImageProcAddress (_In_ HANDLE hModule, _In_ LPSTR lpProcName)
 

Variables

static HSEMAPHORE ghsemLDEVList
 
static LIST_ENTRY gleLdevListHead
 
static LDEVOBJgpldevWin32k = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file ldevobj.c.

◆ RVA_TO_ADDR

#define RVA_TO_ADDR (   Base,
  Rva 
)    ((PVOID)(((ULONG_PTR)(Base)) + (Rva)))

Definition at line 15 of file ldevobj.c.

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( EngLDev  )

◆ EngFindImageProcAddress()

PVOID APIENTRY EngFindImageProcAddress ( _In_ HANDLE  hModule,
_In_ LPSTR  lpProcName 
)

Definition at line 497 of file ldevobj.c.

500 {
501  PLDEVOBJ pldev = (PLDEVOBJ)hModule;
502 
504 
505  /* Check if win32k is requested */
506  if (!pldev)
507  {
508  pldev = gpldevWin32k;
509  }
510 
511  /* Check if the drivers entry point is requested */
512  if (_strnicmp(lpProcName, "DrvEnableDriver", 15) == 0)
513  {
514  return pldev->pGdiDriverInfo->EntryPoint;
515  }
516 
517  /* Try to find the address */
518  return LDEVOBJ_pvFindImageProcAddress(pldev, lpProcName);
519 }
static PVOID LDEVOBJ_pvFindImageProcAddress(_In_ PLDEVOBJ pldev, _In_z_ LPSTR pszProcName)
Definition: ldevobj.c:282
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
smooth NULL
Definition: ftsmooth.c:416
static LDEVOBJ * gpldevWin32k
Definition: ldevobj.c:22
SYSTEM_GDI_DRIVER_INFORMATION * pGdiDriverInfo
Definition: ldevobj.h:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _LDEVOBJ * PLDEVOBJ
HMODULE hModule
Definition: animate.c:44

Referenced by DxDdStartupDxGraphics(), and UserLoadKbdDll().

◆ EngLoadImage()

HANDLE APIENTRY EngLoadImage ( _In_ LPWSTR  pwszDriverName)

Exported functions

Definition at line 456 of file ldevobj.c.

458 {
459  return (HANDLE)EngLoadImageEx(pwszDriverName, LDEV_IMAGE);
460 }
PLDEVOBJ NTAPI EngLoadImageEx(_In_z_ LPWSTR pwszDriverName, _In_ ULONG ldevtype)
Definition: ldevobj.c:328

Referenced by DxDdStartupDxGraphics(), and UserLoadKbdDll().

◆ EngLoadImageEx()

PLDEVOBJ NTAPI EngLoadImageEx ( _In_z_ LPWSTR  pwszDriverName,
_In_ ULONG  ldevtype 
)

Definition at line 328 of file ldevobj.c.

331 {
332  WCHAR acwBuffer[MAX_PATH];
333  PLIST_ENTRY pleLink;
334  PLDEVOBJ pldev;
335  UNICODE_STRING strDriverName;
336  SIZE_T cwcLength;
337  LPWSTR pwsz;
338 
339  TRACE("EngLoadImageEx(%ls, %lu)\n", pwszDriverName, ldevtype);
340  ASSERT(pwszDriverName);
341 
342  /* Initialize buffer for the the driver name */
343  RtlInitEmptyUnicodeString(&strDriverName, acwBuffer, sizeof(acwBuffer));
344 
345  /* Start path with systemroot */
346  RtlAppendUnicodeToString(&strDriverName, L"\\SystemRoot\\System32\\");
347 
348  /* Get Length of given string */
349  cwcLength = wcslen(pwszDriverName);
350 
351  /* Check if we have a system32 path given */
352  pwsz = pwszDriverName + cwcLength;
353  while (pwsz > pwszDriverName)
354  {
355  if ((*pwsz == L'\\') && (_wcsnicmp(pwsz, L"\\system32\\", 10) == 0))
356  {
357  /* Driver name starts after system32 */
358  pwsz += 10;
359  break;
360  }
361  pwsz--;
362  }
363 
364  /* Append the driver name */
365  RtlAppendUnicodeToString(&strDriverName, pwsz);
366 
367  /* MSDN says "The driver must include this suffix in the pwszDriver string."
368  But in fact it's optional. The function can also load .sys files without
369  appending the .dll extension. */
370  if ((cwcLength < 4) ||
371  ((_wcsnicmp(pwszDriverName + cwcLength - 4, L".dll", 4) != 0) &&
372  (_wcsnicmp(pwszDriverName + cwcLength - 4, L".sys", 4) != 0)) )
373  {
374  /* Append the .dll suffix */
375  RtlAppendUnicodeToString(&strDriverName, L".dll");
376  }
377 
378  /* Lock loader */
380 
381  /* Search the List of LDEVS for the driver name */
382  for (pleLink = gleLdevListHead.Flink;
383  pleLink != &gleLdevListHead;
384  pleLink = pleLink->Flink)
385  {
386  pldev = CONTAINING_RECORD(pleLink, LDEVOBJ, leLink);
387 
388  /* Check if the ldev is associated with a file */
389  if (pldev->pGdiDriverInfo)
390  {
391  /* Check for match (case insensative) */
392  if (RtlEqualUnicodeString(&pldev->pGdiDriverInfo->DriverName, &strDriverName, TRUE))
393  {
394  /* Image found in LDEV list */
395  break;
396  }
397  }
398  }
399 
400  /* Did we find one? */
401  if (pleLink == &gleLdevListHead)
402  {
403  /* No, allocate a new LDEVOBJ */
404  pldev = LDEVOBJ_AllocLDEV(ldevtype);
405  if (!pldev)
406  {
407  ERR("Could not allocate LDEV\n");
408  goto leave;
409  }
410 
411  /* Load the image */
412  if (!LDEVOBJ_bLoadImage(pldev, &strDriverName))
413  {
414  LDEVOBJ_vFreeLDEV(pldev);
415  pldev = NULL;
416  ERR("LDEVOBJ_bLoadImage failed\n");
417  goto leave;
418  }
419 
420  /* Shall we load a driver? */
421  if (ldevtype != LDEV_IMAGE)
422  {
423  /* Load the driver */
424  if (!LDEVOBJ_bEnableDriver(pldev))
425  {
426  ERR("LDEVOBJ_bEnableDriver failed\n");
427 
428  /* Unload the image. */
429  LDEVOBJ_vUnloadImage(pldev);
430  LDEVOBJ_vFreeLDEV(pldev);
431  pldev = NULL;
432  goto leave;
433  }
434  }
435 
436  /* Insert the LDEV into the global list */
438  }
439 
440  /* Increase ref count */
441  pldev->cRefs++;
442 
443 leave:
444  /* Unlock loader */
446 
447  TRACE("EngLoadImageEx returning %p\n", pldev);
448  return pldev;
449 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
#define TRUE
Definition: types.h:120
static VOID LDEVOBJ_vFreeLDEV(_In_ _Post_ptr_invalid_ PLDEVOBJ pldev)
Definition: ldevobj.c:103
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
static BOOL LDEVOBJ_bEnableDriver(_Inout_ PLDEVOBJ pldev)
Definition: ldevobj.c:248
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static HSEMAPHORE ghsemLDEVList
Definition: ldevobj.c:20
static VOID LDEVOBJ_vUnloadImage(_Inout_ PLDEVOBJ pldev)
Definition: ldevobj.c:217
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
static LIST_ENTRY gleLdevListHead
Definition: ldevobj.c:21
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
SYSTEM_GDI_DRIVER_INFORMATION * pGdiDriverInfo
Definition: ldevobj.h:19
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
static PLDEVOBJ LDEVOBJ_AllocLDEV(_In_ LDEVTYPE ldevtype)
Definition: ldevobj.c:79
#define MAX_PATH
Definition: compat.h:26
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
static BOOL LDEVOBJ_bLoadImage(_Inout_ PLDEVOBJ pldev, _In_ PUNICODE_STRING pustrPathName)
Definition: ldevobj.c:168
LIST_ENTRY leLink
Definition: ldevobj.h:18
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ULONG cRefs
Definition: ldevobj.h:21

Referenced by EngLoadImage(), EngpCreatePDEV(), and EngpPopulateDeviceModeList().

◆ EngUnloadImage()

VOID APIENTRY EngUnloadImage ( _In_ HANDLE  hModule)

Definition at line 465 of file ldevobj.c.

467 {
468  PLDEVOBJ pldev = (PLDEVOBJ)hModule;
469 
470  /* Make sure the LDEV is in the list */
471  ASSERT((pldev->leLink.Flink != NULL) && (pldev->leLink.Blink != NULL));
472 
473  /* Lock loader */
475 
476  /* Decrement reference count */
477  pldev->cRefs--;
478 
479  /* No more references left? */
480  if (pldev->cRefs == 0)
481  {
482  /* Remove ldev from the list */
483  RemoveEntryList(&pldev->leLink);
484 
485  /* Unload the image and free the LDEV */
486  LDEVOBJ_vUnloadImage(pldev);
487  LDEVOBJ_vFreeLDEV(pldev);
488  }
489 
490  /* Unlock loader */
492 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
static VOID LDEVOBJ_vFreeLDEV(_In_ _Post_ptr_invalid_ PLDEVOBJ pldev)
Definition: ldevobj.c:103
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
static HSEMAPHORE ghsemLDEVList
Definition: ldevobj.c:20
static VOID LDEVOBJ_vUnloadImage(_Inout_ PLDEVOBJ pldev)
Definition: ldevobj.c:217
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _LDEVOBJ * PLDEVOBJ
LIST_ENTRY leLink
Definition: ldevobj.h:18
HMODULE hModule
Definition: animate.c:44
ULONG cRefs
Definition: ldevobj.h:21

Referenced by DxDdStartupDxGraphics(), UnloadKbdFile(), and UserLoadKbdDll().

◆ InitLDEVImpl()

INIT_FUNCTION NTSTATUS NTAPI InitLDEVImpl ( VOID  )

Private functions

Definition at line 30 of file ldevobj.c.

31 {
32  ULONG cbSize;
33 
34  /* Initialize the LDEV list head */
36 
37  /* Initialize the loader lock */
39  if (!ghsemLDEVList)
40  {
41  ERR("Failed to create ghsemLDEVList\n");
43  }
44 
45  /* Allocate a LDEVOBJ for win32k */
47  sizeof(LDEVOBJ) +
49  GDITAG_LDEV);
50  if (!gpldevWin32k)
51  {
52  return STATUS_NO_MEMORY;
53  }
54 
55  /* Initialize the LDEVOBJ for win32k */
59  gpldevWin32k->cRefs = 1;
63  L"\\SystemRoot\\System32\\win32k.sys");
69  TRUE,
71  &cbSize);
73 
74  return STATUS_SUCCESS;
75 }
#define GDITAG_LDEV
Definition: tags.h:135
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
static HSEMAPHORE ghsemLDEVList
Definition: ldevobj.c:20
static const unsigned GDI_ENGINE_VERSION
Definition: ldevobj.h:4
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
static LDEVOBJ * gpldevWin32k
Definition: ldevobj.c:22
static LIST_ENTRY gleLdevListHead
Definition: ldevobj.c:21
SYSTEM_GDI_DRIVER_INFORMATION * pGdiDriverInfo
Definition: ldevobj.h:19
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define RtlImageDirectoryEntryToData
Definition: compat.h:460
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:140
#define ERR(fmt,...)
Definition: debug.h:109
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG ulDriverVersion
Definition: ldevobj.h:22
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
LDEVTYPE ldevtype
Definition: ldevobj.h:20
LIST_ENTRY leLink
Definition: ldevobj.h:18
#define __ImageBase
Definition: crt_handler.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2725
PIMAGE_EXPORT_DIRECTORY ExportSectionPointer
Definition: DriverTester.h:49
ULONG cRefs
Definition: ldevobj.h:21

Referenced by DriverEntry().

◆ LDEVOBJ_AllocLDEV()

static PLDEVOBJ LDEVOBJ_AllocLDEV ( _In_ LDEVTYPE  ldevtype)
static

Definition at line 79 of file ldevobj.c.

81 {
82  PLDEVOBJ pldev;
83 
84  /* Allocate the structure from paged pool */
86  if (!pldev)
87  {
88  ERR("Failed to allocate LDEVOBJ.\n");
89  return NULL;
90  }
91 
92  /* Zero out the structure */
93  RtlZeroMemory(pldev, sizeof(LDEVOBJ));
94 
95  /* Set the ldevtype */
96  pldev->ldevtype = ldevtype;
97 
98  return pldev;
99 }
#define GDITAG_LDEV
Definition: tags.h:135
smooth NULL
Definition: ftsmooth.c:416
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
LDEVTYPE ldevtype
Definition: ldevobj.h:20

Referenced by EngLoadImageEx().

◆ LDEVOBJ_bEnableDriver()

static BOOL LDEVOBJ_bEnableDriver ( _Inout_ PLDEVOBJ  pldev)
static

Definition at line 248 of file ldevobj.c.

250 {
251  PFN_DrvEnableDriver pfnEnableDriver;
252  DRVENABLEDATA ded;
253  ULONG i;
254 
255  /* Make sure we have a driver info */
256  ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
257 
258  /* Call the drivers DrvEnableDriver function */
259  RtlZeroMemory(&ded, sizeof(ded));
260  pfnEnableDriver = pldev->pGdiDriverInfo->EntryPoint;
261  if (!pfnEnableDriver(GDI_ENGINE_VERSION, sizeof(ded), &ded))
262  {
263  ERR("DrvEnableDriver failed\n");
264  return FALSE;
265  }
266 
267  /* Copy the returned driver version */
268  pldev->ulDriverVersion = ded.iDriverVersion;
269 
270  /* Fill the driver function array */
271  for (i = 0; i < ded.c; i++)
272  {
273  pldev->apfn[ded.pdrvfn[i].iFunc] = ded.pdrvfn[i].pfn;
274  }
275 
276  /* Return success. */
277  return TRUE;
278 }
ULONG iFunc
Definition: winddi.h:530
#define TRUE
Definition: types.h:120
PFN pfn
Definition: winddi.h:531
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
static const unsigned GDI_ENGINE_VERSION
Definition: ldevobj.h:4
FN_DrvEnableDriver * PFN_DrvEnableDriver
Definition: winddi.h:3542
smooth NULL
Definition: ftsmooth.c:416
DRVFN * pdrvfn
Definition: winddi.h:544
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ERR(fmt,...)
Definition: debug.h:109
ULONG iDriverVersion
Definition: winddi.h:542
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by EngLoadImageEx().

◆ LDEVOBJ_bLoadImage()

static BOOL LDEVOBJ_bLoadImage ( _Inout_ PLDEVOBJ  pldev,
_In_ PUNICODE_STRING  pustrPathName 
)
static

Definition at line 168 of file ldevobj.c.

171 {
172  PSYSTEM_GDI_DRIVER_INFORMATION pDriverInfo;
174  ULONG cbSize;
175 
176  /* Make sure no image is loaded yet */
177  ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
178 
179  /* Allocate a SYSTEM_GDI_DRIVER_INFORMATION structure */
180  cbSize = sizeof(SYSTEM_GDI_DRIVER_INFORMATION) + pustrPathName->Length;
181  pDriverInfo = ExAllocatePoolWithTag(PagedPool, cbSize, GDITAG_LDEV);
182  if (!pDriverInfo)
183  {
184  ERR("Failed to allocate SYSTEM_GDI_DRIVER_INFORMATION\n");
185  return FALSE;
186  }
187 
188  /* Initialize the UNICODE_STRING and copy the driver name */
189  RtlInitEmptyUnicodeString(&pDriverInfo->DriverName,
190  (PWSTR)(pDriverInfo + 1),
191  pustrPathName->Length);
192  RtlCopyUnicodeString(&pDriverInfo->DriverName, pustrPathName);
193 
194  /* Try to load the driver */
196  pDriverInfo,
198  if (!NT_SUCCESS(Status))
199  {
200  ERR("Failed to load a GDI driver: '%wZ', Status = 0x%lx\n",
201  pustrPathName, Status);
202 
203  /* Free the allocated memory */
204  ExFreePoolWithTag(pDriverInfo, GDITAG_LDEV);
205  return FALSE;
206  }
207 
208  /* Set the driver info */
209  pldev->pGdiDriverInfo = pDriverInfo;
210 
211  /* Return success. */
212  return TRUE;
213 }
#define GDITAG_LDEV
Definition: tags.h:135
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS NTAPI ZwSetSystemInformation(_In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, _In_ PVOID SystemInformation, _In_ SIZE_T SystemInformationLength)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define SystemLoadGdiDriverInformation
Definition: DriverTester.h:34
struct _SYSTEM_GDI_DRIVER_INFORMATION SYSTEM_GDI_DRIVER_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by EngLoadImageEx().

◆ LDEVOBJ_pdmiGetModes()

PDEVMODEINFO NTAPI LDEVOBJ_pdmiGetModes ( _In_ PLDEVOBJ  pldev,
_In_ HANDLE  hDriver 
)

Definition at line 116 of file ldevobj.c.

119 {
120  ULONG cbSize, cbFull;
121  PDEVMODEINFO pdminfo;
122 
123  TRACE("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
124 
125  /* Mirror drivers may omit this function */
126  if (!pldev->pfn.GetModes)
127  {
128  return NULL;
129  }
130 
131  /* Call the driver to get the required size */
132  cbSize = pldev->pfn.GetModes(hDriver, 0, NULL);
133  if (!cbSize)
134  {
135  ERR("DrvGetModes returned 0\n");
136  return NULL;
137  }
138 
139  /* Add space for the header */
140  cbFull = cbSize + FIELD_OFFSET(DEVMODEINFO, adevmode);
141 
142  /* Allocate a buffer for the DEVMODE array */
143  pdminfo = ExAllocatePoolWithTag(PagedPool, cbFull, GDITAG_DEVMODE);
144  if (!pdminfo)
145  {
146  ERR("Could not allocate devmodeinfo\n");
147  return NULL;
148  }
149 
150  pdminfo->pldev = pldev;
151  pdminfo->cbdevmode = cbSize;
152 
153  /* Call the driver again to fill the buffer */
154  cbSize = pldev->pfn.GetModes(hDriver, cbSize, pdminfo->adevmode);
155  if (!cbSize)
156  {
157  /* Could not get modes */
158  ERR("returned size %lu(%lu)\n", cbSize, pdminfo->cbdevmode);
160  pdminfo = NULL;
161  }
162 
163  return pdminfo;
164 }
#define GDITAG_DEVMODE
Definition: tags.h:73
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
ULONG cbdevmode
Definition: pdevobj.h:46
smooth NULL
Definition: ftsmooth.c:416
DEVMODEW adevmode[1]
Definition: pdevobj.h:47
#define TRACE(s)
Definition: solgame.cpp:4
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _LDEVOBJ * pldev
Definition: pdevobj.h:45

Referenced by EngpPopulateDeviceModeList().

◆ LDEVOBJ_pvFindImageProcAddress()

static PVOID LDEVOBJ_pvFindImageProcAddress ( _In_ PLDEVOBJ  pldev,
_In_z_ LPSTR  pszProcName 
)
static

Definition at line 282 of file ldevobj.c.

285 {
286  PVOID pvImageBase;
287  PIMAGE_EXPORT_DIRECTORY pExportDir;
288  PVOID pvProcAdress = NULL;
289  PUSHORT pOrdinals;
290  PULONG pNames, pAddresses;
291  ULONG i;
292 
293  /* Make sure we have a driver info */
294  ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
295 
296  /* Get the pointer to the export directory */
297  pvImageBase = pldev->pGdiDriverInfo->ImageAddress;
298  pExportDir = pldev->pGdiDriverInfo->ExportSectionPointer;
299  if (!pExportDir)
300  {
301  ERR("LDEVOBJ_pvFindImageProcAddress: no export section found\n");
302  return NULL;
303  }
304 
305  /* Get pointers to some tables */
306  pNames = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNames);
307  pOrdinals = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNameOrdinals);
308  pAddresses = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfFunctions);
309 
310  /* Loop the export table */
311  for (i = 0; i < pExportDir->NumberOfNames; i++)
312  {
313  /* Compare the name */
314  if (_stricmp(pszProcName, RVA_TO_ADDR(pvImageBase, pNames[i])) == 0)
315  {
316  /* Found! Calculate the procedure address */
317  pvProcAdress = RVA_TO_ADDR(pvImageBase, pAddresses[pOrdinals[i]]);
318  break;
319  }
320  }
321 
322  /* Return the address */
323  return pvProcAdress;
324 }
#define _stricmp
Definition: cat.c:22
DWORD AddressOfNameOrdinals
Definition: compat.h:155
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
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int * PULONG
Definition: retypes.h:1
#define RVA_TO_ADDR(Base, Rva)
Definition: ldevobj.c:15
unsigned int ULONG
Definition: retypes.h:1
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by EngFindImageProcAddress().

◆ LDEVOBJ_vFreeLDEV()

static VOID LDEVOBJ_vFreeLDEV ( _In_ _Post_ptr_invalid_ PLDEVOBJ  pldev)
static

Definition at line 103 of file ldevobj.c.

105 {
106  /* Make sure we don't have a driver loaded */
107  ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
108  ASSERT(pldev->cRefs == 0);
109 
110  /* Free the memory */
112 }
#define GDITAG_LDEV
Definition: tags.h:135
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by EngLoadImageEx(), and EngUnloadImage().

◆ LDEVOBJ_vUnloadImage()

static VOID LDEVOBJ_vUnloadImage ( _Inout_ PLDEVOBJ  pldev)
static

Definition at line 217 of file ldevobj.c.

219 {
221 
222  /* Make sure we have a driver info */
223  ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
224 
225  /* Check if we have loaded a driver */
226  if (pldev->pfn.DisableDriver)
227  {
228  /* Call the unload function */
229  pldev->pfn.DisableDriver();
230  }
231 
232  /* Unload the driver */
234  &pldev->pGdiDriverInfo->SectionPointer,
235  sizeof(HANDLE));
236  if (!NT_SUCCESS(Status))
237  {
238  ERR("Failed to unload the driver, this is bad.\n");
239  }
240 
241  /* Free the driver info structure */
242  ExFreePoolWithTag(pldev->pGdiDriverInfo, GDITAG_LDEV);
243  pldev->pGdiDriverInfo = NULL;
244 }
#define GDITAG_LDEV
Definition: tags.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS NTAPI ZwSetSystemInformation(_In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, _In_ PVOID SystemInformation, _In_ SIZE_T SystemInformationLength)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by EngLoadImageEx(), and EngUnloadImage().

Variable Documentation

◆ ghsemLDEVList

HSEMAPHORE ghsemLDEVList
static

Globals

Definition at line 20 of file ldevobj.c.

Referenced by EngLoadImageEx(), EngUnloadImage(), and InitLDEVImpl().

◆ gleLdevListHead

LIST_ENTRY gleLdevListHead
static

Definition at line 21 of file ldevobj.c.

Referenced by EngLoadImageEx(), and InitLDEVImpl().

◆ gpldevWin32k

LDEVOBJ* gpldevWin32k = NULL
static

Definition at line 22 of file ldevobj.c.

Referenced by EngFindImageProcAddress(), and InitLDEVImpl().