Blame 0002-Modify-utility-functions-to-be-endian-agnostic.patch

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