- Updated CSQ library to use new kmlibrary target type
authorVizzini <vizzini@plasmic.com>
Mon, 9 Feb 2004 06:59:01 +0000 (06:59 +0000)
committerVizzini <vizzini@plasmic.com>
Mon, 9 Feb 2004 06:59:01 +0000 (06:59 +0000)
 - 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
reactos/drivers/lib/csq/csq.c
reactos/drivers/net/tcpip/include/lan.h
reactos/drivers/net/tcpip/network/ip.c
reactos/drivers/test/csqtest/GNUmakefile [new file with mode: 0644]
reactos/drivers/test/csqtest/Makefile [new file with mode: 0644]
reactos/drivers/test/csqtest/SOURCES [new file with mode: 0644]
reactos/drivers/test/csqtest/csqtest.c [new file with mode: 0644]
reactos/drivers/test/csqtest/csqtest.rc [new file with mode: 0644]

index 42b71a7..7907e42 100644 (file)
@@ -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
index d4fe1ba..701fca3 100644 (file)
@@ -24,8 +24,8 @@
  * processor can create races too.
  */
 #define __NTDRIVER__
-#include <ntddk.h>
-#include "csq.h"
+#include <ddk/ntddk.h>
+#include <ddk/csq.h>
 
 \f
 VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject,
index 1d64465..7fe2631 100644 (file)
@@ -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 */
index 4292a2f..5e73906 100644 (file)
@@ -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 (file)
index 0000000..a03a3f9
--- /dev/null
@@ -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 (file)
index 0000000..9348f56
--- /dev/null
@@ -0,0 +1,7 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the components of Windows NT\r
+#\r
+!INCLUDE $(NTMAKEENV)\makefile.def\r
+\r
diff --git a/reactos/drivers/test/csqtest/SOURCES b/reactos/drivers/test/csqtest/SOURCES
new file mode 100644 (file)
index 0000000..5a9b669
--- /dev/null
@@ -0,0 +1,5 @@
+TARGETNAME=csqtest\r
+TARGETTYPE=DRIVER\r
+TARGETPATH=obj\r
+TARGETLIBS= csq.lib\r
+SOURCES= csqtest.c\r
diff --git a/reactos/drivers/test/csqtest/csqtest.c b/reactos/drivers/test/csqtest/csqtest.c
new file mode 100644 (file)
index 0000000..c362561
--- /dev/null
@@ -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 <ntddk.h>
+#include <ddk/csq.h>
+
+/* 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 (file)
index 0000000..adcb880
--- /dev/null
@@ -0,0 +1,38 @@
+#include <defines.h>
+#include <reactos/resource.h>
+
+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
+