- 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
This commit is contained in:
Vizzini 2004-02-09 06:59:01 +00:00
parent 9a53ebcb92
commit f9d689b644
9 changed files with 284 additions and 10 deletions

View file

@ -1,10 +1,9 @@
PATH_TO_TOP = ../../..
TARGET_TYPE = driver_library
TARGET_NAME = csq
TARGET_NORC = yes
TARGET_CFLAGS = -Wall -Werror
TARGET_TYPE = kmlibrary
TARGET_NAME = csq
TARGET_CFLAGS = -Wall -Werror
TARGET_OBJECTS = csq.o
#TARGET_GCCLIBS = gcc
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk

View 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>
VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject,

View 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 */

View 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)
/*

View file

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

View file

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

View file

@ -0,0 +1,5 @@
TARGETNAME=csqtest
TARGETTYPE=DRIVER
TARGETPATH=obj
TARGETLIBS= csq.lib
SOURCES= csqtest.c

View file

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

View file

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