1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

Kernel: Use Userspace<T> for the uname syscall

This commit is contained in:
Brian Gianforcaro 2020-08-09 13:02:27 -07:00 committed by Andreas Kling
parent cfedd62b5c
commit 8dd78201a4
2 changed files with 13 additions and 7 deletions

View file

@ -28,7 +28,7 @@
namespace Kernel {
int Process::sys$uname(utsname* buf)
int Process::sys$uname(Userspace<utsname*> buf)
{
extern String* g_hostname;
extern Lock* g_hostname_lock;
@ -36,14 +36,20 @@ int Process::sys$uname(utsname* buf)
REQUIRE_PROMISE(stdio);
if (!validate_write_typed(buf))
return -EFAULT;
LOCKER(*g_hostname_lock, Lock::Mode::Shared);
if (g_hostname->length() + 1 > sizeof(utsname::nodename))
return -ENAMETOOLONG;
copy_to_user(buf->sysname, "SerenityOS", 11);
copy_to_user(buf->release, "1.0-dev", 8);
copy_to_user(buf->version, "FIXME", 6);
copy_to_user(buf->machine, "i686", 5);
copy_to_user(buf->nodename, g_hostname->characters(), g_hostname->length() + 1);
// We have already validated the entire utsname struct at this
// point, there is no need to re-validate every write to the struct.
utsname* user_buf = buf.unsafe_userspace_ptr();
copy_to_user(user_buf->sysname, "SerenityOS", 11);
copy_to_user(user_buf->release, "1.0-dev", 8);
copy_to_user(user_buf->version, "FIXME", 6);
copy_to_user(user_buf->machine, "i686", 5);
copy_to_user(user_buf->nodename, g_hostname->characters(), g_hostname->length() + 1);
return 0;
}