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

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