]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseMemoryLibRepStr/CopyMemWrapper.c
Refine new library instances according to review comments.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibRepStr / CopyMemWrapper.c
index 5ca62f50478428426398688c405bb399231eaa7b..1cccde8ed820968b3ed192e47c608f5f188b9e49 100644 (file)
@@ -1,6 +1,16 @@
 /** @file\r
   CopyMem() implementation.\r
 \r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    DxeMemoryLib\r
+\r
   Copyright (c) 2006, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  CopyMemWrapper.c\r
+**/\r
 \r
-  The following BaseMemoryLib instances share the same version of this file:\r
 \r
-    BaseMemoryLib\r
-    BaseMemoryLibMmx\r
-    BaseMemoryLibSse2\r
-    BaseMemoryLibRepStr\r
-    PeiMemoryLib\r
-    UefiMemoryLib\r
 \r
-**/\r
 \r
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Copy Length bytes from Source to Destination.\r
-\r
-  This function copies Length bytes from SourceBuffer to DestinationBuffer, and\r
-  returns DestinationBuffer. The implementation must be reentrant, and it must\r
-  handle the case where SourceBuffer overlaps DestinationBuffer.\r
+  Copies a source buffer to a destination buffer, and returns the destination buffer.\r
 \r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
+  This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns\r
+  DestinationBuffer.  The implementation must be reentrant, and it must handle the case\r
+  where SourceBuffer overlaps DestinationBuffer.\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  @param  Destination Target of copy\r
-  @param  Source Place to copy from\r
-  @param  Length Number of bytes to copy\r
+  @param  DestinationBuffer   Pointer to the destination buffer of the memory copy.\r
+  @param  SourceBuffer        Pointer to the source buffer of the memory copy.\r
+  @param  Length              Number of bytes to copy from SourceBuffer to DestinationBuffer.\r
 \r
-  @return Destination\r
+  @return DestinationBuffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 CopyMem (\r
-  OUT     VOID                      *Destination,\r
-  IN      CONST VOID                *Source,\r
-  IN      UINTN                     Length\r
+  OUT VOID       *DestinationBuffer,\r
+  IN CONST VOID  *SourceBuffer,\r
+  IN UINTN       Length\r
   )\r
 {\r
-  ASSERT (\r
-    Destination == NULL ||\r
-    Length <= MAX_ADDRESS - (UINTN)Destination + 1\r
-    );\r
-  ASSERT (\r
-    Source == NULL ||\r
-    Length <= MAX_ADDRESS - (UINTN)Source + 1\r
-    );\r
-  if (Destination == Source || Length == 0) {\r
-    return Destination;\r
+  if (Length == 0) {\r
+    return DestinationBuffer;\r
+  }\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
+  if (DestinationBuffer == SourceBuffer) {\r
+    return DestinationBuffer;\r
   }\r
-  return InternalMemCopyMem (Destination, Source, Length);\r
+  return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r