#include <debug.h>
#include "internal/io_i.h"
+volatile LONG IoPageReadIrpAllocationFailure = 0;
+volatile LONG IoPageReadNonPagefileIrpAllocationFailure = 0;
+
/* PRIVATE FUNCTIONS *********************************************************/
VOID
ACCESS_MASK DesiredAccess;
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
ULONG BufferLength;
+ POOL_TYPE PoolType;
PAGED_CODE();
StackPtr->Parameters.DeviceIoControl.OutputBufferLength =
OutputBufferLength;
+ PoolType = IsDevIoCtl ? NonPagedPoolCacheAligned : NonPagedPool;
+
/* Handle the Methods */
switch (AccessType)
{
{
/* Allocate the System Buffer */
Irp->AssociatedIrp.SystemBuffer =
- ExAllocatePoolWithTag(NonPagedPool,
- BufferLength,
- TAG_SYS_BUF);
+ ExAllocatePoolWithQuotaTag(PoolType,
+ BufferLength,
+ TAG_SYS_BUF);
/* Check if we got a buffer */
if (InputBuffer)
{
/* Allocate the System Buffer */
Irp->AssociatedIrp.SystemBuffer =
- ExAllocatePoolWithTag(NonPagedPool,
- InputBufferLength,
- TAG_SYS_BUF);
+ ExAllocatePoolWithQuotaTag(PoolType,
+ InputBufferLength,
+ TAG_SYS_BUF);
/* Copy into the System Buffer */
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p \n",
FileObject, Mdl, Offset);
+ /* Is the write originating from Cc? */
+ if (FileObject->SectionObjectPointer != NULL &&
+ FileObject->SectionObjectPointer->SharedCacheMap != NULL)
+ {
+ ++CcDataFlushes;
+ CcDataPages += BYTES_TO_PAGES(MmGetMdlByteCount(Mdl));
+ }
+
/* Get the Device Object */
DeviceObject = IoGetRelatedDeviceObject(FileObject);
/* Allocate IRP */
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
- if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
+ /* If allocation failed, try to see whether we can use
+ * the reserve IRP
+ */
+ if (Irp == NULL)
+ {
+ /* We will use it only for paging file */
+ if (MmIsFileObjectAPagingFile(FileObject))
+ {
+ InterlockedExchangeAdd(&IoPageReadIrpAllocationFailure, 1);
+ Irp = IopAllocateReserveIrp(DeviceObject->StackSize);
+ }
+ else
+ {
+ InterlockedExchangeAdd(&IoPageReadNonPagefileIrpAllocationFailure, 1);
+ }
+
+ /* If allocation failed (not a paging file or too big stack size)
+ * Fail for real
+ */
+ if (Irp == NULL)
+ {
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+ }
/* Get the Stack */
StackPtr = IoGetNextIrpStackLocation(Irp);
{
_SEH2_TRY
{
- /*
- * Check if the handle has either FILE_WRITE_DATA or
- * FILE_APPEND_DATA granted. However, if this is a named pipe,
- * make sure we don't ask for FILE_APPEND_DATA as it interferes
- * with the FILE_CREATE_PIPE_INSTANCE access right!
- */
- if (!(ObjectHandleInfo.GrantedAccess &
- ((!(FileObject->Flags & FO_NAMED_PIPE) ?
- FILE_APPEND_DATA : 0) | FILE_WRITE_DATA)))
- {
- /* We failed */
- ObDereferenceObject(FileObject);
- _SEH2_YIELD(return STATUS_ACCESS_DENIED);
- }
-
/* Probe the status block */
ProbeForWriteIoStatusBlock(IoStatusBlock);