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>
|
2020-07-30 21:38:15 +00:00
|
|
|
#include <Kernel/Process.h>
|
2022-08-29 11:57:14 +00:00
|
|
|
#include <Kernel/Version.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
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
|
|
|
|
2022-08-29 11:57:14 +00:00
|
|
|
utsname buf
|
|
|
|
{
|
|
|
|
"SerenityOS",
|
|
|
|
{}, // Hostname, filled in below.
|
|
|
|
{}, // "Release" (1.0-dev), filled in below.
|
|
|
|
{}, // "Revision" (git commit hash), filled in below.
|
2022-10-04 00:05:54 +00:00
|
|
|
#if ARCH(X86_64)
|
2022-08-29 11:57:14 +00:00
|
|
|
"x86_64",
|
2022-07-22 18:48:24 +00:00
|
|
|
#elif ARCH(AARCH64)
|
2022-08-29 11:57:14 +00:00
|
|
|
"AArch64",
|
2022-07-22 18:48:24 +00:00
|
|
|
#else
|
|
|
|
# error Unknown architecture
|
2021-06-29 17:19:35 +00:00
|
|
|
#endif
|
2022-08-29 11:57:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto version_string = TRY(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION));
|
|
|
|
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.release), version_string->bytes().data(), min(version_string->length(), UTSNAME_ENTRY_LEN - 1));
|
|
|
|
|
|
|
|
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) {
|
2022-01-12 22:30:58 +00:00
|
|
|
auto length = min(name->length(), UTSNAME_ENTRY_LEN - 1);
|
2022-08-29 11:55:55 +00:00
|
|
|
AK::TypedTransfer<char>::copy(reinterpret_cast<char*>(buf.nodename), name->characters(), length);
|
2022-01-12 22:30:58 +00:00
|
|
|
buf.nodename[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
|
|
|
}
|
|
|
|
|
|
|
|
}
|