Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[submodule "thirdparty/vcpkg"]
path = thirdparty/vcpkg
url = https://github.com/microsoft/vcpkg
[submodule "tools/XenonRecomp"]
path = tools/XenonRecomp
url = https://github.com/CRACKbomber/XenonRecomp.git
branch = impl-opcodes
[submodule "thirdparty/ddspp"]
path = thirdparty/ddspp
url = https://github.com/redorav/ddspp.git
Expand Down Expand Up @@ -56,3 +52,6 @@
[submodule "thirdparty/json"]
path = thirdparty/json
url = https://github.com/nlohmann/json
[submodule "tools/XenonRecomp"]
path = tools/XenonRecomp
url = https://github.com/EOT-RecompTest/XenonRecomp.git
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Reference/X360TDocs/system_game_disc_caching.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Reference/X360TDocs/system_vmx128_overview.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 5 additions & 5 deletions reblue/kernel/imports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ GUEST_FUNCTION_HOOK(__imp__IoSynchronousDeviceIoControlRequest, reblue::kernel::
GUEST_FUNCTION_HOOK(__imp__ObOpenObjectByName, reblue::kernel::ObOpenObjectByName);
GUEST_FUNCTION_HOOK(__imp__ObReferenceObjectByName, reblue::kernel::ObReferenceObjectByName);

// GUEST_FUNCTION_HOOK(sub_824694A0, reblue::kernel::RtlAllocateHeap);
// GUEST_FUNCTION_HOOK(sub_82469D88, reblue::kernel::RtlFreeHeap);
GUEST_FUNCTION_HOOK(sub_82255F00, reblue::kernel::RtlAllocateHeap);
GUEST_FUNCTION_HOOK(sub_822567F8, reblue::kernel::RtlFreeHeap);
// GUEST_FUNCTION_HOOK(sub_8246A070, reblue::kernel::RtlReAllocateHeap);
// GUEST_FUNCTION_HOOK(sub_82468738, reblue::kernel::RtlSizeHeap);
// GUEST_FUNCTION_HOOK(sub_82466CC8, reblue::kernel::XAllocMem);
Expand All @@ -289,7 +289,7 @@ GUEST_FUNCTION_HOOK(__imp__ObReferenceObjectByName, reblue::kernel::ObReferenceO
// native memory operations
// GUEST_FUNCTION_HOOK(sub_826C0480, memmove);
// GUEST_FUNCTION_HOOK(sub_826BF770, memcpy);
// GUEST_FUNCTION_HOOK(sub_826BFCF0, memset);
GUEST_FUNCTION_HOOK(sub_8233eaf00, memset);



Expand All @@ -315,7 +315,7 @@ GUEST_FUNCTION_STUB(__imp__swprintf);
#define GUEST__D3DDevice_CreateTexture sub_8246D420
#define GUEST__D3DDevice_SetTexture sub_8246D788
#define GUEST__LockTextureRect sub_8246D408
#define GUEST__D3DDevice_CreatePixelShader sub_8247D840
#define GUEST__D3DDevice_CreatePixelShader sub_82238290
#define GUEST__D3DDevice_SetPixelShader sub_8247BF68
#define GUEST__D3DDevice_CreateIndexBuffer sub_82481310
#define GUEST__D3DIndexBuffer_Lock sub_824813C0
Expand Down Expand Up @@ -419,4 +419,4 @@ GUEST_FUNCTION_STUB(GUEST__D3DDevice_SetPrediction); // D3DDevice_SetPredication
GUEST_FUNCTION_STUB(GUEST__D3DXFilterTexture); // D3DXFilterTexture
GUEST_FUNCTION_STUB(GUEST__D3DDevice_Release); // D3DDevice_Release
GUEST_FUNCTION_STUB(sub_82466ED8);
*/
*/
48 changes: 46 additions & 2 deletions reblue/kernel/obj/guest_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,33 @@ void GuestHeap::Init()

void* GuestHeap::Alloc(size_t size)
{
size = std::max<size_t>(1, size);
size_t alignment = 0x10000;

std::lock_guard lock(mutex);

return o1heapAllocate(heap, std::max<size_t>(1, size));
void* ptr = o1heapAllocate(heap, size + alignment);
if (!ptr)
{
O1HeapDiagnostics diag = o1heapGetDiagnostics(heap);
LOGF_ERROR(
"GuestHeap::Alloc failed size=0x{:X} align=0x{:X} cap=0x{:X} alloc=0x{:X} oom={}",
size,
alignment,
diag.capacity,
diag.allocated,
diag.oom_count);
return nullptr;
}

size_t aligned = ((size_t)ptr + alignment) & ~(alignment - 1);

*((void**)aligned - 1) = ptr;
*((size_t*)aligned - 2) = size + O1HEAP_ALIGNMENT;

return (void*)aligned;

// return o1heapAllocate(heap1, std::max<size_t>(1, size));
}

void* GuestHeap::AllocPhysical(size_t size, size_t alignment)
Expand All @@ -29,12 +53,32 @@ void* GuestHeap::AllocPhysical(size_t size, size_t alignment)
std::lock_guard lock(physicalMutex);

void* ptr = o1heapAllocate(physicalHeap, size + alignment);
if (!ptr)
{
O1HeapDiagnostics diag = o1heapGetDiagnostics(physicalHeap);
LOGF_ERROR(
"GuestHeap::AllocPhysical failed size=0x{:X} align=0x{:X} cap=0x{:X} alloc=0x{:X} oom={}",
size,
alignment,
diag.capacity,
diag.allocated,
diag.oom_count);
return nullptr;
}

size_t aligned = ((size_t)ptr + alignment) & ~(alignment - 1);

*((void**)aligned - 1) = ptr;
*((size_t*)aligned - 2) = size + O1HEAP_ALIGNMENT;
void* result = (void*)aligned;
LOGF_UTILITY(
"GuestHeap::AllocPhysical size=0x{:X} align=0x{:X} -> ptr={} aligned={}",
size,
alignment,
result,
((reinterpret_cast<size_t>(result) & (alignment - 1)) == 0) ? "yes" : "no");

return (void*)aligned;
return result;
}

void GuestHeap::Free(void* ptr)
Expand Down
33 changes: 30 additions & 3 deletions reblue/kernel/obj/guest_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <stdafx.h>
#include <os/logger.h>
#include "guest_memory.h"

using namespace reblue::kernel;

GuestMemory::GuestMemory()
{
bool lowMemProtected = false;
#ifdef _WIN32
base = (uint8_t*)VirtualAlloc((void*)0x100000000ull, PPC_MEMORY_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);

Expand All @@ -14,8 +16,19 @@ GuestMemory::GuestMemory()
if (base == nullptr)
return;

DWORD oldProtect;
VirtualProtect(base, 4096, PAGE_NOACCESS, &oldProtect);
// Protect the first page to catch null pointer dereferences, as done in
// reference implementations such as Fable2, Bluedragon and Xenia.
// This mirrors the behaviour of the console which marks the first 64 KiB
// as inaccessible. Since some titles legitimately use low addresses,
// protection is now opt-in via the REBLUE_ENABLE_LOW_MEM_PROTECTION
// environment variable.
if (const char* enable = getenv("REBLUE_ENABLE_LOW_MEM_PROTECTION");
enable && strcmp(enable, "1") == 0)
{
DWORD oldProtect;
VirtualProtect(base, 4096, PAGE_NOACCESS, &oldProtect);
lowMemProtected = true;
}
#else
base = (uint8_t*)mmap((void*)0x100000000ull, PPC_MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

Expand All @@ -25,9 +38,23 @@ GuestMemory::GuestMemory()
if (base == nullptr)
return;

mprotect(base, 4096, PROT_NONE);
// Mirror the behaviour on POSIX hosts. Reference projects also protect
// the first page to help catch null pointer bugs. Protection is now
// opt-in via the REBLUE_ENABLE_LOW_MEM_PROTECTION environment variable
// for titles that deliberately touch low addresses.
if (const char* enable = getenv("REBLUE_ENABLE_LOW_MEM_PROTECTION");
enable && strcmp(enable, "1") == 0)
{
mprotect(base, 4096, PROT_NONE);
lowMemProtected = true;
}
#endif

LOGF_UTILITY(
"Guest memory base={} low-mem-protection={}",
static_cast<void*>(base),
lowMemProtected ? "enabled" : "disabled");

for (size_t i = 0; PPCFuncMappings[i].guest != 0; i++)
{
if (PPCFuncMappings[i].host != nullptr)
Expand Down
Binary file added rebluelib/ppc.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/XenonRecomp