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 C337DAC1341 for ; Thu, 21 Dec 2023 14:40:08 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=XowWZt9G7JkM/BHzSKH6jWrx5irtSjKbEN0bN/QQ8dM=; 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=1703169607; v=1; b=tQjh/M7Oax8pIedNoMJryqv4KgZUIoo+Cf2Jz5UCKYyk/JkmohqWAcAFQBE5/7sEK/aZDHSd zFUFGIs9KHGpsBSswvJ/Llax8b752gmmz/HKUhr8uMf2d1b888LaDo8oi7GqkRZpeC5dz69zDQF wrpNmBqoTjPIEb+PRjYVpX7U= X-Received: by 127.0.0.2 with SMTP id 15h9YY7687511xnaqlOZatkZ; Thu, 21 Dec 2023 06:40:07 -0800 X-Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by mx.groups.io with SMTP id smtpd.web11.52073.1703169606346488251 for ; Thu, 21 Dec 2023 06:40:06 -0800 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6805FCE1F63 for ; Thu, 21 Dec 2023 14:40:03 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8748BC433CB for ; Thu, 21 Dec 2023 14:40:02 +0000 (UTC) X-Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-50c0f13ea11so1104226e87.3 for ; Thu, 21 Dec 2023 06:40:02 -0800 (PST) X-Gm-Message-State: 2sRxjPt7wHDJ8yO9J8Qhr4m3x7686176AA= X-Google-Smtp-Source: AGHT+IFd6ZYmQNCrc5rA83XWC59izEa+/rvN9NFVUsZcBirP6WdQpvLOMgZxtYDmJTMN8I8r+67kfdqOiMp+/hdxe3c= X-Received: by 2002:ac2:4555:0:b0:50e:2737:f603 with SMTP id j21-20020ac24555000000b0050e2737f603mr3643614lfm.48.1703169600762; Thu, 21 Dec 2023 06:40:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "Ard Biesheuvel" Date: Thu, 21 Dec 2023 15:39:49 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool To: "Chang, Abner" Cc: Jeff Brasen , "devel@edk2.groups.io" , "ardb+tianocore@kernel.org" , "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="tQjh/M7O"; 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, 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+tianocore@kernel.org; > > quic_llindhol@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 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] -=-=-=-=-=-=-=-=-=-=-=-