Skip to content

Commit

Permalink
Using ExAllocatePool2 for deferred API change (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
visvel authored May 11, 2022
1 parent a423baf commit cf17d8d
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 120 deletions.
5 changes: 0 additions & 5 deletions serial/serenum/serenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ Revision History:

#define SERENUM_POOL_TAG (ULONG)'mneS'

/*#undef ExAllocatePool
#define ExAllocatePool(type, size) \
ExAllocatePoolWithTag(type, size, SERENUM_POOL_TAG)*/


#pragma warning(error:4100) // Unreferenced formal parameter
#pragma warning(error:4705) // Statement has no effect
// disable warnings
Expand Down
30 changes: 13 additions & 17 deletions storage/class/cdrom/src/autorun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,18 +1296,14 @@ Return Value:
DeviceExtension->KernelModeMcnContext.LockCount = 0;
DeviceExtension->KernelModeMcnContext.McnDisableCount = 0;

mediaChangeInfo = ExAllocatePoolWithTag(NonPagedPoolNx,
sizeof(MEDIA_CHANGE_DETECTION_INFO),
CDROM_TAG_MEDIA_CHANGE_DETECTION);
mediaChangeInfo = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(MEDIA_CHANGE_DETECTION_INFO),
CDROM_TAG_MEDIA_CHANGE_DETECTION);

if (mediaChangeInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
RtlZeroMemory(mediaChangeInfo, sizeof(MEDIA_CHANGE_DETECTION_INFO));
}

if (NT_SUCCESS(status))
{
Expand Down Expand Up @@ -1354,9 +1350,9 @@ Return Value:

if (NT_SUCCESS(status))
{
senseBuffer = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
SENSE_BUFFER_SIZE,
CDROM_TAG_MEDIA_CHANGE_DETECTION);
senseBuffer = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_CACHE_ALIGNED,
SENSE_BUFFER_SIZE,
CDROM_TAG_MEDIA_CHANGE_DETECTION);
if (senseBuffer == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
Expand Down Expand Up @@ -1531,9 +1527,9 @@ Return Value:
{
if (info->Gesn.Buffer == NULL)
{
info->Gesn.Buffer = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
GESN_BUFFER_SIZE,
CDROM_TAG_GESN);
info->Gesn.Buffer = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_CACHE_ALIGNED,
GESN_BUFFER_SIZE,
CDROM_TAG_GESN);
}

if (info->Gesn.Buffer == NULL)
Expand Down Expand Up @@ -2281,10 +2277,10 @@ Return Value:
// allocate a buffer for the string
deviceString.Length = (USHORT)( length );
deviceString.MaximumLength = deviceString.Length + 1;
deviceString.Buffer = (PCHAR)ExAllocatePoolWithTag( NonPagedPoolNx,
deviceString.MaximumLength,
CDROM_TAG_AUTORUN_DISABLE
);
deviceString.Buffer = (PCHAR)ExAllocatePool2(POOL_FLAG_NON_PAGED,
deviceString.MaximumLength,
CDROM_TAG_AUTORUN_DISABLE
);
if (deviceString.Buffer == NULL)
{
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_MCN,
Expand Down
6 changes: 3 additions & 3 deletions storage/class/cdrom/src/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ Return Value:

// 7. Now, the device can be created.
{
wideDeviceName = ExAllocatePoolWithTag(NonPagedPoolNx,
64 * sizeof(WCHAR),
CDROM_TAG_STRINGS);
wideDeviceName = ExAllocatePool2(POOL_FLAG_NON_PAGED,
64 * sizeof(WCHAR),
CDROM_TAG_STRINGS);

if (wideDeviceName == NULL)
{
Expand Down
38 changes: 19 additions & 19 deletions storage/class/cdrom/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ BufferLength and WriteToDevice to control the data direction of the device
Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;

// Sense buffer is in aligned nonpaged pool.
senseInfoBuffer = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
SENSE_BUFFER_SIZE,
CDROM_TAG_SENSE_INFO);
senseInfoBuffer = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_CACHE_ALIGNED,
SENSE_BUFFER_SIZE,
CDROM_TAG_SENSE_INFO);

if (senseInfoBuffer == NULL)
{
Expand Down Expand Up @@ -838,9 +838,9 @@ Return Value:
return;
}

notification = ExAllocatePoolWithTag(NonPagedPoolNx,
requiredSize,
CDROM_TAG_NOTIFICATION);
notification = ExAllocatePool2(POOL_FLAG_NON_PAGED,
requiredSize,
CDROM_TAG_NOTIFICATION);

// if none allocated, exit
if (notification == NULL)
Expand Down Expand Up @@ -919,9 +919,9 @@ Return Value:
if (NT_SUCCESS(status))
{
// Allocate Srb from nonpaged pool.
context = ExAllocatePoolWithTag(NonPagedPoolNx,
sizeof(COMPLETION_CONTEXT),
CDROM_TAG_COMPLETION_CONTEXT);
context = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(COMPLETION_CONTEXT),
CDROM_TAG_COMPLETION_CONTEXT);

if (context == NULL)
{
Expand Down Expand Up @@ -2272,7 +2272,7 @@ Return Value:
);

dvdReadStructure = (PDVD_READ_STRUCTURE)
ExAllocatePoolWithTag(PagedPool, bufferLen, DVD_TAG_DVD_REGION);
ExAllocatePool2(POOL_FLAG_PAGED, bufferLen, DVD_TAG_DVD_REGION);

if (dvdReadStructure == NULL)
{
Expand Down Expand Up @@ -2656,9 +2656,9 @@ Return Value:

TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_IOCTL, "DeviceRestoreDefaultSpeed: Restore device speed for %p\n", device));

perfDescriptor = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
transferLength,
CDROM_TAG_STREAM);
perfDescriptor = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_CACHE_ALIGNED,
transferLength,
CDROM_TAG_STREAM);
if (perfDescriptor == NULL)
{
return;
Expand Down Expand Up @@ -2765,9 +2765,9 @@ Return Value:
PCDROM_REQUEST_CONTEXT requestContext = RequestGetContext(Request);
PKEVENT syncEvent = NULL;

syncEvent = ExAllocatePoolWithTag(NonPagedPoolNx,
sizeof(KEVENT),
CDROM_TAG_SYNC_EVENT);
syncEvent = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(KEVENT),
CDROM_TAG_SYNC_EVENT);

if (syncEvent == NULL)
{
Expand Down Expand Up @@ -3832,10 +3832,10 @@ Return Value:
// send request and check status

// Disable SDV warning about infinitely waiting in caller's context:
// 1. Some requests (such as SCSI_PASS_THROUGH, contains buffer from user space) need to be sent down in caller’s context.
// Consequently, these requests wait in caller’s context until they are allowed to be sent down.
// 1. Some requests (such as SCSI_PASS_THROUGH, contains buffer from user space) need to be sent down in caller’s context.
// Consequently, these requests wait in caller’s context until they are allowed to be sent down.
// 2. Considering the situation that during sleep, a request can be hold by storage port driver. When system resumes, any time out value (if we set using KMDF time out value) might be expires.
// This will cause the waiting request being failed (behavior change). We’d rather not set time out value.
// This will cause the waiting request being failed (behavior change). We’d rather not set time out value.

_Analysis_assume_(options.Timeout != 0);
requestSent = WdfRequestSend(Request, IoTarget, &options);
Expand Down
59 changes: 29 additions & 30 deletions storage/class/cdrom/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ Return Value:

// Save away the symbolic link name in the driver data block. We need
// it so we can delete the link when the device is removed.
savedName = ExAllocatePoolWithTag(PagedPool,
unicodeLinkName.MaximumLength,
CDROM_TAG_STRINGS);
savedName = ExAllocatePool2(POOL_FLAG_PAGED,
unicodeLinkName.MaximumLength,
CDROM_TAG_STRINGS);

if (savedName == NULL)
{
Expand Down Expand Up @@ -818,9 +818,9 @@ Return Value:
// allocate a private extension for class data
if (DeviceExtension->PrivateFdoData == NULL)
{
DeviceExtension->PrivateFdoData = ExAllocatePoolWithTag(NonPagedPoolNx,
sizeof(CDROM_PRIVATE_FDO_DATA),
CDROM_TAG_PRIVATE_DATA);
DeviceExtension->PrivateFdoData = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(CDROM_PRIVATE_FDO_DATA),
CDROM_TAG_PRIVATE_DATA);
}

if (DeviceExtension->PrivateFdoData == NULL)
Expand All @@ -834,9 +834,9 @@ Return Value:
}

// Allocate request sense buffer.
senseData = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned,
SENSE_BUFFER_SIZE,
CDROM_TAG_SENSE_INFO);
senseData = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_CACHE_ALIGNED,
SENSE_BUFFER_SIZE,
CDROM_TAG_SENSE_INFO);

if (senseData == NULL)
{
Expand Down Expand Up @@ -1068,7 +1068,7 @@ Return Value:
NT_ASSERT(bufferLength >= sizeof(STORAGE_PROPERTY_QUERY));
bufferLength = max(bufferLength, sizeof(STORAGE_PROPERTY_QUERY));

descriptor = ExAllocatePoolWithTag(NonPagedPoolNx, bufferLength, CDROM_TAG_DESCRIPTOR);
descriptor = ExAllocatePool2(POOL_FLAG_NON_PAGED, bufferLength, CDROM_TAG_DESCRIPTOR);

if(descriptor == NULL)
{
Expand Down Expand Up @@ -1795,9 +1795,9 @@ Return Value:
// from the PC-standard 2K to 512. Change the block transfer size
// back to the PC-standard 2K by using a mode select command.

modeParameters = ExAllocatePoolWithTag(NonPagedPoolNx,
sizeof(MODE_PARM_READ_WRITE_DATA),
CDROM_TAG_MODE_DATA);
modeParameters = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(MODE_PARM_READ_WRITE_DATA),
CDROM_TAG_MODE_DATA);
if (modeParameters == NULL)
{
return;
Expand Down Expand Up @@ -1919,9 +1919,9 @@ Return Value:
// 1. retrieve the inquiry data length

// 1.1 allocate inquiry data buffer
tmpInquiry = ExAllocatePoolWithTag(NonPagedPoolNx,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
tmpInquiry = ExAllocatePool2(POOL_FLAG_NON_PAGED,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
if (tmpInquiry == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
Expand Down Expand Up @@ -1987,9 +1987,9 @@ Return Value:
FREE_POOL(tmpInquiry);
RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));

tmpInquiry = ExAllocatePoolWithTag(NonPagedPoolNx,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
tmpInquiry = ExAllocatePool2(POOL_FLAG_NON_PAGED,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
if (tmpInquiry == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
Expand Down Expand Up @@ -2025,9 +2025,9 @@ Return Value:
FREE_POOL(tmpInquiry);
RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));

tmpInquiry = ExAllocatePoolWithTag(NonPagedPoolNx,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
tmpInquiry = ExAllocatePool2(POOL_FLAG_NON_PAGED,
requestedInquiryTransferBytes,
CDROM_TAG_INQUIRY);
if (tmpInquiry == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
Expand Down Expand Up @@ -2283,10 +2283,9 @@ Return Value:
ULONG featureSize = sizeof(GET_CONFIGURATION_HEADER)+sizeof(FEATURE_HEADER);
ULONG usable = 0;

PGET_CONFIGURATION_HEADER configBuffer = ExAllocatePoolWithTag(
NonPagedPoolNx,
featureSize,
CDROM_TAG_GET_CONFIG);
PGET_CONFIGURATION_HEADER configBuffer = ExAllocatePool2(POOL_FLAG_NON_PAGED,
featureSize,
CDROM_TAG_GET_CONFIG);

if (configBuffer == NULL)
{
Expand Down Expand Up @@ -2462,7 +2461,7 @@ Return Value:
// Set timeout value from device extension.
srb.TimeOutValue = DeviceExtension->TimeOutValue;

buffer = ExAllocatePoolWithTag(NonPagedPoolNx, bufferLength, CDROM_TAG_MODE_DATA);
buffer = ExAllocatePool2(POOL_FLAG_NON_PAGED, bufferLength, CDROM_TAG_MODE_DATA);

if (buffer == NULL)
{
Expand Down Expand Up @@ -2608,9 +2607,9 @@ Return Value:

// we got a DVD drive.
bufferLen = DVD_RPC_KEY_LENGTH;
copyProtectKey = (PDVD_COPY_PROTECT_KEY)ExAllocatePoolWithTag(PagedPool,
bufferLen,
DVD_TAG_RPC2_CHECK);
copyProtectKey = (PDVD_COPY_PROTECT_KEY)ExAllocatePool2(POOL_FLAG_PAGED,
bufferLen,
DVD_TAG_RPC2_CHECK);

if (copyProtectKey == NULL)
{
Expand Down
Loading

0 comments on commit cf17d8d

Please sign in to comment.