From 5d1661ec2d7ac02c397135d968428f7973687206 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sat, 27 May 2017 17:29:11 +0000 Subject: [PATCH] [RDBSS] [RXCE] Try to make use of wrapper more 'properly'. Now, we use wrappers for ASSERT and memory management. This allows us to allocate memory with low priority (which isn't supported by ReactOS yet :-(). Note that we go a bit farther than MS: we also define RxFreePoolWithTag() and make use of it. This should make Thomas happy :-) CORE-11327 svn path=/trunk/; revision=74683 --- reactos/sdk/include/ddk/rxovride.h | 8 ++ reactos/sdk/include/ddk/rxpooltg.h | 9 ++ reactos/sdk/lib/drivers/rdbsslib/rdbss.c | 67 ++++++++++++--- reactos/sdk/lib/drivers/rxce/rxce.c | 102 +++++++++++++++++++---- 4 files changed, 159 insertions(+), 27 deletions(-) diff --git a/reactos/sdk/include/ddk/rxovride.h b/reactos/sdk/include/ddk/rxovride.h index 5b5352dff1c..8527c22a0ff 100644 --- a/reactos/sdk/include/ddk/rxovride.h +++ b/reactos/sdk/include/ddk/rxovride.h @@ -1,3 +1,11 @@ #ifndef NO_RXOVRIDE_GLOBAL #include #endif + +#ifndef RX_POOL_WRAPPER +#define RX_POOL_WRAPPER 1 +#endif + +#ifndef RDBSS_ASSERTS +#define RDBSS_ASSERTS 1 +#endif diff --git a/reactos/sdk/include/ddk/rxpooltg.h b/reactos/sdk/include/ddk/rxpooltg.h index d76f78a86f6..adfdf75bc66 100644 --- a/reactos/sdk/include/ddk/rxpooltg.h +++ b/reactos/sdk/include/ddk/rxpooltg.h @@ -9,5 +9,14 @@ #define RX_WORKQ_POOLTAG ('qWxR') #define RX_MISC_POOLTAG ('sMxR') #define RX_IRPC_POOLTAG ('rIxR') +#ifdef __REACTOS__ +#define RX_TLC_POOLTAG ('??xR') +#endif + +extern ULONG RxExplodePoolTags; + +#define RX_DEFINE_POOLTAG(ExplodedPoolTag, DefaultPoolTag) ((RxExplodePoolTags == 0) ? (DefaultPoolTag) : (ExplodedPoolTag)) + +#define RX_DIRCTL_POOLTAG RX_DEFINE_POOLTAG('cDxR', RX_MISC_POOLTAG) #endif diff --git a/reactos/sdk/lib/drivers/rdbsslib/rdbss.c b/reactos/sdk/lib/drivers/rdbsslib/rdbss.c index fffce15802c..ae0e6f1485f 100644 --- a/reactos/sdk/lib/drivers/rdbsslib/rdbss.c +++ b/reactos/sdk/lib/drivers/rdbsslib/rdbss.c @@ -61,6 +61,13 @@ VOID RxAddToTopLevelIrpAllocatedContextsList( PRX_TOPLEVELIRP_CONTEXT TopLevelContext); +VOID +RxAssert( + PVOID Assert, + PVOID File, + ULONG Line, + PVOID Message); + NTSTATUS NTAPI RxCommonCleanup( @@ -450,6 +457,24 @@ NTSTATUS RxXXXControlFileCallthru( PRX_CONTEXT Context); +PVOID +NTAPI +_RxAllocatePoolWithTag( + _In_ POOL_TYPE PoolType, + _In_ SIZE_T NumberOfBytes, + _In_ ULONG Tag); + +VOID +NTAPI +_RxFreePool( + _In_ PVOID Buffer); + +VOID +NTAPI +_RxFreePoolWithTag( + _In_ PVOID Buffer, + _In_ ULONG Tag); + WCHAR RxStarForTemplate = '*'; WCHAR Rx8QMdot3QM[] = L">>>>>>>>.>>>*"; BOOLEAN DisableByteRangeLockingOnReadOnlyFiles = FALSE; @@ -537,6 +562,29 @@ BOOLEAN RxForceQFIPassThrough = FALSE; DECLARE_CONST_UNICODE_STRING(unknownId, L"???"); +#if RDBSS_ASSERTS +#ifdef ASSERT +#undef ASSERT +#endif + +#define ASSERT(exp) \ + if (!(exp)) \ + { \ + RxAssert(#exp, __FILE__, __LINE__, NULL); \ + } +#endif + +#if RX_POOL_WRAPPER +#undef RxAllocatePool +#undef RxAllocatePoolWithTag +#undef RxFreePool + +#define RxAllocatePool(P, S) _RxAllocatePoolWithTag(P, S, 0) +#define RxAllocatePoolWithTag _RxAllocatePoolWithTag +#define RxFreePool _RxFreePool +#define RxFreePoolWithTag _RxFreePoolWithTag +#endif + /* FUNCTIONS ****************************************************************/ VOID @@ -715,7 +763,7 @@ RxAllocateCanonicalNameBuffer( return STATUS_OBJECT_PATH_INVALID; } - CanonicalName->Buffer = ExAllocatePoolWithTag(PagedPool | POOL_COLD_ALLOCATION, CanonicalLength, RX_MISC_POOLTAG); + CanonicalName->Buffer = RxAllocatePoolWithTag(PagedPool | POOL_COLD_ALLOCATION, CanonicalLength, RX_MISC_POOLTAG); if (CanonicalName->Buffer == NULL) { return STATUS_INSUFFICIENT_RESOURCES; @@ -3102,7 +3150,7 @@ RxDriverEntry( RxInitializeDispatcher(); - ExInitializeNPagedLookasideList(&RxContextLookasideList, ExAllocatePoolWithTag, ExFreePool, 0, sizeof(RX_CONTEXT), RX_IRPC_POOLTAG, 4); + ExInitializeNPagedLookasideList(&RxContextLookasideList, RxAllocatePoolWithTag, RxFreePool, 0, sizeof(RX_CONTEXT), RX_IRPC_POOLTAG, 4); InitializeListHead(&RxIrpsList); KeInitializeSpinLock(&RxIrpsListSpinLock); @@ -3276,7 +3324,6 @@ RxFindOrCreateFcb( VNetRoot = (PV_NET_ROOT)RxContext->Create.pVNetRoot; ASSERT(NetRoot == VNetRoot->NetRoot); - TableAcquired = FALSE; Status = STATUS_SUCCESS; AcquiredExclusive = FALSE; @@ -3553,7 +3600,7 @@ RxFreeCanonicalNameBuffer( if (Context->Create.CanonicalNameBuffer != NULL) { - ExFreePoolWithTag(Context->Create.CanonicalNameBuffer, RX_MISC_POOLTAG); + RxFreePoolWithTag(Context->Create.CanonicalNameBuffer, RX_MISC_POOLTAG); Context->Create.CanonicalNameBuffer = NULL; Context->AlsoCanonicalNameBuffer = NULL; } @@ -4825,7 +4872,7 @@ RxPrefixClaim( RxContext->MajorFunction = IRP_MJ_CREATE; /* Fake canon name */ - RxContext->PrefixClaim.SuppliedPathName.Buffer = ExAllocatePoolWithTag(NonPagedPool, QueryRequest->PathNameLength, RX_MISC_POOLTAG); + RxContext->PrefixClaim.SuppliedPathName.Buffer = RxAllocatePoolWithTag(NonPagedPool, QueryRequest->PathNameLength, RX_MISC_POOLTAG); if (RxContext->PrefixClaim.SuppliedPathName.Buffer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; @@ -4885,7 +4932,7 @@ Leave: { if (RxContext->PrefixClaim.SuppliedPathName.Buffer != NULL) { - ExFreePoolWithTag(RxContext->PrefixClaim.SuppliedPathName.Buffer, RX_MISC_POOLTAG); + RxFreePoolWithTag(RxContext->PrefixClaim.SuppliedPathName.Buffer, RX_MISC_POOLTAG); } RxpPrepareCreateContextForReuse(RxContext); @@ -5151,14 +5198,14 @@ RxQueryDirectory( { Fobx->ContainsWildCards = FsRtlDoesNameContainWildCards(FileName); - Fobx->UnicodeQueryTemplate.Buffer = RxAllocatePoolWithTag(PagedPool, FileName->Length, 'cDxR'); + Fobx->UnicodeQueryTemplate.Buffer = RxAllocatePoolWithTag(PagedPool, FileName->Length, RX_DIRCTL_POOLTAG); if (Fobx->UnicodeQueryTemplate.Buffer != NULL) { /* UNICODE_STRING; length has to be even */ if ((FileName->Length & 1) != 0) { Status = STATUS_INVALID_PARAMETER; - RxFreePool(Fobx->UnicodeQueryTemplate.Buffer); + RxFreePoolWithTag(Fobx->UnicodeQueryTemplate.Buffer, RX_DIRCTL_POOLTAG); } else { @@ -6001,7 +6048,7 @@ RxTryToBecomeTheTopLevelIrp( /* If not TLC provider, allocate one */ if (TopLevelContext == NULL) { - TopLevelContext = RxAllocatePoolWithTag(NonPagedPool, sizeof(RX_TOPLEVELIRP_CONTEXT), '??xR'); + TopLevelContext = RxAllocatePoolWithTag(NonPagedPool, sizeof(RX_TOPLEVELIRP_CONTEXT), RX_TLC_POOLTAG); if (TopLevelContext == NULL) { return FALSE; @@ -6129,7 +6176,7 @@ RxUnwindTopLevelIrp( if (BooleanFlagOn(TopLevelContext->Flags, RX_TOPLEVELCTX_FLAG_FROM_POOL)) { RxRemoveFromTopLevelIrpAllocatedContextsList(TopLevelContext); - ExFreePool(TopLevelContext); + RxFreePoolWithTag(TopLevelContext, RX_TLC_POOLTAG); } } diff --git a/reactos/sdk/lib/drivers/rxce/rxce.c b/reactos/sdk/lib/drivers/rxce/rxce.c index ac355e8db98..d34165af1b1 100644 --- a/reactos/sdk/lib/drivers/rxce/rxce.c +++ b/reactos/sdk/lib/drivers/rxce/rxce.c @@ -69,6 +69,24 @@ NTAPI RxWorkItemDispatcher( PVOID Context); +PVOID +NTAPI +_RxAllocatePoolWithTag( + _In_ POOL_TYPE PoolType, + _In_ SIZE_T NumberOfBytes, + _In_ ULONG Tag); + +VOID +NTAPI +_RxFreePool( + _In_ PVOID Buffer); + +VOID +NTAPI +_RxFreePoolWithTag( + _In_ PVOID Buffer, + _In_ ULONG Tag); + extern ULONG ReadAheadGranularity; volatile LONG RxNumberOfActiveFcbs = 0; @@ -86,12 +104,14 @@ RX_DISPATCHER RxDispatcher; RX_WORK_QUEUE_DISPATCHER RxDispatcherWorkQueues; FAST_MUTEX RxLowIoPagingIoSyncMutex; BOOLEAN RxContinueFromAssert = TRUE; +ULONG RxExplodePoolTags = 1; #if DBG BOOLEAN DumpDispatchRoutine = TRUE; #else BOOLEAN DumpDispatchRoutine = FALSE; #endif +#if RDBSS_ASSERTS #ifdef ASSERT #undef ASSERT #endif @@ -101,6 +121,18 @@ BOOLEAN DumpDispatchRoutine = FALSE; { \ RxAssert(#exp, __FILE__, __LINE__, NULL); \ } +#endif + +#if RX_POOL_WRAPPER +#undef RxAllocatePool +#undef RxAllocatePoolWithTag +#undef RxFreePool + +#define RxAllocatePool(P, S) _RxAllocatePoolWithTag(P, S, 0) +#define RxAllocatePoolWithTag _RxAllocatePoolWithTag +#define RxFreePool _RxFreePool +#define RxFreePoolWithTag _RxFreePoolWithTag +#endif /* FUNCTIONS ****************************************************************/ @@ -225,7 +257,7 @@ RxAllocateFcbObject( /* Otherwise, allocate it */ else { - Buffer = ExAllocatePoolWithTag(PoolType, NameSize + FcbSize + SrvOpenSize + FobxSize + NonPagedSize, RX_FCB_POOLTAG); + Buffer = RxAllocatePoolWithTag(PoolType, NameSize + FcbSize + SrvOpenSize + FobxSize + NonPagedSize, RX_FCB_POOLTAG); if (Buffer == NULL) { return NULL; @@ -260,10 +292,10 @@ RxAllocateFcbObject( /* If we were not allocated from non paged, allocate the NON_PAGED_FCB now */ if (PoolType != NonPagedPool) { - NonPagedFcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NON_PAGED_FCB), RX_NONPAGEDFCB_POOLTAG); + NonPagedFcb = RxAllocatePoolWithTag(NonPagedPool, sizeof(NON_PAGED_FCB), RX_NONPAGEDFCB_POOLTAG); if (NonPagedFcb == NULL) { - ExFreePoolWithTag(Buffer, RX_FCB_POOLTAG); + RxFreePoolWithTag(Buffer, RX_FCB_POOLTAG); return NULL; } @@ -399,7 +431,7 @@ RxAllocateObject( /* Now, allocate the object */ ObjectSize = ExtensionSize + StructSize + NameLength; - Object = ExAllocatePoolWithTag(NonPagedPool, ObjectSize, Tag); + Object = RxAllocatePoolWithTag(NonPagedPool, ObjectSize, Tag); if (Object == NULL) { return NULL; @@ -731,7 +763,7 @@ RxConstructNetRoot( ASSERT(*LockHoldingState == LHS_ExclusiveLockHeld); /* Allocate the context */ - Context = ExAllocatePoolWithTag(PagedPool, sizeof(MRX_CREATENETROOT_CONTEXT), RX_SRVCALL_POOLTAG); + Context = RxAllocatePoolWithTag(PagedPool, sizeof(MRX_CREATENETROOT_CONTEXT), RX_SRVCALL_POOLTAG); if (Context == NULL) { return STATUS_INSUFFICIENT_RESOURCES; @@ -797,7 +829,7 @@ RxConstructNetRoot( RxTransitionVNetRoot(VirtualNetRoot, VRootCondition); /* Context is not longer needed */ - ExFreePoolWithTag(Context, RX_SRVCALL_POOLTAG); + RxFreePoolWithTag(Context, RX_SRVCALL_POOLTAG); DPRINT("Status: %x\n", Status); @@ -829,7 +861,7 @@ RxConstructSrvCall( ASSERT(*LockHoldingState == LHS_ExclusiveLockHeld); /* Allocate the context for mini-rdr */ - Calldown = ExAllocatePoolWithTag(NonPagedPool, sizeof(MRX_SRVCALLDOWN_STRUCTURE), RX_SRVCALL_POOLTAG); + Calldown = RxAllocatePoolWithTag(NonPagedPool, sizeof(MRX_SRVCALLDOWN_STRUCTURE), RX_SRVCALL_POOLTAG); if (Calldown == NULL) { SrvCall->Context = NULL; @@ -1893,7 +1925,7 @@ RxDispatchToWorkerThread( PRX_WORK_DISPATCH_ITEM DispatchItem; /* Allocate a bit of context */ - DispatchItem = ExAllocatePoolWithTag(PagedPool, sizeof(RX_WORK_DISPATCH_ITEM), RX_WORKQ_POOLTAG); + DispatchItem = RxAllocatePoolWithTag(PagedPool, sizeof(RX_WORK_DISPATCH_ITEM), RX_WORKQ_POOLTAG); if (DispatchItem == NULL) { return STATUS_INSUFFICIENT_RESOURCES; @@ -1909,7 +1941,7 @@ RxDispatchToWorkerThread( Status = RxInsertWorkQueueItem(pMRxDeviceObject, WorkQueueType, DispatchItem); if (!NT_SUCCESS(Status)) { - ExFreePoolWithTag(DispatchItem, RX_WORKQ_POOLTAG); + RxFreePoolWithTag(DispatchItem, RX_WORKQ_POOLTAG); DPRINT1("RxInsertWorkQueueItem failed! Queue: %ld, Routine: %p, Context: %p, Status: %lx\n", WorkQueueType, Routine, pContext, Status); } @@ -2188,7 +2220,7 @@ RxFinalizeNetFcb( Entry = ThisFcb->BufferedLocks.List; ThisFcb->BufferedLocks.List = Entry->Next; - ExFreePool(Entry); + RxFreePool(Entry); } } @@ -2221,7 +2253,7 @@ RxFinalizeNetFcb( /* Now, release everything */ if (ThisFcb->pBufferingStateChangeCompletedEvent != NULL) { - ExFreePool(ThisFcb->pBufferingStateChangeCompletedEvent); + RxFreePool(ThisFcb->pBufferingStateChangeCompletedEvent); } if (ThisFcb->MRxDispatch != NULL) @@ -2965,7 +2997,7 @@ RxFinishSrvCallConstruction( RxAcquirePrefixTableLockExclusive(PrefixTable, TRUE); RxTransitionSrvCall(SrvCall, Condition); - ExFreePoolWithTag(Calldown, RX_SRVCALL_POOLTAG); + RxFreePoolWithTag(Calldown, RX_SRVCALL_POOLTAG); /* If async, finish it here, otherwise, caller has already finished the stuff */ if (BooleanFlagOn(Context->Flags, RX_CONTEXT_FLAG_ASYNC_OPERATION)) @@ -2994,7 +3026,7 @@ RxFinishSrvCallConstruction( { if (Context->Info.Buffer != NULL) { - ExFreePool(Context->Info.Buffer); + RxFreePool(Context->Info.Buffer); Context->Info.Buffer = NULL; } } @@ -5397,17 +5429,17 @@ RxUninitializeVNetRootParameters( /* Only free what could have been allocated */ if (UserName != NULL) { - ExFreePool(UserName); + RxFreePool(UserName); } if (UserDomainName != NULL) { - ExFreePool(UserDomainName); + RxFreePool(UserDomainName); } if (Password != NULL) { - ExFreePool(Password); + RxFreePool(Password); } /* And remove the possibly set CSC agent flag */ @@ -5639,7 +5671,43 @@ RxWorkItemDispatcher( DispatchItem->DispatchRoutine(DispatchItem->DispatchRoutineParameter); - ExFreePoolWithTag(DispatchItem, RX_WORKQ_POOLTAG); + RxFreePoolWithTag(DispatchItem, RX_WORKQ_POOLTAG); +} + +/* + * @implemented + */ +PVOID +NTAPI +_RxAllocatePoolWithTag( + _In_ POOL_TYPE PoolType, + _In_ SIZE_T NumberOfBytes, + _In_ ULONG Tag) +{ + return ExAllocatePoolWithTagPriority(PoolType, NumberOfBytes, Tag, LowPoolPriority); +} + +/* + * @implemented + */ +VOID +NTAPI +_RxFreePool( + _In_ PVOID Buffer) +{ + ExFreePoolWithTag(Buffer, 0); +} + +/* + * @implemented + */ +VOID +NTAPI +_RxFreePoolWithTag( + _In_ PVOID Buffer, + _In_ ULONG Tag) +{ + ExFreePoolWithTag(Buffer, Tag); } NTSTATUS -- 2.17.1