From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x22a.google.com (mail-wr0-x22a.google.com [IPv6:2a00:1450:400c:c0c::22a]) (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 EE8D1803A6 for ; Mon, 13 Mar 2017 02:28:39 -0700 (PDT) Received: by mail-wr0-x22a.google.com with SMTP id u48so99538943wrc.0 for ; Mon, 13 Mar 2017 02:28:39 -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; bh=tEebw+oVPVtF4DEAzBKDSyPNMc0MSAFpebrph0iMNe8=; b=PtGeg6oSwbmqumVgzvMNxCefF9prsSTAYuyL8XtT1Ciu4y9uu7MV4aXjusJ3ED99MZ 0dDkANbLSkY6qxH8aebz2R/1K/SfvbZnllOXbw32FhpPXR0+T73TDcxlB46LqkOronl/ qDbG8pk3fXm+WjRvzBkn7Of5eG+rHB5U/B6q8= 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; bh=tEebw+oVPVtF4DEAzBKDSyPNMc0MSAFpebrph0iMNe8=; b=Jydk8+nVg8C0Pqvb6Bi7u1LSApHy5HWbwBvwDvg95iPiI6vFt+msCbBtLKYGNzQYDA kNN4zwi2WPX+XVj2jV/hJx5RDCwnViMGypQXLJn+pzT9+btOZYHitnRUi4XT/6pr0+V8 LnU1Wcj0ikFeSoMJ9n+fGBnvxh6yLmdFllM0Wj356DZ3D/JoIjXJqB9AnbEUeceHLePa QgZTRLYeyguZG6W/NZZs0DnPB7vrZ+IMg0tE0BjfZd5VtzHmsYSYLZdJpw7ePEG0FOkc zEtr//czmxFJkTk+tPH42mubphAb/En2/swsKE++y3HjlPfPZACxTU0DnQ79jaqttCrf 6G3g== X-Gm-Message-State: AMke39mhlXFTs+DvE+EmGaB2pV4a23MwLgteNUdbDDfmcbiTqhuXkjYlfDfO2gAXgAwaDPX1 X-Received: by 10.223.170.200 with SMTP id i8mr30812768wrc.79.1489397318367; Mon, 13 Mar 2017 02:28:38 -0700 (PDT) Received: from localhost.localdomain ([160.169.103.157]) by smtp.gmail.com with ESMTPSA id q75sm10546830wmd.27.2017.03.13.02.28.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Mar 2017 02:28:37 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: ryan.harkin@linaro.org, sigmaepsilon92@gmail.com, lersek@redhat.com, Ard Biesheuvel Date: Mon, 13 Mar 2017 09:28:16 +0000 Message-Id: <1489397296-23566-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] EmbeddedPkg/PrePiLib: allocate code pages for DxeCore X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Mar 2017 09:28:40 -0000 The recently introduced memory protection features inadvertently broke the boot on all PrePi platforms, because the changes to explicitly use EfiBootServicesCode for loading the DxeCore PE/COFF image need to be applied in a different way for PrePi. So add a simple helper function that sets the type of an allocation to EfiBootServicesCode, and invoke it to allocate the space for DxeCore. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 34 +++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c index 9a1ef344df6e..bba8e7384edc 100644 --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c +++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c @@ -28,6 +28,38 @@ SecWinNtPeiLoadFile ( IN EFI_PHYSICAL_ADDRESS *EntryPoint ); +STATIC +VOID* +EFIAPI +AllocateCodePages ( + IN UINTN Pages + ) +{ + VOID *Alloc; + EFI_PEI_HOB_POINTERS Hob; + + Alloc = AllocatePages (Pages); + if (Alloc == NULL) { + return NULL; + } + + // find the HOB we just created, and change the type to EfiBootServicesCode + Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION); + while (Hob.Raw != NULL) { + if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) { + Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode; + return Alloc; + } + Hob.Raw = GET_NEXT_HOB (Hob); + Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw); + } + + ASSERT (FALSE); + + FreePages (Alloc, Pages); + return NULL; +} + EFI_STATUS EFIAPI @@ -54,7 +86,7 @@ LoadPeCoffImage ( // // Allocate Memory for the image // - Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize)); + Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize)); ASSERT (Buffer != 0); -- 2.7.4