From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: ALg8bN7cSvITz2M0GVIT3Oj+6vkgvR8pF/wXY03oCyJtNNhIGsQvAzdw9JbXhWHhhu3Wo6Q/IH3CXA== 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 Cc: Ard Biesheuvel , Achin Gupta , Jiewen Yao , Supreeth Venkatesh , Leif Lindholm , Jagadeesh Ujja , Thomas Panakamattam Abraham , Sami Mujawar 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: [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: , X-List-Received-Date: Wed, 16 Jan 2019 20:22:57 -0000 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(-) 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; } -- 2.17.1