From 4f001b4f4cad19f01ca56aaafebe0334fb0ccb22 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 17 Jan 2021 22:55:39 -0800 Subject: [PATCH] erpt: update for new sf semantics --- .../source/psc/psc_pm_module.os.horizon.cpp | 19 +++++++++-- stratosphere/erpt/source/erpt_main.cpp | 34 ++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp b/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp index f4523ada8..e808dbf2b 100644 --- a/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp +++ b/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp @@ -18,6 +18,22 @@ namespace ams::psc { + /* TODO: Nintendo uses sf::ShimLobraryObjectHolder here, we should similarly consider switching. */ + namespace { + + struct PscRemotePmModuleTag; + using RemoteAllocator = ams::sf::ExpHeapStaticAllocator<2_KB, PscRemotePmModuleTag>; + using RemoteObjectFactory = ams::sf::ObjectFactory; + + class StaticAllocatorInitializer { + public: + StaticAllocatorInitializer() { + RemoteAllocator::Initialize(lmem::CreateOption_None); + } + } g_static_allocator_initializer; + + } + PmModule::PmModule() : intf(nullptr), initialized(false), reserved(0) { /* ... */ } PmModule::~PmModule() { @@ -34,8 +50,7 @@ namespace ams::psc { ::PscPmModule module; R_TRY(::pscmGetPmModule(std::addressof(module), static_cast<::PscPmModuleId>(mid), reinterpret_cast(dependencies), dependency_count, clear_mode == os::EventClearMode_AutoClear)); - /* TODO: Proper allocator */ - this->intf = ams::sf::CreateSharedObjectEmplaced(module); + this->intf = RemoteObjectFactory::CreateSharedEmplaced(module); this->system_event.AttachReadableHandle(module.event.revent, false, clear_mode); this->initialized = true; return ResultSuccess(); diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index b2b67f7bc..a65195dfe 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -21,7 +21,7 @@ extern "C" { u32 __nx_applet_type = AppletType_None; u32 __nx_fs_num_sessions = 1; - #define INNER_HEAP_SIZE 0x4000 + #define INNER_HEAP_SIZE 0x0 size_t nx_inner_heap_size = INNER_HEAP_SIZE; char nx_inner_heap[INNER_HEAP_SIZE]; @@ -33,6 +33,10 @@ extern "C" { alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize]; u64 __nx_exception_stack_size = sizeof(__nx_exception_stack); void __libnx_exception_handler(ThreadExceptionDump *ctx); + + void *__libnx_thread_alloc(size_t size); + void __libnx_thread_free(void *mem); + } namespace ams { @@ -121,6 +125,34 @@ namespace ams::erpt { } +namespace ams { + + void *Malloc(size_t size) { + AMS_ABORT("ams::Malloc was called"); + } + + void Free(void *ptr) { + AMS_ABORT("ams::Free was called"); + } + +} + +void *operator new(size_t size) { + AMS_ABORT("operator new(size_t) was called"); +} + +void operator delete(void *p) { + AMS_ABORT("operator delete(void *) was called"); +} + +void *__libnx_thread_alloc(size_t size) { + AMS_ABORT("__libnx_thread_alloc was called"); +} + +void __libnx_thread_free(void *mem) { + AMS_ABORT("__libnx_thread_free was called"); +} + int main(int argc, char **argv) { /* Set thread name. */