ReactOS  0.4.14-dev-49-gfb4591c
device.c File Reference
#include <win32k.h>
Include dependency graph for device.c:

Go to the source code of this file.

Functions

INIT_FUNCTION NTSTATUS NTAPI InitDeviceImpl (VOID)
 
BOOLEAN EngpPopulateDeviceModeList (_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
 
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice (_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription, _In_ PDEVMODEW pdmDefault)
 
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice (_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
 
static NTSTATUS EngpFileIoRequest (_In_ PFILE_OBJECT pFileObject, _In_ ULONG ulMajorFunction, _In_reads_(nBufferSize) PVOID lpBuffer, _In_ SIZE_T nBufferSize, _In_ ULONGLONG ullStartOffset, _Out_ PULONG_PTR lpInformation)
 
VOID APIENTRY EngFileWrite (_In_ PFILE_OBJECT pFileObject, _In_reads_(nLength) PVOID lpBuffer, _In_ SIZE_T nLength, _Out_ PSIZE_T lpBytesWritten)
 
 _Success_ (return >=0) NTSTATUS APIENTRY EngFileIoControl(_In_ PFILE_OBJECT pFileObject
 
_In_ DWORD _In_reads_ (nInBufferSize)
 
 _Success_ (return==0)
 

Variables

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
 
PGRAPHICS_DEVICE gpVgaGraphicsDevice
 
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL
 
static PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL
 
static HSEMAPHORE ghsemGraphicsDeviceList
 
static ULONG giDevNum = 1
 
_In_ DWORD dwIoControlCode
 

Function Documentation

◆ _In_reads_()

_In_ DWORD _In_reads_ ( nInBufferSize  )

Definition at line 411 of file device.c.

416 {
418  KEVENT Event;
419  PIRP pIrp;
422 
423  /* Get corresponding device object */
425  if (!pDeviceObject)
426  {
428  }
429 
430  /* Initialize an event */
432 
433  /* Build IO control IRP */
436  lpInBuffer,
437  (ULONG)nInBufferSize,
438  lpOutBuffer,
439  (ULONG)nOutBufferSize,
440  FALSE,
441  &Event,
442  &Iosb);
443  if (!pIrp)
444  {
446  }
447 
448  /* Call the driver */
450 
451  /* Wait if neccessary */
452  if (Status == STATUS_PENDING)
453  {
455  Status = Iosb.Status;
456  }
457 
458  /* Return information to the caller about the operation. */
459  *lpInformation = Iosb.Information;
460 
461  /* This function returns NTSTATUS */
462  return Status;
463 }
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
_In_ DWORD dwIoControlCode
Definition: device.c:410
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1

◆ _Success_() [1/2]

_Success_ ( return >=  0)

◆ _Success_() [2/2]

_Success_ ( return  = =0)

Definition at line 468 of file device.c.

479 {
480  PIRP Irp;
482  KEVENT Event;
485 
486  TRACE("EngDeviceIoControl() called\n");
487 
488  if (!hDevice)
489  {
490  return ERROR_INVALID_HANDLE;
491  }
492 
494 
495  DeviceObject = (PDEVICE_OBJECT) hDevice;
496 
498  DeviceObject,
499  lpInBuffer,
501  lpOutBuffer,
503  FALSE,
504  &Event,
505  &Iosb);
506  if (!Irp) return ERROR_NOT_ENOUGH_MEMORY;
507 
509 
510  if (Status == STATUS_PENDING)
511  {
513  Status = Iosb.Status;
514  }
515 
516  TRACE("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
517  Iosb.Information);
518 
519  /* Return information to the caller about the operation. */
520  *lpBytesReturned = (DWORD)Iosb.Information;
521 
522  /* Convert NT status values to win32 error codes. */
523  switch (Status)
524  {
527 
529  return ERROR_MORE_DATA;
530 
532  return ERROR_INVALID_FUNCTION;
533 
536 
539 
541  return ERROR_DEV_NOT_EXIST;
542 
543  case STATUS_PENDING:
544  return ERROR_IO_PENDING;
545  }
546 
547  return Status;
548 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:414
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ DWORD _In_ DWORD _In_ DWORD cjOutBufferSize
Definition: winddi.h:1704
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_IO_PENDING
Definition: dderror.h:15
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define DWORD
Definition: nt_native.h:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
_In_ DWORD _In_ DWORD cjInBufferSize
Definition: winddi.h:1702
switch(r->id)
Definition: btrfs.c:2932
_In_ DWORD dwIoControlCode
Definition: device.c:410
#define TRACE(s)
Definition: solgame.cpp:4
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VOID
Definition: acefi.h:82
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ DWORD _In_ DWORD _In_ DWORD _Out_ LPDWORD lpBytesReturned
Definition: winddi.h:1704
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define ERROR_DEV_NOT_EXIST
Definition: dderror.h:8
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

◆ EngFileWrite()

VOID APIENTRY EngFileWrite ( _In_ PFILE_OBJECT  pFileObject,
_In_reads_(nLength) PVOID  lpBuffer,
_In_ SIZE_T  nLength,
_Out_ PSIZE_T  lpBytesWritten 
)

Definition at line 385 of file device.c.

390 {
392 
393  status = EngpFileIoRequest(pFileObject,
394  IRP_MJ_WRITE,
395  lpBuffer,
396  nLength,
397  0,
398  lpBytesWritten);
399  if (!NT_SUCCESS(status))
400  {
401  *lpBytesWritten = 0;
402  }
403 }
LONG NTSTATUS
Definition: precomp.h:26
_In_ DWORD nLength
Definition: wincon.h:461
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
static SERVICE_STATUS status
Definition: service.c:31
static NTSTATUS EngpFileIoRequest(_In_ PFILE_OBJECT pFileObject, _In_ ULONG ulMajorFunction, _In_reads_(nBufferSize) PVOID lpBuffer, _In_ SIZE_T nBufferSize, _In_ ULONGLONG ullStartOffset, _Out_ PULONG_PTR lpInformation)
Definition: device.c:327
Definition: ps.c:97

Referenced by EngpRegisterGraphicsDevice().

◆ EngpFileIoRequest()

static NTSTATUS EngpFileIoRequest ( _In_ PFILE_OBJECT  pFileObject,
_In_ ULONG  ulMajorFunction,
_In_reads_(nBufferSize) PVOID  lpBuffer,
_In_ SIZE_T  nBufferSize,
_In_ ULONGLONG  ullStartOffset,
_Out_ PULONG_PTR  lpInformation 
)
static

Definition at line 327 of file device.c.

334 {
336  KEVENT Event;
337  PIRP pIrp;
340  LARGE_INTEGER liStartOffset;
341 
342  /* Get corresponding device object */
344  if (!pDeviceObject)
345  {
347  }
348 
349  /* Initialize an event */
351 
352  /* Build IRP */
353  liStartOffset.QuadPart = ullStartOffset;
354  pIrp = IoBuildSynchronousFsdRequest(ulMajorFunction,
356  lpBuffer,
357  (ULONG)nBufferSize,
358  &liStartOffset,
359  &Event,
360  &Iosb);
361  if (!pIrp)
362  {
364  }
365 
366  /* Call the driver */
368 
369  /* Wait if neccessary */
370  if (STATUS_PENDING == Status)
371  {
373  Status = Iosb.Status;
374  }
375 
376  /* Return information to the caller about the operation. */
377  *lpInformation = Iosb.Information;
378 
379  /* Return NTSTATUS */
380  return Status;
381 }
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by EngFileWrite().

◆ EngpFindGraphicsDevice()

PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice ( _In_opt_ PUNICODE_STRING  pustrDevice,
_In_ ULONG  iDevNum,
_In_ DWORD  dwFlags 
)

Definition at line 281 of file device.c.

285 {
286  UNICODE_STRING ustrCurrent;
287  PGRAPHICS_DEVICE pGraphicsDevice;
288  ULONG i;
289  TRACE("EngpFindGraphicsDevice('%wZ', %lu, 0x%lx)\n",
290  pustrDevice, iDevNum, dwFlags);
291 
292  /* Lock list */
294 
295  if (pustrDevice && pustrDevice->Buffer)
296  {
297  /* Loop through the list of devices */
298  for (pGraphicsDevice = gpGraphicsDeviceFirst;
299  pGraphicsDevice;
300  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
301  {
302  /* Compare the device name */
303  RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
304  if (RtlEqualUnicodeString(&ustrCurrent, pustrDevice, FALSE))
305  {
306  break;
307  }
308  }
309  }
310  else
311  {
312  /* Loop through the list of devices */
313  for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
314  pGraphicsDevice && i < iDevNum;
315  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
316  }
317 
318  /* Unlock list */
320 
321  return pGraphicsDevice;
322 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
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 PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:16
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
#define TRACE(s)
Definition: solgame.cpp:4
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:18
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)

Referenced by EngpCreatePDEV(), UserEnumDisplayDevices(), and UserEnumDisplaySettings().

◆ EngpPopulateDeviceModeList()

BOOLEAN EngpPopulateDeviceModeList ( _Inout_ PGRAPHICS_DEVICE  pGraphicsDevice,
_In_ PDEVMODEW  pdmDefault 
)

Definition at line 34 of file device.c.

37 {
38  PWSTR pwsz;
39  PLDEVOBJ pldev;
40  PDEVMODEINFO pdminfo;
41  PDEVMODEW pdm, pdmEnd;
42  ULONG i, cModes = 0;
43  BOOLEAN bModeMatch = FALSE;
44 
45  ASSERT(pGraphicsDevice->pdevmodeInfo == NULL);
46  ASSERT(pGraphicsDevice->pDevModeList == NULL);
47 
48  pwsz = pGraphicsDevice->pDiplayDrivers;
49 
50  /* Loop through the driver names
51  * This is a REG_MULTI_SZ string */
52  for (; *pwsz; pwsz += wcslen(pwsz) + 1)
53  {
54  TRACE("trying driver: %ls\n", pwsz);
55  /* Try to load the display driver */
56  pldev = EngLoadImageEx(pwsz, LDEV_DEVICE_DISPLAY);
57  if (!pldev)
58  {
59  ERR("Could not load driver: '%ls'\n", pwsz);
60  continue;
61  }
62 
63  /* Get the mode list from the driver */
64  pdminfo = LDEVOBJ_pdmiGetModes(pldev, pGraphicsDevice->DeviceObject);
65  if (!pdminfo)
66  {
67  ERR("Could not get mode list for '%ls'\n", pwsz);
68  continue;
69  }
70 
71  /* Attach the mode info to the device */
72  pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo;
73  pGraphicsDevice->pdevmodeInfo = pdminfo;
74 
75  /* Loop all DEVMODEs */
76  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
77  for (pdm = pdminfo->adevmode;
78  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
79  pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
80  {
81  /* Count this DEVMODE */
82  cModes++;
83 
84  /* Some drivers like the VBox driver don't fill the dmDeviceName
85  with the name of the display driver. So fix that here. */
86  wcsncpy(pdm->dmDeviceName, pwsz, CCHDEVICENAME);
87  pdm->dmDeviceName[CCHDEVICENAME - 1] = 0;
88  }
89 
90  // FIXME: release the driver again until it's used?
91  }
92 
93  if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
94  {
95  ERR("No devmodes\n");
96  return FALSE;
97  }
98 
99  /* Allocate an index buffer */
100  pGraphicsDevice->cDevModes = cModes;
101  pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool,
102  cModes * sizeof(DEVMODEENTRY),
104  if (!pGraphicsDevice->pDevModeList)
105  {
106  ERR("No devmode list\n");
107  return FALSE;
108  }
109 
110  TRACE("Looking for mode %lux%lux%lu(%lu Hz)\n",
111  pdmDefault->dmPelsWidth,
112  pdmDefault->dmPelsHeight,
113  pdmDefault->dmBitsPerPel,
114  pdmDefault->dmDisplayFrequency);
115 
116  /* Loop through all DEVMODEINFOs */
117  for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
118  pdminfo;
119  pdminfo = pdminfo->pdmiNext)
120  {
121  /* Calculate End of the DEVMODEs */
122  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
123 
124  /* Loop through the DEVMODEs */
125  for (pdm = pdminfo->adevmode;
126  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
127  pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
128  {
129  TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n",
130  pdm->dmDeviceName,
131  pdm->dmPelsWidth,
132  pdm->dmPelsHeight,
133  pdm->dmBitsPerPel,
134  pdm->dmDisplayFrequency);
135  /* Compare with the default entry */
136  if (!bModeMatch &&
137  pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel &&
138  pdm->dmPelsWidth == pdmDefault->dmPelsWidth &&
139  pdm->dmPelsHeight == pdmDefault->dmPelsHeight)
140  {
141  pGraphicsDevice->iDefaultMode = i;
142  pGraphicsDevice->iCurrentMode = i;
143  TRACE("Found default entry: %lu '%ls'\n", i, pdm->dmDeviceName);
144  if (pdm->dmDisplayFrequency == pdmDefault->dmDisplayFrequency)
145  {
146  /* Uh oh, even the display frequency matches. */
147  bModeMatch = TRUE;
148  }
149  }
150 
151  /* Initialize the entry */
152  pGraphicsDevice->pDevModeList[i].dwFlags = 0;
153  pGraphicsDevice->pDevModeList[i].pdm = pdm;
154  i++;
155  }
156  }
157  return TRUE;
158 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
struct _devicemodeW * PDEVMODEW
PDEVMODEINFO NTAPI LDEVOBJ_pdmiGetModes(_In_ PLDEVOBJ pldev, _In_ HANDLE hDriver)
Definition: ldevobj.c:116
uint16_t * PWSTR
Definition: typedefs.h:54
WORD dmDriverExtra
Definition: wingdi.h:1616
DWORD dmBitsPerPel
Definition: wingdi.h:1642
PLDEVOBJ NTAPI EngLoadImageEx(_In_z_ LPWSTR pwszDriverName, _In_ ULONG ldevtype)
Definition: ldevobj.c:328
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
ULONG cbdevmode
Definition: pdevobj.h:46
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
DEVMODEW adevmode[1]
Definition: pdevobj.h:47
#define TRACE(s)
Definition: solgame.cpp:4
struct _DEVMODEINFO * pdmiNext
Definition: pdevobj.h:44
WORD dmSize
Definition: wingdi.h:1615
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1612
DWORD dmPelsWidth
Definition: wingdi.h:1643
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define GDITAG_GDEVICE
Definition: tags.h:98
#define ERR(fmt,...)
Definition: debug.h:109
DWORD dmDisplayFrequency
Definition: wingdi.h:1649
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define CCHDEVICENAME
Definition: ddrawi.h:63
DWORD dmPelsHeight
Definition: wingdi.h:1644
unsigned int ULONG
Definition: retypes.h:1
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by EngpRegisterGraphicsDevice(), and PDEVOBJ_vRefreshModeList().

◆ EngpRegisterGraphicsDevice()

PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice ( _In_ PUNICODE_STRING  pustrDeviceName,
_In_ PUNICODE_STRING  pustrDiplayDrivers,
_In_ PUNICODE_STRING  pustrDescription,
_In_ PDEVMODEW  pdmDefault 
)

Definition at line 162 of file device.c.

167 {
168  PGRAPHICS_DEVICE pGraphicsDevice;
170  PFILE_OBJECT pFileObject;
172  PWSTR pwsz;
173  ULONG cj;
174  SIZE_T cjWritten;
175  BOOL bEnable = TRUE;
176 
177  TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
178 
179  /* Allocate a GRAPHICS_DEVICE structure */
180  pGraphicsDevice = ExAllocatePoolWithTag(PagedPool,
181  sizeof(GRAPHICS_DEVICE),
183  if (!pGraphicsDevice)
184  {
185  ERR("ExAllocatePoolWithTag failed\n");
186  return NULL;
187  }
188 
189  /* Try to open the driver */
190  Status = IoGetDeviceObjectPointer(pustrDeviceName,
192  &pFileObject,
193  &pDeviceObject);
194  if (!NT_SUCCESS(Status))
195  {
196  ERR("Could not open driver %wZ, 0x%lx\n", pustrDeviceName, Status);
197  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
198  return NULL;
199  }
200 
201  /* Enable the device */
202  EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cjWritten);
203 
204  /* Copy the device and file object pointers */
205  pGraphicsDevice->DeviceObject = pDeviceObject;
206  pGraphicsDevice->FileObject = pFileObject;
207 
208  /* Copy device name */
209  RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName,
210  sizeof(pGraphicsDevice->szNtDeviceName),
211  pustrDeviceName->Buffer,
212  pustrDeviceName->Length);
213 
214  /* Create a win device name (FIXME: virtual devices!) */
215  swprintf(pGraphicsDevice->szWinDeviceName, L"\\\\.\\DISPLAY%d", (int)giDevNum);
216 
217  /* Allocate a buffer for the strings */
218  cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR);
220  if (!pwsz)
221  {
222  ERR("Could not allocate string buffer\n");
223  ASSERT(FALSE); // FIXME
224  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
225  return NULL;
226  }
227 
228  /* Copy display driver names */
229  pGraphicsDevice->pDiplayDrivers = pwsz;
230  RtlCopyMemory(pGraphicsDevice->pDiplayDrivers,
231  pustrDiplayDrivers->Buffer,
232  pustrDiplayDrivers->Length);
233 
234  /* Copy description */
235  pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR);
236  RtlCopyMemory(pGraphicsDevice->pwszDescription,
237  pustrDescription->Buffer,
238  pustrDescription->Length);
239  pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0;
240 
241  /* Initialize the pdevmodeInfo list and default index */
242  pGraphicsDevice->pdevmodeInfo = NULL;
243  pGraphicsDevice->iDefaultMode = 0;
244  pGraphicsDevice->iCurrentMode = 0;
245 
246  // FIXME: initialize state flags
247  pGraphicsDevice->StateFlags = 0;
248 
249  /* Create the mode list */
250  pGraphicsDevice->pDevModeList = NULL;
251  if (!EngpPopulateDeviceModeList(pGraphicsDevice, pdmDefault))
252  {
253  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
254  return NULL;
255  }
256 
257  /* Lock loader */
259 
260  /* Insert the device into the global list */
261  pGraphicsDevice->pNextGraphicsDevice = NULL;
263  gpGraphicsDeviceLast->pNextGraphicsDevice = pGraphicsDevice;
264  gpGraphicsDeviceLast = pGraphicsDevice;
266  gpGraphicsDeviceFirst = pGraphicsDevice;
267 
268  /* Increment device number */
269  giDevNum++;
270 
271  /* Unlock loader */
273  TRACE("Prepared %lu modes for %ls\n", pGraphicsDevice->cDevModes, pGraphicsDevice->pwszDescription);
274 
275  return pGraphicsDevice;
276 }
BOOLEAN EngpPopulateDeviceModeList(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
Definition: device.c:34
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ ULONG cj
Definition: winddi.h:3540
static PGRAPHICS_DEVICE gpGraphicsDeviceLast
Definition: device.c:17
PDEVICE_OBJECT DeviceObject
Definition: pdevobj.h:63
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
WCHAR szNtDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:59
uint16_t * PWSTR
Definition: typedefs.h:54
DWORD StateFlags
Definition: pdevobj.h:66
LONG NTSTATUS
Definition: precomp.h:26
PDEVMODEENTRY pDevModeList
Definition: pdevobj.h:70
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSTRSAFEAPI RtlStringCbCopyNW(_Out_writes_bytes_(cbDest) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:416
LPWSTR pwszDescription
Definition: pdevobj.h:72
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:16
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define TRACE(s)
Definition: solgame.cpp:4
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG iCurrentMode
Definition: pdevobj.h:78
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LPWSTR pDiplayDrivers
Definition: pdevobj.h:71
ULONG cDevModes
Definition: pdevobj.h:69
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:18
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#define GDITAG_DRVSUP
Definition: tags.h:76
#define GDITAG_GDEVICE
Definition: tags.h:98
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_In_ BOOL bEnable
Definition: winddi.h:3426
static ULONG giDevNum
Definition: device.c:19
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID APIENTRY EngFileWrite(_In_ PFILE_OBJECT pFileObject, _In_reads_(nLength) PVOID lpBuffer, _In_ SIZE_T nLength, _Out_ PSIZE_T lpBytesWritten)
Definition: device.c:385
PDEVMODEINFO pdevmodeInfo
Definition: pdevobj.h:68
ULONG iDefaultMode
Definition: pdevobj.h:77
PFILE_OBJECT FileObject
Definition: pdevobj.h:75

Referenced by InitDisplayDriver().

◆ InitDeviceImpl()

INIT_FUNCTION NTSTATUS NTAPI InitDeviceImpl ( VOID  )

Definition at line 24 of file device.c.

25 {
29 
30  return STATUS_SUCCESS;
31 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:18
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by DriverEntry().

Variable Documentation

◆ dwIoControlCode

_In_ DWORD dwIoControlCode

Definition at line 410 of file device.c.

Referenced by _In_reads_(), and _Success_().

◆ ghsemGraphicsDeviceList

HSEMAPHORE ghsemGraphicsDeviceList
static

Definition at line 18 of file device.c.

Referenced by EngpFindGraphicsDevice(), EngpRegisterGraphicsDevice(), and InitDeviceImpl().

◆ giDevNum

ULONG giDevNum = 1
static

Definition at line 19 of file device.c.

Referenced by EngpRegisterGraphicsDevice().

◆ gpGraphicsDeviceFirst

PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL
static

Definition at line 16 of file device.c.

Referenced by EngpFindGraphicsDevice(), and EngpRegisterGraphicsDevice().

◆ gpGraphicsDeviceLast

PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL
static

Definition at line 17 of file device.c.

Referenced by EngpRegisterGraphicsDevice().

◆ gpPrimaryGraphicsDevice

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice

Definition at line 13 of file device.c.

Referenced by EngpCreatePDEV(), and InitVideo().

◆ gpVgaGraphicsDevice

PGRAPHICS_DEVICE gpVgaGraphicsDevice

Definition at line 14 of file device.c.

Referenced by InitVideo().