mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2025-02-02 22:51:28 +01:00
Fix memory allocation in GenFw.
This commit is contained in:
parent
fc457c41bb
commit
bcbcbc0ae5
@ -540,6 +540,7 @@ ScanSections64 (
|
|||||||
// First text sections.
|
// First text sections.
|
||||||
//
|
//
|
||||||
mCoffOffset = CoffAlign(mCoffOffset);
|
mCoffOffset = CoffAlign(mCoffOffset);
|
||||||
|
mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset);
|
||||||
mTextOffset = mCoffOffset;
|
mTextOffset = mCoffOffset;
|
||||||
FoundSection = FALSE;
|
FoundSection = FALSE;
|
||||||
SectionCount = 0;
|
SectionCount = 0;
|
||||||
@ -554,7 +555,7 @@ ScanSections64 (
|
|||||||
// if the section address is aligned we must align PE/COFF
|
// if the section address is aligned we must align PE/COFF
|
||||||
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x)\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset);
|
printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llu\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
||||||
mCoffOffset=mCoffOffsetNew;
|
mCoffOffset=mCoffOffsetNew;
|
||||||
} else {
|
} else {
|
||||||
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
||||||
@ -577,6 +578,7 @@ mCoffOffset=mCoffOffsetNew;
|
|||||||
|
|
||||||
mCoffSectionsOffset[i] = mCoffOffset;
|
mCoffSectionsOffset[i] = mCoffOffset;
|
||||||
mCoffOffset += (UINT32) shdr->sh_size;
|
mCoffOffset += (UINT32) shdr->sh_size;
|
||||||
|
mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset);
|
||||||
SectionCount ++;
|
SectionCount ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -610,7 +612,7 @@ mCoffOffset=mCoffOffsetNew;
|
|||||||
// if the section address is aligned we must align PE/COFF
|
// if the section address is aligned we must align PE/COFF
|
||||||
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
UINT32 mCoffOffsetNew = (UINT32) ((shdr->sh_addr + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
mCoffOffset = (UINT32) ((mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1));
|
||||||
printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x)\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset);
|
printf("Section %d %s mCoffOffset=%d(0x%x) mCoffOffsetNew=%d(0x%x) diff=%d(0x%x), size=%llu\n", i, sectName, mCoffOffset, mCoffOffset, mCoffOffsetNew, mCoffOffsetNew, mCoffOffsetNew-mCoffOffset, mCoffOffsetNew-mCoffOffset, shdr->sh_size);
|
||||||
mCoffOffset=mCoffOffsetNew;
|
mCoffOffset=mCoffOffsetNew;
|
||||||
} else {
|
} else {
|
||||||
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
|
||||||
@ -626,6 +628,7 @@ mCoffOffset=mCoffOffsetNew;
|
|||||||
}
|
}
|
||||||
mCoffSectionsOffset[i] = mCoffOffset;
|
mCoffSectionsOffset[i] = mCoffOffset;
|
||||||
mCoffOffset += (UINT32) shdr->sh_size;
|
mCoffOffset += (UINT32) shdr->sh_size;
|
||||||
|
mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset);
|
||||||
SectionCount ++;
|
SectionCount ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -673,6 +676,7 @@ mCoffOffset=mCoffOffsetNew;
|
|||||||
mCoffSectionsOffset[i] = mCoffOffset;
|
mCoffSectionsOffset[i] = mCoffOffset;
|
||||||
mCoffOffset += (UINT32) shdr->sh_size;
|
mCoffOffset += (UINT32) shdr->sh_size;
|
||||||
mCoffOffset = CoffAlign(mCoffOffset);
|
mCoffOffset = CoffAlign(mCoffOffset);
|
||||||
|
mCoffOffsetMax = MAX(mCoffOffsetMax, mCoffOffset);
|
||||||
SetHiiResourceHeader ((UINT8*) mEhdr + shdr->sh_offset, mHiiRsrcOffset);
|
SetHiiResourceHeader ((UINT8*) mEhdr + shdr->sh_offset, mHiiRsrcOffset);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -685,7 +689,7 @@ mCoffOffset=mCoffOffsetNew;
|
|||||||
// Allocate base Coff file. Will be expanded later for relocations.
|
// Allocate base Coff file. Will be expanded later for relocations.
|
||||||
//
|
//
|
||||||
NormalMsg("Allocate %d bytes for mCoffFile", mCoffOffset);
|
NormalMsg("Allocate %d bytes for mCoffFile", mCoffOffset);
|
||||||
mCoffFile = (UINT8 *)malloc(mCoffOffset);
|
mCoffFile = (UINT8 *)malloc(mCoffOffsetMax);
|
||||||
if (mCoffFile == NULL) {
|
if (mCoffFile == NULL) {
|
||||||
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
|
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ UINT16 *mCoffEntryRel;
|
|||||||
// Current offset in coff file.
|
// Current offset in coff file.
|
||||||
//
|
//
|
||||||
UINT32 mCoffOffset;
|
UINT32 mCoffOffset;
|
||||||
|
UINT32 mCoffOffsetMax;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Offset in Coff file of headers and sections.
|
// Offset in Coff file of headers and sections.
|
||||||
|
@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
// Externally defined variables
|
// Externally defined variables
|
||||||
//
|
//
|
||||||
extern UINT32 mCoffOffset;
|
extern UINT32 mCoffOffset;
|
||||||
|
extern UINT32 mCoffOffsetMax;
|
||||||
extern CHAR8 *mInImageName;
|
extern CHAR8 *mInImageName;
|
||||||
extern UINT32 mImageTimeStamp;
|
extern UINT32 mImageTimeStamp;
|
||||||
extern UINT8 *mCoffFile;
|
extern UINT8 *mCoffFile;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "YES"
|
useCustomWorkingDirectory = "YES"
|
||||||
customWorkingDirectory = "/JiefLand/5.Devel/Clover/Clover-projects/Clover--CloverHackyColor--master.2/Build/Clover/RELEASE_GCC53/X64/rEFIt_UEFI/refit/DEBUG"
|
customWorkingDirectory = "/JiefLand/5.Devel/Clover/Clover-projects/Clover--CloverHackyColor--master.2/RELEASE_GCC53"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
debugDocumentVersioning = "YES"
|
debugDocumentVersioning = "YES"
|
||||||
debugServiceExtension = "internal"
|
debugServiceExtension = "internal"
|
||||||
|
Loading…
Reference in New Issue
Block a user