sm: update to excise unnecessary library code

This commit is contained in:
Michael Scire 2021-05-02 10:33:15 -07:00
parent 7d61cab01c
commit 32f487abfb
7 changed files with 47 additions and 6 deletions

View file

@ -34,7 +34,8 @@ export CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \
-Wl,--wrap,_Unwind_Resume \ -Wl,--wrap,_Unwind_Resume \
-Wl,--wrap,_ZSt19__throw_logic_errorPKc \ -Wl,--wrap,_ZSt19__throw_logic_errorPKc \
-Wl,--wrap,_ZSt20__throw_length_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) export LDFLAGS = -specs=$(ATMOSPHERE_LIBRARIES_DIR)/libstratosphere/stratosphere.specs -specs=$(DEVKITPRO)/libnx/switch.specs $(SETTINGS) $(CXXWRAPS) -Wl,-Map,$(notdir $*.map)

View file

@ -124,6 +124,7 @@ $(OFILES_SRC) : $(HFILES_BIN)
ams_environment_weak.o: CXXFLAGS += -fno-lto ams_environment_weak.o: CXXFLAGS += -fno-lto
pm_info_api_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 %_bin.h %.bin.o : %.bin

View file

@ -15,6 +15,8 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
extern "C" void NORETURN __real_exit(int rc);
namespace ams { namespace ams {
WEAK_SYMBOL void *Malloc(size_t size) { WEAK_SYMBOL void *Malloc(size_t size) {
@ -37,6 +39,11 @@ namespace ams {
return std::free(ptr); return std::free(ptr);
} }
WEAK_SYMBOL void NORETURN Exit(int rc) {
__real_exit(rc);
__builtin_unreachable();
}
} }
extern "C" { extern "C" {
@ -46,4 +53,6 @@ extern "C" {
WRAP_ABORT_FUNC(__cxa_pure_virtual) WRAP_ABORT_FUNC(__cxa_pure_virtual)
#undef WRAP_ABORT_FUNC #undef WRAP_ABORT_FUNC
void NORETURN __wrap_exit(int rc) { ::ams::Exit(rc); __builtin_unreachable(); }
} }

View file

@ -15,6 +15,7 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include "hos_version_api_private.hpp" #include "hos_version_api_private.hpp"
#include "../os/impl/os_rng_manager.hpp"
namespace ams::os { 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<uintptr_t>(::ams::os::impl::GetRngManager().GenerateRandomU64());
}
}
namespace ams::hos { namespace ams::hos {
void InitializeForStratosphere() { void InitializeForStratosphere() {

View file

@ -21,12 +21,12 @@ namespace ams::os::impl {
class RngManager { class RngManager {
private: private:
util::TinyMT mt; util::TinyMT mt;
os::Mutex lock; os::SdkMutex lock;
bool initialized; bool initialized;
private: private:
void Initialize(); void Initialize();
public: public:
constexpr RngManager() : mt(), lock(false), initialized() { /* ... */ } constexpr RngManager() : mt(), lock(), initialized() { /* ... */ }
public: public:
u64 GenerateRandomU64(); u64 GenerateRandomU64();
}; };

View file

@ -20,9 +20,9 @@ namespace ams::os {
namespace { namespace {
util::TinyMT g_random; constinit util::TinyMT g_random;
os::Mutex g_random_mutex(false); constinit os::SdkMutex g_random_mutex;
bool g_initialized_random; constinit bool g_initialized_random;
template<typename T> template<typename T>
inline T GenerateRandomTImpl(T max) { inline T GenerateRandomTImpl(T max) {

View file

@ -19,6 +19,9 @@
extern "C" { extern "C" {
extern u32 __start__; extern u32 __start__;
extern int __system_argc;
extern char** __system_argv;
u32 __nx_applet_type = AppletType_None; u32 __nx_applet_type = AppletType_None;
#define INNER_HEAP_SIZE 0x0 #define INNER_HEAP_SIZE 0x0
@ -26,6 +29,7 @@ extern "C" {
char nx_inner_heap[INNER_HEAP_SIZE]; char nx_inner_heap[INNER_HEAP_SIZE];
void __libnx_initheap(void); void __libnx_initheap(void);
void argvSetup(void);
void __appInit(void); void __appInit(void);
void __appExit(void); void __appExit(void);
@ -39,10 +43,20 @@ extern "C" {
void __libnx_free(void *mem); void __libnx_free(void *mem);
} }
namespace {
constinit char *g_empty_argv = nullptr;
}
namespace ams { namespace ams {
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Sm; ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Sm;
void NORETURN Exit(int rc) {
AMS_ABORT("Exit called by immortal process");
}
} }
using namespace ams; using namespace ams;
@ -64,6 +78,12 @@ void __libnx_initheap(void) {
fake_heap_end = (char*)addr + size; fake_heap_end = (char*)addr + size;
} }
void argvSetup(void) {
/* We don't need argc/argv, so set them to empty defaults. */
__system_argc = 0;
__system_argv = std::addressof(g_empty_argv);
}
void __appInit(void) { void __appInit(void) {
hos::InitializeForStratosphere(); hos::InitializeForStratosphere();