diff --git a/AK/Assertions.cpp b/AK/Assertions.cpp index 9334a49ad5725..c4e09b41415aa 100644 --- a/AK/Assertions.cpp +++ b/AK/Assertions.cpp @@ -23,11 +23,7 @@ # include #endif -#if defined(AK_OS_SERENITY) -# define ERRORLN dbgln -#else -# define ERRORLN warnln -#endif +#define ERRORLN warnln #if defined(AK_HAS_BACKTRACE_HEADER) namespace { @@ -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; diff --git a/AK/BumpAllocator.h b/AK/BumpAllocator.h index 21348a4df0c0d..db0c629f6c232 100644 --- a/AK/BumpAllocator.h +++ b/AK/BumpAllocator.h @@ -103,11 +103,7 @@ class BumpAllocator { void* new_chunk = reinterpret_cast(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 { diff --git a/AK/Error.h b/AK/Error.h index f8b60690ad876..3d241a9392e95 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -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(); diff --git a/AK/Format.cpp b/AK/Format.cpp index f8083a5ff592d..672323b9ba148 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -17,10 +17,6 @@ #include #include -#if defined(AK_OS_SERENITY) -# include -#endif - #if defined(AK_OS_ANDROID) # include #endif @@ -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(); @@ -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) { @@ -1181,7 +1165,7 @@ 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) @@ -1189,7 +1173,7 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) { 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); } diff --git a/AK/Math.h b/AK/Math.h index 1a354a7488e91..c40060a113ecf 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -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) return __builtin_fmodl(x, y); if constexpr (IsSame) @@ -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) return __builtin_remainderl(x, y); if constexpr (IsSame) @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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(x) / L2_E; #else return __builtin_log(x); #endif @@ -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(x) / L2_10; #else return __builtin_log10(x); #endif @@ -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 } @@ -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 } diff --git a/AK/NoAllocationGuard.h b/AK/NoAllocationGuard.h index 8cc3c846bad5e..c98af135c7223 100644 --- a/AK/NoAllocationGuard.h +++ b/AK/NoAllocationGuard.h @@ -9,10 +9,6 @@ #include #include -#if defined(AK_OS_SERENITY) -# include -#endif - namespace AK { class NoAllocationGuard { @@ -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 }; diff --git a/AK/Platform.h b/AK/Platform.h index b75aa087e7649..6d951b7001d13 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -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 @@ -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 -# undef PAGE_SIZE -# define PAGE_SIZE sysconf(_SC_PAGESIZE) -# endif +# define PAGE_SIZE 4096 +#else +# include +# undef PAGE_SIZE +# define PAGE_SIZE sysconf(_SC_PAGESIZE) #endif #if defined(AK_OS_WINDOWS) diff --git a/AK/Random.h b/AK/Random.h index c2badd3e6ac64..70eacd3021cd1 100644 --- a/AK/Random.h +++ b/AK/Random.h @@ -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 diff --git a/AK/Singleton.h b/AK/Singleton.h index b1a0d5527f96a..c8b06dad1ea8a 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -19,9 +19,7 @@ extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long); # include #endif -#ifndef AK_OS_SERENITY -# include -#endif +#include namespace AK { diff --git a/AK/StackInfo.cpp b/AK/StackInfo.cpp index 4777c48375d1f..312e221b1c068 100644 --- a/AK/StackInfo.cpp +++ b/AK/StackInfo.cpp @@ -10,9 +10,7 @@ #include #include -#ifdef AK_OS_SERENITY -# include -#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 # include #elif defined(AK_OS_FREEBSD) || defined(AK_OS_OPENBSD) @@ -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); diff --git a/AK/Types.h b/AK/Types.h index de00fccb4dda0..ae43413694190 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -110,41 +110,17 @@ using Conditional = typename __Conditional::Type } -#ifdef AK_OS_SERENITY +#include +#include +#include -using size_t = __SIZE_TYPE__; -using ssize_t = AK::Detail::MakeSigned; - -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 -# include -# include - -# 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; using mode_t = unsigned short; -# endif #endif using FlatPtr = AK::Detail::Conditional; diff --git a/AK/kmalloc.cpp b/AK/kmalloc.cpp index a24444d7e2bea..b56ffe592c3b4 100644 --- a/AK/kmalloc.cpp +++ b/AK/kmalloc.cpp @@ -6,64 +6,3 @@ */ #include - -#if defined(AK_OS_SERENITY) - -# include - -// However deceptively simple these functions look, they must not be inlined. -// Memory allocated in one translation unit has to be deallocatable in another -// translation unit, so these functions must be the same everywhere. -// By making these functions global, this invariant is enforced. - -void* operator new(size_t size) -{ - void* ptr = malloc(size); - VERIFY(ptr); - return ptr; -} - -void* operator new(size_t size, std::nothrow_t const&) noexcept -{ - return malloc(size); -} - -void operator delete(void* ptr) noexcept -{ - return free(ptr); -} - -void operator delete(void* ptr, size_t) noexcept -{ - return free(ptr); -} - -void* operator new[](size_t size) -{ - void* ptr = malloc(size); - VERIFY(ptr); - return ptr; -} - -void* operator new[](size_t size, std::nothrow_t const&) noexcept -{ - return malloc(size); -} - -void operator delete[](void* ptr) noexcept -{ - return free(ptr); -} - -void operator delete[](void* ptr, size_t) noexcept -{ - return free(ptr); -} - -// This is usually provided by libstdc++ in most cases, and the kernel has its own definition in -// Kernel/Heap/kmalloc.cpp. If neither of those apply, the following should suffice to not fail during linking. -namespace AK_REPLACED_STD_NAMESPACE { -nothrow_t const nothrow; -} - -#endif diff --git a/AK/kmalloc.h b/AK/kmalloc.h index 74822c50d19e0..d0276b94333ce 100644 --- a/AK/kmalloc.h +++ b/AK/kmalloc.h @@ -21,16 +21,14 @@ inline void kfree_sized(void* ptr, size_t) free(ptr); } -#ifndef AK_OS_SERENITY -# include +#include -# ifndef AK_OS_MACOS +#ifndef AK_OS_MACOS extern "C" { inline size_t malloc_good_size(size_t size) { return size; } } -# else -# include -# endif +#else +# include #endif using std::nothrow; diff --git a/Tests/LibAudio/TestPlaybackStream.cpp b/Tests/LibAudio/TestPlaybackStream.cpp index 8f14413a9a824..6988ea2db6459 100644 --- a/Tests/LibAudio/TestPlaybackStream.cpp +++ b/Tests/LibAudio/TestPlaybackStream.cpp @@ -21,18 +21,14 @@ // current session ID is 0, and AudioServer's socket address depends on the current sid. // If we can fix that, this test can run on CI. // https://github.com/SerenityOS/serenity/issues/20538 -#if defined(AK_OS_SERENITY) -# define STREAM_TEST BENCHMARK_CASE -#else -# define STREAM_TEST TEST_CASE -#endif +#define STREAM_TEST TEST_CASE STREAM_TEST(create_and_destroy_playback_stream) { Core::EventLoop event_loop; bool has_implementation = false; -#if defined(AK_OS_SERENITY) || defined(HAVE_PULSEAUDIO) || defined(AK_OS_MACOS) +#if defined(HAVE_PULSEAUDIO) || defined(AK_OS_MACOS) has_implementation = true; #endif diff --git a/Tests/LibAudio/TestWav.cpp b/Tests/LibAudio/TestWav.cpp index e8d89f2ec30a5..14ce45e731f14 100644 --- a/Tests/LibAudio/TestWav.cpp +++ b/Tests/LibAudio/TestWav.cpp @@ -39,12 +39,7 @@ static void run_test(StringView file_name, int const num_samples, int const chan auto out_file = TRY_OR_FAIL(FileSystem::TempFile::create_temp_file()); auto out_path = out_file->path(); -// This makes sure that the tests will run both on target and in Lagom. -#ifdef AK_OS_SERENITY - ByteString in_path = ByteString::formatted("/usr/Tests/LibAudio/WAV/{}", file_name); -#else ByteString in_path = ByteString::formatted("WAV/{}", file_name); -#endif auto loader = TRY_OR_FAIL(Audio::Loader::create(in_path)); diff --git a/Tests/LibCompress/TestBrotli.cpp b/Tests/LibCompress/TestBrotli.cpp index 810d27cb2345b..3cd7839568cf9 100644 --- a/Tests/LibCompress/TestBrotli.cpp +++ b/Tests/LibCompress/TestBrotli.cpp @@ -68,12 +68,7 @@ TEST_CASE(dictionary_use_after_uncompressed_block) static void run_test(StringView const file_name) { - // This makes sure that the tests will run both on target and in Lagom. -#ifdef AK_OS_SERENITY - ByteString path = ByteString::formatted("/usr/Tests/LibCompress/brotli-test-files/{}", file_name); -#else ByteString path = ByteString::formatted("brotli-test-files/{}", file_name); -#endif auto cmp_file = MUST(Core::File::open(path, Core::File::OpenMode::Read)); auto cmp_data = MUST(cmp_file->read_until_eof()); @@ -139,12 +134,7 @@ TEST_CASE(brotli_single_x) TEST_CASE(brotli_decompress_zero_one_bin) { - // This makes sure that the tests will run both on target and in Lagom. -#ifdef AK_OS_SERENITY - ByteString path = "/usr/Tests/LibCompress/brotli-test-files/zero-one.bin"; -#else ByteString path = "brotli-test-files/zero-one.bin"; -#endif ByteString path_compressed = ByteString::formatted("{}.br", path); diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp index eb9899f6bc2d4..c263009b240c3 100644 --- a/Tests/LibCompress/TestDeflate.cpp +++ b/Tests/LibCompress/TestDeflate.cpp @@ -14,11 +14,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibCompress/deflate-test-files/" x) -#else -# define TEST_INPUT(x) ("deflate-test-files/" x) -#endif +#define TEST_INPUT(x) ("deflate-test-files/" x) TEST_CASE(canonical_code_simple) { diff --git a/Tests/LibGfx/BenchmarkJPEGLoader.cpp b/Tests/LibGfx/BenchmarkJPEGLoader.cpp index 1522487153a07..e97d356697ce3 100644 --- a/Tests/LibGfx/BenchmarkJPEGLoader.cpp +++ b/Tests/LibGfx/BenchmarkJPEGLoader.cpp @@ -8,11 +8,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) -#else -# define TEST_INPUT(x) ("test-inputs/" x) -#endif +#define TEST_INPUT(x) ("test-inputs/" x) auto small_image = Core::File::open(TEST_INPUT("jpg/rgb24.jpg"sv), Core::File::OpenMode::Read).release_value()->read_until_eof().release_value(); auto big_image = Core::File::open(TEST_INPUT("jpg/big_image.jpg"sv), Core::File::OpenMode::Read).release_value()->read_until_eof().release_value(); diff --git a/Tests/LibGfx/TestICCProfile.cpp b/Tests/LibGfx/TestICCProfile.cpp index 3828c638d04a7..37f8c3c03db63 100644 --- a/Tests/LibGfx/TestICCProfile.cpp +++ b/Tests/LibGfx/TestICCProfile.cpp @@ -16,11 +16,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) -#else -# define TEST_INPUT(x) ("test-inputs/" x) -#endif +#define TEST_INPUT(x) ("test-inputs/" x) TEST_CASE(png) { diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 75503cdd89c78..6d2bcb4433230 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -22,11 +22,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) -#else -# define TEST_INPUT(x) ("test-inputs/" x) -#endif +#define TEST_INPUT(x) ("test-inputs/" x) static ErrorOr expect_single_frame(Gfx::ImageDecoderPlugin& plugin_decoder) { diff --git a/Tests/LibGfx/TestWOFF.cpp b/Tests/LibGfx/TestWOFF.cpp index 452ca0603b5cd..2856ac3108565 100644 --- a/Tests/LibGfx/TestWOFF.cpp +++ b/Tests/LibGfx/TestWOFF.cpp @@ -7,11 +7,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) -#else -# define TEST_INPUT(x) ("test-inputs/" x) -#endif +#define TEST_INPUT(x) ("test-inputs/" x) TEST_CASE(malformed_woff) { diff --git a/Tests/LibGfx/TestWOFF2.cpp b/Tests/LibGfx/TestWOFF2.cpp index 2cc2b2c067b17..f64b5bf6bee8c 100644 --- a/Tests/LibGfx/TestWOFF2.cpp +++ b/Tests/LibGfx/TestWOFF2.cpp @@ -7,11 +7,7 @@ #include #include -#ifdef AK_OS_SERENITY -# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) -#else -# define TEST_INPUT(x) ("test-inputs/" x) -#endif +#define TEST_INPUT(x) ("test-inputs/" x) TEST_CASE(tolerate_incorrect_sfnt_size) { diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index e49e4f12e8e97..57996d24d6967 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -544,17 +544,11 @@ static bool g_in_assert = false; // FIXME: Use a SIGABRT handler here instead of overriding internal libc assertion handlers. // Fixing this will likely require updating the test driver as well to pull the assertion failure // message out of stderr rather than from the json object printed to stdout. -#ifdef AK_OS_SERENITY -void __assertion_failed(char const* assertion) -{ - handle_failed_assert(assertion); -} -#else -# ifdef ASSERT_FAIL_HAS_INT /* Set by CMake */ +#ifdef ASSERT_FAIL_HAS_INT /* Set by CMake */ extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function) -# else +#else extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, unsigned int line, char const* function) -# endif +#endif { auto full_message = ByteString::formatted("{}:{}: {}: Assertion `{}' failed.", file, line, function, assertion); handle_failed_assert(full_message.characters()); diff --git a/Tests/LibWeb/TestHTMLTokenizer.cpp b/Tests/LibWeb/TestHTMLTokenizer.cpp index 1bb25f3336d28..a859af123eb4b 100644 --- a/Tests/LibWeb/TestHTMLTokenizer.cpp +++ b/Tests/LibWeb/TestHTMLTokenizer.cpp @@ -223,12 +223,7 @@ TEST_CASE(doctype) // If that changes, or something is added to the test HTML, the hash needs to be adjusted. TEST_CASE(regression) { - // This makes sure that the tests will run both on target and in Lagom. -#ifdef AK_OS_SERENITY - StringView path = "/usr/Tests/LibWeb/tokenizer-test.html"sv; -#else StringView path = "tokenizer-test.html"sv; -#endif auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read)); auto file_size = MUST(file->size()); diff --git a/Userland/Libraries/LibCore/Command.cpp b/Userland/Libraries/LibCore/Command.cpp index f7120b08790ce..51225fe2091a2 100644 --- a/Userland/Libraries/LibCore/Command.cpp +++ b/Userland/Libraries/LibCore/Command.cpp @@ -118,85 +118,4 @@ ErrorOr Command::status(int options) return ProcessResult::Failed; } -// Only supported in serenity mode because we use `posix_spawn_file_actions_addchdir` -#ifdef AK_OS_SERENITY - -ErrorOr command(ByteString const& command_string, Optional chdir) -{ - auto parts = command_string.split(' '); - if (parts.is_empty()) - return Error::from_string_literal("empty command"); - auto program = parts[0]; - parts.remove(0); - return command(program, parts, chdir); -} - -ErrorOr command(ByteString const& program, Vector const& arguments, Optional chdir) -{ - int stdout_pipe[2] = {}; - int stderr_pipe[2] = {}; - if (pipe2(stdout_pipe, O_CLOEXEC)) { - return Error::from_errno(errno); - } - if (pipe2(stderr_pipe, O_CLOEXEC)) { - perror("pipe2"); - return Error::from_errno(errno); - } - - auto close_pipes = ScopeGuard([stderr_pipe, stdout_pipe] { - // The write-ends of these pipes are closed manually - close(stdout_pipe[0]); - close(stderr_pipe[0]); - }); - - Vector parts = { program.characters() }; - for (auto const& part : arguments) { - parts.append(part.characters()); - } - parts.append(nullptr); - - char const** argv = parts.data(); - - posix_spawn_file_actions_t action; - posix_spawn_file_actions_init(&action); - if (chdir.has_value()) { - posix_spawn_file_actions_addchdir(&action, chdir.value().string().characters()); - } - posix_spawn_file_actions_adddup2(&action, stdout_pipe[1], STDOUT_FILENO); - posix_spawn_file_actions_adddup2(&action, stderr_pipe[1], STDERR_FILENO); - - pid_t pid; - if ((errno = posix_spawnp(&pid, program.characters(), &action, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - VERIFY_NOT_REACHED(); - } - - // close the write-ends so reading wouldn't block - close(stdout_pipe[1]); - close(stderr_pipe[1]); - - auto read_all_from_pipe = [](int pipe[2]) -> ErrorOr { - auto result_file_or_error = Core::File::adopt_fd(pipe[0], Core::File::OpenMode::Read, Core::File::ShouldCloseFileDescriptor::Yes); - auto result_file = TRY(result_file_or_error); - return result_file->read_until_eof(); - }; - auto output = TRY(read_all_from_pipe(stdout_pipe)); - auto error = TRY(read_all_from_pipe(stderr_pipe)); - - int wstatus { 0 }; - waitpid(pid, &wstatus, 0); - posix_spawn_file_actions_destroy(&action); - int exit_code = WEXITSTATUS(wstatus); - - if (exit_code != 0) { -# ifdef DBG_FAILED_COMMANDS - dbgln("command failed. stderr: {}", ); -# endif - } - - return CommandResult { WEXITSTATUS(wstatus), output, error }; -} - -#endif - } diff --git a/Userland/Libraries/LibCore/Environment.cpp b/Userland/Libraries/LibCore/Environment.cpp index f0fc06a884505..1017675786a72 100644 --- a/Userland/Libraries/LibCore/Environment.cpp +++ b/Userland/Libraries/LibCore/Environment.cpp @@ -140,13 +140,9 @@ ErrorOr unset(StringView name) ErrorOr put(StringView env) { -#if defined(AK_OS_SERENITY) - auto rc = ::serenity_putenv(env.characters_without_null_termination(), env.length()); -#else // Leak somewhat unavoidable here due to the putenv API. auto leaked_new_env = strndup(env.characters_without_null_termination(), env.length()); auto rc = ::putenv(leaked_new_env); -#endif if (rc < 0) return Error::from_errno(errno); return {}; diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 11f988b95f8d1..715ea238754c8 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -23,11 +23,7 @@ #include #include -#if defined(AK_OS_SERENITY) -# include -# include -# include -#elif defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_SOLARIS) +#if defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_SOLARIS) # include #elif defined(AK_OS_GNU_HURD) extern "C" { @@ -84,12 +80,8 @@ ErrorOr Process::spawn(ProcessSpawnOptions const& options) }; if (options.working_directory.has_value()) { -#ifdef AK_OS_SERENITY - CHECK(posix_spawn_file_actions_addchdir(&spawn_actions, options.working_directory->characters())); -#else // FIXME: Support ProcessSpawnOptions::working_directory n platforms that support it. TODO(); -#endif } for (auto const& file_action : options.file_actions) { @@ -183,13 +175,7 @@ ErrorOr Process::spawn(StringView path, ReadonlySpan argumen ErrorOr Process::get_name() { -#if defined(AK_OS_SERENITY) - char buffer[BUFSIZ]; - int rc = get_process_name(buffer, BUFSIZ); - if (rc != 0) - return Error::from_syscall("get_process_name"sv, -rc); - return String::from_utf8(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 String::from_utf8(StringView { program_invocation_name, strlen(program_invocation_name) }); #elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) auto const* progname = getprogname(); @@ -202,21 +188,8 @@ ErrorOr Process::get_name() ErrorOr Process::set_name([[maybe_unused]] StringView name, [[maybe_unused]] SetThreadName set_thread_name) { -#if defined(AK_OS_SERENITY) - int rc = set_process_name(name.characters_without_null_termination(), name.length()); - if (rc != 0) - return Error::from_syscall("set_process_name"sv, -rc); - if (set_thread_name == SetThreadName::No) - return {}; - - rc = prctl(PR_SET_THREAD_NAME, gettid(), name.characters_without_null_termination(), name.length()); - if (rc != 0) - return Error::from_syscall("set_thread_name"sv, -rc); - return {}; -#else // FIXME: Implement Process::set_name() for other platforms. return {}; -#endif } ErrorOr Process::is_being_debugged() @@ -327,11 +300,7 @@ void Process::wait_for_debugger_and_break() ErrorOr Process::disown() { if (m_pid != 0 && m_should_disown) { -#ifdef AK_OS_SERENITY - TRY(System::disown(m_pid)); -#else // FIXME: Support disown outside Serenity. -#endif m_should_disown = false; return {}; } else { diff --git a/Userland/Libraries/LibCore/Socket.cpp b/Userland/Libraries/LibCore/Socket.cpp index e2dc3b06761d1..c89b654c076cb 100644 --- a/Userland/Libraries/LibCore/Socket.cpp +++ b/Userland/Libraries/LibCore/Socket.cpp @@ -288,9 +288,7 @@ ErrorOr> LocalSocket::adopt_fd(int fd, PreventSIGPIPE ErrorOr LocalSocket::receive_fd(int flags) { -#if defined(AK_OS_SERENITY) - return Core::System::recvfd(m_helper.fd(), flags); -#elif defined(AK_OS_LINUX) || defined(AK_OS_GNU_HURD) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) +#if defined(AK_OS_LINUX) || defined(AK_OS_GNU_HURD) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) union { struct cmsghdr cmsghdr; char control[CMSG_SPACE(sizeof(int))]; @@ -329,9 +327,7 @@ ErrorOr LocalSocket::receive_fd(int flags) ErrorOr LocalSocket::send_fd(int fd) { -#if defined(AK_OS_SERENITY) - return Core::System::sendfd(m_helper.fd(), fd); -#elif defined(AK_OS_LINUX) || defined(AK_OS_GNU_HURD) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) +#if defined(AK_OS_LINUX) || defined(AK_OS_GNU_HURD) || defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) char c = 'F'; struct iovec iov { .iov_base = &c, diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index 995c992e8f75e..a15f68847408f 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -130,9 +130,7 @@ ByteString StandardPaths::data_directory() StringBuilder builder; builder.append(home_directory()); -#if defined(AK_OS_SERENITY) - builder.append("/.data"sv); -#elif defined(AK_OS_MACOS) +#if defined(AK_OS_MACOS) builder.append("/Library/Application Support"sv); #elif defined(AK_OS_HAIKU) builder.append("/config/non-packaged/data"sv); @@ -150,10 +148,7 @@ ErrorOr StandardPaths::runtime_directory() StringBuilder builder; -#if defined(AK_OS_SERENITY) - auto sid = TRY(Core::SessionManagement::root_session_id()); - builder.appendff("/tmp/session/{}", sid); -#elif defined(AK_OS_MACOS) +#if defined(AK_OS_MACOS) builder.append(home_directory()); builder.append("/Library/Application Support"sv); #elif defined(AK_OS_HAIKU) @@ -200,9 +195,7 @@ ErrorOr> StandardPaths::font_directories() return paths_vector; #else auto paths = Vector { { -# if defined(AK_OS_SERENITY) - "/res/fonts"_string, -# elif defined(AK_OS_MACOS) +# if defined(AK_OS_MACOS) "/System/Library/Fonts"_string, "/Library/Fonts"_string, TRY(String::formatted("{}/Library/Fonts"sv, home_directory())), @@ -211,7 +204,7 @@ ErrorOr> StandardPaths::font_directories() TRY(String::formatted("{}/X11/fonts"sv, data_directory())), # endif } }; -# if !(defined(AK_OS_SERENITY) || defined(AK_OS_MACOS)) +# if !defined(AK_OS_MACOS) auto data_directories = Core::Environment::get("XDG_DATA_DIRS"sv).value_or("/usr/local/share:/usr/share"sv); TRY(data_directories.for_each_split_view(':', SplitBehavior::Nothing, [&paths](auto data_directory) -> ErrorOr { paths.append(TRY(String::formatted("{}/fonts"sv, data_directory))); diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index fb8d366eaeea8..3150f4a3a86ef 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -27,15 +27,6 @@ #include #include -#ifdef AK_OS_SERENITY -# include -# include -# include -# include -# include -# include -#endif - #if defined(AK_OS_LINUX) && !defined(MFD_CLOEXEC) # include # include @@ -146,233 +137,6 @@ namespace Core::System { # endif #endif -#ifdef AK_OS_SERENITY - -ErrorOr beep(u16 tone, u16 milliseconds_duration) -{ - static Optional beep_fd; - if (!beep_fd.has_value()) - beep_fd = TRY(Core::System::open("/dev/beep"sv, O_RDWR)); - BeepInstruction instruction { tone, milliseconds_duration }; - TRY(Core::System::write(beep_fd.value(), Span(&instruction, sizeof(BeepInstruction)))); - return {}; -} - -ErrorOr pledge(StringView promises, StringView execpromises) -{ - Syscall::SC_pledge_params params { - { promises.characters_without_null_termination(), promises.length() }, - { execpromises.characters_without_null_termination(), execpromises.length() }, - }; - int rc = syscall(SC_pledge, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("pledge", rc, {}); -} - -static ErrorOr unveil_dynamic_loader() -{ - static bool dynamic_loader_unveiled { false }; - if (dynamic_loader_unveiled) - return {}; - // FIXME: Try to find a way to not hardcode the dynamic loader path. - constexpr auto dynamic_loader_path = "/usr/lib/Loader.so"sv; - constexpr auto dynamic_loader_permissions = "x"sv; - - Syscall::SC_unveil_params params { - static_cast(UnveilFlags::CurrentProgram), - { dynamic_loader_path.characters_without_null_termination(), dynamic_loader_path.length() }, - { dynamic_loader_permissions.characters_without_null_termination(), dynamic_loader_permissions.length() }, - }; - int rc = syscall(SC_unveil, ¶ms); - if (rc < 0) { - return Error::from_syscall("unveil (DynamicLoader @ /usr/lib/Loader.so)"sv, rc); - } - dynamic_loader_unveiled = true; - return {}; -} - -ErrorOr unveil(StringView path, StringView permissions) -{ - if (permissions.contains('x')) - TRY(unveil_dynamic_loader()); - - Syscall::SC_unveil_params params { - static_cast(UnveilFlags::CurrentProgram), - { nullptr, 0 }, - { nullptr, 0 }, - }; - - ByteString parsed_path; - if (!path.is_null()) { - parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); - params.path = { parsed_path.characters(), parsed_path.length() }; - params.permissions = { permissions.characters_without_null_termination(), permissions.length() }; - } - - int rc = syscall(SC_unveil, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("unveil", rc, {}); -} - -ErrorOr unveil_after_exec(StringView path, StringView permissions) -{ - ByteString parsed_path; - Syscall::SC_unveil_params params { - static_cast(UnveilFlags::AfterExec), - { nullptr, 0 }, - { permissions.characters_without_null_termination(), permissions.length() }, - }; - - if (!path.is_null()) { - parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path)); - params.path = { parsed_path.characters(), parsed_path.length() }; - } - - int rc = syscall(SC_unveil, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("unveil", rc, {}); -} - -ErrorOr sendfd(int sockfd, int fd) -{ - if (::sendfd(sockfd, fd) < 0) - return Error::from_syscall("sendfd"sv, -errno); - return {}; -} - -ErrorOr recvfd(int sockfd, int options) -{ - auto fd = ::recvfd(sockfd, options); - if (fd < 0) - return Error::from_syscall("recvfd"sv, -errno); - return fd; -} - -ErrorOr ptrace_peekbuf(pid_t tid, void const* tracee_addr, Bytes destination_buf) -{ - Syscall::SC_ptrace_buf_params buf_params { - { destination_buf.data(), destination_buf.size() } - }; - Syscall::SC_ptrace_params params { - PT_PEEKBUF, - tid, - const_cast(tracee_addr), - (FlatPtr)&buf_params, - }; - int rc = syscall(SC_ptrace, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("ptrace_peekbuf", rc, {}); -} - -ErrorOr bindmount(int source_fd, StringView target, int flags) -{ - if (target.is_null()) - return Error::from_errno(EFAULT); - - Syscall::SC_bindmount_params params { - { target.characters_without_null_termination(), target.length() }, - source_fd, - flags, - }; - int rc = syscall(SC_bindmount, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("bindmount", rc, {}); -} - -ErrorOr remount(StringView target, int flags) -{ - if (target.is_null()) - return Error::from_errno(EFAULT); - - Syscall::SC_remount_params params { - { target.characters_without_null_termination(), target.length() }, - flags - }; - int rc = syscall(SC_remount, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("remount", rc, {}); -} - -ErrorOr mount(int source_fd, StringView target, StringView fs_type, int flags) -{ - if (target.is_null() || fs_type.is_null()) - return Error::from_errno(EFAULT); - - if (flags & MS_REMOUNT) { - TRY(remount(target, flags)); - return {}; - } - if (flags & MS_BIND) { - TRY(bindmount(source_fd, target, flags)); - return {}; - } - int mount_fd = TRY(fsopen(fs_type, flags)); - return fsmount(mount_fd, source_fd, target); -} - -ErrorOr fsopen(StringView fs_type, int flags) -{ - if (fs_type.is_null()) - return Error::from_errno(EFAULT); - - Syscall::SC_fsopen_params params { - { fs_type.characters_without_null_termination(), fs_type.length() }, - flags, - }; - int rc = syscall(SC_fsopen, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("fsopen", rc, rc); -} - -ErrorOr fsmount(int mount_fd, int source_fd, StringView target) -{ - if (target.is_null()) - return Error::from_errno(EFAULT); - - Syscall::SC_fsmount_params params { - mount_fd, - { target.characters_without_null_termination(), target.length() }, - source_fd, - }; - int rc = syscall(SC_fsmount, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("fsmount", rc, {}); -} - -ErrorOr umount(StringView mount_point) -{ - if (mount_point.is_null()) - return Error::from_errno(EFAULT); - - int rc = syscall(SC_umount, mount_point.characters_without_null_termination(), mount_point.length()); - HANDLE_SYSCALL_RETURN_VALUE("umount", rc, {}); -} - -ErrorOr ptrace(int request, pid_t tid, void* address, void* data) -{ - auto rc = ::ptrace(request, tid, address, data); - if (rc < 0) - return Error::from_syscall("ptrace"sv, -errno); - return rc; -} - -ErrorOr disown(pid_t pid) -{ - int rc = ::disown(pid); - HANDLE_SYSCALL_RETURN_VALUE("disown", rc, {}); -} - -ErrorOr profiling_enable(pid_t pid, u64 event_mask) -{ - int rc = ::profiling_enable(pid, event_mask); - HANDLE_SYSCALL_RETURN_VALUE("profiling_enable", rc, {}); -} - -ErrorOr profiling_disable(pid_t pid) -{ - int rc = ::profiling_disable(pid); - HANDLE_SYSCALL_RETURN_VALUE("profiling_disable", rc, {}); -} - -ErrorOr profiling_free_buffer(pid_t pid) -{ - int rc = ::profiling_free_buffer(pid); - HANDLE_SYSCALL_RETURN_VALUE("profiling_free_buffer", rc, {}); -} -#endif - #if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) ErrorOr> getspent() { @@ -443,13 +207,8 @@ ErrorOr fstatat(int fd, StringView path, int flags) return Error::from_syscall("fstatat"sv, -EFAULT); struct stat st = {}; -#ifdef AK_OS_SERENITY - Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, fd, !(flags & AT_SYMLINK_NOFOLLOW) }; - int rc = syscall(SC_stat, ¶ms); -#else ByteString path_string = path; int rc = ::fstatat(fd, path_string.characters(), &st, flags); -#endif HANDLE_SYSCALL_RETURN_VALUE("fstatat", rc, st); } @@ -465,34 +224,14 @@ ErrorOr fcntl(int fd, int command, ...) return rc; } -#ifdef AK_OS_SERENITY -ErrorOr create_block_device(StringView name, mode_t mode, unsigned major, unsigned minor) -{ - return Core::System::mknod(name, mode | S_IFBLK, makedev(major, minor)); -} - -ErrorOr create_char_device(StringView name, mode_t mode, unsigned major, unsigned minor) -{ - return Core::System::mknod(name, mode | S_IFCHR, makedev(major, minor)); -} -#endif - ErrorOr 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 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, ¶ms); - if (rc < 0 && rc > -EMAXERRNO) - return Error::from_syscall("mmap"sv, rc); - return reinterpret_cast(rc); -#else // NOTE: Regular POSIX mmap() doesn't support custom alignment requests. VERIFY(!alignment); auto* ptr = ::mmap(address, size, protection, flags, fd, offset); if (ptr == MAP_FAILED) return Error::from_syscall("mmap"sv, -errno); return ptr; -#endif } ErrorOr munmap(void* address, size_t size) @@ -505,9 +244,7 @@ ErrorOr munmap(void* address, size_t size) ErrorOr anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int options) { int fd = -1; -#if defined(AK_OS_SERENITY) - fd = ::anon_create(round_up_to_power_of_two(size, PAGE_SIZE), options); -#elif defined(AK_OS_LINUX) || defined(AK_OS_FREEBSD) +#if defined(AK_OS_LINUX) || defined(AK_OS_FREEBSD) // FIXME: Support more options on Linux. auto linux_options = ((options & O_CLOEXEC) > 0) ? MFD_CLOEXEC : 0; fd = memfd_create("", linux_options); @@ -569,18 +306,12 @@ ErrorOr openat(int fd, StringView path, int options, mode_t mode) { if (!path.characters_without_null_termination()) return Error::from_syscall("open"sv, -EFAULT); -#ifdef AK_OS_SERENITY - Syscall::SC_open_params params { fd, { path.characters_without_null_termination(), path.length() }, options, mode }; - int rc = syscall(SC_open, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("open", rc, rc); -#else // NOTE: We have to ensure that the path is null-terminated. ByteString path_string = path; int rc = ::openat(fd, path_string.characters(), options, mode); if (rc < 0) return Error::from_syscall("open"sv, -errno); return rc; -#endif } ErrorOr close(int fd) @@ -610,16 +341,10 @@ ErrorOr stat(StringView path) return Error::from_syscall("stat"sv, -EFAULT); struct stat st = {}; -#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, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("stat", rc, st); -#else ByteString path_string = path; if (::stat(path_string.characters(), &st) < 0) return Error::from_syscall("stat"sv, -errno); return st; -#endif } ErrorOr lstat(StringView path) @@ -629,16 +354,10 @@ ErrorOr lstat(StringView path) return Error::from_syscall("lstat"sv, -EFAULT); struct stat st = {}; -#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, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("lstat", rc, st); -#else ByteString path_string = path; if (::lstat(path_string.characters(), &st) < 0) return Error::from_syscall("lstat"sv, -errno); return st; -#endif } ErrorOr read(int fd, Bytes buffer) @@ -770,21 +489,10 @@ ErrorOr chmod(StringView pathname, mode_t mode) if (!pathname.characters_without_null_termination()) return Error::from_syscall("chmod"sv, -EFAULT); -#ifdef AK_OS_SERENITY - Syscall::SC_chmod_params params { - AT_FDCWD, - { pathname.characters_without_null_termination(), pathname.length() }, - mode, - true - }; - int rc = syscall(SC_chmod, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("chmod", rc, {}); -#else ByteString path = pathname; if (::chmod(path.characters(), mode) < 0) return Error::from_syscall("chmod"sv, -errno); return {}; -#endif } ErrorOr fchmod(int fd, mode_t mode) @@ -806,16 +514,10 @@ ErrorOr lchown(StringView pathname, uid_t uid, gid_t gid) if (!pathname.characters_without_null_termination()) return Error::from_syscall("chown"sv, -EFAULT); -#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, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {}); -#else ByteString path = pathname; if (::chown(path.characters(), uid, gid) < 0) return Error::from_syscall("chown"sv, -errno); return {}; -#endif } ErrorOr chown(StringView pathname, uid_t uid, gid_t gid) @@ -823,16 +525,10 @@ ErrorOr chown(StringView pathname, uid_t uid, gid_t gid) if (!pathname.characters_without_null_termination()) return Error::from_syscall("chown"sv, -EFAULT); -#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, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {}); -#else ByteString path = pathname; if (::lchown(path.characters(), uid, gid) < 0) return Error::from_syscall("lchown"sv, -errno); return {}; -#endif } ErrorOr> getpwent(Span buffer) @@ -908,14 +604,9 @@ ErrorOr> getgrnam(StringView name) #if !defined(AK_OS_IOS) ErrorOr clock_settime(clockid_t clock_id, struct timespec* ts) { -# ifdef AK_OS_SERENITY - int rc = syscall(SC_clock_settime, clock_id, ts); - HANDLE_SYSCALL_RETURN_VALUE("clocksettime", rc, {}); -# else if (::clock_settime(clock_id, ts) < 0) return Error::from_syscall("clocksettime"sv, -errno); return {}; -# endif } #endif @@ -1037,84 +728,50 @@ ErrorOr isatty(int fd) ErrorOr link(StringView old_path, StringView new_path) { -#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() }, - }; - int rc = syscall(SC_link, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("link", rc, {}); -#else ByteString old_path_string = old_path; ByteString new_path_string = new_path; if (::link(old_path_string.characters(), new_path_string.characters()) < 0) return Error::from_syscall("link"sv, -errno); return {}; -#endif } ErrorOr symlink(StringView target, StringView link_path) { -#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() }, - .dirfd = AT_FDCWD, - }; - int rc = syscall(SC_symlink, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("symlink", rc, {}); -#else ByteString target_string = target; ByteString link_path_string = link_path; if (::symlink(target_string.characters(), link_path_string.characters()) < 0) return Error::from_syscall("symlink"sv, -errno); return {}; -#endif } ErrorOr mkdir(StringView path, mode_t mode) { if (path.is_null()) return Error::from_errno(EFAULT); -#ifdef AK_OS_SERENITY - int rc = syscall(SC_mkdir, AT_FDCWD, path.characters_without_null_termination(), path.length(), mode); - HANDLE_SYSCALL_RETURN_VALUE("mkdir", rc, {}); -#else ByteString path_string = path; if (::mkdir(path_string.characters(), mode) < 0) return Error::from_syscall("mkdir"sv, -errno); return {}; -#endif } ErrorOr chdir(StringView path) { if (path.is_null()) return Error::from_errno(EFAULT); -#ifdef AK_OS_SERENITY - int rc = syscall(SC_chdir, path.characters_without_null_termination(), path.length()); - HANDLE_SYSCALL_RETURN_VALUE("chdir", rc, {}); -#else ByteString path_string = path; if (::chdir(path_string.characters()) < 0) return Error::from_syscall("chdir"sv, -errno); return {}; -#endif } ErrorOr rmdir(StringView path) { if (path.is_null()) return Error::from_errno(EFAULT); -#ifdef AK_OS_SERENITY - int rc = syscall(SC_rmdir, path.characters_without_null_termination(), path.length()); - HANDLE_SYSCALL_RETURN_VALUE("rmdir", rc, {}); -#else ByteString path_string = path; if (::rmdir(path_string.characters()) < 0) return Error::from_syscall("rmdir"sv, -errno); return {}; -#endif } ErrorOr fork() @@ -1148,22 +805,11 @@ ErrorOr rename(StringView old_path, StringView new_path) if (old_path.is_null() || new_path.is_null()) return Error::from_errno(EFAULT); -#ifdef AK_OS_SERENITY - Syscall::SC_rename_params params { - .olddirfd = AT_FDCWD, - .old_path = { old_path.characters_without_null_termination(), old_path.length() }, - .newdirfd = AT_FDCWD, - .new_path = { new_path.characters_without_null_termination(), new_path.length() }, - }; - int rc = syscall(SC_rename, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("rename", rc, {}); -#else ByteString old_path_string = old_path; ByteString new_path_string = new_path; if (::rename(old_path_string.characters(), new_path_string.characters()) < 0) return Error::from_syscall("rename"sv, -errno); return {}; -#endif } ErrorOr unlink(StringView path) @@ -1171,15 +817,10 @@ ErrorOr unlink(StringView path) if (path.is_null()) return Error::from_errno(EFAULT); -#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 ByteString path_string = path; if (::unlink(path_string.characters()) < 0) return Error::from_syscall("unlink"sv, -errno); return {}; -#endif } ErrorOr utime(StringView path, Optional maybe_buf) @@ -1190,15 +831,10 @@ ErrorOr utime(StringView path, Optional maybe_buf) struct utimbuf* buf = nullptr; if (maybe_buf.has_value()) buf = &maybe_buf.value(); -#ifdef AK_OS_SERENITY - int rc = syscall(SC_utime, path.characters_without_null_termination(), path.length(), buf); - HANDLE_SYSCALL_RETURN_VALUE("utime", rc, {}); -#else ByteString path_string = path; if (::utime(path_string.characters(), buf) < 0) return Error::from_syscall("utime"sv, -errno); return {}; -#endif } ErrorOr utimensat(int fd, StringView path, struct timespec const times[2], int flag) @@ -1206,40 +842,6 @@ ErrorOr utimensat(int fd, StringView path, struct timespec const times[2], if (path.is_null()) return Error::from_errno(EFAULT); -#ifdef AK_OS_SERENITY - // POSIX allows AT_SYMLINK_NOFOLLOW flag or no flags. - if (flag & ~AT_SYMLINK_NOFOLLOW) - return Error::from_errno(EINVAL); - - // Return early without error since both changes are to be omitted. - if (times && times[0].tv_nsec == UTIME_OMIT && times[1].tv_nsec == UTIME_OMIT) - return {}; - - // According to POSIX, when times is a nullptr, it's equivalent to setting - // both last access time and last modification time to the current time. - // Setting the times argument to nullptr if it matches this case prevents - // the need to copy it in the kernel. - if (times && times[0].tv_nsec == UTIME_NOW && times[1].tv_nsec == UTIME_NOW) - times = nullptr; - - if (times) { - for (int i = 0; i < 2; ++i) { - if ((times[i].tv_nsec != UTIME_NOW && times[i].tv_nsec != UTIME_OMIT) - && (times[i].tv_nsec < 0 || times[i].tv_nsec >= 1'000'000'000L)) { - return Error::from_errno(EINVAL); - } - } - } - - Syscall::SC_utimensat_params params { - .dirfd = fd, - .path = { path.characters_without_null_termination(), path.length() }, - .times = times, - .flag = flag, - }; - int rc = syscall(SC_utimensat, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("utimensat", rc, {}); -#else auto builder = TRY(StringBuilder::create()); TRY(builder.try_append(path)); TRY(builder.try_append('\0')); @@ -1248,125 +850,27 @@ ErrorOr utimensat(int fd, StringView path, struct timespec const times[2], if (::utimensat(fd, builder.string_view().characters_without_null_termination(), times, flag) < 0) return Error::from_syscall("utimensat"sv, -errno); return {}; -#endif } ErrorOr uname() { struct utsname uts; -#ifdef AK_OS_SERENITY - int rc = syscall(SC_uname, &uts); - HANDLE_SYSCALL_RETURN_VALUE("uname", rc, uts); -#else if (::uname(&uts) < 0) return Error::from_syscall("uname"sv, -errno); -#endif return uts; } #if !defined(AK_OS_ANDROID) && !defined(AK_OS_HAIKU) ErrorOr adjtime(const struct timeval* delta, struct timeval* old_delta) { -# ifdef AK_OS_SERENITY - int rc = syscall(SC_adjtime, delta, old_delta); - HANDLE_SYSCALL_RETURN_VALUE("adjtime", rc, {}); -# else if (::adjtime(delta, old_delta) < 0) return Error::from_syscall("adjtime"sv, -errno); return {}; -# endif -} -#endif - -#ifdef AK_OS_SERENITY -ErrorOr exec_command(Vector& command, bool preserve_env) -{ - Vector exec_environment; - for (auto entry : Environment::entries()) { - // FIXME: Allow a custom selection of variables once ArgsParser supports options with optional parameters. - if (!preserve_env && entry.name != "TERM"sv) - continue; - - exec_environment.append(entry.full_entry); - } - - TRY(Core::System::exec(command.at(0), command, Core::System::SearchInPath::Yes, exec_environment)); - return {}; -} - -ErrorOr join_jail(u64 jail_index) -{ - Syscall::SC_jail_attach_params params { jail_index }; - int rc = syscall(SC_jail_attach, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("jail_attach", rc, {}); -} - -ErrorOr create_jail(StringView jail_name, JailIsolationFlags flags) -{ - Syscall::SC_jail_create_params params { 0, { jail_name.characters_without_null_termination(), jail_name.length() }, static_cast(flags) }; - int rc = syscall(SC_jail_create, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("jail_create", rc, static_cast(params.index)); } #endif ErrorOr exec(StringView filename, ReadonlySpan arguments, SearchInPath search_in_path, Optional> environment) { -#ifdef AK_OS_SERENITY - Syscall::SC_execve_params params; - - auto argument_strings = TRY(FixedArray::create(arguments.size())); - for (size_t i = 0; i < arguments.size(); ++i) { - argument_strings[i] = { arguments[i].characters_without_null_termination(), arguments[i].length() }; - } - params.arguments.strings = argument_strings.data(); - params.arguments.length = argument_strings.size(); - - size_t env_count = 0; - if (environment.has_value()) { - env_count = environment->size(); - } else { - env_count = Core::Environment::size(); - } - - auto environment_strings = TRY(FixedArray::create(env_count)); - if (environment.has_value()) { - for (size_t i = 0; i < env_count; ++i) { - environment_strings[i] = { environment->at(i).characters_without_null_termination(), environment->at(i).length() }; - } - } else { - size_t i = 0; - for (auto entry : Core::Environment::entries()) { - environment_strings[i++] = { entry.full_entry.characters_without_null_termination(), entry.full_entry.length() }; - } - } - params.environment.strings = environment_strings.data(); - params.environment.length = environment_strings.size(); - - auto run_exec = [](Syscall::SC_execve_params& params) -> ErrorOr { - int rc = syscall(Syscall::SC_execve, ¶ms); - if (rc < 0) - return Error::from_syscall("exec"sv, rc); - return {}; - }; - - StringView exec_filename; - String resolved_executable_path; - if (search_in_path == SearchInPath::Yes) { - auto executable_or_error = resolve_executable_from_environment(filename); - - if (executable_or_error.is_error()) - return executable_or_error.release_error(); - - resolved_executable_path = executable_or_error.release_value(); - exec_filename = resolved_executable_path; - } else { - exec_filename = filename; - } - - params.path = { exec_filename.characters_without_null_termination(), exec_filename.length() }; - TRY(run_exec(params)); - VERIFY_NOT_REACHED(); -#else ByteString filename_string { filename }; auto argument_strings = TRY(FixedArray::create(arguments.size())); @@ -1388,7 +892,7 @@ ErrorOr exec(StringView filename, ReadonlySpan arguments, Sear envp[environment->size()] = nullptr; if (search_in_path == SearchInPath::Yes && !filename.contains('/')) { -# if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_FREEBSD) || defined(AK_OS_SOLARIS) +#if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_FREEBSD) || defined(AK_OS_SOLARIS) // These BSDs don't support execvpe(), so we'll have to manually search the PATH. ScopedValueRollback errno_rollback(errno); @@ -1401,9 +905,9 @@ ErrorOr exec(StringView filename, ReadonlySpan arguments, Sear ByteString executable = executable_or_error.release_value().to_byte_string(); rc = ::execve(executable.characters(), argv.data(), envp.data()); -# else +#else rc = ::execvpe(filename_string.characters(), argv.data(), envp.data()); -# endif +#endif } else { rc = ::execve(filename_string.characters(), argv.data(), envp.data()); } @@ -1418,7 +922,6 @@ ErrorOr exec(StringView filename, ReadonlySpan arguments, Sear if (rc < 0) return Error::from_syscall("exec"sv, rc); VERIFY_NOT_REACHED(); -#endif } ErrorOr socket(int domain, int type, int protocol) @@ -1628,16 +1131,10 @@ ErrorOr mknod(StringView pathname, mode_t mode, dev_t dev) if (pathname.is_null()) return Error::from_syscall("mknod"sv, -EFAULT); -#ifdef AK_OS_SERENITY - Syscall::SC_mknod_params params { { pathname.characters_without_null_termination(), pathname.length() }, mode, dev, AT_FDCWD }; - int rc = syscall(SC_mknod, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("mknod", rc, {}); -#else ByteString path_string = pathname; if (::mknod(path_string.characters(), mode, dev) < 0) return Error::from_syscall("mknod"sv, -errno); return {}; -#endif } ErrorOr mkfifo(StringView pathname, mode_t mode) @@ -1674,37 +1171,17 @@ ErrorOr access(StringView pathname, int mode, int flags) if (pathname.is_null()) return Error::from_syscall("access"sv, -EFAULT); -#ifdef AK_OS_SERENITY - Syscall::SC_faccessat_params params { - .dirfd = AT_FDCWD, - .pathname = { pathname.characters_without_null_termination(), pathname.length() }, - .mode = mode, - .flags = flags, - }; - int rc = ::syscall(Syscall::SC_faccessat, ¶ms); - HANDLE_SYSCALL_RETURN_VALUE("access", rc, {}); -#else ByteString path_string = pathname; (void)flags; if (::access(path_string.characters(), mode) < 0) return Error::from_syscall("access"sv, -errno); return {}; -#endif } ErrorOr readlink(StringView pathname) { // FIXME: Try again with a larger buffer. -#ifdef AK_OS_SERENITY - char data[PATH_MAX]; - Syscall::SC_readlink_params small_params { - .path = { pathname.characters_without_null_termination(), pathname.length() }, - .buffer = { data, sizeof(data) }, - .dirfd = AT_FDCWD, - }; - int rc = syscall(SC_readlink, &small_params); - HANDLE_SYSCALL_RETURN_VALUE("readlink", rc, ByteString(data, rc)); -#elif defined(AK_OS_GNU_HURD) +#if defined(AK_OS_GNU_HURD) // PATH_MAX is not defined, nor is there an upper limit on path lengths. // Let's do this the right way. int fd = TRY(open(pathname, O_READ | O_NOLINK)); @@ -1731,16 +1208,6 @@ ErrorOr poll(Span poll_fds, int timeout) return { rc }; } -#ifdef AK_OS_SERENITY -ErrorOr posix_fallocate(int fd, off_t offset, off_t length) -{ - int rc = ::posix_fallocate(fd, offset, length); - if (rc != 0) - return Error::from_syscall("posix_fallocate"sv, -rc); - return {}; -} -#endif - // This constant is copied from LibFileSystem. We cannot use or even include it directly, // because that would cause a dependency of LibCore on LibFileSystem, effectively rendering // the distinction between these libraries moot. @@ -1784,7 +1251,7 @@ ErrorOr resolve_executable_from_environment(StringView filename, int fla ErrorOr current_executable_path() { char path[4096] = {}; -#if defined(AK_OS_LINUX) || defined(AK_OS_ANDROID) || defined(AK_OS_SERENITY) +#if defined(AK_OS_LINUX) || defined(AK_OS_ANDROID) auto ret = ::readlink("/proc/self/exe", path, sizeof(path) - 1); // Ignore error if it wasn't a symlink if (ret == -1 && errno != EINVAL) diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 24f1f07223706..1567cdd4640f4 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -31,10 +31,6 @@ #include #include -#ifdef AK_OS_SERENITY -# include -#endif - #if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID) # include #endif @@ -50,32 +46,11 @@ namespace Core::System { -#ifdef AK_OS_SERENITY -ErrorOr beep(u16 tone = 440, u16 milliseconds_duration = 200); -ErrorOr pledge(StringView promises, StringView execpromises = {}); -ErrorOr unveil(StringView path, StringView permissions); -ErrorOr unveil_after_exec(StringView path, StringView permissions); -ErrorOr sendfd(int sockfd, int fd); -ErrorOr recvfd(int sockfd, int options); -ErrorOr ptrace_peekbuf(pid_t tid, void const* tracee_addr, Bytes destination_buf); -ErrorOr mount(int source_fd, StringView target, StringView fs_type, int flags); -ErrorOr bindmount(int source_fd, StringView target, int flags); -ErrorOr fsopen(StringView fs_type, int flags); -ErrorOr fsmount(int mount_fd, int source_fd, StringView target_path); -ErrorOr remount(StringView target, int flags); -ErrorOr umount(StringView mount_point); -ErrorOr ptrace(int request, pid_t tid, void* address, void* data); -ErrorOr disown(pid_t pid); -ErrorOr profiling_enable(pid_t, u64 event_mask); -ErrorOr profiling_disable(pid_t); -ErrorOr profiling_free_buffer(pid_t); -#else inline ErrorOr unveil(StringView, StringView) { return {}; } inline ErrorOr pledge(StringView, StringView = {}) { return {}; } -#endif template ALWAYS_INLINE ErrorOr pledge(char const (&promises)[N]) @@ -201,17 +176,8 @@ enum class SearchInPath { Yes, }; -#ifdef AK_OS_SERENITY -ErrorOr exec_command(Vector& command, bool preserve_env); -#endif - ErrorOr exec(StringView filename, ReadonlySpan arguments, SearchInPath, Optional> environment = {}); -#ifdef AK_OS_SERENITY -ErrorOr join_jail(u64 jail_index); -ErrorOr create_jail(StringView jail_name, JailIsolationFlags); -#endif - ErrorOr socket(int domain, int type, int protocol); ErrorOr bind(int sockfd, struct sockaddr const*, socklen_t); ErrorOr listen(int sockfd, int backlog); @@ -240,11 +206,6 @@ ErrorOr access(StringView pathname, int mode, int flags = 0); ErrorOr readlink(StringView pathname); ErrorOr poll(Span, int timeout); -#ifdef AK_OS_SERENITY -ErrorOr create_block_device(StringView name, mode_t mode, unsigned major, unsigned minor); -ErrorOr create_char_device(StringView name, mode_t mode, unsigned major, unsigned minor); -#endif - class AddressInfoVector { AK_MAKE_NONCOPYABLE(AddressInfoVector); AK_MAKE_DEFAULT_MOVABLE(AddressInfoVector); @@ -277,10 +238,6 @@ class AddressInfoVector { ErrorOr getaddrinfo(char const* nodename, char const* servname, struct addrinfo const& hints); -#ifdef AK_OS_SERENITY -ErrorOr posix_fallocate(int fd, off_t offset, off_t length); -#endif - unsigned hardware_concurrency(); ErrorOr resolve_executable_from_environment(StringView filename, int flags = 0); diff --git a/Userland/Libraries/LibCore/Version.cpp b/Userland/Libraries/LibCore/Version.cpp index 2f7d3c0dbd8cd..8f5b646c734a9 100644 --- a/Userland/Libraries/LibCore/Version.cpp +++ b/Userland/Libraries/LibCore/Version.cpp @@ -7,27 +7,11 @@ #include #include -#ifdef AK_OS_SERENITY -# include -#endif - namespace Core::Version { ErrorOr read_long_version_string() { -#ifdef AK_OS_SERENITY - struct utsname uts; - int rc = uname(&uts); - if ((rc) < 0) { - return Error::from_syscall("uname"sv, rc); - } - auto const* version = uts.release; - auto const* git_hash = uts.version; - - return String::formatted("Version {} revision {}", version, git_hash); -#else return "Version 1.0"_string; -#endif } } diff --git a/Userland/Libraries/LibWeb/Loader/UserAgent.h b/Userland/Libraries/LibWeb/Loader/UserAgent.h index ad75fd8928fed..8ada7e2d5dc9b 100644 --- a/Userland/Libraries/LibWeb/Loader/UserAgent.h +++ b/Userland/Libraries/LibWeb/Loader/UserAgent.h @@ -23,9 +23,7 @@ namespace Web { # error Unknown architecture #endif -#if defined(AK_OS_SERENITY) -# define OS_STRING "SerenityOS" -#elif defined(AK_OS_ANDROID) +#if defined(AK_OS_ANDROID) # define OS_STRING "Android 10" #elif defined(AK_OS_LINUX) # define OS_STRING "Linux"