mirror of
				https://github.com/winfsp/winfsp.git
				synced 2025-11-03 20:48:08 -06:00 
			
		
		
		
	sys: FspAlloc*(), FspFree*()
This commit is contained in:
		@@ -425,10 +425,10 @@ VOID FspFsvolCreateComplete(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (ReparseFileName.Length > FileObject->FileName.MaximumLength)
 | 
					            if (ReparseFileName.Length > FileObject->FileName.MaximumLength)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                PVOID Buffer = ExAllocatePoolWithTag(NonPagedPool, ReparseFileName.Length, FSP_TAG);
 | 
					                PVOID Buffer = FspAllocExternal(ReparseFileName.Length);
 | 
				
			||||||
                if (0 == Buffer)
 | 
					                if (0 == Buffer)
 | 
				
			||||||
                    FSP_RETURN(Result = STATUS_INSUFFICIENT_RESOURCES);
 | 
					                    FSP_RETURN(Result = STATUS_INSUFFICIENT_RESOURCES);
 | 
				
			||||||
                ExFreePool(FileObject->FileName.Buffer);
 | 
					                FspFreeExternal(FileObject->FileName.Buffer);
 | 
				
			||||||
                FileObject->FileName.MaximumLength = ReparseFileName.Length;
 | 
					                FileObject->FileName.MaximumLength = ReparseFileName.Length;
 | 
				
			||||||
                FileObject->FileName.Buffer = Buffer;
 | 
					                FileObject->FileName.Buffer = Buffer;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -189,8 +189,7 @@ static NTSTATUS FspFsvrtDeviceInit(PDEVICE_OBJECT DeviceObject)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    FspIoqInitialize(&FsvrtDeviceExtension->Ioq);
 | 
					    FspIoqInitialize(&FsvrtDeviceExtension->Ioq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FsvrtDeviceExtension->SwapVpb = ExAllocatePoolWithTag(NonPagedPool,
 | 
					    FsvrtDeviceExtension->SwapVpb = FspAllocNonPagedExternal(sizeof *FsvrtDeviceExtension->SwapVpb);
 | 
				
			||||||
        sizeof *FsvrtDeviceExtension->SwapVpb, FSP_TAG);
 | 
					 | 
				
			||||||
    if (0 == FsvrtDeviceExtension->SwapVpb)
 | 
					    if (0 == FsvrtDeviceExtension->SwapVpb)
 | 
				
			||||||
        return STATUS_INSUFFICIENT_RESOURCES;
 | 
					        return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
    RtlZeroMemory(FsvrtDeviceExtension->SwapVpb, sizeof *FsvrtDeviceExtension->SwapVpb);
 | 
					    RtlZeroMemory(FsvrtDeviceExtension->SwapVpb, sizeof *FsvrtDeviceExtension->SwapVpb);
 | 
				
			||||||
@@ -205,7 +204,7 @@ static VOID FspFsvrtDeviceFini(PDEVICE_OBJECT DeviceObject)
 | 
				
			|||||||
    FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(DeviceObject);
 | 
					    FSP_FSVRT_DEVICE_EXTENSION *FsvrtDeviceExtension = FspFsvrtDeviceExtension(DeviceObject);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (0 != FsvrtDeviceExtension->SwapVpb)
 | 
					    if (0 != FsvrtDeviceExtension->SwapVpb)
 | 
				
			||||||
        ExFreePoolWithTag(FsvrtDeviceExtension->SwapVpb, FSP_TAG);
 | 
					        FspFreeExternal(FsvrtDeviceExtension->SwapVpb);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject)
 | 
					static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject)
 | 
				
			||||||
@@ -405,9 +404,8 @@ NTSTATUS FspDeviceCopyList(
 | 
				
			|||||||
        DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount, &DeviceObjectCount))
 | 
					        DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount, &DeviceObjectCount))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (0 != DeviceObjects)
 | 
					        if (0 != DeviceObjects)
 | 
				
			||||||
            ExFreePoolWithTag(DeviceObjects, FSP_TAG);
 | 
					            FspFree(DeviceObjects);
 | 
				
			||||||
        DeviceObjects = ExAllocatePoolWithTag(NonPagedPool,
 | 
					        DeviceObjects = FspAllocNonPaged(sizeof *DeviceObjects * DeviceObjectCount);
 | 
				
			||||||
            sizeof *DeviceObjects * DeviceObjectCount, FSP_TAG);
 | 
					 | 
				
			||||||
        if (0 == DeviceObjects)
 | 
					        if (0 == DeviceObjects)
 | 
				
			||||||
            return STATUS_INSUFFICIENT_RESOURCES;
 | 
					            return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
        RtlZeroMemory(DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount);
 | 
					        RtlZeroMemory(DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount);
 | 
				
			||||||
@@ -427,7 +425,7 @@ VOID FspDeviceDeleteList(
 | 
				
			|||||||
    for (ULONG i = 0; DeviceObjectCount > i; i++)
 | 
					    for (ULONG i = 0; DeviceObjectCount > i; i++)
 | 
				
			||||||
        ObDereferenceObject(DeviceObjects[i]);
 | 
					        ObDereferenceObject(DeviceObjects[i]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ExFreePoolWithTag(DeviceObjects, FSP_TAG);
 | 
					    FspFree(DeviceObjects);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VOID FspDeviceDeleteAll(VOID)
 | 
					VOID FspDeviceDeleteAll(VOID)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,7 +167,8 @@
 | 
				
			|||||||
    } while (0,0)
 | 
					    } while (0,0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* misc macros */
 | 
					/* misc macros */
 | 
				
			||||||
#define FSP_TAG                         ' psF'
 | 
					#define FSP_ALLOC_INTERNAL_TAG          'IpsF'
 | 
				
			||||||
 | 
					#define FSP_ALLOC_EXTERNAL_TAG          'XpsF'
 | 
				
			||||||
#define FSP_IO_INCREMENT                IO_NETWORK_INCREMENT
 | 
					#define FSP_IO_INCREMENT                IO_NETWORK_INCREMENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* disable warnings */
 | 
					/* disable warnings */
 | 
				
			||||||
@@ -430,6 +431,36 @@ VOID FspFileContextRelease(FSP_FILE_CONTEXT *Context)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* misc */
 | 
					/* misc */
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					PVOID FspAlloc(SIZE_T Size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ExAllocatePoolWithTag(PagedPool, Size, FSP_ALLOC_INTERNAL_TAG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					PVOID FspAllocNonPaged(SIZE_T Size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ExAllocatePoolWithTag(NonPagedPool, Size, FSP_ALLOC_INTERNAL_TAG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					VOID FspFree(PVOID Pointer)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ExFreePoolWithTag(Pointer, FSP_ALLOC_INTERNAL_TAG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					PVOID FspAllocExternal(SIZE_T Size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ExAllocatePoolWithTag(PagedPool, Size, FSP_ALLOC_EXTERNAL_TAG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					PVOID FspAllocNonPagedExternal(SIZE_T Size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ExAllocatePoolWithTag(NonPagedPool, Size, FSP_ALLOC_EXTERNAL_TAG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline
 | 
				
			||||||
 | 
					VOID FspFreeExternal(PVOID Pointer)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ExFreePool(Pointer);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
NTSTATUS FspCreateGuid(GUID *Guid);
 | 
					NTSTATUS FspCreateGuid(GUID *Guid);
 | 
				
			||||||
BOOLEAN FspValidRelativeSecurityDescriptor(
 | 
					BOOLEAN FspValidRelativeSecurityDescriptor(
 | 
				
			||||||
    PSECURITY_DESCRIPTOR SecurityDescriptor, ULONG SecurityDescriptorLength,
 | 
					    PSECURITY_DESCRIPTOR SecurityDescriptor, ULONG SecurityDescriptorLength,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,16 +20,14 @@ NTSTATUS FspFileContextCreate(ULONG ExtraSize, FSP_FILE_CONTEXT **PFsContext)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    *PFsContext = 0;
 | 
					    *PFsContext = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FSP_FILE_CONTEXT_NONPAGED *NonPaged = ExAllocatePoolWithTag(NonPagedPool,
 | 
					    FSP_FILE_CONTEXT_NONPAGED *NonPaged = FspAllocNonPaged(sizeof *NonPaged);
 | 
				
			||||||
        sizeof *NonPaged, FSP_TAG);
 | 
					 | 
				
			||||||
    if (0 == NonPaged)
 | 
					    if (0 == NonPaged)
 | 
				
			||||||
        return STATUS_INSUFFICIENT_RESOURCES;
 | 
					        return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FSP_FILE_CONTEXT *FsContext = ExAllocatePoolWithTag(PagedPool,
 | 
					    FSP_FILE_CONTEXT *FsContext = FspAlloc(sizeof *FsContext + ExtraSize);
 | 
				
			||||||
        sizeof *FsContext + ExtraSize, FSP_TAG);
 | 
					 | 
				
			||||||
    if (0 == FsContext)
 | 
					    if (0 == FsContext)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ExFreePoolWithTag(NonPaged, FSP_TAG);
 | 
					        FspFree(NonPaged);
 | 
				
			||||||
        return STATUS_INSUFFICIENT_RESOURCES;
 | 
					        return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -62,7 +60,7 @@ VOID FspFileContextDelete(FSP_FILE_CONTEXT *FsContext)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ExDeleteResourceLite(&FsContext->NonPaged->PagingIoResource);
 | 
					    ExDeleteResourceLite(&FsContext->NonPaged->PagingIoResource);
 | 
				
			||||||
    ExDeleteResourceLite(&FsContext->NonPaged->Resource);
 | 
					    ExDeleteResourceLite(&FsContext->NonPaged->Resource);
 | 
				
			||||||
    ExFreePoolWithTag(FsContext->NonPaged, FSP_TAG);
 | 
					    FspFree(FsContext->NonPaged);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ExFreePoolWithTag(FsContext, FSP_TAG);
 | 
					    FspFree(FsContext);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,7 +128,7 @@ static NTSTATUS FspFsctlCreateVolume(
 | 
				
			|||||||
        return Result;
 | 
					        return Result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* copy the security descriptor from the system buffer to a temporary one */
 | 
					    /* copy the security descriptor from the system buffer to a temporary one */
 | 
				
			||||||
    SecurityDescriptorBuf = ExAllocatePoolWithTag(PagedPool, SecurityDescriptorSize, FSP_TAG);
 | 
					    SecurityDescriptorBuf = FspAlloc(SecurityDescriptorSize);
 | 
				
			||||||
    if (0 == SecurityDescriptorBuf)
 | 
					    if (0 == SecurityDescriptorBuf)
 | 
				
			||||||
        return STATUS_INSUFFICIENT_RESOURCES;
 | 
					        return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
    RtlCopyMemory(SecurityDescriptorBuf, SecurityDescriptor, SecurityDescriptorSize);
 | 
					    RtlCopyMemory(SecurityDescriptorBuf, SecurityDescriptor, SecurityDescriptorSize);
 | 
				
			||||||
@@ -176,7 +176,7 @@ static NTSTATUS FspFsctlCreateVolume(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* free the temporary security descriptor */
 | 
					    /* free the temporary security descriptor */
 | 
				
			||||||
    if (0 != SecurityDescriptorBuf)
 | 
					    if (0 != SecurityDescriptorBuf)
 | 
				
			||||||
        ExFreePoolWithTag(SecurityDescriptorBuf, FSP_TAG);
 | 
					        FspFree(SecurityDescriptorBuf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return Result;
 | 
					    return Result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -306,7 +306,7 @@ static NTSTATUS FspFsvrtDeleteVolume(
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        IoReleaseVpbSpinLock(Irql);
 | 
					        IoReleaseVpbSpinLock(Irql);
 | 
				
			||||||
        if (FreeVpb)
 | 
					        if (FreeVpb)
 | 
				
			||||||
            ExFreePool(OldVpb);
 | 
					            FspFreeExternal(OldVpb);
 | 
				
			||||||
#pragma prefast(pop)
 | 
					#pragma prefast(pop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* release the file system device and virtual volume objects */
 | 
					        /* release the file system device and virtual volume objects */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,8 +51,7 @@ NTSTATUS FspIopCreateRequestEx(
 | 
				
			|||||||
    if (FSP_FSCTL_TRANSACT_REQ_SIZEMAX < sizeof *Request + ExtraSize)
 | 
					    if (FSP_FSCTL_TRANSACT_REQ_SIZEMAX < sizeof *Request + ExtraSize)
 | 
				
			||||||
        return STATUS_INVALID_PARAMETER;
 | 
					        return STATUS_INVALID_PARAMETER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    RequestHeader = ExAllocatePoolWithTag(PagedPool,
 | 
					    RequestHeader = FspAlloc(sizeof *RequestHeader + sizeof *Request + ExtraSize);
 | 
				
			||||||
        sizeof *RequestHeader + sizeof *Request + ExtraSize, FSP_TAG);
 | 
					 | 
				
			||||||
    if (0 == RequestHeader)
 | 
					    if (0 == RequestHeader)
 | 
				
			||||||
        return STATUS_INSUFFICIENT_RESOURCES;
 | 
					        return STATUS_INSUFFICIENT_RESOURCES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -87,7 +86,7 @@ static VOID FspIopDeleteRequest(FSP_FSCTL_TRANSACT_REQ *Request)
 | 
				
			|||||||
    if (0 != RequestHeader->RequestFini)
 | 
					    if (0 != RequestHeader->RequestFini)
 | 
				
			||||||
        RequestHeader->RequestFini(RequestHeader->Context);
 | 
					        RequestHeader->RequestFini(RequestHeader->Context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ExFreePoolWithTag(RequestHeader, FSP_TAG);
 | 
					    FspFree(RequestHeader);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PVOID *FspIopRequestContextAddress(FSP_FSCTL_TRANSACT_REQ *Request, ULONG I)
 | 
					PVOID *FspIopRequestContextAddress(FSP_FSCTL_TRANSACT_REQ *Request, ULONG I)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user