mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-31 00:15:55 -04:00
attempt to remove (hopefully) unnecessary solaris and windows files; fix a couple potential leaks
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// OsMemory.cpp
|
||||
//
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
|
||||
#include "sharedMemoryManager/OsMemory.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
void OsMemory::install()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void OsMemory::remove()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void *OsMemory::reserve(size_t bytes)
|
||||
{
|
||||
return VirtualAlloc(0, bytes, MEM_RESERVE, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void *OsMemory::commit(void *addr, size_t bytes)
|
||||
{
|
||||
return VirtualAlloc(addr, bytes, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
bool OsMemory::free(void *addr, size_t bytes)
|
||||
{
|
||||
UNREF(bytes);
|
||||
return VirtualFree(addr, 0, MEM_RELEASE) ? true : false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
bool OsMemory::protect(void *addr, size_t bytes, bool allowAccess)
|
||||
{
|
||||
DWORD old;
|
||||
BOOL result = VirtualProtect(addr, bytes, allowAccess ? PAGE_READWRITE : PAGE_NOACCESS, &old);
|
||||
return result ? true : false;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// 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
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// OsNewDel.cpp
|
||||
//
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
|
||||
#include "sharedMemoryManager/OsNewDel.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
// this is here because MSVC won't call MemoryManager::allocate() from asm directly
|
||||
static void * __cdecl localAllocate(size_t size, uint32 owner, bool array, bool leakTest)
|
||||
{
|
||||
return MemoryManager::allocate(size, owner, array, leakTest);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// We are using the arguments (except for file and line), but MSVC can't tell that.
|
||||
#pragma warning(disable: 4100)
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
__declspec(naked) void *operator new(size_t size, MemoryManagerNotALeak)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
// setup local call stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
// MemoryManager::alloc(size, [return address], false, false)
|
||||
push 0
|
||||
push 0
|
||||
mov eax, dword ptr [ebp+4]
|
||||
push eax
|
||||
mov eax, dword ptr [ebp+8]
|
||||
push eax
|
||||
call localAllocate
|
||||
add esp, 12
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
__declspec(naked) void *operator new(size_t size)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
// setup local call stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
// MemoryManager::alloc(size, [return address], false, true)
|
||||
push 1
|
||||
push 0
|
||||
mov eax, dword ptr [ebp+4]
|
||||
push eax
|
||||
mov eax, dword ptr [ebp+8]
|
||||
push eax
|
||||
call localAllocate
|
||||
add esp, 12
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
__declspec(naked) void *operator new[](size_t size)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
// setup local call stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
// MemoryManager::alloc(size, [return address], true, true)
|
||||
push 1
|
||||
push 1
|
||||
mov eax, dword ptr [ebp+4]
|
||||
push eax
|
||||
mov eax, dword ptr [ebp+8]
|
||||
push eax
|
||||
call localAllocate
|
||||
add esp, 12
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
__declspec(naked) void *operator new(size_t size, const char *file, int line)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
// setup local call stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
// MemoryManager::alloc(size, [return address], false, true)
|
||||
push 1
|
||||
push 0
|
||||
mov eax, dword ptr [ebp+4]
|
||||
push eax
|
||||
mov eax, dword ptr [ebp+8]
|
||||
push eax
|
||||
call localAllocate
|
||||
add esp, 12
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
__declspec(naked) void *operator new[](size_t size, const char *file, int line)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
// setup local call stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
// MemoryManager::alloc(size, [return address], true, true)
|
||||
push 1
|
||||
push 1
|
||||
mov eax, dword ptr [ebp+4]
|
||||
push eax
|
||||
mov eax, dword ptr [ebp+8]
|
||||
push eax
|
||||
call localAllocate
|
||||
add esp, 12
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#pragma warning(default: 4100)
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void operator delete(void *pointer)
|
||||
{
|
||||
if (pointer)
|
||||
MemoryManager::free(pointer, false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void operator delete[](void *pointer)
|
||||
{
|
||||
if (pointer)
|
||||
MemoryManager::free(pointer, true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void operator delete(void *pointer, const char *file, int line)
|
||||
{
|
||||
UNREF(file);
|
||||
UNREF(line);
|
||||
|
||||
if (pointer)
|
||||
MemoryManager::free(pointer, false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void operator delete[](void *pointer, const char *file, int line)
|
||||
{
|
||||
UNREF(file);
|
||||
UNREF(line);
|
||||
|
||||
if (pointer)
|
||||
MemoryManager::free(pointer, true);
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// WARNING!!!!!!!
|
||||
//
|
||||
// The init_seg pragma command is used to create certain static objects first, before other static objects are created.
|
||||
// However, multiple static variables that use the same init_seg category(i.e. compiler) are not guaranteed to destroy in any
|
||||
// particular order. It is completely random based on how all the linking of static objects occurs. Since this command is being
|
||||
// used on our memory manager(to overwrite new/delete) - NO OTHER STATIC SHOULD EVER USE INIT_SEG(COMPILER)!!!! This static object
|
||||
// *MUST* be the final static object that is destroyed.
|
||||
//
|
||||
#pragma warning(disable: 4074)
|
||||
#pragma init_seg(compiler) // ^-Read warning above.-^
|
||||
static MemoryManager memoryManager;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// OsNewDel.h
|
||||
//
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_OsNewDel_H
|
||||
#define INCLUDED_OsNewDel_H
|
||||
|
||||
// ======================================================================
|
||||
|
||||
enum MemoryManagerNotALeak
|
||||
{
|
||||
MM_notALeak
|
||||
};
|
||||
|
||||
void * __cdecl operator new(size_t size, MemoryManagerNotALeak);
|
||||
void * __cdecl operator new(size_t size);
|
||||
void * __cdecl operator new[](size_t size);
|
||||
void * __cdecl operator new(size_t size, char const *file, int line);
|
||||
void * __cdecl operator new[](size_t size, char const *file, int line);
|
||||
void * __cdecl operator new(size_t size, void *placement);
|
||||
|
||||
void operator delete(void *pointer);
|
||||
void operator delete[](void *pointer);
|
||||
void operator delete(void *pointer, char const *file, int line);
|
||||
void operator delete[](void *pointer, char const *file, int line);
|
||||
void operator delete(void *pointer, void *placement);
|
||||
|
||||
#ifndef __PLACEMENT_NEW_INLINE
|
||||
#define __PLACEMENT_NEW_INLINE
|
||||
|
||||
inline void *operator new(size_t size, void *placement)
|
||||
{
|
||||
static_cast<void>(size);
|
||||
return placement;
|
||||
}
|
||||
|
||||
inline void operator delete(void *pointer, void *placement)
|
||||
{
|
||||
static_cast<void>(pointer);
|
||||
static_cast<void>(placement);
|
||||
}
|
||||
|
||||
#endif // __PLACEMENT_NEW_INLINE
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#endif INCLUDED_OsNewDel_H
|
||||
|
||||
Reference in New Issue
Block a user