2010-01-30 21:12:42 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2011-12-14 04:07:06 +00:00
|
|
|
* PROJECT: ReactOS Win32k subsystem
|
2010-01-30 21:12:42 +00:00
|
|
|
* PURPOSE: Support for logical devices
|
2015-11-10 17:41:55 +00:00
|
|
|
* FILE: win32ss/gdi/eng/ldevobj.c
|
2010-01-30 21:12:42 +00:00
|
|
|
* PROGRAMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
|
|
|
*/
|
|
|
|
|
2010-05-07 07:41:13 +00:00
|
|
|
#include <win32k.h>
|
2010-01-30 21:12:42 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2013-11-11 19:09:53 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(EngLDev);
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
#ifndef RVA_TO_ADDR
|
|
|
|
#define RVA_TO_ADDR(Base,Rva) ((PVOID)(((ULONG_PTR)(Base)) + (Rva)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Globals *******************************************************************/
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static HSEMAPHORE ghsemLDEVList;
|
2014-02-09 12:46:19 +00:00
|
|
|
static LIST_ENTRY gleLdevListHead;
|
2013-11-11 19:09:53 +00:00
|
|
|
static LDEVOBJ *gpldevWin32k = NULL;
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Private functions *********************************************************/
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2010-11-03 00:51:19 +00:00
|
|
|
NTSTATUS
|
2010-01-30 21:12:42 +00:00
|
|
|
NTAPI
|
2013-11-11 19:09:53 +00:00
|
|
|
InitLDEVImpl(VOID)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
2011-01-02 13:05:51 +00:00
|
|
|
ULONG cbSize;
|
|
|
|
|
2014-02-09 12:46:19 +00:00
|
|
|
/* Initialize the LDEV list head */
|
|
|
|
InitializeListHead(&gleLdevListHead);
|
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/* Initialize the loader lock */
|
|
|
|
ghsemLDEVList = EngCreateSemaphore();
|
|
|
|
if (!ghsemLDEVList)
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("Failed to create ghsemLDEVList\n");
|
2010-11-03 00:51:19 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a LDEVOBJ for win32k */
|
|
|
|
gpldevWin32k = ExAllocatePoolWithTag(PagedPool,
|
2010-05-07 07:41:13 +00:00
|
|
|
sizeof(LDEVOBJ) +
|
2010-01-30 21:12:42 +00:00
|
|
|
sizeof(SYSTEM_GDI_DRIVER_INFORMATION),
|
|
|
|
GDITAG_LDEV);
|
|
|
|
if (!gpldevWin32k)
|
|
|
|
{
|
2010-11-03 00:51:19 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the LDEVOBJ for win32k */
|
2014-02-09 12:46:19 +00:00
|
|
|
gpldevWin32k->leLink.Flink = NULL;
|
|
|
|
gpldevWin32k->leLink.Blink = NULL;
|
2010-01-30 21:12:42 +00:00
|
|
|
gpldevWin32k->ldevtype = LDEV_DEVICE_DISPLAY;
|
|
|
|
gpldevWin32k->cRefs = 1;
|
|
|
|
gpldevWin32k->ulDriverVersion = GDI_ENGINE_VERSION;
|
|
|
|
gpldevWin32k->pGdiDriverInfo = (PVOID)(gpldevWin32k + 1);
|
2010-10-24 23:32:18 +00:00
|
|
|
RtlInitUnicodeString(&gpldevWin32k->pGdiDriverInfo->DriverName,
|
|
|
|
L"\\SystemRoot\\System32\\win32k.sys");
|
2010-01-30 21:12:42 +00:00
|
|
|
gpldevWin32k->pGdiDriverInfo->ImageAddress = &__ImageBase;
|
|
|
|
gpldevWin32k->pGdiDriverInfo->SectionPointer = NULL;
|
|
|
|
gpldevWin32k->pGdiDriverInfo->EntryPoint = (PVOID)DriverEntry;
|
2011-01-02 13:05:51 +00:00
|
|
|
gpldevWin32k->pGdiDriverInfo->ExportSectionPointer =
|
|
|
|
RtlImageDirectoryEntryToData(&__ImageBase,
|
|
|
|
TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT,
|
|
|
|
&cbSize);
|
2011-12-14 04:07:06 +00:00
|
|
|
gpldevWin32k->pGdiDriverInfo->ImageLength = 0; // FIXME
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2010-11-03 00:51:19 +00:00
|
|
|
return STATUS_SUCCESS;
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static
|
2010-01-30 21:12:42 +00:00
|
|
|
PLDEVOBJ
|
2013-11-11 19:09:53 +00:00
|
|
|
LDEVOBJ_AllocLDEV(
|
|
|
|
_In_ LDEVTYPE ldevtype)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
PLDEVOBJ pldev;
|
|
|
|
|
|
|
|
/* Allocate the structure from paged pool */
|
|
|
|
pldev = ExAllocatePoolWithTag(PagedPool, sizeof(LDEVOBJ), GDITAG_LDEV);
|
|
|
|
if (!pldev)
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("Failed to allocate LDEVOBJ.\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero out the structure */
|
|
|
|
RtlZeroMemory(pldev, sizeof(LDEVOBJ));
|
2010-05-07 07:41:13 +00:00
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/* Set the ldevtype */
|
|
|
|
pldev->ldevtype = ldevtype;
|
|
|
|
|
|
|
|
return pldev;
|
|
|
|
}
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static
|
2010-01-30 21:12:42 +00:00
|
|
|
VOID
|
2013-11-11 19:09:53 +00:00
|
|
|
LDEVOBJ_vFreeLDEV(
|
|
|
|
_In_ _Post_ptr_invalid_ PLDEVOBJ pldev)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
/* Make sure we don't have a driver loaded */
|
|
|
|
ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
|
2012-03-03 20:00:51 +00:00
|
|
|
ASSERT(pldev->cRefs == 0);
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
/* Free the memory */
|
2011-03-25 22:49:30 +00:00
|
|
|
ExFreePoolWithTag(pldev, GDITAG_LDEV);
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static
|
2010-01-30 21:12:42 +00:00
|
|
|
BOOL
|
|
|
|
LDEVOBJ_bLoadImage(
|
2013-11-11 19:09:53 +00:00
|
|
|
_Inout_ PLDEVOBJ pldev,
|
|
|
|
_In_ PUNICODE_STRING pustrPathName)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
PSYSTEM_GDI_DRIVER_INFORMATION pDriverInfo;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG cbSize;
|
|
|
|
|
|
|
|
/* Make sure no image is loaded yet */
|
|
|
|
ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
|
|
|
|
|
|
|
|
/* Allocate a SYSTEM_GDI_DRIVER_INFORMATION structure */
|
2013-11-11 19:09:53 +00:00
|
|
|
cbSize = sizeof(SYSTEM_GDI_DRIVER_INFORMATION) + pustrPathName->Length;
|
2010-01-30 21:12:42 +00:00
|
|
|
pDriverInfo = ExAllocatePoolWithTag(PagedPool, cbSize, GDITAG_LDEV);
|
|
|
|
if (!pDriverInfo)
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("Failed to allocate SYSTEM_GDI_DRIVER_INFORMATION\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-24 23:32:18 +00:00
|
|
|
/* Initialize the UNICODE_STRING and copy the driver name */
|
|
|
|
RtlInitEmptyUnicodeString(&pDriverInfo->DriverName,
|
|
|
|
(PWSTR)(pDriverInfo + 1),
|
2013-11-11 19:09:53 +00:00
|
|
|
pustrPathName->Length);
|
|
|
|
RtlCopyUnicodeString(&pDriverInfo->DriverName, pustrPathName);
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
/* Try to load the driver */
|
|
|
|
Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation,
|
|
|
|
pDriverInfo,
|
|
|
|
sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("Failed to load a GDI driver: '%wZ', Status = 0x%lx\n",
|
|
|
|
pustrPathName, Status);
|
2010-10-23 21:59:21 +00:00
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/* Free the allocated memory */
|
2011-03-25 22:49:30 +00:00
|
|
|
ExFreePoolWithTag(pDriverInfo, GDITAG_LDEV);
|
2010-01-30 21:12:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the driver info */
|
|
|
|
pldev->pGdiDriverInfo = pDriverInfo;
|
|
|
|
|
|
|
|
/* Return success. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static
|
2010-01-30 21:12:42 +00:00
|
|
|
BOOL
|
2013-11-11 19:09:53 +00:00
|
|
|
LDEVOBJ_bEnableDriver(
|
2022-01-09 10:02:27 +00:00
|
|
|
_Inout_ PLDEVOBJ pldev,
|
|
|
|
_In_ PFN_DrvEnableDriver pfnEnableDriver)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
DRVENABLEDATA ded;
|
|
|
|
ULONG i;
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
TRACE("LDEVOBJ_bEnableDriver('%wZ')\n", &pldev->pGdiDriverInfo->DriverName);
|
|
|
|
|
2022-01-09 10:02:27 +00:00
|
|
|
ASSERT(pldev);
|
2022-01-09 08:42:23 +00:00
|
|
|
ASSERT(pldev->cRefs == 0);
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2022-04-17 11:52:10 +00:00
|
|
|
if (pldev->ldevtype == LDEV_IMAGE)
|
|
|
|
return TRUE;
|
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/* Call the drivers DrvEnableDriver function */
|
|
|
|
RtlZeroMemory(&ded, sizeof(ded));
|
|
|
|
if (!pfnEnableDriver(GDI_ENGINE_VERSION, sizeof(ded), &ded))
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("DrvEnableDriver failed\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the returned driver version */
|
|
|
|
pldev->ulDriverVersion = ded.iDriverVersion;
|
|
|
|
|
|
|
|
/* Fill the driver function array */
|
|
|
|
for (i = 0; i < ded.c; i++)
|
|
|
|
{
|
|
|
|
pldev->apfn[ded.pdrvfn[i].iFunc] = ded.pdrvfn[i].pfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return success. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
static
|
|
|
|
VOID
|
|
|
|
LDEVOBJ_vDisableDriver(
|
|
|
|
_Inout_ PLDEVOBJ pldev)
|
2022-01-09 08:54:53 +00:00
|
|
|
{
|
2022-01-09 08:42:23 +00:00
|
|
|
ASSERT(pldev);
|
|
|
|
ASSERT(pldev->cRefs == 0);
|
2022-01-09 08:54:53 +00:00
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
TRACE("LDEVOBJ_vDisableDriver('%wZ')\n", &pldev->pGdiDriverInfo->DriverName);
|
2022-01-09 08:54:53 +00:00
|
|
|
|
2022-04-17 11:52:10 +00:00
|
|
|
if (pldev->ldevtype == LDEV_IMAGE)
|
|
|
|
return;
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
if (pldev->pfn.DisableDriver)
|
2022-01-09 08:54:53 +00:00
|
|
|
{
|
2022-01-09 08:42:23 +00:00
|
|
|
/* Call the unload function */
|
|
|
|
pldev->pfn.DisableDriver();
|
2022-01-09 08:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 19:09:53 +00:00
|
|
|
static
|
2010-01-30 21:12:42 +00:00
|
|
|
PVOID
|
|
|
|
LDEVOBJ_pvFindImageProcAddress(
|
2013-11-11 19:09:53 +00:00
|
|
|
_In_ PLDEVOBJ pldev,
|
|
|
|
_In_z_ LPSTR pszProcName)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
PVOID pvImageBase;
|
|
|
|
PIMAGE_EXPORT_DIRECTORY pExportDir;
|
|
|
|
PVOID pvProcAdress = NULL;
|
|
|
|
PUSHORT pOrdinals;
|
|
|
|
PULONG pNames, pAddresses;
|
2011-01-02 13:05:51 +00:00
|
|
|
ULONG i;
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
/* Make sure we have a driver info */
|
|
|
|
ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
|
|
|
|
|
|
|
|
/* Get the pointer to the export directory */
|
|
|
|
pvImageBase = pldev->pGdiDriverInfo->ImageAddress;
|
2011-01-02 13:05:51 +00:00
|
|
|
pExportDir = pldev->pGdiDriverInfo->ExportSectionPointer;
|
2010-01-30 21:12:42 +00:00
|
|
|
if (!pExportDir)
|
|
|
|
{
|
2014-10-02 20:11:24 +00:00
|
|
|
ERR("LDEVOBJ_pvFindImageProcAddress: no export section found\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get pointers to some tables */
|
|
|
|
pNames = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNames);
|
|
|
|
pOrdinals = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNameOrdinals);
|
|
|
|
pAddresses = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfFunctions);
|
|
|
|
|
|
|
|
/* Loop the export table */
|
|
|
|
for (i = 0; i < pExportDir->NumberOfNames; i++)
|
|
|
|
{
|
|
|
|
/* Compare the name */
|
|
|
|
if (_stricmp(pszProcName, RVA_TO_ADDR(pvImageBase, pNames[i])) == 0)
|
|
|
|
{
|
|
|
|
/* Found! Calculate the procedure address */
|
|
|
|
pvProcAdress = RVA_TO_ADDR(pvImageBase, pAddresses[pOrdinals[i]]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the address */
|
|
|
|
return pvProcAdress;
|
|
|
|
}
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
LDEVOBJ_bUnloadImage(
|
|
|
|
_Inout_ PLDEVOBJ pldev)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Make sure we have a driver info */
|
|
|
|
ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
|
|
|
|
ASSERT(pldev->cRefs == 0);
|
|
|
|
|
|
|
|
TRACE("LDEVOBJ_bUnloadImage('%wZ')\n", &pldev->pGdiDriverInfo->DriverName);
|
|
|
|
|
|
|
|
/* Unload the driver */
|
|
|
|
#if 0
|
|
|
|
Status = ZwSetSystemInformation(SystemUnloadGdiDriverInformation,
|
|
|
|
&pldev->pGdiDriverInfo->SectionPointer,
|
|
|
|
sizeof(HANDLE));
|
|
|
|
#else
|
|
|
|
/* Unfortunately, ntoskrnl allows unloading a driver, but fails loading
|
|
|
|
* it again with STATUS_IMAGE_ALREADY_LOADED. Prevent this problem by
|
|
|
|
* never unloading any driver.
|
|
|
|
*/
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ExFreePoolWithTag(pldev->pGdiDriverInfo, GDITAG_LDEV);
|
|
|
|
pldev->pGdiDriverInfo = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-01-09 10:02:27 +00:00
|
|
|
PLDEVOBJ
|
|
|
|
LDEVOBJ_pLoadInternal(
|
|
|
|
_In_ PFN_DrvEnableDriver pfnEnableDriver,
|
|
|
|
_In_ ULONG ldevtype)
|
|
|
|
{
|
|
|
|
PLDEVOBJ pldev;
|
|
|
|
|
|
|
|
TRACE("LDEVOBJ_pLoadInternal(%lu)\n", ldevtype);
|
|
|
|
|
|
|
|
/* Lock loader */
|
|
|
|
EngAcquireSemaphore(ghsemLDEVList);
|
|
|
|
|
|
|
|
/* Allocate a new LDEVOBJ */
|
|
|
|
pldev = LDEVOBJ_AllocLDEV(ldevtype);
|
|
|
|
if (!pldev)
|
|
|
|
{
|
|
|
|
ERR("Could not allocate LDEV\n");
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the driver */
|
|
|
|
if (!LDEVOBJ_bEnableDriver(pldev, pfnEnableDriver))
|
|
|
|
{
|
|
|
|
ERR("LDEVOBJ_bEnableDriver failed\n");
|
|
|
|
LDEVOBJ_vFreeLDEV(pldev);
|
|
|
|
pldev = NULL;
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the LDEV into the global list */
|
|
|
|
InsertHeadList(&gleLdevListHead, &pldev->leLink);
|
|
|
|
|
|
|
|
/* Increase ref count */
|
|
|
|
pldev->cRefs++;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
/* Unlock loader */
|
|
|
|
EngReleaseSemaphore(ghsemLDEVList);
|
|
|
|
|
|
|
|
TRACE("LDEVOBJ_pLoadInternal returning %p\n", pldev);
|
|
|
|
return pldev;
|
|
|
|
}
|
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
PLDEVOBJ
|
|
|
|
NTAPI
|
2022-01-09 08:42:23 +00:00
|
|
|
LDEVOBJ_pLoadDriver(
|
2013-11-11 19:09:53 +00:00
|
|
|
_In_z_ LPWSTR pwszDriverName,
|
|
|
|
_In_ ULONG ldevtype)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
2010-10-23 21:59:21 +00:00
|
|
|
WCHAR acwBuffer[MAX_PATH];
|
2014-02-09 12:46:19 +00:00
|
|
|
PLIST_ENTRY pleLink;
|
2010-01-30 21:12:42 +00:00
|
|
|
PLDEVOBJ pldev;
|
|
|
|
UNICODE_STRING strDriverName;
|
2013-01-01 09:40:48 +00:00
|
|
|
SIZE_T cwcLength;
|
2010-10-23 21:59:21 +00:00
|
|
|
LPWSTR pwsz;
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
TRACE("LDEVOBJ_pLoadDriver(%ls, %lu)\n", pwszDriverName, ldevtype);
|
2010-10-23 21:59:21 +00:00
|
|
|
ASSERT(pwszDriverName);
|
|
|
|
|
|
|
|
/* Initialize buffer for the the driver name */
|
|
|
|
RtlInitEmptyUnicodeString(&strDriverName, acwBuffer, sizeof(acwBuffer));
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2010-10-23 21:59:21 +00:00
|
|
|
/* Start path with systemroot */
|
|
|
|
RtlAppendUnicodeToString(&strDriverName, L"\\SystemRoot\\System32\\");
|
|
|
|
|
|
|
|
/* Get Length of given string */
|
|
|
|
cwcLength = wcslen(pwszDriverName);
|
|
|
|
|
|
|
|
/* Check if we have a system32 path given */
|
|
|
|
pwsz = pwszDriverName + cwcLength;
|
|
|
|
while (pwsz > pwszDriverName)
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
if ((*pwsz == L'\\') && (_wcsnicmp(pwsz, L"\\system32\\", 10) == 0))
|
2010-10-23 21:59:21 +00:00
|
|
|
{
|
|
|
|
/* Driver name starts after system32 */
|
|
|
|
pwsz += 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pwsz--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the driver name */
|
|
|
|
RtlAppendUnicodeToString(&strDriverName, pwsz);
|
|
|
|
|
|
|
|
/* MSDN says "The driver must include this suffix in the pwszDriver string."
|
2013-11-11 19:09:53 +00:00
|
|
|
But in fact it's optional. The function can also load .sys files without
|
|
|
|
appending the .dll extension. */
|
|
|
|
if ((cwcLength < 4) ||
|
|
|
|
((_wcsnicmp(pwszDriverName + cwcLength - 4, L".dll", 4) != 0) &&
|
|
|
|
(_wcsnicmp(pwszDriverName + cwcLength - 4, L".sys", 4) != 0)) )
|
2010-10-23 21:59:21 +00:00
|
|
|
{
|
|
|
|
/* Append the .dll suffix */
|
|
|
|
RtlAppendUnicodeToString(&strDriverName, L".dll");
|
|
|
|
}
|
2010-01-30 21:12:42 +00:00
|
|
|
|
|
|
|
/* Lock loader */
|
|
|
|
EngAcquireSemaphore(ghsemLDEVList);
|
|
|
|
|
|
|
|
/* Search the List of LDEVS for the driver name */
|
2014-02-09 12:46:19 +00:00
|
|
|
for (pleLink = gleLdevListHead.Flink;
|
|
|
|
pleLink != &gleLdevListHead;
|
|
|
|
pleLink = pleLink->Flink)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
2014-02-09 12:46:19 +00:00
|
|
|
pldev = CONTAINING_RECORD(pleLink, LDEVOBJ, leLink);
|
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/* Check if the ldev is associated with a file */
|
|
|
|
if (pldev->pGdiDriverInfo)
|
|
|
|
{
|
2010-10-23 21:59:21 +00:00
|
|
|
/* Check for match (case insensative) */
|
2014-06-21 11:07:51 +00:00
|
|
|
if (RtlEqualUnicodeString(&pldev->pGdiDriverInfo->DriverName, &strDriverName, TRUE))
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
/* Image found in LDEV list */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we find one? */
|
2014-02-09 12:46:19 +00:00
|
|
|
if (pleLink == &gleLdevListHead)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
/* No, allocate a new LDEVOBJ */
|
|
|
|
pldev = LDEVOBJ_AllocLDEV(ldevtype);
|
|
|
|
if (!pldev)
|
|
|
|
{
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("Could not allocate LDEV\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the image */
|
|
|
|
if (!LDEVOBJ_bLoadImage(pldev, &strDriverName))
|
|
|
|
{
|
|
|
|
LDEVOBJ_vFreeLDEV(pldev);
|
|
|
|
pldev = NULL;
|
2013-11-11 19:09:53 +00:00
|
|
|
ERR("LDEVOBJ_bLoadImage failed\n");
|
2010-01-30 21:12:42 +00:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
2022-04-17 11:52:10 +00:00
|
|
|
/* Load the driver */
|
|
|
|
if (!LDEVOBJ_bEnableDriver(pldev, pldev->pGdiDriverInfo->EntryPoint))
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
2022-04-17 11:52:10 +00:00
|
|
|
ERR("LDEVOBJ_bEnableDriver failed\n");
|
2013-11-11 19:09:53 +00:00
|
|
|
|
2022-04-17 11:52:10 +00:00
|
|
|
/* Unload the image. */
|
|
|
|
LDEVOBJ_bUnloadImage(pldev);
|
|
|
|
LDEVOBJ_vFreeLDEV(pldev);
|
|
|
|
pldev = NULL;
|
|
|
|
goto leave;
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the LDEV into the global list */
|
2014-02-09 12:46:19 +00:00
|
|
|
InsertHeadList(&gleLdevListHead, &pldev->leLink);
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increase ref count */
|
|
|
|
pldev->cRefs++;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
/* Unlock loader */
|
|
|
|
EngReleaseSemaphore(ghsemLDEVList);
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
TRACE("LDEVOBJ_pLoadDriver returning %p\n", pldev);
|
2010-01-30 21:12:42 +00:00
|
|
|
return pldev;
|
|
|
|
}
|
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
static
|
|
|
|
VOID
|
|
|
|
LDEVOBJ_vDereference(
|
|
|
|
_Inout_ PLDEVOBJ pldev)
|
|
|
|
{
|
|
|
|
/* Lock loader */
|
|
|
|
EngAcquireSemaphore(ghsemLDEVList);
|
|
|
|
|
|
|
|
/* Decrement reference count */
|
|
|
|
ASSERT(pldev->cRefs > 0);
|
|
|
|
pldev->cRefs--;
|
|
|
|
|
|
|
|
/* More references left? */
|
|
|
|
if (pldev->cRefs > 0)
|
|
|
|
{
|
|
|
|
EngReleaseSemaphore(ghsemLDEVList);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LDEVOBJ_vDisableDriver(pldev);
|
|
|
|
|
|
|
|
if (LDEVOBJ_bUnloadImage(pldev))
|
|
|
|
{
|
|
|
|
/* Remove ldev from the list */
|
|
|
|
RemoveEntryList(&pldev->leLink);
|
|
|
|
|
|
|
|
/* Free the driver info structure */
|
|
|
|
LDEVOBJ_vFreeLDEV(pldev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Failed to unload driver '%wZ', trying to re-enable it.\n", &pldev->pGdiDriverInfo->DriverName);
|
|
|
|
LDEVOBJ_bEnableDriver(pldev, pldev->pGdiDriverInfo->EntryPoint);
|
|
|
|
|
|
|
|
/* Increment again reference count */
|
|
|
|
pldev->cRefs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unlock loader */
|
|
|
|
EngReleaseSemaphore(ghsemLDEVList);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
LDEVOBJ_ulGetDriverModes(
|
|
|
|
_In_ LPWSTR pwszDriverName,
|
|
|
|
_In_ HANDLE hDriver,
|
|
|
|
_Out_ PDEVMODEW *ppdm)
|
|
|
|
{
|
|
|
|
PLDEVOBJ pldev = NULL;
|
|
|
|
ULONG cbSize = 0;
|
|
|
|
PDEVMODEW pdm = NULL;
|
|
|
|
|
|
|
|
TRACE("LDEVOBJ_ulGetDriverModes('%ls', %p)\n", pwszDriverName, hDriver);
|
|
|
|
|
|
|
|
pldev = LDEVOBJ_pLoadDriver(pwszDriverName, LDEV_DEVICE_DISPLAY);
|
|
|
|
if (!pldev)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Mirror drivers may omit this function */
|
|
|
|
if (!pldev->pfn.GetModes)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Call the driver to get the required size */
|
|
|
|
cbSize = pldev->pfn.GetModes(hDriver, 0, NULL);
|
|
|
|
if (!cbSize)
|
|
|
|
{
|
|
|
|
ERR("DrvGetModes returned 0\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a buffer for the DEVMODE array */
|
|
|
|
pdm = ExAllocatePoolWithTag(PagedPool, cbSize, GDITAG_DEVMODE);
|
|
|
|
if (!pdm)
|
|
|
|
{
|
|
|
|
ERR("Could not allocate devmodeinfo\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the driver again to fill the buffer */
|
|
|
|
cbSize = pldev->pfn.GetModes(hDriver, cbSize, pdm);
|
|
|
|
if (!cbSize)
|
|
|
|
{
|
|
|
|
/* Could not get modes */
|
|
|
|
ERR("DrvrGetModes returned 0 on second call\n");
|
|
|
|
ExFreePoolWithTag(pdm, GDITAG_DEVMODE);
|
|
|
|
pdm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (pldev)
|
|
|
|
LDEVOBJ_vDereference(pldev);
|
|
|
|
|
|
|
|
*ppdm = pdm;
|
|
|
|
return cbSize;
|
|
|
|
}
|
|
|
|
|
2022-01-09 09:33:10 +00:00
|
|
|
BOOL
|
|
|
|
LDEVOBJ_bBuildDevmodeList(
|
|
|
|
_Inout_ PGRAPHICS_DEVICE pGraphicsDevice)
|
|
|
|
{
|
|
|
|
PWSTR pwsz;
|
|
|
|
PDEVMODEINFO pdminfo;
|
|
|
|
PDEVMODEW pdm, pdmEnd;
|
|
|
|
ULONG i, cModes = 0;
|
|
|
|
ULONG cbSize, cbFull;
|
|
|
|
|
|
|
|
if (pGraphicsDevice->pdevmodeInfo)
|
|
|
|
return TRUE;
|
|
|
|
ASSERT(pGraphicsDevice->pDevModeList == NULL);
|
|
|
|
|
|
|
|
pwsz = pGraphicsDevice->pDiplayDrivers;
|
|
|
|
|
|
|
|
/* Loop through the driver names
|
|
|
|
* This is a REG_MULTI_SZ string */
|
|
|
|
for (; *pwsz; pwsz += wcslen(pwsz) + 1)
|
|
|
|
{
|
|
|
|
/* Get the mode list from the driver */
|
|
|
|
TRACE("Trying driver: %ls\n", pwsz);
|
|
|
|
cbSize = LDEVOBJ_ulGetDriverModes(pwsz, pGraphicsDevice->DeviceObject, &pdm);
|
|
|
|
if (!cbSize)
|
|
|
|
{
|
|
|
|
WARN("Driver %ls returned no valid mode\n", pwsz);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add space for the header */
|
|
|
|
cbFull = cbSize + FIELD_OFFSET(DEVMODEINFO, adevmode);
|
|
|
|
|
|
|
|
/* Allocate a buffer for the DEVMODE array */
|
|
|
|
pdminfo = ExAllocatePoolWithTag(PagedPool, cbFull, GDITAG_DEVMODE);
|
|
|
|
if (!pdminfo)
|
|
|
|
{
|
|
|
|
ERR("Could not allocate devmodeinfo\n");
|
2022-04-18 14:22:30 +00:00
|
|
|
ExFreePoolWithTag(pdm, GDITAG_DEVMODE);
|
2022-01-09 09:33:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdminfo->cbdevmode = cbSize;
|
|
|
|
RtlCopyMemory(pdminfo->adevmode, pdm, cbSize);
|
2022-04-18 14:22:30 +00:00
|
|
|
ExFreePoolWithTag(pdm, GDITAG_DEVMODE);
|
2022-01-09 09:33:10 +00:00
|
|
|
|
|
|
|
/* Attach the mode info to the device */
|
|
|
|
pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo;
|
|
|
|
pGraphicsDevice->pdevmodeInfo = pdminfo;
|
|
|
|
|
|
|
|
/* Loop all DEVMODEs */
|
|
|
|
pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
|
|
|
|
for (pdm = pdminfo->adevmode;
|
|
|
|
(pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
|
|
|
|
pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
|
|
|
|
{
|
|
|
|
/* Count this DEVMODE */
|
|
|
|
cModes++;
|
|
|
|
|
|
|
|
/* Some drivers like the VBox driver don't fill the dmDeviceName
|
|
|
|
with the name of the display driver. So fix that here. */
|
|
|
|
RtlStringCbCopyW(pdm->dmDeviceName, sizeof(pdm->dmDeviceName), pwsz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
|
|
|
|
{
|
|
|
|
ERR("No devmodes\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate an index buffer */
|
|
|
|
pGraphicsDevice->cDevModes = cModes;
|
|
|
|
pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
cModes * sizeof(DEVMODEENTRY),
|
|
|
|
GDITAG_GDEVICE);
|
|
|
|
if (!pGraphicsDevice->pDevModeList)
|
|
|
|
{
|
|
|
|
ERR("No devmode list\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop through all DEVMODEINFOs */
|
|
|
|
for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
|
|
|
|
pdminfo;
|
|
|
|
pdminfo = pdminfo->pdmiNext)
|
|
|
|
{
|
|
|
|
/* Calculate End of the DEVMODEs */
|
|
|
|
pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
|
|
|
|
|
|
|
|
/* Loop through the DEVMODEs */
|
|
|
|
for (pdm = pdminfo->adevmode;
|
|
|
|
(pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
|
|
|
|
pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
|
|
|
|
{
|
|
|
|
TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n",
|
|
|
|
pdm->dmDeviceName,
|
|
|
|
pdm->dmPelsWidth,
|
|
|
|
pdm->dmPelsHeight,
|
|
|
|
pdm->dmBitsPerPel,
|
|
|
|
pdm->dmDisplayFrequency);
|
|
|
|
|
|
|
|
/* Initialize the entry */
|
|
|
|
pGraphicsDevice->pDevModeList[i].dwFlags = 0;
|
|
|
|
pGraphicsDevice->pDevModeList[i].pdm = pdm;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2022-05-22 20:47:20 +00:00
|
|
|
/* Search the closest display mode according to some settings.
|
|
|
|
* Note that we don't care about the DM_* flags in dmFields, but check if value != 0 instead */
|
2022-05-01 12:35:02 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
LDEVOBJ_bGetClosestMode(
|
|
|
|
_Inout_ PGRAPHICS_DEVICE pGraphicsDevice,
|
|
|
|
_In_ PDEVMODEW RequestedMode,
|
|
|
|
_Out_ PDEVMODEW *pSelectedMode)
|
|
|
|
{
|
2022-05-22 20:47:20 +00:00
|
|
|
DEVMODEW dmDiff;
|
|
|
|
PDEVMODEW pdmCurrent, pdmBest = NULL;
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
/* Use a DEVMODE to keep the differences between best mode found and expected mode.
|
|
|
|
* Initialize fields to max value so we can find better modes. */
|
|
|
|
dmDiff.dmPelsWidth = 0xffffffff;
|
|
|
|
dmDiff.dmPelsHeight = 0xffffffff;
|
|
|
|
dmDiff.dmBitsPerPel = 0xffffffff;
|
|
|
|
dmDiff.dmDisplayFrequency = 0xffffffff;
|
2022-05-01 12:35:02 +00:00
|
|
|
|
2022-05-22 20:47:20 +00:00
|
|
|
/* Search the closest mode */
|
|
|
|
#define DM_DIFF(field) (RequestedMode->field > pdmCurrent->field ? (RequestedMode->field - pdmCurrent->field) : (pdmCurrent->field - RequestedMode->field))
|
|
|
|
for (i = 0; i < pGraphicsDevice->cDevModes; i++)
|
2022-05-01 12:35:02 +00:00
|
|
|
{
|
2022-05-22 20:47:20 +00:00
|
|
|
pdmCurrent = pGraphicsDevice->pDevModeList[i].pdm;
|
|
|
|
|
|
|
|
/* Skip current mode if it is worse than best mode found */
|
|
|
|
if (RequestedMode->dmPelsWidth != 0 && DM_DIFF(dmPelsWidth) > dmDiff.dmPelsWidth)
|
|
|
|
continue;
|
|
|
|
if (RequestedMode->dmPelsHeight != 0 && DM_DIFF(dmPelsHeight) > dmDiff.dmPelsHeight)
|
|
|
|
continue;
|
|
|
|
if (RequestedMode->dmBitsPerPel != 0 && DM_DIFF(dmBitsPerPel) > dmDiff.dmBitsPerPel)
|
|
|
|
continue;
|
|
|
|
if (RequestedMode->dmDisplayFrequency != 0 && DM_DIFF(dmDisplayFrequency) > dmDiff.dmDisplayFrequency)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Better (or equivalent) mode found. Update differences */
|
|
|
|
dmDiff.dmPelsWidth = DM_DIFF(dmPelsWidth);
|
|
|
|
dmDiff.dmPelsHeight = DM_DIFF(dmPelsHeight);
|
|
|
|
dmDiff.dmBitsPerPel = DM_DIFF(dmBitsPerPel);
|
|
|
|
dmDiff.dmDisplayFrequency = DM_DIFF(dmDisplayFrequency);
|
|
|
|
pdmBest = pdmCurrent;
|
2022-05-01 12:35:02 +00:00
|
|
|
}
|
2022-05-22 20:47:20 +00:00
|
|
|
#undef DM_DIFF
|
2022-05-01 12:35:02 +00:00
|
|
|
|
2022-05-22 20:47:20 +00:00
|
|
|
if (pdmBest)
|
2022-05-22 12:13:48 +00:00
|
|
|
{
|
2022-05-22 20:47:20 +00:00
|
|
|
TRACE("Closest display mode to '%dx%dx%d %d Hz' is '%dx%dx%d %d Hz'\n",
|
|
|
|
RequestedMode->dmPelsWidth,
|
|
|
|
RequestedMode->dmPelsHeight,
|
|
|
|
RequestedMode->dmBitsPerPel,
|
|
|
|
RequestedMode->dmDisplayFrequency,
|
|
|
|
pdmBest->dmPelsWidth,
|
|
|
|
pdmBest->dmPelsHeight,
|
|
|
|
pdmBest->dmBitsPerPel,
|
|
|
|
pdmBest->dmDisplayFrequency);
|
2022-05-22 12:13:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 20:47:20 +00:00
|
|
|
*pSelectedMode = pdmBest;
|
|
|
|
return pdmBest != NULL;
|
2022-05-01 12:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 09:44:53 +00:00
|
|
|
BOOL
|
|
|
|
LDEVOBJ_bProbeAndCaptureDevmode(
|
|
|
|
_Inout_ PGRAPHICS_DEVICE pGraphicsDevice,
|
|
|
|
_In_ PDEVMODEW RequestedMode,
|
|
|
|
_Out_ PDEVMODEW *pSelectedMode,
|
|
|
|
_In_ BOOL bSearchClosestMode)
|
|
|
|
{
|
2022-05-22 12:23:26 +00:00
|
|
|
DEVMODEW dmSearch;
|
2022-01-09 09:44:53 +00:00
|
|
|
PDEVMODEW pdmCurrent, pdm, pdmSelected = NULL;
|
|
|
|
ULONG i;
|
2022-05-22 12:23:26 +00:00
|
|
|
ULONG ulVirtualWidth = 0, ulVirtualHeight = 0;
|
|
|
|
BOOL bResult = TRUE;
|
|
|
|
NTSTATUS Status;
|
2022-01-09 09:44:53 +00:00
|
|
|
|
|
|
|
if (!LDEVOBJ_bBuildDevmodeList(pGraphicsDevice))
|
|
|
|
return FALSE;
|
|
|
|
|
2022-05-22 12:23:26 +00:00
|
|
|
/* At first, load information from registry */
|
|
|
|
RtlZeroMemory(&dmSearch, sizeof(dmSearch));
|
2022-06-05 12:49:47 +00:00
|
|
|
Status = EngpGetDisplayDriverParameters(pGraphicsDevice, &dmSearch);
|
2022-05-22 12:23:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2022-01-09 09:44:53 +00:00
|
|
|
{
|
2022-05-22 12:23:26 +00:00
|
|
|
ERR("EngpGetDisplayDriverParameters() failed with status 0x%08x\n", Status);
|
|
|
|
return FALSE;
|
2022-01-09 09:44:53 +00:00
|
|
|
}
|
2022-05-22 12:23:26 +00:00
|
|
|
|
|
|
|
/* Override values with the new ones provided */
|
|
|
|
|
|
|
|
_SEH2_TRY
|
2022-01-09 09:44:53 +00:00
|
|
|
{
|
2022-05-22 12:23:26 +00:00
|
|
|
bSearchClosestMode |= RequestedMode->dmFields == 0;
|
|
|
|
|
|
|
|
/* Copy standard fields (if provided) */
|
|
|
|
if (RequestedMode->dmFields & DM_BITSPERPEL && RequestedMode->dmBitsPerPel != 0)
|
|
|
|
dmSearch.dmBitsPerPel = RequestedMode->dmBitsPerPel;
|
|
|
|
if (RequestedMode->dmFields & DM_PELSWIDTH && RequestedMode->dmPelsWidth != 0)
|
|
|
|
dmSearch.dmPelsWidth = RequestedMode->dmPelsWidth;
|
|
|
|
if (RequestedMode->dmFields & DM_PELSHEIGHT && RequestedMode->dmPelsHeight != 0)
|
|
|
|
dmSearch.dmPelsHeight = RequestedMode->dmPelsHeight;
|
|
|
|
if (RequestedMode->dmFields & DM_DISPLAYFREQUENCY && RequestedMode->dmDisplayFrequency != 0)
|
|
|
|
dmSearch.dmDisplayFrequency = RequestedMode->dmDisplayFrequency;
|
|
|
|
|
|
|
|
if ((RequestedMode->dmFields & (DM_PANNINGWIDTH | DM_PANNINGHEIGHT)) == (DM_PANNINGWIDTH | DM_PANNINGHEIGHT) &&
|
|
|
|
RequestedMode->dmPanningWidth != 0 && RequestedMode->dmPanningHeight != 0 &&
|
|
|
|
RequestedMode->dmPanningWidth < dmSearch.dmPelsWidth &&
|
|
|
|
RequestedMode->dmPanningHeight < dmSearch.dmPelsHeight)
|
2022-05-01 12:35:02 +00:00
|
|
|
{
|
2022-05-22 12:23:26 +00:00
|
|
|
/* Get new panning values */
|
|
|
|
ulVirtualWidth = RequestedMode->dmPelsWidth;
|
|
|
|
ulVirtualHeight = RequestedMode->dmPelsHeight;
|
|
|
|
dmSearch.dmPelsWidth = RequestedMode->dmPanningWidth;
|
|
|
|
dmSearch.dmPelsHeight = RequestedMode->dmPanningHeight;
|
2022-05-01 12:35:02 +00:00
|
|
|
}
|
2022-05-22 12:23:26 +00:00
|
|
|
else if (dmSearch.dmPanningWidth != 0 && dmSearch.dmPanningHeight != 0 &&
|
|
|
|
dmSearch.dmPanningWidth < dmSearch.dmPelsWidth &&
|
|
|
|
dmSearch.dmPanningHeight < dmSearch.dmPelsHeight)
|
|
|
|
{
|
|
|
|
/* Keep existing panning values */
|
|
|
|
ulVirtualWidth = dmSearch.dmPelsWidth;
|
|
|
|
ulVirtualHeight = dmSearch.dmPelsHeight;
|
|
|
|
dmSearch.dmPelsWidth = dmSearch.dmPanningWidth;
|
|
|
|
dmSearch.dmPelsHeight = dmSearch.dmPanningHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
bResult = FALSE;
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2022-01-09 09:44:53 +00:00
|
|
|
|
2022-05-22 12:23:26 +00:00
|
|
|
if (!bResult)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (bSearchClosestMode)
|
|
|
|
{
|
|
|
|
if (LDEVOBJ_bGetClosestMode(pGraphicsDevice, &dmSearch, &pdmSelected))
|
2022-05-01 12:35:02 +00:00
|
|
|
{
|
2022-05-22 12:23:26 +00:00
|
|
|
/* Ok, found a closest mode. Update search */
|
|
|
|
dmSearch.dmBitsPerPel = pdmSelected->dmBitsPerPel;
|
|
|
|
dmSearch.dmPelsWidth = pdmSelected->dmPelsWidth;
|
|
|
|
dmSearch.dmPelsHeight = pdmSelected->dmPelsHeight;
|
|
|
|
dmSearch.dmDisplayFrequency = pdmSelected->dmDisplayFrequency;
|
2022-05-01 12:35:02 +00:00
|
|
|
}
|
2022-01-09 09:44:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 12:23:26 +00:00
|
|
|
/* Now, search the exact mode to return to caller */
|
|
|
|
for (i = 0; i < pGraphicsDevice->cDevModes; i++)
|
|
|
|
{
|
|
|
|
pdmCurrent = pGraphicsDevice->pDevModeList[i].pdm;
|
|
|
|
|
|
|
|
/* For now, we only need those */
|
|
|
|
if (pdmCurrent->dmBitsPerPel != dmSearch.dmBitsPerPel)
|
|
|
|
continue;
|
|
|
|
if (pdmCurrent->dmPelsWidth != dmSearch.dmPelsWidth)
|
|
|
|
continue;
|
|
|
|
if (pdmCurrent->dmPelsHeight != dmSearch.dmPelsHeight)
|
|
|
|
continue;
|
|
|
|
if (pdmCurrent->dmDisplayFrequency != dmSearch.dmDisplayFrequency)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pdmSelected = pdmCurrent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pdmSelected)
|
|
|
|
{
|
|
|
|
ERR("Requested mode not found (%dx%dx%d %d Hz)\n",
|
|
|
|
dmSearch.dmPelsWidth,
|
|
|
|
dmSearch.dmPelsHeight,
|
|
|
|
dmSearch.dmBitsPerPel,
|
|
|
|
dmSearch.dmDisplayFrequency);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-01-09 09:44:53 +00:00
|
|
|
/* Allocate memory for output */
|
|
|
|
pdm = ExAllocatePoolZero(PagedPool, pdmSelected->dmSize + pdmSelected->dmDriverExtra, GDITAG_DEVMODE);
|
|
|
|
if (!pdm)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Copy selected mode */
|
|
|
|
RtlCopyMemory(pdm, pdmSelected, pdmSelected->dmSize);
|
|
|
|
RtlCopyMemory((PVOID)((ULONG_PTR)pdm + pdm->dmSize),
|
|
|
|
(PVOID)((ULONG_PTR)pdmSelected + pdmSelected->dmSize),
|
|
|
|
pdmSelected->dmDriverExtra);
|
|
|
|
|
2022-05-22 12:23:26 +00:00
|
|
|
/* Add back panning */
|
|
|
|
if (ulVirtualWidth != 0 && ulVirtualHeight != 0 &&
|
|
|
|
pdm->dmPelsWidth < ulVirtualWidth &&
|
|
|
|
pdm->dmPelsHeight < ulVirtualHeight)
|
|
|
|
{
|
|
|
|
pdm->dmFields |= DM_PANNINGWIDTH | DM_PANNINGHEIGHT;
|
|
|
|
pdm->dmPanningWidth = pdm->dmPelsWidth;
|
|
|
|
pdm->dmPanningHeight = pdm->dmPelsHeight;
|
|
|
|
pdm->dmPelsWidth = ulVirtualWidth;
|
|
|
|
pdm->dmPelsHeight = ulVirtualHeight;
|
|
|
|
}
|
|
|
|
|
2022-01-09 09:44:53 +00:00
|
|
|
*pSelectedMode = pdm;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-30 21:12:42 +00:00
|
|
|
/** Exported functions ********************************************************/
|
|
|
|
|
|
|
|
HANDLE
|
|
|
|
APIENTRY
|
|
|
|
EngLoadImage(
|
2013-01-01 09:40:48 +00:00
|
|
|
_In_ LPWSTR pwszDriverName)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
2022-01-09 08:42:23 +00:00
|
|
|
return (HANDLE)LDEVOBJ_pLoadDriver(pwszDriverName, LDEV_IMAGE);
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
APIENTRY
|
|
|
|
EngUnloadImage(
|
2013-01-01 09:40:48 +00:00
|
|
|
_In_ HANDLE hModule)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
PLDEVOBJ pldev = (PLDEVOBJ)hModule;
|
|
|
|
|
|
|
|
/* Make sure the LDEV is in the list */
|
2014-02-09 12:46:19 +00:00
|
|
|
ASSERT((pldev->leLink.Flink != NULL) && (pldev->leLink.Blink != NULL));
|
2010-01-30 21:12:42 +00:00
|
|
|
|
2022-01-09 08:42:23 +00:00
|
|
|
LDEVOBJ_vDereference(pldev);
|
2010-01-30 21:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PVOID
|
|
|
|
APIENTRY
|
|
|
|
EngFindImageProcAddress(
|
2013-01-01 09:40:48 +00:00
|
|
|
_In_ HANDLE hModule,
|
|
|
|
_In_ LPSTR lpProcName)
|
2010-01-30 21:12:42 +00:00
|
|
|
{
|
|
|
|
PLDEVOBJ pldev = (PLDEVOBJ)hModule;
|
|
|
|
|
|
|
|
ASSERT(gpldevWin32k != NULL);
|
|
|
|
|
|
|
|
/* Check if win32k is requested */
|
|
|
|
if (!pldev)
|
|
|
|
{
|
|
|
|
pldev = gpldevWin32k;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the drivers entry point is requested */
|
|
|
|
if (_strnicmp(lpProcName, "DrvEnableDriver", 15) == 0)
|
|
|
|
{
|
|
|
|
return pldev->pGdiDriverInfo->EntryPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find the address */
|
|
|
|
return LDEVOBJ_pvFindImageProcAddress(pldev, lpProcName);
|
|
|
|
}
|
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
/* EOF */
|