From 4710304a0d72c7a0a5db9a23d7ec9cc5fb9d6ca2 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 26 Jun 2005 19:29:12 +0000 Subject: [PATCH] Fix kdbg build and some more header cleanups: add csq.q to ntifs, since it's now fully documented by MS (kept vizzini's comments though), moved af_irda to w32api because it's part of PSDK, moved ntbootvid.h to bootvid directory, removed ldrfuncs.h and add ndk's ldrfuncs.h to umode ndk (it was missing) svn path=/trunk/; revision=16298 --- reactos/drivers/dd/bootvid/bootvid.c | 2 +- .../ddk => drivers/dd/bootvid}/ntbootvid.h | 2 + reactos/drivers/lib/csq/csq.c | 2 +- .../{include/ddk => drivers/lib/csq}/csq.h | 0 reactos/include/ddk/ldrfuncs.h | 30 -- reactos/include/ndk/ldrfuncs.h | 9 + reactos/include/ndk/ntndk.h | 2 +- reactos/lib/kernel32/misc/res.c | 1 - reactos/lib/ntdll/rtl/message.c | 1 - reactos/ntoskrnl/inbv/inbv.c | 2 +- reactos/ntoskrnl/include/internal/ntoskrnl.h | 2 +- reactos/ntoskrnl/kdbg/i386/kdb_help.S | 4 +- reactos/ntoskrnl/kdbg/kdb_cli.c | 2 - reactos/ntoskrnl/kdbg/kdb_expr.c | 1 - reactos/ntoskrnl/kdbg/kdb_string.c | 6 +- .../{include/ddk => w32api/include}/af_irda.h | 0 reactos/w32api/include/ddk/csq.h | 289 ++++++++++++++++++ reactos/w32api/include/ddk/ntifs.h | 2 +- 18 files changed, 311 insertions(+), 46 deletions(-) rename reactos/{include/ddk => drivers/dd/bootvid}/ntbootvid.h (80%) rename reactos/{include/ddk => drivers/lib/csq}/csq.h (100%) delete mode 100644 reactos/include/ddk/ldrfuncs.h rename reactos/{include/ddk => w32api/include}/af_irda.h (100%) create mode 100644 reactos/w32api/include/ddk/csq.h diff --git a/reactos/drivers/dd/bootvid/bootvid.c b/reactos/drivers/dd/bootvid/bootvid.c index 7b33e9a9e00..1b1ace9e3d8 100644 --- a/reactos/drivers/dd/bootvid/bootvid.c +++ b/reactos/drivers/dd/bootvid/bootvid.c @@ -24,9 +24,9 @@ /* INCLUDES ******************************************************************/ #include -#include #include #include "bootvid.h" +#include "ntbootvid.h" #include "resource.h" #define NDEBUG diff --git a/reactos/include/ddk/ntbootvid.h b/reactos/drivers/dd/bootvid/ntbootvid.h similarity index 80% rename from reactos/include/ddk/ntbootvid.h rename to reactos/drivers/dd/bootvid/ntbootvid.h index ca30f06272e..199a0201f6a 100644 --- a/reactos/include/ddk/ntbootvid.h +++ b/reactos/drivers/dd/bootvid/ntbootvid.h @@ -1,3 +1,5 @@ + +/* FIXME: Bootvid will eventually become a DLL and this will be deprecated */ #define FILE_DEVICE_BOOTVID 53335 #define IOCTL_BOOTVID_INITIALIZE \ diff --git a/reactos/drivers/lib/csq/csq.c b/reactos/drivers/lib/csq/csq.c index 29c28cc09dc..d3991e3344a 100644 --- a/reactos/drivers/lib/csq/csq.c +++ b/reactos/drivers/lib/csq/csq.c @@ -27,7 +27,7 @@ #define __NTDRIVER__ #include -#include +#include static VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject, diff --git a/reactos/include/ddk/csq.h b/reactos/drivers/lib/csq/csq.h similarity index 100% rename from reactos/include/ddk/csq.h rename to reactos/drivers/lib/csq/csq.h diff --git a/reactos/include/ddk/ldrfuncs.h b/reactos/include/ddk/ldrfuncs.h deleted file mode 100644 index 14e3fc2caed..00000000000 --- a/reactos/include/ddk/ldrfuncs.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __INCLUDE_DDK_LDRFUNCS_H -#define __INCLUDE_DDK_LDRFUNCS_H -/* $Id$ */ - -NTSTATUS STDCALL -LdrAccessResource(IN PVOID BaseAddress, - IN PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, - OUT PVOID *Resource OPTIONAL, - OUT PULONG Size OPTIONAL); - -NTSTATUS STDCALL -LdrFindResource_U(IN PVOID BaseAddress, - IN PLDR_RESOURCE_INFO ResourceInfo, - IN ULONG Level, - OUT PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry); - -NTSTATUS STDCALL -LdrFindResourceDirectory_U( IN PVOID BaseAddress, - IN PLDR_RESOURCE_INFO ResourceInfo, - IN ULONG Level, - OUT PIMAGE_RESOURCE_DIRECTORY *ResourceDirectory); - -NTSTATUS STDCALL -LdrEnumResources(IN PVOID BaseAddress, - IN PLDR_RESOURCE_INFO ResourceInfo, - IN ULONG Level, - IN OUT PULONG ResourceCount, - OUT PVOID Resources OPTIONAL); - -#endif /* __INCLUDE_DDK_LDRFUNCS_H */ diff --git a/reactos/include/ndk/ldrfuncs.h b/reactos/include/ndk/ldrfuncs.h index 6ca224c990f..3cf9d79f603 100644 --- a/reactos/include/ndk/ldrfuncs.h +++ b/reactos/include/ndk/ldrfuncs.h @@ -34,6 +34,15 @@ LdrFindResource_U( OUT PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry ); +NTSTATUS +STDCALL +LdrFindResourceDirectory_U( + IN PVOID BaseAddress, + IN PLDR_RESOURCE_INFO ResourceInfo, + IN ULONG Level, + OUT PIMAGE_RESOURCE_DIRECTORY *ResourceDirectory +); + NTSTATUS STDCALL LdrGetProcedureAddress( diff --git a/reactos/include/ndk/ntndk.h b/reactos/include/ndk/ntndk.h index fb17b27702f..1f590622074 100644 --- a/reactos/include/ndk/ntndk.h +++ b/reactos/include/ndk/ntndk.h @@ -23,7 +23,6 @@ #include "iofuncs.h" /* Input/Output Manager Functions */ #include "ketypes.h" /* Kernel Types */ #include "kefuncs.h" /* Kernel Functions */ - #include "ldrfuncs.h" /* Loader Functions */ #include "lpctypes.h" /* Local Procedure Call Types */ #include "mmtypes.h" /* Memory Manager Types */ #include "mmfuncs.h" /* Memory Manager Functions */ @@ -40,6 +39,7 @@ #endif /* Shared NDK */ +#include "ldrfuncs.h" /* Loader Functions */ #include "ldrtypes.h" /* Loader Types */ #include "pstypes.h" /* Process Manager Types */ #include "rtltypes.h" /* Runtime Library Types */ diff --git a/reactos/lib/kernel32/misc/res.c b/reactos/lib/kernel32/misc/res.c index f0a0ed8fbb8..58bd5de3f49 100644 --- a/reactos/lib/kernel32/misc/res.c +++ b/reactos/lib/kernel32/misc/res.c @@ -8,7 +8,6 @@ */ #include -#include #define NDEBUG #include "../include/debug.h" diff --git a/reactos/lib/ntdll/rtl/message.c b/reactos/lib/ntdll/rtl/message.c index dd4bf3f9946..2467e353c93 100644 --- a/reactos/lib/ntdll/rtl/message.c +++ b/reactos/lib/ntdll/rtl/message.c @@ -14,7 +14,6 @@ #include #define NDEBUG #include -#include /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/inbv/inbv.c b/reactos/ntoskrnl/inbv/inbv.c index cc0af802b9d..b42e5a30496 100755 --- a/reactos/ntoskrnl/inbv/inbv.c +++ b/reactos/ntoskrnl/inbv/inbv.c @@ -11,7 +11,7 @@ /* INCLUDES ******************************************************************/ #include -#include +#include "../../drivers/dd/bootvid/ntbootvid.h" #define NDEBUG #include diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index ad3bd50d081..e83d98c159c 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -32,7 +32,7 @@ #include "port.h" #include "nls.h" #ifdef KDBG -#include "kdb.h" +#include "../kdbg/kdb.h" #endif #include "dbgk.h" #include "tag.h" diff --git a/reactos/ntoskrnl/kdbg/i386/kdb_help.S b/reactos/ntoskrnl/kdbg/i386/kdb_help.S index a44bc86733d..11653e0ebc3 100644 --- a/reactos/ntoskrnl/kdbg/i386/kdb_help.S +++ b/reactos/ntoskrnl/kdbg/i386/kdb_help.S @@ -1,5 +1,5 @@ -#include -#include +#include +#include .text diff --git a/reactos/ntoskrnl/kdbg/kdb_cli.c b/reactos/ntoskrnl/kdbg/kdb_cli.c index 5af33413402..0c4325a0806 100644 --- a/reactos/ntoskrnl/kdbg/kdb_cli.c +++ b/reactos/ntoskrnl/kdbg/kdb_cli.c @@ -29,8 +29,6 @@ /* INCLUDES ******************************************************************/ #include -#include -#include #define NDEBUG #include diff --git a/reactos/ntoskrnl/kdbg/kdb_expr.c b/reactos/ntoskrnl/kdbg/kdb_expr.c index 2c23abd3478..4728fd3adf5 100644 --- a/reactos/ntoskrnl/kdbg/kdb_expr.c +++ b/reactos/ntoskrnl/kdbg/kdb_expr.c @@ -35,7 +35,6 @@ /* INCLUDES ******************************************************************/ #include -#include #define NDEBUG #include diff --git a/reactos/ntoskrnl/kdbg/kdb_string.c b/reactos/ntoskrnl/kdbg/kdb_string.c index 60c07e95232..cf4c08b8a16 100644 --- a/reactos/ntoskrnl/kdbg/kdb_string.c +++ b/reactos/ntoskrnl/kdbg/kdb_string.c @@ -91,8 +91,8 @@ strtoul(const char *nptr, char **endptr, int base) } if (base == 0) base = c == '0' ? 8 : 10; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + cutoff = (unsigned long)0xffffffff / (unsigned long)base; + cutlim = (unsigned long)0xffffffff % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { if (isdigit(c)) @@ -113,7 +113,7 @@ strtoul(const char *nptr, char **endptr, int base) } if (any < 0) { - acc = ULONG_MAX; + acc = 0xffffffff; } else if (neg) acc = -acc; diff --git a/reactos/include/ddk/af_irda.h b/reactos/w32api/include/af_irda.h similarity index 100% rename from reactos/include/ddk/af_irda.h rename to reactos/w32api/include/af_irda.h diff --git a/reactos/w32api/include/ddk/csq.h b/reactos/w32api/include/ddk/csq.h new file mode 100644 index 00000000000..b08d02c27e0 --- /dev/null +++ b/reactos/w32api/include/ddk/csq.h @@ -0,0 +1,289 @@ +/* + * Cancel-Safe Queue Library + * Copyright (c) 2004, Vizzini (vizzini@plasmic.com) + * Licensed under the GNU GPL for the ReactOS project + * + * This header defines the interface to the ReactOS Cancel-Safe Queue library. + * This interface is based on and is similar to the Microsoft Cancel-Safe + * Queue interface. + * + * BACKGROUND + * + * IRP queuing is a royal pain in the butt, due to the fact that there are + * tons of built-in race conditions. IRP handling is difficult in general, + * but the cancel logic has been particularly complicated due to some subtle + * races, coupled with the fact that the system interfaces have changed over + * time. + * + * Walter Oney (2nd. Ed. of Programming the Windows Driver Model) states a + * common opinion among driver developers when he says that it is foolish + * to try to roll your own cancel logic. There are only a very few people + * who have gotten it right in the past. He suggests, instead, that you + * either use his own well-tested code, or use the code in the Microsoft + * Cancel-Safe Queue Library. + * + * We cannot do either, of course, due to copyright issues. I have therefore + * created this clone of the Microsoft library in order to concentrate all + * of the IRP-queuing bugs in one place. I'm quite sure there are problems + * here, so if you are a driver writer, I'd be glad to hear your feedback. + * + * Apart from that, please try to use these routines, rather than building + * your own. If you think you have found a bug, please bring it up with me + * or on-list, as this is complicated and non-obvious stuff. Don't just + * change this and hope for the best! + * + * USAGE + * + * This library follows exactly the same interface as the Microsoft Cancel-Safe + * Queue routines (IoCsqXxx()). As such, the authoritative reference is the + * current DDK. There is also a DDK sample called "cancel" that has an + * example of how to use this code. I have also provided a sample driver + * that makes use of this queue. Finally, please do read the header and the + * source if you're curious about the inner workings of these routines. + */ + +#ifndef _REACTOS_CSQ_H +#define _REACTOS_CSQ_H + +/* + * Prevent including the CSQ definitions twice. They're present in NTDDK + * now too, except the *_EX versions. + */ +#ifndef IO_TYPE_CSQ_IRP_CONTEXT + +struct _IO_CSQ; + + +/* + * CSQ Callbacks + * + * The cancel-safe queue is implemented as a set of IoCsqXxx() OS routines + * copuled with a set of driver callbacks to handle the basic operations of + * the queue. You need to supply one of each of these functions in your own + * driver. These routines are also documented in the DDK under CsqXxx(). + * That is the authoritative documentation. + */ + +/* + * Function to insert an IRP in the queue. No need to worry about locking; + * just tack it onto your list or something. + * + * Sample implementation: + * + VOID NTAPI CsqInsertIrp(PIO_CSQ Csq, PIRP Irp) + { + KdPrint(("Inserting IRP 0x%x into CSQ\n", Irp)); + InsertTailList(&IrpQueue, &Irp->Tail.Overlay.ListEntry); + } + * + */ +typedef VOID (NTAPI *PIO_CSQ_INSERT_IRP) (struct _IO_CSQ *Csq, + PIRP Irp); + + +/* + * Function to remove an IRP from the queue. + * + * Sample: + * + VOID NTAPI CsqRemoveIrp(PIO_CSQ Csq, PIRP Irp) + { + KdPrint(("Removing IRP 0x%x from CSQ\n", Irp)); + RemoveEntryList(&Irp->Tail.Overlay.ListEntry); + } + * + */ +typedef VOID (NTAPI *PIO_CSQ_REMOVE_IRP) (struct _IO_CSQ *Csq, + PIRP Irp); + +/* + * Function to look for an IRP in the queue + * + * Sample: + * + 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); + } + * + */ +typedef PIRP (NTAPI *PIO_CSQ_PEEK_NEXT_IRP) (struct _IO_CSQ *Csq, + PIRP Irp, + PVOID PeekContext); + +/* + * Lock the queue. This can be a spinlock, a mutex, or whatever + * else floats your boat. + * + * Sample: + * + VOID NTAPI CsqAcquireLock(PIO_CSQ Csq, PKIRQL Irql) + { + KdPrint(("Acquiring spin lock\n")); + KeAcquireSpinLock(&IrpQueueLock, Irql); + } + * + */ +typedef VOID (NTAPI *PIO_CSQ_ACQUIRE_LOCK) (struct _IO_CSQ *Csq, + PKIRQL Irql); + +/* + * Unlock the queue: + * + VOID NTAPI CsqReleaseLock(PIO_CSQ Csq, KIRQL Irql) + { + KdPrint(("Releasing spin lock\n")); + KeReleaseSpinLock(&IrpQueueLock, Irql); + } + * + */ +typedef VOID (NTAPI *PIO_CSQ_RELEASE_LOCK) (struct _IO_CSQ *Csq, + KIRQL Irql); + +/* + * Finally, this is called by the queue library when it wants to complete + * a canceled IRP. + * + * Sample: + * + 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); + } + * + */ +typedef VOID (NTAPI *PIO_CSQ_COMPLETE_CANCELED_IRP) (struct _IO_CSQ *Csq, + PIRP Irp); + + +/* + * STRUCTURES + * + * NOTE: Please do not use these directly. You will make incompatible code + * if you do. Always only use the documented IoCsqXxx() interfaces and you + * will amass much Good Karma. + */ +#define IO_TYPE_CSQ_IRP_CONTEXT 1 +#define IO_TYPE_CSQ 2 + +/* + * IO_CSQ - Queue control structure + */ +typedef struct _IO_CSQ { + ULONG Type; + PIO_CSQ_INSERT_IRP CsqInsertIrp; + PIO_CSQ_REMOVE_IRP CsqRemoveIrp; + PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp; + PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock; + PIO_CSQ_RELEASE_LOCK CsqReleaseLock; + PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp; + PVOID ReservePointer; /* must be NULL */ +} IO_CSQ, *PIO_CSQ; + +/* + * IO_CSQ_IRP_CONTEXT - Context used to track an IRP in the CSQ + */ +typedef struct _IO_CSQ_IRP_CONTEXT { + ULONG Type; + PIRP Irp; + PIO_CSQ Csq; +} IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT; + +#endif /* IO_TYPE_CSQ_IRP_CONTEXT */ + +/* See IO_TYPE_CSQ_* above */ +#define IO_TYPE_CSQ_EX 3 + +/* + * Function to insert an IRP into the queue with extended context information. + * This is useful if you need to be able to de-queue particular IRPs more + * easily in some cases. + * + * Same deal as above; sample implementation: + * + NTSTATUS NTAPI CsqInsertIrpEx(PIO_CSQ Csq, PIRP Irp, PVOID InsertContext) + { + CsqInsertIrp(Csq, Irp); + return STATUS_PENDING; + } + * + */ +typedef NTSTATUS (NTAPI *PIO_CSQ_INSERT_IRP_EX) (struct _IO_CSQ *Csq, + PIRP Irp, + PVOID InsertContext); + +/* + * CANCEL-SAFE QUEUE DDIs + * + * These device driver interfaces are called to make use of the queue. Again, + * authoritative documentation for these functions is in the DDK. The csqtest + * driver also makes use of some of them. + */ + + +/* + * Call this in DriverEntry or similar in order to set up the Csq structure. + * As long as the Csq struct and the functions you pass in are resident, + * there are no IRQL restrictions. + */ +NTSTATUS NTAPI IoCsqInitialize(PIO_CSQ Csq, + PIO_CSQ_INSERT_IRP CsqInsertIrp, + PIO_CSQ_REMOVE_IRP CsqRemoveIrp, + PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, + PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, + PIO_CSQ_RELEASE_LOCK CsqReleaseLock, + PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp); + +/* + * Same as above, except you provide a CsqInsertIrpEx routine instead of + * CsqInsertIrp. This eventually allows you to supply extra tracking + * information for use with the queue. + */ +NTSTATUS NTAPI IoCsqInitializeEx(PIO_CSQ Csq, + PIO_CSQ_INSERT_IRP_EX CsqInsertIrpEx, + PIO_CSQ_REMOVE_IRP CsqRemoveIrp, + PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, + PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, + PIO_CSQ_RELEASE_LOCK CsqReleaseLock, + PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp); + +/* + * Insert an IRP into the queue + */ +VOID NTAPI IoCsqInsertIrp(PIO_CSQ Csq, + PIRP Irp, + PIO_CSQ_IRP_CONTEXT Context); + +/* + * Insert an IRP into the queue, with special context maintained that + * makes it easy to find IRPs in the queue + */ +NTSTATUS NTAPI IoCsqInsertIrpEx(PIO_CSQ Csq, + PIRP Irp, + PIO_CSQ_IRP_CONTEXT Context, + PVOID InsertContext); + +/* + * Remove a particular IRP from the queue + */ +PIRP NTAPI IoCsqRemoveIrp(PIO_CSQ Csq, + PIO_CSQ_IRP_CONTEXT Context); + +/* + * Remove the next IRP from the queue + */ +PIRP NTAPI IoCsqRemoveNextIrp(PIO_CSQ Csq, + PVOID PeekContext); + +#endif /* _REACTOS_CSQ_H */ diff --git a/reactos/w32api/include/ddk/ntifs.h b/reactos/w32api/include/ddk/ntifs.h index 76d0d587f51..da6925da700 100644 --- a/reactos/w32api/include/ddk/ntifs.h +++ b/reactos/w32api/include/ddk/ntifs.h @@ -29,7 +29,7 @@ #endif #include "ntddk.h" -//#include "ntapi.h" +#include "csq.h" #ifdef __cplusplus extern "C" {