From patchwork Mon Apr 1 03:27:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 161511 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4874472jan; Sun, 31 Mar 2019 20:27:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqIh7vTT601dW9smhhgSJjlNjSLcDod5dVLNSePhbQj8S4hUT6+Lzum61+u2eCEIFupTWN X-Received: by 2002:a63:da4e:: with SMTP id l14mr17738750pgj.96.1554089244254; Sun, 31 Mar 2019 20:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554089244; cv=none; d=google.com; s=arc-20160816; b=OBR/BfD3OoMSZDAt80EwqwG5O0TT78/OR+H9BKfTVaa4IyEZ97PtCcgAE0eQjQ9C3t MPmriTGhbvQf/VfmivYu3klnhlzG1t6BRNINMUZ9crZzyM3su2TJq2faUeEhp6j5FR6/ Di8dWJ5h9Y7TCk5LQ+1bW8hpCl1k+rIqOuFIBV/Zrt5Tx/7mCB2smeEJPV46/PlXMOM9 t93VZVLXzTmtfiYPz69khMGYOkAufkYS4Vlc+qNTuoyyBd0H/2HffCAmQwr2zFMWBo4C 1ZGgGWR8+jhWKaBPsorq7ktHhuMzLHMjXv6Pwni/ELERlOcnuNrmKd8e2WwyhrN6OVPq FhqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=Xi6NfNHALgl22Xpwf7nCiC+k0O7Y0ftdXGu0lQ0ZQJI=; b=PYjY2lebKJY2lYU2R29bdFhV5lf/A5Xn6GDdAP4MLL1Av71TVuNRUUefJEgeGaSUpc TMZhAwJVYYNdx3MJ4hmR/9M+S1ssx9Aj5wLswLsQP78UIMS8NacaQHvlnidzHw3r/rqE yEeJr3QR6M1bDPSKB3RlSuRaZw1/a226RWf9ol1ijJF/u0tfDWQudHquzEftM6BKrZdC gYTXHMDUTiUv1Mq3i5RqrGNofM70CoAs99kEQatZqUrQ+PnrrwEjvNGKiU65XCqHMB8d QmR/HHZtsusQf8PHNGzt3218ZAcvu0BAtfKuHGf5tTXdgEI75guo6N/MuWtTuZbWrIlZ T3lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="LTHEa/Ff"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 33si7916149ply.361.2019.03.31.20.27.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 20:27:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="LTHEa/Ff"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DB43C211EC678; Sun, 31 Mar 2019 20:27:23 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::643; helo=mail-pl1-x643.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8FB59211E011B for ; Sun, 31 Mar 2019 20:27:22 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id w23so807075ply.4 for ; Sun, 31 Mar 2019 20:27: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=LTHEa/Ff4KOVW7EkoKpOR2LnQ+oGqpxbI2g+IwM4FWvQGsEGKkKWQIE6D8LUK1fquy SYYM4ktF9ogTwLQdazq2J6uVOGDlaiDMP3pZc+esKVUawFFV8C1KwTyLozjAwyI0MElV 3M0f1fA8eYXINn2yU/vJmv5wIlieRZU6z2P/quDm4vg3BqBqh4OeFjS84m6zgi+raZ0q PsLAWmzTdHkxjlo1OMaECcFc24LhImP3ytDJAYgvriycdlUhWUNDCzTqgweKxBr2IVwn yVO+JCirtHuOe6EsjALLJQTpC4A52aPZOdu+F2AzQ8Scx/NjbuU/UCsBXGELJfUNAJBM Vj8g== 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=pVl+Nl7QoaZLZ0344PUnE2QQPaAyrr20Cr3uGo0X6PHLLXSrtMokYO+m8dvXjIuyqF R0RcqkJjR/FzNn23XSapP2FBvQ3GDTihhTqUTbxCeX6PBwuuCFEeeI6g/ZDt54uy6cn3 BmkY/X8pAjyhAyOBlBPN2vuDsoGWwRWp17wo5evq7/gbU5I55aZNpx5HT/fGrNN6xbel bJ02ZpiRvV7Hc0neKa7qYaPq8HmfyhqIXJuzeJqMIFf/HwYOzI+C4V2FFtVqcl+rEQBy Vy0/lc6I9vZ38CwUqFYQLJlK4WIfI7OujlwmHPmZngvFTBsxObjUmXQ3cpPkn1eiwuPL A/Aw== X-Gm-Message-State: APjAAAWpduRa3X8AY2fzoFSBCzRkbftphagn3asifXJTpAssevC6BX7q eCkiv7MVPkpmkNkTq/Gb3DgBR8YLVwnSZQ== X-Received: by 2002:a17:902:ba98:: with SMTP id k24mr53359491pls.335.1554089242027; Sun, 31 Mar 2019 20:27:22 -0700 (PDT) Received: from mba13.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id 16sm12758092pfz.106.2019.03.31.20.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 20:27:21 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Mon, 1 Apr 2019 10:27:03 +0700 Message-Id: <20190401032709.14787-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190401032709.14787-1-ard.biesheuvel@linaro.org> References: <20190401032709.14787-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v4 1/7] MdeModulePkg: introduce PE/COFF image emulator protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Vincent Zimmer , Eric Dong , Jaben Carsey , Brian Richardson , Liming Gao , Michael D Kinney , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(+) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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.