|
|
|
@@ -54,11 +54,11 @@ void PutValue(std::span<u8> buffer, const T& t) {
|
|
|
|
|
|
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
|
|
void BSD::PollWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::PollWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->PollImpl(write_buffer, read_buffer, nfds, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::PollWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::PollWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
if (write_buffer.size() > 0) {
|
|
|
|
|
ctx.WriteBuffer(write_buffer);
|
|
|
|
|
}
|
|
|
|
@@ -69,11 +69,11 @@ void BSD::PollWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::AcceptWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::AcceptWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->AcceptImpl(fd, write_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::AcceptWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::AcceptWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
if (write_buffer.size() > 0) {
|
|
|
|
|
ctx.WriteBuffer(write_buffer);
|
|
|
|
|
}
|
|
|
|
@@ -85,22 +85,22 @@ void BSD::AcceptWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::ConnectWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::ConnectWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
bsd_errno = bsd->ConnectImpl(fd, addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::ConnectWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::ConnectWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
|
rb.Push<s32>(bsd_errno == Errno::SUCCESS ? 0 : -1);
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RecvWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::RecvWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->RecvImpl(fd, flags, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RecvWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::RecvWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
ctx.WriteBuffer(message);
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
@@ -109,11 +109,11 @@ void BSD::RecvWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RecvFromWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::RecvFromWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->RecvFromImpl(fd, flags, message, addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RecvFromWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::RecvFromWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
ctx.WriteBuffer(message, 0);
|
|
|
|
|
if (!addr.empty()) {
|
|
|
|
|
ctx.WriteBuffer(addr, 1);
|
|
|
|
@@ -126,29 +126,29 @@ void BSD::RecvFromWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(addr.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SendWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::SendWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->SendImpl(fd, flags, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SendWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::SendWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
|
rb.Push<s32>(ret);
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SendToWork::Execute(BSD* bsd) {
|
|
|
|
|
void NetworkBSD::SendToWork::Execute(NetworkBSD* bsd) {
|
|
|
|
|
std::tie(ret, bsd_errno) = bsd->SendToImpl(fd, flags, message, addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SendToWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::SendToWork::Response(HLERequestContext& ctx) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
|
rb.Push<s32>(ret);
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RegisterClient(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::RegisterClient(HLERequestContext& ctx) {
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) called");
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
@@ -157,7 +157,7 @@ void BSD::RegisterClient(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<s32>(0); // bsd errno
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::StartMonitoring(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::StartMonitoring(HLERequestContext& ctx) {
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) called");
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
@@ -165,7 +165,7 @@ void BSD::StartMonitoring(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Socket(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Socket(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const u32 domain = rp.Pop<u32>();
|
|
|
|
|
const u32 type = rp.Pop<u32>();
|
|
|
|
@@ -182,7 +182,7 @@ void BSD::Socket(HLERequestContext& ctx) {
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Select(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Select(HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service, "(STUBBED) called");
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
@@ -192,7 +192,7 @@ void BSD::Select(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(0); // bsd errno
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Poll(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Poll(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 nfds = rp.Pop<s32>();
|
|
|
|
|
const s32 timeout = rp.Pop<s32>();
|
|
|
|
@@ -207,7 +207,7 @@ void BSD::Poll(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Accept(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Accept(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -219,7 +219,7 @@ void BSD::Accept(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Bind(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Bind(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -227,7 +227,7 @@ void BSD::Bind(HLERequestContext& ctx) {
|
|
|
|
|
BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Connect(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Connect(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -239,7 +239,7 @@ void BSD::Connect(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::GetPeerName(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::GetPeerName(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -257,7 +257,7 @@ void BSD::GetPeerName(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::GetSockName(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::GetSockName(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -275,7 +275,7 @@ void BSD::GetSockName(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::GetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::GetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
const u32 level = rp.Pop<u32>();
|
|
|
|
@@ -297,7 +297,7 @@ void BSD::GetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(optval.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Listen(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Listen(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
const s32 backlog = rp.Pop<s32>();
|
|
|
|
@@ -307,7 +307,7 @@ void BSD::Listen(HLERequestContext& ctx) {
|
|
|
|
|
BuildErrnoResponse(ctx, ListenImpl(fd, backlog));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Fcntl(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Fcntl(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
const s32 cmd = rp.Pop<s32>();
|
|
|
|
@@ -323,7 +323,7 @@ void BSD::Fcntl(HLERequestContext& ctx) {
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::SetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
@@ -337,7 +337,7 @@ void BSD::SetSockOpt(HLERequestContext& ctx) {
|
|
|
|
|
BuildErrnoResponse(ctx, SetSockOptImpl(fd, level, optname, optval));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Shutdown(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Shutdown(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
@@ -348,7 +348,7 @@ void BSD::Shutdown(HLERequestContext& ctx) {
|
|
|
|
|
BuildErrnoResponse(ctx, ShutdownImpl(fd, how));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Recv(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Recv(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
@@ -363,7 +363,7 @@ void BSD::Recv(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::RecvFrom(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::RecvFrom(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
@@ -380,7 +380,7 @@ void BSD::RecvFrom(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Send(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Send(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
@@ -395,7 +395,7 @@ void BSD::Send(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::SendTo(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::SendTo(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
const u32 flags = rp.Pop<u32>();
|
|
|
|
@@ -411,7 +411,7 @@ void BSD::SendTo(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Write(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Write(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -424,7 +424,7 @@ void BSD::Write(HLERequestContext& ctx) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Read(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Read(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -436,7 +436,7 @@ void BSD::Read(HLERequestContext& ctx) {
|
|
|
|
|
rb.Push<u32>(0); // bsd errno
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::Close(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::Close(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const s32 fd = rp.Pop<s32>();
|
|
|
|
|
|
|
|
|
@@ -445,7 +445,7 @@ void BSD::Close(HLERequestContext& ctx) {
|
|
|
|
|
BuildErrnoResponse(ctx, CloseImpl(fd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::DuplicateSocket(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::DuplicateSocket(HLERequestContext& ctx) {
|
|
|
|
|
struct InputParameters {
|
|
|
|
|
s32 fd;
|
|
|
|
|
u64 reserved;
|
|
|
|
@@ -479,7 +479,7 @@ void BSD::DuplicateSocket(HLERequestContext& ctx) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::EventFd(HLERequestContext& ctx) {
|
|
|
|
|
void NetworkBSD::EventFd(HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const u64 initval = rp.Pop<u64>();
|
|
|
|
|
const u32 flags = rp.Pop<u32>();
|
|
|
|
@@ -490,12 +490,12 @@ void BSD::EventFd(HLERequestContext& ctx) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Work>
|
|
|
|
|
void BSD::ExecuteWork(HLERequestContext& ctx, Work work) {
|
|
|
|
|
void NetworkBSD::ExecuteWork(HLERequestContext& ctx, Work work) {
|
|
|
|
|
work.Execute(this);
|
|
|
|
|
work.Response(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protocol) {
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::SocketImpl(Domain domain, Type type, Protocol protocol) {
|
|
|
|
|
|
|
|
|
|
if (type == Type::SEQPACKET) {
|
|
|
|
|
UNIMPLEMENTED_MSG("SOCK_SEQPACKET errno management");
|
|
|
|
@@ -537,7 +537,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
|
|
|
|
|
return {fd, Errno::SUCCESS};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
|
|
|
|
|
s32 nfds, s32 timeout) {
|
|
|
|
|
if (nfds <= 0) {
|
|
|
|
|
// When no entries are provided, -1 is returned with errno zero
|
|
|
|
@@ -604,7 +604,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::span<con
|
|
|
|
|
return Translate(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
|
}
|
|
|
|
@@ -632,7 +632,7 @@ std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
return {new_fd, Errno::SUCCESS};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::BindImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
Errno NetworkBSD::BindImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -647,7 +647,7 @@ Errno BSD::BindImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
Errno NetworkBSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -670,7 +670,7 @@ Errno BSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
Errno NetworkBSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -692,7 +692,7 @@ Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
return Translate(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
Errno NetworkBSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -714,7 +714,7 @@ Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
|
|
|
|
return Translate(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::ListenImpl(s32 fd, s32 backlog) {
|
|
|
|
|
Errno NetworkBSD::ListenImpl(s32 fd, s32 backlog) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -725,7 +725,7 @@ Errno BSD::ListenImpl(s32 fd, s32 backlog) {
|
|
|
|
|
return Translate(file_descriptors[fd]->socket->Listen(backlog));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
|
}
|
|
|
|
@@ -755,7 +755,7 @@ std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& optval) {
|
|
|
|
|
Errno NetworkBSD::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& optval) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -790,7 +790,7 @@ Errno BSD::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& o
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8> optval) {
|
|
|
|
|
Errno NetworkBSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8> optval) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -844,7 +844,7 @@ Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::ShutdownImpl(s32 fd, s32 how) {
|
|
|
|
|
Errno NetworkBSD::ShutdownImpl(s32 fd, s32 how) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -856,7 +856,7 @@ Errno BSD::ShutdownImpl(s32 fd, s32 how) {
|
|
|
|
|
return Translate(file_descriptors[fd]->socket->Shutdown(host_how));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) {
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
|
}
|
|
|
|
@@ -883,7 +883,7 @@ std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message)
|
|
|
|
|
return {ret, bsd_errno};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
|
|
|
|
|
std::vector<u8>& addr) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
@@ -930,7 +930,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
|
|
|
|
|
return {ret, bsd_errno};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, std::span<const u8> message) {
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::SendImpl(s32 fd, u32 flags, std::span<const u8> message) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
|
}
|
|
|
|
@@ -941,7 +941,7 @@ std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, std::span<const u8> messa
|
|
|
|
|
return Translate(file_descriptors[fd]->socket->Send(message, flags));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
|
|
|
|
|
std::pair<s32, Errno> NetworkBSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
|
|
|
|
|
std::span<const u8> addr) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return {-1, Errno::BADF};
|
|
|
|
@@ -963,7 +963,7 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> mes
|
|
|
|
|
return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Errno BSD::CloseImpl(s32 fd) {
|
|
|
|
|
Errno NetworkBSD::CloseImpl(s32 fd) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -983,7 +983,7 @@ Errno BSD::CloseImpl(s32 fd) {
|
|
|
|
|
return bsd_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::variant<s32, Errno> BSD::DuplicateSocketImpl(s32 fd) {
|
|
|
|
|
std::variant<s32, Errno> NetworkBSD::DuplicateSocketImpl(s32 fd) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return Errno::BADF;
|
|
|
|
|
}
|
|
|
|
@@ -1002,7 +1002,7 @@ std::variant<s32, Errno> BSD::DuplicateSocketImpl(s32 fd) {
|
|
|
|
|
return new_fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::shared_ptr<Network::SocketBase>> BSD::GetSocket(s32 fd) {
|
|
|
|
|
std::optional<std::shared_ptr<Network::SocketBase>> NetworkBSD::GetSocket(s32 fd) {
|
|
|
|
|
if (!IsFileDescriptorValid(fd)) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
@@ -1013,7 +1013,7 @@ std::optional<std::shared_ptr<Network::SocketBase>> BSD::GetSocket(s32 fd) {
|
|
|
|
|
return file_descriptors[fd]->socket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 BSD::FindFreeFileDescriptorHandle() noexcept {
|
|
|
|
|
s32 NetworkBSD::FindFreeFileDescriptorHandle() noexcept {
|
|
|
|
|
for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) {
|
|
|
|
|
if (!file_descriptors[fd]) {
|
|
|
|
|
return fd;
|
|
|
|
@@ -1022,7 +1022,7 @@ s32 BSD::FindFreeFileDescriptorHandle() noexcept {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
|
|
|
|
|
bool NetworkBSD::IsFileDescriptorValid(s32 fd) const noexcept {
|
|
|
|
|
if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
|
|
|
|
|
LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
|
|
|
|
|
return false;
|
|
|
|
@@ -1034,7 +1034,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept {
|
|
|
|
|
void NetworkBSD::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
|
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
@@ -1042,7 +1042,7 @@ void BSD::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noex
|
|
|
|
|
rb.PushEnum(bsd_errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BSD::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
|
|
|
|
void NetworkBSD::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
|
|
|
|
for (auto& optional_descriptor : file_descriptors) {
|
|
|
|
|
if (!optional_descriptor.has_value()) {
|
|
|
|
|
continue;
|
|
|
|
@@ -1052,42 +1052,42 @@ void BSD::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BSD::BSD(Core::System& system_, const char* name)
|
|
|
|
|
NetworkBSD::NetworkBSD(Core::System& system_, const char* name)
|
|
|
|
|
: ServiceFramework{system_, name} {
|
|
|
|
|
// clang-format off
|
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
|
{0, &BSD::RegisterClient, "RegisterClient"},
|
|
|
|
|
{1, &BSD::StartMonitoring, "StartMonitoring"},
|
|
|
|
|
{2, &BSD::Socket, "Socket"},
|
|
|
|
|
{0, &NetworkBSD::RegisterClient, "RegisterClient"},
|
|
|
|
|
{1, &NetworkBSD::StartMonitoring, "StartMonitoring"},
|
|
|
|
|
{2, &NetworkBSD::Socket, "Socket"},
|
|
|
|
|
{3, nullptr, "SocketExempt"},
|
|
|
|
|
{4, nullptr, "Open"},
|
|
|
|
|
{5, &BSD::Select, "Select"},
|
|
|
|
|
{6, &BSD::Poll, "Poll"},
|
|
|
|
|
{5, &NetworkBSD::Select, "Select"},
|
|
|
|
|
{6, &NetworkBSD::Poll, "Poll"},
|
|
|
|
|
{7, nullptr, "Sysctl"},
|
|
|
|
|
{8, &BSD::Recv, "Recv"},
|
|
|
|
|
{9, &BSD::RecvFrom, "RecvFrom"},
|
|
|
|
|
{10, &BSD::Send, "Send"},
|
|
|
|
|
{11, &BSD::SendTo, "SendTo"},
|
|
|
|
|
{12, &BSD::Accept, "Accept"},
|
|
|
|
|
{13, &BSD::Bind, "Bind"},
|
|
|
|
|
{14, &BSD::Connect, "Connect"},
|
|
|
|
|
{15, &BSD::GetPeerName, "GetPeerName"},
|
|
|
|
|
{16, &BSD::GetSockName, "GetSockName"},
|
|
|
|
|
{17, &BSD::GetSockOpt, "GetSockOpt"},
|
|
|
|
|
{18, &BSD::Listen, "Listen"},
|
|
|
|
|
{8, &NetworkBSD::Recv, "Recv"},
|
|
|
|
|
{9, &NetworkBSD::RecvFrom, "RecvFrom"},
|
|
|
|
|
{10, &NetworkBSD::Send, "Send"},
|
|
|
|
|
{11, &NetworkBSD::SendTo, "SendTo"},
|
|
|
|
|
{12, &NetworkBSD::Accept, "Accept"},
|
|
|
|
|
{13, &NetworkBSD::Bind, "Bind"},
|
|
|
|
|
{14, &NetworkBSD::Connect, "Connect"},
|
|
|
|
|
{15, &NetworkBSD::GetPeerName, "GetPeerName"},
|
|
|
|
|
{16, &NetworkBSD::GetSockName, "GetSockName"},
|
|
|
|
|
{17, &NetworkBSD::GetSockOpt, "GetSockOpt"},
|
|
|
|
|
{18, &NetworkBSD::Listen, "Listen"},
|
|
|
|
|
{19, nullptr, "Ioctl"},
|
|
|
|
|
{20, &BSD::Fcntl, "Fcntl"},
|
|
|
|
|
{21, &BSD::SetSockOpt, "SetSockOpt"},
|
|
|
|
|
{22, &BSD::Shutdown, "Shutdown"},
|
|
|
|
|
{20, &NetworkBSD::Fcntl, "Fcntl"},
|
|
|
|
|
{21, &NetworkBSD::SetSockOpt, "SetSockOpt"},
|
|
|
|
|
{22, &NetworkBSD::Shutdown, "Shutdown"},
|
|
|
|
|
{23, nullptr, "ShutdownAllSockets"},
|
|
|
|
|
{24, &BSD::Write, "Write"},
|
|
|
|
|
{25, &BSD::Read, "Read"},
|
|
|
|
|
{26, &BSD::Close, "Close"},
|
|
|
|
|
{27, &BSD::DuplicateSocket, "DuplicateSocket"},
|
|
|
|
|
{24, &NetworkBSD::Write, "Write"},
|
|
|
|
|
{25, &NetworkBSD::Read, "Read"},
|
|
|
|
|
{26, &NetworkBSD::Close, "Close"},
|
|
|
|
|
{27, &NetworkBSD::DuplicateSocket, "DuplicateSocket"},
|
|
|
|
|
{28, nullptr, "GetResourceStatistics"},
|
|
|
|
|
{29, nullptr, "RecvMMsg"}, //3.0.0+
|
|
|
|
|
{30, nullptr, "SendMMsg"}, //3.0.0+
|
|
|
|
|
{31, &BSD::EventFd, "EventFd"}, //7.0.0+
|
|
|
|
|
{31, &NetworkBSD::EventFd, "EventFd"}, //7.0.0+
|
|
|
|
|
{32, nullptr, "RegisterResourceStatisticsName"}, //7.0.0+
|
|
|
|
|
{33, nullptr, "RegisterClientShared"}, //10.0.0+
|
|
|
|
|
{34, nullptr, "GetSocketStatistics"}, //15.0.0+
|
|
|
|
@@ -1115,13 +1115,13 @@ BSD::BSD(Core::System& system_, const char* name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BSD::~BSD() {
|
|
|
|
|
NetworkBSD::~NetworkBSD() {
|
|
|
|
|
if (auto room_member = Network::GetRoomMember().lock()) {
|
|
|
|
|
room_member->Unbind(proxy_packet_received);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> BSD::LockService() noexcept {
|
|
|
|
|
std::unique_lock<std::mutex> NetworkBSD::LockService() noexcept {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|