]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/DebugSupport/Dxe/Ia32/plDebugSupport.c
Allocate memory in DebugSupport beforehand, in order to avoid calling memory allocati...
[mirror_edk2.git] / EdkModulePkg / Universal / DebugSupport / Dxe / Ia32 / plDebugSupport.c
index 88b8c5a14acaae74879afaa7074057ff5c564b4f..1eaa5ec591134239abc0388188d2be96c719ee40 100644 (file)
@@ -46,41 +46,32 @@ 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  89 25 00000004 R  mov     AppEsp, esp             ; save stack top\r
-    //    00000006  BC 00008014 R     mov     esp, offset DbgStkBot   ; switch to debugger stack\r
-    //    0000000B  6A 00             push    0                       ; push vector number - will be modified before installed\r
-    //    0000000D  E9                db      0e9h                    ; jump rel32\r
-    //    0000000E  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[0x0c] = (UINT8) ExceptionType;\r
-\r
-    //\r
-    // fixup the jump target to point to the common entry\r
-    //\r
-    *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];\r
-\r
-    return EFI_SUCCESS;\r
-  }\r
 \r
-  return EFI_OUT_OF_RESOURCES;\r
+  // The stub code looks like this:\r
+  //\r
+  //    00000000  89 25 00000004 R  mov     AppEsp, esp             ; save stack top\r
+  //    00000006  BC 00008014 R     mov     esp, offset DbgStkBot   ; switch to debugger stack\r
+  //    0000000B  6A 00             push    0                       ; push vector number - will be modified before installed\r
+  //    0000000D  E9                db      0e9h                    ; jump rel32\r
+  //    0000000E  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[0x0c] = (UINT8) ExceptionType;\r
+\r
+  //\r
+  // fixup the jump target to point to the common entry\r
+  //\r
+  *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 STATIC\r
@@ -151,8 +142,6 @@ Returns:
 \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
@@ -362,16 +351,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