/** @file\r
Elf convert solution\r
\r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
\r
-This program and the accompanying materials are licensed and made available \r
-under the terms and conditions of the BSD License which accompanies this \r
-distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php\r
-\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
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include <string.h>\r
#include <time.h>\r
#include <ctype.h>\r
+#include <assert.h>\r
\r
#include <Common/UefiBaseTypes.h>\r
#include <IndustryStandard/PeImage.h>\r
//\r
UINT32 mTableOffset;\r
\r
+//\r
+//mFileBufferSize\r
+//\r
+UINT32 mFileBufferSize;\r
+\r
//\r
//*****************************************************************************\r
// Common ELF Functions\r
// Add a null entry (is it required ?)\r
//\r
CoffAddFixupEntry (0);\r
- \r
+\r
//\r
// Pad for alignment.\r
//\r
mCoffFile,\r
mCoffOffset + sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
);\r
+ if (mCoffFile == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ }\r
+ assert (mCoffFile != NULL);\r
memset (\r
mCoffFile + mCoffOffset, 0,\r
sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
UINT8 *FileBuffer\r
)\r
{\r
- return (FileBuffer[EI_MAG0] == ELFMAG0 && \r
+ return (FileBuffer[EI_MAG0] == ELFMAG0 &&\r
FileBuffer[EI_MAG1] == ELFMAG1 &&\r
FileBuffer[EI_MAG2] == ELFMAG2 &&\r
FileBuffer[EI_MAG3] == ELFMAG3);\r
ELF_FUNCTION_TABLE ElfFunctions;\r
UINT8 EiClass;\r
\r
+ mFileBufferSize = *FileLength;\r
//\r
// Determine ELF type and set function table pointer correctly.\r
//\r
\r
//\r
// Compute sections new address.\r
- // \r
+ //\r
VerboseMsg ("Compute sections new address.");\r
ElfFunctions.ScanSections ();\r
\r
// Write and relocate sections.\r
//\r
VerboseMsg ("Write and relocate sections.");\r
- ElfFunctions.WriteSections (SECTION_TEXT);\r
- ElfFunctions.WriteSections (SECTION_DATA);\r
- ElfFunctions.WriteSections (SECTION_HII);\r
+ if (!ElfFunctions.WriteSections (SECTION_TEXT)) {\r
+ return FALSE;\r
+ }\r
+ if (!ElfFunctions.WriteSections (SECTION_DATA)) {\r
+ return FALSE;\r
+ }\r
+ if (!ElfFunctions.WriteSections (SECTION_HII)) {\r
+ return FALSE;\r
+ }\r
\r
//\r
// Translate and write relocations.\r
VerboseMsg ("Write debug info.");\r
ElfFunctions.WriteDebug ();\r
\r
+ //\r
+ // For PRM Driver to Write export info.\r
+ //\r
+ if (mExportFlag) {\r
+ VerboseMsg ("Write export info.");\r
+ ElfFunctions.WriteExport ();\r
+ }\r
+\r
//\r
// Make sure image size is correct before returning the new image.\r
//\r
// Free resources used by ELF functions.\r
//\r
ElfFunctions.CleanUp ();\r
- \r
+\r
return TRUE;\r
}\r