From cfb192e8a2ea7c3de6f7e0c545c089a3973431e4 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 31 Oct 2021 15:47:08 -0700 Subject: [PATCH] dmnt: enable experimental standalone usage of gdbstub, while starlink is in dev --- .../fssystem/fssystem_utility.hpp | 10 ++--- .../stratosphere/socket/socket_api.hpp | 1 + .../socket/socket_system_config.hpp | 38 +++++++++++++++++++ libstratosphere/source/boot2/boot2_api.cpp | 9 +++++ .../source/socket/impl/socket_api.hpp | 1 + .../socket/impl/socket_api.os.horizon.cpp | 18 +++++++++ libstratosphere/source/socket/socket_api.cpp | 4 ++ 7 files changed, 76 insertions(+), 5 deletions(-) diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp index 0255d627..827f094f 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp @@ -118,12 +118,12 @@ namespace ams::fssystem { /* Copy API. */ Result CopyFile(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size); - NX_INLINE Result CopyFile(fs::fsa::IFileSystem *fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size) { + ALWAYS_INLINE Result CopyFile(fs::fsa::IFileSystem *fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size) { return CopyFile(fs, fs, dst_parent_path, src_path, dir_ent, work_buf, work_buf_size); } Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size); - NX_INLINE Result CopyDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) { + ALWAYS_INLINE Result CopyDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) { return CopyDirectoryRecursively(fs, fs, dst_path, src_path, work_buf, work_buf_size); } @@ -148,11 +148,11 @@ namespace ams::fssystem { Result EnsureDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path); Result EnsureParentDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path); - template - NX_INLINE Result RetryFinitelyForTargetLocked(F f) { + template + ALWAYS_INLINE Result RetryFinitelyForTargetLocked(auto f) { /* Retry up to 10 times, 100ms between retries. */ constexpr s32 MaxRetryCount = 10; - constexpr TimeSpan RetryWaitTime = TimeSpan::FromMilliSeconds(100); + constexpr TimeSpan RetryWaitTime = TimeSpan::FromMilliSeconds(RetryMilliSeconds); s32 remaining_retries = MaxRetryCount; while (true) { diff --git a/libstratosphere/include/stratosphere/socket/socket_api.hpp b/libstratosphere/include/stratosphere/socket/socket_api.hpp index 30b5d2d2..07acdf96 100644 --- a/libstratosphere/include/stratosphere/socket/socket_api.hpp +++ b/libstratosphere/include/stratosphere/socket/socket_api.hpp @@ -43,6 +43,7 @@ namespace ams::socket { s32 Shutdown(s32 desc, ShutdownMethod how); + s32 Socket(Family domain, Type type, Protocol protocol); s32 SocketExempt(Family domain, Type type, Protocol protocol); s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len); diff --git a/libstratosphere/include/stratosphere/socket/socket_system_config.hpp b/libstratosphere/include/stratosphere/socket/socket_system_config.hpp index b13018ad..c6bac93e 100644 --- a/libstratosphere/include/stratosphere/socket/socket_system_config.hpp +++ b/libstratosphere/include/stratosphere/socket/socket_system_config.hpp @@ -57,4 +57,42 @@ namespace ams::socket { } }; + class SystemConfigLightDefault : public Config { + public: + static constexpr size_t DefaultTcpInitialSendBufferSize = 16_KB; + static constexpr size_t DefaultTcpInitialReceiveBufferSize = 16_KB; + static constexpr size_t DefaultTcpAutoSendBufferSizeMax = 0_KB; + static constexpr size_t DefaultTcpAutoReceiveBufferSizeMax = 0_KB; + static constexpr size_t DefaultUdpSendBufferSize = 9_KB; + static constexpr size_t DefaultUdpReceiveBufferSize = 42240; + static constexpr auto DefaultSocketBufferEfficiency = 2; + static constexpr auto DefaultConcurrency = 2; + static constexpr size_t DefaultAllocatorPoolSize = 64_KB; + + static constexpr size_t PerTcpSocketWorstCaseMemoryPoolSize = [] { + constexpr size_t WorstCaseTcpSendBufferSize = AlignMss(std::max(DefaultTcpInitialSendBufferSize, DefaultTcpAutoSendBufferSizeMax)); + constexpr size_t WorstCaseTcpReceiveBufferSize = AlignMss(std::max(DefaultTcpInitialReceiveBufferSize, DefaultTcpAutoReceiveBufferSizeMax)); + + return util::AlignUp(WorstCaseTcpSendBufferSize * DefaultSocketBufferEfficiency + WorstCaseTcpReceiveBufferSize * DefaultSocketBufferEfficiency, os::MemoryPageSize); + }(); + + static constexpr size_t PerUdpSocketWorstCaseMemoryPoolSize = [] { + constexpr size_t WorstCaseUdpSendBufferSize = AlignMss(DefaultUdpSendBufferSize); + constexpr size_t WorstCaseUdpReceiveBufferSize = AlignMss(DefaultUdpReceiveBufferSize); + + return util::AlignUp(WorstCaseUdpSendBufferSize * DefaultSocketBufferEfficiency + WorstCaseUdpReceiveBufferSize * DefaultSocketBufferEfficiency, os::MemoryPageSize); + }(); + public: + constexpr SystemConfigLightDefault(void *mp, size_t mp_sz, size_t ap, int c=DefaultConcurrency) + : Config(mp, mp_sz, ap, + DefaultTcpInitialSendBufferSize, DefaultTcpInitialReceiveBufferSize, + DefaultTcpAutoSendBufferSizeMax, DefaultTcpAutoReceiveBufferSizeMax, + DefaultUdpSendBufferSize, DefaultUdpReceiveBufferSize, + DefaultSocketBufferEfficiency, c) + { + /* Mark as system. */ + m_system = true; + } + }; + } diff --git a/libstratosphere/source/boot2/boot2_api.cpp b/libstratosphere/source/boot2/boot2_api.cpp index 17c90292..a40e95f8 100644 --- a/libstratosphere/source/boot2/boot2_api.cpp +++ b/libstratosphere/source/boot2/boot2_api.cpp @@ -188,6 +188,12 @@ namespace ams::boot2 { return enable_htc != 0; } + bool IsStandaloneGdbstubEnabled() { + u8 enable_gdbstub = 0; + settings::fwdbg::GetSettingsItemValue(std::addressof(enable_gdbstub), sizeof(enable_gdbstub), "atmosphere", "enable_standalone_gdbstub"); + return enable_gdbstub != 0; + } + bool IsAtmosphereLogManagerEnabled() { /* If htc is enabled, ams log manager is enabled. */ if (IsHtcEnabled()) { @@ -403,6 +409,9 @@ namespace ams::boot2 { LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Htc, ncm::StorageId::None), 0); LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Cs, ncm::StorageId::None), 0); LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::DmntGen2, ncm::StorageId::None), 0); + } else if (IsStandaloneGdbstubEnabled()) { + LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::DmntGen2, ncm::StorageId::None), 0); + LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0); } else { LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Dmnt, ncm::StorageId::None), 0); LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0); diff --git a/libstratosphere/source/socket/impl/socket_api.hpp b/libstratosphere/source/socket/impl/socket_api.hpp index f80e4675..f1dcc551 100644 --- a/libstratosphere/source/socket/impl/socket_api.hpp +++ b/libstratosphere/source/socket/impl/socket_api.hpp @@ -41,6 +41,7 @@ namespace ams::socket::impl { s32 Shutdown(s32 desc, ShutdownMethod how); + s32 Socket(Family domain, Type type, Protocol protocol); s32 SocketExempt(Family domain, Type type, Protocol protocol); s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len); diff --git a/libstratosphere/source/socket/impl/socket_api.os.horizon.cpp b/libstratosphere/source/socket/impl/socket_api.os.horizon.cpp index db145ba6..299d762d 100644 --- a/libstratosphere/source/socket/impl/socket_api.os.horizon.cpp +++ b/libstratosphere/source/socket/impl/socket_api.os.horizon.cpp @@ -206,6 +206,8 @@ namespace ams::socket::impl { /* TODO: socket::resolver::EnableResolverCalls()? Not necessary in our case (htc), but consider calling it. */ + g_initialized = true; + return ResultSuccess(); } @@ -422,6 +424,22 @@ namespace ams::socket::impl { return result; } + s32 Socket(Family domain, Type type, Protocol protocol) { + /* Check pre-conditions. */ + AMS_ABORT_UNLESS(IsInitialized()); + + /* Perform the call. */ + Errno error = Errno::ESuccess; + int result = ::bsdSocket(static_cast(domain), static_cast(type), static_cast(protocol)); + TranslateResultToBsdError(error, result); + + if (result < 0) { + socket::impl::SetLastError(error); + } + + return result; + } + s32 SocketExempt(Family domain, Type type, Protocol protocol) { /* Check pre-conditions. */ AMS_ABORT_UNLESS(IsInitialized()); diff --git a/libstratosphere/source/socket/socket_api.cpp b/libstratosphere/source/socket/socket_api.cpp index 30a84a64..bd1949d6 100644 --- a/libstratosphere/source/socket/socket_api.cpp +++ b/libstratosphere/source/socket/socket_api.cpp @@ -74,6 +74,10 @@ namespace ams::socket { return impl::Shutdown(desc, how); } + s32 Socket(Family domain, Type type, Protocol protocol) { + return impl::Socket(domain, type, protocol); + } + s32 SocketExempt(Family domain, Type type, Protocol protocol) { return impl::SocketExempt(domain, type, protocol); }