]> git.pld-linux.org Git - packages/acpica.git/blob - 0002-Modify-utility-functions-to-be-endian-agnostic.patch
a32809642e9a63174b1ef99eb22acc5b6ee68009
[packages/acpica.git] / 0002-Modify-utility-functions-to-be-endian-agnostic.patch
1 From 51b0d06c0a6c4d4e19432ebf930299855c8fcf23 Mon Sep 17 00:00:00 2001
2 From: Al Stone <ahs3@redhat.com>
3 Date: Fri, 18 Sep 2020 15:14:30 -0600
4 Subject: [PATCH 02/45] Modify utility functions to be endian-agnostic
5
6 All of the modifications here use the big-endian code previously added
7 (see utendian.c) to make themselves endian-agnostic; i.e., that the code
8 does not need to change further to work on both big- and little-endian
9 machines.
10
11 These particular files were changed to handle the reading and writing
12 of files (the length is often embedded in the binary stream), and to
13 handle the reading and writing of integer values.  The common cases are
14 to "read" a 32-bit unsigned int in little-endian format, but convert it
15 to host-native, and to write a byte, word, double word or quad word value
16 as little-endian, regardless of host-native format.
17
18 Signed-off-by: Al Stone <ahs3@redhat.com>
19 ---
20  source/common/acfileio.c           | 16 ++++++++++------
21  source/common/dmtable.c            |  8 ++++----
22  source/compiler/dtfield.c          |  2 +-
23  source/compiler/dtsubtable.c       |  4 ++--
24  source/components/tables/tbprint.c | 13 +++++++++----
25  5 files changed, 26 insertions(+), 17 deletions(-)
26
27 Index: acpica-unix2-20220331/source/common/acfileio.c
28 ===================================================================
29 --- acpica-unix2-20220331.orig/source/common/acfileio.c
30 +++ acpica-unix2-20220331/source/common/acfileio.c
31 @@ -280,6 +280,7 @@ AcGetOneTableFromFile (
32      ACPI_TABLE_HEADER       *Table;
33      INT32                   Count;
34      long                    TableOffset;
35 +    UINT32                  Length;
36  
37  
38      *ReturnTable = NULL;
39 @@ -319,7 +320,8 @@ AcGetOneTableFromFile (
40  
41      /* Allocate a buffer for the entire table */
42  
43 -    Table = AcpiOsAllocate ((ACPI_SIZE) TableHeader.Length);
44 +    Length = AcpiUtReadUint32 (&TableHeader.Length);
45 +    Table = AcpiOsAllocate ((ACPI_SIZE) Length);
46      if (!Table)
47      {
48          return (AE_NO_MEMORY);
49 @@ -329,13 +331,13 @@ AcGetOneTableFromFile (
50  
51      fseek (File, TableOffset, SEEK_SET);
52  
53 -    Count = fread (Table, 1, TableHeader.Length, File);
54 +    Count = fread (Table, 1, Length, File);
55  
56      /*
57       * Checks for data table headers happen later in the execution. Only verify
58       * for Aml tables at this point in the code.
59       */
60 -    if (GetOnlyAmlTables && Count != (INT32) TableHeader.Length)
61 +    if (GetOnlyAmlTables && Count != (INT32) Length)
62      {
63          Status = AE_ERROR;
64          goto ErrorExit;
65 @@ -343,7 +345,7 @@ AcGetOneTableFromFile (
66  
67      /* Validate the checksum (just issue a warning) */
68  
69 -    Status = AcpiTbVerifyChecksum (Table, TableHeader.Length);
70 +    Status = AcpiTbVerifyChecksum (Table, Length);
71      if (ACPI_FAILURE (Status))
72      {
73          Status = AcCheckTextModeCorruption (Table);
74 @@ -436,6 +438,7 @@ AcValidateTableHeader (
75      long                    OriginalOffset;
76      UINT32                  FileSize;
77      UINT32                  i;
78 +    UINT32                  Length;
79  
80  
81      ACPI_FUNCTION_TRACE (AcValidateTableHeader);
82 @@ -472,11 +475,12 @@ AcValidateTableHeader (
83      /* Validate table length against bytes remaining in the file */
84  
85      FileSize = CmGetFileSize (File);
86 -    if (TableHeader.Length > (UINT32) (FileSize - TableOffset))
87 +    Length = AcpiUtReadUint32 (&TableHeader.Length);
88 +    if (Length > (UINT32) (FileSize - TableOffset))
89      {
90          fprintf (stderr, "Table [%4.4s] is too long for file - "
91              "needs: 0x%.2X, remaining in file: 0x%.2X\n",
92 -            TableHeader.Signature, TableHeader.Length,
93 +            TableHeader.Signature, Length,
94              (UINT32) (FileSize - TableOffset));
95          return (AE_BAD_HEADER);
96      }
97 Index: acpica-unix2-20220331/source/common/dmtable.c
98 ===================================================================
99 --- acpica-unix2-20220331.orig/source/common/dmtable.c
100 +++ acpica-unix2-20220331/source/common/dmtable.c
101 @@ -713,7 +713,7 @@ AcpiDmDumpDataTable (
102          {
103              /* Dump the raw table data */
104  
105 -            Length = Table->Length;
106 +            Length = AcpiUtReadUint32 (&Table->Length);
107  
108              AcpiOsPrintf ("\n/*\n%s: Length %d (0x%X)\n\n",
109                  ACPI_RAW_TABLE_DATA_HEADER, Length, Length);
110 @@ -730,7 +730,7 @@ AcpiDmDumpDataTable (
111       */
112      if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
113      {
114 -        Length = Table->Length;
115 +        Length = AcpiUtReadUint32 (&Table->Length);
116          Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoFacs);
117          if (ACPI_FAILURE (Status))
118          {
119 @@ -751,7 +751,7 @@ AcpiDmDumpDataTable (
120          /*
121           * All other tables must use the common ACPI table header, dump it now
122           */
123 -        Length = Table->Length;
124 +        Length = AcpiUtReadUint32(&Table->Length);
125          Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoHeader);
126          if (ACPI_FAILURE (Status))
127          {
128 @@ -1415,7 +1415,7 @@ AcpiDmDumpTable (
129  
130              AcpiOsPrintf ("%2.2X", *Target);
131              Temp8 = AcpiDmGenerateChecksum (Table,
132 -                ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length,
133 +                AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length)),
134                  ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum);
135  
136              if (Temp8 != ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum)
137 Index: acpica-unix2-20220331/source/compiler/dtfield.c
138 ===================================================================
139 --- acpica-unix2-20220331.orig/source/compiler/dtfield.c
140 +++ acpica-unix2-20220331/source/compiler/dtfield.c
141 @@ -361,7 +361,7 @@ DtCompileInteger (
142          DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, AslGbl_MsgBuffer);
143      }
144  
145 -    memcpy (Buffer, &Value, ByteLength);
146 +    AcpiUtWriteUint (Buffer, ByteLength, &Value, sizeof (UINT64));
147      return;
148  }
149  
150 Index: acpica-unix2-20220331/source/compiler/dtsubtable.c
151 ===================================================================
152 --- acpica-unix2-20220331.orig/source/compiler/dtsubtable.c
153 +++ acpica-unix2-20220331/source/compiler/dtsubtable.c
154 @@ -378,6 +378,6 @@ DtSetSubtableLength (
155          return;
156      }
157  
158 -    memcpy (Subtable->LengthField, &Subtable->TotalLength,
159 -        Subtable->SizeOfLengthField);
160 +    AcpiUtWriteUint (Subtable->LengthField, Subtable->SizeOfLengthField,
161 +                     &Subtable->TotalLength, sizeof (Subtable->TotalLength));
162  }
163 Index: acpica-unix2-20220331/source/components/tables/tbprint.c
164 ===================================================================
165 --- acpica-unix2-20220331.orig/source/components/tables/tbprint.c
166 +++ acpica-unix2-20220331/source/components/tables/tbprint.c
167 @@ -44,6 +44,8 @@
168  #include "acpi.h"
169  #include "accommon.h"
170  #include "actables.h"
171 +#include "platform/acenv.h"
172 +#include "acutils.h"
173  
174  #define _COMPONENT          ACPI_TABLES
175          ACPI_MODULE_NAME    ("tbprint")
176 @@ -151,7 +153,7 @@ AcpiTbPrintTableHeader (
177  
178          ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
179              Header->Signature, ACPI_FORMAT_UINT64 (Address),
180 -            Header->Length));
181 +            AcpiUtReadUint32 (&Header->Length)));
182      }
183      else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
184          Header)->Signature))
185 @@ -179,9 +181,12 @@ AcpiTbPrintTableHeader (
186              "%-4.4s 0x%8.8X%8.8X"
187              " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
188              LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address),
189 -            LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
190 -            LocalHeader.OemTableId, LocalHeader.OemRevision,
191 -            LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
192 +            AcpiUtReadUint32 (&LocalHeader.Length),
193 +            LocalHeader.Revision, LocalHeader.OemId,
194 +            LocalHeader.OemTableId,
195 +            AcpiUtReadUint32 (&LocalHeader.OemRevision),
196 +            LocalHeader.AslCompilerId,
197 +            AcpiUtReadUint32 (&LocalHeader.AslCompilerRevision)));
198      }
199  }
200  
This page took 0.038574 seconds and 3 git commands to generate.