From patchwork Sat Sep 15 13:28:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146769 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805007ljw; Sat, 15 Sep 2018 06:29:10 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbg8ddF96TuJj5UiM5ovx9CM83mmSNo1z7iXK27vZaiu0cg5zsj7SX6k+aByj05U5ZNni3B X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr16975315pld.48.1537018150394; Sat, 15 Sep 2018 06:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018150; cv=none; d=google.com; s=arc-20160816; b=T6PC09ouRZhSVVyA2h6ciO+aIvBl6cXL2Jq0ZWNrgdPjCzGYZtjpM0Vp/t8NMHgDSa I9vwJE7mFzjjHpQYAVTmNkHttBfseL6NskVFiaRo6O3TH+iH+r4Pi5WX/dpyrLorwKdL 7ocebJ7opsmsIQx9hSlPH4DqTRr06comLv9A6mXUnYYJfpkKuLSe6x8YpN8X8TM4KCzy PCsJgJKhQVmrs64KSwex1X9UFYBlpEzbh85o/oJ/FlrnNUzkbQhJB+ZUVc8dPNyeXPOk J3ZWQB/9+HXWen7NzrrZiYdfYF1dn7H9AJZS9+F9KbM9W3JvXKecdKiLim+lIDpjKk6D /IGQ== 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=axJpFaAfp0dPAvAJw5pJqVDENnXtExkJlxY0Aobqco8=; b=WL0wTmGI5eh0UDv7kvUW877JoZOVe/KLACTvh13NOdTPcOplB/VFvOFpt8xbsCv2xu wK64xJGbg25pSrWKDS5qPpY2CX4f70bjWyNwQb6Og1Vinjt+7/rqnlb5JGDlVE/sc7Si DWuKhwwoHH81pTaJK0FZ6Ak+j0i5O0NvRTy82zY44+5qa61LeRyRC0y7PtilblEPC67M 26fWvqEdtIkuszG1JWG65pwGLsAdNUGVIbOvV8RrmlM1PkL5pQ+4idE3V40XnGOh2RXm PLngm1RWYrXEZnSEIlKAxzBJDZAjq0PdORKCeBXTmiH8qIJY3LKK8LWIZLn3dO61EZSG yhwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AJcKPsJ5; 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 21-v6si10196745pgs.520.2018.09.15.06.29.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:10 -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=AJcKPsJ5; 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 06BBC211350E6; Sat, 15 Sep 2018 06:29:10 -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=2a00:1450:4864:20::535; helo=mail-ed1-x535.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (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 936B9211350E3 for ; Sat, 15 Sep 2018 06:29:08 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id y20-v6so9522658edq.2 for ; Sat, 15 Sep 2018 06:29:08 -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=Esjbao0rZczUSkbR6wpULZwSfRNuLlca16a2HDJRnjE=; b=AJcKPsJ5Dhp7reEUZELdXpccZuQTINsmef1EC4H8ioXhIBjjng2RAaZ0a0tuKgHumY 9joPV7MTSvsQIkPeQWMHPAlw13q+Q/2O5Dp6sM0jliz9jVWvMstK9FF2UEOKZAWnoHGH dsfrsRtJBJ4hP8Hz+wtlT4ytsvThXtwAXogW4= 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=Esjbao0rZczUSkbR6wpULZwSfRNuLlca16a2HDJRnjE=; b=srwFKESQVO4DDPhEH7BpcRAMb7VYLyLtTVuuS+vS69gTEe1yeh8WAuW98zBzbwC9Ll gGtQmAgAaazuUNGw72UZ0LJcoaP7+c8zgEpXXCH3GhvHLGWF3KqnsPEkwx9mkVJ5FMMW bXEu1hPMNfDZvtAm0+n3sJuHxnvhtqIx+rGBDKxyLxXkahbgbv6mCh6jSTZipdbh8nQO +qMBwQklmgOuqlq1iq3Y1oWg3s0Cf6LouNpvCOfD28h1/Gzi96iEaLq0756KDMGCX3K7 WplK3IzsoQtmo7MiPHdKbXxHSqaw0FqfzGTwaGM0myj5EuPEPfnB42H1CdUpKzt02+Iw /qrw== X-Gm-Message-State: APzg51ARpsPfjdMc1YPr/vXHWploWGsiy98BOum1q74pgwq9/8GLHmd9 sTdTiAwDZfHd0xB/LGo5RSxdLPm04L2BKQ== X-Received: by 2002:a50:b824:: with SMTP id j33-v6mr28018389ede.272.1537018146546; Sat, 15 Sep 2018 06:29:06 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:05 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:53 +0200 Message-Id: <20180915132859.25727-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 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 , Andrew Fish , 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.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h | 99 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 4 + 2 files changed, 103 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..a604df322999 --- /dev/null +++ b/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h @@ -0,0 +1,99 @@ +/** @file + Copyright (c) 2018, 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] MachineType The machine type for which the image was built + @param[in] ImageType Whether the image is an application, a boot time + driver or a runtime driver. + + @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 MachineType, + IN UINT16 ImageType + ); + +/** + 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 + ); + +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; +} EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL; + +extern EFI_GUID gEdkiiPeCoffImageEmulatorProtocolGuid; + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 6a6d9660edc2..be307329f901 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -617,6 +617,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. From patchwork Sat Sep 15 13:28:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146770 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805026ljw; Sat, 15 Sep 2018 06:29:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdavQK2nax8TKzayevssVoJa4rdRK7XQZ+oPVH/FwYPp+4RPiLQIDBZmob660smQsSGIOAjR X-Received: by 2002:a63:ca09:: with SMTP id n9-v6mr16099138pgi.287.1537018152203; Sat, 15 Sep 2018 06:29:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018152; cv=none; d=google.com; s=arc-20160816; b=FGITCEg7RZF6gLEPDqvbbB5mRVtYvm04WhI/0fZPiBmt6cZ7Haw4KHva/WonP2C4kJ fEkz37qLMyCYxZzqZZk+yQNQPa+m8q1FyT7KSdMr7w7DwtFDpwQIFj+S0ez1KPk3hOBI ql98p33gQVGn8jIQbjT7X4+E7G0T+e39hnwDuhZ9dFAh3Ng3XC/NVPDOYwuw0S4YO+6p WfoEwo4TurmR6wHUlcI8jsYz0b57yBNBKN70J78IIhKyHVPLbxUa4RiXSJ7o08ZwA1eW hhEQyHgGGC6cvkCfxnFGQ93ecHf7pIuK4CwctKyFWMU29lQ2zPM+sRLTw79SQId18odU gG0Q== 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=y1ewnFcxSCtwHeDLufPFG9Cu1uOJEj3W7NiGWAMxi/U=; b=VHMZrKzs4vdQ7Ki4ypItZqlOkhgAQKSL6YaSIBVqownyZsm4PAYgwVDV/Ltpyr2B8l 0g1X2sPa8/KRmUqp8Mq7zTsVB9TI3mOh+/UDY6/0PR89VzJf7QEX6Oe5dXQT6HY5Hh1j Mzbx10m8qbAFO61fi7DVwQNEYnex2/IA7BacWOJ2XuSKN3Gju5OlsGLL51B6zvNwMRJZ uX2XNOVv4P/HtMm6VeINJyUxjdPxUg6x3Qy8+aKccTYd6L2+HUgrVmDSRPA+KctQiqq1 TDkod6PyzGcpEbn7Br3eiJ6HJlLPgIOcAznt5lHwJO3yooGsb2uVNzIf7cD5XkME+1cP A4zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jUdxIqNr; 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 p67-v6si10241242pfg.295.2018.09.15.06.29.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:12 -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=jUdxIqNr; 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 307AC211350EA; Sat, 15 Sep 2018 06:29:11 -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=2a00:1450:4864:20::536; helo=mail-ed1-x536.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 C7F18211350E5 for ; Sat, 15 Sep 2018 06:29:09 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id y20-v6so9522684edq.2 for ; Sat, 15 Sep 2018 06:29:09 -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=Igh65ZMfpEHInhjqoH+ggt0oB+Sf8yTvKsI17Jb6Ndc=; b=jUdxIqNr4ee+Eabh5595+Pv2uF9osqOAV93nrDjD+G2pMM4uhEXS8H3/7Lj67wML9x GSmZfh7LybR1SAHTd5uh8/eQQ8XG2zdboMA8yM6DBGcJ5H6GMQti8PWJQ7KmerEIwhRP 77iUMqDj3iqVPFOWZD23/jCl4RxXuWEv39HVQ= 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=Igh65ZMfpEHInhjqoH+ggt0oB+Sf8yTvKsI17Jb6Ndc=; b=BbDbK+tdw0jWJyWRCgC3eshou1s/Kh0xeM63d3fJMoR2AKGKH5GANV8nMHDC/Yi+xc qc7Wo7eEoN3Rb4t4XsKLgKTaw/O3QuatufWji0v4C0POMkBCtH8solKeVXT9IN3FJ9e4 KPbwK/ZfcQqidqIkntxBqd0lh1vru3VCvIAOgFkBGYD/7PZkqLgLEUGrqPyVJt4/xUbY ANG5BKUxpctlMY8D1BVVtUBUjNSMlhTnrUKrE+vHTcXYXoKYWoHdG6XS/CoNTvP69IcZ VM6XK23stiXmDiybu1yymC4sRaqxrwtsgHwnSSXMuISTCGwLPbOKOllIhVGeuBge7fJa QwDg== X-Gm-Message-State: APzg51AqoF6wsX59+F23VE6OFRmHomA5hh6PbTySz2ZBBli65ZnmMAC7 blPaTIoZlO9DA+nbJL7c8by8CiCd9gPVvQ== X-Received: by 2002:a50:fa0a:: with SMTP id b10-v6mr27883570edq.138.1537018147935; Sat, 15 Sep 2018 06:29:07 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:07 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:54 +0200 Message-Id: <20180915132859.25727-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 2/7] MdeModulePkg/DxeCore: invoke the emulator protocol for foreign images 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 , Andrew Fish , 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" When encountering PE/COFF images that cannot be supported natively, attempt to locate an instance of the PE/COFF image emulator protocol, and if it supports the image, proceed with loading it and register it with the emulator. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/DxeMain.h | 3 + MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/Image/Image.c | 102 +++++++++++++++++--- 3 files changed, 95 insertions(+), 11 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 7ec82388a3f9..ff2418c5ae5e 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -53,6 +53,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -229,6 +230,8 @@ typedef struct { UINT16 Machine; /// EBC Protocol pointer EFI_EBC_PROTOCOL *Ebc; + /// PE/COFF Image Emulator Protocol pointer + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *PeCoffEmu; /// Runtime image list EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; /// Pointer to Loaded Image Device Path Protocol diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 68fa0a01d9bd..63e650ee7c27 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -164,6 +164,7 @@ gEfiEbcProtocolGuid ## SOMETIMES_CONSUMES gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES # Arch Protocols gEfiBdsArchProtocolGuid ## CONSUMES diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index eddca140ee1a..0a4bb3644af0 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -67,6 +67,7 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { NULL, // JumpContext 0, // Machine NULL, // Ebc + NULL, // PeCoffEmu NULL, // RuntimeData NULL // LoadedImageDevicePath }; @@ -425,6 +426,69 @@ GetPeCoffImageFixLoadingAssignedAddress( DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status)); return Status; } + +/** + Decides whether a PE/COFF image can execute on this system, either natively + or via emulation/interpretation. In that latter case, the PeCoffEmu member + of the LOADED_IMAGE_PRIVATE_DATA struct pointer is populated with a pointer + to the emulator protocol that supports this image. + + @param[in] Image LOADED_IMAGE_PRIVATE_DATA struct pointer +**/ +STATIC +BOOLEAN +CoreIsImageTypeSupported ( + IN OUT LOADED_IMAGE_PRIVATE_DATA *Image + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + BOOLEAN ReturnValue; + UINTN Index; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine) || + EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Image->ImageContext.Machine)) { + return TRUE; + } + + // + // Locate the emulator protocol to check whether it supports this + // image. + // + Status = CoreLocateHandleBuffer ( + ByProtocol, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + ReturnValue = FALSE; + for (Index = 0; Index < HandleCount; Index++) { + Status = CoreHandleProtocol ( + HandleBuffer[Index], + &gEdkiiPeCoffImageEmulatorProtocolGuid, + (VOID **)&Emu + ); + ASSERT_EFI_ERROR (Status); + + if (Emu->IsImageSupported (Emu, Image->ImageContext.Machine, + Image->ImageContext.ImageType)) { + ReturnValue = TRUE; + Image->PeCoffEmu = Emu; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Loads, relocates, and invokes a PE/COFF image @@ -473,16 +537,14 @@ CoreLoadPeImage ( return Status; } - if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) { - if (!EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Image->ImageContext.Machine)) { - // - // The PE/COFF loader can support loading image types that can be executed. - // If we loaded an image type that we can not execute return EFI_UNSUPORTED. - // - DEBUG ((EFI_D_ERROR, "Image type %s can't be loaded ", GetMachineTypeName(Image->ImageContext.Machine))); - DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType))); - return EFI_UNSUPPORTED; - } + if (!CoreIsImageTypeSupported (Image)) { + // + // The PE/COFF loader can support loading image types that can be executed. + // If we loaded an image type that we can not execute return EFI_UNSUPORTED. + // + DEBUG ((EFI_D_ERROR, "Image type %s can't be loaded ", GetMachineTypeName(Image->ImageContext.Machine))); + DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType))); + return EFI_UNSUPPORTED; } // @@ -687,6 +749,16 @@ CoreLoadPeImage ( if (EFI_ERROR(Status)) { goto Done; } + } else if (Image->PeCoffEmu != NULL) { + Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, + Image->ImageBasePage, + EFI_PAGES_TO_SIZE (Image->NumberOfPages), + &Image->EntryPoint); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_LOAD | DEBUG_ERROR, + "CoreLoadPeImage: Failed to register foreign image with emulator.\n")); + goto Done; + } } // @@ -874,6 +946,13 @@ CoreUnloadAndCloseImage ( Image->Ebc->UnloadImage (Image->Ebc, Image->Handle); } + if (Image->PeCoffEmu != NULL) { + // + // If the PE/COFF Emulator protocol exists we must unregister the image. + // + Image->PeCoffEmu->UnregisterImage (Image->PeCoffEmu, Image->ImageBasePage); + } + // // Unload image, free Image->ImageContext->ModHandle // @@ -1599,7 +1678,8 @@ CoreStartImage ( // // The image to be started must have the machine type supported by DxeCore. // - if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)) { + if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine) && + Image->PeCoffEmu == NULL) { // // Do not ASSERT here, because image might be loaded via EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED // But it can not be started. From patchwork Sat Sep 15 13:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146771 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805057ljw; Sat, 15 Sep 2018 06:29:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ1GwbhHExIMe16zF0o+eTvCYK61DlhjY12GD/GfjS+wxqYEsc/C+R8j5AfbZu7ngWWcq5O X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr16658307pgc.48.1537018154970; Sat, 15 Sep 2018 06:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018154; cv=none; d=google.com; s=arc-20160816; b=Rk5K7ybdAv+GufLL9AC/w7nUmUADGj+CB5tHVZ3ZrBalb6ur3p7teGsdskzlyg44n9 BGV9xhXw3d8ZewmwXm+QtxztD5QGlKRDkFyOymw9NlzWXDaMnJ2yAPnZre4LFas2tSzM zHxbXJGvIFge/JTCpHHXS1dXrIOF0WOPFEWEcMwaVQfQhzR/YMGlOmRmPkL30bOmiPQp jjSWtBdkZUIeh7pmvdC5XkpgmEOvCrzuB+sNNEw77TXNOk1BtyQEuvSrDuF9PYk/aAaW P8mQwYUc8WKfytV1ajlg8aJ/eQHnQ8NZk3jOjDAtZV4adjJkiXGTlEuXOmGyiVXs+s2f 714w== 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=63uV4eyg3d/6R2ClxptfMwIYYhLOFNUWkhVXij8TOnY=; b=0R14h99qNVHFGhvdYJm2Q6/ictlYDTE8gtiaCpD+VNcj92+5TAfz8bkE2Qu6MuSkh9 CnQFXA1Ch3FwqNmkAl9+bpq7cdPVlq1KRsma80uqcPbd5iBR3TDFCXbOQpf9Od25LTa6 EH861qxn6bX8vhupocZXWI8zFFCYniTFcv70S+jJOzDzJqzfMgFQwfOYq/CZZk29+ixR YWCrWN12hOqQLwLAuPhArEZ2uSU+F+RmV3NtpEI8js46lcBTFj9qAB6FCGBMQ3qeXTIb pPnXbssVMKsre5FXRYf4SYvLpMPENBRqwuPtJnC9j0roiDB8unCUAYTrZWh0AIcO3aUe JUWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=BmHcGu7u; 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 d11-v6si9625426plo.91.2018.09.15.06.29.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:14 -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=BmHcGu7u; 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 5CD3A211350EF; Sat, 15 Sep 2018 06:29:13 -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=2a00:1450:4864:20::52c; helo=mail-ed1-x52c.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 5C1B5211350E3 for ; Sat, 15 Sep 2018 06:29:11 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id h4-v6so9492391edi.6 for ; Sat, 15 Sep 2018 06:29:11 -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=/8cs24/TIOOKeYusJolRaqh2SEZTJHbEt0J+wg7JK8I=; b=BmHcGu7uDJ8/FvMuLd+/mxugjB/cC0hbFI+jenMmd15p3Xgg8Lh533rbe71he/71YB N2Njh6CUhPtyZ0Ab5kX1i5laFEBh5QQmfkoubT6Nkg9oiZQ72JudSv8P+wBhLtKGkJ5J 1pPKGC2f2TWgR6/W8VpUhN347iRiFt4DDqt7E= 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=/8cs24/TIOOKeYusJolRaqh2SEZTJHbEt0J+wg7JK8I=; b=mgzXolk8yh5JRtn3OsJIJ11VMkgMRRhOaFvhLOxWM7JXiiw7Zgld8k4lZ/axe13dlA K4tu6RRoyPf/EL8/Shw+aT+UimuPLSETYs4vuCkdmg/rZ79IGQ8AaUbV2VETt9zOyQ7a PYIoR36N0nB5zlbRKxDn+0pWxCMZlwzG2CF7EhjMeObNzeZ/gnJl68sVgmXoBtk4B1xJ ADS1sBf7ZRuGFqaq3voyiIdsuAQKP44G5o1eLtG2QC6OlLNIFkJH4bXlunYSmzVXsvvw VhM7+mU1MCFVANNeyE9LbtYzJtIDIaDjVwJCz7HHeHhlbni5JWrV0a4x83Z2nJ4jOS6U N62A== X-Gm-Message-State: APzg51D/rLFLRNyHjpXvhPKj56UhZE4CW10zQVvCGGz5+T+zHVJ7OYjI 3/761H6L3r5mzRB9xDBjPyyR+378NJhzLQ== X-Received: by 2002:a50:c2d1:: with SMTP id u17-v6mr29446469edf.119.1537018149433; Sat, 15 Sep 2018 06:29:09 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:08 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:55 +0200 Message-Id: <20180915132859.25727-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 3/7] MdeModulePkg/PciBusDxe: invoke PE/COFF emulator for foreign option ROMs 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 , Andrew Fish , 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" When enumerating option ROM images, take into account whether an emulator exists that would allow dispatch of PE/COFF images built for foreign architectures. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 1 + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 1 + MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 51 +++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h index 55eb3a5a8070..dc57d4876c0f 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h @@ -33,6 +33,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf index a21dd2b5edf4..c8b861093292 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -96,6 +96,7 @@ gEfiIncompatiblePciDeviceSupportProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadFile2ProtocolGuid ## SOMETIMES_PRODUCES gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadedImageDevicePathProtocolGuid ## CONSUMES [FeaturePcd] diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index c2be85a906af..ac3a9fcaf1d0 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -651,6 +651,54 @@ RomDecode ( } } +STATIC +BOOLEAN +IsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem + ) +{ + EFI_STATUS Status; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + BOOLEAN ReturnValue; + UINTN Index; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (MachineType)) { + return TRUE; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + ReturnValue = FALSE; + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkiiPeCoffImageEmulatorProtocolGuid, + (VOID **)&Emu + ); + ASSERT_EFI_ERROR (Status); + + if (Emu->IsImageSupported (Emu, MachineType, SubSystem)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Load and start the Option Rom image. @@ -715,7 +763,8 @@ ProcessOpRomImage ( // // Skip the EFI PCI Option ROM image if its machine type is not supported // - if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (EfiRomHeader->EfiMachineType)) { + if (!IsImageTypeSupported(EfiRomHeader->EfiMachineType, + EfiRomHeader->EfiSubsystem)) { goto NextImage; } From patchwork Sat Sep 15 13:28:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146772 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805103ljw; Sat, 15 Sep 2018 06:29:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYKB1usOJkkNCiWJ/e4+GO1XKvNHHqRKL6mxs9C8PipzJr9ic/D/AYoTOf97a9/9WtHghPY X-Received: by 2002:a63:e255:: with SMTP id y21-v6mr16189412pgj.160.1537018158004; Sat, 15 Sep 2018 06:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018157; cv=none; d=google.com; s=arc-20160816; b=VAYlJViKkaRve/qYWVrkASehlDkVQK410Wr+v8IadtBzTSAvP2xxa52ZvX0Uv7ynsp fA496bNAzZ3oYGs0KaCBk1/k+4s1rppM8c8ns1aHCheiLxb6+m4CREl3fO2/wirt5HsV 7P/XlH4myGLvK5YpDE7VjyemsE61jf3SGgRjc3oqce/qdSZOVAvtl2LGdyite0dN6uAs Ra57sQfyk3+JAOYjC9bIgCZ5BgQQV+a6HYPcMn3TycapIwp6D7m09p+iOgIvFyyfFSw9 5J/5GjBE4IB87vCrGOSwjxNqLTaEqan8vY/DGufEG7ICvLOj8QmdKwtU0ebU+aHnPfPF tzXA== 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=6HiaoUWDN3L3Nwj4HMMV5okD33MR/jo5sB0f3crbIPg=; b=BmeNDFR9VOBwTDNFcSLPYDoYukq8K0ODUu4bXCA75q5gySbq7m1bNHXHjQoP0M30cA L7qW/Am8KIhVeyGD8MP3R8++BQJ+w/yKAIpXZlHTVdNPuiCGpZ04PtsZ/iS802Az1VeI H9+xADY+979oBcagV1Mascq7Gxzp/z7V8mq06h1e9cRXL+APYuhEEMrxWVQrm/f3oDUU jfZoM584FKAKKPTfvRgvhXOwgyaHKJAPcv9jkuHnjNk4Hgqiv2OrNV8Sua82pQNWe07D jJr+QbLjT6NMuNOwLgJssVpUFpOv/K88+VlJp7SSD5DKTDqsOPnf7R05bAS+6G2vHImx 7uBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jNCYC63r; 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 1-v6si9594020plv.28.2018.09.15.06.29.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:17 -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=jNCYC63r; 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 8C5C6211350F4; Sat, 15 Sep 2018 06:29:14 -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=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (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 9F3C02194D387 for ; Sat, 15 Sep 2018 06:29:12 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id k14-v6so9472956edr.13 for ; Sat, 15 Sep 2018 06:29:12 -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=mfP/CMMmtQmCdyuMC7VkUiLdmXv4uBEe+9Q0sLkcMfU=; b=jNCYC63reuWidpLbeZAvxYAkHP4PMK9q4Mn2w73KhA6+Nx45fhDuLRvPEjRixgBXrP QSeD9tMCQoEXaemXbdEjnt5xbAZLpv8QC/5HUw4ENamLp1mfrIaBMZGFxbcEnBmW8LZS UIorcaV6zFt4T91j5V698bYpwCDNaawEBFG+Q= 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=mfP/CMMmtQmCdyuMC7VkUiLdmXv4uBEe+9Q0sLkcMfU=; b=plYQkguJdmVve41lGcaSfkAG4Qxe23jsz2y0PTxgQ5euWFeXlBuNDcPY4r7Xq7g0Sj w6KwqDbx/9a1nHLP6zQIARX9h8P6sefaZIIxJOqxLU6Q2u//0XkB84iQRCZA1Li2/da1 IGnrgGNoN69TMr23+BtpyvAqlMn3AfbiFr7FJRGRdujENInhhNwlwM0j47UxLU23Dc0d wK3hTvO/iIqDA7LOvnrbbgJSdw0zhUpT0gRk8Y8+Hj5NFm64jLvJfn59KVAj7mdJAge6 PCAXhwPynz3+gMJVRC8X4UOFqaT0jWvg5eATr6xj8jTSUWITRuuifXpPwtB/marzQ/T9 5uFg== X-Gm-Message-State: APzg51Ava9tItPkXqpZkZ7U+EBzEetlyH06wE3N7gnaM9o0OFDkg9MbI VILASQCwinCeyRSo96hJInte2rAl0eR/iA== X-Received: by 2002:aa7:ca51:: with SMTP id j17-v6mr29759103edt.45.1537018150930; Sat, 15 Sep 2018 06:29:10 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:56 +0200 Message-Id: <20180915132859.25727-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 4/7] MdeModulePkg/UefiBootManagerLib: allow foreign Driver#### images 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 , Andrew Fish , 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" Allow PE/COFF images that must execute under emulation for Driver#### options, by relaxing the machine type check to include support for machine types that is provided by the emulator. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c | 51 +++++++++++++++++++- MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 1 + MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 7bf96646c690..9bd8bbcf0bf1 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -1185,6 +1185,54 @@ EfiBootManagerFreeLoadOptions ( return EFI_SUCCESS; } +STATIC +BOOLEAN +BmIsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem + ) +{ + EFI_STATUS Status; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + BOOLEAN ReturnValue; + UINTN Index; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (MachineType)) { + return TRUE; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + ReturnValue = FALSE; + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkiiPeCoffImageEmulatorProtocolGuid, + (VOID **)&Emu + ); + ASSERT_EFI_ERROR (Status); + + if (Emu->IsImageSupported (Emu, MachineType, SubSystem)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Return whether the PE header of the load option is valid or not. @@ -1235,7 +1283,8 @@ BmIsLoadOptionPeHeaderValid ( OptionalHeader = (EFI_IMAGE_OPTIONAL_HEADER32 *) &PeHeader->Pe32.OptionalHeader; if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC || OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) && - EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeHeader->Pe32.FileHeader.Machine) + BmIsImageTypeSupported (PeHeader->Pe32.FileHeader.Machine, + OptionalHeader->Subsystem) ) { // // Check the Subsystem: diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h index 978fbff966f6..5f64ef304b87 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -47,6 +47,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf index 72c5ca1cd59e..09e2134acf8e 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -104,6 +104,7 @@ gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES gEfiBootLogoProtocolGuid ## SOMETIMES_CONSUMES gEfiSimpleTextInputExProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES From patchwork Sat Sep 15 13:28:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146773 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805144ljw; Sat, 15 Sep 2018 06:29:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbabZy00/WWiCE5qYNJCqyMZvepb/JAJXW7ypKyJDJoZgabqztJS7bH72Xe7ztQeKjCcB60 X-Received: by 2002:a17:902:6f10:: with SMTP id w16-v6mr16636684plk.216.1537018160790; Sat, 15 Sep 2018 06:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018160; cv=none; d=google.com; s=arc-20160816; b=zQ88FwclMWqUqwICkDHeTwn53u+xYGSI+71WzAzr2BDu2XOipMpiYgmoAtGltuGcC2 9V4WbDXlFzuN91sqkYHMmUeL+u7T2t9aQ9pkevElobXqNpKQNnDQmu0XnBhgoDRn2nrM XCM0vMAfDr/ztAp2GTOigCWsxEaTqevX8YnzVC6gy5pCG2rmzAuFKcGug83TvF5NKjEL hl1ae09qZt6WE52RjKXGOz26aZi2mI7Ho5uGTdwQpn31CRn49KyVWIoV8dyOl7slaEks gobImN1kO7qQwv8eubNDNcYS827IWiqvk2bFK3FH8Zu2xmllPHE3fxqAQG40yx67ZcPi BgtQ== 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=GZUQ79W3Yy9rW9TT5VbllSffbwHmo1Sk3Fe0VkO8+oo=; b=Ll8oNPjJGLlQMSpeJBdfpt3/8zJmiaX5OcttkFZLYPKoeb+xPDAWbgdk2XSVAkTAKi AGNG6HERZbzBWOd+OF7FuEEtoR+yqy0x4WzaFcHydinJyrAR1/lMPpz8LPOuzeypDYVu LDTQgEvU7QXNIwGeMUYnCANFJ43nr7641UNuQkf6giJdtmxI16TV3FTJ/MyymvnvsBPt UiAKmwBZ9gsNfyydHJ03bzf4wLkvf9PxP7wRVqJ0mTy8fW9xvoVR0eHewFXPIdKezHT2 R6XZsqpZC4GMJ3rxmdATGsXKzPsjWCtusymlOaSwBjHDv9ey75Vx2ZWIXJ+m4LDnQ0HM FY5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KOXNBTqA; 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 e37-v6si9997785plb.313.2018.09.15.06.29.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:20 -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=KOXNBTqA; 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 B7EBB211350F1; Sat, 15 Sep 2018 06:29:15 -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=2a00:1450:4864:20::533; helo=mail-ed1-x533.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 6B871211350F1 for ; Sat, 15 Sep 2018 06:29:14 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id z27-v6so9488176edb.10 for ; Sat, 15 Sep 2018 06:29:14 -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=nj4K3NwqmcW9kLr0mTuGyiKIhHw8TkGtlSCfGV+GoTY=; b=KOXNBTqAJb+7smSUCtFoW4SNVRrli+TQLEsYfG3kfu4REMxaRbjrPNgPpRe5UtuAlB sYmoex9GSG0/UpZXlCzVLq2zxqN+ww22llIvWYoltYbcQDtfi1rUbIxYO6jvQfrudaBb 1xSIRBuA2vHzDP97hvEJwAOQpcPH587IOiFh4= 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=nj4K3NwqmcW9kLr0mTuGyiKIhHw8TkGtlSCfGV+GoTY=; b=Dlg9JD1uniEeF7bezdAi8/U4KC1ovGN2E6pOvIvIwlPwaWpr7mTLnB8pXp8a5juGNC klYa6+xepPQYAaJBWIcjAPoqB9Gv7N5W3/q2hCw5LROed8QRxpn2r1UraGfXv3Ns1t8V uYF6wcFd6nq5ZRi8rsELYXylJMUG5vmpEozU8q1HzXvbbG48MIfdsU6rYHeytE8fze4t lDwrdKXkMpKmFe4L62uH94u+5RV45cw5qdjZzeCiuDCFNhnV88jq3vV2whbUoFze6NJM hl2yIID2qroZSgRawFO3KjupiyrFtHCGYK1gFWu4BNEN6mz2wpcLEWan1NuLl06wU5FT ba4A== X-Gm-Message-State: APzg51CIoCWptIQC9yT48N8lopPlbXPdSEnRKkc1NKaAP0QsMO+1AxX4 PTiEjzV5VLC29GNudaULFUeIjPGzUr1Yhg== X-Received: by 2002:aa7:c708:: with SMTP id i8-v6mr28223255edq.231.1537018152577; Sat, 15 Sep 2018 06:29:12 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:11 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:57 +0200 Message-Id: <20180915132859.25727-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 5/7] MdeModulePkg/EbcDxe: implement the PE/COFF 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 , Andrew Fish , 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" 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. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Universal/EbcDxe/EbcDxe.inf | 3 + MdeModulePkg/Universal/EbcDxe/EbcInt.c | 124 ++++++++++++++++++++ MdeModulePkg/Universal/EbcDxe/EbcInt.h | 3 + 3 files changed, 130 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/Universal/EbcDxe/EbcDxe.inf b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf index 8f128b121d0b..9cba1d0a917b 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf +++ b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf @@ -62,7 +62,9 @@ MdeModulePkg/MdeModulePkg.dec [LibraryClasses] + CacheMaintenanceLib MemoryAllocationLib + PeCoffLib UefiBootServicesTableLib BaseMemoryLib UefiDriverEntryPoint @@ -73,6 +75,7 @@ [Protocols] gEfiDebugSupportProtocolGuid ## PRODUCES gEfiEbcProtocolGuid ## PRODUCES + gEdkiiPeCoffImageEmulatorProtocolGuid ## PRODUCES gEfiEbcVmTestProtocolGuid ## SOMETIMES_PRODUCES gEfiEbcSimpleDebuggerProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.c b/MdeModulePkg/Universal/EbcDxe/EbcInt.c index 727ba8bcae44..fbd9003565be 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c @@ -349,6 +349,120 @@ UINTN mStackNum = 0; EFI_EVENT mEbcPeriodicEvent; VM_CONTEXT *mVmPtr = NULL; +/** + 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] MachineType The machine type for which the image was built + @param[in] ImageType Whether the image is an application, a boot time + driver or a runtime driver. + + @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 MachineType, + IN UINT16 ImageType + ) +{ + if (MachineType != EFI_IMAGE_MACHINE_EBC) { + return FALSE; + } + + if (ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION && + ImageType != 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 = (VOID *)(UINTN)ImageBase; + ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; + + Status = PeCoffLoaderGetImageInfo (&ImageContext); + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (ImageContext.Machine == EFI_IMAGE_MACHINE_EBC); + ASSERT (ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION || + ImageContext.ImageType == 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); +} + +/** + 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 = { + EbcIsImageSupported, + EbcRegisterImage, + EbcUnregisterImage +}; /** Initializes the VM EFI interface. Allocates memory for the VM interface @@ -449,6 +563,16 @@ InitializeEbcDriver ( } } + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + EFI_NATIVE_INTERFACE, + &mPeCoffEmuProtocol + ); + if (EFI_ERROR(Status)) { + goto ErrorExit; + } + Status = 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 #include +#include #include +#include #include #include #include From patchwork Sat Sep 15 13:28:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146774 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805192ljw; Sat, 15 Sep 2018 06:29:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZrykvFbLD/lz0zZFYU6u47FWi6ViwO/WJ71u8/7xQl/9D/ZyVpENCapG3SIg7q20I53zHC X-Received: by 2002:a63:df04:: with SMTP id u4-v6mr16547005pgg.434.1537018163888; Sat, 15 Sep 2018 06:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018163; cv=none; d=google.com; s=arc-20160816; b=veYL0EVNfC5Z2dqvxd9I1REK4Wq64rzyo/SyisI4nVM3LkJ0X5oBQYAMFy1PYpEouG RqNDZlZ2GfdXtiO6//376hJgDmJp8ngrZ9Ouu8QwlfsehL5SRW/rQ/FmNL1vby81bjEm YZNCheJ1zJ88vUaTQRnf6wPmLc+BTXzf+2LXScYbXIA29aYx1f4iUAHBgP+AJJnoDxX/ 7G3HLVOFQ/fV46gPbUhktw0BtZs8lP8Qb800zN0hxL9iSS1rngkLAEYc5lryqHW0NsnZ YvVTlOoeOvKZzN/S5ej/bez0Jt/+0uTCmFXO6F/tGv7x45zJWFNJwoqoD2pW8hwvEXyU hudw== 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=aSgBfGzeKVNGRhm4ZlKcmT3FMDmvCnz8cakJRezF3L8=; b=U4VGv+eVFkY03QKZrgqqTzOGLf8Xbbj3VZUDjoMQx8Cl0BXLj5pxwIKrwegyXYUylY XRIW/p9TcC6Y4BCF5a435Kj5JZNuT65fJtKZgnVJWRTeXHHikltCtbUm2R5Mk6zgHK5c x64Rz6wHIE6HUpBsR55WArkuKWfSRCzKY+MwLBZRGRzEl8xkGu4rZoQTvjCgv8hDltMz yMseUv3q7RtgteVFsDM+IuycE+2oegbqjkRQSkDxWmTt9ch63l22tvfIf7VUaST/valq klCEkFP7IP7oGom0T7/KpIPyK0F1cHgI60xjEiCVyhitSzsgkhihqneToZAlP/qBN5DG n1CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=BW3dkVs2; 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 k1-v6si8101255pgo.0.2018.09.15.06.29.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:23 -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=BW3dkVs2; 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 E426B211350F8; Sat, 15 Sep 2018 06:29:16 -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=2a00:1450:4864:20::542; helo=mail-ed1-x542.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (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 A996F211350DA for ; Sat, 15 Sep 2018 06:29:15 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id l5so9500961edw.9 for ; Sat, 15 Sep 2018 06:29:15 -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=Ft0Q4pLHJguByhAwaNLJXdR9Pe2IpF6qrxp5PSAGM40=; b=BW3dkVs2QJNLZsLc+LBgiJjgbLSwLVxVG2jJIFhGibS82dOS7XrKqMtNmdYfFrUPTF uPbqIy+kdH35i7hgOtfzJTO7wLxpTwRSokmh5HjII9uRa7PusT0RJldpZ0dweZ9Epfyi BreECLdvIM0tPUh454uNWxSkUkREd+qWuwWdQ= 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=Ft0Q4pLHJguByhAwaNLJXdR9Pe2IpF6qrxp5PSAGM40=; b=LiNNG8B6S76cDgicOfIe4VZGOQDBDKRL7vdlK5I7HGvKdtjVNT6BkMbo0Lx3mU6rvP AHmgJ4AY5O+QY2n08NkrpEkEm1kCGu7w5FpXFLF01Jk3cHN/tRWTwa/egcA2iQ6YNDGa EE6ZcmGp921NR/xTADjnF0QsY2kb5qvhabTk9R3VWYzV4Fx7DE7DX9UaKXvxaBCoVDpn VcFhSeQ+sry/Oa64GXPc5l9ObSyN5OvxzwxORaLIiudgsVQsLWRLSDPbW6X8dbQ+Mddx HBxC+uD7AQIGE+ktcMTUcokGKFzksluwyxmMoEGxZYy31JM8/lbtbOLz9l/CpwCqwnt9 o6Dw== X-Gm-Message-State: APzg51Cvej0FxKisRhJrsVP+vSwMOit0nNAnLNvagQ22p5Zx/1L7UBKn 0P+xyCzN+X8QricnCPPchi/jMJdWV6rssQ== X-Received: by 2002:a50:c05a:: with SMTP id u26-v6mr29518067edd.107.1537018153903; Sat, 15 Sep 2018 06:29:13 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:13 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:58 +0200 Message-Id: <20180915132859.25727-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 6/7] MdePkg/UefiBaseType.h: treat EBC as a non-native machine type 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 , Andrew Fish , 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" Instead of classifying EBC as a supported machine type and have special handling in DXE core for loading EBC images, make it a foreign type and rely on the EDK2 PE/COFF image emulator protocol to claim the image when the DXE core finds that it cannot be supported natively. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdePkg/Include/Uefi/UefiBaseType.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Include/Uefi/UefiBaseType.h b/MdePkg/Include/Uefi/UefiBaseType.h index 401db7f620b3..e52121809deb 100644 --- a/MdePkg/Include/Uefi/UefiBaseType.h +++ b/MdePkg/Include/Uefi/UefiBaseType.h @@ -250,21 +250,21 @@ typedef union { #if defined (MDE_CPU_IA32) #define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \ - (((Machine) == EFI_IMAGE_MACHINE_IA32) || ((Machine) == EFI_IMAGE_MACHINE_EBC)) + ((Machine) == EFI_IMAGE_MACHINE_IA32) #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_X64) #elif defined (MDE_CPU_IPF) #define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \ - (((Machine) == EFI_IMAGE_MACHINE_IA64) || ((Machine) == EFI_IMAGE_MACHINE_EBC)) + ((Machine) == EFI_IMAGE_MACHINE_IA64) #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE) #elif defined (MDE_CPU_X64) #define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \ - (((Machine) == EFI_IMAGE_MACHINE_X64) || ((Machine) == EFI_IMAGE_MACHINE_EBC)) + ((Machine) == EFI_IMAGE_MACHINE_X64) #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_IA32) @@ -277,7 +277,7 @@ typedef union { #elif defined (MDE_CPU_AARCH64) #define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \ - (((Machine) == EFI_IMAGE_MACHINE_AARCH64) || ((Machine) == EFI_IMAGE_MACHINE_EBC)) + ((Machine) == EFI_IMAGE_MACHINE_AARCH64) #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE) From patchwork Sat Sep 15 13:28:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146775 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805233ljw; Sat, 15 Sep 2018 06:29:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY+kfEby/LhPqUe06Y698jwb5B1FbWG14yQoCK+w3f07KMnyEOUeBR9JlsuA8k5QlrVFxhf X-Received: by 2002:a17:902:4001:: with SMTP id b1-v6mr16856541pld.312.1537018167077; Sat, 15 Sep 2018 06:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018167; cv=none; d=google.com; s=arc-20160816; b=NSNNDgD3J0hB2TLnNo4UVO4AWfZIeQjO+mDUgADpY89imA/w+zJkxN8zoLehdMSzVi DI4jDGBvF0d3IHvrULV78mko101chlqJZi7NrAsvwE1v8lYX3/+2piMxw7e3EFz6ueJr N3qT4Tg59xGObxORbSiwX2zX1MEYRsdbdQcNvbdkaIedGiA3lYrbkYVgSMBlIYptWUOX 1FejgGIE0xkE28Edj3Rfu3cTHflJeLBNym2l8bygwJ7RUE3SinfRNP1R65g5RdG+f/E+ T5tMbbZKQRhULyk043/9uIxSbx8e+IlIuCkb8FLF6R8dniTnr44z2f48OhI95zEPpn2S hoDA== 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=B3twvqznjVMh18bOhtY62XeMx/dtVFQo++/4NAD8Dy0=; b=UFVdsfslUAE3yUra2Ez3XJK8bmwjRrDyeDPltrwi3/vutGma6ND6/x3cWt1NpOWKYI Dc85rwz1nxB9aIz0z99xuuJ3KWIq/cpeVylFhH92dLnltBPda1eAziX1kussxpWwzlUM YtxPrxCvh+zojwNWuqqeT26eYnm96nqfLBXURcCdp7+h4kGHPsGBtxqH2R7WCcBwwEFQ cHRRy7AJOgRh7WsLateQDzlNxcAq4s9JFTBPVvjTsh8QAnyss1ll8F83Qm0VIMbwYxGZ ikDqvH07nTY0uuDjZxA50EyStT5mV0hyvhWtnQEXSUv3DgbI2oFEGo2jW44YzoCb8bRO LRBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G4kHutGy; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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. [198.145.21.10]) by mx.google.com with ESMTPS id u4-v6si10731283plj.134.2018.09.15.06.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G4kHutGy; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 1A1AE211350FF; Sat, 15 Sep 2018 06:29:19 -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=2a00:1450:4864:20::543; helo=mail-ed1-x543.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) (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 4FEEE211350E9 for ; Sat, 15 Sep 2018 06:29:17 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id u1-v6so9512863eds.1 for ; Sat, 15 Sep 2018 06:29:17 -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=eX7WTuqwg+qX1Ys2FS9saLuKyaP89HVy37MEcuk/Xco=; b=G4kHutGyCqJEuPhcsLcsauyDe4w9GvTHgYUaMGdN57bVSTPeTGufLT7el1vgUwS4FY 8TaTJ2iBmqwm7vU6TdMw1UHtnUOvFMGTg8FrY0+k7tWusXHl8V8adan/6IXEDMfXGiH8 zNbUbnaKZTDgd6wquzJPumF6NzlqlK02RyJYM= 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=eX7WTuqwg+qX1Ys2FS9saLuKyaP89HVy37MEcuk/Xco=; b=rhHqkVhk3sCZ9d9ECPAiOc4X43Sy+bGFDWwgk2Thx9gV41bhAfZD623dTpJ1OoXFag da6afxmf0Ujl0hBOIMiPq27EtyReZiEaFE/V9JCwhUCAGCVXU0PB+T+oM6MJOWpMoZB8 RE/LEztqxM1z/NEG9OHRfyQYS2NkirrSZiQmWHA0qeyJyVBxg0WgT4FlsleX+8Ig9FD5 iTaHzlX4Y2MvyU0bUWvIcospu2OJTJekIl2CmzS3pMcapb4IFD+MpPNNhQ5SrN4oPn+K uRrtsVl2X0PggTMcHV0Z0TUEFn6aDNjqWfXCUFsLKvnBsROGobOOu9L55NywLF0wFx3R gfKA== X-Gm-Message-State: APzg51B7icsfsfg8Rexzscrp/v9xq3NlwzrcPOcwLVBpojW1mOjw+/k2 +eKGHkTUkCE36SYcpN006AYKCBTJmEs3SQ== X-Received: by 2002:a50:acc6:: with SMTP id x64-v6mr29336389edc.152.1537018155432; Sat, 15 Sep 2018 06:29:15 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:14 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:59 +0200 Message-Id: <20180915132859.25727-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 7/7] MdeModulePkg/DxeCore: remove explicit EBC handling 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 , Andrew Fish , 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" Now that the EBC machine type is no longer classified as a natively supported machine type on the architectures that can support it via the EBC interpreter, the EBC specific handling in DXE core is no longer used and can be removed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/DxeMain.h | 3 -- MdeModulePkg/Core/Dxe/DxeMain.inf | 1 - MdeModulePkg/Core/Dxe/Image/Image.c | 53 ++------------------ 3 files changed, 3 insertions(+), 54 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index ff2418c5ae5e..c473006813fe 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -42,7 +42,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include #include #include @@ -228,8 +227,6 @@ typedef struct { BASE_LIBRARY_JUMP_BUFFER *JumpContext; /// Machine type from PE image UINT16 Machine; - /// EBC Protocol pointer - EFI_EBC_PROTOCOL *Ebc; /// PE/COFF Image Emulator Protocol pointer EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *PeCoffEmu; /// Runtime image list diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 63e650ee7c27..a969b869b331 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -161,7 +161,6 @@ gEfiLoadedImageProtocolGuid ## PRODUCES gEfiLoadedImageDevicePathProtocolGuid ## PRODUCES gEfiHiiPackageListProtocolGuid ## SOMETIMES_PRODUCES - gEfiEbcProtocolGuid ## SOMETIMES_CONSUMES gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 0a4bb3644af0..902a44455fdd 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -66,7 +66,6 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { NULL, // JumpBuffer NULL, // JumpContext 0, // Machine - NULL, // Ebc NULL, // PeCoffEmu NULL, // RuntimeData NULL // LoadedImageDevicePath @@ -83,9 +82,6 @@ typedef struct { CHAR16 *MachineTypeName; } MACHINE_TYPE_INFO; -// -// EBC machine is not listed in this table, because EBC is in the default supported scopes of other machine type. -// GLOBAL_REMOVE_IF_UNREFERENCED MACHINE_TYPE_INFO mMachineTypeInfo[] = { {EFI_IMAGE_MACHINE_IA32, L"IA32"}, {EFI_IMAGE_MACHINE_IA64, L"IA64"}, @@ -705,51 +701,15 @@ CoreLoadPeImage ( InvalidateInstructionCacheRange ((VOID *)(UINTN)Image->ImageContext.ImageAddress, (UINTN)Image->ImageContext.ImageSize); // - // Copy the machine type from the context to the image private data. This - // is needed during image unload to know if we should call an EBC protocol - // to unload the image. + // Copy the machine type from the context to the image private data. // Image->Machine = Image->ImageContext.Machine; // - // Get the image entry point. If it's an EBC image, then call into the - // interpreter to create a thunk for the entry point and use the returned - // value for the entry point. + // Get the image entry point. // Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint; - if (Image->ImageContext.Machine == EFI_IMAGE_MACHINE_EBC) { - // - // Locate the EBC interpreter protocol - // - Status = CoreLocateProtocol (&gEfiEbcProtocolGuid, NULL, (VOID **)&Image->Ebc); - if (EFI_ERROR(Status) || Image->Ebc == NULL) { - DEBUG ((DEBUG_LOAD | DEBUG_ERROR, "CoreLoadPeImage: There is no EBC interpreter for an EBC image.\n")); - goto Done; - } - - // - // Register a callback for flushing the instruction cache so that created - // thunks can be flushed. - // - Status = Image->Ebc->RegisterICacheFlush (Image->Ebc, (EBC_ICACHE_FLUSH)InvalidateInstructionCacheRange); - if (EFI_ERROR(Status)) { - goto Done; - } - - // - // Create a thunk for the image's entry point. This will be the new - // entry point for the image. - // - Status = Image->Ebc->CreateThunk ( - Image->Ebc, - Image->Handle, - (VOID *)(UINTN) Image->ImageContext.EntryPoint, - (VOID **) &Image->EntryPoint - ); - if (EFI_ERROR(Status)) { - goto Done; - } - } else if (Image->PeCoffEmu != NULL) { + if (Image->PeCoffEmu != NULL) { Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, Image->ImageBasePage, EFI_PAGES_TO_SIZE (Image->NumberOfPages), @@ -939,13 +899,6 @@ CoreUnloadAndCloseImage ( UnprotectUefiImage (&Image->Info, Image->LoadedImageDevicePath); - if (Image->Ebc != NULL) { - // - // If EBC protocol exists we must perform cleanups for this image. - // - Image->Ebc->UnloadImage (Image->Ebc, Image->Handle); - } - if (Image->PeCoffEmu != NULL) { // // If the PE/COFF Emulator protocol exists we must unregister the image.