20#define VALID_QUOTA_FLAGS (QUOTA_LIMITS_HARDWS_MIN_ENABLE | \
21 QUOTA_LIMITS_HARDWS_MIN_DISABLE | \
22 QUOTA_LIMITS_HARDWS_MAX_ENABLE | \
23 QUOTA_LIMITS_HARDWS_MAX_DISABLE)
50PspReturnQuotasOnDestroy(
53 ULONG PsQuotaTypeIndex;
69 QuotaToReturn = QuotaBlock->QuotaEntry[PsQuotaTypeIndex].Limit + QuotaBlock->QuotaEntry[PsQuotaTypeIndex].Return;
100PspReturnExcessQuotas(
106 SIZE_T AmountToReturn = 0;
121 PspQuotaList = PspQuotaList->
Flink)
154 DPRINT(
"PspReturnExcessQuotas(): Amount of quota released -- %lu\n", AmountToReturn);
155 MmReturnPoolQuota(QuotaType, AmountToReturn);
156 *ReturnedQuotas = AmountToReturn;
213 if (QuotaBlock->QuotaEntry[QuotaType].Usage +
Amount >
214 QuotaBlock->QuotaEntry[QuotaType].Limit &&
221 DPRINT1(
"PspChargeProcessQuotaSpecifiedPool(): Quota amount exceeds the limit on page file quota (limit -- %lu || amount -- %lu)\n",
222 QuotaBlock->QuotaEntry[QuotaType].Limit,
Amount);
231 if (!MmRaisePoolQuota(QuotaType,
232 QuotaBlock->QuotaEntry[QuotaType].Limit,
244 PspReturnExcessQuotas(QuotaType, &ReturnedQuotas);
245 if (ReturnedQuotas == 0)
247 DPRINT1(
"PspChargeProcessQuotaSpecifiedPool(): Failed to free some resources in order to raise quota limits...\n");
253 MmRaisePoolQuota(QuotaType,
254 QuotaBlock->QuotaEntry[QuotaType].Limit,
268 if (QuotaBlock->QuotaEntry[QuotaType].Usage +
Amount >
269 QuotaBlock->QuotaEntry[QuotaType].Limit)
271 DPRINT1(
"PspChargeProcessQuotaSpecifiedPool(): Quota amount exceeds the limit (limit -- %lu || amount -- %lu)\n",
272 QuotaBlock->QuotaEntry[QuotaType].Limit,
Amount);
281 if (QuotaBlock->QuotaEntry[QuotaType].Peak <
282 QuotaBlock->QuotaEntry[QuotaType].Usage)
285 QuotaBlock->QuotaEntry[QuotaType].Usage);
302 if (
Process->QuotaPeak[QuotaType] <
Process->QuotaUsage[QuotaType])
305 Process->QuotaUsage[QuotaType]);
353 SIZE_T AmountToReturn = 0;
364 QuotaBlock->QuotaEntry[QuotaType].Usage <
Amount)
371 QuotaBlock->QuotaEntry[QuotaType].Usage,
383 (QuotaBlock->QuotaEntry[QuotaType].Limit > QuotaBlock->QuotaEntry[QuotaType].Usage + ReturnThreshold))
390 AmountToReturn =
min(
Amount, ReturnThreshold);
400 if (QuotaBlock->QuotaEntry[QuotaType].Return > ReturnThreshold)
402 MmReturnPoolQuota(QuotaType, QuotaBlock->QuotaEntry[QuotaType].Return);
408 QuotaBlock->QuotaEntry[QuotaType].Limit - AmountToReturn);
489 if (ParentProcess !=
NULL)
492 QuotaBlock = ParentProcess->QuotaBlock;
502 Process->QuotaBlock = QuotaBlock;
557 ULONG PsQuotaTypeIndex;
588 PspReturnQuotasOnDestroy(QuotaBlock);
630 if (AmountToReturnPaged != 0)
635 if (AmountToReturnNonPaged != 0)
640 DPRINT(
"PsReturnSharedPoolQuota(): Amount returned back (paged %lu -- non paged %lu)\n", AmountToReturnPaged, AmountToReturnNonPaged);
686 if (AmountToChargePaged != 0)
692 DPRINT1(
"PsChargeSharedPoolQuota(): Failed to charge the shared pool quota (Status 0x%lx)\n",
Status);
698 if (AmountToChargeNonPaged != 0)
704 DPRINT1(
"PsChargeSharedPoolQuota(): Failed to charge the shared pool quota (Status 0x%lx). Attempting to return some paged pool back...\n",
Status);
713 DPRINT(
"PsChargeSharedPoolQuota(): Amount charged (paged %lu -- non paged %lu)\n", AmountToChargePaged, AmountToChargeNonPaged);
1074 CapturedQuotaLimits.
Flags = 0;
1088 DPRINT1(
"Invalid quota flags: 0x%lx\n", CapturedQuotaLimits.
Flags);
1099 DPRINT1(
"Invalid value: (%lx,%lx,%lx,%lx,%lx)\n",
1110 DPRINT1(
"Invalid quota size: 0x%lx\n", QuotaLimitsLength);
1116 DPRINT1(
"Exception while copying data\n");
1130 IncreaseOkay =
FALSE;
1165 if (QuotaBlock ==
NULL)
#define STATUS_PRIVILEGE_NOT_HELD
#define _Requires_lock_held_(lock)
#define NT_SUCCESS(StatCode)
#define ASSERT_IRQL_EQUAL(x)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeReleaseSpinLock(sl, irql)
#define KeAcquireSpinLock(sl, irql)
#define KeGetCurrentIrql()
#define InterlockedDecrementUL(Addend)
#define InterlockedExchangeSizeT(Target, Value)
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
enum _PS_QUOTA_TYPE PS_QUOTA_TYPE
#define EXCEPTION_EXECUTE_HANDLER
#define QUOTA_LIMITS_HARDWS_MIN_DISABLE
#define QUOTA_LIMITS_HARDWS_MAX_DISABLE
#define QUOTA_LIMITS_HARDWS_MAX_ENABLE
#define QUOTA_LIMITS_HARDWS_MIN_ENABLE
#define InterlockedCompareExchangePointer
#define InterlockedExchangeAddSizeT(a, b)
#define InterlockedIncrementSizeT(a)
#define KeLeaveGuardedRegion()
#define KeEnterGuardedRegion()
#define ExFreePoolWithTag(_P, _T)
#define UNREFERENCED_PARAMETER(P)
NTSTATUS NTAPI MmAdjustWorkingSetSize(IN SIZE_T WorkingSetMinimumInBytes, IN SIZE_T WorkingSetMaximumInBytes, IN ULONG SystemCache, IN BOOLEAN IncreaseOkay)
_In_ SIZE_T QuotaToReturn
const LUID SeIncreaseQuotaPrivilege
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
#define STATUS_QUOTA_EXCEEDED
#define STATUS_PAGEFILE_QUOTA_EXCEEDED
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
#define PSP_NON_PAGED_POOL_QUOTA_THRESHOLD
#define PSP_PAGED_POOL_QUOTA_THRESHOLD
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
#define _SEH2_YIELD(__stmt)
PEPROCESS PsInitialSystemProcess
VOID NTAPI PsReturnSharedPoolQuota(_In_ PEPROCESS_QUOTA_BLOCK QuotaBlock, _In_ SIZE_T AmountToReturnPaged, _In_ SIZE_T AmountToReturnNonPaged)
Returns the shared (paged and non paged) pool quotas. The function is used exclusively by the Object ...
VOID NTAPI PspReturnProcessQuotaSpecifiedPool(_In_opt_ PEPROCESS Process, _In_ PEPROCESS_QUOTA_BLOCK QuotaBlock, _In_ PS_QUOTA_TYPE QuotaType, _In_ SIZE_T Amount)
Internal kernel function that provides the bulk logic of process quota returning. It returns (takes a...
#define VALID_QUOTA_FLAGS
NTSTATUS NTAPI PspSetQuotaLimits(_In_ PEPROCESS Process, _In_ ULONG Unused, _In_ PVOID QuotaLimits, _In_ ULONG QuotaLimitsLength, _In_ KPROCESSOR_MODE PreviousMode)
This function adjusts the working set limits of a process and sets up new quota limits when necessary...
VOID NTAPI PsInitializeQuotaSystem(VOID)
Initializes the quota system during boot phase of the system, which sets up the default quota block t...
NTSTATUS NTAPI PsChargeProcessPageFileQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Charges the process page file quota. The function is used internally by the kernel.
NTSTATUS NTAPI PsChargeProcessNonPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Charges the non paged pool quota of a given process.
NTSTATUS NTAPI PspChargeProcessQuotaSpecifiedPool(_In_opt_ PEPROCESS Process, _In_ PEPROCESS_QUOTA_BLOCK QuotaBlock, _In_ PS_QUOTA_TYPE QuotaType, _In_ SIZE_T Amount)
Internal kernel function that provides the bulk logic of process quota charging, necessary for export...
PEPROCESS_QUOTA_BLOCK NTAPI PsChargeSharedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T AmountToChargePaged, _In_ SIZE_T AmountToChargeNonPaged)
Charges the shared (paged and non paged) pool quotas. The function is used exclusively by the Object ...
VOID NTAPI PspDereferenceQuotaBlock(_In_opt_ PEPROCESS Process, _In_ PEPROCESS_QUOTA_BLOCK QuotaBlock)
De-references a quota block when quotas have been returned back because of an object de-allocation or...
VOID NTAPI PsReturnProcessNonPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Returns the non paged quota pool that the process was taking up.
NTSTATUS NTAPI PsReturnProcessPageFileQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Returns the page file quota that the process was taking up. The function is used exclusively by the k...
EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock
VOID NTAPI PsReturnProcessPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Returns the paged pool quota that the process was taking up.
static LIST_ENTRY PspQuotaBlockList
static KSPIN_LOCK PspQuotaLock
VOID NTAPI PspInsertQuotaBlock(_In_ PEPROCESS_QUOTA_BLOCK QuotaBlock)
Inserts the new quota block into the quota list.
VOID NTAPI PspInheritQuota(_In_ PEPROCESS Process, _In_opt_ PEPROCESS ParentProcess)
Inherits the quota block to another newborn (child) process. If there's no parent process,...
NTSTATUS NTAPI PsChargeProcessPoolQuota(_In_ PEPROCESS Process, _In_ POOL_TYPE PoolType, _In_ SIZE_T Amount)
Charges the process' quota pool. The type of quota to be charged depends upon the PoolType parameter.
VOID NTAPI PsChargePoolQuota(_In_ PEPROCESS Process, _In_ POOL_TYPE PoolType, _In_ SIZE_T Amount)
Charges the pool quota of a given process. The kind of pool quota to charge is determined by the Pool...
NTSTATUS NTAPI PsChargeProcessPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Charges the paged pool quota of a given process.
VOID NTAPI PsReturnPoolQuota(_In_ PEPROCESS Process, _In_ POOL_TYPE PoolType, _In_ SIZE_T Amount)
Returns the pool quota that the process was taking up.
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
EPROCESS_QUOTA_ENTRY QuotaEntry[PsQuotaTypes]
struct _LIST_ENTRY * Flink
SIZE_T MaximumWorkingSetSize
RATE_QUOTA_LIMIT CpuRateLimit
SIZE_T MinimumWorkingSetSize
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_PARAMETER
#define STATUS_INFO_LENGTH_MISMATCH
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
#define ObDereferenceObject
#define PsGetCurrentProcess
_In_ KPROCESSOR_MODE PreviousMode