On Jun 23, 2014, at 11:01 AM, Sathya Prakash <[email protected]>
wrote:
> I would like to see the CopyMem implementation. Which source file I should
> look for it. I see some implementation in commonlib.c in basetools but I
> assume it wont be taken from there and instead will be used from boot
> services table. So how can I know about the implementation. The reason I
> want to look into that is, in reallocatepool, there is a possibility that
> the CopyMem can be called with 0 length. If CopyMem implementation is
> similar to what is in commonlib.c (as mentioned below), the 0 will be
> decremented and due to the type of length (UINTN) there might be some memory
> corruption.
>
>
There are multiple CopyMem() implementations, as there are multiple instances
of the BaseMemoryLib. You will need to look in your DSC, or build log, to see
which instance of the BaseMemoryLib you are using.
> Please correct if my understanding is wrong.
>
>
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BaseMemoryLibOptDxe/CopyMemWrapper.c
/**
Copies a source buffer to a destination buffer, and returns the destination
buffer.
This function copies Length bytes from SourceBuffer to DestinationBuffer, and
returns
DestinationBuffer. The implementation must be reentrant, and it must handle
the case
where SourceBuffer overlaps DestinationBuffer.
If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then
ASSERT().
If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
@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.
@return DestinationBuffer.
**/
VOID *
EFIAPI
CopyMem (
OUT VOID *DestinationBuffer,
IN CONST VOID *SourceBuffer,
IN UINTN Length
)
{
if (Length == 0) {
return DestinationBuffer;
}
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
if (DestinationBuffer == SourceBuffer) {
return DestinationBuffer;
}
return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);
}
There is a check for a length of zero, ASSERT() macros for pointer overflow
checks, and and check to make sure the pointers are not the same. After that it
calls the assembly language code.
Thanks,
Andrew Fish
>
> VOID
> PeiCopyMem (
> IN VOID *Destination,
> IN VOID *Source,
> IN UINTN Length
> )
> /*++
>
> Routine Description:
>
> Copy Length bytes from Source to Destination.
>
> Arguments:
>
> Destination - Target of copy
>
> Source - Place to copy from
>
> Length - Number of bytes to copy
>
> Returns:
>
> None
>
> --*/
> {
> CHAR8 *Destination8;
> CHAR8 *Source8;
>
> Destination8 = Destination;
> Source8 = Source;
> while (Length--) {
> *(Destination8++) = *(Source8++);
> }
> }
>
> Thanks
> Sathya
>
> PS: My E-mail ID changed from [email protected] to
> [email protected]. Please update your address book.
>
> ------------------------------------------------------------------------------
> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
> Find What Matters Most in Your Big Data with HPCC Systems
> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
> Leverages Graph Analysis for Fast Processing & Easy Data Exploration
> http://p.sf.net/sfu/hpccsystems_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel