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 --- acpica-unix2-20221020/source/common/acfileio.c.orig 2022-10-20 23:17:29.000000000 +0200
28 +++ acpica-unix2-20221020/source/common/acfileio.c 2023-07-01 21:29:48.697091987 +0200
29 @@ -337,11 +337,11 @@ AcGetOneTableFromFile (
33 - TableLength = ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader)->Length;
34 + TableLength = AcpiUtReadUint32(&(ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader)->Length));
38 - TableLength = TableHeader.Length;
39 + TableLength = AcpiUtReadUint32(&TableHeader.Length);
42 /* Allocate a buffer for the entire table */
43 @@ -474,6 +474,7 @@ AcValidateTableHeader (
50 ACPI_FUNCTION_TRACE (AcValidateTableHeader);
51 @@ -537,25 +538,30 @@ AcValidateTableHeader (
53 /* Standard ACPI table header */
55 - if (TableHeader.Length > (UINT32) (FileSize - TableOffset))
56 + Length = AcpiUtReadUint32 (&TableHeader.Length);
57 + if (Length > (UINT32) (FileSize - TableOffset))
59 fprintf (stderr, "Table [%4.4s] is too long for file - "
60 "needs: 0x%.2X, remaining in file: 0x%.2X\n",
61 - TableHeader.Signature, TableHeader.Length,
62 + TableHeader.Signature, Length,
63 (UINT32) (FileSize - TableOffset));
64 return (AE_BAD_HEADER);
67 - else if (CdatTableHeader->Length > (UINT32) (FileSize - TableOffset))
70 + Length = AcpiUtReadUint32 (&CdatTableHeader->Length);
71 + if (Length > (UINT32) (FileSize - TableOffset))
73 /* Special header for CDAT table */
75 fprintf (stderr, "Table [CDAT] is too long for file - "
76 "needs: 0x%.2X, remaining in file: 0x%.2X\n",
77 - CdatTableHeader->Length,
79 (UINT32) (FileSize - TableOffset));
80 return (AE_BAD_HEADER);
84 /* For CDAT table, there are no ASCII fields in the header, we are done */
86 --- acpica-unix2-20221020/source/common/dmtable.c.orig 2022-10-20 23:17:29.000000000 +0200
87 +++ acpica-unix2-20221020/source/common/dmtable.c 2023-07-01 21:33:40.842501014 +0200
88 @@ -695,7 +695,7 @@ AcpiDmDumpDataTable (
90 /* Dump the raw table data */
92 - Length = Table->Length;
93 + Length = AcpiUtReadUint32 (&Table->Length);
95 AcpiOsPrintf ("\n/*\n%s: Length %d (0x%X)\n\n",
96 ACPI_RAW_TABLE_DATA_HEADER, Length, Length);
97 @@ -712,7 +712,7 @@ AcpiDmDumpDataTable (
99 if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
101 - Length = Table->Length;
102 + Length = AcpiUtReadUint32 (&Table->Length);
103 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoFacs);
104 if (ACPI_FAILURE (Status))
106 @@ -755,7 +755,7 @@ AcpiDmDumpDataTable (
108 * All other tables must use the common ACPI table header, dump it now
110 - Length = Table->Length;
111 + Length = AcpiUtReadUint32(&Table->Length);
112 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoHeader);
113 if (ACPI_FAILURE (Status))
115 @@ -1146,7 +1146,7 @@ AcpiDmDumpTable (
116 * Start of the vendor data (Target)
118 ByteLength = ((ACPI_CAST_PTR (char, Table) +
119 - (ACPI_CAST_PTR (ACPI_PMTT_HEADER, Table)->Length)) -
120 + AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_PMTT_HEADER, Table)->Length))) -
121 ACPI_CAST_PTR (char, Target));
124 @@ -1421,7 +1421,7 @@ AcpiDmDumpTable (
126 AcpiOsPrintf ("%2.2X", *Target);
127 Temp8 = AcpiUtGenerateChecksum (Table,
128 - ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length,
129 + AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Length)),
130 ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum);
132 if (Temp8 != ACPI_CAST_PTR (ACPI_TABLE_HEADER, Table)->Checksum)
133 Index: acpica-unix2-20220331/source/compiler/dtfield.c
134 ===================================================================
135 --- acpica-unix2-20220331.orig/source/compiler/dtfield.c
136 +++ acpica-unix2-20220331/source/compiler/dtfield.c
137 @@ -361,7 +361,7 @@ DtCompileInteger (
138 DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, AslGbl_MsgBuffer);
141 - memcpy (Buffer, &Value, ByteLength);
142 + AcpiUtWriteUint (Buffer, ByteLength, &Value, sizeof (UINT64));
146 Index: acpica-unix2-20220331/source/compiler/dtsubtable.c
147 ===================================================================
148 --- acpica-unix2-20220331.orig/source/compiler/dtsubtable.c
149 +++ acpica-unix2-20220331/source/compiler/dtsubtable.c
150 @@ -378,6 +378,6 @@ DtSetSubtableLength (
154 - memcpy (Subtable->LengthField, &Subtable->TotalLength,
155 - Subtable->SizeOfLengthField);
156 + AcpiUtWriteUint (Subtable->LengthField, Subtable->SizeOfLengthField,
157 + &Subtable->TotalLength, sizeof (Subtable->TotalLength));
159 --- acpica-unix2-20221020/source/components/tables/tbprint.c.orig 2022-10-20 23:17:32.000000000 +0200
160 +++ acpica-unix2-20221020/source/components/tables/tbprint.c 2023-07-01 21:41:53.759830651 +0200
162 #include "actables.h"
163 #include "acdisasm.h"
165 +#include "platform/acenv.h"
167 #define _COMPONENT ACPI_TABLES
168 ACPI_MODULE_NAME ("tbprint")
169 @@ -153,7 +154,7 @@ AcpiTbPrintTableHeader (
171 ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
172 Header->Signature, ACPI_FORMAT_UINT64 (Address),
174 + AcpiUtReadUint32 (&Header->Length)));
176 else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
178 @@ -167,7 +168,7 @@ AcpiTbPrintTableHeader (
179 ACPI_INFO (("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
180 ACPI_FORMAT_UINT64 (Address),
181 (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
182 - ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
183 + AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length)) : 20,
184 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
187 @@ -181,9 +182,12 @@ AcpiTbPrintTableHeader (
188 "%-4.4s 0x%8.8X%8.8X"
189 " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
190 LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address),
191 - LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
192 - LocalHeader.OemTableId, LocalHeader.OemRevision,
193 - LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
194 + AcpiUtReadUint32 (&LocalHeader.Length),
195 + LocalHeader.Revision, LocalHeader.OemId,
196 + LocalHeader.OemTableId,
197 + AcpiUtReadUint32 (&LocalHeader.OemRevision),
198 + LocalHeader.AslCompilerId,
199 + AcpiUtReadUint32 (&LocalHeader.AslCompilerRevision)));