mirror of
https://github.com/reactos/reactos.git
synced 2025-07-02 00:31:24 +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;
|
GDIINFO GDIInfo;
|
||||||
DEVINFO DevInfo;
|
DEVINFO DevInfo;
|
||||||
DRIVER_FUNCTIONS DriverFunctions;
|
DRIVER_FUNCTIONS DriverFunctions;
|
||||||
HANDLE DisplayDevice;
|
PDEVICE_OBJECT VideoDeviceObject;
|
||||||
} GDIDEVICE;
|
} GDIDEVICE;
|
||||||
|
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
|
|
|
@ -160,7 +160,7 @@ typedef struct _DRIVER_FUNCTIONS
|
||||||
|
|
||||||
BOOL DRIVER_RegisterDriver(LPCWSTR Name, PGD_ENABLEDRIVER EnableDriver);
|
BOOL DRIVER_RegisterDriver(LPCWSTR Name, PGD_ENABLEDRIVER EnableDriver);
|
||||||
PGD_ENABLEDRIVER DRIVER_FindDDIDriver(LPCWSTR Name);
|
PGD_ENABLEDRIVER DRIVER_FindDDIDriver(LPCWSTR Name);
|
||||||
HANDLE DRIVER_FindMPDriver(LPCWSTR Name);
|
PDEVICE_OBJECT DRIVER_FindMPDriver(LPCWSTR Name);
|
||||||
BOOL DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED,
|
BOOL DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED,
|
||||||
PDRIVER_FUNCTIONS DF);
|
PDRIVER_FUNCTIONS DF);
|
||||||
BOOL DRIVER_UnregisterDriver(LPCWSTR Name);
|
BOOL DRIVER_UnregisterDriver(LPCWSTR Name);
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef __WIN32K_MISC_H
|
#ifndef __WIN32K_MISC_H
|
||||||
#define __WIN32K_MISC_H
|
#define __WIN32K_MISC_H
|
||||||
|
|
||||||
/* Process context in which miniport driver is opened/used */
|
|
||||||
extern PEPROCESS Win32kDeviceProcess;
|
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
STDCALL
|
STDCALL
|
||||||
Win32kInitialize (VOID);
|
Win32kInitialize (VOID);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* 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
|
* Entry Point for win32k.sys
|
||||||
*/
|
*/
|
||||||
|
@ -48,9 +48,6 @@ extern SSDT Win32kSSDT[];
|
||||||
extern SSPT Win32kSSPT[];
|
extern SSPT Win32kSSPT[];
|
||||||
extern ULONG Win32kNumberOfSysCalls;
|
extern ULONG Win32kNumberOfSysCalls;
|
||||||
|
|
||||||
PEPROCESS Win32kDeviceProcess;
|
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
Win32kProcessCallback (struct _EPROCESS *Process,
|
Win32kProcessCallback (struct _EPROCESS *Process,
|
||||||
BOOLEAN Create)
|
BOOLEAN Create)
|
||||||
|
@ -270,8 +267,6 @@ Win32kInitialize (VOID)
|
||||||
{
|
{
|
||||||
DPRINT("in Win32kInitialize\n");
|
DPRINT("in Win32kInitialize\n");
|
||||||
|
|
||||||
Win32kDeviceProcess = PsGetCurrentProcess();
|
|
||||||
|
|
||||||
InitGdiObjectHandleTable ();
|
InitGdiObjectHandleTable ();
|
||||||
|
|
||||||
// Initialize FreeType library
|
// Initialize FreeType library
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* 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
|
* GDI Driver support routines
|
||||||
* (mostly swiped from Wine)
|
* (mostly swiped from Wine)
|
||||||
|
@ -235,21 +235,15 @@ BOOL DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED,
|
||||||
|
|
||||||
typedef VP_STATUS (*PMP_DRIVERENTRY)(PVOID, PVOID);
|
typedef VP_STATUS (*PMP_DRIVERENTRY)(PVOID, PVOID);
|
||||||
|
|
||||||
HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
PDEVICE_OBJECT DRIVER_FindMPDriver(LPCWSTR Name)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
UNICODE_STRING DeviceName;
|
UNICODE_STRING DeviceName;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
HANDLE DisplayHandle;
|
HANDLE DisplayHandle;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PEPROCESS CurrentProcess;
|
PFILE_OBJECT VideoFileObject;
|
||||||
|
PDEVICE_OBJECT VideoDeviceObject;
|
||||||
CurrentProcess = PsGetCurrentProcess();
|
|
||||||
if (CurrentProcess != Win32kDeviceProcess)
|
|
||||||
{
|
|
||||||
/* Switch to process context in which handle is to be valid */
|
|
||||||
KeAttachProcess(Win32kDeviceProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
|
RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\??\\DISPLAY1");
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
@ -263,10 +257,21 @@ HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
||||||
&Iosb,
|
&Iosb,
|
||||||
0,
|
0,
|
||||||
FILE_SYNCHRONOUS_IO_ALERT);
|
FILE_SYNCHRONOUS_IO_ALERT);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
if (CurrentProcess != Win32kDeviceProcess)
|
|
||||||
{
|
{
|
||||||
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))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -276,7 +281,7 @@ HANDLE DRIVER_FindMPDriver(LPCWSTR Name)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(DisplayHandle);
|
return VideoDeviceObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* 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
|
* DC.C - Device context functions
|
||||||
*
|
*
|
||||||
|
@ -192,7 +192,7 @@ NtGdiCreateCompatableDC(HDC hDC)
|
||||||
/* DriverName is copied in the AllocDC routine */
|
/* DriverName is copied in the AllocDC routine */
|
||||||
if(OrigDC == NULL)
|
if(OrigDC == NULL)
|
||||||
{
|
{
|
||||||
NewDC->DeviceDriver = PrimarySurface.DisplayDevice;
|
NewDC->DeviceDriver = (HANDLE) PrimarySurface.VideoDeviceObject;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -312,23 +312,6 @@ FindDriverFileNames(PUNICODE_STRING DriverFileNames)
|
||||||
return TRUE;
|
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
|
static NTSTATUS STDCALL
|
||||||
DevModeCallback(IN PWSTR ValueName,
|
DevModeCallback(IN PWSTR ValueName,
|
||||||
IN ULONG ValueType,
|
IN ULONG ValueType,
|
||||||
|
@ -501,13 +484,10 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
PWSTR CurrentName;
|
PWSTR CurrentName;
|
||||||
BOOL GotDriver;
|
BOOL GotDriver;
|
||||||
BOOL DoDefault;
|
BOOL DoDefault;
|
||||||
NTSTATUS Status;
|
|
||||||
PFILE_OBJECT FileObject;
|
|
||||||
PEPROCESS CurrentProcess;
|
|
||||||
extern void FASTCALL IntInitDesktopWindow(ULONG Width, ULONG Height);
|
extern void FASTCALL IntInitDesktopWindow(ULONG Width, ULONG Height);
|
||||||
|
|
||||||
/* Open the miniport driver */
|
/* Open the miniport driver */
|
||||||
if ((PrimarySurface.DisplayDevice = DRIVER_FindMPDriver(Driver)) == NULL)
|
if ((PrimarySurface.VideoDeviceObject = DRIVER_FindMPDriver(Driver)) == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("FindMPDriver failed\n");
|
DPRINT1("FindMPDriver failed\n");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
@ -565,7 +545,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
RtlFreeUnicodeString(&DriverFileNames);
|
RtlFreeUnicodeString(&DriverFileNames);
|
||||||
if (! GotDriver)
|
if (! GotDriver)
|
||||||
{
|
{
|
||||||
CloseMiniport();
|
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||||
DPRINT1("No suitable DDI driver found\n");
|
DPRINT1("No suitable DDI driver found\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -580,36 +560,11 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
/* Construct DDI driver function dispatch table */
|
/* Construct DDI driver function dispatch table */
|
||||||
if (!DRIVER_BuildDDIFunctions(&DED, &PrimarySurface.DriverFunctions))
|
if (!DRIVER_BuildDDIFunctions(&DED, &PrimarySurface.DriverFunctions))
|
||||||
{
|
{
|
||||||
CloseMiniport();
|
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||||
DPRINT1("BuildDDIFunctions failed\n");
|
DPRINT1("BuildDDIFunctions failed\n");
|
||||||
return(FALSE);
|
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 */
|
/* Allocate a phyical device handle from the driver */
|
||||||
if (SetupDevMode(&PrimarySurface.DMW))
|
if (SetupDevMode(&PrimarySurface.DMW))
|
||||||
{
|
{
|
||||||
|
@ -624,7 +579,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
&PrimarySurface.DevInfo,
|
&PrimarySurface.DevInfo,
|
||||||
NULL,
|
NULL,
|
||||||
L"",
|
L"",
|
||||||
(HANDLE) (FileObject->DeviceObject));
|
(HANDLE) (PrimarySurface.VideoDeviceObject));
|
||||||
DoDefault = (NULL == PrimarySurface.PDev);
|
DoDefault = (NULL == PrimarySurface.PDev);
|
||||||
if (DoDefault)
|
if (DoDefault)
|
||||||
{
|
{
|
||||||
|
@ -650,12 +605,11 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
&PrimarySurface.DevInfo,
|
&PrimarySurface.DevInfo,
|
||||||
NULL,
|
NULL,
|
||||||
L"",
|
L"",
|
||||||
(HANDLE) (FileObject->DeviceObject));
|
(HANDLE) (PrimarySurface.VideoDeviceObject));
|
||||||
|
|
||||||
if (NULL == PrimarySurface.PDev)
|
if (NULL == PrimarySurface.PDev)
|
||||||
{
|
{
|
||||||
ObDereferenceObject(FileObject);
|
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||||
CloseMiniport();
|
|
||||||
DPRINT1("DrvEnablePDEV with default parameters failed\n");
|
DPRINT1("DrvEnablePDEV with default parameters failed\n");
|
||||||
DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
|
DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -691,8 +645,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver,
|
||||||
PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev);
|
PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev);
|
||||||
if (NULL == PrimarySurface.Handle)
|
if (NULL == PrimarySurface.Handle)
|
||||||
{
|
{
|
||||||
ObDereferenceObject(FileObject);
|
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||||
CloseMiniport();
|
|
||||||
DPRINT1("DrvEnableSurface failed\n");
|
DPRINT1("DrvEnableSurface failed\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -824,7 +777,7 @@ NtGdiDeleteDC(HDC DCHandle)
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
DCToDelete->DriverFunctions.DisablePDev(DCToDelete->PDev);
|
DCToDelete->DriverFunctions.DisablePDev(DCToDelete->PDev);
|
||||||
|
|
||||||
CloseMiniport();
|
ObDereferenceObject(PrimarySurface.VideoDeviceObject);
|
||||||
|
|
||||||
PrimarySurfaceCreated = FALSE;
|
PrimarySurfaceCreated = FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue