]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptPei/CopyMemWrapper.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptPei / CopyMemWrapper.c
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 - 2018, Intel Corporation. All rights reserved.<BR>
16 SPDX-License-Identifier: BSD-2-Clause-Patent
17
18 **/
19
20 #include "MemLibInternals.h"
21
22 /**
23 Copies a source buffer to a destination buffer, and returns the destination buffer.
24
25 This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns
26 DestinationBuffer. The implementation must be reentrant, and it must handle the case
27 where SourceBuffer overlaps DestinationBuffer.
28
29 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
30 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
31
32 @param DestinationBuffer The pointer to the destination buffer of the memory copy.
33 @param SourceBuffer The pointer to the source buffer of the memory copy.
34 @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.
35
36 @return DestinationBuffer.
37
38 **/
39 VOID *
40 EFIAPI
41 CopyMem (
42 OUT VOID *DestinationBuffer,
43 IN CONST VOID *SourceBuffer,
44 IN UINTN Length
45 )
46 {
47 if (Length == 0) {
48 return DestinationBuffer;
49 }
50 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
51 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
52
53 if (DestinationBuffer == SourceBuffer) {
54 return DestinationBuffer;
55 }
56 return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);
57 }