From patchwork Thu Sep 20 23:01:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147168 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp99892ljw; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYooBWNKa/IoEVKU0vaLulEM3gVZ3YhByvvInEynBE/mmml8TNNSszzKId5ZalF4kpMBaCU X-Received: by 2002:a63:2541:: with SMTP id l62-v6mr8459607pgl.343.1537484514200; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484514; cv=none; d=google.com; s=arc-20160816; b=oHxgWhf7wq4sSdkkHNgO7F91a8FvlEwGywLEmkcCFTcnetgefRvj2eaSHvcy7ovofn U5IbBzx4FV2KUZhQXzc4SxmKtnzrmp4iHSrPWwTKRKXI5tzWHWyBkEWTflQpS+kxYGEU pfTVTLoTdAuGiqV77j48SQmLOq5D4+PtFeec6/7b6zrtwwDbsdPn4x+pIZMOThl32goz fmiXIMXMJhT+MImpKaKwTf/TGHsp4T5Rh26yoqHdb0sRCsh03by8mMpeRp9h10TExeZt AxtlD51OsWqi2//svlajWGY/JB0zLC6FgUTwwBmgbPuPwJFsVIozycRfD4uhrYEiAIAo iXNg== 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=uBKchTVFjOHCFOsPTBXsZXUtKfRvOhuhqpBLyK/qvzw=; b=dXAUarhke23laMhp9uYivE7RFrVvD7ZGKAYpIGt9goWGeks4c3LW2GTUjDHyH23BUM yOLrFtIqzV4pR2oFtJcCIC6NonYzrECFmIsS8Oorr4pzyQsMZRt7A8vuYS6nOFYWUCvT jBsngEZ/hCH+PowCYYsZYG2r96960GRds5Hy1QlWg900LmBYQ6GVhCFCdFGLBK/JlHb2 sqskplbtjojxOJ2855Ya1Jrk/y3k0FRm/G1HajhTMvf/5F29a0EhC0byooNSbZy0UO+c 5A/cuVZbbxGbjHoRlU+YYFSBFkmsLyQhvy8Pbig/20NIDuSb/Zi9MaiKxF77ytUGlfHu gMsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="b9qGP//O"; 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 p16-v6si26056237pgc.82.2018.09.20.16.01.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:54 -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="b9qGP//O"; 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 4B2552114A6A7; Thu, 20 Sep 2018 16:01:53 -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::644; helo=mail-pl1-x644.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 122F52114A6A0 for ; Thu, 20 Sep 2018 16:01:52 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id j8-v6so5007774pll.12 for ; Thu, 20 Sep 2018 16:01:52 -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=RKa6sk950nx1X6j2UPTyWtqZoR5yEDEcdm8MuqIXrfA=; b=b9qGP//On9S14EkVlPe0Zx/ymuRCzqUzF4xMQGQnvBAzinNEBU1QtJ4Jr2m0GCeili 0xwTOpkvOdBbuY3UCqU/r60zv9YtNRD2St4o5IYgpJ5VasZnnxTo1kgitp1teqA1JEX9 uoBWF7A+TqUnLlAyVeFPRbpibPrcBeXmGqkhg= 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=RKa6sk950nx1X6j2UPTyWtqZoR5yEDEcdm8MuqIXrfA=; b=YYps3HdWywQIDlEF++rnguKomE3Iibs01L5oM6acw2L/v+W+2PzK54EFuxt1hKhX6d M4MWoxLQpymq6rzw7NsdAR/B8bPy90WdU+lcZ/qu4W04LBhGEeB41UkSKStYU2SMoW4C CF2/DD0BQ4nET3MstJDNmfy3sWvDzENszVsGiIw0J4dzfXAIwNvosSVWDal3u2PUTydx Fow0JIOvtBzHU5bm16cZ7y/BrQ9LycJzXsNgiWsjK/FI8Yslg6HW3gzLSi//vHVm+ie7 qt8cDsN6K0ZRoOh/UjYsWubS4Rm7zYNRr42Bi+mJ78O03L40XTv570Vfz9/Zz3Ot4sh8 Eo6w== X-Gm-Message-State: APzg51DxA6siAwmDp4T76+DBK2FHmmt5g6E2uvAMRnDyaxYMbicXBINQ 2rcqQKOXOMc/awvgOoKyautQlx6gY/g= X-Received: by 2002:a17:902:8345:: with SMTP id z5-v6mr40776919pln.147.1537484511483; Thu, 20 Sep 2018 16:01:51 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:50 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:39 -0700 Message-Id: <20180920230145.7565-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h | 102 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 4 + 2 files changed, 106 insertions(+) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Signed-off-by: Ard Biesheuvel diff --git a/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h b/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h new file mode 100644 index 000000000000..27bad556209c --- /dev/null +++ b/MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h @@ -0,0 +1,102 @@ +/** @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. + @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 MachineType, + 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 + ); + +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 Thu Sep 20 23:01:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147169 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp99965ljw; Thu, 20 Sep 2018 16:01:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbPWRXDwDp4mKL4EmhJ1IXOxCpMt4oUhSefdCD1MavAAo04bp7i28aE6V5+7jR0MnLIcbY3 X-Received: by 2002:a63:3207:: with SMTP id y7-v6mr38999321pgy.101.1537484517829; Thu, 20 Sep 2018 16:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484517; cv=none; d=google.com; s=arc-20160816; b=jSZTYQM6XK5qy50dmJnNn2TUaS+ex/KGR6yLzclKYceKaJyUNU0rL5LkRdAdR/O2Eb dE3zCvnWzWuS3BFhpThnEtQCBULRE5sfIxfr/e6b8QoesJZHIodThQ6c29gG1A5Un9hy 383ZRLYrCIj1JTzCXrs/qyCHzeVUutIWbTk+MtR5ciTVV1bvhqVC9EteAxnBJJ2Tf3nS N6foQR4q3XMFgXNpcqJpWjVaV5l8jtVWYT5CKkSuVqQc5tQedzquqO9trB2bR5pCeFQF b7XLtIQbciHqp15Rh5OszEre+gXICpfh098fUVpwmLPEIy3HZYZQd4EEpSxkWZ3IrR3s TEpQ== 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=YzkxBza9TP7noUwn42g+HXYxgknKZFfGzjzjFhUfp1M=; b=mRikDq7QPiMvM8AjWt0AdxDnwdmZ/WGrPQ4/2oPztum3rHWUn+y4V56KbPK/d3aCw+ jI2mv+mhnmEo2bsym4LiltBDcyI+HLkbV8Bytw2PPpISK3drec7Bm2fZB5uMkV75UQq+ e42V9UdmSBYU88Zsuz36FQFlnBhxNfulLUXWEy9pa5S3+oEQ1gZPHPOttxArRzU5Yqz9 qv4GEVGvc/xE19UFF8fe7tdlNZG2AmvxFwmyGCtAV84TApjmys5Zm990hTKFP4MsfM7y khma+Ug8mZrgxP8OP7Dm36c9gyyxnC2wZiBbK5Asa/d6EGkn3rfSR1NJPRHKC2XgA8GR q8gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XFUxCUYP; 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 r2-v6si23988023pgk.452.2018.09.20.16.01.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:57 -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=XFUxCUYP; 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 7B43C2114A6AB; Thu, 20 Sep 2018 16:01:54 -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::641; helo=mail-pl1-x641.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 B8A0721148ED9 for ; Thu, 20 Sep 2018 16:01:53 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id w14-v6so5020917plp.6 for ; Thu, 20 Sep 2018 16:01:53 -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=0+ayhj9g+JFy2E7nqN1mtbqnYOoYL8T7VFgqH5NlwNU=; b=XFUxCUYPvcIeA2nTjMUbyZvnzKJfGyOuD5MeMAvcg8KEcYRoggK/AqCBjoWdDGr7le TJqpkZIMZ/s7onp9ZXZtWNm3braiH7bIiVnFp7CRlXgcRoRB8eK7rztxPfnVgiGtJGt2 B3cS+6lqhZDePRSP4fDGIthNSYn0e05OinipQ= 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=0+ayhj9g+JFy2E7nqN1mtbqnYOoYL8T7VFgqH5NlwNU=; b=qWYSyD8s3TVKqdhXRnsV6bE5GM6P8VL12a5JgVQkqLJzkWDTMtkildFyPM9LxCNl9Q +++KXYqTZ59shIUsdC0jQ2S62o0LBOfeH+EdTCT5MouirIifV7JK15Mf8EWJRujmqJmm XB7DGLZ3HsSwmy6janess2QnBlOCg7fPCUk/34H+N1sO6r1ZCm9BuGwZHxhcK6GHCS5k f7Y4fRzS/YEp3xj5aR9ScoMhuq2lvMk4PL6spl4cXMOCF1GktWUm/Q3EOxvIHtMLEp9l wjwlYYTXzkBDLdr2VDF4KGu7g4uzLu0Gv+lhZLFfLgUdGaSeAIP5HjZtY9yc6V+Tk8ff sW6Q== X-Gm-Message-State: APzg51ChmsMWa1B+5QKkqC1iv0V7IOaJXCkHJGaBti5mHaxA0Y2p1FE3 c4g44aenoW3MyRNP5njr0GLwnsxiSWk= X-Received: by 2002:a17:902:6907:: with SMTP id j7-v6mr41672542plk.323.1537484513054; Thu, 20 Sep 2018 16:01:53 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:51 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:40 -0700 Message-Id: <20180920230145.7565-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/DxeMain.h | 3 + MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/Image/Image.c | 139 ++++++++++++++++++-- MdeModulePkg/Core/Dxe/Image/Image.h | 1 + 4 files changed, 133 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..dd987f7fcea7 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -29,6 +29,14 @@ LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = { } }; +STATIC +EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *mAvailableEmulators[MAX_NUM_EMULATORS]; + +STATIC +EFI_EVENT mPeCoffEmuProtocolRegistrationEvent; + +STATIC +VOID *mPeCoffEmuProtocolNotifyRegistration; // // This code is needed to build the Image handle for the DXE Core @@ -67,6 +75,7 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { NULL, // JumpContext 0, // Machine NULL, // Ebc + NULL, // PeCoffEmu NULL, // RuntimeData NULL // LoadedImageDevicePath }; @@ -118,6 +127,41 @@ GetMachineTypeName ( return L""; } +/** + Notification event handler registered by CoreInitializeImageServices () to + keep track of which PE/COFF image emulators are available. + + @param Event The Event that is being processed, not used. + @param Context Event Context, not used. + +**/ +STATIC +VOID +EFIAPI +PeCoffEmuProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + UINTN Index; + + for (Index = 0; Index < MAX_NUM_EMULATORS; Index++) { + if (mAvailableEmulators[Index] == NULL) { + break; + } + } + + // ensure that there is still room in the emulator protocol array + ASSERT (Index < MAX_NUM_EMULATORS); + + Status = CoreLocateProtocol (&gEdkiiPeCoffImageEmulatorProtocolGuid, + mPeCoffEmuProtocolNotifyRegistration, + (VOID **)&mAvailableEmulators[Index] + ); + ASSERT_EFI_ERROR (Status); +} + /** Add the Image Services to EFI Boot Services Table and install the protocol interfaces for this image. @@ -192,6 +236,28 @@ CoreInitializeImageServices ( gDxeCoreImageHandle = Image->Handle; gDxeCoreLoadedImage = &Image->Info; + // + // Create the PE/COFF emulator protocol registration event + // + Status = CoreCreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PeCoffEmuProtocolNotify, + NULL, + &mPeCoffEmuProtocolRegistrationEvent + ); + ASSERT_EFI_ERROR(Status); + + // + // Register for protocol notifications on this event + // + Status = CoreRegisterProtocolNotify ( + &gEdkiiPeCoffImageEmulatorProtocolGuid, + mPeCoffEmuProtocolRegistrationEvent, + &mPeCoffEmuProtocolNotifyRegistration + ); + ASSERT_EFI_ERROR(Status); + if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) { // // Export DXE Core PE Loader functionality for backward compatibility. @@ -425,6 +491,41 @@ 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 + ) +{ + UINTN Index; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + + for (Index = 0; Index < MAX_NUM_EMULATORS; Index++) { + Emu = mAvailableEmulators[Index]; + if (Emu == NULL) { + break; + } + + if (Emu->IsImageSupported (Emu, Image->ImageContext.Machine, + Image->ImageContext.ImageType, NULL)) { + Image->PeCoffEmu = Emu; + return TRUE; + } + } + + return EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine) || + EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Image->ImageContext.Machine); +} + /** Loads, relocates, and invokes a PE/COFF image @@ -473,16 +574,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 +786,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 +983,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 +1715,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. diff --git a/MdeModulePkg/Core/Dxe/Image/Image.h b/MdeModulePkg/Core/Dxe/Image/Image.h index 5cff84fee094..021d516f46e2 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.h +++ b/MdeModulePkg/Core/Dxe/Image/Image.h @@ -28,6 +28,7 @@ typedef struct { #define LOAD_PE32_IMAGE_PRIVATE_DATA_FROM_THIS(a) \ CR(a, LOAD_PE32_IMAGE_PRIVATE_DATA, Pe32Image, LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE) +#define MAX_NUM_EMULATORS 4 // // Private Data Types From patchwork Thu Sep 20 23:01:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147170 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100020ljw; Thu, 20 Sep 2018 16:02:00 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda4E9KjSV63bH5WrbYBvlZp1p/3lyt2nmmy/N4fnuMnTjejxlBYXC2MHdbGHdk9TUul7nr4 X-Received: by 2002:a63:1363:: with SMTP id 35-v6mr38755570pgt.202.1537484520747; Thu, 20 Sep 2018 16:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484520; cv=none; d=google.com; s=arc-20160816; b=EJtcq8N0dHq0dfNs9nQOR5XVF7+s/IkSEoITgMtsfDe+1eUeqXDqczXY3CdMy3prx4 WkWUvGqXIqwi8IXDRAO7O7TDJP3apS8psxau9EnqFQw/vc9kk8Pb3E9J6/adPKBBUCCN Wys3N6JOrUaPctutvHVovJm5WhqwH9zzJOIn1k3/HDnm3aw4zTMrPfp/6Ilc5hzcm0R8 TPxcDvmcvCtNVBpg8l9giCwN1CPziZEld3m/DewBBQ+hPlZdodczgBWMI7oCtbj0za+b Go46BQ7BV4bYQhS3GMK77qIUaHK9LzVEQy4K/wofoAit/in5wYpdC7IlBox5Oad/idB8 EMwA== 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=iq+Hxe7lbm3PDva2peZGCyJKhxn8CseURCeFgoSb+Jk=; b=ltYsPAWtACOd5bmziDE951RctdJ0jPoscEHJ0mXoFlEzNMQVkorlrFPrAxThNTzjoC B0n9bDAytV0fsrb4u3BsnQu8dCXQF5ZYX2wT82cjKi1KJKOl5aq/U5GQdf6gapluDDjk Wk6qXuotKxUFPX1980yDvH/X8WkjWkmlbhN9EmHMXpEgdM0LghrRDAtrom6Javvt6+r+ OJHmEDyxT/sKidCCAi/UJxUKS08wHldMb41xS7nk6GGwb1a8RqlLiFOMV3n5zlzgydHp zd30544NMLEU8X99XBBE0rDJMArJZkO/rMbupsaLu5G8iSgg7j504TKJ1KQOVZlaVHQO up1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hw3KEiIQ; 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 r34-v6si25307043pgb.656.2018.09.20.16.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:00 -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=hw3KEiIQ; 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 A6E312114A6AF; Thu, 20 Sep 2018 16:01:56 -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::62d; helo=mail-pl1-x62d.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 E507C21148ED9 for ; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id q5-v6so1552240pli.4 for ; Thu, 20 Sep 2018 16:01:54 -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=NeNO2yxxJHj3+5x/STZPGsImoQ1uwGw7nU4vxibZh1E=; b=hw3KEiIQAtwAUw6COAW9iMWCMhxt1au+eseDQHZUXK1lQjC1u72zavK0KUn8I9SLtq uRI99faJcgbx6Pdv4CWKe5MgNpBkaktNlVxZ4ircVtxP/sxpPdR4mYnQPW8pppLWvt9x KL3u0EtrXZoBz4z5y9pXa85fJI5ccEv9jtJUA= 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=NeNO2yxxJHj3+5x/STZPGsImoQ1uwGw7nU4vxibZh1E=; b=YMkrPChmFxdS5zpGW7CfYzaUnu3mWl/UKWsWcic6lZ3KCkZs8xcpl7v53+6HYFrOm3 4cvo5T/zaOY/XmEH8MyEEZt5M9GrJflZizrWapObicvpL7GxKsAFp8W5tNudY+WsbPob 3QH9Z5uyPKzOVJoyH5mXUoi+CtVHQe50vzfPErVy1GOltE1T53Sf/Vp9mLyDwyUtbUGo C0eopo9DJ3X/BbEiU1CqIfORP2puI9dmu+reWercJpgnI0n2ENE/IYIJRreLhmdak3SX rZdosqy3WnhY20WN/9Kdny8YS+y6/TF8FsdQWdwHdFVd7h+kI8d57vtVUUxg/KyWv19x GBZw== X-Gm-Message-State: APzg51Dqrozrtdr7BJ8eo6dBaptCqtRZe9AYdLG9yg2hs+mmsHogiQ2v T314k9yGSEJ9zQYhjEBVZ/Uy50quNR8= X-Received: by 2002:a17:902:4e:: with SMTP id 72-v6mr41191567pla.318.1537484514241; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:53 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:41 -0700 Message-Id: <20180920230145.7565-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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.1 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 | 53 +++++++++++++++++++- 3 files changed, 54 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..085bd5d571bd 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -651,6 +651,55 @@ RomDecode ( } } +STATIC +BOOLEAN +IsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + 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, DevicePath)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Load and start the Option Rom image. @@ -715,7 +764,9 @@ 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, + PciDevice->DevicePath)) { goto NextImage; } From patchwork Thu Sep 20 23:01:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147171 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100075ljw; Thu, 20 Sep 2018 16:02:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZWWm1yWPRzWek6oTqxe2vOQZm0gruclQ0erd7R0Er1RFnF3TqUGWg/suZnHkS1mrjSvqz1 X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr41313834pls.88.1537484524274; Thu, 20 Sep 2018 16:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484524; cv=none; d=google.com; s=arc-20160816; b=twHyI6nNxAM3x+cS2D6kSBiR5CfWuL5m93vVKP2RrZJZcoWyzY4LAoR5EZ27BBhJFO 2t9CTurCpj+mCHqE71opbrm7Nnf/Lieel54eRRs10P5D9G9ogM44Bkleukb1d+RGKuqF cwoR9/PKKO8kKzgPs/by2XcqwanFyDp0VDD2xEM6GNDmpw+23QHuoYlVHfEy6SfUI4Ia ulrk4+BEvNgwEq/tZQd6DBta4Ehfcabb/dDNdUqwKlYewQQtIZ0gXwAaGfBe/LzHA+T8 8iyEBagLJzknhOxvkCuucdLtDdjcJJnWCZNUuMIaZEY/gBzXEa9cIJMJI1cIwEWd9xWa X8Rw== 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=Awf1dD2iPMN65CnMnr4YUsLE6f2Grh9F7EZBNJH98iU=; b=d1yRAhtJ1ICNZKv+IiySUyNKrbpA3Pnb3QEN0yq6psRUaXmEk0XJGBc4zivrPRVjwk /q7n5/Kl6zfl8JIFq8U2db9VTA2f3DjqNFPotijBc+XwG0hUK8eGZMTGD6Z2ySCd8clh ChKNoqwJpcLwyuzXFm5lM+gWQ922BVYwW/n+pSQMBNu9lXZrGZGR+o/PXt7by5WrNTDN +Rrri2Jd5Bq5xsc66mMoh+VGxouHqRHtHQWa+eV9r9cYfhIlrDvlvNGkN3OzbpU51KsK E5rvFozUwQrRrdLsWKtdqeAWTIW/mder9LvDff12pMdk6XaPRdlWTKVvoBEiMHb1QJCl 7uQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Hrisa28h; 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 j10-v6si25992375plk.406.2018.09.20.16.02.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:04 -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=Hrisa28h; 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 CEEFA2114A6B6; Thu, 20 Sep 2018 16:01:59 -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::641; helo=mail-pl1-x641.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 CC30821148ED9 for ; Thu, 20 Sep 2018 16:01:55 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t20-v6so1587701ply.13 for ; Thu, 20 Sep 2018 16:01:55 -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=Puva7D6n7qs6A7mDCY6+0VGyWDnCuLuLCTtGt47XCTA=; b=Hrisa28hAjUTrhAJEOjl0Sw2ZNZ4i5JH/zt3QrcQsNOjntm0j/46jZ3TrQmfarDW+J CQM+q+JVmO1GkMpyx9Y6b3T+/vrvk+vuY38QGjyuZY2l+eo1o8HgkK4vHXAhaCtVnK7t hEfn+bXwebUWn1jreJrtb4oTU4J6hKzvBtjGU= 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=Puva7D6n7qs6A7mDCY6+0VGyWDnCuLuLCTtGt47XCTA=; b=QCksZRyb1+iaKtcTo5eGgS3iscrSAAp2y0EFZ8KhCD7SOpIndwV9hEXX+hHpwPOET9 yVwuL2SkPcR5GvVTBiwSjEOhZJikuH4R+yAJtOqsazUmMUeWH1qpFTC0RWNY6oa5oT4q aEeZ549vC3OBRsRQLzrj9pn7hha4Z6y2ZLZaIIqK5C+UuN5citqfgK4l6avWKJLMrboV hcYboU/gcZh1bP0qGp0lg8Sl0Wxu3bEJbxXyq0IzDeNb12SMJxLbLwM7bHAf1B8oaki3 per9DI6oZRaDJhywLyXIDFM4/EPZSCsNcde24pHeiRQAYOjyxpMUZmnaG44lUUJ6NRGz D9Vg== X-Gm-Message-State: APzg51BXyTKXeeYqQAchTcy+N09Pm4aGVRWfYhjhsgCZFB/WrwTEtlqh y2x1vy5qWQ55FMZLvra/gH3KsBphuKk= X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr41747185pll.256.1537484515349; Thu, 20 Sep 2018 16:01:55 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:54 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:42 -0700 Message-Id: <20180920230145.7565-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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 an 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..f6fda8f2c3f7 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, NULL)) { + 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 Thu Sep 20 23:01:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147172 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100130ljw; Thu, 20 Sep 2018 16:02:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYSSM+639m7eX+9n0f82OHmBP17sqQZu3rjBizZHBp6J/j6PxIldOidI6XzC7CFgR/NeCOu X-Received: by 2002:a63:fa49:: with SMTP id g9-v6mr26837914pgk.18.1537484528073; Thu, 20 Sep 2018 16:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484528; cv=none; d=google.com; s=arc-20160816; b=J+0kzRnEAaEpRNmt+PTfl7MlfnJOEdjnRRzs4rTag2X39ZhiDsr6gC7zXYg+QrvIHY fHQC7KcH9hc1KF4dCM/hi2Xt4jIch8dW999D8ScEz7RQRitWd11bzHqhp48qTFoiUKIZ aanR6SvA4CMBeyVaXED3QMMp+2ogz6hQ5hirK6NIAm8v7o0bpYTuz8mRcjl6yFnhCnex aTICpDumeM0JclnCa5H7jr+9lpwQhy8xilBvO9/Xa9i6NyH7suI3WUgv8Qqgcly3v7FV zRVMEnXYqJZm8VleVST1umcxekoWqL/vqOQ6RU7+fSpvx03BjQqFiXRQaLSC2TLeSXyU nVsA== 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=2SD1NByA8VD7L6n94QwMaYxVuipHOrEGZE5ilaOwziI=; b=O18WLyZsqSz2gzVwmeOpYUFrWeCBzbJLtFVqzh1EbFzCYfh6N5YB2vLS1RRzzkPu/L k6rY7nRINeRdxljWoZG8NRi7qCP9kO5lq3a2CuMuYn7RbV4Kd4U4Rm93SUSImikVVyfF kutiSFdHxvj99BXbiUt1L8cVtimRNwDObrkKNbqqZtFUMwWkk5ntOYQugLV2SLkHumQ0 IaCQ7mJYFZXTjX7m+vG9xh4QYPwzFHGyl01EWYfjz9cKRM758q1Xy//gP/K2edZ5vq/R z71rObh8eLD2DJu/FmYjtuMv3hdSwbtO0QXt5I4U2NMXlNhY3uG0PS3h32QZwAO0GamT K3pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RdwdkFqS; 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 f94-v6si17992109plb.10.2018.09.20.16.02.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:08 -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=RdwdkFqS; 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 061932194D3B8; Thu, 20 Sep 2018 16:02:00 -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::543; helo=mail-pg1-x543.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0: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 5DDEF2114A6A1 for ; Thu, 20 Sep 2018 16:01:57 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id q19-v6so4248050pgn.10 for ; Thu, 20 Sep 2018 16:01:57 -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=QZsxm0ylxN5Ie88kSOXV1CPT8vEwy5q94Cy3QGVEpvA=; b=RdwdkFqSFHHGIWVf9Ki6Ve3AOwj7G/HagrROkt/lkQX/GGNEnQOrrygagT7mJRS253 umI/2/zR4GXc3RCDOI0kfatcGA5HcrQsvrQz/o3F/WtFeXRoHpVsZAJZjG+8bj/kzeNu qQ0ZqDbE8gmFBwPKHjttBCfy5dcbNiZYBuhF8= 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=QZsxm0ylxN5Ie88kSOXV1CPT8vEwy5q94Cy3QGVEpvA=; b=TfYLKOAQdYMvxr3RV5ouecc6nifsSe9gFQ/4JZ5Qsy8Sh970IyAjugdiCLgb6dM/Yc ofi6NGI+K8GnGBqvSFKIN8/ktQ07HptPxAzhAadKLr1q2g374NkUCoD7rgDBMBr+sv47 61MyynRdlVqcUQniVXXAdDidM19Oi4MPLUvAaFGcNBo49ydE6F1X6ogkS/ZRNvOUtv+O 1pcnGhdYZQ8p1XuKk+T1lukQavaCpnfuplRTax0Viv73X5/wZiTORy6ra4/waZTfWRpY +id02wmwdQVCArvFPI9DH++3/z0acnRtfLiFDv8MZuRfpbDHtPruc0wStrzx47wrYpJx bZuw== X-Gm-Message-State: APzg51DRRiX7jIF9VzSGLLAHnVzetm12S/BCWbPW6kBZNwgS5iJ/52Dc sHB+dPXrTlpjq9j+oCj5qsia7nO0Xsc= X-Received: by 2002:a62:c8d2:: with SMTP id i79-v6mr43174697pfk.35.1537484516770; Thu, 20 Sep 2018 16:01:56 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:55 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:43 -0700 Message-Id: <20180920230145.7565-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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 | 127 ++++++++++++++++++++ MdeModulePkg/Universal/EbcDxe/EbcInt.h | 3 + 3 files changed, 133 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..45e5da1823e7 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c @@ -349,6 +349,123 @@ 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. + @param[in] DevicePath Path to device where the image originated + (e.g., a PCI option ROM) + + @retval TRUE The image is supported by the emulator + @retval FALSE The image is not supported by the emulator. +**/ +BOOLEAN +EFIAPI +EbcIsImageSupported ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN UINT16 MachineType, + IN UINT16 ImageType, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL + ) +{ + 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 +566,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 Thu Sep 20 23:01:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147173 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100180ljw; Thu, 20 Sep 2018 16:02:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYazBOgAiJ/8Hpi+xRSM/G1g6O3Cv0NnEtxfaj4WP5LtbQoOraZx8NVLuJUTUpkaC6dfZhS X-Received: by 2002:a63:2acc:: with SMTP id q195-v6mr35746205pgq.291.1537484531606; Thu, 20 Sep 2018 16:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484531; cv=none; d=google.com; s=arc-20160816; b=o2L9lGC/hm7F5/OI9Vo+hUz16xTHwGSUIz896xMYEcC9fuGWLx2QpKnqVhIqfO4SO/ ocbz/4PJ4hZNoMlku19Os20Gu/bNvQXVS1FrOr9mZaj46TG1yCGVngXxUbsE4Halpxsu lgm73B/rkd6ssArvDk6IePqSX7T0Rev98aHyvSWCdv76fXoDERG229TNGnF9L9E3gApn yPFkLBgbK9BBCZCVvevjnZOlkhC4PGbA2kO9n09ouBj3eWakQBVCpC/v0/bQsRV1z6iF BCRSMPXxwX2Pz4h16MwxROOzv5V4PjlxlussGfVCzVPGFEnbZDsEQJQHNmTaN2sOPAJl n/sg== 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=IZYncyZs4NS1F5lZpZhRlbC15IWEBAVaPoDSdWnK1iBIhRVFTeBXcsUoHO5DJJ+eE7 EsEwW55GnAlJeb+7166DzO2rU6JX2XM+fkmLkfGY5DG7k1jQOBs/jFCpr34dxyOPteWE p3c9dkBcCqaFVNomBMolrTtXOysQVZjI24YsHnTV/SFe3B9UnGzirD7FnjpuGuPjHzfI T/Hv7baOf0DZiog7LmE55WE2w8lLrBZGp80Bd030PSo/7aje9/nshZgbwNJ8BX3HFsX2 MSGYr1MybVBFdTD+7YLyAYWX+H8UfFCADdtqG6r/WALNLXmkMZAE0HpQSTZMpmsG9gdl 5PcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=f58H5xT3; 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 y18-v6si27424347pfb.161.2018.09.20.16.02.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:11 -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=f58H5xT3; 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 2FBD921BADAB3; Thu, 20 Sep 2018 16:02:00 -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::544; helo=mail-pg1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0: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 6EDFB2114A6A1 for ; Thu, 20 Sep 2018 16:01:58 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id z3-v6so139941pgv.8 for ; Thu, 20 Sep 2018 16:01:58 -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=f58H5xT3VcR711Vs/qcM4hcaBxdI5g1CocDEwVy3gLAhhdtlElkpXzZb8XHojOId+o K7c8IyYrwPcGwcynneAGdJ8Gru5P6/U1oZQojxsO2vCbfSpPNNEBlZ8oklXnQJKirQzZ +ZN2BuZFMYRJcezo2KXoeBAKB0gSIEXgtem2Y= 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=X82C896/sDVyts6BgeM436u9AOfdInha9m2Ofp0JM5WA8biQWiyeh525Qzsqq7w9zb a8elZKlGEyx7f21flDkyHSpWqqQqb5wnBgZN3ZLGUJ6bPty2wBSIsvYHDypfo9Mr6t0A bIy5XoFiNujqRle6QqyTFzW0M3jQp1w8w/K81G9szjF8Nk7syVZQ0o4gCu9qT8HXpxvr 0JT3+DzDvNfNEBX3I3kR0HywYDEuueAk/r2NUfpHH0CNAsv0GVqR14YjyGB9O3DJ7moS 6cVuCU9FDz31YpTNIYpfoAhP3RVi/J/HNJpuYNutbzL2wzCODLAwC6J5WVAQkUCynoWQ O0zA== X-Gm-Message-State: APzg51CYXjCOvHa8uiVWMJwAjSr1gu216NZmupLy93TPu+BSpbmNZHcN AKRlYzBVNfVaM9j/GwV1ERns7CB/Qbc= X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr43006537pfa.63.1537484517902; Thu, 20 Sep 2018 16:01:57 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:57 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:44 -0700 Message-Id: <20180920230145.7565-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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 Thu Sep 20 23:01:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147174 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100223ljw; Thu, 20 Sep 2018 16:02:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbvP4h5FbMIDyrppAnao635YFziV6Di2tt9J2xxVQI697d+//GPcz6ehx79FSa86qznmo22 X-Received: by 2002:a62:9349:: with SMTP id b70-v6mr43883468pfe.193.1537484534985; Thu, 20 Sep 2018 16:02:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484534; cv=none; d=google.com; s=arc-20160816; b=YSC22rzAKypwsciy/tzooj5cZ+Z/sPT23L31ZAkHxI/OsGjsOualwH1a4P1xegI4Pm L87JiBUY1xMoNp9GZVEnpRcOZRZP8ldlX0JEDeUQiVE78wVTnjAB3cQIdYV0s4w6yiM5 0wqOUPqlG2X5anz/tFPvq88ayXzIl1TMC9JYN6bydJd2+IyxwWK6EXIc1hlZENMug8rJ EPSwc8qQh4Q02alBbJMoBYJywfZws6bkzbLFTF+cZze+vmC6QHaVZwR9mwZHP2p32LsF RflsGJhseMy2/SB3L+/wRaFAQPGOAvzRwRz5mJfTRMkuLWLj0KYh5Owj9VrhdmRuUuwW aCoA== 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=dkzmrFAd6KCZTcp0Ti63S5GwlrAsmXXw/NNb1sdj8Vc=; b=pfFjfMG4knGJvY7TpSrY+d0sNlRq/TvQ1cRFkFkDWoHgdIu8zi+FT3ajLCDTaUUDXA E9U89Nhownw/oQiBwG1cxfnjWH/5o5GWxd555EtcwZ5oVq8Zcc8I93ioX3NBcRlYmfR+ UW0rdxgQE3MgWW8RX1oab4UD342nNH+G6r+VpAkrWSZQYGyy4LP4jkSHVpvxQffV4vmB JE7Y17fowHfi+Izwp0UrmBikJC/i+COExrHkCjtS3lAtf3Vh0y6TIvAhaQYZMg183fH2 kW0ypzJi0uZGOh2rqXWEz5EQAmqP0OdoP9JWlMJqghzpwyyHVOuMyFzkSDSRJYs2nbkp u2Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GTOGs6tx; 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 l12-v6si6703516pgj.76.2018.09.20.16.02.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:14 -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=GTOGs6tx; 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 5AC552114A6B8; Thu, 20 Sep 2018 16:02:01 -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::442; helo=mail-pf1-x442.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (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 DDB5B2114A6B8 for ; Thu, 20 Sep 2018 16:01:59 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id k19-v6so5063467pfi.1 for ; Thu, 20 Sep 2018 16:01:59 -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=v73A6xh5lqYSrw/3CfUVlKZwqT6yWqMFc31EjjLPYjs=; b=GTOGs6tx6ouC6XrrPh8aSu/duDJPflMHCqoJ8fBZIlFt7oyvga6ZraYsMkvcbJSBVE nXgARLyNmQw+YKqzxb3iFxBmTGiShqOHRvygq52hf5lkDL+f6/3DcxAvyhPeTLc5rbFq oevZKmBOysJmvW8Azju21pTKGaE6vAnSuALXE= 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=v73A6xh5lqYSrw/3CfUVlKZwqT6yWqMFc31EjjLPYjs=; b=qU58pS9ixCFDJqIIkXgBB+Lwc5zd5JDBs/Npw2dH+5Asw4tLHdWB6LSAemvbJgUCaa GvBr83qzrjZRlBmcDRhoTdQcSV8tgexObFvVaDUeGpgrSk3YbAoFH9IqxNf3vxYTTWMi tfWS2XSH3JfXxHgPLqS1vwERyd2ZmJm7wpWspDwAT0xc7RUXMogWFUyZ4o+6tUFiR3KJ ZGSKZV0Pqnck0Q8EyhVDrndpo+uyS5Nu3gM2hAbAPw+BihTwfYDUfzs6z+oE9QK0ahYn BDV8UBNMl2ZNsDqdTG+fb7W7OXbgOC5UxeyoLlFBVaguZt1aCyEaNDsQxGrHorE4+ZCk qFRQ== X-Gm-Message-State: APzg51DII3XAX6hPbakka1J/K/HbzxuFBxlmRKIxeak8HIjExjmR+8Gn uDBic2BalxeSutV8XoIQAcJrrocFDyk= X-Received: by 2002:a63:ec43:: with SMTP id r3-v6mr32624366pgj.295.1537484519320; Thu, 20 Sep 2018 16:01:59 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:58 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 20 Sep 2018 16:01:45 -0700 Message-Id: <20180920230145.7565-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 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 dd987f7fcea7..53d526fddc7d 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -74,7 +74,6 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { NULL, // JumpBuffer NULL, // JumpContext 0, // Machine - NULL, // Ebc NULL, // PeCoffEmu NULL, // RuntimeData NULL // LoadedImageDevicePath @@ -91,9 +90,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"}, @@ -742,51 +738,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), @@ -976,13 +936,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.