Home | History | Annotate | Download | only in PeiMemoryLib
      1 /** @file
      2   CopyMem() implementation.
      3 
      4   The following BaseMemoryLib instances contain the same copy of this file:
      5 
      6     BaseMemoryLib
      7     BaseMemoryLibMmx
      8     BaseMemoryLibSse2
      9     BaseMemoryLibRepStr
     10     BaseMemoryLibOptDxe
     11     BaseMemoryLibOptPei
     12     PeiMemoryLib
     13     UefiMemoryLib
     14 
     15   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     16   This program and the accompanying materials
     17   are licensed and made available under the terms and conditions of the BSD License
     18   which accompanies this distribution.  The full text of the license may be found at
     19   http://opensource.org/licenses/bsd-license.php.
     20 
     21   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     22   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     23 
     24 **/
     25 
     26 #include "MemLibInternals.h"
     27 
     28 /**
     29   Copies a source buffer to a destination buffer, and returns the destination buffer.
     30 
     31   This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns
     32   DestinationBuffer.  The implementation must be reentrant, and it must handle the case
     33   where SourceBuffer overlaps DestinationBuffer.
     34 
     35   If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
     36   If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
     37 
     38   @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
     39   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
     40   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
     41 
     42   @return DestinationBuffer.
     43 
     44 **/
     45 VOID *
     46 EFIAPI
     47 CopyMem (
     48   OUT VOID       *DestinationBuffer,
     49   IN CONST VOID  *SourceBuffer,
     50   IN UINTN       Length
     51   )
     52 {
     53   if (Length == 0) {
     54     return DestinationBuffer;
     55   }
     56   ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
     57   ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
     58 
     59   if (DestinationBuffer == SourceBuffer) {
     60     return DestinationBuffer;
     61   }
     62   return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);
     63 }
     64