From f28b5f7302899cbca1292a3bf87f2808b74b7191 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 1 Aug 2005 11:20:44 +0000 Subject: [PATCH] Setup quota blocks for processes. svn path=/trunk/; revision=16942 --- reactos/ntoskrnl/ps/kill.c | 2 ++ reactos/ntoskrnl/ps/process.c | 8 +++++--- reactos/ntoskrnl/ps/psmgr.c | 33 ++++++++++++++++++++++----------- reactos/ntoskrnl/ps/quota.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index 42f5554e696..ca28ec73e4f 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -509,6 +509,8 @@ PspExitProcess(PEPROCESS Process) PspRunCreateProcessNotifyRoutines(Process, FALSE); + PspDestroyQuotaBlock(Process); + /* close all handles associated with our process, this needs to be done when the last thread still runs */ ObKillProcess(Process); diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 6640dc19636..8bef54d08c4 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -20,6 +20,8 @@ PEPROCESS EXPORTED PsInitialSystemProcess = NULL; PEPROCESS PsIdleProcess = NULL; POBJECT_TYPE EXPORTED PsProcessType = NULL; +EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock; + LIST_ENTRY PsActiveProcessHead; FAST_MUTEX PspActiveProcessMutex; LARGE_INTEGER ShortPsLockDelay, PsLockTimeout; @@ -295,8 +297,8 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, Process->Session = pParentProcess->Session; } - /* FIXME: Set up the Quota Block from the Parent - PspInheritQuota(Parent, Process); */ + /* Set up the Quota Block from the Parent */ + PspInheritQuota(Process, pParentProcess); /* FIXME: Set up Dos Device Map from the Parent ObInheritDeviceMap(Parent, Process) */ @@ -369,7 +371,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, DPRINT1("Failed to create CID handle (unique process ID)! Status: 0x%x\n", Status); ObDereferenceObject(Process); goto exitdereferenceobjects; - } + } /* FIXME: Insert into Job Object */ diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index 45d94361c72..49592f17778 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -126,21 +126,30 @@ PsInitProcessManagment(VOID) DPRINT("Creating Process Object Type\n"); - /* Initialize the Thread type */ - RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); - RtlInitUnicodeString(&Name, L"Process"); - ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); - ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(EPROCESS); - ObjectTypeInitializer.GenericMapping = PiProcessMapping; - ObjectTypeInitializer.PoolType = NonPagedPool; - ObjectTypeInitializer.ValidAccessMask = PROCESS_ALL_ACCESS; - ObjectTypeInitializer.UseDefaultObject = TRUE; - ObjectTypeInitializer.DeleteProcedure = PspDeleteProcess; - ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &PsProcessType); + /* Initialize the Process type */ + RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); + RtlInitUnicodeString(&Name, L"Process"); + ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); + ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(EPROCESS); + ObjectTypeInitializer.GenericMapping = PiProcessMapping; + ObjectTypeInitializer.PoolType = NonPagedPool; + ObjectTypeInitializer.ValidAccessMask = PROCESS_ALL_ACCESS; + ObjectTypeInitializer.UseDefaultObject = TRUE; + ObjectTypeInitializer.DeleteProcedure = PspDeleteProcess; + ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &PsProcessType); InitializeListHead(&PsActiveProcessHead); ExInitializeFastMutex(&PspActiveProcessMutex); + /* + * Initialize the default quota block. + */ + + RtlZeroMemory(&PspDefaultQuotaBlock, sizeof(PspDefaultQuotaBlock)); + PspDefaultQuotaBlock.QuotaEntry[PagedPool].Limit = (SIZE_T)-1; + PspDefaultQuotaBlock.QuotaEntry[NonPagedPool].Limit = (SIZE_T)-1; + PspDefaultQuotaBlock.QuotaEntry[2].Limit = (SIZE_T)-1; /* Page file */ + /* * Initialize the idle process */ @@ -175,6 +184,7 @@ PsInitProcessManagment(VOID) FALSE); PsIdleProcess->Pcb.DirectoryTableBase.QuadPart = (ULONG_PTR)MmGetPageDirectory(); strcpy(PsIdleProcess->ImageFileName, "Idle"); + PspInheritQuota(PsIdleProcess, NULL); /* * Initialize the system process @@ -207,6 +217,7 @@ PsInitProcessManagment(VOID) sizeof(EPROCESS), FALSE); KProcess = &PsInitialSystemProcess->Pcb; + PspInheritQuota(PsInitialSystemProcess, NULL); MmInitializeAddressSpace(PsInitialSystemProcess, &PsInitialSystemProcess->AddressSpace); diff --git a/reactos/ntoskrnl/ps/quota.c b/reactos/ntoskrnl/ps/quota.c index ed0b1737490..494287d1699 100644 --- a/reactos/ntoskrnl/ps/quota.c +++ b/reactos/ntoskrnl/ps/quota.c @@ -15,6 +15,36 @@ /* FUNCTIONS ***************************************************************/ +VOID +STDCALL +PspInheritQuota(PEPROCESS Process, PEPROCESS ParentProcess) +{ + PEPROCESS_QUOTA_BLOCK QuotaBlock; + + if (ParentProcess != NULL) + QuotaBlock = ParentProcess->QuotaBlock; + else + QuotaBlock = &PspDefaultQuotaBlock; + + ASSERT(QuotaBlock != NULL); + + InterlockedIncrement(&QuotaBlock->ReferenceCount); + Process->QuotaBlock = QuotaBlock; +} + +VOID +STDCALL +PspDestroyQuotaBlock(PEPROCESS Process) +{ + PEPROCESS_QUOTA_BLOCK QuotaBlock = Process->QuotaBlock; + + if (InterlockedDecrement(&QuotaBlock->ReferenceCount) == 0) + { + if (QuotaBlock != &PspDefaultQuotaBlock) + ExFreePool(QuotaBlock); + } +} + /* * @implemented */