Using CopyMem service to replace the "while" loop for the memory copy
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / Ipf / ImageRead.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ImageRead.c
15
16 Abstract:
17
18 --*/
19
20 #include "DxeIpl.h"
21
22 EFI_STATUS
23 PeiImageRead (
24 IN VOID *FileHandle,
25 IN UINTN FileOffset,
26 IN OUT UINTN *ReadSize,
27 OUT VOID *Buffer
28 )
29 /*++
30
31 Routine Description:
32
33 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
34
35 Arguments:
36
37 FileHandle - The handle to the PE/COFF file
38
39 FileOffset - The offset, in bytes, into the file to read
40
41 ReadSize - The number of bytes to read from the file starting at FileOffset
42
43 Buffer - A pointer to the buffer to read the data into.
44
45 Returns:
46
47 EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
48
49 --*/
50 {
51 CHAR8 *Destination8;
52 CHAR8 *Source8;
53 volatile UINTN Length;
54
55 Destination8 = Buffer;
56 Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
57 Length = *ReadSize;
58 CopyMem (Destination8, Source8, Length);
59
60 return EFI_SUCCESS;
61 }
62
63 EFI_STATUS
64 GetImageReadFunction (
65 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
66 )
67 {
68 ImageContext->ImageRead = PeiImageRead;
69 return EFI_SUCCESS;
70 }