From 585e0b0e46a50680380c724e39e94905f55df076 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 11 Feb 2015 10:16:54 -0800 Subject: [PATCH] XamAlloc/XamFree. Fixes #153. --- src/xenia/kernel/xam_info.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/xenia/kernel/xam_info.cc b/src/xenia/kernel/xam_info.cc index 70f5061bf..09d8ac5db 100644 --- a/src/xenia/kernel/xam_info.cc +++ b/src/xenia/kernel/xam_info.cc @@ -100,6 +100,33 @@ SHIM_CALL XamLoaderTerminateTitle_shim(PPCContext* ppc_state, assert_always(); } +SHIM_CALL XamAlloc_shim(PPCContext* ppc_state, KernelState* state) { + uint32_t unk = SHIM_GET_ARG_32(0); + uint32_t size = SHIM_GET_ARG_32(1); + uint32_t out_ptr = SHIM_GET_ARG_32(2); + + XELOGD("XamAlloc(%d, %d, %.8X)", unk, size, out_ptr); + + assert_true(unk == 0); + + // Allocate from the heap. Not sure why XAM does this specially, perhaps + // it keeps stuff in a separate heap? + uint64_t ptr = state->memory()->HeapAlloc(0, size, MEMORY_FLAG_ZERO); + SHIM_SET_MEM_32(out_ptr, uint32_t(ptr)); + + SHIM_SET_RETURN_32(X_ERROR_SUCCESS); +} + +SHIM_CALL XamFree_shim(PPCContext* ppc_state, KernelState* state) { + uint32_t ptr = SHIM_GET_ARG_32(0); + + XELOGD("XamFree(%.8X)", ptr); + + state->memory()->HeapFree(ptr, 0); + + SHIM_SET_RETURN_32(X_ERROR_SUCCESS); +} + SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t zero = SHIM_GET_ARG_32(1); @@ -154,5 +181,8 @@ void xe::kernel::xam::RegisterInfoExports(ExportResolver* export_resolver, SHIM_SET_MAPPING("xam.xex", XamLoaderLaunchTitle, state); SHIM_SET_MAPPING("xam.xex", XamLoaderTerminateTitle, state); + SHIM_SET_MAPPING("xam.xex", XamAlloc, state); + SHIM_SET_MAPPING("xam.xex", XamFree, state); + SHIM_SET_MAPPING("xam.xex", XamEnumerate, state); }