2020-07-30 21:38:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-08-29 11:57:14 +00:00
|
|
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2020-07-30 21:38:15 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
2022-08-29 11:57:14 +00:00
|
|
|
#include <AK/TypedTransfer.h>
|
2023-02-24 17:45:37 +00:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2022-08-29 11:57:14 +00:00
|
|
|
#include <Kernel/Version.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2023-07-08 02:48:11 +00:00
|
|
|
#if ARCH(X86_64)
|
|
|
|
# define UNAME_MACHINE "x86_64"
|
|
|
|
#elif ARCH(AARCH64)
|
|
|
|
# define UNAME_MACHINE "AArch64"
|
2023-11-02 22:21:09 +00:00
|
|
|
#elif ARCH(RISCV64)
|
|
|
|
# define UNAME_MACHINE "riscv64"
|
2023-07-08 02:48:11 +00:00
|
|
|
#else
|
|
|
|
# error Unknown architecture
|
|
|
|
#endif
|
|
|
|
|
2023-07-20 18:34:15 +00:00
|
|
|
KString* g_version_string { nullptr };
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2020-08-09 20:02:27 +00:00
|
|
|
|
2023-07-08 02:48:11 +00:00
|
|
|
utsname buf {
|
2022-08-29 11:57:14 +00:00
|
|
|
"SerenityOS",
|
2023-07-08 02:48:11 +00:00
|
|
|
{}, // Hostname, filled in below.
|
|
|
|
{}, // "Release" (1.0-dev), filled in below.
|
|
|
|
{}, // "Revision" (git commit hash), filled in below.
|
|
|
|
UNAME_MACHINE
|
2022-08-29 11:57:14 +00:00
|
|
|
};
|
|
|
|
|
2023-07-20 18:34:15 +00:00
|
|
|
VERIFY(g_version_string);
|
|
|
|
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.release), g_version_string->bytes().data(), min(g_version_string->length(), UTSNAME_ENTRY_LEN - 1));
|
2022-08-29 11:57:14 +00:00
|
|
|
|
|
|
|
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.version), SERENITY_VERSION.bytes().data(), min(SERENITY_VERSION.length(), UTSNAME_ENTRY_LEN - 1));
|
2021-06-29 17:19:35 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
hostname().with_shared([&](auto const& name) {
|
2023-07-17 16:22:01 +00:00
|
|
|
auto name_length = name.representable_view().length();
|
|
|
|
VERIFY(name_length <= (UTSNAME_ENTRY_LEN - 1));
|
|
|
|
AK::TypedTransfer<char>::copy(reinterpret_cast<char*>(buf.nodename), name.representable_view().characters_without_null_termination(), name_length);
|
|
|
|
buf.nodename[name_length] = '\0';
|
2021-07-18 13:00:48 +00:00
|
|
|
});
|
2021-02-24 13:33:50 +00:00
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
TRY(copy_to_user(user_buf, &buf));
|
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|