aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Barnoy2010-12-22 15:33:46 +0000
committerYotam Barnoy2010-12-22 15:33:46 +0000
commita79ccfed55b881c30de598b7fadd479860b15adf (patch)
tree489809dea6193844ac92a2bf7add7af3881b53a4
parent0134ffd86ef46da8f9311b284ecdd0c5a9fe0957 (diff)
downloadscummvm-rg350-a79ccfed55b881c30de598b7fadd479860b15adf.tar.gz
scummvm-rg350-a79ccfed55b881c30de598b7fadd479860b15adf.tar.bz2
scummvm-rg350-a79ccfed55b881c30de598b7fadd479860b15adf.zip
PLUGINS: replace all size_t's with uint32's and add #include <malloc.h> to memory manager
uint32 is all we need since we only handle ELF32 anyway. svn-id: r55012
-rw-r--r--backends/plugins/elf/memory-manager.cpp17
-rw-r--r--backends/plugins/elf/memory-manager.h20
2 files changed, 19 insertions, 18 deletions
diff --git a/backends/plugins/elf/memory-manager.cpp b/backends/plugins/elf/memory-manager.cpp
index 7c6cdd328d..3682a7235d 100644
--- a/backends/plugins/elf/memory-manager.cpp
+++ b/backends/plugins/elf/memory-manager.cpp
@@ -28,7 +28,8 @@
#if defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER)
#include "backends/plugins/elf/memory-manager.h"
-#include "common/util.h"
+#include "common/util.h"
+#include <malloc.h>
DECLARE_SINGLETON(ELFMemoryManager);
@@ -56,7 +57,7 @@ void ELFMemoryManager::trackPlugin(bool value) {
} else { // we're done measuring
// get the total allocated size
- size_t measuredSize = _allocList.back().end() - _allocList.front().start;
+ uint32 measuredSize = _allocList.back().end() - _allocList.front().start;
_heapSize = MAX(_heapSize, measuredSize);
_heapAlign = MAX(_heapAlign, _measuredAlign);
@@ -68,7 +69,7 @@ void ELFMemoryManager::trackPlugin(bool value) {
}
}
-void ELFMemoryManager::trackAlloc(size_t align, size_t size) {
+void ELFMemoryManager::trackAlloc(uint32 align, uint32 size) {
if (!_measuredAlign)
_measuredAlign = align;
@@ -97,14 +98,14 @@ void ELFMemoryManager::allocateHeap() {
assert(_heap);
}
-void *ELFMemoryManager::pluginAllocate(size_t size) {
+void *ELFMemoryManager::pluginAllocate(uint32 size) {
if (_heap) {
return pluginAllocate(sizeof(void *), size);
}
return ::malloc(size);
}
-void *ELFMemoryManager::pluginAllocate(size_t align, size_t size) {
+void *ELFMemoryManager::pluginAllocate(uint32 align, uint32 size) {
if (_heap) {
return allocateOnHeap(align, size);
}
@@ -119,7 +120,7 @@ void ELFMemoryManager::pluginDeallocate(void *ptr) {
}
// Allocate space for the request in our heap
-void *ELFMemoryManager::allocateOnHeap(size_t align, size_t size) {
+void *ELFMemoryManager::allocateOnHeap(uint32 align, uint32 size) {
byte *lastAddress = (byte *)_heap;
// We can't allow allocations smaller than sizeof(Allocation). This could
@@ -135,13 +136,13 @@ void *ELFMemoryManager::allocateOnHeap(size_t align, size_t size) {
lastAddress = i->end();
// align to desired alignment
if (align) {
- lastAddress = (byte *)( ((size_t)lastAddress + align - 1) & ~(align - 1) );
+ 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 && ((size_t)lastAddress + size > (size_t)_heap + _heapSize)) {
+ if (!_trackAllocs && ((uint32)lastAddress + size > (uint32)_heap + _heapSize)) {
debug(2, "failed to find space to allocate %d bytes", size);
return 0;
}
diff --git a/backends/plugins/elf/memory-manager.h b/backends/plugins/elf/memory-manager.h
index c190f5f593..7a5f3c25df 100644
--- a/backends/plugins/elf/memory-manager.h
+++ b/backends/plugins/elf/memory-manager.h
@@ -45,12 +45,12 @@
class ELFMemoryManager : public Common::Singleton<ELFMemoryManager> {
public:
void trackPlugin(bool value);
- void trackAlloc(size_t align, size_t size);
+ void trackAlloc(uint32 align, uint32 size);
void allocateHeap();
- void *pluginAllocate(size_t size);
- void *pluginAllocate(size_t align, size_t size);
+ void *pluginAllocate(uint32 size);
+ void *pluginAllocate(uint32 align, uint32 size);
void pluginDeallocate(void *ptr);
private:
@@ -59,25 +59,25 @@ private:
ELFMemoryManager();
~ELFMemoryManager();
- void *allocateOnHeap(size_t align, size_t size);
+ void *allocateOnHeap(uint32 align, uint32 size);
void deallocateFromHeap(void *ptr);
struct Allocation {
byte *start;
- size_t size;
+ uint32 size;
byte *end() { return start + size; }
- Allocation(byte *a, size_t b) : start(a), size(b) {}
+ Allocation(byte *a, uint32 b) : start(a), size(b) {}
};
// heap
void *_heap;
- size_t _heapAlign; // alignment of the heap
- size_t _heapSize; // size of the heap
+ uint32 _heapAlign; // alignment of the heap
+ uint32 _heapSize; // size of the heap
// tracking allocations
bool _trackAllocs; // whether we are currently tracking
- size_t _measuredSize;
- size_t _measuredAlign;
+ uint32 _measuredSize;
+ uint32 _measuredAlign;
// real allocations
Common::List<Allocation> _allocList;