From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- .../HeapInspector/Samples/Hook/HookSample.cpp | 30 ++++ .../Samples/Hook/PS3/HookSample.vcproj | 183 ++++++++++++++++++++ .../Samples/Hook/PS3/HookSample.vcxproj | 72 ++++++++ .../HeapInspector/Samples/Hook/PS3/Main.cpp | 18 ++ .../HeapInspector/Samples/Hook/PS3/Wait.cpp | 6 + .../HeapInspector/Samples/Manual/ManualSample.cpp | 78 +++++++++ .../HeapInspector/Samples/Manual/PS3/Main.cpp | 7 + .../Samples/Manual/PS3/ManualSample.vcproj | 183 ++++++++++++++++++++ .../Samples/Manual/PS3/ManualSample.vcxproj | 70 ++++++++ .../HeapInspector/Samples/Manual/PS3/Wait.cpp | 6 + .../Samples/MultiThreadedHook/IThread.h | 17 ++ .../MultiThreadedHook/MultiThreadedHookSample.cpp | 80 +++++++++ .../Samples/MultiThreadedHook/PS3/Main.cpp | 18 ++ .../PS3/MultiThreadedHookSample.vcproj | 191 +++++++++++++++++++++ .../PS3/MultiThreadedHookSample.vcxproj | 76 ++++++++ .../Samples/MultiThreadedHook/PS3/ThreadPS3.cpp | 41 +++++ .../Samples/MultiThreadedHook/PS3/Wait.cpp | 6 + .../Samples/ReplaceNewDelete/PS3/Main.cpp | 7 + .../PS3/ReplaceNewDeleteSample.vcproj | 183 ++++++++++++++++++++ .../PS3/ReplaceNewDeleteSample.vcxproj | 70 ++++++++ .../Samples/ReplaceNewDelete/PS3/Wait.cpp | 6 + .../ReplaceNewDelete/ReplaceNewDeleteSample.cpp | 67 ++++++++ 22 files changed, 1415 insertions(+) create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/HookSample.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcxproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Main.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Wait.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Main.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcxproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Wait.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/IThread.h create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/MultiThreadedHookSample.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Main.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcxproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/ThreadPS3.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Wait.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Main.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcxproj create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Wait.cpp create mode 100644 Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp (limited to 'Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples') diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/HookSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/HookSample.cpp new file mode 100644 index 00000000..07ad4e20 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/HookSample.cpp @@ -0,0 +1,30 @@ +// ================================================================================================================================= +// This sample demonstrates how to use the auto-hooking functionality of HeapInspector. On PlayStation 3, this uses link-time +// malloc/realloc/free overloading. On PC it uses the mhook API, which will hook into the very low-level HeapAlloc, HeapRealloc +// and HeapFree functions. This will cause any allocations in your application to be caught. +// +// NOTE: the platform specific hooking calls can be found in the Main.cpp. +// ================================================================================================================================= + +#include + +void Wait(int a_MilliSeconds); + +void RunHeapInspectorServer() +{ + while (1) + { + void* mem1; + void* memB; + + mem1 = malloc(16); + memB = malloc(1024); + + Wait(100); + + free(mem1); + free(memB); + + Wait(100); + } +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcproj new file mode 100644 index 00000000..a838f008 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcproj @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcxproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcxproj new file mode 100644 index 00000000..74c78a6a --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/HookSample.vcxproj @@ -0,0 +1,72 @@ + + + + + Debug + PS3 + + + Release + PS3 + + + + + + + + + {F749F5D0-B972-4E99-8B4B-2B865D4A8BC9} + + + + Application + GCC + + + Application + GCC + + + + + + + + + + + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + + _DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + true + + + "$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions) + + + + + NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + Level2 + + + "..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions) + + + + + + + \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Main.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Main.cpp new file mode 100644 index 00000000..e3417e42 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Main.cpp @@ -0,0 +1,18 @@ +#include "../../../Server/HeapInspectorServer.h" +#include "../../../Server/PS3/HeapHooks.hpp" + +void RunHeapInspectorServer(); + +extern "C" void* __real__malloc_init(); +extern "C" void* __wrap__malloc_init() +{ + void* result = __real__malloc_init(); + Initialise(HeapInspectorServer::GetDefaultHeapInfo(), 3000, HeapInspectorServer::WaitForConnection_Enabled); + return result; +} + +int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/) +{ + RunHeapInspectorServer(); + HeapInspectorServer::Shutdown(); +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Wait.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Wait.cpp new file mode 100644 index 00000000..2c436c84 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Hook/PS3/Wait.cpp @@ -0,0 +1,6 @@ +#include + +void Wait(int a_Milliseconds) +{ + sys_timer_usleep(a_Milliseconds * 1000); +} \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp new file mode 100644 index 00000000..34914717 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp @@ -0,0 +1,78 @@ +// ================================================================================================================================= +// This sample demonstrates how to use the Server API to send allocs, reallocs and frees directly to the client. It also shows +// how to configure multiple heaps. +// ================================================================================================================================= + +#include "../../Server/HeapInspectorServer.h" +#include + +using namespace HeapInspectorServer; + +void Wait(int a_MilliSeconds); + +std::vector GetHeapInfo() +{ + std::vector result; + HeapInfo heapInfo; + heapInfo.m_Description = "Heap1"; + heapInfo.m_Range.m_Min = 0; + heapInfo.m_Range.m_Max = 0x80000000 - 1; + result.push_back(heapInfo); + + heapInfo.m_Description = "Heap2"; + heapInfo.m_Range.m_Min = 0; + heapInfo.m_Range.m_Max = 0x80000000 - 1; + result.push_back(heapInfo); + + return result; +} + +void* Alloc(uint32 a_Size, int a_Heap) +{ + Mutation mutation = BeginAlloc(); + void* mem = malloc(a_Size); + EndAlloc(mutation, a_Heap, mem, a_Size, a_Size); + return mem; +} + +void Free(void* a_Block, int a_Heap) +{ + Mutation mutation = BeginFree(); + free(a_Block); + EndFree(mutation, a_Heap, a_Block); +} + +void* ReAlloc(void* a_OldBlock, uint32 a_Size, int a_Heap) +{ + Mutation mutation = BeginReAlloc(); + void* mem = realloc(a_OldBlock, a_Size); + EndReAlloc(mutation, a_Heap, a_OldBlock, mem, a_Size, a_Size); + return mem; +} + +void RunHeapInspectorServer() +{ + Initialise(GetHeapInfo(), 3000, WaitForConnection_Enabled); + + while (1) + { + void* mem1; + void* memB; + + mem1 = Alloc(16, 0); + memB = Alloc(1024, 1); + + Wait(100); + + void* mem2 = ReAlloc(mem1, 32, 0); + + Wait(100); + + Free(mem2, 0); + Free(memB, 1); + + Wait(100); + } + + Shutdown(); +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Main.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Main.cpp new file mode 100644 index 00000000..06429da3 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Main.cpp @@ -0,0 +1,7 @@ + +void RunHeapInspectorServer(); + +int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/) +{ + RunHeapInspectorServer(); +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcproj new file mode 100644 index 00000000..01fbd38d --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcproj @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcxproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcxproj new file mode 100644 index 00000000..9dd6a130 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/ManualSample.vcxproj @@ -0,0 +1,70 @@ + + + + + Debug + PS3 + + + Release + PS3 + + + + + + + + + {B6B851C9-DC76-4A5B-9AFE-6CF944BFB502} + + + + Application + GCC + + + Application + GCC + + + + + + + + + + + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + + _DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + true + + + "$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + + + + + NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + Level2 + + + "..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + + + + + + + \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Wait.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Wait.cpp new file mode 100644 index 00000000..2c436c84 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/PS3/Wait.cpp @@ -0,0 +1,6 @@ +#include + +void Wait(int a_Milliseconds) +{ + sys_timer_usleep(a_Milliseconds * 1000); +} \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/IThread.h b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/IThread.h new file mode 100644 index 00000000..9ac6dcf9 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/IThread.h @@ -0,0 +1,17 @@ +#ifndef _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_ +#define _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_ + +typedef void(*ThreadFunction)(); + +class IThread +{ +public: + virtual ~IThread() {} + virtual void Fork(ThreadFunction a_Function) = 0; + virtual void Join() = 0; +}; + +IThread* CreateThread(); +void DestroyThread(IThread* a_Thread); + +#endif // _MULTITHREADEDHOOKSAMPLE_ITHREAD_H_ \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/MultiThreadedHookSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/MultiThreadedHookSample.cpp new file mode 100644 index 00000000..4c872680 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/MultiThreadedHookSample.cpp @@ -0,0 +1,80 @@ +// ================================================================================================================================= +// This sample is more of a show-(and test) case for HeapInspector's. It demonstrates: +// 1) That HeapInspector is multithread safe. +// 2) HeapInspector's ability to deal with allocations prior to Initialise (although those allocations will not be tracked). +// 3) HeapInspector's ability to deal with API calls during static initialisation phase. +// +// In this sample, multiple threads are started that perform allocations for a set period of time. The +// application will wait for those threads to finish. After the time is passed and the application calls Shutdown, +// the client will disconnect. +// +// To switch between launching the threads during the static initalisation phase and launching the treads +// in main, flip the INIT_IN_STATIC_PHASE define. +// +// ================================================================================================================================= + +#include "IThread.h" +#include + +void Wait(int a_MilliSeconds); + +#define INIT_IN_STATIC_PHASE 0 +const int g_NumThreads = 4; + +class MultiThreadedAllocator +{ +public: + static void WorkerThread() + { + for (int i = 0; i != 1000; ++i) + { + void* mem1 = malloc(10); + Wait(10); + free(mem1); + Wait(10); + } + } + + MultiThreadedAllocator() + { + for (int i = 0; i != g_NumThreads; ++i) + { + m_Threads[i] = CreateThread(); + m_Threads[i]->Fork(WorkerThread); + } + } + + ~MultiThreadedAllocator() + { + WaitForThreads(); + for (int i = 0; i != g_NumThreads; ++i) + { + DestroyThread(m_Threads[i]); + } + } + +private: + void WaitForThreads() + { + for (int i = 0; i != g_NumThreads; ++i) + { + m_Threads[i]->Join(); + } + } + +private: + IThread* m_Threads[g_NumThreads]; +}; + +#if INIT_IN_STATIC_PHASE +static MultiThreadedAllocator* g_Allocator = new MultiThreadedAllocator(); +#endif + +void RunHeapInspectorServer() +{ +#if !INIT_IN_STATIC_PHASE + MultiThreadedAllocator* g_Allocator = new MultiThreadedAllocator(); +#endif + + delete g_Allocator; +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Main.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Main.cpp new file mode 100644 index 00000000..e3417e42 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Main.cpp @@ -0,0 +1,18 @@ +#include "../../../Server/HeapInspectorServer.h" +#include "../../../Server/PS3/HeapHooks.hpp" + +void RunHeapInspectorServer(); + +extern "C" void* __real__malloc_init(); +extern "C" void* __wrap__malloc_init() +{ + void* result = __real__malloc_init(); + Initialise(HeapInspectorServer::GetDefaultHeapInfo(), 3000, HeapInspectorServer::WaitForConnection_Enabled); + return result; +} + +int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/) +{ + RunHeapInspectorServer(); + HeapInspectorServer::Shutdown(); +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcproj new file mode 100644 index 00000000..76c17590 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcproj @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcxproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcxproj new file mode 100644 index 00000000..69d3882c --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/MultiThreadedHookSample.vcxproj @@ -0,0 +1,76 @@ + + + + + Debug + PS3 + + + Release + PS3 + + + + + + + + + + + + + {E9BC25AD-CFFD-43B6-ABEC-CA516CADD296} + + + + Application + GCC + + + Application + GCC + + + + + + + + + + + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + + _DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + true + + + "$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions) + + + + + NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + Level2 + + + "..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + -Wl,--wrap=malloc,--wrap=free,--wrap=calloc,--wrap=memalign,--wrap=realloc,--wrap=reallocalign,--wrap=_malloc_init %(AdditionalOptions) + + + + + + + \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/ThreadPS3.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/ThreadPS3.cpp new file mode 100644 index 00000000..ed27945a --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/ThreadPS3.cpp @@ -0,0 +1,41 @@ +#include +#include "../IThread.h" + +void* InternalThread(void* a_UserData) +{ + ThreadFunction function = (ThreadFunction)a_UserData; + function(); + + pthread_exit(0); + return 0; +} + +class ThreadPS3 : public IThread +{ +public: + virtual void Fork(ThreadFunction a_Function) + { + pthread_create(&m_Thread, 0, InternalThread, (void*)a_Function); + } + + virtual void Join() + { + void* threadResult; + pthread_join(m_Thread, &threadResult); + } + +private: + pthread_t m_Thread; +}; + + +IThread* CreateThread() +{ + return new ThreadPS3(); +} + +void DestroyThread(IThread* a_Thread) +{ + delete a_Thread; +} + diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Wait.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Wait.cpp new file mode 100644 index 00000000..2c436c84 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/MultiThreadedHook/PS3/Wait.cpp @@ -0,0 +1,6 @@ +#include + +void Wait(int a_Milliseconds) +{ + sys_timer_usleep(a_Milliseconds * 1000); +} \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Main.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Main.cpp new file mode 100644 index 00000000..06429da3 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Main.cpp @@ -0,0 +1,7 @@ + +void RunHeapInspectorServer(); + +int main(int /*a_ArgC*/, const char* /*a_ArgV[]*/) +{ + RunHeapInspectorServer(); +} diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcproj new file mode 100644 index 00000000..84a9be14 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcproj @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcxproj b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcxproj new file mode 100644 index 00000000..9515f936 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/ReplaceNewDeleteSample.vcxproj @@ -0,0 +1,70 @@ + + + + + Debug + PS3 + + + Release + PS3 + + + + + + + + + {B0416FCD-A32B-4F91-93D1-4EDFF99F740B} + + + + Application + GCC + + + Application + GCC + + + + + + + + + + + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + $(ProjectDir)$(Platform)_$(Configuration)_VS2010\ + $(Platform)_$(Configuration)_VS2010\ + + + + _DEBUG;__CELL_ASSERT__;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + true + + + "$(SCE_PS3_ROOT)\target\ppu\lib\libm.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libio_stub.a";"..\..\..\Server\PS3\Debug\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + + + + + NDEBUG;%(PreprocessorDefinitions);;HEAPINSPECTOR_PS3=1 + Level2 + + + "..\..\..\Server\PS3\Release\libHeapInspectorServer.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libpthread.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a";"$(SCE_PS3_ROOT)\target\ppu\lib\libsysmodule_stub.a";%(AdditionalDependencies) + + + + + + + \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Wait.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Wait.cpp new file mode 100644 index 00000000..2c436c84 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/PS3/Wait.cpp @@ -0,0 +1,6 @@ +#include + +void Wait(int a_Milliseconds) +{ + sys_timer_usleep(a_Milliseconds * 1000); +} \ No newline at end of file diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp new file mode 100644 index 00000000..305d589b --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp @@ -0,0 +1,67 @@ +// ================================================================================================================================= +// This sample demonstrates how to replace operator new and delete and how to send these allocations to the HeapInspector client. +// Please note that the Hook sample captures allocations on a lower level and will also trace all new/delete allocations. +// +// WARNING: Make sure that you replace both the array and non-array operators. If there are any pairing issues in your code +// (allocating with new[] and deleting with delete), HeapInspector will miss those deallocations and that will be problematic +// for a subsequent allocation on that address: it will then warn that it found a double allocation. That will actually be a +// sign that the operators aren't properly matched. +// ================================================================================================================================= + +#include "../../Server/HeapInspectorServer.h" +#include +#include + +using namespace HeapInspectorServer; + +void Wait(int a_MilliSeconds); + +void* operator new(size_t a_Size) +{ + Mutation mutation = BeginAlloc(); + void* mem = malloc(a_Size); + EndAlloc(mutation, 0, mem, a_Size, a_Size); + return mem; +} + +void operator delete(void* a_Pointer) +{ + Mutation mutation = BeginFree(); + free(a_Pointer); + EndFree(mutation, 0, a_Pointer); +} + +void* operator new[](size_t a_Size) +{ + Mutation mutation = BeginAlloc(); + void* mem = malloc(a_Size); + EndAlloc(mutation, 0, mem, a_Size, a_Size); + return mem; +} + +void operator delete[](void* a_Pointer) +{ + Mutation mutation = BeginFree(); + free(a_Pointer); + EndFree(mutation, 0, a_Pointer); +} + +void RunHeapInspectorServer() +{ + Initialise(GetDefaultHeapInfo(), 3000, WaitForConnection_Enabled); + + while (1) + { + int* xArray = new int[100]; + float* y = new float; + + Wait(100); + + delete[] xArray; + delete y; + + Wait(100); + } + + Shutdown(); +} -- cgit v1.2.3