diff --git a/libraries/libstratosphere/Makefile b/libraries/libstratosphere/Makefile index 81237e3a2..4d302b467 100644 --- a/libraries/libstratosphere/Makefile +++ b/libraries/libstratosphere/Makefile @@ -122,6 +122,8 @@ $(OFILES) : $(GCH_FILES) $(OFILES_SRC) : $(HFILES_BIN) +ams_environment_weak.o: CXXFLAGS += -fno-lto + #--------------------------------------------------------------------------------- %_bin.h %.bin.o : %.bin #--------------------------------------------------------------------------------- diff --git a/libraries/libstratosphere/include/stratosphere/ams/ams_environment.hpp b/libraries/libstratosphere/include/stratosphere/ams/ams_environment.hpp index d610bce34..c237ed05f 100644 --- a/libraries/libstratosphere/include/stratosphere/ams/ams_environment.hpp +++ b/libraries/libstratosphere/include/stratosphere/ams/ams_environment.hpp @@ -26,4 +26,7 @@ namespace ams { void InitializeForBoot(); void SetInitialRebootPayload(const void *src, size_t src_size); + void *Malloc(size_t size); + void Free(void *ptr); + } diff --git a/libraries/libstratosphere/source/ams/ams_environment_weak.cpp b/libraries/libstratosphere/source/ams/ams_environment_weak.cpp new file mode 100644 index 000000000..b3965e7d9 --- /dev/null +++ b/libraries/libstratosphere/source/ams/ams_environment_weak.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include + +namespace ams { + + WEAK_SYMBOL void *Malloc(size_t size) { + return std::malloc(size); + } + + WEAK_SYMBOL void Free(void *ptr) { + return std::free(ptr); + } + +} diff --git a/libraries/libstratosphere/source/fs/fs_memory_management.cpp b/libraries/libstratosphere/source/fs/fs_memory_management.cpp index da4ba2701..d929e52b3 100644 --- a/libraries/libstratosphere/source/fs/fs_memory_management.cpp +++ b/libraries/libstratosphere/source/fs/fs_memory_management.cpp @@ -23,16 +23,16 @@ namespace ams::fs { void *DefaultAllocate(size_t size) { g_used_default_allocator = true; - return std::malloc(size); + return ams::Malloc(size); } void DefaultDeallocate(void *ptr, size_t size) { - std::free(ptr); + ams::Free(ptr); } - os::Mutex g_lock(false); - AllocateFunction g_allocate_func = DefaultAllocate; - DeallocateFunction g_deallocate_func = DefaultDeallocate; + constinit os::SdkMutex g_lock; + constinit AllocateFunction g_allocate_func = DefaultAllocate; + constinit DeallocateFunction g_deallocate_func = DefaultDeallocate; constexpr size_t RequiredAlignment = alignof(u64); diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp index 784daae4d..9012d23cd 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp +++ b/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp @@ -37,7 +37,7 @@ namespace ams::os::impl { return ResultSuccess(); } - Result ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) { + Result WaitableManagerHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) { /* NOTE: Nintendo does not initialize this value, which seems like it can cause incorrect behavior. */ s32 index = WaitableManagerImpl::WaitInvalid; static_assert(WaitableManagerImpl::WaitInvalid != -1); diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index 77083ebfc..e669a1789 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -170,8 +170,15 @@ void __appExit(void) { setsysExit(); } -namespace { +namespace ams { + void *Malloc(size_t size) { + AMS_ABORT("ams::Malloc was called"); + } + + void Free(void *ptr) { + AMS_ABORT("ams::Free was called"); + } }