aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorMax Horn2010-11-05 01:20:34 +0000
committerMax Horn2010-11-05 01:20:34 +0000
commit7ace85e63646d3fd4843e7f45595bc04f3b2c7dc (patch)
tree31fb058c695dab2969f5bf6a4f33db6973c20a33 /backends
parent102e7ee88cf04fa470ec372a1ac38846d278d463 (diff)
downloadscummvm-rg350-7ace85e63646d3fd4843e7f45595bc04f3b2c7dc.tar.gz
scummvm-rg350-7ace85e63646d3fd4843e7f45595bc04f3b2c7dc.tar.bz2
scummvm-rg350-7ace85e63646d3fd4843e7f45595bc04f3b2c7dc.zip
PLUGINS: Simplify ELF plugin providers & DLObject subclasses
* Remove DLObject virtual methods allocSegment and freeSegment. As long as all DLObject implementations use memalign + free to allocate/release segments, there is no point in wrapping those. This enables further simplifications. * Add TemplatedELFPlugin template class. Use this instead of explicit ELFPlugin subclasses. * Rename DLObject::discard_symtab to discardSymtab svn-id: r54082
Diffstat (limited to 'backends')
-rw-r--r--backends/plugins/ds/ds-provider.cpp30
-rw-r--r--backends/plugins/elf/arm-loader.h5
-rw-r--r--backends/plugins/elf/elf-loader.cpp13
-rw-r--r--backends/plugins/elf/elf-loader.h4
-rw-r--r--backends/plugins/elf/elf-provider.cpp2
-rw-r--r--backends/plugins/elf/elf-provider.h13
-rw-r--r--backends/plugins/elf/mips-loader.cpp7
-rw-r--r--backends/plugins/elf/mips-loader.h5
-rw-r--r--backends/plugins/elf/ppc-loader.h5
-rw-r--r--backends/plugins/ps2/ps2-provider.cpp29
-rw-r--r--backends/plugins/psp/psp-provider.cpp30
-rw-r--r--backends/plugins/wii/wii-provider.cpp30
12 files changed, 38 insertions, 135 deletions
diff --git a/backends/plugins/ds/ds-provider.cpp b/backends/plugins/ds/ds-provider.cpp
index c188b6c9df..832fd1312c 100644
--- a/backends/plugins/ds/ds-provider.cpp
+++ b/backends/plugins/ds/ds-provider.cpp
@@ -32,43 +32,15 @@
#include "backends/plugins/elf/arm-loader.h"
class DSDLObject : public ARMDLObject {
-public:
- DSDLObject() :
- ARMDLObject() {
- }
-
- virtual ~DSDLObject() {
- unload();
- }
-
protected:
- virtual void *allocSegment(size_t boundary, size_t size) const {
- return memalign(boundary, size);
- }
-
- virtual void freeSegment(void *segment) const {
- free(segment);
- }
-
virtual void flushDataCache(void *ptr, uint32 len) const {
DC_FlushRange(ptr, len);
IC_InvalidateRange(ptr, len);
}
};
-class DSPlugin : public ELFPlugin {
-public:
- DSPlugin(const Common::String &filename) :
- ELFPlugin(filename) {
- }
-
- virtual DLObject *makeDLObject() {
- return new DSDLObject();
- }
-};
-
Plugin *DSPluginProvider::createPlugin(const Common::FSNode &node) const {
- return new DSPlugin(node.getPath());
+ return new TemplatedELFPlugin<DSDLObject>(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(__DS__)
diff --git a/backends/plugins/elf/arm-loader.h b/backends/plugins/elf/arm-loader.h
index e08f8cd0a5..cb4230c1ee 100644
--- a/backends/plugins/elf/arm-loader.h
+++ b/backends/plugins/elf/arm-loader.h
@@ -36,11 +36,6 @@ class ARMDLObject : public DLObject {
protected:
virtual bool relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment);
virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
-
-public:
- ARMDLObject() :
- DLObject() {
- }
};
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) && defined(ARM_TARGET) */
diff --git a/backends/plugins/elf/elf-loader.cpp b/backends/plugins/elf/elf-loader.cpp
index 24a4fda703..f7b151ecee 100644
--- a/backends/plugins/elf/elf-loader.cpp
+++ b/backends/plugins/elf/elf-loader.cpp
@@ -34,6 +34,8 @@
#include "common/fs.h"
#include "common/ptr.h"
+#include <malloc.h> // for memalign()
+
DLObject::DLObject() :
_file(0),
_segment(0),
@@ -49,10 +51,13 @@ DLObject::DLObject() :
}
DLObject::~DLObject() {
+ discardSymtab();
+ free(_segment);
+ _segment = 0;
}
// Expel the symbol table from memory
-void DLObject::discard_symtab() {
+void DLObject::discardSymtab() {
free(_symtab);
_symtab = 0;
@@ -64,9 +69,9 @@ void DLObject::discard_symtab() {
// Unload all objects from memory
void DLObject::unload() {
- discard_symtab();
+ discardSymtab();
- freeSegment(_segment);
+ free(_segment);
_segment = 0;
_segmentSize = 0;
@@ -160,7 +165,7 @@ bool DLObject::readProgramHeaders(Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, Elf32_Half
}
bool DLObject::loadSegment(Elf32_Phdr *phdr) {
- _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
+ _segment = (byte *)memalign(phdr->p_align, phdr->p_memsz);
if (!_segment) {
warning("elfloader: Out of memory.");
diff --git a/backends/plugins/elf/elf-loader.h b/backends/plugins/elf/elf-loader.h
index 87907d67c9..2825cc9d8d 100644
--- a/backends/plugins/elf/elf-loader.h
+++ b/backends/plugins/elf/elf-loader.h
@@ -84,8 +84,6 @@ protected:
virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) = 0;
// platform specific
- virtual void *allocSegment(size_t boundary, size_t size) const = 0;
- virtual void freeSegment(void *segment) const = 0;
virtual void flushDataCache(void *ptr, uint32 len) const = 0;
public:
@@ -95,7 +93,7 @@ public:
bool open(const char *path);
bool close();
void *symbol(const char *name);
- void discard_symtab();
+ void discardSymtab();
};
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) */
diff --git a/backends/plugins/elf/elf-provider.cpp b/backends/plugins/elf/elf-provider.cpp
index d1c8f6aa05..b241379934 100644
--- a/backends/plugins/elf/elf-provider.cpp
+++ b/backends/plugins/elf/elf-provider.cpp
@@ -137,7 +137,7 @@ bool ELFPlugin::loadPlugin() {
}
#endif
- _dlHandle->discard_symtab();
+ _dlHandle->discardSymtab();
return ret;
}
diff --git a/backends/plugins/elf/elf-provider.h b/backends/plugins/elf/elf-provider.h
index 0309ffcece..4d05c0956b 100644
--- a/backends/plugins/elf/elf-provider.h
+++ b/backends/plugins/elf/elf-provider.h
@@ -71,6 +71,19 @@ public:
void unloadPlugin();
};
+template<class T>
+class TemplatedELFPlugin : public ELFPlugin {
+public:
+ TemplatedELFPlugin(const Common::String &filename) :
+ ELFPlugin(filename) {
+ }
+
+ virtual DLObject *makeDLObject() {
+ return new T();
+ }
+};
+
+
class ELFPluginProvider : public FilePluginProvider {
protected:
virtual Plugin *createPlugin(const Common::FSNode &node) const = 0;
diff --git a/backends/plugins/elf/mips-loader.cpp b/backends/plugins/elf/mips-loader.cpp
index 53ffc2f01b..b25017af98 100644
--- a/backends/plugins/elf/mips-loader.cpp
+++ b/backends/plugins/elf/mips-loader.cpp
@@ -281,7 +281,7 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
// 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
- _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
+ _segment = (byte *)memalign(phdr->p_align, phdr->p_memsz);
if (!_segment) {
warning("elfloader: Out of memory.");
@@ -328,7 +328,10 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
// Unload all objects from memory
void MIPSDLObject::unload() {
DLObject::unload();
-
+ freeShortsSegment();
+}
+
+void MIPSDLObject::freeShortsSegment() {
if (_shortsSegment) {
ShortsMan.deleteSegment(_shortsSegment);
_shortsSegment = 0;
diff --git a/backends/plugins/elf/mips-loader.h b/backends/plugins/elf/mips-loader.h
index f8f31f1e7a..23bd5980c8 100644
--- a/backends/plugins/elf/mips-loader.h
+++ b/backends/plugins/elf/mips-loader.h
@@ -45,12 +45,17 @@ protected:
virtual bool loadSegment(Elf32_Phdr *phdr);
virtual void unload();
+ void freeShortsSegment();
+
public:
MIPSDLObject() :
DLObject() {
_shortsSegment = NULL;
_gpVal = 0;
}
+ ~MIPSDLObject() {
+ freeShortsSegment();
+ }
};
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) && defined(MIPS_TARGET) */
diff --git a/backends/plugins/elf/ppc-loader.h b/backends/plugins/elf/ppc-loader.h
index f9340a6a7b..edf2b33965 100644
--- a/backends/plugins/elf/ppc-loader.h
+++ b/backends/plugins/elf/ppc-loader.h
@@ -36,11 +36,6 @@ class PPCDLObject : public DLObject {
protected:
virtual bool relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment);
virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
-
-public:
- PPCDLObject() :
- DLObject() {
- }
};
#endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) && defined(PPC_TARGET) */
diff --git a/backends/plugins/ps2/ps2-provider.cpp b/backends/plugins/ps2/ps2-provider.cpp
index 71e715ae50..37bdff0525 100644
--- a/backends/plugins/ps2/ps2-provider.cpp
+++ b/backends/plugins/ps2/ps2-provider.cpp
@@ -29,23 +29,7 @@
#include "backends/plugins/elf/mips-loader.h"
class PS2DLObject : public MIPSDLObject {
-public:
- PS2DLObject() :
- MIPSDLObject() {
- }
-
- virtual ~PS2DLObject() {
- unload();
- }
-
protected:
- virtual void *allocSegment(size_t boundary, size_t size) const {
- return memalign(boundary, size);
- }
-
- virtual void freeSegment(void *segment) const {
- free(segment);
- }
virtual void flushDataCache(void *, uint32) const {
FlushCache(0);
@@ -53,19 +37,8 @@ protected:
}
};
-class PS2Plugin : public ELFPlugin {
-public:
- PS2Plugin(const Common::String &filename) :
- ELFPlugin(filename) {
- }
-
- virtual DLObject *makeDLObject() {
- return new PS2DLObject();
- }
-};
-
Plugin *PS2PluginProvider::createPlugin(const Common::FSNode &node) const {
- return new PS2Plugin(node.getPath());
+ return new TemplatedELFPlugin<PS2DLObject>(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(__PLAYSTATION2__)
diff --git a/backends/plugins/psp/psp-provider.cpp b/backends/plugins/psp/psp-provider.cpp
index 5bf9b0cc20..87e4428024 100644
--- a/backends/plugins/psp/psp-provider.cpp
+++ b/backends/plugins/psp/psp-provider.cpp
@@ -32,43 +32,15 @@
#include "backends/plugins/elf/mips-loader.h"
class PSPDLObject : public MIPSDLObject {
-public:
- PSPDLObject() :
- MIPSDLObject() {
- }
-
- virtual ~PSPDLObject() {
- unload();
- }
-
protected:
- virtual void *allocSegment(size_t boundary, size_t size) const {
- return memalign(boundary, size);
- }
-
- virtual void freeSegment(void *segment) const {
- free(segment);
- }
-
virtual void flushDataCache(void *ptr, uint32 len) const {
sceKernelDcacheWritebackRange(ptr, len);
sceKernelIcacheInvalidateRange(ptr, len);
}
};
-class PSPPlugin : public ELFPlugin {
-public:
- PSPPlugin(const Common::String &filename) :
- ELFPlugin(filename) {
- }
-
- virtual DLObject *makeDLObject() {
- return new PSPDLObject();
- }
-};
-
Plugin *PSPPluginProvider::createPlugin(const Common::FSNode &node) const {
- return new PSPPlugin(node.getPath());
+ return new TemplatedELFPlugin<PSPDLObject>(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(__PSP__)
diff --git a/backends/plugins/wii/wii-provider.cpp b/backends/plugins/wii/wii-provider.cpp
index 25f54f02de..b05bc59432 100644
--- a/backends/plugins/wii/wii-provider.cpp
+++ b/backends/plugins/wii/wii-provider.cpp
@@ -32,43 +32,15 @@
#include "backends/plugins/elf/ppc-loader.h"
class WiiDLObject : public PPCDLObject {
-public:
- WiiDLObject() :
- PPCDLObject() {
- }
-
- virtual ~WiiDLObject() {
- unload();
- }
-
protected:
- virtual void *allocSegment(size_t boundary, size_t size) const {
- return memalign(boundary, size);
- }
-
- virtual void freeSegment(void *segment) const {
- free(segment);
- }
-
virtual void flushDataCache(void *ptr, uint32 len) const {
DCFlushRange(ptr, len);
ICInvalidateRange(ptr, len);
}
};
-class WiiPlugin : public ELFPlugin {
-public:
- WiiPlugin(const Common::String &filename) :
- ELFPlugin(filename) {
- }
-
- virtual DLObject *makeDLObject() {
- return new WiiDLObject();
- }
-};
-
Plugin *WiiPluginProvider::createPlugin(const Common::FSNode &node) const {
- return new WiiPlugin(node.getPath());
+ return new TemplatedELFPlugin<WiiDLObject>(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(__WII__)