]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c
1fd00acabd531e5f82bedd49f8cc042bf8f58557
[mirror_edk2.git] / MdePkg / Library / UefiMemoryLib / CopyMemWrapper.c
1 /** @file
2 CopyMem() implementation.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: CopyMemWrapper.c
14
15 The following BaseMemoryLib instances share the same version of this file:
16
17 BaseMemoryLib
18 BaseMemoryLibMmx
19 BaseMemoryLibSse2
20 BaseMemoryLibRepStr
21 PeiMemoryLib
22 UefiMemoryLib
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 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
35 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
36
37 @param DestinationBuffer Pointer to the destination buffer of the memory copy.
38 @param SourceBuffer Pointer to the source buffer of the memory copy.
39 @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer.
40
41 @return DestinationBuffer.
42
43 **/
44 VOID *
45 EFIAPI
46 CopyMem (
47 OUT VOID *DestinationBuffer,
48 IN CONST VOID *SourceBuffer,
49 IN UINTN Length
50 )
51 {
52 if (Length == 0) {
53 return DestinationBuffer;
54 }
55 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
56 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
57
58 if (DestinationBuffer == SourceBuffer) {
59 return DestinationBuffer;
60 }
61 return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);
62 }