Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"

This reverts commit 15b7df8ef1.
This commit is contained in:
souldbminersmwc
2025-11-09 16:14:52 -05:00
parent 22ec140738
commit 21a3f953d7
3804 changed files with 435 additions and 570162 deletions

View File

@@ -1,99 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/socket/socket_types.hpp>
#include <stratosphere/socket/socket_options.hpp>
#include <stratosphere/socket/socket_constants.hpp>
#include <stratosphere/socket/socket_errno.hpp>
namespace ams::socket::impl {
#if defined(ATMOSPHERE_OS_WINDOWS)
class PosixWinSockConverter {
private:
struct SocketData {
SOCKET winsock;
bool exempt;
bool shutdown;
constexpr SocketData() : winsock(static_cast<SOCKET>(INVALID_SOCKET)), exempt(), shutdown() { /* ... */ }
};
private:
os::SdkMutex m_mutex{};
SocketData m_data[MaxSocketsPerClient]{};
private:
static constexpr int GetInitialIndex(SOCKET winsock) {
/* The lower 2 bits of a winsock are always zero; Nintendo uses the upper bits as a hashmap index into m_data. */
return (winsock >> 2) % MaxSocketsPerClient;
}
public:
constexpr PosixWinSockConverter() = default;
s32 AcquirePosixHandle(SOCKET winsock, bool exempt = false);
s32 GetShutdown(bool &shutdown, s32 posix);
s32 GetSocketExempt(bool &exempt, s32 posix);
SOCKET PosixToWinsockSocket(s32 posix);
void ReleaseAllPosixHandles();
void ReleasePosixHandle(s32 posix);
s32 SetShutdown(s32 posix, bool shutdown);
s32 SetSocketExempt(s32 posix, bool exempt);
s32 WinsockToPosixSocket(SOCKET winsock);
};
s32 MapProtocolValue(Protocol protocol);
Protocol MapProtocolValue(s32 protocol);
s32 MapTypeValue(Type type);
Type MapTypeValue(s32 type);
s8 MapFamilyValue(Family family);
Family MapFamilyValue(s8 family);
s32 MapMsgFlagValue(MsgFlag flag);
MsgFlag MapMsgFlagValue(s32 flag);
u32 MapAddrInfoFlagValue(AddrInfoFlag flag);
AddrInfoFlag MapAddrInfoFlagValue(u32 flag);
u32 MapShutdownMethodValue(ShutdownMethod how);
ShutdownMethod MapShutdownMethodValue(u32 how);
u32 MapFcntlFlagValue(FcntlFlag flag);
FcntlFlag MapFcntlFlagValue(u32 flag);
s32 MapLevelValue(Level level);
Level MapLevelValue(s32 level);
s32 MapOptionValue(Level level, Option option);
Option MapOptionValue(s32 level, s32 option);
s32 MapErrnoValue(Errno error);
Errno MapErrnoValue(s32 error);
#endif
#define AMS_SOCKET_IMPL_DECLARE_CONVERSION(AMS, PLATFORM) \
void CopyToPlatform(PLATFORM *dst, const AMS *src); \
void CopyFromPlatform(AMS *dst, const PLATFORM *src);
AMS_SOCKET_IMPL_DECLARE_CONVERSION(SockAddrIn, sockaddr_in);
AMS_SOCKET_IMPL_DECLARE_CONVERSION(TimeVal, timeval);
AMS_SOCKET_IMPL_DECLARE_CONVERSION(Linger, linger);
#undef AMS_SOCKET_IMPL_DECLARE_CONVERSION
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/socket/socket_types.hpp>
#include <stratosphere/socket/socket_options.hpp>
#include <stratosphere/socket/socket_errno.hpp>
#include <stratosphere/socket/socket_config.hpp>
namespace ams::socket {
Errno GetLastError();
void SetLastError(Errno err);
u32 InetHtonl(u32 host);
u16 InetHtons(u16 host);
u32 InetNtohl(u32 net);
u16 InetNtohs(u16 net);
Result Initialize(const Config &config);
Result Finalize();
Result InitializeAllocatorForInternal(void *buffer, size_t size);
ssize_t RecvFrom(s32 desc, void *buffer, size_t buffer_size, MsgFlag flags, SockAddr *out_address, SockLenT *out_addr_len);
ssize_t Recv(s32 desc, void *buffer, size_t buffer_size, MsgFlag flags);
ssize_t SendTo(s32 desc, const void *buffer, size_t buffer_size, MsgFlag flags, const SockAddr *address, SockLenT len);
ssize_t Send(s32 desc, const void *buffer, size_t buffer_size, MsgFlag flags);
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);
s32 Bind(s32 desc, const SockAddr *address, SockLenT len);
s32 Connect(s32 desc, const SockAddr *address, SockLenT len);
s32 GetSockName(s32 desc, SockAddr *out_address, SockLenT *out_addr_len);
s32 SetSockOpt(s32 desc, Level level, Option option_name, const void *option_value, SockLenT option_size);
s32 Listen(s32 desc, s32 backlog);
s32 Close(s32 desc);
}

View File

@@ -1,89 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/socket/socket_constants.hpp>
namespace ams::socket {
constexpr ALWAYS_INLINE size_t AlignMss(size_t size) {
return util::DivideUp(size, static_cast<size_t>(1500)) * static_cast<size_t>(1500);
}
class Config {
private:
u32 m_version;
protected:
bool m_system;
bool m_smbp;
void *m_memory_pool;
size_t m_memory_pool_size;
size_t m_allocator_pool_size;
size_t m_tcp_initial_send_buffer_size;
size_t m_tcp_initial_receive_buffer_size;
size_t m_tcp_auto_send_buffer_size_max;
size_t m_tcp_auto_receive_buffer_size_max;
size_t m_udp_send_buffer_size;
size_t m_udp_receive_buffer_size;
int m_sb_efficiency;
int m_concurrency_count_max;
public:
constexpr Config(void *mp, size_t mp_sz, size_t ap, size_t is, size_t ir, size_t as, size_t ar, size_t us, size_t ur, int sbe, int c)
: m_version(LibraryVersion),
m_system(false),
m_smbp(false),
m_memory_pool(mp),
m_memory_pool_size(mp_sz),
m_allocator_pool_size(ap),
m_tcp_initial_send_buffer_size(is),
m_tcp_initial_receive_buffer_size(ir),
m_tcp_auto_send_buffer_size_max(as),
m_tcp_auto_receive_buffer_size_max(ar),
m_udp_send_buffer_size(us),
m_udp_receive_buffer_size(ur),
m_sb_efficiency(sbe),
m_concurrency_count_max(c)
{
/* ... */
}
constexpr u32 GetVersion() const { return m_version; }
constexpr bool IsSystemClient() const { return m_system; }
constexpr bool IsSmbpClient() const { return m_smbp; }
constexpr void *GetMemoryPool() const { return m_memory_pool; }
constexpr size_t GetMemoryPoolSize() const { return m_memory_pool_size; }
constexpr size_t GetAllocatorPoolSize() const { return m_allocator_pool_size; }
constexpr size_t GetTcpInitialSendBufferSize() const { return m_tcp_initial_send_buffer_size; }
constexpr size_t GetTcpInitialReceiveBufferSize() const { return m_tcp_initial_receive_buffer_size; }
constexpr size_t GetTcpAutoSendBufferSizeMax() const { return m_tcp_auto_send_buffer_size_max; }
constexpr size_t GetTcpAutoReceiveBufferSizeMax() const { return m_tcp_auto_receive_buffer_size_max; }
constexpr size_t GetUdpSendBufferSize() const { return m_udp_send_buffer_size; }
constexpr size_t GetUdpReceiveBufferSize() const { return m_udp_receive_buffer_size; }
constexpr int GetSocketBufferEfficiency() const { return m_sb_efficiency; }
constexpr int GetConcurrencyCountMax() const { return m_concurrency_count_max; }
constexpr void SetTcpInitialSendBufferSize(size_t size) { m_tcp_initial_send_buffer_size = size; }
constexpr void SetTcpInitialReceiveBufferSize(size_t size) { m_tcp_initial_receive_buffer_size = size; }
constexpr void SetTcpAutoSendBufferSizeMax(size_t size) { m_tcp_auto_send_buffer_size_max = size; }
constexpr void SetTcpAutoReceiveBufferSizeMax(size_t size) { m_tcp_auto_receive_buffer_size_max = size; }
constexpr void SetUdpSendBufferSize(size_t size) { m_udp_send_buffer_size = size; }
constexpr void SetUdpReceiveBufferSize(size_t size) { m_udp_receive_buffer_size = size; }
constexpr void SetSocketBufferEfficiency(int sb) { AMS_ABORT_UNLESS(1 <= sb && sb <= 8); m_sb_efficiency = sb; }
constexpr void SetConcurrencyCountMax(int c) { m_concurrency_count_max = c; }
};
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::socket {
constexpr inline s32 InvalidSocket = -1;
constexpr inline s32 SocketError = -1;
constexpr inline u32 MaxSocketsPerClient = 0x80;
constexpr inline auto DefaultTcpAutoBufferSizeMax = 192_KB;
constexpr inline auto MinTransferMemorySize = (2 * DefaultTcpAutoBufferSizeMax + 128_KB);
constexpr inline auto MinSocketAllocatorSize = 128_KB;
constexpr inline auto MinSocketMemoryPoolSize = MinSocketAllocatorSize + MinTransferMemorySize;
constexpr inline auto MinMemHeapAllocatorSize = 16_KB;
constexpr inline auto MinimumSharedMbufPoolReservation = 4_KB;
constexpr inline size_t MemoryPoolAlignment = 4_KB;
constexpr inline auto ConcurrencyLimitMax = 14;
/* TODO: Does this need to be 1 for sockets to work on lower firmware versions? */
/* Is this value actually used/checked by bsdsockets sysmodule? */
constexpr inline auto LibraryVersion = 7;
}

View File

@@ -1,181 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::socket {
enum class Errno : u32 {
ESuccess = 0,
EPerm = 1,
ENoEnt = 2,
ESrch = 3,
EIntr = 4,
EIo = 5,
ENxIo = 6,
E2Big = 7,
ENoExec = 8,
EBadf = 9,
EChild = 10,
EAgain = 11,
EWouldBlock = EAgain,
ENoMem = 12,
EAcces = 13,
EFault = 14,
ENotBlk = 15,
EBusy = 16,
EExist = 17,
EXDev = 18,
ENoDev = 19,
ENotDir = 20,
EIsDir = 21,
EInval = 22,
ENFile = 23,
EMFile = 24,
ENotTy = 25,
ETxtBsy = 26,
EFBig = 27,
ENoSpc = 28,
ESPipe = 29,
ERofs = 30,
EMLink = 31,
EPipe = 32,
EDom = 33,
ERange = 34,
EDeadLk = 35,
EDeadLock = EDeadLk,
ENameTooLong = 36,
ENoLck = 37,
ENoSys = 38,
ENotEmpty = 39,
ELoop = 40,
ENoMsg = 42,
EIdrm = 43,
EChrng = 44,
EL2NSync = 45,
EL3Hlt = 46,
EL3Rst = 47,
ELnrng = 48,
EUnatch = 49,
ENoCsi = 50,
EL2Hlt = 51,
EBade = 52,
EBadr = 53,
EXFull = 54,
ENoAno = 55,
EBadRqc = 56,
EBadSsl = 57,
EBFont = 59,
ENoStr = 60,
ENoData = 61,
ETime = 62,
ENoSr = 63,
ENoNet = 64,
ENoPkg = 65,
ERemote = 66,
ENoLink = 67,
EAdv = 68,
ESrmnt = 69,
EComm = 70,
EProto = 71,
EMultiHop = 72,
EDotDot = 73,
EBadMsg = 74,
EOverflow = 75,
ENotUnuq = 76,
EBadFd = 77,
ERemChg = 78,
ELibAcc = 79,
ELibBad = 80,
ELibScn = 81,
ELibMax = 82,
ELibExec = 83,
EIlSeq = 84,
ERestart = 85,
EStrPipe = 86,
EUsers = 87,
ENotSock = 88,
EDestAddrReq = 89,
EMsgSize = 90,
EPrototype = 91,
ENoProtoOpt = 92,
EProtoNoSupport = 93,
ESocktNoSupport = 94,
EOpNotSupp = 95,
ENotSup = EOpNotSupp,
EPfNoSupport = 96,
EAfNoSupport = 97,
EAddrInUse = 98,
EAddrNotAvail = 99,
ENetDown = 100,
ENetUnreach = 101,
ENetReset = 102,
EConnAborted = 103,
EConnReset = 104,
ENoBufs = 105,
EIsConn = 106,
ENotConn = 107,
EShutDown = 108,
ETooManyRefs = 109,
ETimedOut = 110,
EConnRefused = 111,
EHostDown = 112,
EHostUnreach = 113,
EAlready = 114,
EInProgress = 115,
EStale = 116,
EUClean = 117,
ENotNam = 118,
ENAvail = 119,
EIsNam = 120,
ERemoteIo = 121,
EDQuot = 122,
ENoMedium = 123,
EMediumType = 124,
ECanceled = 125,
ENoKey = 126,
EKeyExpired = 127,
EKeyRevoked = 128,
EKeyRejected = 129,
EOwnerDead = 130,
ENotRecoverable = 131,
ERfKill = 132,
EHwPoison = 133,
/* ... */
EProcLim = 156,
};
enum class HErrno : s32 {
Netdb_Internal = -1,
Netdb_Success = 0,
Host_Not_Found = 1,
Try_Again = 2,
No_Recovery = 3,
No_Data = 4,
No_Address = No_Data,
};
enum class AiErrno : u32 {
EAi_Success = 0,
/* ... */
};
constexpr inline bool operator!(Errno e) { return e == Errno::ESuccess; }
constexpr inline bool operator!(HErrno e) { return e == HErrno::Netdb_Success; }
constexpr inline bool operator!(AiErrno e) { return e == AiErrno::EAi_Success; }
}

View File

@@ -1,116 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::socket {
enum class Level : s32 {
Sol_Ip = 0,
Sol_Icmp = 1,
Sol_Tcp = 6,
Sol_Udp = 17,
Sol_UdpLite = 136,
Sol_Socket = 0xFFFF,
};
enum class Option : u32 {
/* ==================================== */
So_Debug = (1 << 0),
So_AcceptConn = (1 << 1),
So_ReuseAddr = (1 << 2),
So_KeepAlive = (1 << 3),
So_DontRoute = (1 << 4),
So_Broadcast = (1 << 5),
So_UseLoopback = (1 << 6),
So_Linger = (1 << 7),
So_OobInline = (1 << 8),
So_ReusePort = (1 << 9),
So_SndBuf = (1 << 12) | 0x01,
So_RcvBuf = (1 << 12) | 0x02,
So_SndLoWat = (1 << 12) | 0x03,
So_RcvLoWat = (1 << 12) | 0x04,
So_SndTimeo = (1 << 12) | 0x05,
So_RcvTimeo = (1 << 12) | 0x06,
So_Error = (1 << 12) | 0x07,
So_Type = (1 << 12) | 0x08,
So_Label = (1 << 12) | 0x09,
So_PeerLabel = (1 << 12) | 0x10,
So_ListenQLimit = (1 << 12) | 0x11,
So_ListenQLen = (1 << 12) | 0x12,
So_ListenIncQLen = (1 << 12) | 0x13,
So_SetFib = (1 << 12) | 0x14,
So_User_Cookie = (1 << 12) | 0x15,
So_Protocol = (1 << 12) | 0x16,
So_Nn_Shutdown_Exempt = (1 << 16),
So_Vendor = (1u << 31),
So_Nn_Linger = So_Vendor | 0x01,
/* ==================================== */
/* ==================================== */
Ip_Options = 1,
Ip_HdrIncl = 2,
Ip_Tos = 3,
Ip_Ttl = 4,
Ip_RecvOpts = 5,
Ip_Multicast_If = 9,
Ip_Multicast_Ttl = 10,
Ip_Multicast_Loop = 11,
Ip_Add_Membership = 12,
Ip_Drop_Membership = 13,
Ip_Multicast_Vif = 14,
Ip_Rsvp_On = 15,
Ip_Rsvp_Off = 16,
Ip_Rsvp_Vif_On = 17,
Ip_Rsvp_Vif_Off = 18,
Ip_PortRange = 19,
Ip_Faith = 22,
Ip_OnesBcast = 23,
Ip_BindAny = 24,
Ip_RecvTtl = 65,
Ip_MinTtl = 66,
Ip_DontFrag = 67,
Ip_RecvTos = 68,
Ip_Add_Source_Membership = 70,
Ip_Drop_Source_Membership = 71,
Ip_Block_Source = 72,
Ip_Unblock_Source = 73,
/* ==================================== */
/* ==================================== */
Tcp_NoDelay = (1 << 0),
Tcp_MaxSeg = (1 << 1),
Tcp_NoPush = (1 << 2),
Tcp_NoOpt = (1 << 3),
Tcp_Md5Sig = (1 << 4),
Tcp_Info = (1 << 5),
Tcp_Congestion = (1 << 6),
Tcp_KeepInit = (1 << 7),
Tcp_KeepIdle = (1 << 8),
Tcp_KeepIntvl = (1 << 9),
Tcp_KeepCnt = (1 << 10),
Tcp_Vendor = So_Vendor,
/* ==================================== */
};
}

View File

@@ -1,98 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/socket/socket_config.hpp>
namespace ams::socket {
class SystemConfigDefault : public Config {
public:
static constexpr size_t DefaultTcpInitialSendBufferSize = 32_KB;
static constexpr size_t DefaultTcpInitialReceiveBufferSize = 64_KB;
static constexpr size_t DefaultTcpAutoSendBufferSizeMax = 256_KB;
static constexpr size_t DefaultTcpAutoReceiveBufferSizeMax = 256_KB;
static constexpr size_t DefaultUdpSendBufferSize = 9_KB;
static constexpr size_t DefaultUdpReceiveBufferSize = 42240;
static constexpr auto DefaultSocketBufferEfficiency = 2;
static constexpr auto DefaultConcurrency = 8;
static constexpr size_t DefaultAllocatorPoolSize = 128_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 SystemConfigDefault(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;
}
};
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;
}
};
}

View File

@@ -1,188 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::socket {
using InAddrT = u32;
using InPortT = u16;
using SockLenT = u32;
using NfdsT = u64;
using FdMask = u64;
constexpr inline unsigned int FdSetSize = 0x400;
template<u32 A, u32 B, u32 C, u32 D>
constexpr inline InAddrT EncodeInAddr = util::ConvertToBigEndian(InAddrT{(A << 24) | (B << 16) | (C << 8) | (D << 0)});
constexpr inline InAddrT InAddr_Any = EncodeInAddr< 0, 0, 0, 0>;
constexpr inline InAddrT InAddr_Broadcast = EncodeInAddr<255, 255, 255, 255>;
constexpr inline InAddrT InAddr_None = EncodeInAddr<255, 255, 255, 255>;
constexpr inline InAddrT InAddr_Loopback = EncodeInAddr<127, 0, 0, 1>;
enum class Protocol : s32 {
IpProto_Ip = 0,
IpProto_Icmp = 1,
IpProto_Tcp = 6,
IpProto_Udp = 17,
IpProto_None = 59,
IpProto_UdpLite = 136,
IpProto_Raw = 255,
IpProto_Max = 256,
};
enum class Type : u32 {
Sock_Default = 0,
Sock_Stream = 1,
Sock_Dgram = 2,
Sock_Raw = 3,
Sock_SeqPacket = 5,
Sock_NonBlock = 0x20000000,
};
enum class Family : u8 {
Af_Unspec = 0,
Pf_Unspec = Af_Unspec,
Af_Inet = 2,
Pf_Inet = Af_Inet,
Af_Route = 17,
Pf_Route = Af_Route,
Af_Link = 18,
Pf_Link = Af_Link,
Af_Inet6 = 28,
Pf_Inet6 = Af_Inet6,
Af_Max = 42,
Pf_Max = Af_Max
};
enum class MsgFlag : s32 {
Msg_None = (0 << 0),
Msg_Oob = (1 << 0),
Msg_Peek = (1 << 1),
Msg_DontRoute = (1 << 2),
/* ... */
Msg_Trunc = (1 << 4),
Msg_CTrunc = (1 << 5),
Msg_WaitAll = (1 << 6),
Msg_DontWait = (1 << 7),
/* ... */
};
enum class FcntlCommand : u32 {
F_GetFl = 3,
F_SetFl = 4,
};
enum class FcntlFlag : u32 {
None = (0 << 0),
O_NonBlock = (1 << 11),
};
enum class ShutdownMethod : u32 {
Shut_Rd = 0,
Shut_Wr = 1,
Shut_RdWr = 2,
};
struct HostEnt {
char *h_name;
char **h_aliases;
Family h_addrtype;
int h_length;
char **h_addr_list;
};
struct InAddr {
InAddrT s_addr;
};
enum class AddrInfoFlag : u32 {
Ai_None = (0 << 0),
Ai_Passive = (1 << 0),
Ai_CanonName = (1 << 1),
Ai_NumericHost = (1 << 2),
Ai_NumericServ = (1 << 3),
Ai_AddrConfig = (1 << 10),
};
struct SockAddr {
u8 sa_len;
Family sa_family;
char sa_data[14];
};
struct SockAddrIn {
u8 sin_len;
Family sin_family;
InPortT sin_port;
InAddr sin_addr;
u8 sin_zero[8];
};
static_assert(sizeof(SockAddr) == sizeof(SockAddrIn));
struct AddrInfo {
AddrInfoFlag ai_flags;
Family ai_family;
Type ai_socktype;
Protocol ai_protocol;
SockLenT ai_addrlen;
SockAddr *ai_addr;
char *ai_canonname;
AddrInfo *ai_next;
};
struct TimeVal {
long tv_sec;
long tv_usec;
};
struct Linger {
int l_onoff;
int l_linger;
};
#define AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS(__ENUM__) \
constexpr inline __ENUM__ operator | (__ENUM__ lhs, __ENUM__ rhs) { return static_cast<__ENUM__>(static_cast<std::underlying_type_t<__ENUM__>>(lhs) | static_cast<std::underlying_type_t<__ENUM__>>(rhs)); } \
constexpr inline __ENUM__ operator |=(__ENUM__ &lhs, __ENUM__ rhs) { return lhs = lhs | rhs; } \
constexpr inline __ENUM__ operator & (__ENUM__ lhs, __ENUM__ rhs) { return static_cast<__ENUM__>(static_cast<std::underlying_type_t<__ENUM__>>(lhs) & static_cast<std::underlying_type_t<__ENUM__>>(rhs)); } \
constexpr inline __ENUM__ operator &=(__ENUM__ &lhs, __ENUM__ rhs) { return lhs = lhs & rhs; } \
constexpr inline __ENUM__ operator ^ (__ENUM__ lhs, __ENUM__ rhs) { return static_cast<__ENUM__>(static_cast<std::underlying_type_t<__ENUM__>>(lhs) ^ static_cast<std::underlying_type_t<__ENUM__>>(rhs)); } \
constexpr inline __ENUM__ operator ^=(__ENUM__ &lhs, __ENUM__ rhs) { return lhs = lhs ^ rhs; } \
constexpr inline __ENUM__ operator ~ (__ENUM__ e) { return static_cast<__ENUM__>(~static_cast<std::underlying_type_t<__ENUM__>>(e)); }
AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS(Type)
AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS(AddrInfoFlag)
AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS(MsgFlag)
AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS(FcntlFlag)
#undef AMS_SOCKET_IMPL_DEFINE_ENUM_OPERATORS
}