From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 09FE5941440 for ; Tue, 12 Dec 2023 09:49:02 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ZannD4j8xpBgcNMkyJhInZ6fevv09BUW4a8DSFhPemQ=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1702374541; v=1; b=cLZFrOgZMpcW9P1VH0KykroFl3NgcZQmyX6qbXX7+ftPhir4/XGolFW4lqmoLQDUcrjOZRg0 5iUVvwNhU8pL1MQc88UFjmPtqy9UFQVRiJuZzZmdrqQIL8iMGetm7/9gjazzWbWN2E3L5WAz/le FvNSgSlfpzPoOoh00XYYhrDA= X-Received: by 127.0.0.2 with SMTP id IEFJYY7687511xMppCm3BTbM; Tue, 12 Dec 2023 01:49:01 -0800 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.13154.1702374541027249469 for ; Tue, 12 Dec 2023 01:49:01 -0800 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 73EFB61766 for ; Tue, 12 Dec 2023 09:49:00 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26559C433C9 for ; Tue, 12 Dec 2023 09:49:00 +0000 (UTC) X-Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2c9ea37ac87so75195961fa.3 for ; Tue, 12 Dec 2023 01:49:00 -0800 (PST) X-Gm-Message-State: D8pBObGQc8XX5kbdPfLKXl8Tx7686176AA= X-Google-Smtp-Source: AGHT+IFrfj8lGYqcy7Mp86tv8SkHu4z89aQ5j6fUNS3TaiJYdJ2pXUBUrh63cCxZqPpgGcjdDCXZLI6P5fv4NCEIo9k= X-Received: by 2002:a2e:ab18:0:b0:2cc:1e99:3f50 with SMTP id ce24-20020a2eab18000000b002cc1e993f50mr2559538ljb.43.1702374538329; Tue, 12 Dec 2023 01:48:58 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "Ard Biesheuvel" Date: Tue, 12 Dec 2023 10:48:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool To: Jeff Brasen Cc: devel@edk2.groups.io, abner.chang@amd.com, quic_llindhol@quicinc.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=cLZFrOgZ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Mon, 11 Dec 2023 at 16:48, Jeff Brasen wrote: > > Add implementation of ReallocatePool which is defined in the > MemoryAllocationLib header file to allow components to not > need special handling for PrePi module types. > > Signed-off-by: Jeff Brasen Reviewed-by: Ard Biesheuvel > --- > .../MemoryAllocationLib.c | 57 +++++++++++++++++++ > 1 file changed, 57 insertions(+) > > diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > index 08a0add340..39fbe243dd 100644 > --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > @@ -269,3 +269,60 @@ FreePool ( > { > // Not implemented yet > } > + > +/** > + Reallocates a buffer of type EfiBootServicesData. > + > + Allocates and zeros the number bytes specified by NewSize from memory of type > + EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and > + NewSize bytes are copied from OldBuffer to the newly allocated buffer, and > + OldBuffer is freed. A pointer to the newly allocated buffer is returned. > + If NewSize is 0, then a valid buffer of 0 size is returned. If there is not > + enough memory remaining to satisfy the request, then NULL is returned. > + > + If the allocation of the new buffer is successful and the smaller of NewSize and OldSize > + is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT(). > + > + @param OldSize The size, in bytes, of OldBuffer. > + @param NewSize The size, in bytes, of the buffer to reallocate. > + @param OldBuffer The buffer to copy to the allocated buffer. This is an optional > + parameter that may be NULL. > + > + @return A pointer to the allocated buffer or NULL if allocation fails. > + > +**/ > +VOID * > +EFIAPI > +ReallocatePool ( > + IN UINTN OldSize, > + IN UINTN NewSize, > + IN VOID *OldBuffer OPTIONAL > + ) > +{ > + VOID *NewBuffer; > + > + // Validate the OldBuffer is HobAllocated. > + DEBUG_CODE_BEGIN (); > + EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob; > + > + if (OldBuffer != NULL) { > + HandOffHob = GetHobList (); > + ASSERT (((EFI_PHYSICAL_ADDRESS)OldBuffer >= HandOffHob->EfiMemoryBottom)); > + ASSERT (((EFI_PHYSICAL_ADDRESS)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom)); > + } > + > + DEBUG_CODE_END (); > + > + // If new buffer would be smaller just return old buffer as FreePool isn't supported. > + if ((OldBuffer != NULL) && (OldSize >= NewSize)) { > + return OldBuffer; > + } > + > + NewBuffer = AllocateZeroPool (NewSize); > + if ((NewBuffer != NULL) && (OldBuffer != NULL)) { > + CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); > + FreePool (OldBuffer); > + } > + > + return NewBuffer; > +} > -- > 2.34.1 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112383): https://edk2.groups.io/g/devel/message/112383 Mute This Topic: https://groups.io/mt/103110962/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-