Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
Looks like I missed an UINTN cast will fix and push a v2. > -Original Message- > From: Ard Biesheuvel > Sent: Thursday, December 21, 2023 7:54 AM > To: Chang, Abner > Cc: Jeff Brasen ; devel@edk2.groups.io; > ardb+tianoc...@kernel.org; quic_llind...@quicinc.com > Subject: Re: [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add > ReallocatePool > > External email: Use caution opening links or attachments > > > On Thu, 21 Dec 2023 at 15:39, Ard Biesheuvel wrote: > > > > On Mon, 18 Dec 2023 at 03:23, Chang, Abner > wrote: > > > > > > [AMD Official Use Only - General] > > > > > > Reviewed-by: Abner Chang > > > > > > > I've queued this up, along with the mock one - thanks. > > > > Rejected by CI: > https://github.com/tianocore/edk2/pull/5184 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112988): https://edk2.groups.io/g/devel/message/112988 Mute This Topic: https://groups.io/mt/103110962/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
On Thu, 21 Dec 2023 at 15:39, Ard Biesheuvel wrote: > > On Mon, 18 Dec 2023 at 03:23, Chang, Abner wrote: > > > > [AMD Official Use Only - General] > > > > Reviewed-by: Abner Chang > > > > I've queued this up, along with the mock one - thanks. > Rejected by CI: https://github.com/tianocore/edk2/pull/5184 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112821): https://edk2.groups.io/g/devel/message/112821 Mute This Topic: https://groups.io/mt/103110962/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
On Mon, 18 Dec 2023 at 03:23, Chang, Abner wrote: > > [AMD Official Use Only - General] > > Reviewed-by: Abner Chang > I've queued this up, along with the mock one - thanks. > > -Original Message- > > From: Jeff Brasen > > Sent: Monday, December 11, 2023 11:48 PM > > To: devel@edk2.groups.io > > Cc: Chang, Abner ; ardb+tianoc...@kernel.org; > > quic_llind...@quicinc.com; Jeff Brasen > > 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 > > --- > > .../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 OldSizeThe size, in bytes, of OldBuffer. > > + @param NewSizeThe 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/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
[AMD Official Use Only - General] Reviewed-by: Abner Chang > -Original Message- > From: Jeff Brasen > Sent: Monday, December 11, 2023 11:48 PM > To: devel@edk2.groups.io > Cc: Chang, Abner ; ardb+tianoc...@kernel.org; > quic_llind...@quicinc.com; Jeff Brasen > 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 > --- > .../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 OldSizeThe size, in bytes, of OldBuffer. > + @param NewSizeThe 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 (#112613): https://edk2.groups.io/g/devel/message/112613 Mute This Topic: https://groups.io/mt/103110962/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
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 OldSizeThe size, in bytes, of OldBuffer. > + @param NewSizeThe 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/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
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 --- .../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 OldSizeThe size, in bytes, of OldBuffer. + @param NewSizeThe 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 (#112312): https://edk2.groups.io/g/devel/message/112312 Mute This Topic: https://groups.io/mt/103110962/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-