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.