yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

bsd: Use std::span for read payloads

Allows the use of HLERequestContext::ReadBufferSpan
This commit is contained in:
ameerj 2022-12-25 14:29:53 -05:00
parent f517f82416
commit 7c1bf68bb4
6 changed files with 38 additions and 36 deletions

View File

@ -186,7 +186,7 @@ void BSD::Poll(Kernel::HLERequestContext& ctx) {
ExecuteWork(ctx, PollWork{ ExecuteWork(ctx, PollWork{
.nfds = nfds, .nfds = nfds,
.timeout = timeout, .timeout = timeout,
.read_buffer = ctx.ReadBuffer(), .read_buffer = ctx.ReadBufferSpan(),
.write_buffer = std::vector<u8>(ctx.GetWriteBufferSize()), .write_buffer = std::vector<u8>(ctx.GetWriteBufferSize()),
}); });
} }
@ -208,8 +208,7 @@ void BSD::Bind(Kernel::HLERequestContext& ctx) {
const s32 fd = rp.Pop<s32>(); const s32 fd = rp.Pop<s32>();
LOG_DEBUG(Service, "called. fd={} addrlen={}", fd, ctx.GetReadBufferSize()); LOG_DEBUG(Service, "called. fd={} addrlen={}", fd, ctx.GetReadBufferSize());
BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBufferSpan()));
BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer()));
} }
void BSD::Connect(Kernel::HLERequestContext& ctx) { void BSD::Connect(Kernel::HLERequestContext& ctx) {
@ -220,7 +219,7 @@ void BSD::Connect(Kernel::HLERequestContext& ctx) {
ExecuteWork(ctx, ConnectWork{ ExecuteWork(ctx, ConnectWork{
.fd = fd, .fd = fd,
.addr = ctx.ReadBuffer(), .addr = ctx.ReadBufferSpan(),
}); });
} }
@ -312,7 +311,7 @@ void BSD::SetSockOpt(Kernel::HLERequestContext& ctx) {
const u32 level = rp.Pop<u32>(); const u32 level = rp.Pop<u32>();
const OptName optname = static_cast<OptName>(rp.Pop<u32>()); const OptName optname = static_cast<OptName>(rp.Pop<u32>());
const std::vector<u8> buffer = ctx.ReadBuffer(); const auto buffer = ctx.ReadBufferSpan();
const u8* optval = buffer.empty() ? nullptr : buffer.data(); const u8* optval = buffer.empty() ? nullptr : buffer.data();
size_t optlen = buffer.size(); size_t optlen = buffer.size();
@ -383,7 +382,7 @@ void BSD::Send(Kernel::HLERequestContext& ctx) {
ExecuteWork(ctx, SendWork{ ExecuteWork(ctx, SendWork{
.fd = fd, .fd = fd,
.flags = flags, .flags = flags,
.message = ctx.ReadBuffer(), .message = ctx.ReadBufferSpan(),
}); });
} }
@ -398,8 +397,8 @@ void BSD::SendTo(Kernel::HLERequestContext& ctx) {
ExecuteWork(ctx, SendToWork{ ExecuteWork(ctx, SendToWork{
.fd = fd, .fd = fd,
.flags = flags, .flags = flags,
.message = ctx.ReadBuffer(0), .message = ctx.ReadBufferSpan(0),
.addr = ctx.ReadBuffer(1), .addr = ctx.ReadBufferSpan(1),
}); });
} }
@ -412,7 +411,7 @@ void BSD::Write(Kernel::HLERequestContext& ctx) {
ExecuteWork(ctx, SendWork{ ExecuteWork(ctx, SendWork{
.fd = fd, .fd = fd,
.flags = 0, .flags = 0,
.message = ctx.ReadBuffer(), .message = ctx.ReadBufferSpan(),
}); });
} }
@ -489,7 +488,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
return {fd, Errno::SUCCESS}; return {fd, Errno::SUCCESS};
} }
std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
s32 nfds, s32 timeout) { s32 nfds, s32 timeout) {
if (write_buffer.size() < nfds * sizeof(PollFD)) { if (write_buffer.size() < nfds * sizeof(PollFD)) {
return {-1, Errno::INVAL}; return {-1, Errno::INVAL};
@ -584,7 +583,7 @@ std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
return {new_fd, Errno::SUCCESS}; return {new_fd, Errno::SUCCESS};
} }
Errno BSD::BindImpl(s32 fd, const std::vector<u8>& addr) { Errno BSD::BindImpl(s32 fd, std::span<const u8> addr) {
if (!IsFileDescriptorValid(fd)) { if (!IsFileDescriptorValid(fd)) {
return Errno::BADF; return Errno::BADF;
} }
@ -595,7 +594,7 @@ Errno BSD::BindImpl(s32 fd, const std::vector<u8>& addr) {
return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in))); return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in)));
} }
Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { Errno BSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
if (!IsFileDescriptorValid(fd)) { if (!IsFileDescriptorValid(fd)) {
return Errno::BADF; return Errno::BADF;
} }
@ -800,15 +799,15 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
return {ret, bsd_errno}; return {ret, bsd_errno};
} }
std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, const std::vector<u8>& message) { std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, std::span<const u8> message) {
if (!IsFileDescriptorValid(fd)) { if (!IsFileDescriptorValid(fd)) {
return {-1, Errno::BADF}; return {-1, Errno::BADF};
} }
return Translate(file_descriptors[fd]->socket->Send(message, flags)); return Translate(file_descriptors[fd]->socket->Send(message, flags));
} }
std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
const std::vector<u8>& addr) { std::span<const u8> addr) {
if (!IsFileDescriptorValid(fd)) { if (!IsFileDescriptorValid(fd)) {
return {-1, Errno::BADF}; return {-1, Errno::BADF};
} }

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <span>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
@ -44,7 +45,7 @@ private:
s32 nfds; s32 nfds;
s32 timeout; s32 timeout;
std::vector<u8> read_buffer; std::span<const u8> read_buffer;
std::vector<u8> write_buffer; std::vector<u8> write_buffer;
s32 ret{}; s32 ret{};
Errno bsd_errno{}; Errno bsd_errno{};
@ -65,7 +66,7 @@ private:
void Response(Kernel::HLERequestContext& ctx); void Response(Kernel::HLERequestContext& ctx);
s32 fd; s32 fd;
std::vector<u8> addr; std::span<const u8> addr;
Errno bsd_errno{}; Errno bsd_errno{};
}; };
@ -98,7 +99,7 @@ private:
s32 fd; s32 fd;
u32 flags; u32 flags;
std::vector<u8> message; std::span<const u8> message;
s32 ret{}; s32 ret{};
Errno bsd_errno{}; Errno bsd_errno{};
}; };
@ -109,8 +110,8 @@ private:
s32 fd; s32 fd;
u32 flags; u32 flags;
std::vector<u8> message; std::span<const u8> message;
std::vector<u8> addr; std::span<const u8> addr;
s32 ret{}; s32 ret{};
Errno bsd_errno{}; Errno bsd_errno{};
}; };
@ -143,11 +144,11 @@ private:
void ExecuteWork(Kernel::HLERequestContext& ctx, Work work); void ExecuteWork(Kernel::HLERequestContext& ctx, Work work);
std::pair<s32, Errno> SocketImpl(Domain domain, Type type, Protocol protocol); std::pair<s32, Errno> SocketImpl(Domain domain, Type type, Protocol protocol);
std::pair<s32, Errno> PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, std::pair<s32, Errno> PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
s32 nfds, s32 timeout); s32 nfds, s32 timeout);
std::pair<s32, Errno> AcceptImpl(s32 fd, std::vector<u8>& write_buffer); std::pair<s32, Errno> AcceptImpl(s32 fd, std::vector<u8>& write_buffer);
Errno BindImpl(s32 fd, const std::vector<u8>& addr); Errno BindImpl(s32 fd, std::span<const u8> addr);
Errno ConnectImpl(s32 fd, const std::vector<u8>& addr); Errno ConnectImpl(s32 fd, std::span<const u8> addr);
Errno GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer); Errno GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer);
Errno GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer); Errno GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer);
Errno ListenImpl(s32 fd, s32 backlog); Errno ListenImpl(s32 fd, s32 backlog);
@ -157,9 +158,9 @@ private:
std::pair<s32, Errno> RecvImpl(s32 fd, u32 flags, std::vector<u8>& message); std::pair<s32, Errno> RecvImpl(s32 fd, u32 flags, std::vector<u8>& message);
std::pair<s32, Errno> RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message, std::pair<s32, Errno> RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
std::vector<u8>& addr); std::vector<u8>& addr);
std::pair<s32, Errno> SendImpl(s32 fd, u32 flags, const std::vector<u8>& message); std::pair<s32, Errno> SendImpl(s32 fd, u32 flags, std::span<const u8> message);
std::pair<s32, Errno> SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
const std::vector<u8>& addr); std::span<const u8> addr);
Errno CloseImpl(s32 fd); Errno CloseImpl(s32 fd);
s32 FindFreeFileDescriptorHandle() noexcept; s32 FindFreeFileDescriptorHandle() noexcept;

View File

@ -546,7 +546,7 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock
return {-1, GetAndLogLastError()}; return {-1, GetAndLogLastError()};
} }
std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) { std::pair<s32, Errno> Socket::Send(std::span<const u8> message, int flags) {
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
ASSERT(flags == 0); ASSERT(flags == 0);
@ -559,7 +559,7 @@ std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) {
return {-1, GetAndLogLastError()}; return {-1, GetAndLogLastError()};
} }
std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> Socket::SendTo(u32 flags, std::span<const u8> message,
const SockAddrIn* addr) { const SockAddrIn* addr) {
ASSERT(flags == 0); ASSERT(flags == 0);

View File

@ -182,7 +182,7 @@ std::pair<s32, Errno> ProxySocket::ReceivePacket(int flags, std::vector<u8>& mes
return {static_cast<u32>(read_bytes), Errno::SUCCESS}; return {static_cast<u32>(read_bytes), Errno::SUCCESS};
} }
std::pair<s32, Errno> ProxySocket::Send(const std::vector<u8>& message, int flags) { std::pair<s32, Errno> ProxySocket::Send(std::span<const u8> message, int flags) {
LOG_WARNING(Network, "(STUBBED) called"); LOG_WARNING(Network, "(STUBBED) called");
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
ASSERT(flags == 0); ASSERT(flags == 0);
@ -200,7 +200,7 @@ void ProxySocket::SendPacket(ProxyPacket& packet) {
} }
} }
std::pair<s32, Errno> ProxySocket::SendTo(u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> ProxySocket::SendTo(u32 flags, std::span<const u8> message,
const SockAddrIn* addr) { const SockAddrIn* addr) {
ASSERT(flags == 0); ASSERT(flags == 0);

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <mutex> #include <mutex>
#include <span>
#include <vector> #include <vector>
#include <queue> #include <queue>
@ -48,11 +49,11 @@ public:
std::pair<s32, Errno> ReceivePacket(int flags, std::vector<u8>& message, SockAddrIn* addr, std::pair<s32, Errno> ReceivePacket(int flags, std::vector<u8>& message, SockAddrIn* addr,
std::size_t max_length); std::size_t max_length);
std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags) override; std::pair<s32, Errno> Send(std::span<const u8> message, int flags) override;
void SendPacket(ProxyPacket& packet); void SendPacket(ProxyPacket& packet);
std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> SendTo(u32 flags, std::span<const u8> message,
const SockAddrIn* addr) override; const SockAddrIn* addr) override;
Errno SetLinger(bool enable, u32 linger) override; Errno SetLinger(bool enable, u32 linger) override;

View File

@ -5,6 +5,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <span>
#include <utility> #include <utility>
#if defined(_WIN32) #if defined(_WIN32)
@ -66,9 +67,9 @@ public:
virtual std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, virtual std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message,
SockAddrIn* addr) = 0; SockAddrIn* addr) = 0;
virtual std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags) = 0; virtual std::pair<s32, Errno> Send(std::span<const u8> message, int flags) = 0;
virtual std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, virtual std::pair<s32, Errno> SendTo(u32 flags, std::span<const u8> message,
const SockAddrIn* addr) = 0; const SockAddrIn* addr) = 0;
virtual Errno SetLinger(bool enable, u32 linger) = 0; virtual Errno SetLinger(bool enable, u32 linger) = 0;
@ -138,9 +139,9 @@ public:
std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) override; std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) override;
std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags) override; std::pair<s32, Errno> Send(std::span<const u8> message, int flags) override;
std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, std::pair<s32, Errno> SendTo(u32 flags, std::span<const u8> message,
const SockAddrIn* addr) override; const SockAddrIn* addr) override;
Errno SetLinger(bool enable, u32 linger) override; Errno SetLinger(bool enable, u32 linger) override;