mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 07:39:49 -04:00
htc: implement socket driver (socket api not really impl'd yet)
This commit is contained in:
parent
b5ab491603
commit
1c974a387c
31 changed files with 1389 additions and 35 deletions
|
@ -16,7 +16,9 @@
|
|||
#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 {
|
||||
|
||||
|
@ -28,4 +30,30 @@ namespace ams::socket {
|
|||
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 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 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);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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 <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));
|
||||
}
|
||||
|
||||
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; }
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 <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 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;
|
||||
|
||||
}
|
|
@ -19,10 +19,21 @@
|
|||
namespace ams::socket {
|
||||
|
||||
enum class Errno : u32 {
|
||||
ESuccess = 0,
|
||||
ESuccess = 0,
|
||||
/* ... */
|
||||
ENoSpc = 28,
|
||||
EAgain = 11,
|
||||
ENoMem = 12,
|
||||
/* ... */
|
||||
EFault = 14,
|
||||
/* ... */
|
||||
EInval = 22,
|
||||
/* ... */
|
||||
ENoSpc = 28,
|
||||
/* ... */
|
||||
EL3Hlt = 46,
|
||||
/* ... */
|
||||
EOpNotSupp = 95,
|
||||
ENotSup = EOpNotSupp,
|
||||
};
|
||||
|
||||
enum class HErrno : s32 {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 <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_ReuseAddr = (1 << 2),
|
||||
/* ... */
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 <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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -79,6 +79,19 @@ namespace ams::socket {
|
|||
Pf_Max = Af_Max
|
||||
};
|
||||
|
||||
enum class MsgFlag : s32 {
|
||||
MsgFlag_None = (0 << 0),
|
||||
/* ... */
|
||||
MsgFlag_WaitAll = (1 << 6),
|
||||
/* ... */
|
||||
};
|
||||
|
||||
enum class ShutdownMethod : u32 {
|
||||
Shut_Rd = 0,
|
||||
Shut_Wr = 1,
|
||||
Shut_RdWr = 2,
|
||||
};
|
||||
|
||||
struct HostEnt {
|
||||
char *h_name;
|
||||
char **h_aliases;
|
||||
|
@ -98,7 +111,7 @@ namespace ams::socket {
|
|||
Ai_NumericHost = (1 << 2),
|
||||
Ai_NumericServ = (1 << 3),
|
||||
|
||||
Ai_AddrConfig = (1 << 10),
|
||||
Ai_AddrConfig = (1 << 10),
|
||||
};
|
||||
|
||||
struct SockAddr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue