Initial commits of the sharedDebug and sharedMemoryManager projects

This commit is contained in:
Anonymous
2014-01-13 09:07:22 -07:00
parent 5940c017b7
commit b632e73284
91 changed files with 12704 additions and 0 deletions
@@ -0,0 +1,40 @@
// ======================================================================
//
// OsMemory.cpp
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
#include "sharedMemoryManager/OsMemory.h"
// ======================================================================
void OsMemory::install()
{
}
// ----------------------------------------------------------------------
void OsMemory::remove()
{
}
// ----------------------------------------------------------------------
void *OsMemory::commit(void *, size_t bytes)
{
return ::malloc(bytes);
}
// ----------------------------------------------------------------------
bool OsMemory::free(void *addr, size_t)
{
::free(addr);
return true;
}
// ======================================================================
@@ -0,0 +1,29 @@
// ======================================================================
//
// OsMemory.h
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_OsMemory_H
#define INCLUDED_OsMemory_H
// ======================================================================
class OsMemory
{
public:
static void install();
static void remove();
static void * reserve(size_t bytes);
static void * commit(void *addr, size_t bytes);
static bool free(void *addr, size_t bytes);
static bool protect(void *addr, size_t bytes, bool allowAccess);
};
// ======================================================================
#endif // INCLUDED_OsMemory_H
@@ -0,0 +1,134 @@
// ======================================================================
//
// OsNewDel.cpp
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
#include "sharedMemoryManager/MemoryManager.h"
#include "sharedMemoryManager/OsNewDel.h"
#include <malloc.h>
#include <unistd.h>
#include <sys/mman.h>
static MemoryManager memoryManager __attribute__ ((init_priority (101)));
#define USE_LIBC_MALLOC_HOOKS 0
#if USE_LIBC_MALLOC_HOOKS
extern "C"
{
void memoryManagerFreeHook(__malloc_ptr_t __ptr, __const __malloc_ptr_t)
{
delete[] (char *)__ptr;
}
__malloc_ptr_t memoryManagerMallocHook(size_t __size, const __malloc_ptr_t)
{
return new char[__size];
}
__malloc_ptr_t memoryManagerReallocHook(__malloc_ptr_t __ptr, size_t size, __const __malloc_ptr_t)
{
if(! __ptr)
return new char[size];
return MemoryManager::reallocate(__ptr, size);
}
__malloc_ptr_t memoryManagerMemAlignHook(size_t alignment, size_t size, __const __malloc_ptr_t)
{
DEBUG_FATAL(true, ("memalign not implemented!"));
return new char[size];
}
static void memoryManagerMallocInitializeHook(void)
{
__free_hook = memoryManagerFreeHook;
__malloc_hook = memoryManagerMallocHook;
__realloc_hook = memoryManagerReallocHook;
__memalign_hook = memoryManagerMemAlignHook;
}
void (*__malloc_initialize_hook) (void) = memoryManagerMallocInitializeHook;
}
#endif//USE_LIBC_MALLOC_HOOKS
// ======================================================================
void *operator new(size_t size, MemoryManagerNotALeak) throw (std::bad_alloc)
{
return MemoryManager::allocate(size, reinterpret_cast<uint32>(__builtin_return_address(0)), false, false);
}
// ----------------------------------------------------------------------
void *operator new(size_t size) throw (std::bad_alloc)
{
return MemoryManager::allocate(size, reinterpret_cast<uint32>(__builtin_return_address(0)), false, true);
}
// ----------------------------------------------------------------------
void *operator new[](size_t size) throw (std::bad_alloc)
{
return MemoryManager::allocate(size, reinterpret_cast<uint32>(__builtin_return_address(0)), true, true);
}
// ----------------------------------------------------------------------
void *operator new(size_t size, const char *file, int line) throw (std::bad_alloc)
{
return MemoryManager::allocate(size, reinterpret_cast<uint32>(__builtin_return_address(0)), false, true);
}
// ----------------------------------------------------------------------
void *operator new[](size_t size, const char *file, int line) throw (std::bad_alloc)
{
return MemoryManager::allocate(size, reinterpret_cast<uint32>(__builtin_return_address(0)), true, true);
}
// ----------------------------------------------------------------------
void operator delete(void *pointer) throw()
{
if (pointer)
MemoryManager::free(pointer, false);
}
// ----------------------------------------------------------------------
void operator delete[](void *pointer) throw()
{
if (pointer)
MemoryManager::free(pointer, true);
}
// ----------------------------------------------------------------------
void operator delete(void *pointer, const char *file, int line) throw()
{
UNREF(file);
UNREF(line);
if (pointer)
MemoryManager::free(pointer, false);
}
// ----------------------------------------------------------------------
void operator delete[](void *pointer, const char *file, int line) throw()
{
UNREF(file);
UNREF(line);
if (pointer)
MemoryManager::free(pointer, true);
}
// ======================================================================
@@ -0,0 +1,33 @@
// ======================================================================
//
// OsNewDel.h
//
// Copyright 2002 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_OsNewDel_H
#define INCLUDED_OsNewDel_H
// ======================================================================
enum MemoryManagerNotALeak
{
MM_notALeak
};
void *operator new(size_t size, MemoryManagerNotALeak) throw(std::bad_alloc);
void *operator new(size_t size) throw(std::bad_alloc);
void *operator new[](size_t size) throw(std::bad_alloc);
void *operator new(size_t size, char const *file, int line) throw(std::bad_alloc);
void *operator new[](size_t size, char const *file, int line) throw(std::bad_alloc);
void operator delete(void *pointer) throw();
void operator delete[](void *pointer) throw();
void operator delete(void *pointer, char const *file, int line) throw();
void operator delete[](void *pointer, char const *file, int line) throw();
// ======================================================================
#endif // INCLUDED_OsNewDel_H