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