There are 4 cases when comparing VirtualSize with SizeOfRawData. Original codes works very well for 3 cases but case 2. My new codes mainly focus on case 2.
I also removed ZeroMem() when Characteristics & EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA is true. This is because the original codes have already covered the case 4.
- if (Section->Characteristics & EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA) {
- ZeroMem(base, Section->Misc.VirtualSize);
- }
case 1: if VirtualSize(init+uninit) > SizeOfRawData(init+alignment), then
minSize = SizeOfRawData
CopyMem(base, data+Section->PointerToRawData, SizeOfRawData);
//We need to fill 0 in uninit part of VirtualSize
ZeroMem(base+SizeOfRawData, Section->Misc.VirtualSize-SizeOfRawData);
case 2: if VirtualSize(init+uninit) < SizeOfRawData(init+alignment), then
minSize = VirtualSize(init+uninit)
CopyMem(base, data+Section->PointerToRawData, VirtualSize);
//We might already copied garbage uninit bytes from RawData after above CopyMem(), so
//we need to fill 0 for uninit part of VirtualSize
ZeroMem(base+SizeOfRawData, Section->Misc.VirtualSize-SizeOfRawData);
case 3: if VirtualSize(init) < SizeOfRawData(init+alignment), then
minSize = VirtualSize(init)
CopyMem(base, data+Section->PointerToRawData, VirtualSize);
case 4: if VirtualSize(uninit) > SizeOfRawData(0), then
minSize = SizeOfRawData(0)
//We need to fill 0 in uninit part of VirtualSize
ZeroMem(base+0, Section->Misc.VirtualSize-0);
There are 4 cases when comparing VirtualSize with SizeOfRawData. Original codes works very well for 3 cases but case 2. My new codes mainly focus on case 2.
I also removed ZeroMem() when Characteristics & EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA is true. This is because the original codes have already covered the case 4.