mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-24 19:21:52 +00:00
Kernel: Use Userspace<T> for the getsockopt syscall and Socket interface
The way getsockopt is implemented for socket types requires us to push down Userspace<T> using into those interfaces. This change does so, and utilizes proper copy implementations instead of the kind of haphazard pointer dereferencing that was occurring there before.
This commit is contained in:
parent
6920d5f423
commit
30b2c0dc85
Notes:
sideshowbarker
2024-07-19 04:09:46 +09:00
Author: https://github.com/bgianfo
Commit: 30b2c0dc85
Pull-request: https://github.com/SerenityOS/serenity/pull/3039
9 changed files with 69 additions and 43 deletions
|
@ -451,16 +451,22 @@ KResult IPv4Socket::setsockopt(int level, int option, Userspace<const void*> use
|
|||
}
|
||||
}
|
||||
|
||||
KResult IPv4Socket::getsockopt(FileDescription& description, int level, int option, void* value, socklen_t* value_size)
|
||||
KResult IPv4Socket::getsockopt(FileDescription& description, int level, int option, Userspace<void*> value, Userspace<socklen_t*> value_size)
|
||||
{
|
||||
if (level != IPPROTO_IP)
|
||||
return Socket::getsockopt(description, level, option, value, value_size);
|
||||
|
||||
socklen_t size;
|
||||
if (!Process::current()->validate_read_and_copy_typed(&size, value_size))
|
||||
return KResult(-EFAULT);
|
||||
|
||||
switch (option) {
|
||||
case IP_TTL:
|
||||
if (*value_size < sizeof(int))
|
||||
if (size < sizeof(int))
|
||||
return KResult(-EINVAL);
|
||||
*(int*)value = m_ttl;
|
||||
copy_to_user(static_ptr_cast<int*>(value), (int*)&m_ttl);
|
||||
size = sizeof(int);
|
||||
copy_to_user(value_size, &size);
|
||||
return KSuccess;
|
||||
default:
|
||||
return KResult(-ENOPROTOOPT);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue