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
This commit is contained in:
Hervé Poussineau 2005-04-15 15:56:19 +00:00
parent df118afc6f
commit fc68dda45d
11 changed files with 74 additions and 24 deletions

View file

@ -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);

View file

@ -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);

View file

@ -99,6 +99,7 @@ SerenumPdoQueryDeviceRelations(
return STATUS_INSUFFICIENT_RESOURCES;
ObReferenceObject(DeviceObject);
DeviceRelations->Count = 1;
DeviceRelations->Objects[0] = DeviceObject;
*pDeviceRelations = DeviceRelations;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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;

View file

@ -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++;
}