Skip to content

Commit

Permalink
Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Browse files Browse the repository at this point in the history
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
  • Loading branch information
ADKaster authored and linusg committed Oct 10, 2022
1 parent 896d4e8 commit 8284418
Show file tree
Hide file tree
Showing 46 changed files with 118 additions and 113 deletions.
2 changes: 1 addition & 1 deletion AK/BumpAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BumpAllocator {
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);
Expand Down
4 changes: 2 additions & 2 deletions AK/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -86,7 +86,7 @@ class [[nodiscard]] ErrorOr {
{
}

#ifdef __serenity__
#ifdef AK_OS_SERENITY
ErrorOr(ErrnoCode code)
: m_value_or_error(Error::from_errno(code))
{
Expand Down
10 changes: 5 additions & 5 deletions AK/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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());
Expand All @@ -930,7 +930,7 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params)
{
StringBuilder builder;

# ifdef __serenity__
# ifdef AK_OS_SERENITY
struct timespec ts = {};

# if !ARCH(AARCH64)
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion AK/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions AK/NoAllocationGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NoAllocationGuard {
{
#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
Expand All @@ -51,7 +51,7 @@ class NoAllocationGuard {
{
#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;
Expand Down
2 changes: 1 addition & 1 deletion AK/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion AK/PrintfImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions AK/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion AK/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions AK/StackInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion AK/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
5 changes: 3 additions & 2 deletions AK/kmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion AK/kmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <AK/Checked.h>
#include <AK/Platform.h>

#if defined(KERNEL)
# include <Kernel/Heap/kmalloc.h>
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion AK/kstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#pragma once

#ifdef __serenity__
#include <AK/Platform.h>

#ifdef AK_OS_SERENITY
# ifdef KERNEL
# include <Kernel/kstdio.h>
# else
Expand Down
2 changes: 1 addition & 1 deletion Kernel/API/Syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ enum Function {
__Count
};

#ifdef __serenity__
#ifdef AK_OS_SERENITY
struct StringArgument {
char const* characters;
size_t length { 0 };
Expand Down
4 changes: 2 additions & 2 deletions Tests/LibCompress/TestBrotli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Tests/LibGL/TestRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Tests/LibJS/test262-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Spreadsheet/test-spreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions Userland/Libraries/LibCore/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,7 +160,7 @@ class InspectorServerConnection : public Object {
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) });
Expand Down Expand Up @@ -236,7 +236,7 @@ class InspectorServerConnection : public Object {
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);
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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());
Expand Down
9 changes: 5 additions & 4 deletions Userland/Libraries/LibCore/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/FileWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibCore/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <errno.h>
#include <spawn.h>

#ifdef __serenity__
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 8284418

Please sign in to comment.