From patchwork Fri Jan 4 11:03:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 154761 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp495705ljp; Fri, 4 Jan 2019 03:03:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/XnGuPQ4zwi1F27+QiFd34JcbJnNCSV9GWpdz9Z+gHn5RoSZIBVhVshBHXx8rA/h0rsKpf9 X-Received: by 2002:a62:4156:: with SMTP id o83mr51741665pfa.72.1546599826303; Fri, 04 Jan 2019 03:03:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546599826; cv=none; d=google.com; s=arc-20160816; b=CoL6r4cBE6F+fJ+5LWFwsTBPO8rh9LLdA5n3SHG234F2DNwQrWvbOutMd3jar4tnOE BPNMXml3Sfuw/YiIRfmNyqvO77lrTVjyExrNZB7bjU4bGEZJvsHvH3ZyRYvHjt22oWGQ MV4rPx2puv26g6BiGleR6zHr9PqX27c0xWyYn23WwlDC+PMnhDn39j8b/q1PZqzbZ5rU V2HdFaDowwTpi8Mi7OJYilC6aY2qMV59B3nEFT/030fOA6Nn73rebHuvN9u7h1bph+Ev nQIr3WdMDYNtqewHXu5g3UiqHZGc3YpG3gIhTQNXw8KXIsedAoT526JTRk+EB86aoqBr 2drw== 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=haDSKjUt0mUSM5wW4c3Yvn+c2qBFNIMEFNA81zJvRjtymeU1NM41CKz7SstVyUpW8V ImoeeXxbUNs3goNzOSZQMGu24Y3EVqIeqmBT+Y3v6stWtvywxI/OpNyITHS5zJv3xcYN kdR/3FPDBocC8+iZ/p1KjovbBBjDmt7kja8vq6I3v57aUmhZPjwwTc98grNO0YYikoBt d4NK0I8KP1SSGGdF5cvG591f/Gqvtf41H1gB6BQzmdt3tAYRUukoB+R2y8gYH0qDZwnU YbKdLvinKxEp+VzfO1JtFX5xBW4vpvj5odYw0+AlOyVw9OHCeY19/kLsAzTzZojceaGu e0DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MQ3C8ktj; 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 g34si36708659pld.15.2019.01.04.03.03.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 03:03:46 -0800 (PST) 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=MQ3C8ktj; 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 40D0D211AE8C6; Fri, 4 Jan 2019 03:03:35 -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::542; helo=mail-ed1-x542.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C23B0211AE8C3 for ; Fri, 4 Jan 2019 03:03:33 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id d39so31429276edb.12 for ; Fri, 04 Jan 2019 03:03:33 -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=MQ3C8ktjylO1tHUH2uHjsLFK9rF3qPaWGbQNCxmOND242wrxEo+I4TuWBna5ZofBgW CdN/hLjvvgs6hSaebmrs1VqZnk3Llez7gbSbEUl56qjPG+aeUppiNqmZAhZa/wmGNO5A AGv2M4h5AC6/qoHfj5+Wwgai+IC/AO8gdiWOQ= 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=dknR4635VeL7+sRk/KSgkYBbbD0azhRg1+L0FxMAt5Po01QOwhvPcLRoWM7VWgcl0z VvF3GnJVp2BnYmeLw73laoxMB4Vgy2C8yVqpDT7TetYkIkE4VNcvZbdnCTzySHKx9Ttj kOyHvsoSFC3usIxlkjdD1kp7b3NZRLnB8vuMWSzMX346URDbcdKQg44KINxN/0sTDrXJ fT5dSitXvmBwCiIz8fQlX0U7BIdEYGnOkRmwpK1J4joIiT7NyM95Lv8Fh4VsKDqinsr8 4JB9TJl4JoOJ84QXyvl72PfBAao/MaqEj3aypXR3wLnPQ9bsbT19pPpbsWX+JSDBkQH4 kaow== X-Gm-Message-State: AA+aEWbXvpoU1RkJOUW6aVuc89d8FwvozwWoWCa4nhmw6ObNittuJcnf yebxUjX3ITlgj0LZnI7NFkGDI2z1QbZ+0g== X-Received: by 2002:a17:906:1f09:: with SMTP id w9-v6mr38759271ejj.22.1546599812073; Fri, 04 Jan 2019 03:03:32 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:704e:c241:dc88:597d]) by smtp.gmail.com with ESMTPSA id n11sm26650578edn.14.2019.01.04.03.03.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 03:03:31 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 4 Jan 2019 12:03:13 +0100 Message-Id: <20190104110315.18339-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190104110315.18339-1-ard.biesheuvel@linaro.org> References: <20190104110315.18339-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 6/8] 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 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; }