From 07073a758090b63356854878e2be21433b76a87e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 2 May 2021 10:33:15 -0700 Subject: [PATCH] sm: update to excise unnecessary library code --- config/templates/stratosphere.mk | 3 ++- libstratosphere/Makefile | 1 + libstratosphere/source/ams/ams_environment_weak.cpp | 9 +++++++++ libstratosphere/source/hos/hos_stratosphere_api.cpp | 10 ++++++++++ libstratosphere/source/os/impl/os_rng_manager_impl.hpp | 4 ++-- libstratosphere/source/os/os_random.cpp | 6 +++--- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/config/templates/stratosphere.mk b/config/templates/stratosphere.mk index 6f4395b1..fe796490 100644 --- a/config/templates/stratosphere.mk +++ b/config/templates/stratosphere.mk @@ -34,7 +34,8 @@ export CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,_Unwind_Resume \ -Wl,--wrap,_ZSt19__throw_logic_errorPKc \ -Wl,--wrap,_ZSt20__throw_length_errorPKc \ - -Wl,--wrap,_ZNSt11logic_errorC2EPKc + -Wl,--wrap,_ZNSt11logic_errorC2EPKc \ + -Wl,--wrap,exit export LDFLAGS = -specs=$(ATMOSPHERE_LIBRARIES_DIR)/libstratosphere/stratosphere.specs -specs=$(DEVKITPRO)/libnx/switch.specs $(SETTINGS) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map) diff --git a/libstratosphere/Makefile b/libstratosphere/Makefile index 20e0c6c7..cca5aba5 100644 --- a/libstratosphere/Makefile +++ b/libstratosphere/Makefile @@ -124,6 +124,7 @@ $(OFILES_SRC) : $(HFILES_BIN) ams_environment_weak.o: CXXFLAGS += -fno-lto pm_info_api_weak.o: CXXFLAGS += -fno-lto +hos_stratosphere_api.o: CXXFLAGS += -fno-lto #--------------------------------------------------------------------------------- %_bin.h %.bin.o : %.bin diff --git a/libstratosphere/source/ams/ams_environment_weak.cpp b/libstratosphere/source/ams/ams_environment_weak.cpp index 89b68067..284a725e 100644 --- a/libstratosphere/source/ams/ams_environment_weak.cpp +++ b/libstratosphere/source/ams/ams_environment_weak.cpp @@ -15,6 +15,8 @@ */ #include +extern "C" void NORETURN __real_exit(int rc); + namespace ams { WEAK_SYMBOL void *Malloc(size_t size) { @@ -37,6 +39,11 @@ namespace ams { return std::free(ptr); } + WEAK_SYMBOL void NORETURN Exit(int rc) { + __real_exit(rc); + __builtin_unreachable(); + } + } extern "C" { @@ -46,4 +53,6 @@ extern "C" { WRAP_ABORT_FUNC(__cxa_pure_virtual) #undef WRAP_ABORT_FUNC + void NORETURN __wrap_exit(int rc) { ::ams::Exit(rc); __builtin_unreachable(); } + } diff --git a/libstratosphere/source/hos/hos_stratosphere_api.cpp b/libstratosphere/source/hos/hos_stratosphere_api.cpp index 092211ff..10af44f2 100644 --- a/libstratosphere/source/hos/hos_stratosphere_api.cpp +++ b/libstratosphere/source/hos/hos_stratosphere_api.cpp @@ -15,6 +15,7 @@ */ #include #include "hos_version_api_private.hpp" +#include "../os/impl/os_rng_manager.hpp" namespace ams::os { @@ -22,6 +23,15 @@ namespace ams::os { } +extern "C" { + + /* Provide libnx address space allocation shim. */ + uintptr_t __libnx_virtmem_rng(void) { + return static_cast(::ams::os::impl::GetRngManager().GenerateRandomU64()); + } + +} + namespace ams::hos { void InitializeForStratosphere() { diff --git a/libstratosphere/source/os/impl/os_rng_manager_impl.hpp b/libstratosphere/source/os/impl/os_rng_manager_impl.hpp index b782edde..b981c39d 100644 --- a/libstratosphere/source/os/impl/os_rng_manager_impl.hpp +++ b/libstratosphere/source/os/impl/os_rng_manager_impl.hpp @@ -21,12 +21,12 @@ namespace ams::os::impl { class RngManager { private: util::TinyMT mt; - os::Mutex lock; + os::SdkMutex lock; bool initialized; private: void Initialize(); public: - constexpr RngManager() : mt(), lock(false), initialized() { /* ... */ } + constexpr RngManager() : mt(), lock(), initialized() { /* ... */ } public: u64 GenerateRandomU64(); }; diff --git a/libstratosphere/source/os/os_random.cpp b/libstratosphere/source/os/os_random.cpp index b0bc60c5..1368365f 100644 --- a/libstratosphere/source/os/os_random.cpp +++ b/libstratosphere/source/os/os_random.cpp @@ -20,9 +20,9 @@ namespace ams::os { namespace { - util::TinyMT g_random; - os::Mutex g_random_mutex(false); - bool g_initialized_random; + constinit util::TinyMT g_random; + constinit os::SdkMutex g_random_mutex; + constinit bool g_initialized_random; template inline T GenerateRandomTImpl(T max) {