Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY

Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
This commit is contained in:
Andrew Kaster 2022-10-09 15:23:23 -06:00 committed by Linus Groh
parent 896d4e8dc1
commit 828441852f
Notes: sideshowbarker 2024-07-17 06:06:27 +09:00
46 changed files with 118 additions and 113 deletions

View file

@ -103,7 +103,7 @@ protected:
void* new_chunk = (void*)s_unused_allocation_cache.exchange(0);
if (!new_chunk) {
if constexpr (use_mmap) {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
new_chunk = serenity_mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RANDOMIZED | MAP_PRIVATE, 0, 0, m_chunk_size, "BumpAllocator Chunk");
#else
new_chunk = mmap(nullptr, m_chunk_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

View file

@ -10,7 +10,7 @@
#include <AK/Try.h>
#include <AK/Variant.h>
#if defined(__serenity__) && defined(KERNEL)
#if defined(AK_OS_SERENITY) && defined(KERNEL)
# include <LibC/errno_codes.h>
#else
# include <errno.h>
@ -86,7 +86,7 @@ public:
{
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr(ErrnoCode code)
: m_value_or_error(Error::from_errno(code))
{

View file

@ -11,7 +11,7 @@
#include <AK/StringBuilder.h>
#include <AK/kstdio.h>
#if defined(__serenity__) && !defined(KERNEL)
#if defined(AK_OS_SERENITY) && !defined(KERNEL)
# include <serenity.h>
#endif
@ -877,7 +877,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams& params)
StringBuilder builder;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# ifdef KERNEL
if (Kernel::Processor::is_initialized()) {
struct timespec ts = {};
@ -914,7 +914,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams& params)
auto const string = builder.string_view();
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# ifdef KERNEL
if (!Kernel::Processor::is_initialized()) {
kernelearlyputstr(string.characters_without_null_termination(), string.length());
@ -930,7 +930,7 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params)
{
StringBuilder builder;
# ifdef __serenity__
# ifdef AK_OS_SERENITY
struct timespec ts = {};
# if !ARCH(AARCH64)
@ -959,7 +959,7 @@ void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams& params)
// at OOM conditions.
StringBuilder builder;
# ifdef __serenity__
# ifdef AK_OS_SERENITY
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
auto& thread = *Kernel::Thread::current();
builder.appendff("[{}({}:{})]: ", thread.process().name(), thread.pid().value(), thread.tid().value());

View file

@ -671,7 +671,7 @@ template<>
struct Formatter<Error> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
{
#if defined(__serenity__) && defined(KERNEL)
#if defined(AK_OS_SERENITY) && defined(KERNEL)
if (error.is_errno())
return Formatter<FormatString>::format(builder, "Error(errno={})"sv, error.code());
return Formatter<FormatString>::format(builder, "Error({})"sv, error.string_literal());

View file

@ -39,7 +39,7 @@ private:
{
#if defined(KERNEL)
return Processor::current_thread()->get_allocation_enabled();
#elif defined(__serenity__)
#elif defined(AK_OS_SERENITY)
// This extern thread-local lives in our LibC, which doesn't exist on other systems.
return s_allocation_enabled;
#else
@ -51,7 +51,7 @@ private:
{
#if defined(KERNEL)
Processor::current_thread()->set_allocation_enabled(value);
#elif defined(__serenity__)
#elif defined(AK_OS_SERENITY)
s_allocation_enabled = value;
#else
(void)value;

View file

@ -148,7 +148,7 @@
# define ASAN_UNPOISON_MEMORY_REGION(addr, size)
#endif
#ifndef __serenity__
#ifndef AK_OS_SERENITY
// On macOS (at least Mojave), Apple's version of this header is not wrapped
// in extern "C".
# ifdef AK_OS_MACOS

View file

@ -16,7 +16,7 @@
# include <math.h>
#endif
#ifdef __serenity__
#ifdef AK_OS_SERENITY
extern "C" size_t strlen(char const*);
#else
# include <string.h>

View file

@ -9,7 +9,7 @@
#include <AK/Platform.h>
#include <AK/Types.h>
#if defined(__serenity__) || defined(AK_OS_ANDROID)
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
# include <stdlib.h>
#endif
@ -30,7 +30,7 @@ namespace AK {
inline void fill_with_random([[maybe_unused]] void* buffer, [[maybe_unused]] size_t length)
{
#if defined(__serenity__) || defined(AK_OS_ANDROID)
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
arc4random_buf(buffer, length);
#elif defined(OSS_FUZZ)
#elif defined(__unix__) or defined(AK_OS_MACOS)

View file

@ -23,7 +23,7 @@ extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
# include <sched.h>
#endif
#ifndef __serenity__
#ifndef AK_OS_SERENITY
# include <new>
#endif

View file

@ -10,7 +10,7 @@
#include <stdio.h>
#include <string.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#elif defined(__linux__) or defined(AK_OS_MACOS)
# include <pthread.h>
@ -23,7 +23,7 @@ namespace AK {
StackInfo::StackInfo()
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (get_stack_bounds(&m_base, &m_size) < 0) {
perror("get_stack_bounds");
VERIFY_NOT_REACHED();

View file

@ -19,7 +19,7 @@ using i32 = __INT32_TYPE__;
using i16 = __INT16_TYPE__;
using i8 = __INT8_TYPE__;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
using size_t = __SIZE_TYPE__;
using ssize_t = MakeSigned<size_t>;

View file

@ -5,10 +5,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#if defined(__serenity__) && !defined(KERNEL)
#include <AK/kmalloc.h>
#if defined(AK_OS_SERENITY) && !defined(KERNEL)
# include <AK/Assertions.h>
# include <AK/kmalloc.h>
// However deceptively simple these functions look, they must not be inlined.
// Memory allocated in one translation unit has to be deallocatable in another

View file

@ -8,6 +8,7 @@
#pragma once
#include <AK/Checked.h>
#include <AK/Platform.h>
#if defined(KERNEL)
# include <Kernel/Heap/kmalloc.h>
@ -25,7 +26,7 @@ inline void kfree_sized(void* ptr, size_t)
}
#endif
#ifndef __serenity__
#ifndef AK_OS_SERENITY
# include <AK/Types.h>
# ifndef AK_OS_MACOS

View file

@ -6,7 +6,9 @@
#pragma once
#ifdef __serenity__
#include <AK/Platform.h>
#ifdef AK_OS_SERENITY
# ifdef KERNEL
# include <Kernel/kstdio.h>
# else

View file

@ -204,7 +204,7 @@ enum Function {
__Count
};
#ifdef __serenity__
#ifdef AK_OS_SERENITY
struct StringArgument {
char const* characters;
size_t length { 0 };

View file

@ -12,7 +12,7 @@
static void run_test(StringView const file_name)
{
// This makes sure that the tests will run both on target and in Lagom.
#ifdef __serenity__
#ifdef AK_OS_SERENITY
String path = String::formatted("/usr/Tests/LibCompress/brotli-test-files/{}", file_name);
#else
String path = String::formatted("brotli-test-files/{}", file_name);
@ -83,7 +83,7 @@ TEST_CASE(brotli_single_z)
TEST_CASE(brotli_decompress_zero_one_bin)
{
// This makes sure that the tests will run both on target and in Lagom.
#ifdef __serenity__
#ifdef AK_OS_SERENITY
String path = "/usr/Tests/LibCompress/brotli-test-files/zero-one.bin";
#else
String path = "brotli-test-files/zero-one.bin";

View file

@ -14,7 +14,7 @@
#include <LibGfx/QOIWriter.h>
#include <LibTest/TestCase.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# define REFERENCE_IMAGE_DIR "/usr/Tests/LibGL/reference-images"
#else
# define REFERENCE_IMAGE_DIR "reference-images"

View file

@ -544,7 +544,7 @@ static bool g_in_assert = false;
exit(12);
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
void __assertion_failed(char const* assertion)
{
handle_failed_assert(assertion);

View file

@ -9,7 +9,7 @@
TEST_ROOT("Userland/Applications/Spreadsheet/Tests");
#ifdef __serenity__
#ifdef AK_OS_SERENITY
static constexpr auto s_spreadsheet_runtime_path = "/res/js/Spreadsheet/runtime.js"sv;
#else
static constexpr auto s_spreadsheet_runtime_path = "../../../../Base/res/js/Spreadsheet/runtime.js"sv;
@ -32,7 +32,7 @@ TESTJS_RUN_FILE_FUNCTION(String const&, JS::Interpreter& interpreter, JS::Execut
interpreter.vm().pop_execution_context();
};
#ifdef __serenity__
#ifdef AK_OS_SERENITY
run_file(s_spreadsheet_runtime_path);
#else
run_file(LexicalPath::join(Test::JS::g_test_root, s_spreadsheet_runtime_path).string());

View file

@ -16,7 +16,7 @@
namespace Core {
// Only supported in serenity mode because we use `posix_spawn_file_actions_addchdir`
#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr<CommandResult> command(String const& command_string, Optional<LexicalPath> chdir)
{

View file

@ -36,7 +36,7 @@
#include <time.h>
#include <unistd.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <LibCore/Account.h>
extern bool s_global_initializers_ran;
@ -160,7 +160,7 @@ private:
return allocator->allocate();
}))
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
m_socket->on_ready_to_read = [this] {
u32 length;
auto maybe_bytes_read = m_socket->read({ (u8*)&length, sizeof(length) });
@ -236,7 +236,7 @@ public:
JsonObject response;
response.set("type", type);
response.set("pid", getpid());
#ifdef __serenity__
#ifdef AK_OS_SERENITY
char buffer[1024];
if (get_process_name(buffer, sizeof(buffer)) >= 0) {
response.set("process_name", buffer);
@ -312,7 +312,7 @@ EventLoop::EventLoop([[maybe_unused]] MakeInspectable make_inspectable)
: m_wake_pipe_fds(&s_wake_pipe_fds)
, m_private(make<Private>())
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (!s_global_initializers_ran) {
// NOTE: Trying to have an event loop as a global variable will lead to initialization-order fiascos,
// as the event loop constructor accesses and/or sets other global variables.
@ -334,7 +334,7 @@ EventLoop::EventLoop([[maybe_unused]] MakeInspectable make_inspectable)
s_pid = getpid();
s_event_loop_stack->append(*this);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (getuid() != 0) {
if (getenv("MAKE_INSPECTABLE") == "1"sv)
make_inspectable = Core::EventLoop::MakeInspectable::Yes;
@ -361,7 +361,7 @@ EventLoop::~EventLoop()
bool connect_to_inspector_server()
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto maybe_path = SessionManagement::parse_path_with_sid("/tmp/session/%sid/portal/inspectables"sv);
if (maybe_path.is_error()) {
dbgln("connect_to_inspector_server: {}", maybe_path.error());

View file

@ -4,9 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#ifdef __serenity__
# include <serenity.h>
#endif
#include <AK/LexicalPath.h>
#include <AK/ScopeGuard.h>
#include <LibCore/DirIterator.h>
@ -20,6 +17,10 @@
#include <unistd.h>
#include <utime.h>
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
// On Linux distros that use glibc `basename` is defined as a macro that expands to `__xpg_basename`, so we undefine it
#if defined(__linux__) && defined(basename)
# undef basename
@ -241,7 +242,7 @@ String File::absolute_path(String const& path)
return LexicalPath::canonicalized_path(full_path.string());
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr<String> File::read_link(String const& link_path)
{

View file

@ -21,7 +21,7 @@
namespace Core {
// Only supported in serenity mode because we use InodeWatcher syscalls
#ifdef __serenity__
#ifdef AK_OS_SERENITY
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, String> const& wd_to_path)
{

View file

@ -12,7 +12,7 @@
#include <errno.h>
#include <spawn.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
@ -46,7 +46,7 @@ struct ArgvList {
ErrorOr<pid_t> spawn()
{
auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast<char**>(get().data()), environ));
#ifdef __serenity__
#ifdef AK_OS_SERENITY
TRY(System::disown(pid));
#endif
return pid;

View file

@ -14,7 +14,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
#ifdef __FreeBSD__

View file

@ -25,7 +25,7 @@
#include <termios.h>
#include <unistd.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <LibCore/Account.h>
# include <LibSystem/syscall.h>
# include <serenity.h>
@ -61,7 +61,7 @@ namespace Core::System {
# endif
#endif
#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr<void> beep()
{
@ -256,7 +256,7 @@ ErrorOr<int> fcntl(int fd, int command, ...)
ErrorOr<void*> mmap(void* address, size_t size, int protection, int flags, int fd, off_t offset, [[maybe_unused]] size_t alignment, [[maybe_unused]] StringView name)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_mmap_params params { address, size, alignment, protection, flags, fd, offset, { name.characters_without_null_termination(), name.length() } };
ptrdiff_t rc = syscall(SC_mmap, &params);
if (rc < 0 && rc > -EMAXERRNO)
@ -282,7 +282,7 @@ ErrorOr<void> munmap(void* address, size_t size)
ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int options)
{
int fd = -1;
#if defined(__serenity__)
#if defined(AK_OS_SERENITY)
fd = ::anon_create(round_up_to_power_of_two(size, PAGE_SIZE), options);
#elif defined(__linux__) || defined(__FreeBSD__)
// FIXME: Support more options on Linux.
@ -337,7 +337,7 @@ ErrorOr<int> openat(int fd, StringView path, int options, mode_t mode)
{
if (!path.characters_without_null_termination())
return Error::from_syscall("open"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_open_params params { fd, { path.characters_without_null_termination(), path.length() }, options, mode };
int rc = syscall(SC_open, &params);
HANDLE_SYSCALL_RETURN_VALUE("open", rc, rc);
@ -371,7 +371,7 @@ ErrorOr<struct stat> stat(StringView path)
return Error::from_syscall("stat"sv, -EFAULT);
struct stat st = {};
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, AT_FDCWD, true };
int rc = syscall(SC_stat, &params);
HANDLE_SYSCALL_RETURN_VALUE("stat", rc, st);
@ -389,7 +389,7 @@ ErrorOr<struct stat> lstat(StringView path)
return Error::from_syscall("lstat"sv, -EFAULT);
struct stat st = {};
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, AT_FDCWD, false };
int rc = syscall(SC_stat, &params);
HANDLE_SYSCALL_RETURN_VALUE("lstat", rc, st);
@ -522,7 +522,7 @@ ErrorOr<void> chmod(StringView pathname, mode_t mode)
if (!pathname.characters_without_null_termination())
return Error::from_syscall("chmod"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_chmod_params params {
AT_FDCWD,
{ pathname.characters_without_null_termination(), pathname.length() },
@ -558,7 +558,7 @@ ErrorOr<void> lchown(StringView pathname, uid_t uid, gid_t gid)
if (!pathname.characters_without_null_termination())
return Error::from_syscall("chown"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid, AT_FDCWD, false };
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {});
@ -575,7 +575,7 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
if (!pathname.characters_without_null_termination())
return Error::from_syscall("chown"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid, AT_FDCWD, true };
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {});
@ -649,7 +649,7 @@ ErrorOr<Optional<struct group>> getgrnam(StringView name)
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_clock_settime, clock_id, ts);
HANDLE_SYSCALL_RETURN_VALUE("clocksettime", rc, {});
#else
@ -777,7 +777,7 @@ ErrorOr<bool> isatty(int fd)
ErrorOr<void> link(StringView old_path, StringView new_path)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_link_params params {
.old_path = { old_path.characters_without_null_termination(), old_path.length() },
.new_path = { new_path.characters_without_null_termination(), new_path.length() },
@ -795,7 +795,7 @@ ErrorOr<void> link(StringView old_path, StringView new_path)
ErrorOr<void> symlink(StringView target, StringView link_path)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_symlink_params params {
.target = { target.characters_without_null_termination(), target.length() },
.linkpath = { link_path.characters_without_null_termination(), link_path.length() },
@ -815,7 +815,7 @@ ErrorOr<void> mkdir(StringView path, mode_t mode)
{
if (path.is_null())
return Error::from_errno(EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_mkdir, path.characters_without_null_termination(), path.length(), mode);
HANDLE_SYSCALL_RETURN_VALUE("mkdir", rc, {});
#else
@ -830,7 +830,7 @@ ErrorOr<void> chdir(StringView path)
{
if (path.is_null())
return Error::from_errno(EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_chdir, path.characters_without_null_termination(), path.length());
HANDLE_SYSCALL_RETURN_VALUE("chdir", rc, {});
#else
@ -845,7 +845,7 @@ ErrorOr<void> rmdir(StringView path)
{
if (path.is_null())
return Error::from_errno(EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_rmdir, path.characters_without_null_termination(), path.length());
HANDLE_SYSCALL_RETURN_VALUE("rmdir", rc, {});
#else
@ -877,7 +877,7 @@ ErrorOr<void> rename(StringView old_path, StringView new_path)
if (old_path.is_null() || new_path.is_null())
return Error::from_errno(EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_rename_params params {
.old_path = { old_path.characters_without_null_termination(), old_path.length() },
.new_path = { new_path.characters_without_null_termination(), new_path.length() },
@ -898,7 +898,7 @@ ErrorOr<void> unlink(StringView path)
if (path.is_null())
return Error::from_errno(EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_unlink, AT_FDCWD, path.characters_without_null_termination(), path.length(), 0);
HANDLE_SYSCALL_RETURN_VALUE("unlink", rc, {});
#else
@ -917,7 +917,7 @@ ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
struct utimbuf* buf = nullptr;
if (maybe_buf.has_value())
buf = &maybe_buf.value();
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_utime, path.characters_without_null_termination(), path.length(), buf);
HANDLE_SYSCALL_RETURN_VALUE("utime", rc, {});
#else
@ -931,7 +931,7 @@ ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
ErrorOr<struct utsname> uname()
{
utsname uts;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = syscall(SC_uname, &uts);
HANDLE_SYSCALL_RETURN_VALUE("uname", rc, uts);
#else
@ -944,7 +944,7 @@ ErrorOr<struct utsname> uname()
#ifndef AK_OS_ANDROID
ErrorOr<void> adjtime(const struct timeval* delta, struct timeval* old_delta)
{
# ifdef __serenity__
# ifdef AK_OS_SERENITY
int rc = syscall(SC_adjtime, delta, old_delta);
HANDLE_SYSCALL_RETURN_VALUE("adjtime", rc, {});
# else
@ -957,7 +957,7 @@ ErrorOr<void> adjtime(const struct timeval* delta, struct timeval* old_delta)
ErrorOr<void> exec(StringView filename, Span<StringView> arguments, SearchInPath search_in_path, Optional<Span<StringView>> environment)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_execve_params params;
auto argument_strings = TRY(FixedArray<Syscall::StringArgument>::try_create(arguments.size()));
@ -1231,7 +1231,7 @@ ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev)
if (pathname.is_null())
return Error::from_syscall("mknod"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
Syscall::SC_mknod_params params { { pathname.characters_without_null_termination(), pathname.length() }, mode, dev };
int rc = syscall(SC_mknod, &params);
HANDLE_SYSCALL_RETURN_VALUE("mknod", rc, {});
@ -1250,7 +1250,7 @@ ErrorOr<void> mkfifo(StringView pathname, mode_t mode)
ErrorOr<void> setenv(StringView name, StringView value, bool overwrite)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto const rc = ::serenity_setenv(name.characters_without_null_termination(), name.length(), value.characters_without_null_termination(), value.length(), overwrite);
#else
String name_string = name;
@ -1291,7 +1291,7 @@ ErrorOr<void> access(StringView pathname, int mode)
if (pathname.is_null())
return Error::from_syscall("access"sv, -EFAULT);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = ::syscall(Syscall::SC_access, pathname.characters_without_null_termination(), pathname.length(), mode);
HANDLE_SYSCALL_RETURN_VALUE("access", rc, {});
#else

View file

@ -32,7 +32,7 @@
namespace Core::System {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr<void> beep();
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
ErrorOr<void> unveil(StringView path, StringView permissions);

View file

@ -26,7 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
#ifndef __serenity__
#ifndef AK_OS_SERENITY
static void* mmap_with_name(void* addr, size_t length, int prot, int flags, int fd, off_t offset, char const*)
{
return mmap(addr, length, prot, flags, fd, offset);
@ -239,7 +239,7 @@ Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> DynamicLoader::load_stage_3
return DlErrorMessage { String::formatted("mprotect .relro: PROT_READ: {}", strerror(errno)) };
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (set_mmap_name(m_relro_segment_address.as_ptr(), m_relro_segment_size, String::formatted("{}: .relro", m_filepath).characters()) < 0) {
return DlErrorMessage { String::formatted("set_mmap_name .relro: {}", strerror(errno)) };
}

View file

@ -15,9 +15,9 @@ namespace GPU {
// FIXME: Think of a better way to configure these paths. Maybe use ConfigServer?
static HashMap<String, String> const s_driver_path_map
{
#if defined(__serenity__)
#if defined(AK_OS_SERENITY)
{ "softgpu", "libsoftgpu.so.serenity" },
#elif defined(__APPLE__)
#elif defined(AK_OS_MACOS)
{ "softgpu", "liblagom-softgpu.dylib" },
#else
{ "softgpu", "liblagom-softgpu.so.0" },

View file

@ -498,7 +498,7 @@ Bitmap::~Bitmap()
void Bitmap::set_mmap_name([[maybe_unused]] String const& name)
{
VERIFY(m_needs_munmap);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
::set_mmap_name(m_data, size_in_bytes(), name.characters());
#endif
}
@ -516,7 +516,7 @@ void Bitmap::set_volatile()
{
if (m_volatile)
return;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = madvise(m_data, size_in_bytes(), MADV_SET_VOLATILE);
if (rc < 0) {
perror("madvise(MADV_SET_VOLATILE)");
@ -533,7 +533,7 @@ void Bitmap::set_volatile()
return true;
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
int rc = madvise(m_data, size_in_bytes(), MADV_SET_NONVOLATILE);
if (rc < 0) {
if (errno == ENOMEM) {
@ -566,7 +566,7 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz
auto const data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor);
int map_flags = MAP_ANONYMOUS | MAP_PRIVATE;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
map_flags |= MAP_PURGEABLE;
void* data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::formatted("GraphicsBitmap [{}]", size).characters());
#else

View file

@ -429,7 +429,7 @@ MarkedVector<Value> Console::vm_arguments()
void Console::output_debug_message([[maybe_unused]] LogLevel log_level, [[maybe_unused]] String output) const
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
switch (log_level) {
case Console::LogLevel::Debug:
dbgln("\033[32;1m(js debug)\033[0m {}", output);

View file

@ -21,7 +21,7 @@ BlockAllocator::~BlockAllocator()
{
for (auto* block : m_blocks) {
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::block_size);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (munmap(block, HeapBlock::block_size) < 0) {
perror("munmap");
VERIFY_NOT_REACHED();
@ -39,7 +39,7 @@ void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
size_t random_index = get_random_uniform(m_blocks.size());
auto* block = m_blocks.unstable_take(random_index);
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::block_size);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (set_mmap_name(block, HeapBlock::block_size, name) < 0) {
perror("set_mmap_name");
VERIFY_NOT_REACHED();
@ -48,7 +48,7 @@ void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
return block;
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto* block = (HeapBlock*)serenity_mmap(nullptr, HeapBlock::block_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_RANDOMIZED | MAP_PRIVATE, 0, 0, HeapBlock::block_size, name);
VERIFY(block != MAP_FAILED);
#else
@ -62,7 +62,7 @@ void BlockAllocator::deallocate_block(void* block)
{
VERIFY(block);
if (m_blocks.size() >= max_cached_blocks) {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (munmap(block, HeapBlock::block_size) < 0) {
perror("munmap");
VERIFY_NOT_REACHED();

View file

@ -20,13 +20,13 @@
#include <LibJS/SafeFunction.h>
#include <setjmp.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
namespace JS {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
static int gc_perf_string_id;
#endif
@ -36,7 +36,7 @@ static __thread HashMap<FlatPtr*, size_t>* s_custom_ranges_for_conservative_scan
Heap::Heap(VM& vm)
: m_vm(vm)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto gc_signpost_string = "Garbage collection"sv;
gc_perf_string_id = perf_register_string(gc_signpost_string.characters_without_null_termination(), gc_signpost_string.length());
#endif
@ -91,7 +91,7 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report)
VERIFY(!m_collecting_garbage);
TemporaryChange change(m_collecting_garbage, true);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
static size_t global_gc_counter = 0;
perf_event(PERF_EVENT_SIGNPOST, gc_perf_string_id, global_gc_counter++);
#endif

View file

@ -20,7 +20,7 @@ namespace JS {
NonnullOwnPtr<HeapBlock> HeapBlock::create_with_cell_size(Heap& heap, size_t cell_size)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
char name[64];
snprintf(name, sizeof(name), "LibJS: HeapBlock(%zu)", cell_size);
#else

View file

@ -200,7 +200,7 @@ GlobalObject::~GlobalObject() = default;
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::gc)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
dbgln("Forced garbage collection requested!");
#endif
vm.heap().collect_garbage();

View file

@ -44,7 +44,7 @@ int main(int argc, char** argv)
if (result.is_error()) {
auto error = result.release_error();
warnln("\033[31;1mRuntime error\033[0m: {}", error);
#ifdef __serenity__
#ifdef AK_OS_SERENITY
dbgln("\033[31;1mExiting with runtime error\033[0m: {}", error);
#endif
return Main::return_code_for_errors();

View file

@ -8,7 +8,7 @@
#include <AK/String.h>
#include <AK/Types.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <bits/regex_defs.h>
#else
# include <LibC/bits/regex_defs.h>

View file

@ -8,7 +8,7 @@
#include <AK/Types.h>
#include <stdio.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <bits/regex_defs.h>
#else
# include <LibC/bits/regex_defs.h>

View file

@ -37,7 +37,7 @@
#include <sys/time.h>
#include <unistd.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
@ -292,7 +292,7 @@ inline JSFileResult TestRunner::run_file_test(String const& test_path)
{
g_currently_running_test = test_path;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto string_id = perf_register_string(test_path.characters(), test_path.length());
perf_event(PERF_EVENT_SIGNPOST, string_id, 0);
#endif
@ -499,7 +499,7 @@ inline void TestRunner::print_file_result(JSFileResult const& file_result) const
if (!file_result.logged_messages.is_empty()) {
print_modifiers({ FG_GRAY, FG_BOLD });
#ifdef __serenity__
#ifdef AK_OS_SERENITY
outln(" Console output:");
#else
// This emoji has a second invisible byte after it. The one above does not
@ -514,7 +514,7 @@ inline void TestRunner::print_file_result(JSFileResult const& file_result) const
auto test_error = file_result.error.value();
print_modifiers({ FG_RED });
#ifdef __serenity__
#ifdef AK_OS_SERENITY
outln(" ❌ The file failed to parse");
#else
// No invisible byte here, but the spacing still needs to be altered on the host
@ -541,14 +541,14 @@ inline void TestRunner::print_file_result(JSFileResult const& file_result) const
print_modifiers({ FG_GRAY, FG_BOLD });
if (failed) {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
out(" ❌ Suite: ");
#else
// No invisible byte here, but the spacing still needs to be altered on the host
out(" ❌ Suite: ");
#endif
} else {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
out(" ⚠ Suite: ");
#else
// This emoji has a second invisible byte after it. The one above does not

View file

@ -81,7 +81,7 @@ int main(int argc, char** argv)
bool print_times = false;
bool print_progress =
#ifdef __serenity__
#ifdef AK_OS_SERENITY
true; // Use OSC 9 to print progress
#else
false;
@ -140,7 +140,7 @@ int main(int argc, char** argv)
if (specified_test_root) {
test_root = String { specified_test_root };
} else {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
test_root = LexicalPath::join("/home/anon/Tests"sv, String::formatted("{}-tests", program_name.split_view('-').last())).string();
#else
char* serenity_source_dir = getenv("SERENITY_SOURCE_DIR");
@ -158,7 +158,7 @@ int main(int argc, char** argv)
}
if (common_path.is_empty()) {
#ifdef __serenity__
#ifdef AK_OS_SERENITY
common_path = "/home/anon/Tests/js-tests/test-common.js";
#else
char* serenity_source_dir = getenv("SERENITY_SOURCE_DIR");

View file

@ -24,7 +24,7 @@ public:
Mutex()
: m_lock_count(0)
{
#ifndef __serenity__
#ifndef AK_OS_SERENITY
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
@ -41,7 +41,7 @@ public:
void unlock();
private:
#ifdef __serenity__
#ifdef AK_OS_SERENITY
pthread_mutex_t m_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#else
pthread_mutex_t m_mutex;

View file

@ -101,7 +101,7 @@ StringView current_time_zone()
dbgln_if(TIME_ZONE_DEBUG, "Could not determine time zone from TZ environment: {}", time_zone);
}
#ifdef __serenity__
#ifdef AK_OS_SERENITY
return system_time_zone();
#else
static constexpr auto zoneinfo = "/zoneinfo/"sv;
@ -127,7 +127,7 @@ StringView current_time_zone()
ErrorOr<void> change_time_zone([[maybe_unused]] StringView time_zone)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
TimeZoneFile time_zone_file("w");
if (auto new_time_zone = canonicalize_time_zone(time_zone); new_time_zone.has_value())

View file

@ -18,7 +18,7 @@
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/Timer.h>
#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
@ -127,7 +127,7 @@ static String sanitized_url_for_logging(AK::URL const& url)
static void emit_signpost(String const& message, int id)
{
#ifdef __serenity__
#ifdef AK_OS_SERENITY
auto string_id = perf_register_string(message.characters(), message.length());
perf_event(PERF_EVENT_SIGNPOST, string_id, id);
#else

View file

@ -19,7 +19,7 @@ DOMTreeModel::DOMTreeModel(JsonObject dom_tree, GUI::TreeView* tree_view)
, m_dom_tree(move(dom_tree))
{
// FIXME: Get these from the outside somehow instead of hard-coding paths here.
#ifdef __serenity__
#ifdef AK_OS_SERENITY
m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png"sv).release_value_but_fixme_should_propagate_errors());
m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png"sv).release_value_but_fixme_should_propagate_errors());
m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png"sv).release_value_but_fixme_should_propagate_errors());
@ -123,7 +123,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
auto type = node.get("type"sv).as_string_or("unknown"sv);
// FIXME: This FIXME can go away when we fix the one below.
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (role == GUI::ModelRole::ForegroundColor) {
// FIXME: Allow models to return a foreground color *role*.
// Then we won't need to have a GUI::TreeView& member anymore.
@ -138,7 +138,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
#endif
// FIXME: This FIXME can go away when the icons are provided from the outside (see constructor).
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (role == GUI::ModelRole::Icon) {
if (type == "document")
return m_document_icon;

View file

@ -625,7 +625,7 @@ void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, Hi
Line::Style bold = { Line::Style::Bold };
Line::Style style = bold;
#ifdef __serenity__
#ifdef AK_OS_SERENITY
if (runnable->kind == Shell::RunnablePath::Kind::Executable || runnable->kind == Shell::RunnablePath::Kind::Alias) {
auto name = shell.help_path_for({}, *runnable);
if (name.has_value()) {

View file

@ -306,7 +306,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
#endif
bool print_progress =
#ifdef __serenity__
#ifdef AK_OS_SERENITY
true; // Use OSC 9 to print progress
#else
false;