mirror of
https://github.com/acpica/acpica/
synced 2025-02-07 17:14:13 +03:00
Fixes for 64-bit alignment issues and buffer size calculations
This commit is contained in:
parent
71afc36184
commit
b6fc95599d
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Module Name: rscalc - Calculate stream and list lengths
|
||||
* $Revision: 1.74 $
|
||||
* $Revision: 1.75 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
@ -256,9 +256,11 @@ AcpiRsStreamOptionLength (
|
||||
StringLength = ResourceLength - MinimumAmlResourceLength - 1;
|
||||
}
|
||||
|
||||
/* Round up length to 32 bits for internal structure alignment */
|
||||
|
||||
return ((UINT32) ACPI_ROUND_UP_TO_32BIT (StringLength));
|
||||
/*
|
||||
* Round the length up to a multiple of the native word in order to
|
||||
* guarantee that the entire resource descriptor is native word aligned
|
||||
*/
|
||||
return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
|
||||
}
|
||||
|
||||
|
||||
@ -437,7 +439,7 @@ AcpiRsGetListLength (
|
||||
ACPI_STATUS Status;
|
||||
UINT8 *EndAml;
|
||||
UINT8 *Buffer;
|
||||
UINT32 BufferSize = 0;
|
||||
UINT32 BufferSize;
|
||||
UINT16 Temp16;
|
||||
UINT16 ResourceLength;
|
||||
UINT32 ExtraStructBytes;
|
||||
@ -448,6 +450,7 @@ AcpiRsGetListLength (
|
||||
ACPI_FUNCTION_TRACE ("RsGetListLength");
|
||||
|
||||
|
||||
*SizeNeeded = 0;
|
||||
EndAml = AmlBuffer + AmlBufferLength;
|
||||
|
||||
/* Walk the list of AML resource descriptors */
|
||||
@ -496,38 +499,30 @@ AcpiRsGetListLength (
|
||||
|
||||
|
||||
case ACPI_RESOURCE_NAME_VENDOR_SMALL:
|
||||
case ACPI_RESOURCE_NAME_VENDOR_LARGE:
|
||||
/*
|
||||
* Vendor Resource:
|
||||
* Ensure a 32-bit boundary for the structure
|
||||
* Get the number of vendor data bytes
|
||||
*/
|
||||
ExtraStructBytes = (UINT32)
|
||||
ACPI_ROUND_UP_TO_32BIT (ResourceLength) - ResourceLength;
|
||||
ExtraStructBytes = ResourceLength;
|
||||
break;
|
||||
|
||||
|
||||
case ACPI_RESOURCE_NAME_END_TAG:
|
||||
/*
|
||||
* End Tag: This is the normal exit, add size of EndTag
|
||||
* End Tag:
|
||||
* This is the normal exit, add size of EndTag
|
||||
*/
|
||||
*SizeNeeded = BufferSize + ACPI_RS_SIZE_MIN;
|
||||
*SizeNeeded += ACPI_RS_SIZE_MIN;
|
||||
return_ACPI_STATUS (AE_OK);
|
||||
|
||||
|
||||
case ACPI_RESOURCE_NAME_VENDOR_LARGE:
|
||||
/*
|
||||
* Vendor Resource:
|
||||
* Add vendor data and ensure a 32-bit boundary for the structure
|
||||
*/
|
||||
ExtraStructBytes = (UINT32)
|
||||
ACPI_ROUND_UP_TO_32BIT (ResourceLength) - ResourceLength;
|
||||
break;
|
||||
|
||||
|
||||
case ACPI_RESOURCE_NAME_ADDRESS32:
|
||||
case ACPI_RESOURCE_NAME_ADDRESS16:
|
||||
/*
|
||||
* 32-Bit or 16-bit Address Resource:
|
||||
* Add the size of any optional data (ResourceSource)
|
||||
case ACPI_RESOURCE_NAME_ADDRESS64:
|
||||
/*
|
||||
* Address Resource:
|
||||
* Add the size of the optional ResourceSource
|
||||
*/
|
||||
ExtraStructBytes = AcpiRsStreamOptionLength (
|
||||
ResourceLength, MinimumAmlResourceLength);
|
||||
@ -536,36 +531,17 @@ AcpiRsGetListLength (
|
||||
|
||||
case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
|
||||
/*
|
||||
* Extended IRQ:
|
||||
* Point past the InterruptVectorFlags to get the
|
||||
* InterruptTableLength.
|
||||
* Extended IRQ Resource:
|
||||
* Using the InterruptTableLength, add 4 bytes for each additional
|
||||
* interrupt. Note: at least one interrupt is required and is
|
||||
* included in the minimum descriptor size (reason for the -1)
|
||||
*/
|
||||
Buffer++;
|
||||
ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
|
||||
|
||||
/* Add the size of the optional ResourceSource */
|
||||
|
||||
ExtraStructBytes = (UINT32)
|
||||
/*
|
||||
* Add 4 bytes for each additional interrupt. Note: at
|
||||
* least one interrupt is required and is included in
|
||||
* the minimum descriptor size
|
||||
*/
|
||||
((*Buffer - 1) * sizeof (UINT32)) +
|
||||
|
||||
/* Add the size of any optional data (ResourceSource) */
|
||||
|
||||
AcpiRsStreamOptionLength (ResourceLength - ExtraStructBytes,
|
||||
MinimumAmlResourceLength);
|
||||
break;
|
||||
|
||||
|
||||
case ACPI_RESOURCE_NAME_ADDRESS64:
|
||||
/*
|
||||
* 64-Bit Address Resource:
|
||||
* Add the size of any optional data (ResourceSource)
|
||||
* Ensure a 64-bit boundary for the structure
|
||||
*/
|
||||
ExtraStructBytes = (UINT32)
|
||||
ACPI_ROUND_UP_TO_64BIT (AcpiRsStreamOptionLength (
|
||||
ResourceLength, MinimumAmlResourceLength));
|
||||
ExtraStructBytes += AcpiRsStreamOptionLength (
|
||||
ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
|
||||
break;
|
||||
|
||||
|
||||
@ -573,17 +549,28 @@ AcpiRsGetListLength (
|
||||
break;
|
||||
}
|
||||
|
||||
/* Update the required buffer size for the internal descriptor structs */
|
||||
/*
|
||||
* Update the required buffer size for the internal descriptor structs
|
||||
*
|
||||
* Important: Round the size up for the appropriate alignment. This
|
||||
* is a requirement on IA64.
|
||||
*/
|
||||
BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
|
||||
ExtraStructBytes;
|
||||
BufferSize = ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
|
||||
|
||||
Temp16 = (UINT16) (AcpiGbl_ResourceStructSizes[ResourceIndex] +
|
||||
ExtraStructBytes);
|
||||
BufferSize += (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (Temp16);
|
||||
*SizeNeeded += BufferSize;
|
||||
|
||||
ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
|
||||
"Type %.2X, Aml %.2X internal %.2X\n",
|
||||
AcpiUtGetResourceType (AmlBuffer),
|
||||
AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
|
||||
|
||||
/*
|
||||
* Point to the next resource within the stream
|
||||
* using the size of the header plus the length contained in the header
|
||||
* Point to the next resource within the AML stream using the length
|
||||
* contained in the resource descriptor header
|
||||
*/
|
||||
AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
|
||||
AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
|
||||
}
|
||||
|
||||
/* Did not find an EndTag resource descriptor */
|
||||
@ -720,7 +707,7 @@ AcpiRsGetPciRoutingTableLength (
|
||||
}
|
||||
|
||||
/*
|
||||
* Adding an extra element to the end of the list, essentially a
|
||||
* Add an extra element to the end of the list, essentially a
|
||||
* NULL terminator
|
||||
*/
|
||||
*BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Module Name: rslist - Linked list utilities
|
||||
* $Revision: 1.53 $
|
||||
* $Revision: 1.54 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
@ -160,6 +160,16 @@ AcpiRsConvertAmlToResources (
|
||||
|
||||
while (Aml < EndAml)
|
||||
{
|
||||
/*
|
||||
* Check that the input buffer and all subsequent pointers into it
|
||||
* are aligned on a native word boundary. Most important on IA64
|
||||
*/
|
||||
if (ACPI_IS_MISALIGNED (Resource))
|
||||
{
|
||||
ACPI_WARNING ((AE_INFO,
|
||||
"Misaligned resource pointer %p", Resource));
|
||||
}
|
||||
|
||||
/* Validate the Resource Type and Resource Length */
|
||||
|
||||
Status = AcpiUtValidateResource (Aml, &ResourceIndex);
|
||||
@ -180,6 +190,11 @@ AcpiRsConvertAmlToResources (
|
||||
return_ACPI_STATUS (Status);
|
||||
}
|
||||
|
||||
ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
|
||||
"Type %.2X, Aml %.2X internal %.2X\n",
|
||||
AcpiUtGetResourceType (Aml), AcpiUtGetDescriptorLength (Aml),
|
||||
Resource->Length));
|
||||
|
||||
/* Normal exit on completion of an EndTag resource descriptor */
|
||||
|
||||
if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Module Name: rsmisc - Miscellaneous resource descriptors
|
||||
* $Revision: 1.43 $
|
||||
* $Revision: 1.44 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
@ -163,7 +163,7 @@ AcpiRsConvertAmlToResource (
|
||||
UINT16 Temp16 = 0;
|
||||
|
||||
|
||||
ACPI_FUNCTION_TRACE ("RsGetResource");
|
||||
ACPI_FUNCTION_TRACE ("RsConvertAmlToResource");
|
||||
|
||||
|
||||
if (((ACPI_NATIVE_UINT) Resource) & 0x3)
|
||||
@ -397,9 +397,9 @@ AcpiRsConvertAmlToResource (
|
||||
Exit:
|
||||
if (!FlagsMode)
|
||||
{
|
||||
/* Round the resource struct length up to the next 32-bit boundary */
|
||||
/* Round the resource struct length up to the next boundary (32 or 64) */
|
||||
|
||||
Resource->Length = (UINT32) ACPI_ROUND_UP_TO_32BIT (Resource->Length);
|
||||
Resource->Length = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
|
||||
}
|
||||
return_ACPI_STATUS (AE_OK);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Module Name: rsutils - Utilities for the resource manager
|
||||
* $Revision: 1.58 $
|
||||
* $Revision: 1.59 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
@ -417,7 +417,8 @@ AcpiRsStrcpy (
|
||||
* StringPtr - (optional) where to store the actual
|
||||
* ResourceSource string
|
||||
*
|
||||
* RETURN: Length of the string plus NULL terminator, rounded up to 32 bit
|
||||
* RETURN: Length of the string plus NULL terminator, rounded up to native
|
||||
* word boundary
|
||||
*
|
||||
* DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
|
||||
* to an internal resource descriptor
|
||||
@ -467,15 +468,15 @@ AcpiRsGetResourceSource (
|
||||
}
|
||||
|
||||
/*
|
||||
* In order for the StructSize to fall on a 32-bit boundary, calculate
|
||||
* the length of the string (+1 for the NULL terminator) and expand the
|
||||
* StructSize to the next 32-bit boundary.
|
||||
* In order for the Resource length to be a multiple of the native
|
||||
* word, calculate the length of the string (+1 for NULL terminator)
|
||||
* and expand to the next word multiple.
|
||||
*
|
||||
* Zero the entire area of the buffer.
|
||||
*/
|
||||
TotalLength = (UINT32) ACPI_ROUND_UP_TO_32BIT (
|
||||
ACPI_STRLEN (ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1);
|
||||
|
||||
TotalLength = ACPI_STRLEN (ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
|
||||
TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
|
||||
|
||||
ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength);
|
||||
|
||||
/* Copy the ResourceSource string to the destination */
|
||||
|
Loading…
x
Reference in New Issue
Block a user