MSETのヒープ管理ライブラリを使うように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@665 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2012-03-15 06:26:23 +00:00
parent 5a828e6ecf
commit 57bec8362f
12 changed files with 510 additions and 164 deletions

View File

@ -1,64 +0,0 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: HeapManager.cpp
Copyright 2009 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#include "HeapManager.h"
namespace common
{
nn::fnd::ThreadSafeExpHeap s_AppHeap;
HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse)
{
m_Ptr = s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse);
}
HeapManager::~HeapManager()
{
if(m_Ptr != NULL)
{
s_AppHeap.Free(m_Ptr);
}
}
void* HeapManager::GetAddr()
{
return m_Ptr;
}
void InitializeHeap()
{
s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress() + nn::os::GetDeviceMemorySize() / 2, nn::os::GetDeviceMemorySize() / 2, nn::os::ALLOCATE_OPTION_LINEAR);
}
size_t GetAllocatableSize(s32 alignment)
{
return s_AppHeap.GetAllocatableSize(alignment);
}
void* ForceAllocate(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse)
{
return s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse);
}
void ForceFree(void* ptr)
{
if(ptr != NULL)
{
s_AppHeap.Free(ptr);
}
}
}

View File

@ -1,51 +0,0 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: HeapManager.h
Copyright 2009 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#ifndef HEAPMANAGER_H_
#define HEAPMANAGER_H_
#include <nn.h>
#include <nn/fnd.h>
namespace common
{
class HeapManager
{
public:
explicit HeapManager(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0,
nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false);
virtual ~HeapManager();
void* GetAddr();
private:
void* m_Ptr;
};
void InitializeHeap();
size_t GetAllocatableSize(s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT);
// HeapManagerを使わず確保する場合のみ
void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0,
nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false);
// HeapManagerを使わず解放する場合のみ
void ForceFree(void* ptr);
} // namespace common
#endif /* HEAPMANAGER_H_ */

View File

@ -23,13 +23,11 @@ CTR_BANNER_SPEC = AutoBoot.bsf
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
../../common \
idb/include \
$(dir $(NW4C_ROOT)/include/) \
SOURCES[] =
main.cpp
HeapManager.cpp
StateManager.cpp
CfgChanger.cpp
VersionDetect.cpp
@ -38,6 +36,7 @@ SOURCES[] =
sysUserInfoAccessor.cpp
sysFile.cpp
sysInput.cpp
sysHeap.cpp
idb/src/IDB.cpp
idb/src/IDBi.cpp
idb/src/IDBUT.cpp
@ -49,7 +48,6 @@ ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf
# DESC
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/systemapplications/Mset_EU.desc
LIBS += lib_demo \
libnn_ns \
libnn_am \

View File

@ -14,34 +14,34 @@
# $Rev:$
#----------------------------------------------------------------------------
# ディレクトリレイアウトについての説明
# ディレクトリレイアウトについての説明
#
# a) ソースコードがルートディレクトリ直下に配置される場合
# 例:
# a) ソースコードがルートディレクトリ直下に配置される場合
# 例:
# /OMakeroot
# /foo/bar/OMakefile
#
# 結果:
# OMakefile と同じディレクトリ以下に objects や images が生成されます。
# 結果:
# OMakefile と同じディレクトリ以下に objects や images が生成されます。
#
# /foo/bar/objects/...
# /foo/bar/images/..
#
#
# b) ソースコードが sources 以下に配置される場合
# 例:
# b) ソースコードが sources 以下に配置される場合
# 例:
# /OMakeroot
# /sources/foo/bar/OMakefile
#
# 結果:
# ルートディレクトリ以下に objects や images が生成されます。
# 結果:
# ルートディレクトリ以下に objects や images が生成されます。
#
# /objects/foo/bar/...
# /images/foo/bar/...
#
#
# ルート環境変数の取得
# ルート環境変数の取得
public.HORIZON_ROOT =
if $(defined-env HORIZON_ROOT)
HORIZON_ROOT = $(absname $(getenv HORIZON_ROOT))
@ -50,24 +50,36 @@ if $(defined-env HORIZON_ROOT)
if $(defined-env CTRSDK_ROOT)
CTRSDK_ROOT = $(absname $(getenv CTRSDK_ROOT))
if $(and $(defined-env HORIZON_ROOT), $(not $(equal $(HORIZON_ROOT), $(CTRSDK_ROOT))))
eprintln(HORIZON_ROOT と CTRSDK_ROOT が一致しません。同じパスを設定するか、どちらか一方だけを定義して下さい。)
eprintln(HORIZON_ROOT と CTRSDK_ROOT が一致しません。同じパスを設定するか、どちらか一方だけを定義して下さい。)
exit(1)
HORIZON_ROOT = $(CTRSDK_ROOT)
export
if $(not $(HORIZON_ROOT))
eprintln($"$$CTRSDK_ROOT が定義されていません")
eprintln($"$$CTRSDK_ROOT が定義されていません")
exit(1)
include $(HORIZON_ROOT)/build/omake/commondefs
# ルート環境変数の取得
public.NW4C_ROOT =
if $(defined-env NW4C_ROOT)
NW4C_ROOT = $(absname $(getenv NW4C_ROOT))
export
if $(not $(NW4C_ROOT))
eprintln($"$$NW4C_ROOT が定義されていません")
exit(1)
include $(getenv NW4C_ROOT)/build/omake/commondefs
DefineCommandVars()
.PHONY: all build clean clobber
.PHONY: run run-scripts run-emumem
#
# OMakefile の読み込み
# OMakefile の読み込み
#
.SUBDIRS: .

View File

@ -37,3 +37,7 @@ Option:
CardInfo:
CardDevice: NorFlash
Rom:
# ROM に含めるファイルシステムのルートパスを指定します。
HostRoot: "$(ROMFS_ROOT)"

View File

@ -17,8 +17,8 @@
#include <nn/fs.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include "sysHeap.h"
#include "VersionDetect.h"
#include "HeapManager.h"
namespace
{
@ -63,9 +63,7 @@ nn::Result GetCupVersion(nn::pl::CTR::CardUpdateVersion* cup, nn::cfg::CTR::CfgR
s64 fileSize = fis.GetSize();
NN_LOG("version.bin size = %lld\n", fileSize);
s32 ret;
void* addr = NULL;
common::HeapManager heap(fileSize);
addr = heap.GetAddr();
void* addr = sys::Mem::getMainHeap()->getHeap()->Allocate(fileSize);
if(!addr)
{
return nn::MakePermanentResult(nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_APPLICATION,
@ -83,6 +81,8 @@ nn::Result GetCupVersion(nn::pl::CTR::CardUpdateVersion* cup, nn::cfg::CTR::CfgR
NN_UTIL_RETURN_IF_FAILED(
nn::fs::Unmount("cver:")
);
sys::Mem::getMainHeap()->getHeap()->Free(addr);
return nn::ResultSuccess();
}
@ -104,10 +104,7 @@ nn::Result GetNupVersion(nn::pl::CTR::NetworkUpdateVersion* nup, nn::cfg::CTR::C
s64 fileSize = fis.GetSize();
NN_LOG("version.bin size = %lld\n", fileSize);
s32 ret;
void* addr = NULL;
common::HeapManager heap(fileSize);
addr = heap.GetAddr();
void* addr = sys::Mem::getMainHeap()->getHeap()->Allocate(fileSize);
if(!addr)
{
return nn::MakePermanentResult(nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_APPLICATION,
@ -125,6 +122,8 @@ nn::Result GetNupVersion(nn::pl::CTR::NetworkUpdateVersion* nup, nn::cfg::CTR::C
NN_UTIL_RETURN_IF_FAILED(
nn::fs::Unmount("nver:")
);
sys::Mem::getMainHeap()->getHeap()->Free(addr);
return nn::ResultSuccess();
}

View File

@ -20,14 +20,14 @@
#include <nn/cfg/CTR/detail/cfg_Keys.h>
#include <nn/ns.h>
#include <nn/hid/CTR/hid_ApiWithPrivilege.h>
#include <scene.h>
#include "HeapManager.h"
#include "sysHeap.h"
#include "syokaikidou.h"
#include "CfgChanger.h"
#include "StateManager.h"
#include "demo.h"
#include <scene.h>
#define HANDLE_ERROR(result) \
if(result.IsFailure()) \
@ -69,28 +69,31 @@ extern "C" void nnMain()
nn::applet::Enable();
nn::cfg::CTR::init::Initialize();
nn::os::Initialize();
nn::fs::Initialize();
// ヒープの準備
sys::Mem::init();
// RenderSystem の準備
const size_t gxHeapSize = nn::os::GetDeviceMemorySize() / 2;
const size_t heapSizeofRender = 8 * 1024 * 1024;
nn::fnd::ExpHeap heapForGx;
heapForGx.Initialize(nn::os::GetDeviceMemoryAddress(), gxHeapSize, nn::os::ALLOCATE_OPTION_LINEAR);
void* heapBuf = heapForGx.Allocate(heapSizeofRender);
void* heapBuf = sys::Mem::getDeviceHeap()->getHeap()->Allocate(heapSizeofRender);
s_RenderSystem.Initialize(reinterpret_cast<uptr>(heapBuf), heapSizeofRender);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1);
common::InitializeHeap();
result = nn::ns::InitializeForShell();
HANDLE_ERROR(result);
nn::fs::Initialize();
nn::hid::InitializeWithPrivilege();
nn::hid::PadReader padReader;
nn::hid::PadStatus padStatus;
const size_t heapSizeofWriter = 4 * 1024 * 1024;
void* fontHeapAddr = sys::Mem::getDeviceHeap()->getHeap()->Allocate(heapSizeofWriter);
scene::TextWriter textWriter;
textWriter.Initialize(&heapForGx);
nn::fnd::ExpHeap fontHeap;
fontHeap.Initialize(reinterpret_cast<uptr>(fontHeapAddr), heapSizeofWriter);
textWriter.Initialize(&fontHeap);
// タイトル設定
wchar_t title[] = L"CTR User Setting Manager";
@ -108,11 +111,11 @@ extern "C" void nnMain()
if(updateSaveData)
{
pManager = new StateManager(StateManager::MODE_OVERWITE);
pManager = new(sys::Mem::getMainHeap()) StateManager(StateManager::MODE_OVERWITE);
}
else
{
pManager = new StateManager(StateManager::MODE_APPLY);
pManager = new(sys::Mem::getMainHeap()) StateManager(StateManager::MODE_APPLY);
}
for(;;)

View File

@ -7,10 +7,10 @@
#include <nn/pl/CTR/pl_PedometerApiSys.h>
#include "sysSharedExtSaveData.h"
#include "sysUserInfoAccessor.h"
#include "sysHeap.h"
#include "IDB.h"
#include "IDBi.h"
#include "IDBUT.h"
#include "HeapManager.h"
#include "syokaikidou.h"
namespace System
@ -53,8 +53,7 @@ nn::Result fnc_1st_setting()
{
u32 size = IDB_GetBufferSize();
NN_LOG("idbBufferSize = %d\n", size);
common::HeapManager heap(size);
void* buf = heap.GetAddr();
u8* buf = new( sys::Mem::getMainHeap() ) u8[size];
NN_ASSERT(buf);
IDB_Initialize( reinterpret_cast<u8*>(buf), false, false );

View File

@ -7,10 +7,12 @@
#include <nn/cfg.h>
#include <nn/fs.h>
#include "sysFile.h"
#include "sysHeap.h"
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <nn/fs/fs_ApiSysSaveData.h>
#include <nn/CTR/CTR_ProgramId.h>
#include "HeapManager.h"
#define cDefaultDeviceAlignment 4
namespace sys
{
@ -69,7 +71,7 @@ u8* File::read( const wchar_t* fileName, u32* size, bool device, bool prefix )
// ファイルシステム内にこれを書くのは正直どうかと思う
// resLoader側に移動するかも
#ifdef NW_PLATFORM_CTR
swprintf( name, 128, L"rom:/%ls", (wchar_t*)fileName );
std::swprintf( name, 128, L"rom:/%ls", (wchar_t*)fileName );
#else
std::swprintf( name, 128, L"data/%s", fileName );
#endif
@ -97,7 +99,8 @@ u8* File::read( const wchar_t* fileName, u32* size, bool device, bool prefix )
}
*size = static_cast<u32>( fileSize );
buffer = reinterpret_cast<u8*>(common::ForceAllocate(*size));
if( device ) buffer = new( Mem::getDeviceHeap(), cDefaultDeviceAlignment ) u8[ *size ];
else buffer = new( Mem::getMainHeap() ) u8[ *size ];
if( buffer == NULL )
{
@ -111,7 +114,7 @@ u8* File::read( const wchar_t* fileName, u32* size, bool device, bool prefix )
{
debug_print_();
fileReader.Finalize();
common::ForceFree(buffer);
delete buffer;
return NULL;
}
@ -522,7 +525,7 @@ u8* pTmp = NULL;
{
// 管理ファイルが読み込めた
std::memcpy( pSaveData, pTmp, size );
common::ForceFree(pTmp);
delete pTmp;
}
}

View File

@ -0,0 +1,275 @@
/*!
@file sysHeap.cpp
@brief
*/
//#include "sys.h"
#include "sysHeap.h"
#ifndef NW_RELEASE
//#include "sceneManager.h"
#endif
static const size_t scMainHeapSize = 0x800000; // 8MB
static const size_t scSceneHeapSize = 0x200000; // 2MB
static const size_t scDeviceHeapSize = 0x1000000; // 16MB
#ifdef DEBUG_MEMORY
static size_t smSceneHeapSize = 0xffffffff;
static size_t smMainHeapSize = 0xffffffff;
static size_t smDeviceHeapSize = 0xffffffff;
#endif
// デフォルトのStartUp関数を呼ばないようにする
extern "C" void nninitStartUp(void)
{
nn::os::SetDeviceMemorySize(0);
nn::os::SetHeapSize(0);
}
namespace sys
{
#ifndef NW_RELEASE
Mem::MemList Mem::smList;
#endif
Heap Mem::smMainHeap;
Heap Mem::smSceneHeap;
Heap Mem::smDeviceHeap;
/*!
*/
void Mem::init()
{
NN_LOG("Use Memory Size:0x%x %x\n", nn::os::GetUsingMemorySize(), nn::os::GetAppMemorySize() );
nn::os::SetHeapSize( scMainHeapSize + scSceneHeapSize );
nn::Result result = nn::os::SetDeviceMemorySize( scDeviceHeapSize );
NN_UTIL_PANIC_IF_FAILED( result );
size_t size = nn::os::GetHeapSize();
uptr address = nn::os::GetHeapAddress();
NN_LOG("################# Main Memory : 0x%x - 0x%x #################\n", ( uint )address, ( ( uint )address + size ) );
// メインメモリ初期化
smMainHeap.getHeap()->Initialize( address, scMainHeapSize, nn::os::ALLOCATE_OPTION_LINEAR );
// シーンメモリ初期化
smSceneHeap.getHeap()->Initialize( address + scMainHeapSize, size - scMainHeapSize, nn::os::ALLOCATE_OPTION_LINEAR );
// デバイス用メモリ初期化
smDeviceHeap.getHeap()->Initialize( nn::os::GetDeviceMemoryAddress(), scDeviceHeapSize, nn::os::ALLOCATE_OPTION_LINEAR );
nwosPrintf("################# Device Memory : 0x%x - 0x%x #################\n", nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemoryAddress() + scDeviceHeapSize );
{
s32 memSize = nn::fs::GetRomRequiredMemorySize(
/*ROMFS_MAX_FILE, ROMFS_MAX_DIRECTORY*/128, 128 );
// s32 memSize = 32 * 1024;
u8* fs_buf = new( &smMainHeap ) u8[ memSize ];
bool ret = nn::fs::MountRom(
128,//ROMFS_MAX_FILE,
128,//ROMFS_MAX_DIRECTORY,
fs_buf,
memSize ).IsSuccess();
// NN_LOG("RomFS: mem(%p) size(%d) files(%d) dirs(%d)\n",
// fs_buf, memSize,
// /*ROMFS_MAX_FILE, ROMFS_MAX_DIRECTORY*/128, 128 );
}
#ifndef NW_RELEASE
// デバッグ用SDカードアクセス
nn::fs::MountSdmc();
#endif
}
/*!
*/
void Mem::finish()
{
smSceneHeap.getHeap()->Invalidate();
smMainHeap.getHeap()->Invalidate();
smDeviceHeap.getHeap()->Invalidate();
nn::os::SetHeapSize(0);
nn::os::SetDeviceMemorySize(0);
}
void* Mem::AllocDeviceMemory( size_t size, s32 alignment )
{
// 2のべき乗のチェック
NW_ASSERT( (alignment & (alignment - 1)) == 0 );
if ( alignment == 0 ) { alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT; }
void* memory = smDeviceHeap.getHeap()->Allocate( size, alignment );
#ifdef DEBUG_MEMORY
if( smDeviceHeap.getHeap()->GetAllocatableSize() < smDeviceHeapSize )
{
smDeviceHeapSize = smDeviceHeap.getHeap()->GetAllocatableSize();
NN_LOG("DeviceHeap AllocatableSize: 0x%x\n", smDeviceHeapSize );
// sys::Mem::getDeviceHeap()->getHeap()->Dump();
}
#endif
return memory;
}
void* Mem::Alloc( Heap* p_heap, size_t size, s32 alignment )
{
// 2のべき乗のチェック
NW_ASSERT( (alignment & (alignment - 1)) == 0 );
NW_ASSERT( p_heap != &smDeviceHeap );
if( alignment == 0 ) alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT;
if( p_heap == NULL ) p_heap = &smMainHeap;
void* memory = p_heap->getHeap()->Allocate( size, alignment );
#ifndef NW_RELEASE
if( p_heap == &smSceneHeap )
{
NW_ASSERTMSG(memory, "Failed allocate SceneHeap %d/%d", size,
scSceneHeapSize - p_heap->getHeap()->GetTotalSize() );
//SceneMem* mem = new( &smMainHeap ) SceneMem( memory, scene::Manager::getActiveSceneID(), size );
//smList.PushBack( mem );
}
#endif
#ifdef DEBUG_MEMORY
if( p_heap == &smSceneHeap &&
smSceneHeap.getHeap()->GetAllocatableSize() < smSceneHeapSize )
{
smSceneHeapSize = smSceneHeap.getHeap()->GetAllocatableSize();
NN_LOG("SceneHeap AllocatableSize: 0x%x\n", smSceneHeapSize );
// sys::Mem::getSceneHeap()->getHeap()->Dump();
}
if( p_heap == &smMainHeap &&
smMainHeap.getHeap()->GetAllocatableSize() < smMainHeapSize )
{
smMainHeapSize = smMainHeap.getHeap()->GetAllocatableSize();
NN_LOG("MainHeap AllocatableSize: 0x%x\n", smMainHeapSize );
// sys::Mem::getMainHeap()->getHeap()->Dump();
}
#endif
return memory;
}
void Mem::Free( void* memory )
{
if( smDeviceHeap.getHeap()->HasAddress( memory ) )
{
smDeviceHeap.getHeap()->Free( memory );
}
else if( smMainHeap.getHeap()->HasAddress( memory ) )
{
smMainHeap.getHeap()->Free( memory );
}
else
{
smSceneHeap.getHeap()->Free( memory );
#ifndef NW_RELEASE
for( MemList::Iterator it = smList.GetBeginIter(); it != smList.GetEndIter(); ++it )
{
SceneMem* mem = reinterpret_cast< SceneMem* >( &(*it) );
if( mem->getAddress() == memory )
{
smList.Erase( mem );
delete mem;
break;
}
}
#endif
}
}
/*!
*/
#ifndef NW_RELEASE
bool Mem::checkSceneHeap( int scene_id )
{
bool ret = true;
for( MemList::Iterator it = smList.GetBeginIter(); it != smList.GetEndIter(); ++it )
{
SceneMem* mem = reinterpret_cast< SceneMem* >( &(*it) );
if( mem->getID() == scene_id )
{
NN_LOG("%d Scene Memory Leak!!(size%d) (addr%x)\n", scene_id, mem->getSize(), mem->getAddress() );
ret = false;
}
}
return ret;
}
#endif
}
void* operator new( size_t size, int alignment ) throw()
{
NW_ASSERT( 0 );
return operator new( size, NULL, alignment );
}
void* operator new( size_t size, sys::Heap* p_heap, int alignment ) throw()
{
if( p_heap == sys::Mem::getDeviceHeap() )
{
return sys::Mem::AllocDeviceMemory( size, alignment );
}
return sys::Mem::Alloc( p_heap, size, alignment );
}
void* operator new[]( size_t size, int alignment ) throw()
{
NW_ASSERT( 0 );
return operator new[]( size, NULL, alignment );
}
void* operator new[]( size_t size, const ::std::nothrow_t& ) throw()
{
return operator new[]( size, NULL, NN_FND_HEAP_DEFAULT_ALIGNMENT );
}
void* operator new[]( size_t size, sys::Heap* p_heap, int alignment ) throw()
{
if( p_heap == sys::Mem::getDeviceHeap() )
{
return sys::Mem::AllocDeviceMemory( size, alignment );
}
return sys::Mem::Alloc( p_heap, size, alignment );
}
void operator delete( void* mem_block ) throw()
{
if( mem_block != NULL )
{
sys::Mem::Free( mem_block );
}
}
void operator delete[]( void* mem_block ) throw()
{
if( mem_block != NULL )
{
sys::Mem::Free( mem_block );
}
}

View File

@ -0,0 +1,169 @@
/*!
@file sysHeap.h
@brief
*/
#ifndef SYS_HEAP_H_
#define SYS_HEAP_H_
#include <nw/types.h>
#include <nn/fnd.h>
#include <nw.h>
//#include "sysMacro.h"
namespace sys
{
#ifndef NW_RELEASE
class SceneMem
{
public:
SceneMem( void* address, int id, u32 size ) :
mpAddress( address ),
mID( id ),
mSize( size ){}
void* getAddress(){ return mpAddress; }
int getID(){ return mID; }
u32 getSize(){ return mSize; }
nw::ut::LinkListNode mLink;
private:
void* mpAddress;
int mID;
u32 mSize;
};
#endif
class Heap
{
public:
nn::fnd::ThreadSafeExpHeap* getHeap()
{
return &msHeap;
}
private:
nn::fnd::ThreadSafeExpHeap msHeap;
};
class Allocator;
class Mem
{
public:
static void init();
static void finish();
static void* AllocDeviceMemory( size_t size, s32 alignment );
static void* Alloc( Heap* p_heap, size_t size, s32 alignment );
static void Free( void* memory );
static Heap* getMainHeap(){ return &smMainHeap; }
static Heap* getSceneHeap(){ return &smSceneHeap; }
static Heap* getDeviceHeap(){ return &smDeviceHeap; }
#ifndef NW_RELEASE
static bool checkSceneHeap( int scene_id );
static size_t getMainFreeSize()
{
return smMainHeap.getHeap()->GetTotalFreeSize();
}
static size_t getSceneFreeSize()
{
return smSceneHeap.getHeap()->GetTotalFreeSize();
}
static size_t getDeviceFreeSize()
{
return smDeviceHeap.getHeap()->GetTotalFreeSize();
}
#endif
private:
#ifndef NW_RELEASE
typedef nw::ut::LinkList<SceneMem, offsetof( SceneMem, mLink )> MemList;
static MemList smList;
#endif
static Heap smMainHeap;
static Heap smSceneHeap;
static Heap smDeviceHeap;
};
/*!
SDKメモリアロケータ
*/
class SdkAllocator : public nn::fnd::IAllocator
{
public:
virtual void* Allocate( size_t size, s32 alignment )
{
return sys::Mem::Alloc( NULL, size, alignment );
}
virtual void Free(void* memory)
{
sys::Mem::Free( memory );
}
};
/*!
*/
class Allocator : public nw::os::IAllocator
{
public:
virtual void* Alloc( size_t size, u8 alignment )
{
return sys::Mem::Alloc( NULL, size, alignment );
}
using nw::os::IAllocator::Alloc;
virtual void Free(void* memory)
{
sys::Mem::Free( memory );
}
};
/*!
*/
class DeviceAllocator : public nw::os::IAllocator
{
public:
virtual void* Alloc( size_t size, u8 alignment )
{
return sys::Mem::AllocDeviceMemory( size, alignment );
}
using nw::os::IAllocator::Alloc;
virtual void Free( void* memory )
{
sys::Mem::Free( memory );
}
};
}
extern void* operator new( size_t size, sys::Heap* p_heap, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new( size_t size, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new[]( size_t size, const ::std::nothrow_t& ) throw();
extern void* operator new[]( size_t size, sys::Heap* p_heap, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new[]( size_t size, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void operator delete( void* mem_block ) throw();
extern void operator delete[]( void* mem_block ) throw();
#endif

View File

@ -4,8 +4,8 @@
*/
#ifndef MAKE_AREACHECK
#include "HeapManager.h"
//#include "sys.h"
#include "sysHeap.h"
#include "sysUserInfoAccessor.h"
//#include "sysKeyboardManager.h"
@ -2218,7 +2218,7 @@ size_t readDataSize = 0;
result = action.AddHeaderField( "X-Boss-Digest", setSha1Hash );
delete[] readDataSha1;
common::ForceFree(readData);
delete[] readData;
NN_RESULT_ASSERT( result );
}
@ -2291,8 +2291,7 @@ nn::Result result;
bool UserInfoAccessor::save_boss_send_info_()
{
size_t size = sizeof( BossSendInfo );
common::HeapManager heap(size);
BossSendInfo* pSaveData = reinterpret_cast<BossSendInfo*>(heap.GetAddr());
BossSendInfo* pSaveData = new( sys::Mem::getMainHeap() ) BossSendInfo;
bool ret = false;
sys::File::initializeMsetSys();