]> git.pld-linux.org Git - packages/acpica.git/blob - 0002-Modify-utility-functions-to-be-endian-agnostic.patch
- initial update to 20221020
[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 --- 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 (
30       */
31      if (AcpiGbl_CDAT)
32      {
33 -        TableLength = ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader)->Length;
34 +        TableLength = AcpiUtReadUint32(&(ACPI_CAST_PTR (ACPI_TABLE_CDAT, &TableHeader)->Length));
35      }
36      else
37      {
38 -        TableLength = TableHeader.Length;
39 +        TableLength = AcpiUtReadUint32(&TableHeader.Length);
40      }
41  
42      /* Allocate a buffer for the entire table */
43 @@ -474,6 +474,7 @@ AcValidateTableHeader (
44      long                    OriginalOffset;
45      UINT32                  FileSize;
46      UINT32                  i;
47 +    UINT32                  Length;
48  
49  
50      ACPI_FUNCTION_TRACE (AcValidateTableHeader);
51 @@ -537,25 +538,30 @@ AcValidateTableHeader (
52      {
53          /* Standard ACPI table header */
54  
55 -        if (TableHeader.Length > (UINT32) (FileSize - TableOffset))
56 +        Length = AcpiUtReadUint32 (&TableHeader.Length);
57 +        if (Length > (UINT32) (FileSize - TableOffset))
58          {
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);
65          }
66      }
67 -    else if (CdatTableHeader->Length > (UINT32) (FileSize - TableOffset))
68 +    else
69 +    {
70 +    Length = AcpiUtReadUint32 (&CdatTableHeader->Length);
71 +    if (Length > (UINT32) (FileSize - TableOffset))
72      {
73          /* Special header for CDAT table */
74  
75          fprintf (stderr, "Table [CDAT] is too long for file - "
76              "needs: 0x%.2X, remaining in file: 0x%.2X\n",
77 -            CdatTableHeader->Length,
78 +            Length,
79              (UINT32) (FileSize - TableOffset));
80          return (AE_BAD_HEADER);
81      }
82 +    }
83  
84      /* For CDAT table, there are no ASCII fields in the header, we are done */
85  
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 (
89          {
90              /* Dump the raw table data */
91  
92 -            Length = Table->Length;
93 +            Length = AcpiUtReadUint32 (&Table->Length);
94  
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 (
98       */
99      if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
100      {
101 -        Length = Table->Length;
102 +        Length = AcpiUtReadUint32 (&Table->Length);
103          Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoFacs);
104          if (ACPI_FAILURE (Status))
105          {
106 @@ -755,7 +755,7 @@ AcpiDmDumpDataTable (
107          /*
108           * All other tables must use the common ACPI table header, dump it now
109           */
110 -        Length = Table->Length;
111 +        Length = AcpiUtReadUint32(&Table->Length);
112          Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoHeader);
113          if (ACPI_FAILURE (Status))
114          {
115 @@ -1146,7 +1146,7 @@ AcpiDmDumpTable (
116               *          Start of the vendor data (Target)
117               */
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));
122              break;
123  
124 @@ -1421,7 +1421,7 @@ AcpiDmDumpTable (
125  
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);
131  
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);
139      }
140  
141 -    memcpy (Buffer, &Value, ByteLength);
142 +    AcpiUtWriteUint (Buffer, ByteLength, &Value, sizeof (UINT64));
143      return;
144  }
145  
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 (
151          return;
152      }
153  
154 -    memcpy (Subtable->LengthField, &Subtable->TotalLength,
155 -        Subtable->SizeOfLengthField);
156 +    AcpiUtWriteUint (Subtable->LengthField, Subtable->SizeOfLengthField,
157 +                     &Subtable->TotalLength, sizeof (Subtable->TotalLength));
158  }
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
161 @@ -46,6 +46,7 @@
162  #include "actables.h"
163  #include "acdisasm.h"
164  #include "acutils.h"
165 +#include "platform/acenv.h"
166  
167  #define _COMPONENT          ACPI_TABLES
168          ACPI_MODULE_NAME    ("tbprint")
169 @@ -153,7 +154,7 @@ AcpiTbPrintTableHeader (
170  
171          ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
172              Header->Signature, ACPI_FORMAT_UINT64 (Address),
173 -            Header->Length));
174 +            AcpiUtReadUint32 (&Header->Length)));
175      }
176      else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
177          Header)->Signature))
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,
185              LocalHeader.OemId));
186      }
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)));
200      }
201  }
202  
This page took 0.047658 seconds and 3 git commands to generate.