From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=rhbQEY5v; spf=pass (domain: linaro.org, ip: 209.85.215.196, mailfrom: ard.biesheuvel@linaro.org) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by groups.io with SMTP; Thu, 11 Apr 2019 11:58:22 -0700 Received: by mail-pg1-f196.google.com with SMTP id d31so3941365pgl.7 for ; Thu, 11 Apr 2019 11:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lj4odYtvxsw9UYzZLUqw/gPOstQuquFC6SfqcgweAQQ=; b=rhbQEY5vq4gli5oo0Lj5CGfNG29cg7l0cpfk3zR1laWsIaCVd53CsO50ilMjKPACEq L3EwpBiVzPIJRMd5S4Dn3BMa3X77aFicJ/zBgGjpoVj7S78ALNS7QmtCSxhzpXijTn+i cA1ZeBrAQBBEIy3U+yjsAlSlK0At6ecWqjU3G7h3H/CIKX+S2gj8tHgeHeItoGjNaFuV RhsMfznJwKt7qmMBEvMvBtS0d/gunj93SV1M7oBEMkCnKGa96C7nggHgjO5iVqWtL6In wwm4HEDYBMmx2GBxHNy2/5AWz9nBCois5xfkd0D2a3aGXr0Gt4Xxr1hMmHX6V1W6GwJm fIEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lj4odYtvxsw9UYzZLUqw/gPOstQuquFC6SfqcgweAQQ=; b=jPu1vtgoqcZaQpdhC8/QQo7kL/3CzH1AY9I48zG0Xr4sNH8KgIvnBmi0OQQUpaYk39 LZUge7x/Mqh389d63mHVskv7nAS2UbqtcIeRIqjIKO5uNLbYJ1NsB9duQP3krkeAi94M c5h8ZvJtkpgeS4QSZJ+WIxDBS3vWhpj5hT7HSFh7d349AGodbSDUskGdPFfSijtHf/Oy mhKGEVRL7rbQy5uy2RoUs0/NH1Hm/NKeE1+bbfqUUBm0vQKNx1oaHmd1u/4I8IoGc3b+ tnW85GFI6sqkkctUKR46ITU/zsK7197EJV6Wx3CzeGXHUNzdd9Lp/1ocLdQygW6rXq7R kmwQ== X-Gm-Message-State: APjAAAWvtZqKvsrBVS2sSeXoLTvUjQ549ZSA9U8XqFo76Hfs3ZXUV5yI CB/SHyGeIx4IGqfS1yVJitrZIMI4X9wG6ixf X-Google-Smtp-Source: APXvYqyRTNK4DKbIMGURrQgD9T+MnY1Ee7crcbI2WTCXSvYDrPjRtk5jqm3ZswKK4xIgKKHVXtPt9g== X-Received: by 2002:a63:ed4e:: with SMTP id m14mr49280342pgk.182.1555009101694; Thu, 11 Apr 2019 11:58:21 -0700 (PDT) Return-Path: Received: from localhost.localdomain (50-205-23-12-static.hfc.comcastbusiness.net. [50.205.23.12]) by smtp.gmail.com with ESMTPSA id w3sm82712861pfn.179.2019.04.11.11.58.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:58:20 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Vincent Zimmer , Brian Richardson , Michael D Kinney , Andrew Fish , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni , Liming Gao , Jaben Carsey , Steven Shi Subject: [PATCH v5 1/7] MdeModulePkg: introduce PE/COFF image emulator protocol Date: Thu, 11 Apr 2019 11:58:07 -0700 Message-Id: <20190411185813.2084-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411185813.2084-1-ard.biesheuvel@linaro.org> References: <20190411185813.2084-1-ard.biesheuvel@linaro.org> Introduce a protocol that can be invoked by the image loading services to execute foreign architecture PE/COFF images via an emulator. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h | 107 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 4 + 2 files changed, 111 insertions(+) diff --git a/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h b/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h new file mode 100644 index 000000000000..1ca302440e4a --- /dev/null +++ b/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h @@ -0,0 +1,107 @@ +/** @file + Copyright (c) 2019, Linaro, Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made available + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef PECOFF_IMAGE_EMULATOR_PROTOCOL_GUID_H +#define PECOFF_IMAGE_EMULATOR_PROTOCOL_GUID_H + +#define EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL_GUID \ + { 0x96F46153, 0x97A7, 0x4793, { 0xAC, 0xC1, 0xFA, 0x19, 0xBF, 0x78, 0xEA, 0x97 } } + +typedef struct _EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL; + +/** + 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. +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_PECOFF_IMAGE_EMULATOR_IS_IMAGE_SUPPORTED) ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN UINT16 ImageType, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL + ); + +/** + 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(). +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_PECOFF_IMAGE_EMULATOR_REGISTER_IMAGE) ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT64 ImageSize, + IN OUT EFI_IMAGE_ENTRY_POINT *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. +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_PECOFF_IMAGE_EMULATOR_UNREGISTER_IMAGE) ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS ImageBase + ); + +#define EDKII_PECOFF_IMAGE_EMULATOR_VERSION 0x1 + +typedef struct _EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL { + EDKII_PECOFF_IMAGE_EMULATOR_IS_IMAGE_SUPPORTED IsImageSupported; + EDKII_PECOFF_IMAGE_EMULATOR_REGISTER_IMAGE RegisterImage; + EDKII_PECOFF_IMAGE_EMULATOR_UNREGISTER_IMAGE UnregisterImage; + + // Protocol version implemented by the emulator + UINT32 Version; + // The machine type implemented by the emulator + UINT16 MachineType; +} EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL; + +extern EFI_GUID gEdkiiPeCoffImageEmulatorProtocolGuid; + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index a2130bc43991..c2b4e7f69367 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -629,6 +629,10 @@ ## Include/Protocol/AtaAtapiPolicy.h gEdkiiAtaAtapiPolicyProtocolGuid = { 0xe59cd769, 0x5083, 0x4f26,{ 0x90, 0x94, 0x6c, 0x91, 0x9f, 0x91, 0x6c, 0x4e } } + + ## Include/Protocol/PeCoffImageEmulator.h + gEdkiiPeCoffImageEmulatorProtocolGuid = { 0x96f46153, 0x97a7, 0x4793, { 0xac, 0xc1, 0xfa, 0x19, 0xbf, 0x78, 0xea, 0x97 } } + # # [Error.gEfiMdeModulePkgTokenSpaceGuid] # 0x80000001 | Invalid value provided. -- 2.17.1