public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: devel@edk2.groups.io
Cc: Zhiguang Liu <zhiguang.liu@intel.com>, Andrew Fish <afish@apple.com>
Subject: [PATCH] EmulatorPkg/Win: Unload DLLs before reset
Date: Mon,  5 Dec 2022 14:58:42 +0800	[thread overview]
Message-ID: <20221205065842.1792-1-ray.ni@intel.com> (raw)

EmulatorPkg/Win calls LoadLibraryEx() when the corresponding DLL file
is found for each PEIM or DXE driver. The module entry point is
changed to point to the entry point from the DLL. This helps to
notify Visual Studio that a new windows module is loaded and
corresponding symbol parsing is performed for source level debugging.

But entry point from the DLL is only executed when the module is not
loaded by AddModHandle().
When reset happens, we need to clear the DLL loading so that in next
boot the module can be loaded again by AddModHandle().

Without this patch, source level debugging doesn't work after reset.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Andrew Fish <afish@apple.com>
---
 EmulatorPkg/Win/Host/WinHost.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c
index 096292f95a..084cd4cbd7 100644
--- a/EmulatorPkg/Win/Host/WinHost.c
+++ b/EmulatorPkg/Win/Host/WinHost.c
@@ -226,12 +226,26 @@ WinReset (
   IN VOID            *ResetData OPTIONAL
   )
 {
+  UINTN  Index;
+
   ASSERT (ResetType <= EfiResetPlatformSpecific);
   SecPrint ("  Emu ResetSystem is called: ResetType = %s\n", mResetTypeStr[ResetType]);
 
   if (ResetType == EfiResetShutdown) {
     exit (0);
   } else {
+    //
+    // Unload all DLLs
+    //
+    for (Index = 0; Index < mPdbNameModHandleArraySize; Index++) {
+      if (mPdbNameModHandleArray[Index].PdbPointer != NULL) {
+        SecPrint ("  Emu Unload DLL: %s\n", mPdbNameModHandleArray[Index].PdbPointer);
+        FreeLibrary (mPdbNameModHandleArray[Index].ModHandle);
+        HeapFree (GetProcessHeap (), 0, mPdbNameModHandleArray[Index].PdbPointer);
+        mPdbNameModHandleArray[Index].PdbPointer = NULL;
+      }
+    }
+
     //
     // Jump back to SetJump with jump code = ResetType + 1
     //
-- 
2.37.2.windows.2


                 reply	other threads:[~2022-12-05  6:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221205065842.1792-1-ray.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox