DPRINT1("FIXME: Need to check for large pages\n");
}
+ Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+ if (!NT_SUCCESS(Status))
+ {
+ Vad = NULL;
+ goto Error;
+ }
+
/* Allocate a VAD for our mapped region */
Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD_LONG), 'ldaV');
if (Vad == NULL)
{
+ PsReturnProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
Status = STATUS_INSUFFICIENT_RESOURCES;
goto Error;
}
MiLockProcessWorkingSetUnsafe(Process, Thread);
ASSERT(Vad->EndingVpn >= Vad->StartingVpn);
-
MiInsertVad((PMMVAD)Vad, &Process->VadRoot);
- Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
- if (!NT_SUCCESS(Status))
- goto Error;
-
/* Check if this is uncached */
if (CacheAttribute != MiCached)
{
if (Vad != NULL)
{
ExFreePoolWithTag(Vad, 'ldaV');
+ PsReturnProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
}
ExRaiseStatus(Status);
}
ULONG AlignedSize;
LARGE_INTEGER CurrentTime;
+ Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+ if (!NT_SUCCESS(Status))
+ return Status;
+
/* Allocate a VAD */
Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD_LONG), 'ldaV');
- if (!Vad) return STATUS_NO_MEMORY;
+ if (!Vad)
+ {
+ Status = STATUS_NO_MEMORY;
+ goto FailPath;
+ }
/* Setup the primary flags with the size, and make it commited, private, RW */
Vad->u.LongFlags = 0;
if (!NT_SUCCESS(Status))
{
ExFreePoolWithTag(Vad, 'ldaV');
- return STATUS_NO_MEMORY;
+ Status = STATUS_NO_MEMORY;
+ goto FailPath;
}
- Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
- if (!NT_SUCCESS(Status))
- {
- ExFreePoolWithTag(Vad, 'ldaV');
- return Status;
- }
/* Success */
return STATUS_SUCCESS;
+
+FailPath:
+ PsReturnProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+
+ return Status;
}
VOID
ULONG_PTR BaseAddress;
NTSTATUS Status;
+ if (Process->QuotaBlock != NULL)
+ {
+ Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Ran out of quota.\n");
+ return Status;
+ }
+ }
+
/* Allocate a VAD */
Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD_LONG), 'ldaV');
if (Vad == NULL)
{
DPRINT1("Failed to allocate VAD for shared user page\n");
- return STATUS_INSUFFICIENT_RESOURCES;
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto FailPath;
}
/* Setup the primary flags with the size, and make it private, RO */
{
DPRINT1("Failed to insert shared user VAD\n");
ExFreePoolWithTag(Vad, 'ldaV');
- return Status;
+ goto FailPath;
}
- if (Process->QuotaBlock != NULL)
- {
- Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Ran out of quota.\n");
- ExFreePoolWithTag(Vad, 'ldaV');
- return Status;
- }
- }
-
-
/* Success */
return STATUS_SUCCESS;
+
+FailPath:
+ if (Process->QuotaBlock != NULL)
+ PsReturnProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+
+ return Status;
}
#endif
PETHREAD CurrentThread = PsGetCurrentThread();
KAPC_STATE ApcState;
ULONG ProtectionMask, QuotaCharge = 0, QuotaFree = 0;
- BOOLEAN Attached = FALSE, ChangeProtection = FALSE;
+ BOOLEAN Attached = FALSE, ChangeProtection = FALSE, QuotaCharged = FALSE;
MMPTE TempPte;
PMMPTE PointerPte, LastPte;
PMMPDE PointerPde;
StartingAddress = (ULONG_PTR)PBaseAddress;
}
+ // Charge quotas for the VAD
+ Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Quota exceeded.\n");
+ goto FailPathNoLock;
+ }
+
+ QuotaCharged = TRUE;
+
//
// Allocate and initialize the VAD
//
goto FailPathNoLock;
}
- // Charge quotas for the VAD
- Status = PsChargeProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Quota exceeded.\n");
- ExFreePoolWithTag(Vad, 'SdaV');
- goto FailPathNoLock;
- }
-
//
// Detach and dereference the target process if
// it was different from the current process
}
_SEH2_END;
}
+ else if (QuotaCharged)
+ {
+ PsReturnProcessNonPagedPoolQuota(Process, sizeof(MMVAD_LONG));
+ }
return Status;
}