mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
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
This commit is contained in:
parent
0134ffd86e
commit
a79ccfed55
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user