mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
Simplify code by passing PDEVICE_OBJECT instead of HANDLE around for
miniport device, fixing a reference-counting bug I introduced earlier along the way. svn path=/trunk/; revision=6560
This commit is contained in:
parent
0372ed1758
commit
daad4f8d41
6 changed files with 32 additions and 82 deletions
|
@ -114,7 +114,7 @@ typedef struct
|
|||
GDIINFO GDIInfo;
|
||||
DEVINFO DevInfo;
|
||||
DRIVER_FUNCTIONS DriverFunctions;
|
||||
HANDLE DisplayDevice;
|
||||
PDEVICE_OBJECT VideoDeviceObject;
|
||||
} GDIDEVICE;
|
||||
|
||||
/* Internal functions */
|
||||
|
|
|
@ -160,7 +160,7 @@ typedef struct _DRIVER_FUNCTIONS
|
|||
|
||||
BOOL DRIVER_RegisterDriver(LPCWSTR Name, PGD_ENABLEDRIVER EnableDriver);
|
||||
PGD_ENABLEDRIVER DRIVER_FindDDIDriver(LPCWSTR Name);
|
||||
HANDLE DRIVER_FindMPDriver(LPCWSTR Name);
|
||||
PDEVICE_OBJECT DRIVER_FindMPDriver(LPCWSTR Name);
|
||||
BOOL DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED,
|
||||
PDRIVER_FUNCTIONS DF);
|
||||
BOOL DRIVER_UnregisterDriver(LPCWSTR Name);
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#ifndef __WIN32K_MISC_H
|
||||
#define __WIN32K_MISC_H
|
||||
|
||||
/* Process context in which miniport driver is opened/used */
|
||||
extern PEPROCESS Win32kDeviceProcess;
|
||||
|
||||
BOOLEAN
|
||||
STDCALL
|
||||
Win32kInitialize (VOID);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: dllmain.c,v 1.47 2003/11/03 18:51:40 ekohl Exp $
|
||||
/* $Id: dllmain.c,v 1.48 2003/11/07 17:40:02 gvg Exp $
|
||||
*
|
||||
* Entry Point for win32k.sys
|
||||
*/
|
||||
|
@ -48,9 +48,6 @@ extern SSDT Win32kSSDT[];
|
|||
extern SSPT Win32kSSPT[];
|
||||
extern ULONG Win32kNumberOfSysCalls;
|
||||
|
||||
PEPROCESS Win32kDeviceProcess;
|
||||
|
||||
|
||||
NTSTATUS STDCALL
|
||||
Win32kProcessCallback (struct _EPROCESS *Process,
|
||||
BOOLEAN Create)
|
||||
|
@ -270,8 +267,6 @@ Win32kInitialize (VOID)
|
|||
{
|
||||
DPRINT("in Win32kInitialize\n");
|
||||
|
||||
Win32kDeviceProcess = PsGetCurrentProcess();
|
||||
|
||||
InitGdiObjectHandleTable ();
|
||||
|
||||
// Initialize FreeType library
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: driver.c,v 1.30 2003/10/25 18:45:13 gvg Exp $
|
||||
/* $Id: driver.c,v 1.31 2003/11/07 17:40:02 gvg Exp $
|
||||
*
|
||||
* GDI Driver support routines
|
||||
* (mostly swiped from Wine)
|
||||
|
@ -235,21 +235,15 @@ BOOL DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED,
|
|||
|
||||
typedef VP_STATUS (*PMP_DRIVERENTRY)(PVOID, PVOID);
|
||||
|
||||
HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
||||
PDEVICE_OBJECT DRIVER_FindMPDriver(LPCWSTR Name)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING DeviceName;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
HANDLE DisplayHandle;
|
||||
NTSTATUS Status;
|
||||
PEPROCESS CurrentProcess;
|
||||
|
||||
CurrentProcess = PsGetCurrentProcess();
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
{
|
||||
/* Switch to process context in which handle is to be valid */
|
||||
KeAttachProcess(Win32kDeviceProcess);
|
||||
}
|
||||
PFILE_OBJECT VideoFileObject;
|
||||
PDEVICE_OBJECT VideoDeviceObject;
|
||||
|
||||
RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
|
@ -263,10 +257,21 @@ HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
|||
&Iosb,
|
||||
0,
|
||||
FILE_SYNCHRONOUS_IO_ALERT);
|
||||
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
KeDetachProcess();
|
||||
Status = ObReferenceObjectByHandle(DisplayHandle,
|
||||
FILE_READ_DATA | FILE_WRITE_DATA,
|
||||
IoFileObjectType,
|
||||
KernelMode,
|
||||
(PVOID *)&VideoFileObject,
|
||||
NULL);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
VideoDeviceObject = VideoFileObject->DeviceObject;
|
||||
ObReferenceObject(VideoDeviceObject);
|
||||
ObDereferenceObject(VideoFileObject);
|
||||
}
|
||||
ZwClose(DisplayHandle);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
|
@ -276,7 +281,7 @@ HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
|||
return(NULL);
|
||||
}
|
||||
|
||||
return(DisplayHandle);
|
||||
return VideoDeviceObject;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: dc.c,v 1.95 2003/11/05 22:46:05 gvg Exp $
|
||||
/* $Id: dc.c,v 1.96 2003/11/07 17:40:02 gvg Exp $
|
||||
*
|
||||
* DC.C - Device context functions
|
||||
*
|
||||
|
@ -192,7 +192,7 @@ NtGdiCreateCompatableDC(HDC hDC)
|
|||
/* DriverName is copied in the AllocDC routine */
|
||||
if(OrigDC == NULL)
|
||||
{
|
||||
NewDC->DeviceDriver = PrimarySurface.DisplayDevice;
|
||||
NewDC->DeviceDriver = (HANDLE) PrimarySurface.VideoDeviceObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -312,23 +312,6 @@ FindDriverFileNames(PUNICODE_STRING DriverFileNames)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void FASTCALL
|
||||
CloseMiniport()
|
||||
{
|
||||
PEPROCESS CurrentProcess;
|
||||
|
||||
CurrentProcess = PsGetCurrentProcess();
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
{
|
||||
KeAttachProcess(Win32kDeviceProcess);
|
||||
}
|
||||
ZwClose(PrimarySurface.DisplayDevice);
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
{
|
||||
KeDetachProcess();
|
||||
}
|
||||
}
|
||||
|
||||
static NTSTATUS STDCALL
|
||||
DevModeCallback(IN PWSTR ValueName,
|
||||
IN ULONG ValueType,
|
||||
|
@ -501,13 +484,10 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
PWSTR CurrentName;
|
||||
BOOL GotDriver;
|
||||
BOOL DoDefault;
|
||||
NTSTATUS Status;
|
||||
PFILE_OBJECT FileObject;
|
||||
PEPROCESS CurrentProcess;
|
||||
extern void FASTCALL IntInitDesktopWindow(ULONG Width, ULONG Height);
|
||||
|
||||
/* Open the miniport driver */
|
||||
if ((PrimarySurface.DisplayDevice = DRIVER_FindMPDriver(Driver)) == NULL)
|
||||
if ((PrimarySurface.VideoDeviceObject = DRIVER_FindMPDriver(Driver)) == NULL)
|
||||
{
|
||||
DPRINT1("FindMPDriver failed\n");
|
||||
return(FALSE);
|
||||
|
@ -565,7 +545,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
RtlFreeUnicodeString(&DriverFileNames);
|
||||
if (! GotDriver)
|
||||
{
|
||||
CloseMiniport();
|
||||
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||
DPRINT1("No suitable DDI driver found\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -580,36 +560,11 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
/* Construct DDI driver function dispatch table */
|
||||
if (!DRIVER_BuildDDIFunctions(&DED, &PrimarySurface.DriverFunctions))
|
||||
{
|
||||
CloseMiniport();
|
||||
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||
DPRINT1("BuildDDIFunctions failed\n");
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
CurrentProcess = PsGetCurrentProcess();
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
{
|
||||
/* Switch to process context in which device handle is valid */
|
||||
KeAttachProcess(Win32kDeviceProcess);
|
||||
}
|
||||
|
||||
Status = ObReferenceObjectByHandle(PrimarySurface.DisplayDevice,
|
||||
FILE_READ_DATA | FILE_WRITE_DATA,
|
||||
IoFileObjectType,
|
||||
KernelMode,
|
||||
(PVOID *)&FileObject,
|
||||
NULL);
|
||||
if (CurrentProcess != Win32kDeviceProcess)
|
||||
{
|
||||
KeDetachProcess();
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
CloseMiniport();
|
||||
DPRINT1("Referencing miniport device failed with status 0x%08x\n", Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Allocate a phyical device handle from the driver */
|
||||
if (SetupDevMode(&PrimarySurface.DMW))
|
||||
{
|
||||
|
@ -624,7 +579,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
&PrimarySurface.DevInfo,
|
||||
NULL,
|
||||
L"",
|
||||
(HANDLE) (FileObject->DeviceObject));
|
||||
(HANDLE) (PrimarySurface.VideoDeviceObject));
|
||||
DoDefault = (NULL == PrimarySurface.PDev);
|
||||
if (DoDefault)
|
||||
{
|
||||
|
@ -650,12 +605,11 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
&PrimarySurface.DevInfo,
|
||||
NULL,
|
||||
L"",
|
||||
(HANDLE) (FileObject->DeviceObject));
|
||||
(HANDLE) (PrimarySurface.VideoDeviceObject));
|
||||
|
||||
if (NULL == PrimarySurface.PDev)
|
||||
{
|
||||
ObDereferenceObject(FileObject);
|
||||
CloseMiniport();
|
||||
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||
DPRINT1("DrvEnablePDEV with default parameters failed\n");
|
||||
DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
|
||||
return FALSE;
|
||||
|
@ -691,8 +645,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
|||
PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev);
|
||||
if (NULL == PrimarySurface.Handle)
|
||||
{
|
||||
ObDereferenceObject(FileObject);
|
||||
CloseMiniport();
|
||||
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||
DPRINT1("DrvEnableSurface failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -824,7 +777,7 @@ NtGdiDeleteDC(HDC DCHandle)
|
|||
CHECKPOINT;
|
||||
DCToDelete->DriverFunctions.DisablePDev(DCToDelete->PDev);
|
||||
|
||||
CloseMiniport();
|
||||
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||
|
||||
PrimarySurfaceCreated = FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue