From patchwork Wed Jan 16 20:22:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 155757 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1097118jaa; Wed, 16 Jan 2019 12:23:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN57emUlRfmRcAl8vzdQnQA9PB0vRJnp+M0dcCyaFzK9IQYw/Qszhc3KbAhsrFvbBYONczTx X-Received: by 2002:a17:902:4124:: with SMTP id e33mr11671148pld.236.1547670197584; Wed, 16 Jan 2019 12:23:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547670197; cv=none; d=google.com; s=arc-20160816; b=qecc3fhigsrw/yQzNKqVzZwtZqlPMuS3gvlolnG0GypSKi3ue5bt+uMKft6Sg8g8i+ /oVMQv5lQ1+m1mzT7kHfZoIKUuLrrz5VYX4Q1n9UnePWrYxagzS5WMsxKqwXBUiRznVO i1TquBo4cGCjG7H/4F1tI+9j5+fedrBy2mzJBtwQ8lfLnAuLGK3spaAeE04XQeI4DgxD rpob69w7D6cR0xdGXDCBqAnWxCT5UNRHpPFJlowjG4hmuZy5FfcOijBtRtvSeXiPStwK UuACu6XFoGPkMUTtt8Vw8kKanfgwelefbSGmeWkyzVULhq60SLn3B1jpEqA+J8GGsS2b ta0Q== 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=tEElhh10QdmMPt/ZNo8gYxyiLCvI4KxTvvTY9qkhCd4=; b=pMcoM2QbwohKzWLWgQS98QfnI/xbIkdMBEJjvU0tuyklDPonGoYectebnbAHVH8Ew5 A48vFynyIjK/m7E5IMgkWgAn3wNURyR+nnPFJg04e2+xY3PWRIukQLZBAJvRDCixxOIS lWLTNILS5xomEw0dbZvjxjAu+vIKsWZpWmbUdsm552nvpb6fAc9e09TPH7kilfN1notS BVw/d0MsvvEjKDTg1EA219VTGOjLOcJYhrmxjJE+RTEizLLbxmJrg7ohtl/hm+nrLPCH bB9TtUDI8FqO/9ZTGeLWlMjKDCD6TfRmR6H149OP5hU0lKg89vJmI7u6GrvczebQkWjd //Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="B3Fb/phZ"; 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 a16si7117375pls.146.2019.01.16.12.23.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 12:23:17 -0800 (PST) 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="B3Fb/phZ"; 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 2705D211B81B2; Wed, 16 Jan 2019 12:22:59 -0800 (PST) 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::442; helo=mail-wr1-x442.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450: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 32426211A759E for ; Wed, 16 Jan 2019 12:22:57 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id t6so8423557wrr.12 for ; Wed, 16 Jan 2019 12:22:57 -0800 (PST) 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=zrkmfQttdsToZzhBFzUUJUcrvh6u3Vf96lPFkeOEPvg=; b=B3Fb/phZVXEZcHyK7Z4wAwMEmaH92ng8Mlt8ipacyZfWRXBAntyABc2yykcmNns1d8 k0UKpE/QAE8B1FgIis1bahsB6JmwX4pZCzEPLELVG8LiF5sI6GO5RxdWR4kiHjGKeayA rCuUaeJEyJCfRjBFpCTrTu4+SzRS9BVRdkHPE= 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=zrkmfQttdsToZzhBFzUUJUcrvh6u3Vf96lPFkeOEPvg=; b=k9DW0en3Q37w3OU9bWEf76UH07JP14E9L9UKWiOZrUX4dOtbyaFAGsqJUgxI29V5xI SAernXimUj8J+Di4ITSv6cYQQOBRmGkPYjGBEeH574XArU1YelVcN+TBekTsgae03Z0n VCzXYZObhAO57hdRmfzmWJn0w0ZmwBdA2ySKJDiHDFlxlBJtW4MZBUOu4Y13glrnG0Kp aSchRJ3767+PIdaFyNyt7VjCZHwYyrkX+0xdPpqOgXEMykEiiBWzKgPRidO/KTrpXv1A w3YuLxfr6935xrixr841T5r/pH0Y7QskNzXbbebwMbZVwSy+vgSVIEivx5xMDiskMDNE xESQ== X-Gm-Message-State: AJcUukeinnISB6c1RWLeLAG50Ix3p4NGspEfKHDt6V3XxG9F0aHyorhZ oEJVSKyKEvZFMmaWvQfxs/YJ1QWA4XKkdQ== X-Received: by 2002:adf:91c3:: with SMTP id 61mr8679130wri.324.1547670175524; Wed, 16 Jan 2019 12:22:55 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:28df:207d:542c:1451]) by smtp.gmail.com with ESMTPSA id p139sm70901316wmd.31.2019.01.16.12.22.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 12:22:54 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 16 Jan 2019 21:22:34 +0100 Message-Id: <20190116202236.6977-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190116202236.6977-1-ard.biesheuvel@linaro.org> References: <20190116202236.6977-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 09/11] StandaloneMmPkg/Core/Dispatcher: don't copy dispatched image twice 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: Jiewen Yao MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The dispatcher uses the PE/COFF loader to load images into the heap, but only does so after copying the entire image first, leading to two copies being made for no good reason. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- StandaloneMmPkg/Core/Dispatcher.c | 30 +------------------- 1 file changed, 1 insertion(+), 29 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Jiewen.yao@intel.com diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c index 8d009b4f80c1..8a2ad5118d92 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -294,7 +294,6 @@ MmLoadImage ( IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry ) { - VOID *Buffer; UINTN PageCount; EFI_STATUS Status; EFI_PHYSICAL_ADDRESS DstBuffer; @@ -302,17 +301,12 @@ MmLoadImage ( DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName)); - Buffer = AllocateCopyPool (DriverEntry->Pe32DataSize, DriverEntry->Pe32Data); - if (Buffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Status = EFI_SUCCESS; // // Initialize ImageContext // - ImageContext.Handle = Buffer; + ImageContext.Handle = DriverEntry->Pe32Data; ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; // @@ -320,9 +314,6 @@ MmLoadImage ( // Status = PeCoffLoaderGetImageInfo (&ImageContext); if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - MmFreePool (Buffer); - } return Status; } @@ -336,9 +327,6 @@ MmLoadImage ( &DstBuffer ); if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - MmFreePool (Buffer); - } return Status; } @@ -355,9 +343,6 @@ MmLoadImage ( // Status = PeCoffLoaderLoadImage (&ImageContext); if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - MmFreePool (Buffer); - } MmFreePages (DstBuffer, PageCount); return Status; } @@ -367,9 +352,6 @@ MmLoadImage ( // Status = PeCoffLoaderRelocateImage (&ImageContext); if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - MmFreePool (Buffer); - } MmFreePages (DstBuffer, PageCount); return Status; } @@ -393,9 +375,6 @@ MmLoadImage ( (VOID **)&DriverEntry->LoadedImage ); if (EFI_ERROR (Status)) { - if (Buffer != NULL) { - MmFreePool (Buffer); - } MmFreePages (DstBuffer, PageCount); return Status; } @@ -482,13 +461,6 @@ MmLoadImage ( DEBUG_CODE_END (); - // - // Free buffer allocated by Fv->ReadSection. - // - // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection - // used the UEFI Boot Services AllocatePool() function - // - MmFreePool (Buffer); return Status; }