]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.c
Allocate memory in DebugSupport beforehand, in order to avoid calling memory allocati...
[mirror_edk2.git] / EdkModulePkg / Universal / DebugSupport / Dxe / x64 / plDebugSupport.c
index 6fb4cdb542157091ba1c9dd63f50c319730519eb..8b907ee6e144d085bee2271ac1a75c315907651d 100644 (file)
@@ -1,14 +1,14 @@
 /**@file\r
   X64 specific debug support functions\r
 \r
-Copyright (c) 2006 Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -46,39 +46,30 @@ Returns:
 {\r
   UINT8       *StubCopy;\r
 \r
+  StubCopy = *Stub;\r
+\r
   //\r
-  // First, allocate a new buffer and copy the stub code into it\r
+  // Fixup the stub code for this vector\r
   //\r
-  *Stub = AllocatePool (StubSize);\r
-  if (*Stub != NULL) {\r
-    StubCopy = *Stub;\r
-    CopyMem (StubCopy, InterruptEntryStub, StubSize);\r
-\r
-    //\r
-    // Next fixup the stub code for this vector\r
-    //\r
 \r
-    // The stub code looks like this:\r
-    //\r
-    //    00000000  6A 00               push    0                       ; push vector number - will be modified before installed\r
-    //    00000002  E9                  db      0e9h                    ; jump rel32\r
-    //    00000003  00000000            dd      0                       ; fixed up to relative address of CommonIdtEntry\r
-    //\r
+  // The stub code looks like this:\r
+  //\r
+  //    00000000  6A 00               push    0                       ; push vector number - will be modified before installed\r
+  //    00000002  E9                  db      0e9h                    ; jump rel32\r
+  //    00000003  00000000            dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+  //\r
 \r
-    //\r
-    // poke in the exception type so the second push pushes the exception type\r
-    //\r
-    StubCopy[0x1] = (UINT8) ExceptionType;\r
+  //\r
+  // poke in the exception type so the second push pushes the exception type\r
+  //\r
+  StubCopy[0x1] = (UINT8) ExceptionType;\r
 \r
-    //\r
-    // fixup the jump target to point to the common entry\r
-    //\r
-    *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
-    \r
-    return EFI_SUCCESS;\r
-  }\r
+  //\r
+  // fixup the jump target to point to the common entry\r
+  //\r
+  *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
 \r
-  return EFI_OUT_OF_RESOURCES;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 STATIC\r
@@ -147,11 +138,9 @@ Returns:
 --*/\r
 {\r
   BOOLEAN     OldIntFlagState;\r
-  \r
+\r
   OldIntFlagState = WriteInterruptFlag (0);\r
   WriteIdt (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
-  FreePool ((VOID *) (UINTN) IdtEntryTable[ExceptionType].StubEntry);\r
-  ZeroMem (&IdtEntryTable[ExceptionType], sizeof (IDT_ENTRY));\r
   WriteInterruptFlag (OldIntFlagState);\r
 \r
   return EFI_SUCCESS;\r
@@ -359,16 +348,37 @@ Returns:
 \r
 --*/\r
 {\r
+  EFI_EXCEPTION_TYPE  ExceptionType;\r
+\r
   if (!FxStorSupport ()) {\r
     return EFI_UNSUPPORTED;\r
-  } else {\r
-    IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);\r
-    if (IdtEntryTable != NULL) {\r
-      return EFI_SUCCESS;\r
-    } else {\r
-      return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);\r
+  if (IdtEntryTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
+    IdtEntryTable[ExceptionType].StubEntry = (DEBUG_PROC) (UINTN) AllocatePool (StubSize);\r
+    if (IdtEntryTable[ExceptionType].StubEntry == NULL) {\r
+      goto ErrorCleanup;\r
+    }\r
+\r
+    CopyMem ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry, InterruptEntryStub, StubSize);\r
+  }\r
+  return EFI_SUCCESS;\r
+\r
+ErrorCleanup:\r
+\r
+  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
+    if (IdtEntryTable[ExceptionType].StubEntry != NULL) {\r
+      FreePool ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry);\r
     }\r
   }\r
+  FreePool (IdtEntryTable);\r
+\r
+  return EFI_OUT_OF_RESOURCES;\r
 }\r
 \r
 EFI_STATUS\r