|
|
214d7a |
From 51b0d06c0a6c4d4e19432ebf930299855c8fcf23 Mon Sep 17 00:00:00 2001
|
|
|
214d7a |
From: Al Stone <ahs3@redhat.com>
|
|
|
214d7a |
Date: Fri, 18 Sep 2020 15:14:30 -0600
|
|
|
214d7a |
Subject: [PATCH 02/45] Modify utility functions to be endian-agnostic
|
|
|
214d7a |
|
|
|
214d7a |
All of the modifications here use the big-endian code previously added
|
|
|
214d7a |
(see utendian.c) to make themselves endian-agnostic; i.e., that the code
|
|
|
214d7a |
does not need to change further to work on both big- and little-endian
|
|
|
214d7a |
machines.
|
|
|
214d7a |
|
|
|
214d7a |
These particular files were changed to handle the reading and writing
|
|
|
214d7a |
of files (the length is often embedded in the binary stream), and to
|
|
|
214d7a |
handle the reading and writing of integer values. The common cases are
|
|
|
214d7a |
to "read" a 32-bit unsigned int in little-endian format, but convert it
|
|
|
214d7a |
to host-native, and to write a byte, word, double word or quad word value
|
|
|
214d7a |
as little-endian, regardless of host-native format.
|
|
|
214d7a |
|
|
|
214d7a |
Signed-off-by: Al Stone <ahs3@redhat.com>
|
|
|
214d7a |
---
|
|
|
214d7a |
source/common/acfileio.c | 16 ++++++++++------
|
|
|
214d7a |
source/common/dmtable.c | 8 ++++----
|
|
|
214d7a |
source/compiler/dtfield.c | 2 +-
|
|
|
214d7a |
source/compiler/dtsubtable.c | 4 ++--
|
|
|
214d7a |
source/components/tables/tbprint.c | 13 +++++++++----
|
|
|
214d7a |
5 files changed, 26 insertions(+), 17 deletions(-)
|
|
|
214d7a |
|
|
|
214d7a |
Index: acpica-unix2-20210604/source/common/acfileio.c
|
|
|
214d7a |
===================================================================
|
|
|
214d7a |
--- acpica-unix2-20210604.orig/source/common/acfileio.c
|
|
|
214d7a |
+++ acpica-unix2-20210604/source/common/acfileio.c
|
|
|
214d7a |
@@ -280,6 +280,7 @@ AcGetOneTableFromFile (
|
|
|
214d7a |
ACPI_TABLE_HEADER *Table;
|
|
|
214d7a |
INT32 Count;
|
|
|
214d7a |
long TableOffset;
|
|
|
214d7a |
+ UINT32 Length;
|
|
|
214d7a |
|
|
|
214d7a |
|
|
|
214d7a |
*ReturnTable = NULL;
|
|
|
214d7a |
@@ -319,7 +320,8 @@ AcGetOneTableFromFile (
|
|
|
214d7a |
|
|
|
214d7a |
/* Allocate a buffer for the entire table */
|
|
|
214d7a |
|
|
|
214d7a |
- Table = AcpiOsAllocate ((ACPI_SIZE) TableHeader.Length);
|
|
|
214d7a |
+ Length = AcpiUtReadUint32 (&TableHeader.Length);
|
|
|
214d7a |
+ Table = AcpiOsAllocate ((ACPI_SIZE) Length);
|
|
|
214d7a |
if (!Table)
|
|
|
214d7a |
{
|
|
|
214d7a |
return (AE_NO_MEMORY);
|
|
|
214d7a |
@@ -329,13 +331,13 @@ AcGetOneTableFromFile (
|
|
|
214d7a |
|
|
|
214d7a |
fseek (File, TableOffset, SEEK_SET);
|
|
|
214d7a |
|
|
|
214d7a |
- Count = fread (Table, 1, TableHeader.Length, File);
|
|
|
214d7a |
+ Count = fread (Table, 1, Length, File);
|
|
|
214d7a |
|
|
|
214d7a |
/*
|
|
|
214d7a |
* Checks for data table headers happen later in the execution. Only verify
|
|
|
214d7a |
* for Aml tables at this point in the code.
|
|
|
214d7a |
*/
|
|
|
214d7a |
- if (GetOnlyAmlTables && Count != (INT32) TableHeader.Length)
|
|
|
214d7a |
+ if (GetOnlyAmlTables && Count != (INT32) Length)
|
|
|
214d7a |
{
|
|
|
214d7a |
Status = AE_ERROR;
|
|
|
214d7a |
goto ErrorExit;
|
|
|
214d7a |
@@ -343,7 +345,7 @@ AcGetOneTableFromFile (
|
|
|
214d7a |
|
|
|
214d7a |
/* Validate the checksum (just issue a warning) */
|
|
|
214d7a |
|
|
|
214d7a |
- Status = AcpiTbVerifyChecksum (Table, TableHeader.Length);
|
|
|
214d7a |
+ Status = AcpiTbVerifyChecksum (Table, Length);
|
|
|
214d7a |
if (ACPI_FAILURE (Status))
|
|
|
214d7a |
{
|
|
|
214d7a |
Status = AcCheckTextModeCorruption (Table);
|
|
|
214d7a |
@@ -436,6 +438,7 @@ AcValidateTableHeader (
|
|
|
214d7a |
long OriginalOffset;
|
|
|
214d7a |
UINT32 FileSize;
|
|
|
214d7a |
UINT32 i;
|
|
|
214d7a |
+ UINT32 Length;
|
|
|
214d7a |
|
|
|
214d7a |
|
|
|
214d7a |
ACPI_FUNCTION_TRACE (AcValidateTableHeader);
|
|
|
214d7a |
@@ -467,11 +470,12 @@ AcValidateTableHeader (
|
|
|
214d7a |
/* Validate table length against bytes remaining in the file */
|
|
|
214d7a |
|
|
|
214d7a |
FileSize = CmGetFileSize (File);
|
|
|
214d7a |
- if (TableHeader.Length > (UINT32) (FileSize - TableOffset))
|
|
|
214d7a |
+ Length = AcpiUtReadUint32 (&TableHeader.Length);
|
|
|
214d7a |
+ if (Length > (UINT32) (FileSize - TableOffset))
|
|
|
214d7a |
{
|
|
|
214d7a |
fprintf (stderr, "Table [%4.4s] is too long for file - "
|
|
|
214d7a |
"needs: 0x%.2X, remaining in file: 0x%.2X\n",
|
|
|
214d7a |
- TableHeader.Signature, TableHeader.Length,
|
|
|
214d7a |
+ TableHeader.Signature, Length,
|
|
|
214d7a |
(UINT32) (FileSize - TableOffset));
|
|
|
214d7a |
return (AE_BAD_HEADER);
|
|
|
214d7a |
}
|
|
|
214d7a |
Index: acpica-unix2-20210604/source/common/dmtable.c
|
|
|
214d7a |
===================================================================
|
|
|
214d7a |
--- acpica-unix2-20210604.orig/source/common/dmtable.c
|
|
|
214d7a |
+++ acpica-unix2-20210604/source/common/dmtable.c
|
|
|
214d7a |
@@ -591,7 +591,7 @@ AcpiDmDumpDataTable (
|
|
|
214d7a |
{
|
|
|
214d7a |
/* Dump the raw table data */
|
|
|
214d7a |
|
|
|
214d7a |
- Length = Table->Length;
|
|
|
214d7a |
+ Length = AcpiUtReadUint32 (&Table->Length);
|
|
|
214d7a |
|
|
|
214d7a |
AcpiOsPrintf ("\n/*\n%s: Length %d (0x%X)\n\n",
|
|
|
214d7a |
ACPI_RAW_TABLE_DATA_HEADER, Length, Length);
|
|
|
214d7a |
@@ -608,7 +608,7 @@ AcpiDmDumpDataTable (
|
|
|
214d7a |
*/
|
|
|
214d7a |
if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
|
|
|
214d7a |
{
|
|
|
214d7a |
- Length = Table->Length;
|
|
|
214d7a |
+ Length = AcpiUtReadUint32 (&Table->Length);
|
|
|
214d7a |
Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoFacs);
|
|
|
214d7a |
if (ACPI_FAILURE (Status))
|
|
|
214d7a |
{
|
|
|
214d7a |
@@ -628,7 +628,7 @@ AcpiDmDumpDataTable (
|
|
|
214d7a |
/*
|
|
|
214d7a |
* All other tables must use the common ACPI table header, dump it now
|
|
|
214d7a |
*/
|
|
|
214d7a |
- Length = Table->Length;
|
|
|
214d7a |
+ Length = AcpiUtReadUint32(&Table->Length);
|
|
|
214d7a |
Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoHeader);
|
|
|
214d7a |
if (ACPI_FAILURE (Status))
|
|
|
214d7a |
{
|
|
|
214d7a |
@@ -1262,7 +1262,7 @@ AcpiDmDumpTable (
|
|
|
214d7a |
|
|
|
214d7a |
AcpiOsPrintf ("%2.2X", *Target);
|
|
|
214d7a |
Temp8 = AcpiDmGenerateChecksum (Table,
|
|
|
214d7a |
- ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length,
|
|
|
214d7a |
+ AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length)),
|
|
|
214d7a |
ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum);
|
|
|
214d7a |
|
|
|
214d7a |
if (Temp8 != ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum)
|
|
|
214d7a |
Index: acpica-unix2-20210604/source/compiler/dtfield.c
|
|
|
214d7a |
===================================================================
|
|
|
214d7a |
--- acpica-unix2-20210604.orig/source/compiler/dtfield.c
|
|
|
214d7a |
+++ acpica-unix2-20210604/source/compiler/dtfield.c
|
|
|
214d7a |
@@ -361,7 +361,7 @@ DtCompileInteger (
|
|
|
214d7a |
DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, AslGbl_MsgBuffer);
|
|
|
214d7a |
}
|
|
|
214d7a |
|
|
|
214d7a |
- memcpy (Buffer, &Value, ByteLength);
|
|
|
214d7a |
+ AcpiUtWriteUint (Buffer, ByteLength, &Value, sizeof (UINT64));
|
|
|
214d7a |
return;
|
|
|
214d7a |
}
|
|
|
214d7a |
|
|
|
214d7a |
Index: acpica-unix2-20210604/source/compiler/dtsubtable.c
|
|
|
214d7a |
===================================================================
|
|
|
214d7a |
--- acpica-unix2-20210604.orig/source/compiler/dtsubtable.c
|
|
|
214d7a |
+++ acpica-unix2-20210604/source/compiler/dtsubtable.c
|
|
|
214d7a |
@@ -378,6 +378,6 @@ DtSetSubtableLength (
|
|
|
214d7a |
return;
|
|
|
214d7a |
}
|
|
|
214d7a |
|
|
|
214d7a |
- memcpy (Subtable->LengthField, &Subtable->TotalLength,
|
|
|
214d7a |
- Subtable->SizeOfLengthField);
|
|
|
214d7a |
+ AcpiUtWriteUint (Subtable->LengthField, Subtable->SizeOfLengthField,
|
|
|
214d7a |
+ &Subtable->TotalLength, sizeof (Subtable->TotalLength));
|
|
|
214d7a |
}
|
|
|
214d7a |
Index: acpica-unix2-20210604/source/components/tables/tbprint.c
|
|
|
214d7a |
===================================================================
|
|
|
214d7a |
--- acpica-unix2-20210604.orig/source/components/tables/tbprint.c
|
|
|
214d7a |
+++ acpica-unix2-20210604/source/components/tables/tbprint.c
|
|
|
214d7a |
@@ -44,6 +44,8 @@
|
|
|
214d7a |
#include "acpi.h"
|
|
|
214d7a |
#include "accommon.h"
|
|
|
214d7a |
#include "actables.h"
|
|
|
214d7a |
+#include "platform/acenv.h"
|
|
|
214d7a |
+#include "acutils.h"
|
|
|
214d7a |
|
|
|
214d7a |
#define _COMPONENT ACPI_TABLES
|
|
|
214d7a |
ACPI_MODULE_NAME ("tbprint")
|
|
|
214d7a |
@@ -151,7 +153,7 @@ AcpiTbPrintTableHeader (
|
|
|
214d7a |
|
|
|
214d7a |
ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
|
|
|
214d7a |
Header->Signature, ACPI_FORMAT_UINT64 (Address),
|
|
|
214d7a |
- Header->Length));
|
|
|
214d7a |
+ AcpiUtReadUint32 (&Header->Length)));
|
|
|
214d7a |
}
|
|
|
214d7a |
else if (ACPI_VALIDATE_RSDP_SIG (Header->Signature))
|
|
|
214d7a |
{
|
|
|
214d7a |
@@ -178,9 +180,12 @@ AcpiTbPrintTableHeader (
|
|
|
214d7a |
"%-4.4s 0x%8.8X%8.8X"
|
|
|
214d7a |
" %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
|
|
|
214d7a |
LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address),
|
|
|
214d7a |
- LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
|
|
|
214d7a |
- LocalHeader.OemTableId, LocalHeader.OemRevision,
|
|
|
214d7a |
- LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
|
|
|
214d7a |
+ AcpiUtReadUint32 (&LocalHeader.Length),
|
|
|
214d7a |
+ LocalHeader.Revision, LocalHeader.OemId,
|
|
|
214d7a |
+ LocalHeader.OemTableId,
|
|
|
214d7a |
+ AcpiUtReadUint32 (&LocalHeader.OemRevision),
|
|
|
214d7a |
+ LocalHeader.AslCompilerId,
|
|
|
214d7a |
+ AcpiUtReadUint32 (&LocalHeader.AslCompilerRevision)));
|
|
|
214d7a |
}
|
|
|
214d7a |
}
|
|
|
214d7a |
|