/** Private functions *********************************************************/
-BOOL
+INIT_FUNCTION
+NTSTATUS
NTAPI
InitLDEVImpl()
{
ghsemLDEVList = EngCreateSemaphore();
if (!ghsemLDEVList)
{
- return FALSE;
+ return STATUS_INSUFFICIENT_RESOURCES;
}
/* Allocate a LDEVOBJ for win32k */
GDITAG_LDEV);
if (!gpldevWin32k)
{
- return FALSE;
+ return STATUS_NO_MEMORY;
}
/* Initialize the LDEVOBJ for win32k */
gpldevWin32k->cRefs = 1;
gpldevWin32k->ulDriverVersion = GDI_ENGINE_VERSION;
gpldevWin32k->pGdiDriverInfo = (PVOID)(gpldevWin32k + 1);
- gpldevWin32k->pGdiDriverInfo->DriverName.Buffer = NULL; // FIXME
+ RtlInitUnicodeString(&gpldevWin32k->pGdiDriverInfo->DriverName,
+ L"\\SystemRoot\\System32\\win32k.sys");
gpldevWin32k->pGdiDriverInfo->ImageAddress = &__ImageBase;
gpldevWin32k->pGdiDriverInfo->SectionPointer = NULL;
gpldevWin32k->pGdiDriverInfo->EntryPoint = (PVOID)DriverEntry;
gpldevWin32k->pGdiDriverInfo->ExportSectionPointer = NULL;
gpldevWin32k->pGdiDriverInfo->ImageLength = 0; // FIXME;
- return TRUE;
+ return STATUS_SUCCESS;
}
PLDEVOBJ
ULONG cbSize, cbFull;
PDEVMODEINFO pdminfo;
- DPRINT1("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
+ DPRINT("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
/* Call the driver to get the required size */
cbSize = pldev->pfn.GetModes(hDriver, 0, NULL);
return FALSE;
}
- /* Initialize the UNICODE_STRING */
- pDriverInfo->DriverName.Buffer = (PWSTR)(pDriverInfo + 1);
- pDriverInfo->DriverName.Length = pstrPathName->Length;
- pDriverInfo->DriverName.MaximumLength = pstrPathName->Length;
-
- /* Copy the driver name */
-// RtlCopyUnicodeString(pDriverInfo->DriverName, pstrPathName);
- RtlCopyMemory(pDriverInfo->DriverName.Buffer,
- pstrPathName->Buffer,
- pstrPathName->Length);
+ /* Initialize the UNICODE_STRING and copy the driver name */
+ RtlInitEmptyUnicodeString(&pDriverInfo->DriverName,
+ (PWSTR)(pDriverInfo + 1),
+ pstrPathName->Length);
+ RtlCopyUnicodeString(&pDriverInfo->DriverName, pstrPathName);
/* Try to load the driver */
Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation,
if (!NT_SUCCESS(Status))
{
- DPRINT1("Failed to load a GDI driver: '%S'\n", pstrPathName->Buffer);
- ASSERT(FALSE);
+ DPRINT1("Failed to load a GDI driver: '%S', Status = 0x%lx\n",
+ pstrPathName->Buffer, Status);
+
/* Free the allocated memory */
ExFreePoolWithTag(pDriverInfo, TAG_LDEV);
return FALSE;
LPWSTR pwszDriverName,
ULONG ldevtype)
{
+ WCHAR acwBuffer[MAX_PATH];
PLDEVOBJ pldev;
UNICODE_STRING strDriverName;
+ ULONG cwcLength;
+ LPWSTR pwsz;
DPRINT("EngLoadImageEx(%ls, %ld)\n", pwszDriverName, ldevtype);
+ ASSERT(pwszDriverName);
+
+ /* Initialize buffer for the the driver name */
+ RtlInitEmptyUnicodeString(&strDriverName, acwBuffer, sizeof(acwBuffer));
+
+ /* 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)
+ {
+ if (_wcsnicmp(pwsz, L"\\system32\\", 10) == 0)
+ {
+ /* Driver name starts after system32 */
+ pwsz += 10;
+ break;
+ }
+ pwsz--;
+ }
- /* Initialize the driver name */
- RtlInitUnicodeString(&strDriverName, pwszDriverName);
+ /* Append the driver name */
+ RtlAppendUnicodeToString(&strDriverName, pwsz);
+
+ /* MSDN says "The driver must include this suffix in the pwszDriver string."
+ But in fact it's optional. */
+ if (_wcsnicmp(pwszDriverName + cwcLength - 4, L".dll", 4) != 0)
+ {
+ /* Append the .dll suffix */
+ RtlAppendUnicodeToString(&strDriverName, L".dll");
+ }
/* Lock loader */
EngAcquireSemaphore(ghsemLDEVList);
/* Check if the ldev is associated with a file */
if (pldev->pGdiDriverInfo)
{
- /* Check for match */
+ /* Check for match (case insensative) */
if (RtlEqualUnicodeString(&pldev->pGdiDriverInfo->DriverName, &strDriverName, 1))
{
/* Image found in LDEV list */
return pldev;
}
-PLDEVOBJ
-APIENTRY
-EngLoadDriver(
- LPWSTR pwszDriverName,
- ULONG ldevtype)
-{
- WCHAR acwBuffer[MAX_PATH];
- PLDEVOBJ pldev;
-
- ASSERT(pwszDriverName);
- DPRINT("EngLoadDriver(%ls, %ld)\n", pwszDriverName, ldevtype);
-
- /* Create a full file name */ // FIXME: do better than that
- swprintf(acwBuffer, L"\\SystemRoot\\System32\\%ls.dll", pwszDriverName);
-
- pldev = EngLoadImageEx(acwBuffer, ldevtype);
-
- return pldev;
-}
/** Exported functions ********************************************************/