CopyMemWrapper.c 2.1 KB

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