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 2CEFCAC1A1D for ; Thu, 28 Dec 2023 20:47:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=5JdmXdhRAbVZYXHZJDHU5b2/b9EMVWZZhViLMp1c7k0=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1703796450; v=1; b=fJ7saJ+3mMrA0e1Rxw1270PFDtxLme0OoVek8AJJZHjw9Q8GZZZHJJCgB935c+wI70ofSmkj Ndpn6Bw848zTWCmefQk8EDUHAmthLfKgjJOuaxxtUgx93MKxyGn+8v9AY9zTg+9/My/RQpUR4GE yLhmAFmhWmEzefkAemGRbZOg= X-Received: by 127.0.0.2 with SMTP id m3NsYY7687511xDt4tGYebQO; Thu, 28 Dec 2023 12:47:30 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.79]) by mx.groups.io with SMTP id smtpd.web11.131661.1703796450195263590 for ; Thu, 28 Dec 2023 12:47:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WOBEmD083ASrc0mODaJYDnbI45y89lxnYNrDl4LLD6VvfYyxgozbX3+VGz5dbmh08uQd3+4Xtb7OlPzzkl1lWdl18aQs5U1bZsEXF8r8k6QtZaVBOAoREpKf/tBO+4vg9rsn9ZxKQ0Ulm8HORL9pjSpDSYWaC1RZGKembY0jgQM+AL1lSdKfuyA1L8s85AcBIOApkAWjipekoHH47+/jIiu02oTYIfZVAQtekRCmwXUcBI11GiDL1ZYYfsgZ3o7U8XKdkRBgYRRNK5OBWeRF90tFDg5DPY2v17BihRPxq1zzT1UX1r9VGtbXZsd0Y7HjXsAC8rTt/cuAICPgvhwviQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bPbqR+objVw/teB3/oyJAnwrl6l9aKar2Ot3Zp9NHQE=; b=cvNBZcTb0QCsgHjvrvM4reG+bt/9c1FL4yzTphwLC+eqBJia0UWNgypRPAsNhsxaqnYwcai/Jwdl4tXHFQAx0JqCfFfuqTYWd7vSofkDTpvYH3gIIVpufUpQF/2ejhVkE59YpqXNrmDkvZ9xyjrzJmv4DDR4UKvkrP/qlDlf79hixHJjty7LwTyMAf4KI+rDvoChynHj9GUIhqCKmwVKvbE7IUztsgvJ252q9V8HuK1oUD5zr+LZdgf3YD68ZjFKeGmhmoTmThGOmdtwCIzUKNkk2alVzlXuOUhXrGq6xZGVmiHUdUejuvF5hfl1aW4tFP0cDTinIhKsczqrQYgEMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) X-Received: from SN6PR08CA0010.namprd08.prod.outlook.com (2603:10b6:805:66::23) by MW3PR12MB4506.namprd12.prod.outlook.com (2603:10b6:303:53::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27; Thu, 28 Dec 2023 20:47:27 +0000 X-Received: from SA2PEPF00001508.namprd04.prod.outlook.com (2603:10b6:805:66:cafe::96) by SN6PR08CA0010.outlook.office365.com (2603:10b6:805:66::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27 via Frontend Transport; Thu, 28 Dec 2023 20:47:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.160) by SA2PEPF00001508.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.14 via Frontend Transport; Thu, 28 Dec 2023 20:47:27 +0000 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Dec 2023 12:47:12 -0800 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Dec 2023 12:47:12 -0800 X-Received: from cad98f4d2e3d.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Thu, 28 Dec 2023 12:47:12 -0800 From: "Jeff Brasen via groups.io" To: CC: , , , Jeff Brasen Subject: [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Date: Thu, 28 Dec 2023 12:47:06 -0800 Message-ID: <824c8fc0358b7c0823d4d35de5bfe7440f09c84c.1703796256.git.jbrasen@nvidia.com> In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001508:EE_|MW3PR12MB4506:EE_ X-MS-Office365-Filtering-Correlation-Id: b0e4301a-9575-4aa6-823e-08dc07e633d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: t0FNf1LCIx2E+egMTWixNh21pcCDB4i8qvmD2bqqZVFsoP5hbC1W39vil9mvuFa6P6dA0v1bLB8GP44lvAFUgyaU15xU2CoDk5B7JvhZpoj2+pWDQn/wHIhMXqttFcROcSYntQjiFHJTxsBN2htULIRKpp08mTrzvuybeHaf5DFkI6W4DaUbjYH4IhBp/xnTIjPipfFEl9zoQ484WkNWEmLLVbMoqwpggGGI3Zi7fERXxf2vpEwRYevE//6qIiaJqMwQy5O80w8TqNjHgU1z4HeknbA2VMkwh2VIOFZU0Jy3hODmwpJeabqXb7I89vYdBMicOD5B3m0HEUQ7xFobZY8XHRtqtuPd3oyB6O8AoT/y+/mLX1iD6nx2NvSAzeb3s5RInSr+y4c2qsAW7GeVKIKeRdAPODyAOMdI902AGoZsc0MBan2X4UtHldJxz/jSZlA9/cVktL3YS9aMAh5ueX4BHiM+uJY24T1/YWaHI0xZAo0nTpBNX1D13T1KCSWP7i4xpR3eYdqb3rAWACnvKOcK+Ez8VmrnukeXzwu12EwvXE2AA6UPkruLRcYaCypxGEc4i1GA9c7i8/EB/J5oTShp+vw5JObjwXzov2aiKKv3S7y7G0AgyYhmpXoNc12OP4IINcMotwqEaNf/dxMnOryTGkFNuuKL0FmqbsCJecY4EmnI82SxIABAocsIB52ILrbw1p2UH+hAryFjJidPBcBqvh4WHnhdfPn3SOS5jPR8Xhu3gxkAg5Y5mZoIYQLg X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Dec 2023 20:47:27.1930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0e4301a-9575-4aa6-823e-08dc07e633d6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001508.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4506 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,jbrasen@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: vR79gBx9HxV108iLGQiPRHrPx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=fJ7saJ+3; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=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 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/MemoryAllocationL= ib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c index 08a0add340cf..fa81cc9d595a 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 OldS= ize and + NewSize bytes are copied from OldBuffer to the newly allocated buffer, a= nd + 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 i= s 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 New= Size 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 !=3D NULL) { + HandOffHob =3D GetHobList (); + ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >=3D HandOffHob->EfiMe= moryBottom)); + ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <=3D HandO= ffHob->EfiFreeMemoryBottom)); + } + + DEBUG_CODE_END (); + + // If new buffer would be smaller just return old buffer as FreePool isn= 't supported. + if ((OldBuffer !=3D NULL) && (OldSize >=3D NewSize)) { + return OldBuffer; + } + + NewBuffer =3D AllocateZeroPool (NewSize); + if ((NewBuffer !=3D NULL) && (OldBuffer !=3D NULL)) { + CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); + FreePool (OldBuffer); + } + + return NewBuffer; +} --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112991): https://edk2.groups.io/g/devel/message/112991 Mute This Topic: https://groups.io/mt/103407484/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-