From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8D1C22263DD95 for ; Mon, 16 Apr 2018 15:30:59 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 15:30:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="48389621" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga001.jf.intel.com with ESMTP; 16 Apr 2018 15:30:58 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 16 Apr 2018 15:30:57 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 16 Apr 2018 15:30:57 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.239]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.198]) with mapi id 14.03.0319.002; Tue, 17 Apr 2018 06:30:55 +0800 From: "Yao, Jiewen" To: Achin Gupta , Supreeth Venkatesh CC: "ard.biesheuvel@linaro.org" , "edk2-devel@lists.01.org" , "leif.lindholm@linaro.org" , "Gao, Liming" , "Kinney, Michael D" , "nd@arm.com" Thread-Topic: [edk2] [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 Specific instance of memory check library. Thread-Index: AQHTzbWc89UB7WCljECp3GwwKPhBbKQDCUeAgAD/bJA= Date: Mon, 16 Apr 2018 22:30:55 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AB659B5@SHSMSX104.ccr.corp.intel.com> References: <20180406144223.10931-1-supreeth.venkatesh@arm.com> <20180406144223.10931-9-supreeth.venkatesh@arm.com> <20180416151258.GP663@e104320-lin> In-Reply-To: <20180416151258.GP663@e104320-lin> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGYyZWI0YjMtZmUxNS00MDJlLTllMTYtODNjNmVmYmQwMWNmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJHVEdvNHF1dlhUQnVGdW8rUTZmZG9iT1phM2FTMXdZMXgxT3ZNdkxQaVwvXC81dGZ4WmoyalJ2THRCU1RhSWNVVmEifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 Specific instance of memory check library. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2018 22:30:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi I don't think this lib is generic, because it hardcode the physical address= bits. PhysicalAddressBits =3D 36; For X86 CPU, we get it from CPUID. :-) As enhancement, we may put most common C-code logic (such as CopyMem, or me= mmap calculation) to StandaloneMmPkg/MemLib, and only include the PhysicalA= ddresBit calculation under StandaloneMmPkg/MemLib/Arm folder. As such, we know clearly on which one is ARM specific. Thank you Yao Jiewen > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ac= hin > Gupta > Sent: Monday, April 16, 2018 11:13 PM > To: Supreeth Venkatesh > Cc: ard.biesheuvel@linaro.org; edk2-devel@lists.01.org; > leif.lindholm@linaro.org; Yao, Jiewen ; Gao, Liming > ; Kinney, Michael D ; > nd@arm.com > Subject: Re: [edk2] [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 > Specific instance of memory check library. >=20 > Hi Supreeth, >=20 > On Fri, Apr 06, 2018 at 03:42:13PM +0100, Supreeth Venkatesh wrote: > > MM memory check library library implementation. This library consumes > > MM_ACCESS_PROTOCOL to get MMRAM information. In order to use this > > library instance, the platform should produce all MMRAM range via > > MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core > > and MM driver) and/or specific dedicated hardware. > > > > This patch provides services for MM Memory Operation. > > The management mode Mem Library provides function for checking if buffe= r > > is outside MMRAM and valid. It also provides functions for copy data > > from MMRAM to non-MMRAM, from non-MMRAM to MMRAM, > > from non-MMRAM to non-MMRAM, or set data in non-MMRAM. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Achin Gupta > > Signed-off-by: Supreeth Venkatesh > > --- > > StandaloneMmPkg/Include/Library/MemLib.h | 140 ++++++++++++++ > > StandaloneMmPkg/Library/MemLib/Arm/MemLib.c | 276 > ++++++++++++++++++++++++++++ >=20 > Why is this Library Arm specific. Apart from cosmetics tweaks, it has not > changed since it was originally contributed? >=20 > cheers, > Achin >=20 > > StandaloneMmPkg/Library/MemLib/MemLib.inf | 47 +++++ > > 3 files changed, 463 insertions(+) > > create mode 100644 StandaloneMmPkg/Include/Library/MemLib.h > > create mode 100644 StandaloneMmPkg/Library/MemLib/Arm/MemLib.c > > create mode 100644 StandaloneMmPkg/Library/MemLib/MemLib.inf > > > > diff --git a/StandaloneMmPkg/Include/Library/MemLib.h > b/StandaloneMmPkg/Include/Library/MemLib.h > > new file mode 100644 > > index 0000000000..3264f10010 > > --- /dev/null > > +++ b/StandaloneMmPkg/Include/Library/MemLib.h > > @@ -0,0 +1,140 @@ > > +/** @file > > + Provides services for MM Memory Operation. > > + > > + The MM Mem Library provides function for checking if buffer is outsi= de > MMRAM and valid. > > + It also provides functions for copy data from MMRAM to non-MMRAM, > from non-MMRAM to MMRAM, > > + from non-MMRAM to non-MMRAM, or set data in non-MMRAM. > > + > > + Copyright (c) 2015, Intel Corporation. All rights reserved.
> > + Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > + > > + This program and the accompanying materials > > + are licensed and made available under the terms and conditions of th= e BSD > License > > + which accompanies this distribution. The full text of the license m= ay be > found at > > + http://opensource.org/licenses/bsd-license.php > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > > + > > +**/ > > + > > +#ifndef _MM_MEM_LIB_H_ > > +#define _MM_MEM_LIB_H_ > > + > > +/** > > + This function check if the buffer is valid per processor architectur= e and not > overlap with MMRAM. > > + > > + @param Buffer The buffer start address to be checked. > > + @param Length The buffer length to be checked. > > + > > + @retval TRUE This buffer is valid per processor architecture and no= t > overlap with MMRAM. > > + @retval FALSE This buffer is not valid per processor architecture or= overlap > with MMRAM. > > +**/ > > +BOOLEAN > > +EFIAPI > > +MmIsBufferOutsideMmValid ( > > + IN EFI_PHYSICAL_ADDRESS Buffer, > > + IN UINT64 Length > > + ); > > + > > +/** > > + Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if source buffer is valid per processor architecture and n= ot overlap > with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it return EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMemToSmram ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ); > > + > > +/** > > + Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if destination buffer is valid per processor architecture = and not > overlap with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMemFromSmram ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ); > > + > > +/** > > + Copies a source buffer (NON-MMRAM) to a destination buffer > (NON-MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if source buffer and destination buffer are valid per proc= essor > architecture and not overlap with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant, and it must handle the case wh= ere > source buffer overlaps destination buffer. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMem ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ); > > + > > +/** > > + Fills a target buffer (NON-MMRAM) with a byte value. > > + > > + This function fills a target buffer (non-MMRAM) with a byte value. > > + It checks if target buffer is valid per processor architecture and n= ot overlap > with MMRAM. > > + If the check passes, it fills memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + > > + @param Buffer The memory to set. > > + @param Length The number of bytes to set. > > + @param Value The value with which to fill Length bytes of Buffe= r. > > + > > + @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor > architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is set. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmSetMem ( > > + OUT VOID *Buffer, > > + IN UINTN Length, > > + IN UINT8 Value > > + ); > > + > > +#endif > > diff --git a/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c > b/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c > > new file mode 100644 > > index 0000000000..432a45698b > > --- /dev/null > > +++ b/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c > > @@ -0,0 +1,276 @@ > > +/** @file > > + Instance of MM memory check library. > > + > > + MM memory check library library implementation. This library consume= s > MM_ACCESS_PROTOCOL > > + to get MMRAM information. In order to use this library instance, the > platform should produce > > + all MMRAM range via MM_ACCESS_PROTOCOL, including the range for > firmware (like MM Core > > + and MM driver) and/or specific dedicated hardware. > > + > > + Copyright (c) 2015, Intel Corporation. All rights reserved.
> > + Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > + > > + This program and the accompanying materials > > + are licensed and made available under the terms and conditions of th= e BSD > License > > + which accompanies this distribution. The full text of the license m= ay be > found at > > + http://opensource.org/licenses/bsd-license.php > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > > + > > +**/ > > + > > + > > +#include > > + > > +#include > > +#include > > +#include > > + > > +EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges; > > +UINTN mMmMemLibInternalMmramCount; > > + > > +// > > +// Maximum support address used to check input buffer > > +// > > +EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress =3D > 0; > > + > > +/** > > + Calculate and save the maximum support address. > > + > > +**/ > > +VOID > > +MmMemLibInternalCalculateMaximumSupportAddress ( > > + VOID > > + ) > > +{ > > + UINT8 PhysicalAddressBits; > > + > > + PhysicalAddressBits =3D 36; > > + > > + // > > + // Save the maximum support address in one global variable > > + // > > + mMmMemLibInternalMaximumSupportAddress =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1); > > + DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress =3D > 0x%lx\n", mMmMemLibInternalMaximumSupportAddress)); > > +} > > + > > +/** > > + This function check if the buffer is valid per processor architectur= e and not > overlap with MMRAM. > > + > > + @param Buffer The buffer start address to be checked. > > + @param Length The buffer length to be checked. > > + > > + @retval TRUE This buffer is valid per processor architecture and no= t > overlap with MMRAM. > > + @retval FALSE This buffer is not valid per processor architecture or= overlap > with MMRAM. > > +**/ > > +BOOLEAN > > +EFIAPI > > +MmIsBufferOutsideMmValid ( > > + IN EFI_PHYSICAL_ADDRESS Buffer, > > + IN UINT64 Length > > + ) > > +{ > > + UINTN Index; > > + > > + // > > + // Check override. > > + // NOTE: (B:0->L:4G) is invalid for IA32, but (B:1->L:4G-1)/(B:4G-1-= >L:1) is > valid. > > + // > > + if ((Length > mMmMemLibInternalMaximumSupportAddress) || > > + (Buffer > mMmMemLibInternalMaximumSupportAddress) || > > + ((Length !=3D 0) && (Buffer > > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))) ) { > > + // > > + // Overflow happen > > + // > > + DEBUG (( > > + DEBUG_ERROR, > > + "MmIsBufferOutsideMmValid: Overflow: Buffer (0x%lx) - Length > (0x%lx), MaximumSupportAddress (0x%lx)\n", > > + Buffer, > > + Length, > > + mMmMemLibInternalMaximumSupportAddress > > + )); > > + return FALSE; > > + } > > + > > + for (Index =3D 0; Index < mMmMemLibInternalMmramCount; Index ++) { > > + if (((Buffer >=3D mMmMemLibInternalMmramRanges[Index].CpuStart) && > (Buffer < mMmMemLibInternalMmramRanges[Index].CpuStart + > mMmMemLibInternalMmramRanges[Index].PhysicalSize)) || > > + ((mMmMemLibInternalMmramRanges[Index].CpuStart >=3D Buffer) > && (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length))) { > > + DEBUG (( > > + DEBUG_ERROR, > > + "MmIsBufferOutsideMmValid: Overlap: Buffer (0x%lx) - Length > (0x%lx), ", > > + Buffer, > > + Length > > + )); > > + DEBUG (( > > + DEBUG_ERROR, > > + "CpuStart (0x%lx) - PhysicalSize (0x%lx)\n", > > + mMmMemLibInternalMmramRanges[Index].CpuStart, > > + mMmMemLibInternalMmramRanges[Index].PhysicalSize > > + )); > > + return FALSE; > > + } > > + } > > + > > + return TRUE; > > +} > > + > > +/** > > + Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if source buffer is valid per processor architecture and n= ot overlap > with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it return EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMemToMmram ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ) > > +{ > > + if (!MmIsBufferOutsideMmValid > ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) { > > + DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation: > Source (0x%x), Length (0x%x)\n", SourceBuffer, Length)); > > + return EFI_SECURITY_VIOLATION; > > + } > > + CopyMem (DestinationBuffer, SourceBuffer, Length); > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if destination buffer is valid per processor architecture = and not > overlap with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMemFromMmram ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ) > > +{ > > + if (!MmIsBufferOutsideMmValid > ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) { > > + DEBUG ((DEBUG_ERROR, "MmCopyMemFromMmram: Security > Violation: Destination (0x%x), Length (0x%x)\n", DestinationBuffer, Lengt= h)); > > + return EFI_SECURITY_VIOLATION; > > + } > > + CopyMem (DestinationBuffer, SourceBuffer, Length); > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + Copies a source buffer (NON-MMRAM) to a destination buffer > (NON-MMRAM). > > + > > + This function copies a source buffer (non-MMRAM) to a destination bu= ffer > (MMRAM). > > + It checks if source buffer and destination buffer are valid per proc= essor > architecture and not overlap with MMRAM. > > + If the check passes, it copies memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + The implementation must be reentrant, and it must handle the case wh= ere > source buffer overlaps destination buffer. > > + > > + @param DestinationBuffer The pointer to the destination buffer of= the > memory copy. > > + @param SourceBuffer The pointer to the source buffer of the > memory copy. > > + @param Length The number of bytes to copy from > SourceBuffer to DestinationBuffer. > > + > > + @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per > processor architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is copied. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmCopyMem ( > > + OUT VOID *DestinationBuffer, > > + IN CONST VOID *SourceBuffer, > > + IN UINTN Length > > + ) > > +{ > > + if (!MmIsBufferOutsideMmValid > ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) { > > + DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Destination > (0x%x), Length (0x%x)\n", DestinationBuffer, Length)); > > + return EFI_SECURITY_VIOLATION; > > + } > > + if (!MmIsBufferOutsideMmValid > ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) { > > + DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source > (0x%x), Length (0x%x)\n", SourceBuffer, Length)); > > + return EFI_SECURITY_VIOLATION; > > + } > > + CopyMem (DestinationBuffer, SourceBuffer, Length); > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + Fills a target buffer (NON-MMRAM) with a byte value. > > + > > + This function fills a target buffer (non-MMRAM) with a byte value. > > + It checks if target buffer is valid per processor architecture and n= ot overlap > with MMRAM. > > + If the check passes, it fills memory and returns EFI_SUCCESS. > > + If the check fails, it returns EFI_SECURITY_VIOLATION. > > + > > + @param Buffer The memory to set. > > + @param Length The number of bytes to set. > > + @param Value The value with which to fill Length bytes of Buffe= r. > > + > > + @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor > architecture or overlap with MMRAM. > > + @retval EFI_SUCCESS Memory is set. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MmSetMem ( > > + OUT VOID *Buffer, > > + IN UINTN Length, > > + IN UINT8 Value > > + ) > > +{ > > + if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, > Length)) { > > + DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source > (0x%x), Length (0x%x)\n", Buffer, Length)); > > + return EFI_SECURITY_VIOLATION; > > + } > > + SetMem (Buffer, Length, Value); > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + The constructor function initializes the Mm Mem library > > + > > + @param ImageHandle The firmware allocated handle for the EFI > image. > > + @param SystemTable A pointer to the EFI System Table. > > + > > + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +MemLibConstructor ( > > + IN EFI_HANDLE ImageHandle, > > + IN EFI_MM_SYSTEM_TABLE *MmSystemTable > > + ) > > +{ > > + > > + // > > + // Calculate and save maximum support address > > + // > > + MmMemLibInternalCalculateMaximumSupportAddress (); > > + > > + return EFI_SUCCESS; > > +} > > diff --git a/StandaloneMmPkg/Library/MemLib/MemLib.inf > b/StandaloneMmPkg/Library/MemLib/MemLib.inf > > new file mode 100644 > > index 0000000000..52b7c06397 > > --- /dev/null > > +++ b/StandaloneMmPkg/Library/MemLib/MemLib.inf > > @@ -0,0 +1,47 @@ > > +## @file > > +# Instance of MM memory check library. > > +# > > +# MM memory check library library implementation. This library consum= es > MM_ACCESS_PROTOCOL > > +# to get MMRAM information. In order to use this library instance, th= e > platform should produce > > +# all MMRAM range via MM_ACCESS_PROTOCOL, including the range for > firmware (like MM Core > > +# and MM driver) and/or specific dedicated hardware. > > +# > > +# Copyright (c) 2015, Intel Corporation. All rights reserved.
> > +# Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > +# > > +# This program and the accompanying materials > > +# are licensed and made available under the terms and conditions of t= he > BSD License > > +# which accompanies this distribution. The full text of the license = may be > found at > > +# http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > > +# > > +## > > + > > +[Defines] > > + INF_VERSION =3D 0x0001001A > > + BASE_NAME =3D MemLib > > + FILE_GUID =3D > EA355F14-6409-4716-829F-37B3BC7C7F26 > > + MODULE_TYPE =3D MM_STANDALONE > > + VERSION_STRING =3D 1.0 > > + PI_SPECIFICATION_VERSION =3D 0x00010032 > > + LIBRARY_CLASS =3D MemLib|MM_STANDALONE > MM_CORE_STANDALONE > > + CONSTRUCTOR =3D MemLibConstructor > > + > > +# > > +# The following information is for reference only and not required by = the > build tools. > > +# > > +# VALID_ARCHITECTURES =3D AARCH64 > > +# > > + > > +[Sources.AARCH64] > > + Arm/MemLib.c > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + StandaloneMmPkg/StandaloneMmPkg.dec > > + > > +[LibraryClasses] > > + BaseMemoryLib > > + DebugLib > > -- > > 2.16.2 > > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel