From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: michael.d.kinney@intel.com) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by groups.io with SMTP; Thu, 11 Apr 2019 13:29:59 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2019 13:29:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,338,1549958400"; d="scan'208";a="160403968" Received: from orsmsx101.amr.corp.intel.com ([10.22.225.128]) by fmsmga002.fm.intel.com with ESMTP; 11 Apr 2019 13:29:58 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.24]) by ORSMSX101.amr.corp.intel.com ([169.254.8.212]) with mapi id 14.03.0415.000; Thu, 11 Apr 2019 13:29:58 -0700 From: "Michael D Kinney" To: "devel@edk2.groups.io" , "ard.biesheuvel@linaro.org" , "Kinney, Michael D" CC: "Zimmer, Vincent" , "Richardson, Brian" , Andrew Fish , Leif Lindholm , "Zeng, Star" , "Dong, Eric" , "Ni, Ray" , "Gao, Liming" , "Carsey, Jaben" , "Shi, Steven" Subject: Re: [edk2-devel] [PATCH v5 5/7] MdeModulePkg/EbcDxe: implement the PE/COFF emulator protocol Thread-Topic: [edk2-devel] [PATCH v5 5/7] MdeModulePkg/EbcDxe: implement the PE/COFF emulator protocol Thread-Index: AQHU8JiR7O+f1JLgGE2TWLs0AJzPvaY3Z1yQ Date: Thu, 11 Apr 2019 20:29:57 +0000 Message-ID: References: <20190411185813.2084-1-ard.biesheuvel@linaro.org> <20190411185813.2084-6-ard.biesheuvel@linaro.org> In-Reply-To: <20190411185813.2084-6-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ard, Comment below on a VS2015x86 build issue. Mike > -----Original Message----- > From: devel@edk2.groups.io > [mailto:devel@edk2.groups.io] On Behalf Of Ard > Biesheuvel > Sent: Thursday, April 11, 2019 11:58 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Zimmer, > Vincent ; Richardson, Brian > ; Kinney, Michael D > ; Andrew Fish > ; Leif Lindholm > ; Zeng, Star > ; Dong, Eric > ; Ni, Ray ; Gao, > Liming ; Carsey, Jaben > ; Shi, Steven > > Subject: [edk2-devel] [PATCH v5 5/7] > MdeModulePkg/EbcDxe: implement the PE/COFF emulator > protocol >=20 > Implement the new EDK2 PE/COFF image emulator protocol > so that we can > remove the EBC specific handling in the DXE core and > other places in > the core code. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > > --- > MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf | 3 + > MdeModulePkg/Universal/EbcDxe/EbcDxe.inf | 3 + > MdeModulePkg/Universal/EbcDxe/EbcInt.c | 123 > ++++++++++++++++++++ > MdeModulePkg/Universal/EbcDxe/EbcInt.h | 3 + > 4 files changed, 132 insertions(+) >=20 > diff --git > a/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf > b/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf > index 8f293f5c7c29..c7a9d519b080 100644 > --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf > +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf > @@ -89,6 +89,8 @@ > BaseMemoryLib > DebugLib > BaseLib > + CacheMaintenanceLib > + PeCoffLib >=20 > [Protocols] > gEfiDebugSupportProtocolGuid ## > PRODUCES > @@ -98,6 +100,7 @@ > gEfiEbcSimpleDebuggerProtocolGuid ## > SOMETIMES_CONSUMES > gEfiPciRootBridgeIoProtocolGuid ## > SOMETIMES_CONSUMES > gEfiSimpleFileSystemProtocolGuid ## > SOMETIMES_CONSUMES > + gEdkiiPeCoffImageEmulatorProtocolGuid ## > PRODUCES >=20 > [Guids] > gEfiFileInfoGuid ## > SOMETIMES_CONSUMES ## GUID > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > index d6ee6194a0c8..ecccf2c57ffe 100644 > --- a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > +++ b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > @@ -57,7 +57,9 @@ > MdeModulePkg/MdeModulePkg.dec >=20 > [LibraryClasses] > + CacheMaintenanceLib > MemoryAllocationLib > + PeCoffLib > UefiBootServicesTableLib > BaseMemoryLib > UefiDriverEntryPoint > @@ -68,6 +70,7 @@ > [Protocols] > gEfiDebugSupportProtocolGuid ## > PRODUCES > gEfiEbcProtocolGuid ## > PRODUCES > + gEdkiiPeCoffImageEmulatorProtocolGuid ## > PRODUCES > gEfiEbcVmTestProtocolGuid ## > SOMETIMES_PRODUCES > gEfiEbcSimpleDebuggerProtocolGuid ## > SOMETIMES_CONSUMES >=20 > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.c > b/MdeModulePkg/Universal/EbcDxe/EbcInt.c > index 727ba8bcae44..051eb0aaa07b 100644 > --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c > +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c > @@ -349,6 +349,119 @@ UINTN mStackNum > =3D 0; > EFI_EVENT mEbcPeriodicEvent; > VM_CONTEXT *mVmPtr =3D NULL; >=20 > +/** > + Check whether the emulator supports executing a > certain PE/COFF image > + > + @param[in] This This pointer for > EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL > + structure > + @param[in] ImageType Whether the image is an > application, a boot time > + driver or a runtime driver. > + @param[in] DevicePath Path to device where the > image originated > + (e.g., a PCI option ROM) > + > + @retval TRUE The image is supported by > the emulator > + @retval FALSE The image is not supported > by the emulator. > +**/ > +BOOLEAN > +EFIAPI > +EbcIsImageSupported ( > + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, > + IN UINT16 > ImageType, > + IN EFI_DEVICE_PATH_PROTOCOL > *DevicePath OPTIONAL > + ) > +{ > + if (ImageType !=3D EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION > && > + ImageType !=3D > EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) { > + return FALSE; > + } > + return TRUE; > +} > + > +/** > + Register a supported PE/COFF image with the > emulator. After this call > + completes successfully, the PE/COFF image may be > started as usual, and > + it is the responsibility of the emulator > implementation that any branch > + into the code section of the image (including > returns from functions called > + from the foreign code) is executed as if it were > running on the machine > + type it was built for. > + > + @param[in] This This pointer for > + > EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL structure > + @param[in] ImageBase The base address in > memory of the PE/COFF image > + @param[in] ImageSize The size in memory of > the PE/COFF image > + @param[in,out] EntryPoint The entry point of the > PE/COFF image. Passed by > + reference so that the > emulator may modify it. > + > + @retval EFI_SUCCESS The image was > registered with the emulator and > + can be started as > usual. > + @retval other The image could not be > registered. > + > + If the PE/COFF machine type or image type are not > supported by the emulator, > + then ASSERT(). > +**/ > +EFI_STATUS > +EFIAPI > +EbcRegisterImage ( > + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL > *This, > + IN EFI_PHYSICAL_ADDRESS > ImageBase, > + IN UINT64 > ImageSize, > + IN OUT EFI_IMAGE_ENTRY_POINT > *EntryPoint > + ) > +{ > + DEBUG_CODE_BEGIN (); > + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; > + EFI_STATUS Status; > + > + ZeroMem (&ImageContext, sizeof (ImageContext)); > + > + ImageContext.Handle =3D (VOID *)(UINTN)ImageBase; > + ImageContext.ImageRead =3D > PeCoffLoaderImageReadFromMemory; > + > + Status =3D PeCoffLoaderGetImageInfo (&ImageContext); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + ASSERT (ImageContext.Machine =3D=3D > EFI_IMAGE_MACHINE_EBC); > + ASSERT (ImageContext.ImageType =3D=3D > EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION || > + ImageContext.ImageType =3D=3D > EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER); > + DEBUG_CODE_END (); > + > + EbcRegisterICacheFlush (NULL, > + > (EBC_ICACHE_FLUSH)InvalidateInstructionCacheRange); > + > + return EbcCreateThunk (NULL, (VOID > *)(UINTN)ImageBase, *EntryPoint, > + (VOID **)EntryPoint); This breaks on a VS2015x86 build. *EntryPoint is type EFI_IMAGE_ENTRY_POINT and the 3rd param is type VOID *. This can be fixed by adding typecasts: return EbcCreateThunk (NULL, (VOID *)(UINTN)ImageBase, (VOID *)(UINTN)*E= ntryPoint, (VOID **)EntryPoint); > +} > + > +/** > + Unregister a PE/COFF image that has been registered > with the emulator. > + This should be done before the image is unloaded > from memory. > + > + @param[in] This This pointer for > EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL > + structure > + @param[in] ImageBase The base address in memory > of the PE/COFF image > + > + @retval EFI_SUCCESS The image was unregistered > with the emulator. > + @retval other Image could not be unloaded. > +**/ > +EFI_STATUS > +EFIAPI > +EbcUnregisterImage ( > + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, > + IN EFI_PHYSICAL_ADDRESS > ImageBase > + ) > +{ > + return EbcUnloadImage (NULL, (VOID > *)(UINTN)ImageBase); > +} > + > +EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL > mPeCoffEmuProtocol =3D { > + EbcIsImageSupported, > + EbcRegisterImage, > + EbcUnregisterImage, > + EDKII_PECOFF_IMAGE_EMULATOR_VERSION, > + EFI_IMAGE_MACHINE_EBC > +}; >=20 > /** > Initializes the VM EFI interface. Allocates memory > for the VM interface > @@ -449,6 +562,16 @@ InitializeEbcDriver ( > } > } >=20 > + Status =3D gBS->InstallProtocolInterface ( > + &ImageHandle, > + > &gEdkiiPeCoffImageEmulatorProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mPeCoffEmuProtocol > + ); > + if (EFI_ERROR(Status)) { > + goto ErrorExit; > + } > + > Status =3D InitEBCStack(); > if (EFI_ERROR(Status)) { > goto ErrorExit; > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.h > b/MdeModulePkg/Universal/EbcDxe/EbcInt.h > index 8aa7a4abbd63..9b25e91f951c 100644 > --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.h > +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.h > @@ -23,9 +23,12 @@ WITHOUT WARRANTIES OR > REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > +#include >=20 > #include > +#include > #include > +#include > #include > #include > #include > -- > 2.17.1 >=20 >=20 >=20