From f9d689b6443e60ec369654420cdaec29593ac6a7 Mon Sep 17 00:00:00 2001 From: Vizzini Date: Mon, 9 Feb 2004 06:59:01 +0000 Subject: [PATCH] - Updated CSQ library to use new kmlibrary target type - Updated includes in csq.c - Added IPv6 ethertype in lan.h - Fixed a typo in ip.c - Added csqtest driver for testing cancel-safe queues svn path=/trunk/; revision=8107 --- reactos/drivers/lib/csq/GNUmakefile | 7 +- reactos/drivers/lib/csq/csq.c | 4 +- reactos/drivers/net/tcpip/include/lan.h | 4 +- reactos/drivers/net/tcpip/network/ip.c | 3 +- reactos/drivers/test/csqtest/GNUmakefile | 10 ++ reactos/drivers/test/csqtest/Makefile | 7 + reactos/drivers/test/csqtest/SOURCES | 5 + reactos/drivers/test/csqtest/csqtest.c | 214 +++++++++++++++++++++++ reactos/drivers/test/csqtest/csqtest.rc | 38 ++++ 9 files changed, 283 insertions(+), 9 deletions(-) create mode 100644 reactos/drivers/test/csqtest/GNUmakefile create mode 100644 reactos/drivers/test/csqtest/Makefile create mode 100644 reactos/drivers/test/csqtest/SOURCES create mode 100644 reactos/drivers/test/csqtest/csqtest.c create mode 100644 reactos/drivers/test/csqtest/csqtest.rc diff --git a/reactos/drivers/lib/csq/GNUmakefile b/reactos/drivers/lib/csq/GNUmakefile index 42b71a74406..7907e42faa6 100644 --- a/reactos/drivers/lib/csq/GNUmakefile +++ b/reactos/drivers/lib/csq/GNUmakefile @@ -1,10 +1,9 @@ PATH_TO_TOP = ../../.. -TARGET_TYPE = driver_library + +TARGET_TYPE = kmlibrary TARGET_NAME = csq -TARGET_NORC = yes TARGET_CFLAGS = -Wall -Werror - TARGET_OBJECTS = csq.o -#TARGET_GCCLIBS = gcc + include $(PATH_TO_TOP)/rules.mak include $(TOOLS_PATH)/helper.mk diff --git a/reactos/drivers/lib/csq/csq.c b/reactos/drivers/lib/csq/csq.c index d4fe1baa89b..701fca33875 100644 --- a/reactos/drivers/lib/csq/csq.c +++ b/reactos/drivers/lib/csq/csq.c @@ -24,8 +24,8 @@ * processor can create races too. */ #define __NTDRIVER__ -#include -#include "csq.h" +#include +#include VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject, diff --git a/reactos/drivers/net/tcpip/include/lan.h b/reactos/drivers/net/tcpip/include/lan.h index 1d64465cdc1..7fe2631ea50 100644 --- a/reactos/drivers/net/tcpip/include/lan.h +++ b/reactos/drivers/net/tcpip/include/lan.h @@ -8,7 +8,7 @@ #define __LAN_H -/* Medias we support */ +/* Media we support */ #define MEDIA_ETH 0 #define MAX_MEDIA 1 @@ -71,7 +71,7 @@ typedef struct LAN_ADAPTER { /* Ethernet types. We swap constants so we can compare values at runtime without swapping them there */ #define ETYPE_IPv4 WH2N(0x0800) -#define ETYPE_IPv6 WH2N(0x0000) /* FIXME */ +#define ETYPE_IPv6 WH2N(0x86DD) #define ETYPE_ARP WH2N(0x0806) /* Protocols */ diff --git a/reactos/drivers/net/tcpip/network/ip.c b/reactos/drivers/net/tcpip/network/ip.c index 4292a2f4189..5e7390689ea 100644 --- a/reactos/drivers/net/tcpip/network/ip.c +++ b/reactos/drivers/net/tcpip/network/ip.c @@ -84,7 +84,8 @@ VOID FreeIF( PADDRESS_ENTRY CreateADE( - PIP_INTERFACE IF, PIP_ADDRESS Address, + PIP_INTERFACE IF, + PIP_ADDRESS Address, UCHAR Type, PNET_TABLE_ENTRY NTE) /* diff --git a/reactos/drivers/test/csqtest/GNUmakefile b/reactos/drivers/test/csqtest/GNUmakefile new file mode 100644 index 00000000000..a03a3f9d8d7 --- /dev/null +++ b/reactos/drivers/test/csqtest/GNUmakefile @@ -0,0 +1,10 @@ +PATH_TO_TOP = ../../.. + +TARGET_TYPE = driver +TARGET_NAME = csqtest +TARGET_DDKLIBS = csq.a +TARGET_CFLAGS = -Wall -Werror +TARGET_OBJECTS = csqtest.o + +include $(PATH_TO_TOP)/rules.mak +include $(TOOLS_PATH)/helper.mk diff --git a/reactos/drivers/test/csqtest/Makefile b/reactos/drivers/test/csqtest/Makefile new file mode 100644 index 00000000000..9348f56cf51 --- /dev/null +++ b/reactos/drivers/test/csqtest/Makefile @@ -0,0 +1,7 @@ +# +# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source +# file to this component. This file merely indirects to the real make file +# that is shared by all the components of Windows NT +# +!INCLUDE $(NTMAKEENV)\makefile.def + diff --git a/reactos/drivers/test/csqtest/SOURCES b/reactos/drivers/test/csqtest/SOURCES new file mode 100644 index 00000000000..5a9b6695eeb --- /dev/null +++ b/reactos/drivers/test/csqtest/SOURCES @@ -0,0 +1,5 @@ +TARGETNAME=csqtest +TARGETTYPE=DRIVER +TARGETPATH=obj +TARGETLIBS= csq.lib +SOURCES= csqtest.c diff --git a/reactos/drivers/test/csqtest/csqtest.c b/reactos/drivers/test/csqtest/csqtest.c new file mode 100644 index 00000000000..c362561a0d9 --- /dev/null +++ b/reactos/drivers/test/csqtest/csqtest.c @@ -0,0 +1,214 @@ +/* + * CSQ Test Driver + * Copyright (c) 2004, Vizzini (vizzini@plasmic.com) + * Released under the GNU GPL for the ReactOS project + * + * This driver is designed to exercise the cancel-safe IRP queue logic. + * Please refer to reactos/include/ddk/csq.h and reactos/drivers/lib/csq. + */ +#include +#include + +/* XXX shortcomings in our headers... */ +#define assert(x) +#ifndef KdPrint +#define KdPrint(x) DbgPrint x +#endif + +/* Device name */ +#define NT_DEVICE_NAME L"\\Device\\csqtest" + +/* DosDevices name */ +#define DOS_DEVICE_NAME L"\\??\\csqtest" + +/* Global CSQ struct that the CSQ functions init */ +IO_CSQ Csq; + +/* List and lock for the actual IRP queue */ +LIST_ENTRY IrpQueue; +KSPIN_LOCK IrpQueueLock; + +/* + * CSQ Callbacks + */ +VOID NTAPI CsqInsertIrp(PIO_CSQ Csq, PIRP Irp) +{ + KdPrint(("Inserting IRP 0x%x into CSQ\n", Irp)); + InsertTailList(&IrpQueue, &Irp->Tail.Overlay.ListEntry); +} + +VOID NTAPI CsqRemoveIrp(PIO_CSQ Csq, PIRP Irp) +{ + KdPrint(("Removing IRP 0x%x from CSQ\n", Irp)); + RemoveEntryList(&Irp->Tail.Overlay.ListEntry); +} + +PIRP NTAPI CsqPeekNextIrp(PIO_CSQ Csq, PIRP Irp, PVOID PeekContext) +{ + KdPrint(("Peeking for next IRP\n")); + + if(Irp) + return CONTAINING_RECORD(&Irp->Tail.Overlay.ListEntry.Flink, IRP, Tail.Overlay.ListEntry); + + if(IsListEmpty(&IrpQueue)) + return NULL; + + return CONTAINING_RECORD(IrpQueue.Flink, IRP, Tail.Overlay.ListEntry); +} + +VOID NTAPI CsqAcquireLock(PIO_CSQ Csq, PKIRQL Irql) +{ + KdPrint(("Acquiring spin lock\n")); + KeAcquireSpinLock(&IrpQueueLock, Irql); +} + +VOID NTAPI CsqReleaseLock(PIO_CSQ Csq, KIRQL Irql) +{ + KdPrint(("Releasing spin lock\n")); + KeReleaseSpinLock(&IrpQueueLock, Irql); +} + +VOID NTAPI CsqCompleteCancelledIrp(PIO_CSQ Csq, PIRP Irp) +{ + KdPrint(("cancelling irp 0x%x\n", Irp)); + Irp->IoStatus.Status = STATUS_CANCELLED; + Irp->IoStatus.Information = 0; + IoCompleteRequest(Irp, IO_NO_INCREMENT); +} + +NTSTATUS NTAPI CsqInsertIrpEx(PIO_CSQ Csq, PIRP Irp, PVOID InsertContext) +/* + * FUNCTION: Insert into IRP queue, with extra context + * + * NOTE: Switch call in DriverEntry to IoCsqInitializeEx to use this + */ +{ + CsqInsertIrp(Csq, Irp); + return STATUS_PENDING; +} + +/* + * DISPATCH ROUTINES + */ + +NTSTATUS NTAPI DispatchCreateCloseCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp) +{ + PIO_STACK_LOCATION StackLocation = IoGetCurrentIrpStackLocation(Irp); + + if(StackLocation->MajorFunction == IRP_MJ_CLEANUP) + { + /* flush the irp queue */ + PIRP CurrentIrp; + + KdPrint(("csqtest: Cleanup received; flushing the IRP queue with cancel\n")); + + while((CurrentIrp = IoCsqRemoveNextIrp(&Csq, 0))) + { + CurrentIrp->IoStatus.Status = STATUS_CANCELLED; + CurrentIrp->IoStatus.Information = 0; + + IoCompleteRequest(CurrentIrp, IO_NO_INCREMENT); + } + } + + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return STATUS_SUCCESS; +} + +NTSTATUS NTAPI DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp) +{ + /* According to the cancel sample in the DDK, IoCsqInsertIrp() marks the irp pending */ + /* However, I think it's wrong. */ + IoMarkIrpPending(Irp); + IoCsqInsertIrp(&Csq, Irp, 0); + + return STATUS_PENDING; +} + +NTSTATUS NTAPI DispatchIoctl(PDEVICE_OBJECT DeviceObject, PIRP Irp) +/* + * all IOCTL requests flush the irp queue + */ +{ + PIRP CurrentIrp; + + KdPrint(("csqtest: Ioctl received; flushing the IRP queue with success\n")); + + while((CurrentIrp = IoCsqRemoveNextIrp(&Csq, 0))) + { + CurrentIrp->IoStatus.Status = STATUS_SUCCESS; + CurrentIrp->IoStatus.Information = 0; + + IoCompleteRequest(CurrentIrp, IO_NO_INCREMENT); + } + + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return STATUS_SUCCESS; +} + +VOID NTAPI Unload(PDRIVER_OBJECT DriverObject) +{ +} + +/* + * DriverEntry + */ + +NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) +{ + NTSTATUS Status; + UNICODE_STRING NtName; + UNICODE_STRING DosName; + PDEVICE_OBJECT DeviceObject; + + DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)DispatchCreateCloseCleanup; + DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)DispatchCreateCloseCleanup; + DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)DispatchCreateCloseCleanup; + DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)DispatchReadWrite; + DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH)DispatchReadWrite; + DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)DispatchIoctl; + DriverObject->DriverUnload = (PDRIVER_UNLOAD)Unload; + + Status = IoCsqInitialize(&Csq, (PIO_CSQ_INSERT_IRP)CsqInsertIrp, CsqRemoveIrp, CsqPeekNextIrp, + CsqAcquireLock, (PIO_CSQ_RELEASE_LOCK)CsqReleaseLock, CsqCompleteCancelledIrp); + + if(Status != STATUS_SUCCESS) + KdPrint(("csqtest: IoCsqInitalize failed: 0x%x\n", Status)); + else + KdPrint(("csqtest: IoCsqInitalize succeeded\n")); + + InitializeListHead(&IrpQueue); + KeInitializeSpinLock(&IrpQueueLock); + + /* Set up a device */ + RtlInitUnicodeString(&NtName, NT_DEVICE_NAME); + Status = IoCreateDevice(DriverObject, 0, &NtName, FILE_DEVICE_UNKNOWN, 0, 0, &DeviceObject); + + if(!NT_SUCCESS(Status)) + { + KdPrint(("csqtest: Unable to create device: 0x%x\n", Status)); + return Status; + } + + RtlInitUnicodeString(&DosName, DOS_DEVICE_NAME); + Status = IoCreateSymbolicLink(&DosName, &NtName); + + if(!NT_SUCCESS(Status)) + { + KdPrint(("csqtest: Unable to create link: 0x%x\n", Status)); + return Status; + } + + DeviceObject->Flags |= DO_BUFFERED_IO; + + return STATUS_SUCCESS; +} + diff --git a/reactos/drivers/test/csqtest/csqtest.rc b/reactos/drivers/test/csqtest/csqtest.rc new file mode 100644 index 00000000000..adcb8803801 --- /dev/null +++ b/reactos/drivers/test/csqtest/csqtest.rc @@ -0,0 +1,38 @@ +#include +#include + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD + PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", RES_STR_COMPANY_NAME + VALUE "FileDescription", "CSQ Test\0" + VALUE "FileVersion", "0.1.4\0" + VALUE "InternalName", "csqtest\0" + VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT + VALUE "OriginalFilename", "csqtest.sys\0" + VALUE "ProductName", RES_STR_PRODUCT_NAME + VALUE "ProductVersion", RES_STR_PRODUCT_VERSION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + -- 2.17.1