mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
Kernel: Use Userspace<T> for the sendto syscall, and Socket implementation
Note that the data member is of type ImmutableBufferArgument, which has no Userspace<T> usage. I left it alone for now, to be fixed in a future change holistically for all usages.
This commit is contained in:
parent
d4dae49dcd
commit
9f9b05ba0f
Notes:
sideshowbarker
2024-07-19 03:25:30 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/9f9b05ba0f8 Pull-request: https://github.com/SerenityOS/serenity/pull/3201 Reviewed-by: https://github.com/awesomekling
9 changed files with 16 additions and 13 deletions
|
@ -290,7 +290,7 @@ struct SC_sendto_params {
|
|||
int sockfd;
|
||||
ImmutableBufferArgument<void, size_t> data;
|
||||
int flags;
|
||||
const sockaddr* addr;
|
||||
Userspace<const sockaddr*> addr;
|
||||
socklen_t addr_length;
|
||||
};
|
||||
|
||||
|
|
|
@ -193,19 +193,22 @@ int IPv4Socket::allocate_local_port_if_needed()
|
|||
return port;
|
||||
}
|
||||
|
||||
KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
||||
KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const void* data, size_t data_length, int flags, Userspace<const sockaddr*> addr, socklen_t addr_length)
|
||||
{
|
||||
(void)flags;
|
||||
if (addr && addr_length != sizeof(sockaddr_in))
|
||||
return KResult(-EINVAL);
|
||||
|
||||
if (addr) {
|
||||
if (addr->sa_family != AF_INET) {
|
||||
klog() << "sendto: Bad address family: " << addr->sa_family << " is not AF_INET!";
|
||||
sockaddr_in ia;
|
||||
if (!Process::current()->validate_read_and_copy_typed(&ia, Userspace<const sockaddr_in*>(addr.ptr())))
|
||||
return KResult(-EFAULT);
|
||||
|
||||
if (ia.sin_family != AF_INET) {
|
||||
klog() << "sendto: Bad address family: " << ia.sin_family << " is not AF_INET!";
|
||||
return KResult(-EAFNOSUPPORT);
|
||||
}
|
||||
|
||||
auto& ia = *(const sockaddr_in*)addr;
|
||||
m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr);
|
||||
m_peer_port = ntohs(ia.sin_port);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
virtual void detach(FileDescription&) override;
|
||||
virtual bool can_read(const FileDescription&, size_t) const override;
|
||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int, Userspace<const sockaddr*>, socklen_t) override;
|
||||
virtual KResultOr<size_t> recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||
virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t) override;
|
||||
virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
|
||||
|
|
|
@ -260,7 +260,7 @@ bool LocalSocket::can_write(const FileDescription& description, size_t) const
|
|||
return false;
|
||||
}
|
||||
|
||||
KResultOr<size_t> LocalSocket::sendto(FileDescription& description, const void* data, size_t data_size, int, const sockaddr*, socklen_t)
|
||||
KResultOr<size_t> LocalSocket::sendto(FileDescription& description, const void* data, size_t data_size, int, Userspace<const sockaddr*>, socklen_t)
|
||||
{
|
||||
if (!has_attached_peer(description))
|
||||
return KResult(-EPIPE);
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
virtual void detach(FileDescription&) override;
|
||||
virtual bool can_read(const FileDescription&, size_t) const override;
|
||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int, Userspace<const sockaddr*>, socklen_t) override;
|
||||
virtual KResultOr<size_t> recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||
virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override;
|
||||
virtual KResult chown(FileDescription&, uid_t, gid_t) override;
|
||||
|
|
|
@ -202,7 +202,7 @@ KResultOr<size_t> Socket::write(FileDescription& description, size_t, const u8*
|
|||
{
|
||||
if (is_shut_down_for_writing())
|
||||
return -EPIPE;
|
||||
return sendto(description, data, size, 0, nullptr, 0);
|
||||
return sendto(description, data, size, 0, {}, 0);
|
||||
}
|
||||
|
||||
KResult Socket::shutdown(int how)
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
virtual bool is_ipv4() const { return false; }
|
||||
virtual void attach(FileDescription&) = 0;
|
||||
virtual void detach(FileDescription&) = 0;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int flags, const sockaddr*, socklen_t) = 0;
|
||||
virtual KResultOr<size_t> sendto(FileDescription&, const void*, size_t, int flags, Userspace<const sockaddr*>, socklen_t) = 0;
|
||||
virtual KResultOr<size_t> recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) = 0;
|
||||
|
||||
virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t);
|
||||
|
|
|
@ -295,7 +295,7 @@ public:
|
|||
int sys$accept(int sockfd, Userspace<sockaddr*>, Userspace<socklen_t*>);
|
||||
int sys$connect(int sockfd, Userspace<const sockaddr*>, socklen_t);
|
||||
int sys$shutdown(int sockfd, int how);
|
||||
ssize_t sys$sendto(const Syscall::SC_sendto_params*);
|
||||
ssize_t sys$sendto(Userspace<const Syscall::SC_sendto_params*>);
|
||||
ssize_t sys$recvfrom(const Syscall::SC_recvfrom_params*);
|
||||
int sys$getsockopt(Userspace<const Syscall::SC_getsockopt_params*>);
|
||||
int sys$setsockopt(Userspace<const Syscall::SC_setsockopt_params*>);
|
||||
|
|
|
@ -188,7 +188,7 @@ int Process::sys$shutdown(int sockfd, int how)
|
|||
return socket.shutdown(how);
|
||||
}
|
||||
|
||||
ssize_t Process::sys$sendto(const Syscall::SC_sendto_params* user_params)
|
||||
ssize_t Process::sys$sendto(Userspace<const Syscall::SC_sendto_params*> user_params)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
Syscall::SC_sendto_params params;
|
||||
|
@ -196,7 +196,7 @@ ssize_t Process::sys$sendto(const Syscall::SC_sendto_params* user_params)
|
|||
return -EFAULT;
|
||||
|
||||
int flags = params.flags;
|
||||
const sockaddr* addr = params.addr;
|
||||
Userspace<const sockaddr*> addr = params.addr;
|
||||
socklen_t addr_length = params.addr_length;
|
||||
|
||||
if (!validate(params.data))
|
||||
|
|
Loading…
Add table
Reference in a new issue