2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ps/quota.c
5 * PURPOSE: Process Pool Quotas
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
10 /* INCLUDES **************************************************************/
14 #include <internal/debug.h>
16 /* FUNCTIONS ***************************************************************/
23 PsChargePoolQuota(IN PEPROCESS Process
,
24 IN POOL_TYPE PoolType
,
29 /* Charge the usage */
30 Status
= PsChargeProcessPoolQuota(Process
, PoolType
, Amount
);
33 if (!NT_SUCCESS(Status
))
35 ExRaiseStatus(Status
);
44 PsChargeProcessNonPagedPoolQuota(IN PEPROCESS Process
,
47 /* Call the general function */
48 return PsChargeProcessPoolQuota(Process
, NonPagedPool
, Amount
);
56 PsChargeProcessPagedPoolQuota(IN PEPROCESS Process
,
59 /* Call the general function */
60 return PsChargeProcessPoolQuota(Process
, PagedPool
, Amount
);
68 PsChargeProcessPoolQuota(IN PEPROCESS Process
,
69 IN POOL_TYPE PoolType
,
72 PEPROCESS_QUOTA_BLOCK QuotaBlock
;
76 /* Get current Quota Block */
77 QuotaBlock
= Process
->QuotaBlock
;
79 /* Quota Operations are not to be done on the SYSTEM Process */
80 if (Process
== PsInitialSystemProcess
) return STATUS_SUCCESS
;
83 NewUsageSize
= QuotaBlock
->QuotaEntry
[PoolType
].Usage
+ Amount
;
85 /* Does this size respect the quota? */
86 if (NewUsageSize
> QuotaBlock
->QuotaEntry
[PoolType
].Limit
)
88 /* It doesn't, so keep raising the Quota */
89 while (MiRaisePoolQuota(PoolType
,
90 QuotaBlock
->QuotaEntry
[PoolType
].Limit
,
93 /* Save new Maximum Quota */
94 QuotaBlock
->QuotaEntry
[PoolType
].Limit
= NewMaxQuota
;
96 /* See if the new Maximum Quota fulfills our need */
97 if (NewUsageSize
<= NewMaxQuota
) goto QuotaChanged
;
100 return STATUS_QUOTA_EXCEEDED
;
105 QuotaBlock
->QuotaEntry
[PoolType
].Usage
= NewUsageSize
;
107 /* Is this a new peak? */
108 if (NewUsageSize
> QuotaBlock
->QuotaEntry
[PoolType
].Peak
)
110 QuotaBlock
->QuotaEntry
[PoolType
].Peak
= NewUsageSize
;
114 return STATUS_SUCCESS
;
122 PsReturnPoolQuota(IN PEPROCESS Process
,
123 IN POOL_TYPE PoolType
,
134 PsReturnProcessNonPagedPoolQuota(IN PEPROCESS Process
,
145 PsReturnProcessPagedPoolQuota(IN PEPROCESS Process
,