mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
c911781c21
This is a new option in clang-format-16.
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/TypedTransfer.h>
|
|
#include <Kernel/Tasks/Process.h>
|
|
#include <Kernel/Version.h>
|
|
|
|
namespace Kernel {
|
|
|
|
#if ARCH(X86_64)
|
|
# define UNAME_MACHINE "x86_64"
|
|
#elif ARCH(AARCH64)
|
|
# define UNAME_MACHINE "AArch64"
|
|
#else
|
|
# error Unknown architecture
|
|
#endif
|
|
|
|
ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
|
|
{
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
|
|
utsname buf {
|
|
"SerenityOS",
|
|
{}, // Hostname, filled in below.
|
|
{}, // "Release" (1.0-dev), filled in below.
|
|
{}, // "Revision" (git commit hash), filled in below.
|
|
UNAME_MACHINE
|
|
};
|
|
|
|
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));
|
|
|
|
hostname().with_shared([&](auto const& name) {
|
|
auto length = min(name->length(), UTSNAME_ENTRY_LEN - 1);
|
|
AK::TypedTransfer<char>::copy(reinterpret_cast<char*>(buf.nodename), name->characters(), length);
|
|
buf.nodename[length] = '\0';
|
|
});
|
|
|
|
TRY(copy_to_user(user_buf, &buf));
|
|
return 0;
|
|
}
|
|
|
|
}
|