Skip to content

Commit

Permalink
Everywhere: Remove all AK_OS_SERENITY preprocessor statements
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 committed Jul 4, 2024
1 parent ae983a2 commit 5a5c1d8
Show file tree
Hide file tree
Showing 33 changed files with 52 additions and 1,021 deletions.
8 changes: 2 additions & 6 deletions AK/Assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
# include <cxxabi.h>
#endif

#if defined(AK_OS_SERENITY)
# define ERRORLN dbgln
#else
# define ERRORLN warnln
#endif
#define ERRORLN warnln

#if defined(AK_HAS_BACKTRACE_HEADER)
namespace {
Expand Down Expand Up @@ -83,7 +79,7 @@ extern "C" {

void ak_verification_failed(char const* message)
{
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
#if defined(AK_OS_ANDROID)
bool colorize_output = true;
#elif defined(AK_OS_WINDOWS)
bool colorize_output = false;
Expand Down
4 changes: 0 additions & 4 deletions AK/BumpAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ class BumpAllocator {
void* new_chunk = reinterpret_cast<void*>(s_unused_allocation_cache.exchange(0));
if (!new_chunk) {
if constexpr (use_mmap) {
#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);
#endif
if (new_chunk == MAP_FAILED)
return false;
} else {
Expand Down
7 changes: 0 additions & 7 deletions AK/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ class [[nodiscard]] ErrorOr {
{
}

#ifdef AK_OS_SERENITY
ErrorOr(ErrnoCode code)
: m_value_or_error(Error::from_errno(code))
{
}
#endif

T& value()
{
return m_value_or_error.template get<T>();
Expand Down
24 changes: 4 additions & 20 deletions AK/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include <string.h>
#include <time.h>

#if defined(AK_OS_SERENITY)
# include <serenity.h>
#endif

#if defined(AK_OS_ANDROID)
# include <android/log.h>
#endif
Expand Down Expand Up @@ -1114,13 +1110,7 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params,
// FIXME: Deduplicate with Core::Process:get_name()
[[gnu::used]] static ByteString process_name_helper()
{
#if defined(AK_OS_SERENITY)
char buffer[BUFSIZ] = {};
int rc = get_process_name(buffer, BUFSIZ);
if (rc != 0)
return ByteString {};
return StringView { buffer, strlen(buffer) };
#elif defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
#if defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
return StringView { program_invocation_name, strlen(program_invocation_name) };
#elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU)
auto const* progname = getprogname();
Expand Down Expand Up @@ -1154,13 +1144,7 @@ void set_debug_enabled(bool value)
is_debug_enabled = value;
}

// On Serenity, dbgln goes to a non-stderr output
static bool is_rich_debug_enabled =
#if defined(AK_OS_SERENITY)
true;
#else
false;
#endif
static bool is_rich_debug_enabled = false;

void set_rich_debug_enabled(bool value)
{
Expand All @@ -1181,15 +1165,15 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline)
struct timespec ts = {};
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
auto pid = getpid();
# if defined(AK_OS_SERENITY) || defined(AK_OS_LINUX)
# if defined(AK_OS_LINUX)
// Linux and Serenity handle thread IDs as if they are related to process ids
auto tid = gettid();
if (pid == tid)
# endif
{
builder.appendff("{}.{:03} \033[33;1m{}({})\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000, process_name, pid);
}
# if defined(AK_OS_SERENITY) || defined(AK_OS_LINUX)
# if defined(AK_OS_LINUX)
else {
builder.appendff("{}.{:03} \033[33;1m{}({}:{})\033[0m: ", ts.tv_sec, ts.tv_nsec / 1000000, process_name, pid, tid);
}
Expand Down
48 changes: 0 additions & 48 deletions AK/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ constexpr T fmod(T x, T y)
// might work

#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
if constexpr (IsSame<T, long double>)
return __builtin_fmodl(x, y);
if constexpr (IsSame<T, double>)
Expand All @@ -449,10 +445,6 @@ constexpr T remainder(T x, T y)
} while (fpu_status & 0x400);
return x;
#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
if constexpr (IsSame<T, long double>)
return __builtin_remainderl(x, y);
if constexpr (IsSame<T, double>)
Expand Down Expand Up @@ -559,13 +551,7 @@ constexpr T sin(T angle)
: "0"(angle));
return ret;
#else
# if defined(AK_OS_SERENITY)
// FIXME: This is a very naive implementation, and is only valid for small x.
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
return angle;
# else
return __builtin_sin(angle);
# endif
#endif
}

Expand All @@ -582,13 +568,7 @@ constexpr T cos(T angle)
: "0"(angle));
return ret;
#else
# if defined(AK_OS_SERENITY)
// FIXME: This is a very naive implementation, and is only valid for small x.
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
return 1 - ((angle * angle) / 2);
# else
return __builtin_cos(angle);
# endif
#endif
}

Expand Down Expand Up @@ -625,13 +605,7 @@ constexpr T tan(T angle)

return ret;
#else
# if defined(AK_OS_SERENITY)
// FIXME: This is a very naive implementation, and is only valid for small x.
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
return angle;
# else
return __builtin_tan(angle);
# endif
#endif
}

Expand All @@ -649,10 +623,6 @@ constexpr T atan(T value)
: "0"(value));
return ret;
#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
return __builtin_atan(value);
#endif
}
Expand Down Expand Up @@ -708,10 +678,6 @@ constexpr T atan2(T y, T x)
: "st(1)");
return ret;
#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
return __builtin_atan2(y, x);
#endif
}
Expand Down Expand Up @@ -826,9 +792,6 @@ constexpr T log(T x)
: "=t"(ret)
: "0"(x));
return ret;
#elif defined(AK_OS_SERENITY)
// FIXME: Adjust the polynomial and formula in log2 to fit this
return log2<T>(x) / L2_E<T>;
#else
return __builtin_log(x);
#endif
Expand All @@ -848,9 +811,6 @@ constexpr T log10(T x)
: "=t"(ret)
: "0"(x));
return ret;
#elif defined(AK_OS_SERENITY)
// FIXME: Adjust the polynomial and formula in log2 to fit this
return log2<T>(x) / L2_10<T>;
#else
return __builtin_log10(x);
#endif
Expand All @@ -876,10 +836,6 @@ constexpr T exp(T exponent)
: "0"(exponent));
return res;
#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
return __builtin_exp(exponent);
#endif
}
Expand All @@ -902,10 +858,6 @@ constexpr T exp2(T exponent)
: "0"(exponent));
return res;
#else
# if defined(AK_OS_SERENITY)
// TODO: Add implementation for this function.
TODO();
# endif
return __builtin_exp2(exponent);
#endif
}
Expand Down
13 changes: 0 additions & 13 deletions AK/NoAllocationGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#include <AK/Forward.h>
#include <AK/Noncopyable.h>

#if defined(AK_OS_SERENITY)
# include <mallocdefs.h>
#endif

namespace AK {

class NoAllocationGuard {
Expand All @@ -34,21 +30,12 @@ class NoAllocationGuard {
private:
static bool get_thread_allocation_state()
{
#if defined(AK_OS_SERENITY)
// This extern thread-local lives in our LibC, which doesn't exist on other systems.
return s_allocation_enabled;
#else
return true;
#endif
}

static void set_thread_allocation_state(bool value)
{
#if defined(AK_OS_SERENITY)
s_allocation_enabled = value;
#else
(void)value;
#endif
}

bool m_allocation_enabled_previously { true };
Expand Down
18 changes: 6 additions & 12 deletions AK/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
# define AK_LIBC_GLIBC_PREREQ(maj, min) 0
#endif

#if defined(__serenity__)
# define AK_OS_SERENITY
#endif

#if defined(__linux__)
# define AK_OS_LINUX
#endif
Expand Down Expand Up @@ -248,15 +244,13 @@
# define LSAN_UNREGISTER_ROOT_REGION(base, size)
#endif

#ifndef AK_OS_SERENITY
# ifdef AK_OS_WINDOWS
#ifdef AK_OS_WINDOWS
// FIXME: No idea where to get this, but it's 4096 anyway :^)
# define PAGE_SIZE 4096
# else
# include <unistd.h>
# undef PAGE_SIZE
# define PAGE_SIZE sysconf(_SC_PAGESIZE)
# endif
# define PAGE_SIZE 4096
#else
# include <unistd.h>
# undef PAGE_SIZE
# define PAGE_SIZE sysconf(_SC_PAGESIZE)
#endif

#if defined(AK_OS_WINDOWS)
Expand Down
2 changes: 1 addition & 1 deletion AK/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace AK {

inline void fill_with_random([[maybe_unused]] Bytes bytes)
{
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) || AK_LIBC_GLIBC_PREREQ(2, 36)
#if defined(AK_OS_ANDROID) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) || AK_LIBC_GLIBC_PREREQ(2, 36)
arc4random_buf(bytes.data(), bytes.size());
#elif defined(OSS_FUZZ)
#else
Expand Down
4 changes: 1 addition & 3 deletions AK/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
# include <sched.h>
#endif

#ifndef AK_OS_SERENITY
# include <new>
#endif
#include <new>

namespace AK {

Expand Down
11 changes: 2 additions & 9 deletions AK/StackInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <stdio.h>
#include <string.h>

#ifdef AK_OS_SERENITY
# include <serenity.h>
#elif defined(AK_OS_LINUX) || defined(AK_LIBC_GLIBC) || defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_NETBSD) || defined(AK_OS_SOLARIS) || defined(AK_OS_HAIKU)
#if defined(AK_OS_LINUX) || defined(AK_LIBC_GLIBC) || defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_NETBSD) || defined(AK_OS_SOLARIS) || defined(AK_OS_HAIKU)
# include <pthread.h>
# include <sys/resource.h>
#elif defined(AK_OS_FREEBSD) || defined(AK_OS_OPENBSD)
Expand All @@ -28,12 +26,7 @@ namespace AK {

StackInfo::StackInfo()
{
#ifdef AK_OS_SERENITY
if (get_stack_bounds(&m_base, &m_size) < 0) {
perror("get_stack_bounds");
VERIFY_NOT_REACHED();
}
#elif defined(AK_OS_LINUX) or defined(AK_LIBC_GLIBC) or defined(AK_OS_FREEBSD) or defined(AK_OS_NETBSD) or defined(AK_OS_SOLARIS) or defined(AK_OS_HAIKU)
#if defined(AK_OS_LINUX) or defined(AK_LIBC_GLIBC) or defined(AK_OS_FREEBSD) or defined(AK_OS_NETBSD) or defined(AK_OS_SOLARIS) or defined(AK_OS_HAIKU)
int rc;
pthread_attr_t attr;
pthread_attr_init(&attr);
Expand Down
36 changes: 6 additions & 30 deletions AK/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,41 +110,17 @@ using Conditional = typename __Conditional<condition, TrueType, FalseType>::Type

}

#ifdef AK_OS_SERENITY
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

using size_t = __SIZE_TYPE__;
using ssize_t = AK::Detail::MakeSigned<size_t>;

using ptrdiff_t = __PTRDIFF_TYPE__;

using intptr_t = __INTPTR_TYPE__;
using uintptr_t = __UINTPTR_TYPE__;

using uint8_t = u8;
using uint16_t = u16;
using uint32_t = u32;
using uint64_t = u64;

using int8_t = i8;
using int16_t = i16;
using int32_t = i32;
using int64_t = i64;

using pid_t = int;

#else
# include <stddef.h>
# include <stdint.h>
# include <sys/types.h>

# ifdef __ptrdiff_t
#ifdef __ptrdiff_t
using __ptrdiff_t = __PTRDIFF_TYPE__;
# endif
#endif

# if defined(AK_OS_WINDOWS)
#if defined(AK_OS_WINDOWS)
using ssize_t = AK::Detail::MakeSigned<size_t>;
using mode_t = unsigned short;
# endif
#endif

using FlatPtr = AK::Detail::Conditional<sizeof(void*) == 8, u64, u32>;
Expand Down
Loading

0 comments on commit 5a5c1d8

Please sign in to comment.