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
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
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.
18 Signed-off-by: Al Stone <ahs3@redhat.com>
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(-)
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;
39 @@ -319,7 +320,8 @@ AcGetOneTableFromFile (
41 /* Allocate a buffer for the entire table */
43 - Table = AcpiOsAllocate ((ACPI_SIZE) TableHeader.Length);
44 + Length = AcpiUtReadUint32 (&TableHeader.Length);
45 + Table = AcpiOsAllocate ((ACPI_SIZE) Length);
48 return (AE_NO_MEMORY);
49 @@ -329,13 +331,13 @@ AcGetOneTableFromFile (
51 fseek (File, TableOffset, SEEK_SET);
53 - Count = fread (Table, 1, TableHeader.Length, File);
54 + Count = fread (Table, 1, Length, File);
57 * Checks for data table headers happen later in the execution. Only verify
58 * for Aml tables at this point in the code.
60 - if (GetOnlyAmlTables && Count != (INT32) TableHeader.Length)
61 + if (GetOnlyAmlTables && Count != (INT32) Length)
65 @@ -343,7 +345,7 @@ AcGetOneTableFromFile (
67 /* Validate the checksum (just issue a warning) */
69 - Status = AcpiTbVerifyChecksum (Table, TableHeader.Length);
70 + Status = AcpiTbVerifyChecksum (Table, Length);
71 if (ACPI_FAILURE (Status))
73 Status = AcCheckTextModeCorruption (Table);
74 @@ -436,6 +438,7 @@ AcValidateTableHeader (
81 ACPI_FUNCTION_TRACE (AcValidateTableHeader);
82 @@ -472,11 +475,12 @@ AcValidateTableHeader (
83 /* Validate table length against bytes remaining in the file */
85 FileSize = CmGetFileSize (File);
86 - if (TableHeader.Length > (UINT32) (FileSize - TableOffset))
87 + Length = AcpiUtReadUint32 (&TableHeader.Length);
88 + if (Length > (UINT32) (FileSize - TableOffset))
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);
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 (
103 /* Dump the raw table data */
105 - Length = Table->Length;
106 + Length = AcpiUtReadUint32 (&Table->Length);
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 (
112 if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
114 - Length = Table->Length;
115 + Length = AcpiUtReadUint32 (&Table->Length);
116 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoFacs);
117 if (ACPI_FAILURE (Status))
119 @@ -751,7 +751,7 @@ AcpiDmDumpDataTable (
121 * All other tables must use the common ACPI table header, dump it now
123 - Length = Table->Length;
124 + Length = AcpiUtReadUint32(&Table->Length);
125 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoHeader);
126 if (ACPI_FAILURE (Status))
128 @@ -1415,7 +1415,7 @@ AcpiDmDumpTable (
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);
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);
145 - memcpy (Buffer, &Value, ByteLength);
146 + AcpiUtWriteUint (Buffer, ByteLength, &Value, sizeof (UINT64));
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 (
158 - memcpy (Subtable->LengthField, &Subtable->TotalLength,
159 - Subtable->SizeOfLengthField);
160 + AcpiUtWriteUint (Subtable->LengthField, Subtable->SizeOfLengthField,
161 + &Subtable->TotalLength, sizeof (Subtable->TotalLength));
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
169 #include "accommon.h"
170 #include "actables.h"
171 +#include "platform/acenv.h"
172 +#include "acutils.h"
174 #define _COMPONENT ACPI_TABLES
175 ACPI_MODULE_NAME ("tbprint")
176 @@ -151,7 +153,7 @@ AcpiTbPrintTableHeader (
178 ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
179 Header->Signature, ACPI_FORMAT_UINT64 (Address),
181 + AcpiUtReadUint32 (&Header->Length)));
183 else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
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)));