Pass pointer to CSRSS process on first create request.

svn path=/trunk/; revision=3079
This commit is contained in:
Eric Kohl 2002-06-14 14:23:14 +00:00
parent 69c0982e64
commit 01b92c6de5
2 changed files with 96 additions and 77 deletions

View file

@ -1,4 +1,4 @@
/* $Id: vidport.c,v 1.22 2002/02/12 12:00:28 jfilby Exp $ /* $Id: vidport.c,v 1.23 2002/06/14 14:22:22 ekohl Exp $
* *
* VideoPort driver * VideoPort driver
* Written by Rex Jolliff * Written by Rex Jolliff
@ -11,7 +11,10 @@
#include "vidport.h" #include "vidport.h"
#define UNIMPLEMENTED do {DbgPrint("%s:%d: Function not implemented", __FILE__, __LINE__); for(;;);} while (0) #define NDEBUG
#include <debug.h>
//#define UNIMPLEMENTED do {DbgPrint("%s:%d: Function not implemented", __FILE__, __LINE__); for(;;);} while (0)
#define VERSION "0.0.0" #define VERSION "0.0.0"
@ -19,8 +22,9 @@ static VOID STDCALL VidStartIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
static NTSTATUS STDCALL VidDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp); static NTSTATUS STDCALL VidDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
static NTSTATUS STDCALL VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); static NTSTATUS STDCALL VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
static HANDLE CsrssHandle; static BOOLEAN CsrssInitialized = FALSE;
static struct _EPROCESS* Csrss; static HANDLE CsrssHandle = 0;
static struct _EPROCESS* Csrss = NULL;
PBYTE ReturnCsrssAddress(void) PBYTE ReturnCsrssAddress(void)
{ {
@ -46,11 +50,11 @@ PBYTE ReturnCsrssAddress(void)
// RETURNS: // RETURNS:
// NTSTATUS // NTSTATUS
STDCALL NTSTATUS STDCALL NTSTATUS
DriverEntry(IN PDRIVER_OBJECT DriverObject, DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath) IN PUNICODE_STRING RegistryPath)
{ {
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
VOID VOID
@ -170,8 +174,7 @@ VideoPortGetRegistryParameters(IN PVOID HwDeviceExtension,
UNIMPLEMENTED; UNIMPLEMENTED;
} }
ULONG ULONG STDCALL
STDCALL
VideoPortInitialize(IN PVOID Context1, VideoPortInitialize(IN PVOID Context1,
IN PVOID Context2, IN PVOID Context2,
IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData, IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData,
@ -201,15 +204,15 @@ VideoPortInitialize(IN PVOID Context1,
RtlInitUnicodeString(&DeviceName, DeviceBuffer); RtlInitUnicodeString(&DeviceName, DeviceBuffer);
/* Create the device */ /* Create the device */
Status = IoCreateDevice(MPDriverObject, Status = IoCreateDevice(MPDriverObject,
HwInitializationData->HwDeviceExtensionSize + HwInitializationData->HwDeviceExtensionSize +
sizeof(VIDEOPORT_EXTENSION_DATA), sizeof(VIDEOPORT_EXTENSION_DATA),
&DeviceName, &DeviceName,
FILE_DEVICE_VIDEO, FILE_DEVICE_VIDEO,
0, 0,
TRUE, TRUE,
&MPDeviceObject); &MPDeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("IoCreateDevice call failed\n",0); DbgPrint("IoCreateDevice call failed\n",0);
return Status; return Status;
@ -259,6 +262,7 @@ VideoPortInitialize(IN PVOID Context1,
!(ConfigInfo.BusInterruptLevel == 0 && !(ConfigInfo.BusInterruptLevel == 0 &&
ConfigInfo.BusInterruptVector == 0)) ConfigInfo.BusInterruptVector == 0))
{ {
#if 0
ExtensionData->IRQL = ConfigInfo.BusInterruptLevel; ExtensionData->IRQL = ConfigInfo.BusInterruptLevel;
ExtensionData->InterruptLevel = ExtensionData->InterruptLevel =
HalGetInterruptVector(ConfigInfo.AdapterInterfaceType, HalGetInterruptVector(ConfigInfo.AdapterInterfaceType,
@ -287,39 +291,12 @@ VideoPortInitialize(IN PVOID Context1,
return Status; return Status;
} }
#endif
} }
DeviceNumber++; DeviceNumber++;
} }
while (Again); while (Again);
/* Find a process handle for csrss */
Cid.UniqueProcess = (HANDLE)3;
Cid.UniqueThread = 0;
Status = ZwOpenProcess(&CsrssHandle,
PROCESS_ALL_ACCESS,
NULL,
&Cid);
if (!NT_SUCCESS(Status))
{
DbgPrint("VIDPORT: Failed to open csrss\n");
Csrss = NULL;
}
else
{
Status = ObReferenceObjectByHandle(CsrssHandle,
PROCESS_ALL_ACCESS,
NULL,
KernelMode,
(PVOID*)&Csrss,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("VIDPORT: Failed to reference csrss handle\n");
Csrss = NULL;
}
}
/* FIXME: initialize timer routine for MP Driver */ /* FIXME: initialize timer routine for MP Driver */
if (HwInitializationData->HwTimer != NULL) if (HwInitializationData->HwTimer != NULL)
{ {
@ -340,7 +317,7 @@ VideoPortInitialize(IN PVOID Context1,
return Status; return Status;
} }
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -350,9 +327,9 @@ VideoPortInt10(IN PVOID HwDeviceExtension,
{ {
KV86M_REGISTERS Regs; KV86M_REGISTERS Regs;
NTSTATUS Status; NTSTATUS Status;
KeAttachProcess(Csrss); KeAttachProcess(Csrss);
memset(&Regs, 0, sizeof(Regs)); memset(&Regs, 0, sizeof(Regs));
Regs.Eax = BiosArguments->Eax; Regs.Eax = BiosArguments->Eax;
Regs.Ebx = BiosArguments->Ebx; Regs.Ebx = BiosArguments->Ebx;
@ -690,28 +667,25 @@ VideoPortWriteRegisterBufferUchar(IN PUCHAR Register,
WRITE_REGISTER_BUFFER_UCHAR(Register, Buffer, Count); WRITE_REGISTER_BUFFER_UCHAR(Register, Buffer, Count);
} }
VOID VOID STDCALL
STDCALL VideoPortWriteRegisterBufferUshort(IN PUSHORT Register,
VideoPortWriteRegisterBufferUshort(IN PUSHORT Register, IN PUSHORT Buffer,
IN PUSHORT Buffer,
IN ULONG Count) IN ULONG Count)
{ {
WRITE_REGISTER_BUFFER_USHORT(Register, Buffer, Count); WRITE_REGISTER_BUFFER_USHORT(Register, Buffer, Count);
} }
VOID VOID STDCALL
STDCALL VideoPortWriteRegisterBufferUlong(IN PULONG Register,
VideoPortWriteRegisterBufferUlong(IN PULONG Register, IN PULONG Buffer,
IN PULONG Buffer,
IN ULONG Count) IN ULONG Count)
{ {
WRITE_REGISTER_BUFFER_ULONG(Register, Buffer, Count); WRITE_REGISTER_BUFFER_ULONG(Register, Buffer, Count);
} }
VOID VOID STDCALL
STDCALL VideoPortZeroDeviceMemory(OUT PVOID Destination,
VideoPortZeroDeviceMemory(OUT PVOID Destination, IN ULONG Length)
IN ULONG Length)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
@ -734,11 +708,25 @@ VideoPortZeroDeviceMemory(OUT PVOID Destination,
// NTSTATUS // NTSTATUS
// //
static NTSTATUS static NTSTATUS STDCALL
STDCALL VidDispatchOpenClose(IN PDEVICE_OBJECT pDO,
VidDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp)
IN PIRP Irp)
{ {
PIO_STACK_LOCATION IrpStack;
DPRINT("VidDispatchOpenClose() called\n");
IrpStack = IoGetCurrentIrpStackLocation(Irp);
if (IrpStack->MajorFunction == IRP_MJ_CREATE &&
CsrssInitialized == FALSE)
{
DPRINT("Referencing CSRSS\n");
Csrss = PsGetCurrentProcess();
CsrssInitialized = TRUE;
DPRINT("Csrss %p\n", Csrss);
}
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED; Irp->IoStatus.Information = FILE_OPENED;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
@ -761,10 +749,9 @@ VidDispatchOpenClose(IN PDEVICE_OBJECT pDO,
// NTSTATUS // NTSTATUS
// //
static VOID static VOID STDCALL
STDCALL VidStartIo(IN PDEVICE_OBJECT DeviceObject,
VidStartIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IN PIRP Irp)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
@ -784,30 +771,32 @@ VidStartIo(IN PDEVICE_OBJECT DeviceObject,
// NTSTATUS // NTSTATUS
// //
static NTSTATUS static NTSTATUS STDCALL
STDCALL VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IN PIRP Irp)
{ {
PIO_STACK_LOCATION IrpStack;
PVIDEO_REQUEST_PACKET vrp; PVIDEO_REQUEST_PACKET vrp;
IrpStack = IoGetCurrentIrpStackLocation(Irp);
// Translate the IRP to a VRP // Translate the IRP to a VRP
vrp = ExAllocatePool(PagedPool, sizeof(VIDEO_REQUEST_PACKET)); vrp = ExAllocatePool(PagedPool, sizeof(VIDEO_REQUEST_PACKET));
vrp->StatusBlock = ExAllocatePool(PagedPool, sizeof(STATUS_BLOCK)); vrp->StatusBlock = ExAllocatePool(PagedPool, sizeof(STATUS_BLOCK));
vrp->IoControlCode = Irp->Stack[0].Parameters.DeviceIoControl.IoControlCode; vrp->IoControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
// We're assuming METHOD_BUFFERED // We're assuming METHOD_BUFFERED
vrp->InputBuffer = Irp->AssociatedIrp.SystemBuffer; vrp->InputBuffer = Irp->AssociatedIrp.SystemBuffer;
vrp->InputBufferLength = Irp->Stack[0].Parameters.DeviceIoControl.InputBufferLength; vrp->InputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
vrp->OutputBuffer = Irp->UserBuffer; vrp->OutputBuffer = Irp->UserBuffer;
vrp->OutputBufferLength = Irp->Stack[0].Parameters.DeviceIoControl.OutputBufferLength; vrp->OutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
// Call the Miniport Driver with the VRP // Call the Miniport Driver with the VRP
DeviceObject->DriverObject->DriverStartIo(DeviceObject->DeviceExtension, (PIRP)vrp); DeviceObject->DriverObject->DriverStartIo(DeviceObject->DeviceExtension, (PIRP)vrp);
// Translate the VRP back into the IRP for OutputBuffer // Translate the VRP back into the IRP for OutputBuffer
Irp->UserBuffer = vrp->OutputBuffer; Irp->UserBuffer = vrp->OutputBuffer;
Irp->Stack[0].Parameters.DeviceIoControl.OutputBufferLength = vrp->OutputBufferLength; IrpStack->Parameters.DeviceIoControl.OutputBufferLength = vrp->OutputBufferLength;
// Free the VRP // Free the VRP
ExFreePool(vrp->StatusBlock); ExFreePool(vrp->StatusBlock);

View file

@ -1,4 +1,4 @@
/* $Id: init.c,v 1.12 2001/06/25 23:48:20 ekohl Exp $ /* $Id: init.c,v 1.13 2002/06/14 14:23:14 ekohl Exp $
* *
* reactos/subsys/csrss/init.c * reactos/subsys/csrss/init.c
* *
@ -75,6 +75,34 @@ CsrParseCommandLine (
} }
static VOID
CsrInitVideo(VOID)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DeviceName;
IO_STATUS_BLOCK Iosb;
HANDLE VideoHandle;
NTSTATUS Status;
RtlInitUnicodeString(&DeviceName, L"\\??\\DISPLAY1");
InitializeObjectAttributes(&ObjectAttributes,
&DeviceName,
0,
NULL,
NULL);
Status = NtOpenFile(&VideoHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&Iosb,
0,
0);
if (NT_SUCCESS(Status))
{
NtClose(VideoHandle);
}
}
/********************************************************************** /**********************************************************************
* NAME * NAME
* CsrServerInitialization * CsrServerInitialization
@ -108,7 +136,9 @@ CsrServerInitialization (
PrintString("CSR: Unable to parse the command line (Status: %x)\n", Status); PrintString("CSR: Unable to parse the command line (Status: %x)\n", Status);
return(FALSE); return(FALSE);
} }
CsrInitVideo();
/* NEW NAMED PORT: \ApiPort */ /* NEW NAMED PORT: \ApiPort */
RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort"); RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
InitializeObjectAttributes(&ObAttributes, InitializeObjectAttributes(&ObAttributes,