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