public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Chang, Abner" <Abner.Chang@amd.com>
Cc: Jeff Brasen <jbrasen@nvidia.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>,
	 "ardb+tianocore@kernel.org" <ardb+tianocore@kernel.org>,
	 "quic_llindhol@quicinc.com" <quic_llindhol@quicinc.com>
Subject: Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
Date: Thu, 21 Dec 2023 15:39:49 +0100	[thread overview]
Message-ID: <CAMj1kXGOeDr3v16PS8Fh5=x0Gh=pW_xBD8Qe+X6766hbU4Diug@mail.gmail.com> (raw)
In-Reply-To: <MN2PR12MB3966AC2B7534A32078F8A233EA90A@MN2PR12MB3966.namprd12.prod.outlook.com>

On Mon, 18 Dec 2023 at 03:23, Chang, Abner <Abner.Chang@amd.com> wrote:
>
> [AMD Official Use Only - General]
>
> Reviewed-by: Abner Chang <abner.chang@amd.com>
>

I've queued this up, along with the mock one - thanks.

> > -----Original Message-----
> > From: Jeff Brasen <jbrasen@nvidia.com>
> > Sent: Monday, December 11, 2023 11:48 PM
> > To: devel@edk2.groups.io
> > Cc: Chang, Abner <Abner.Chang@amd.com>; ardb+tianocore@kernel.org;
> > quic_llindhol@quicinc.com; Jeff Brasen <jbrasen@nvidia.com>
> > Subject: [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add
> > ReallocatePool
> >
> > Caution: This message originated from an External Source. Use proper caution
> > when opening attachments, clicking links, or responding.
> >
> >
> > 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 <jbrasen@nvidia.com>
> > ---
> >  .../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 (#112820): https://edk2.groups.io/g/devel/message/112820
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]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-12-21 14:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 15:48 [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Jeff Brasen via groups.io
2023-12-12  9:48 ` Ard Biesheuvel
2023-12-18  2:23 ` Chang, Abner via groups.io
2023-12-21 14:39   ` Ard Biesheuvel [this message]
2023-12-21 14:54     ` Ard Biesheuvel
2023-12-28 17:29       ` Jeff Brasen via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMj1kXGOeDr3v16PS8Fh5=x0Gh=pW_xBD8Qe+X6766hbU4Diug@mail.gmail.com' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox