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 A pointer to the destination buffer of the memory copy.
|
---|
33 | @param SourceBuffer A 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 |
|
---|
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 |
|
---|
58 | return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);
|
---|
59 | }
|
---|