From fc68dda45d62d8f680adb4f2a1ff4bac5378491a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Fri, 15 Apr 2005 15:56:19 +0000 Subject: [PATCH] Add ASSERTs Correct a bug when processing IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation (serenum) Don't breakpoint if NDEBUG is defined (serenum) Allow to write more than 16 bytes in one IRP_MJ_WRITE (serial) svn path=/trunk/; revision=14627 --- reactos/drivers/bus/serenum/detect.c | 2 +- reactos/drivers/bus/serenum/misc.c | 15 ++++++++++++--- reactos/drivers/bus/serenum/pdo.c | 1 + reactos/drivers/bus/serenum/serenum.c | 10 ++++------ reactos/drivers/dd/serial/circularbuffer.c | 6 ++++++ reactos/drivers/dd/serial/create.c | 2 ++ reactos/drivers/dd/serial/devctrl.c | 17 +++++++++++++---- reactos/drivers/dd/serial/info.c | 11 ++++++++--- reactos/drivers/dd/serial/misc.c | 4 ++++ reactos/drivers/dd/serial/pnp.c | 11 +++++++---- reactos/drivers/dd/serial/rw.c | 19 ++++++++++++++++--- 11 files changed, 74 insertions(+), 24 deletions(-) diff --git a/reactos/drivers/bus/serenum/detect.c b/reactos/drivers/bus/serenum/detect.c index a8de8336392..db4d8bf9d47 100644 --- a/reactos/drivers/bus/serenum/detect.c +++ b/reactos/drivers/bus/serenum/detect.c @@ -199,7 +199,7 @@ SerenumWait(ULONG milliseconds) KTIMER Timer; LARGE_INTEGER DueTime; - DueTime.QuadPart = -milliseconds * 10; + DueTime.QuadPart = milliseconds * -10; KeInitializeTimer(&Timer); KeSetTimer(&Timer, DueTime, NULL); return KeWaitForSingleObject(&Timer, Executive, KernelMode, FALSE, NULL); diff --git a/reactos/drivers/bus/serenum/misc.c b/reactos/drivers/bus/serenum/misc.c index 94eb3933474..03ef526ad17 100644 --- a/reactos/drivers/bus/serenum/misc.c +++ b/reactos/drivers/bus/serenum/misc.c @@ -14,10 +14,12 @@ NTSTATUS SerenumDuplicateUnicodeString( - OUT PUNICODE_STRING Destination, - IN PUNICODE_STRING Source, - IN POOL_TYPE PoolType) + OUT PUNICODE_STRING Destination, + IN PUNICODE_STRING Source, + IN POOL_TYPE PoolType) { + ASSERT(Destination); + if (Source == NULL) { RtlInitUnicodeString(Destination, NULL); @@ -52,6 +54,8 @@ SerenumInitMultiSzString( ULONG DestinationSize = 0; NTSTATUS Status = STATUS_SUCCESS; + ASSERT(Destination); + /* Calculate length needed for destination unicode string */ va_start(args, Destination); Source = va_arg(args, PCSZ); @@ -133,6 +137,8 @@ ForwardIrpAndWait( ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO); LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + ASSERT(LowerDevice); + KeInitializeEvent(&Event, NotificationEvent, FALSE); IoCopyCurrentIrpStackLocationToNext(Irp); @@ -162,6 +168,7 @@ ForwardIrpToLowerDeviceAndForget( ASSERT(DeviceExtension->Common.IsFDO); LowerDevice = DeviceExtension->LowerDevice; + ASSERT(LowerDevice); DPRINT("Serenum: calling lower device 0x%p [%wZ]\n", LowerDevice, &LowerDevice->DriverObject->DriverName); IoSkipCurrentIrpStackLocation(Irp); @@ -180,6 +187,7 @@ ForwardIrpToAttachedFdoAndForget( ASSERT(!DeviceExtension->Common.IsFDO); Fdo = DeviceExtension->AttachedFdo; + ASSERT(Fdo); DPRINT("Serenum: calling attached Fdo 0x%p [%wZ]\n", Fdo, &Fdo->DriverObject->DriverName); IoSkipCurrentIrpStackLocation(Irp); @@ -195,6 +203,7 @@ ForwardIrpAndForget( ASSERT(((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO); LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + ASSERT(LowerDevice); IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(LowerDevice, Irp); diff --git a/reactos/drivers/bus/serenum/pdo.c b/reactos/drivers/bus/serenum/pdo.c index 54ade591a6c..02d6c4c96ec 100644 --- a/reactos/drivers/bus/serenum/pdo.c +++ b/reactos/drivers/bus/serenum/pdo.c @@ -99,6 +99,7 @@ SerenumPdoQueryDeviceRelations( return STATUS_INSUFFICIENT_RESOURCES; ObReferenceObject(DeviceObject); + DeviceRelations->Count = 1; DeviceRelations->Objects[0] = DeviceObject; *pDeviceRelations = DeviceRelations; diff --git a/reactos/drivers/bus/serenum/serenum.c b/reactos/drivers/bus/serenum/serenum.c index ead4e826458..5715843c854 100644 --- a/reactos/drivers/bus/serenum/serenum.c +++ b/reactos/drivers/bus/serenum/serenum.c @@ -52,7 +52,9 @@ IrpStub( { DPRINT1("Serenum: FDO stub for major function 0x%lx\n", IoGetCurrentIrpStackLocation(Irp)->MajorFunction); +#ifndef NDEBUG DbgBreakPoint(); +#endif Status = Irp->IoStatus.Status; } } @@ -73,7 +75,9 @@ IrpStub( { DPRINT1("Serenum: PDO stub for major function 0x%lx\n", IoGetCurrentIrpStackLocation(Irp)->MajorFunction); +#ifndef NDEBUG DbgBreakPoint(); +#endif Status = Irp->IoStatus.Status; } } @@ -100,12 +104,6 @@ DriverEntry( for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) DriverObject->MajorFunction[i] = IrpStub; - /*DriverObject->MajorFunction[IRP_MJ_CREATE] = SerialCreate; - DriverObject->MajorFunction[IRP_MJ_CLOSE] = SerialClose; - DriverObject->MajorFunction[IRP_MJ_CLEANUP] = SerialCleanup; - DriverObject->MajorFunction[IRP_MJ_READ] = SerialRead; - DriverObject->MajorFunction[IRP_MJ_WRITE] = SerialWrite;*/ - //DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Serenum; //DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = SerialQueryInformation; DriverObject->MajorFunction[IRP_MJ_PNP] = SerenumPnp; //DriverObject->MajorFunction[IRP_MJ_POWER] = SerialPower; diff --git a/reactos/drivers/dd/serial/circularbuffer.c b/reactos/drivers/dd/serial/circularbuffer.c index 31c9cc22cf5..521f0ab3b89 100644 --- a/reactos/drivers/dd/serial/circularbuffer.c +++ b/reactos/drivers/dd/serial/circularbuffer.c @@ -17,6 +17,7 @@ InitializeCircularBuffer( IN ULONG BufferSize) { DPRINT("Serial: InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize); + ASSERT(pBuffer); pBuffer->Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG); if (!pBuffer->Buffer) return STATUS_INSUFFICIENT_RESOURCES; @@ -30,6 +31,7 @@ FreeCircularBuffer( IN PCIRCULAR_BUFFER pBuffer) { DPRINT("Serial: FreeCircularBuffer(pBuffer %p)\n", pBuffer); + ASSERT(pBuffer); ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG); return STATUS_SUCCESS; } @@ -39,6 +41,7 @@ IsCircularBufferEmpty( IN PCIRCULAR_BUFFER pBuffer) { DPRINT("Serial: IsCircularBufferEmpty(pBuffer %p)\n", pBuffer); + ASSERT(pBuffer); return (pBuffer->ReadPosition == pBuffer->WritePosition); } @@ -49,6 +52,7 @@ PushCircularBufferEntry( { ULONG NextPosition; DPRINT("Serial: PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry); + ASSERT(pBuffer); ASSERT(pBuffer->Length); NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length; if (NextPosition == pBuffer->ReadPosition) @@ -64,6 +68,7 @@ PopCircularBufferEntry( OUT PUCHAR Entry) { DPRINT("Serial: PopCircularBufferEntry(pBuffer %p)\n", pBuffer); + ASSERT(pBuffer); ASSERT(pBuffer->Length); if (IsCircularBufferEmpty(pBuffer)) return STATUS_ARRAY_BOUNDS_EXCEEDED; @@ -80,6 +85,7 @@ IncreaseCircularBufferSize( PUCHAR NewBuffer; DPRINT("Serial: IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize); + ASSERT(pBuffer); ASSERT(pBuffer->Length); if (pBuffer->Length > NewBufferSize) return STATUS_INVALID_PARAMETER; diff --git a/reactos/drivers/dd/serial/create.c b/reactos/drivers/dd/serial/create.c index e823916ca7b..d330dc734ba 100644 --- a/reactos/drivers/dd/serial/create.c +++ b/reactos/drivers/dd/serial/create.c @@ -26,6 +26,8 @@ SerialCreate( FileObject = Stack->FileObject; DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(FileObject); + if (Stack->Parameters.Create.Options & FILE_DIRECTORY_FILE) { CHECKPOINT; diff --git a/reactos/drivers/dd/serial/devctrl.c b/reactos/drivers/dd/serial/devctrl.c index 72e8a5158f0..ee4c0bffc15 100644 --- a/reactos/drivers/dd/serial/devctrl.c +++ b/reactos/drivers/dd/serial/devctrl.c @@ -20,10 +20,10 @@ SerialGetUserBuffers( OUT PVOID* BufferIn, OUT PVOID* BufferOut) { - ASSERT(Irp); - ASSERT(BufferIn); - ASSERT(BufferOut); - + ASSERT(Irp); + ASSERT(BufferIn); + ASSERT(BufferOut); + switch (IO_METHOD_FROM_CTL_CODE(IoControlCode)) { case METHOD_BUFFERED: @@ -118,6 +118,9 @@ SerialSetLineControl( UCHAR Lcr = 0; NTSTATUS Status; + ASSERT(DeviceExtension); + ASSERT(NewSettings); + DPRINT("Serial: SerialSetLineControl(COM%lu, Settings { %lu %lu %lu })\n", DeviceExtension->ComPort, NewSettings->StopBits, NewSettings->Parity, NewSettings->WordLength); @@ -184,6 +187,8 @@ BOOLEAN SerialClearPerfStats( IN PSERIAL_DEVICE_EXTENSION DeviceExtension) { + ASSERT(DeviceExtension); + RtlZeroMemory(&DeviceExtension->SerialPerfStats, sizeof(SERIALPERF_STATS)); DeviceExtension->BreakInterruptErrorCount = 0; return TRUE; @@ -195,6 +200,7 @@ SerialGetPerfStats(IN PIRP pIrp) PSERIAL_DEVICE_EXTENSION pDeviceExtension; pDeviceExtension = (PSERIAL_DEVICE_EXTENSION) IoGetCurrentIrpStackLocation(pIrp)->DeviceObject->DeviceExtension; + ASSERT(DeviceExtension); /* * we assume buffer is big enough to hold SerialPerfStats structure * caller must verify this @@ -212,6 +218,8 @@ SerialGetCommProp( OUT PSERIAL_COMMPROP pCommProp, IN PSERIAL_DEVICE_EXTENSION DeviceExtension) { + ASSERT(pCommProp); + RtlZeroMemory(pCommProp, sizeof(SERIAL_COMMPROP)); pCommProp->PacketLength = sizeof(SERIAL_COMMPROP); @@ -257,6 +265,7 @@ SerialGetCommStatus( { KIRQL Irql; + ASSERT(pSerialStatus); RtlZeroMemory(pSerialStatus, sizeof(SERIAL_STATUS)); pSerialStatus->Errors = 0; diff --git a/reactos/drivers/dd/serial/info.c b/reactos/drivers/dd/serial/info.c index 0b63deb794f..85fcee47283 100644 --- a/reactos/drivers/dd/serial/info.c +++ b/reactos/drivers/dd/serial/info.c @@ -37,12 +37,13 @@ SerialQueryInformation( DPRINT("Serial: IRP_MJ_QUERY_INFORMATION / FileStandardInformation\n"); if (BufferLength < sizeof(FILE_STANDARD_INFORMATION)) Status = STATUS_BUFFER_OVERFLOW; - else + else if (!StandardInfo) + Status = STATUS_INVALID_PARAMETER; { StandardInfo->AllocationSize.QuadPart = 0; StandardInfo->EndOfFile.QuadPart = 0; - StandardInfo->Directory = FALSE; - StandardInfo->NumberOfLinks = 0; + StandardInfo->Directory = FALSE; + StandardInfo->NumberOfLinks = 0; StandardInfo->DeletePending = FALSE; /* FIXME: should be TRUE sometimes */ Status = STATUS_SUCCESS; } @@ -52,9 +53,13 @@ SerialQueryInformation( { PFILE_POSITION_INFORMATION PositionInfo = (PFILE_POSITION_INFORMATION)SystemBuffer; + ASSERT(PositionInfo); + DPRINT("Serial: IRP_MJ_QUERY_INFORMATION / FilePositionInformation\n"); if (BufferLength < sizeof(PFILE_POSITION_INFORMATION)) Status = STATUS_BUFFER_OVERFLOW; + else if (!PositionInfo) + Status = STATUS_INVALID_PARAMETER; else { PositionInfo->CurrentByteOffset.QuadPart = 0; diff --git a/reactos/drivers/dd/serial/misc.c b/reactos/drivers/dd/serial/misc.c index 04c2205dccc..7fda4c907db 100644 --- a/reactos/drivers/dd/serial/misc.c +++ b/reactos/drivers/dd/serial/misc.c @@ -32,6 +32,8 @@ ForwardIrpAndWait( KEVENT Event; NTSTATUS Status; + ASSERT(LowerDevice); + KeInitializeEvent(&Event, NotificationEvent, FALSE); IoCopyCurrentIrpStackLocationToNext(Irp); @@ -56,6 +58,8 @@ ForwardIrpAndForget( { PDEVICE_OBJECT LowerDevice = ((PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + ASSERT(LowerDevice); + IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(LowerDevice, Irp); } diff --git a/reactos/drivers/dd/serial/pnp.c b/reactos/drivers/dd/serial/pnp.c index 211f7ae4386..baa81967a51 100644 --- a/reactos/drivers/dd/serial/pnp.c +++ b/reactos/drivers/dd/serial/pnp.c @@ -31,6 +31,9 @@ SerialAddDeviceInternal( static ULONG ComPortNumber = 1; DPRINT("Serial: SerialAddDeviceInternal called\n"); + + ASSERT(DeviceObject); + ASSERT(Pdo); /* Create new device object */ swprintf(DeviceNameBuffer, L"\\Device\\Serial%lu", DeviceNumber); @@ -125,12 +128,10 @@ SerialAddDevice( if (Pdo == NULL) return STATUS_SUCCESS; - /* We have here a PDO that does not correspond to a legacy - * serial port. So call the internal AddDevice function. + /* We have here a PDO not null. It represents a real serial + * port. So call the internal AddDevice function. */ return SerialAddDeviceInternal(DriverObject, Pdo, UartUnknown, NULL, NULL); - - } NTSTATUS STDCALL @@ -160,6 +161,8 @@ SerialPnpStartDevice( DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(ResourceList); + ASSERT(DeviceExtension); ASSERT(DeviceExtension->PnpState == dsStopped); DeviceExtension->BaudRate = 19200 | SERIAL_BAUD_USER; diff --git a/reactos/drivers/dd/serial/rw.c b/reactos/drivers/dd/serial/rw.c index f58b4f2bfc4..38c1735d533 100644 --- a/reactos/drivers/dd/serial/rw.c +++ b/reactos/drivers/dd/serial/rw.c @@ -37,6 +37,9 @@ ReadBytes( ULONG_PTR Information = 0; NTSTATUS Status; + ASSERT(DeviceObject); + ASSERT(WorkItemData); + DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension; ComPortBase = (PUCHAR)DeviceExtension->BaseAddress; Length = IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length; @@ -285,9 +288,19 @@ SerialWrite( Status = PushCircularBufferEntry(&DeviceExtension->OutputBuffer, Buffer[Information]); if (!NT_SUCCESS(Status)) { - DPRINT("Serial: buffer overrun on COM%lu\n", DeviceExtension->ComPort); - DeviceExtension->SerialPerfStats.BufferOverrunErrorCount++; - break; + if (Status == STATUS_BUFFER_TOO_SMALL) + { + KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql); + SerialSendByte(NULL, DeviceExtension, NULL, NULL); + KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql); + continue; + } + else + { + DPRINT("Serial: buffer overrun on COM%lu\n", DeviceExtension->ComPort); + DeviceExtension->SerialPerfStats.BufferOverrunErrorCount++; + break; + } } Information++; }