Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#include <AK/TypedTransfer.h>
9#include <Kernel/Process.h>
10#include <Kernel/Version.h>
11
12namespace Kernel {
13
14ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
15{
16 VERIFY_NO_PROCESS_BIG_LOCK(this);
17 TRY(require_promise(Pledge::stdio));
18
19 utsname buf
20 {
21 "SerenityOS",
22 {}, // Hostname, filled in below.
23 {}, // "Release" (1.0-dev), filled in below.
24 {}, // "Revision" (git commit hash), filled in below.
25#if ARCH(X86_64)
26 "x86_64",
27#elif ARCH(AARCH64)
28 "AArch64",
29#else
30# error Unknown architecture
31#endif
32 };
33
34 auto version_string = TRY(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION));
35 AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.release), version_string->bytes().data(), min(version_string->length(), UTSNAME_ENTRY_LEN - 1));
36
37 AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.version), SERENITY_VERSION.bytes().data(), min(SERENITY_VERSION.length(), UTSNAME_ENTRY_LEN - 1));
38
39 hostname().with_shared([&](auto const& name) {
40 auto length = min(name->length(), UTSNAME_ENTRY_LEN - 1);
41 AK::TypedTransfer<char>::copy(reinterpret_cast<char*>(buf.nodename), name->characters(), length);
42 buf.nodename[length] = '\0';
43 });
44
45 TRY(copy_to_user(user_buf, &buf));
46 return 0;
47}
48
49}