ALL: Remove trailing whitespaces
This tries to make our code a bit more compliant with our code formatting conventions. For future use, this is the command I used: git ls-files "*.cpp" "*.h" | xargs sed -i -e 's/[ \t]*$//'
This commit is contained in:
parent
3853e76202
commit
88913c0139
314 changed files with 1761 additions and 1761 deletions
|
@ -169,7 +169,7 @@ bool DLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
warning("elfloader: Out of memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
debug(2, "elfloader: Allocated segment @ %p", _segment);
|
||||
|
||||
// Get offset to load segment into
|
||||
|
@ -222,7 +222,7 @@ Elf32_Shdr * DLObject::loadSectionHeaders(Elf32_Ehdr *ehdr) {
|
|||
|
||||
int DLObject::findSymbolTableSection(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
|
||||
int SymbolTableSection = -1;
|
||||
|
||||
|
||||
// Loop over sections, looking for symbol table linked to a string table
|
||||
for (uint32 i = 0; i < ehdr->e_shnum; i++) {
|
||||
if (shdr[i].sh_type == SHT_SYMTAB &&
|
||||
|
@ -233,7 +233,7 @@ int DLObject::findSymbolTableSection(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return SymbolTableSection;
|
||||
}
|
||||
|
||||
|
@ -315,12 +315,12 @@ void DLObject::relocateSymbols(ptrdiff_t offset) {
|
|||
}
|
||||
|
||||
// Track the size of the plugin through memory manager without loading
|
||||
// the plugin into memory.
|
||||
// the plugin into memory.
|
||||
//
|
||||
void DLObject::trackSize(const char *path) {
|
||||
|
||||
|
||||
_file = Common::FSNode(path).createReadStream();
|
||||
|
||||
|
||||
if (!_file) {
|
||||
warning("elfloader: File %s not found.", path);
|
||||
return;
|
||||
|
@ -334,11 +334,11 @@ void DLObject::trackSize(const char *path) {
|
|||
_file = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ELFMemMan.trackPlugin(true); // begin tracking the plugin size
|
||||
|
||||
|
||||
// Load the segments
|
||||
for (uint32 i = 0; i < ehdr.e_phnum; i++) {
|
||||
for (uint32 i = 0; i < ehdr.e_phnum; i++) {
|
||||
debug(2, "elfloader: Loading segment %d", i);
|
||||
|
||||
if (!readProgramHeaders(&ehdr, &phdr, i)) {
|
||||
|
@ -351,7 +351,7 @@ void DLObject::trackSize(const char *path) {
|
|||
ELFMemMan.trackAlloc(phdr.p_align, phdr.p_memsz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ELFMemMan.trackPlugin(false); // we're done tracking the plugin size
|
||||
|
||||
delete _file;
|
||||
|
@ -367,7 +367,7 @@ bool DLObject::load() {
|
|||
return false;
|
||||
|
||||
//Load the segments
|
||||
for (uint32 i = 0; i < ehdr.e_phnum; i++) {
|
||||
for (uint32 i = 0; i < ehdr.e_phnum; i++) {
|
||||
debug(2, "elfloader: Loading segment %d", i);
|
||||
|
||||
if (readProgramHeaders(&ehdr, &phdr, i) == false)
|
||||
|
@ -386,12 +386,12 @@ bool DLObject::load() {
|
|||
free(shdr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!loadStringTable(shdr)) {
|
||||
free(shdr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Offset by our segment allocated address
|
||||
// must use _segmentVMA here for multiple segments (MIPS)
|
||||
_segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
|
||||
|
|
|
@ -100,7 +100,7 @@ DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
|
|||
void ELFPlugin::trackSize() {
|
||||
// All we need to do is create our object, track its size, then delete it
|
||||
DLObject *obj = makeDLObject();
|
||||
|
||||
|
||||
obj->trackSize(_filename.c_str());
|
||||
delete obj;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ void ELFPlugin::unloadPlugin() {
|
|||
PluginList ELFPluginProvider::getPlugins() {
|
||||
PluginList pl = FilePluginProvider::getPlugins();
|
||||
|
||||
#if defined(UNCACHED_PLUGINS) && !defined(ELF_NO_MEM_MANAGER)
|
||||
#if defined(UNCACHED_PLUGINS) && !defined(ELF_NO_MEM_MANAGER)
|
||||
// This static downcast is safe because all of the plugins must
|
||||
// be ELF plugins
|
||||
for (PluginList::iterator p = pl.begin(); p != pl.end(); ++p) {
|
||||
|
@ -190,8 +190,8 @@ PluginList ELFPluginProvider::getPlugins() {
|
|||
// The Memory Manager should now allocate space based on the information
|
||||
// it collected
|
||||
ELFMemMan.allocateHeap();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#if defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER)
|
||||
|
||||
|
@ -28,12 +28,12 @@
|
|||
#include "common/debug.h"
|
||||
#include "common/util.h"
|
||||
#include <malloc.h>
|
||||
|
||||
DECLARE_SINGLETON(ELFMemoryManager);
|
||||
|
||||
ELFMemoryManager::ELFMemoryManager() :
|
||||
_heap(0), _heapSize(0), _heapAlign(0),
|
||||
_trackAllocs(false), _measuredSize(0), _measuredAlign(0),
|
||||
DECLARE_SINGLETON(ELFMemoryManager);
|
||||
|
||||
ELFMemoryManager::ELFMemoryManager() :
|
||||
_heap(0), _heapSize(0), _heapAlign(0),
|
||||
_trackAllocs(false), _measuredSize(0), _measuredAlign(0),
|
||||
_bytesAllocated(0) {}
|
||||
|
||||
ELFMemoryManager::~ELFMemoryManager() {
|
||||
|
@ -46,23 +46,23 @@ void ELFMemoryManager::trackPlugin(bool value) {
|
|||
|
||||
if (value == _trackAllocs)
|
||||
return;
|
||||
|
||||
|
||||
_trackAllocs = value;
|
||||
|
||||
|
||||
if (_trackAllocs) { // start measuring
|
||||
// start tracking allocations
|
||||
_measuredAlign = 0;
|
||||
|
||||
|
||||
} else { // we're done measuring
|
||||
// get the total allocated size
|
||||
uint32 measuredSize = _allocList.back().end() - _allocList.front().start;
|
||||
|
||||
_heapSize = MAX(_heapSize, measuredSize);
|
||||
_heapAlign = MAX(_heapAlign, _measuredAlign);
|
||||
|
||||
|
||||
_allocList.clear();
|
||||
_bytesAllocated = 0; // reset
|
||||
|
||||
|
||||
debug(2, "measured a plugin of size %d. Max size %d. Max align %d", measuredSize, _heapSize, _heapAlign);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void ELFMemoryManager::trackPlugin(bool value) {
|
|||
void ELFMemoryManager::trackAlloc(uint32 align, uint32 size) {
|
||||
if (!_measuredAlign)
|
||||
_measuredAlign = align;
|
||||
|
||||
|
||||
// use the allocate function to simulate allocation
|
||||
allocateOnHeap(align, size);
|
||||
}
|
||||
|
@ -79,20 +79,20 @@ void ELFMemoryManager::allocateHeap() {
|
|||
// The memory manager should only allocate once
|
||||
assert (!_heap);
|
||||
assert (_heapSize);
|
||||
|
||||
|
||||
// clear the list
|
||||
_allocList.clear();
|
||||
_bytesAllocated = 0;
|
||||
|
||||
|
||||
debug(2, "ELFMemoryManager: allocating %d bytes aligned at %d as the \
|
||||
plugin heap", _heapSize, _heapAlign);
|
||||
|
||||
|
||||
// prepare the heap
|
||||
if (_heapAlign)
|
||||
if (_heapAlign)
|
||||
_heap = ::memalign(_heapAlign, _heapSize);
|
||||
else
|
||||
_heap = ::malloc(_heapSize);
|
||||
|
||||
|
||||
assert(_heap);
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ void *ELFMemoryManager::pluginAllocate(uint32 size) {
|
|||
void *ELFMemoryManager::pluginAllocate(uint32 align, uint32 size) {
|
||||
if (_heap) {
|
||||
return allocateOnHeap(align, size);
|
||||
}
|
||||
}
|
||||
return ::memalign(align, size);
|
||||
}
|
||||
|
||||
|
@ -120,16 +120,16 @@ void ELFMemoryManager::pluginDeallocate(void *ptr) {
|
|||
// Allocate space for the request in our heap
|
||||
void *ELFMemoryManager::allocateOnHeap(uint32 align, uint32 size) {
|
||||
byte *lastAddress = (byte *)_heap;
|
||||
|
||||
|
||||
// We can't allow allocations smaller than sizeof(Allocation). This could
|
||||
// only be from non-plugin allocations and would cause infinite recursion
|
||||
// only be from non-plugin allocations and would cause infinite recursion
|
||||
// when allocating our Allocation in the list.
|
||||
if (size <= sizeof(Allocation))
|
||||
return 0;
|
||||
|
||||
|
||||
Common::List<Allocation>::iterator i;
|
||||
for (i = _allocList.begin(); i != _allocList.end(); i++) {
|
||||
if (i->start - lastAddress > (int)size)
|
||||
if (i->start - lastAddress > (int)size)
|
||||
break;
|
||||
lastAddress = i->end();
|
||||
// align to desired alignment
|
||||
|
@ -137,20 +137,20 @@ void *ELFMemoryManager::allocateOnHeap(uint32 align, uint32 size) {
|
|||
lastAddress = (byte *)( ((uint32)lastAddress + align - 1) & ~(align - 1) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if we exceeded our heap limit
|
||||
// We skip this case if we're only tracking allocations
|
||||
if (!_trackAllocs && ((uint32)lastAddress + size > (uint32)_heap + _heapSize)) {
|
||||
debug(2, "failed to find space to allocate %d bytes", size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
_allocList.insert(i, Allocation(lastAddress, size));
|
||||
_bytesAllocated += size;
|
||||
|
||||
debug(7, "ELFMemoryManager: allocated %d bytes at %p. Total %d bytes",
|
||||
|
||||
debug(7, "ELFMemoryManager: allocated %d bytes at %p. Total %d bytes",
|
||||
size, lastAddress, _bytesAllocated);
|
||||
|
||||
|
||||
return lastAddress;
|
||||
}
|
||||
|
||||
|
@ -159,14 +159,14 @@ void ELFMemoryManager::deallocateFromHeap(void *ptr) {
|
|||
for (i = _allocList.begin(); i != _allocList.end(); i++) {
|
||||
if (i->start == ptr) {
|
||||
_bytesAllocated -= (*i).size;
|
||||
|
||||
debug(7, "ELFMemoryManager: freed %d bytes at %p. Total %d bytes",
|
||||
|
||||
debug(7, "ELFMemoryManager: freed %d bytes at %p. Total %d bytes",
|
||||
(*i).size, (*i).start, _bytesAllocated);
|
||||
|
||||
|
||||
_allocList.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) */
|
||||
|
|
|
@ -30,17 +30,17 @@
|
|||
#include "common/singleton.h"
|
||||
#include "common/list.h"
|
||||
#include "common/mutex.h"
|
||||
|
||||
|
||||
/**
|
||||
* A 'foolproof' way to prevent memory fragmentation. This class is used to
|
||||
* serve as a permanent allocation to prevent the process of loading and
|
||||
* A 'foolproof' way to prevent memory fragmentation. This class is used to
|
||||
* serve as a permanent allocation to prevent the process of loading and
|
||||
* unloading plugins from causing heavy fragmentation.
|
||||
**/
|
||||
|
||||
|
||||
#define ELFMemMan ELFMemoryManager::instance()
|
||||
|
||||
|
||||
class ELFMemoryManager : public Common::Singleton<ELFMemoryManager> {
|
||||
public:
|
||||
public:
|
||||
void trackPlugin(bool value);
|
||||
void trackAlloc(uint32 align, uint32 size);
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
void *pluginAllocate(uint32 size);
|
||||
void *pluginAllocate(uint32 align, uint32 size);
|
||||
void pluginDeallocate(void *ptr);
|
||||
|
||||
|
||||
private:
|
||||
friend class Common::Singleton<ELFMemoryManager>;
|
||||
|
||||
|
@ -58,7 +58,7 @@ private:
|
|||
|
||||
void *allocateOnHeap(uint32 align, uint32 size);
|
||||
void deallocateFromHeap(void *ptr);
|
||||
|
||||
|
||||
struct Allocation {
|
||||
byte *start;
|
||||
uint32 size;
|
||||
|
@ -70,17 +70,17 @@ private:
|
|||
void *_heap;
|
||||
uint32 _heapAlign; // alignment of the heap
|
||||
uint32 _heapSize; // size of the heap
|
||||
|
||||
|
||||
// tracking allocations
|
||||
bool _trackAllocs; // whether we are currently tracking
|
||||
uint32 _measuredSize;
|
||||
uint32 _measuredAlign;
|
||||
|
||||
uint32 _measuredSize;
|
||||
uint32 _measuredAlign;
|
||||
|
||||
// real allocations
|
||||
Common::List<Allocation> _allocList;
|
||||
uint32 _bytesAllocated;
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) */
|
||||
|
||||
#endif /* ELF_MEMORY_MANAGER_H */
|
||||
|
|
|
@ -53,7 +53,7 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
|
|||
debug(2, "elfloader: Loaded relocation table. %d entries. base address=%p", cnt, relSegment);
|
||||
|
||||
Elf32_Addr adjustedMainSegment = Elf32_Addr(_segment) - _segmentVMA; // adjust for VMA offset
|
||||
|
||||
|
||||
bool seenHi16 = false; // For treating HI/LO16 commands
|
||||
int32 firstHi16 = -1; // Mark the point of the first hi16 seen
|
||||
Elf32_Addr ahl = 0; // Calculated addend
|
||||
|
@ -259,7 +259,7 @@ void MIPSDLObject::relocateSymbols(ptrdiff_t offset) {
|
|||
if (!ShortsMan.inGeneralSegment((char *)s->st_value)) {
|
||||
if (s->st_value < _segmentVMA)
|
||||
s->st_value = _segmentVMA; // deal with symbols referring to sections, which start before the VMA
|
||||
|
||||
|
||||
s->st_value += offset;
|
||||
|
||||
if (s->st_value < Elf32_Addr(_segment) || s->st_value > Elf32_Addr(_segment) + _segmentSize)
|
||||
|
@ -287,7 +287,7 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
}
|
||||
|
||||
debug(2, "elfloader: Allocated segment @ %p", _segment);
|
||||
|
||||
|
||||
// Get offset to load segment into
|
||||
baseAddress = _segment;
|
||||
_segmentSize = phdr->p_memsz;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue