[Scummvm-cvs-logs] SF.net SVN: scummvm:[52576] scummvm/branches/gsoc2010-plugins/backends/ plugins/elf
dhewg at users.sourceforge.net
dhewg at users.sourceforge.net
Mon Sep 6 00:00:20 CEST 2010
Revision: 52576
http://scummvm.svn.sourceforge.net/scummvm/?rev=52576&view=rev
Author: dhewg
Date: 2010-09-05 22:00:19 +0000 (Sun, 05 Sep 2010)
Log Message:
-----------
PLUGINS: Remove spurious extra allocation.
Elf32_Phdr.p_align is to align the memory location of the loaded
segment, not to extend its size. The size of the scratch area
(like .bss and .sbss) is p_memsz-p_filesz, which has to be set to
zero by the loader.
Modified Paths:
--------------
scummvm/branches/gsoc2010-plugins/backends/plugins/elf/elf-loader.cpp
scummvm/branches/gsoc2010-plugins/backends/plugins/elf/mips-loader.cpp
Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf/elf-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf/elf-loader.cpp 2010-09-05 21:59:50 UTC (rev 52575)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf/elf-loader.cpp 2010-09-05 22:00:19 UTC (rev 52576)
@@ -157,12 +157,8 @@
}
bool DLObject::loadSegment(Elf32_Phdr *phdr) {
- // Attempt to allocate memory for segment
- uint32 extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
- debug(2, "elfloader: Extra mem is %x", extra);
+ _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
- _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
-
if (!_segment) {
warning("elfloader: Out of memory.");
return false;
@@ -171,10 +167,10 @@
debug(2, "elfloader: Allocated segment @ %p", _segment);
// Get offset to load segment into
- _segmentSize = phdr->p_memsz + extra;
+ _segmentSize = phdr->p_memsz;
_segmentVMA = phdr->p_vaddr;
- // Set bss segment to 0 if necessary (assumes bss is at the end)
+ // Set .bss segment to 0 if necessary
if (phdr->p_memsz > phdr->p_filesz) {
debug(2, "elfloader: Setting %p to %p to 0 for bss",
_segment + phdr->p_filesz, _segment + phdr->p_memsz);
Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf/mips-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf/mips-loader.cpp 2010-09-05 21:59:50 UTC (rev 52575)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf/mips-loader.cpp 2010-09-05 22:00:19 UTC (rev 52576)
@@ -273,14 +273,10 @@
// We need to take account of non-allocated segment for shorts
if (phdr->p_flags & PF_X) { // This is a relocated segment
- // Attempt to allocate memory for segment
- uint32 extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
- debug(2, "elfloader: Extra mem is %x", extra);
-
if (phdr->p_align < 0x10000)
phdr->p_align = 0x10000; // Fix for wrong alignment on e.g. AGI
- _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
+ _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
if (!_segment) {
warning("elfloader: Out of memory.");
@@ -291,7 +287,14 @@
// Get offset to load segment into
baseAddress = _segment + phdr->p_vaddr;
- _segmentSize = phdr->p_memsz + extra;
+ _segmentSize = phdr->p_memsz;
+
+ // Set .bss segment to 0 if necessary
+ if (phdr->p_memsz > phdr->p_filesz) {
+ debug(2, "elfloader: Setting %p to %p to 0 for bss",
+ _segment + phdr->p_filesz, _segment + phdr->p_memsz);
+ memset(_segment + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
+ }
} else { // This is a shorts section.
_shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *)phdr->p_vaddr);
@@ -301,7 +304,7 @@
_shortsSegment->getOffset());
}
- // Set bss segment to 0 if necessary (assumes bss is at the end)
+ // Set .sbss segment to 0 if necessary
if (phdr->p_memsz > phdr->p_filesz) {
debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz,
baseAddress + phdr->p_memsz);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list