]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
Add validation on ACPI_S3_CONTEXT.S3DebugBufferAddress, moreover only debug tip could...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / X64 / SetIdtEntry.c
index 8c34993587507e872bbfc0ddedbc822d509ece32..40c27e4f678a4d646c3612f9ba1357919c9a4c31 100644 (file)
@@ -126,23 +126,24 @@ SetIdtEntry (
   //\r
   SetupCpuExceptionHandlers ();\r
 \r
-  //\r
-  // Update IDT entry INT3\r
-  //\r
-  IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));\r
-  S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);\r
-\r
-  IdtEntry->Offset15To0     = (UINT16)S3DebugBuffer;\r
-  IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();\r
-  IdtEntry->Attributes      = (UINT16)INTERRUPT_GATE_ATTRIBUTE;\r
-  IdtEntry->Offset31To16    = (UINT16)(S3DebugBuffer >> 16);\r
-  IdtEntry->Offset63To32    = (UINT32)(S3DebugBuffer >> 32);\r
-  IdtEntry->Reserved        = 0;\r
+  DEBUG_CODE (\r
+    //\r
+    // Update IDT entry INT3 if the instruction is valid in it\r
+    //\r
+    S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);\r
+    if (*(UINTN *)S3DebugBuffer != (UINTN) -1) {\r
+      IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));\r
+      IdtEntry->Offset15To0     = (UINT16)S3DebugBuffer;\r
+      IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();\r
+      IdtEntry->Attributes      = (UINT16)INTERRUPT_GATE_ATTRIBUTE;\r
+      IdtEntry->Offset31To16    = (UINT16)(S3DebugBuffer >> 16);\r
+      IdtEntry->Offset63To32    = (UINT32)(S3DebugBuffer >> 32);\r
+      IdtEntry->Reserved        = 0;\r
+    }\r
+  );\r
 \r
   IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (14 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));\r
   HookPageFaultHandler (IdtEntry);\r
-\r
-  AsmWriteIdtr (IdtDescriptor);\r
 }\r
 \r
 /**\r