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