diff --git a/AK/Assertions.cpp b/AK/Assertions.cpp index 57ea335a979..407634e18a3 100644 --- a/AK/Assertions.cpp +++ b/AK/Assertions.cpp @@ -33,9 +33,7 @@ # define ERRORLN warnln #endif -#if !defined(KERNEL) - -# if defined(EXECINFO_BACKTRACE) +#if defined(EXECINFO_BACKTRACE) namespace { ALWAYS_INLINE void dump_backtrace() { @@ -74,39 +72,37 @@ ALWAYS_INLINE void dump_backtrace() } else { error_builder.append(sym); } -# if !defined(AK_OS_ANDROID) +# if !defined(AK_OS_ANDROID) error_builder.append('\n'); -# endif +# endif error_builder.append('\0'); PRINT_ERROR(error_builder.string_view().characters_without_null_termination()); } free(syms); } } -# endif +#endif extern "C" { void ak_verification_failed(char const* message) { -# if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID) +#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID) bool colorize_output = true; -# elif defined(AK_OS_WINDOWS) +#elif defined(AK_OS_WINDOWS) bool colorize_output = false; -# else +#else bool colorize_output = isatty(STDERR_FILENO) == 1; -# endif +#endif if (colorize_output) ERRORLN("\033[31;1mVERIFICATION FAILED\033[0m: {}", message); else ERRORLN("VERIFICATION FAILED: {}", message); -# if defined(EXECINFO_BACKTRACE) +#if defined(EXECINFO_BACKTRACE) dump_backtrace(); -# endif +#endif __builtin_trap(); } } - -#endif diff --git a/AK/Assertions.h b/AK/Assertions.h index 53766c2994d..200e47cbd14 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -6,19 +6,15 @@ #pragma once -#if defined(KERNEL) -# include -#else extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*); -# define __stringify_helper(x) #x -# define __stringify(x) __stringify_helper(x) -# define VERIFY(expr) \ - (__builtin_expect(!(expr), 0) \ - ? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \ - : (void)0) -# define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ +#define __stringify_helper(x) #x +#define __stringify(x) __stringify_helper(x) +#define VERIFY(expr) \ + (__builtin_expect(!(expr), 0) \ + ? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \ + : (void)0) +#define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ static constexpr bool TODO = false; -# define TODO() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ -# define TODO_AARCH64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ -# define TODO_RISCV64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ -#endif +#define TODO() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ +#define TODO_AARCH64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ +#define TODO_RISCV64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ diff --git a/AK/Demangle.h b/AK/Demangle.h index 3321256f451..378d7de7fe6 100644 --- a/AK/Demangle.h +++ b/AK/Demangle.h @@ -6,11 +6,9 @@ #pragma once -#ifndef KERNEL - -# include -# include -# include +#include +#include +#include namespace AK { @@ -26,8 +24,6 @@ inline ByteString demangle(StringView name) } -# if USING_AK_GLOBALLY +#if USING_AK_GLOBALLY using AK::demangle; -# endif - #endif diff --git a/AK/DoublyLinkedList.h b/AK/DoublyLinkedList.h index c536d40354f..7d02b0a47eb 100644 --- a/AK/DoublyLinkedList.h +++ b/AK/DoublyLinkedList.h @@ -134,7 +134,6 @@ public: return {}; } -#ifndef KERNEL template void append(U&& value) { @@ -146,7 +145,6 @@ public: { MUST(try_prepend(forward(value))); } -#endif [[nodiscard]] bool contains_slow(T const& value) const { diff --git a/AK/Error.cpp b/AK/Error.cpp index df2e9a19865..882c00d350c 100644 --- a/AK/Error.cpp +++ b/AK/Error.cpp @@ -6,20 +6,11 @@ #include -#ifdef KERNEL -# include -#endif - namespace AK { Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code) { -#ifdef KERNEL - dmesgln("{}", string_literal); - return Error::from_errno(code); -#else return Error::from_string_view(string_literal); -#endif } } diff --git a/AK/Error.h b/AK/Error.h index 9ed9a53124a..f8b60690ad8 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -9,13 +9,8 @@ #include #include #include - -#if defined(AK_OS_SERENITY) && defined(KERNEL) -# include -#else -# include -# include -#endif +#include +#include namespace AK { @@ -36,7 +31,6 @@ public: // the Error::from_string_view method! static Error from_string_view_or_print_error_and_return_errno(StringView string_literal, int code); -#ifndef KERNEL static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); @@ -52,14 +46,11 @@ public: VERIFY_NOT_REACHED(); } -#endif - static Error copy(Error const& error) { return Error(error); } -#ifndef KERNEL // NOTE: Prefer `from_string_literal` when directly typing out an error message: // // return Error::from_string_literal("Class: Some failure"); @@ -78,15 +69,10 @@ public: { return from_string_view(string); } -#endif bool operator==(Error const& other) const { -#ifdef KERNEL - return m_code == other.m_code; -#else return m_code == other.m_code && m_string_literal == other.m_string_literal && m_syscall == other.m_syscall; -#endif } int code() const { return m_code; } @@ -94,7 +80,6 @@ public: { return m_code != 0; } -#ifndef KERNEL bool is_syscall() const { return m_syscall; @@ -103,7 +88,6 @@ public: { return m_string_literal; } -#endif protected: Error(int code) @@ -112,7 +96,6 @@ protected: } private: -#ifndef KERNEL Error(StringView string_literal) : m_string_literal(string_literal) { @@ -124,20 +107,15 @@ private: , m_syscall(true) { } -#endif Error(Error const&) = default; Error& operator=(Error const&) = default; -#ifndef KERNEL StringView m_string_literal; -#endif int m_code { 0 }; -#ifndef KERNEL bool m_syscall { false }; -#endif }; template diff --git a/AK/FixedPoint.h b/AK/FixedPoint.h index 708aefdabb7..a11077b4091 100644 --- a/AK/FixedPoint.h +++ b/AK/FixedPoint.h @@ -9,12 +9,10 @@ #include #include #include +#include #include #include -#ifndef KERNEL -# include -#endif #ifndef __SIZEOF_INT128__ # include # include @@ -45,13 +43,11 @@ public: { } -#ifndef KERNEL template FixedPoint(F value) : m_value(round_to(value * (static_cast(1) << precision))) { } -#endif template explicit constexpr FixedPoint(FixedPoint const& other) @@ -59,13 +55,11 @@ public: { } -#ifndef KERNEL template explicit ALWAYS_INLINE operator F() const { return (F)m_value * pow(0.5, precision); } -#endif template explicit constexpr operator I() const diff --git a/AK/FloatingPointStringConversions.h b/AK/FloatingPointStringConversions.h index d2c51bac3bc..9181889a69c 100644 --- a/AK/FloatingPointStringConversions.h +++ b/AK/FloatingPointStringConversions.h @@ -6,11 +6,6 @@ #pragma once -#ifdef KERNEL -# error This file should not be included in the KERNEL as it deals with doubles \ - and there is no guraantee does not do any floating point computations. -#endif - #include namespace AK { diff --git a/AK/Format.cpp b/AK/Format.cpp index cc59e4bd3b6..181398145af 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -8,34 +8,24 @@ #include #include #include +#include #include #include +#include #include +#include +#include +#include +#include -#if defined(AK_OS_SERENITY) && !defined(KERNEL) +#if defined(AK_OS_SERENITY) # include #endif -#ifdef KERNEL -# include -# include -# include -#else -# include -# include -# include -# include -# include -#endif - #if defined(AK_OS_ANDROID) # include #endif -#ifndef KERNEL -# include -#endif - namespace AK { class FormatParser : public GenericLexer { @@ -452,7 +442,6 @@ ErrorOr FormatBuilder::put_fixed_point( return {}; } -#ifndef KERNEL static ErrorOr round_up_digits(StringBuilder& digits_builder) { auto digits_buffer = TRY(digits_builder.to_byte_buffer()); @@ -746,8 +735,6 @@ ErrorOr FormatBuilder::put_f80( return {}; } -#endif - ErrorOr FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill) { auto put_char_view = [&](auto i) -> ErrorOr { @@ -991,7 +978,6 @@ ErrorOr Formatter::format(FormatBuilder& builder, bool value) return formatter.format(builder, value ? "true"sv : "false"sv); } } -#ifndef KERNEL ErrorOr Formatter::format(FormatBuilder& builder, long double value) { u8 base; @@ -1070,9 +1056,7 @@ ErrorOr Formatter::format(FormatBuilder& builder, float value) template ErrorOr FormatBuilder::put_f32_or_f64(float, u8, bool, bool, bool, Align, size_t, Optional, char, SignMode, RealNumberDisplayMode); template ErrorOr FormatBuilder::put_f32_or_f64(double, u8, bool, bool, bool, Align, size_t, Optional, char, SignMode, RealNumberDisplayMode); -#endif -#ifndef KERNEL void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline) { StringBuilder builder; @@ -1088,7 +1072,6 @@ void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool ne dbgln("vout() failed ({} written out of {}), error was {} ({})", retval, string.length(), error, strerror(error)); } } -#endif #ifdef AK_OS_ANDROID static char const* s_log_tag_name = "Serenity"; @@ -1129,25 +1112,24 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params, #endif -#ifndef KERNEL // FIXME: Deduplicate with Core::Process:get_name() [[gnu::used]] static ByteString process_name_helper() { -# if defined(AK_OS_SERENITY) +#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)) +#elif 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) +#elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) auto const* progname = getprogname(); return StringView { progname, strlen(progname) }; -# else +#else // FIXME: Implement process_name_helper() for other platforms. return StringView {}; -# endif +#endif } static StringView process_name_for_logging() @@ -1165,7 +1147,6 @@ static StringView process_name_for_logging() } return process_name; } -#endif static bool is_debug_enabled = true; @@ -1195,21 +1176,7 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) StringBuilder builder; if (is_rich_debug_enabled) { -#ifdef KERNEL - if (Kernel::Processor::is_initialized() && TimeManagement::is_initialized()) { - auto time = TimeManagement::the().monotonic_time(TimePrecision::Coarse); - if (Kernel::Thread::current()) { - auto& thread = *Kernel::Thread::current(); - thread.process().name().with([&](auto& process_name) { - builder.appendff("{}.{:03} \033[34;1m[#{} {}({}:{})]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, Kernel::Processor::current_id(), process_name.representable_view(), thread.pid().value(), thread.tid().value()); - }); - } else { - builder.appendff("{}.{:03} \033[34;1m[#{} Kernel]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, Kernel::Processor::current_id()); - } - } else { - builder.appendff("\033[34;1m[Kernel]\033[0m: "); - } -#elif !defined(AK_OS_WINDOWS) +#ifndef AK_OS_WINDOWS auto process_name = process_name_for_logging(); if (!process_name.is_empty()) { struct timespec ts = {}; @@ -1240,14 +1207,6 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) #endif auto const string = builder.string_view(); -#ifdef AK_OS_SERENITY -# ifdef KERNEL - if (!Kernel::Processor::is_initialized()) { - kernelearlyputstr(string.characters_without_null_termination(), string.length()); - return; - } -# endif -#endif #ifdef AK_OS_ANDROID __android_log_write(ANDROID_LOG_DEBUG, s_log_tag_name, string.characters_without_null_termination()); #else @@ -1255,61 +1214,6 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) #endif } -#ifdef KERNEL -void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params) -{ - StringBuilder builder; - -# ifdef AK_OS_SERENITY - if (TimeManagement::is_initialized()) { - auto time = TimeManagement::the().monotonic_time(TimePrecision::Coarse); - - if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) { - auto& thread = *Kernel::Thread::current(); - thread.process().name().with([&](auto& process_name) { - builder.appendff("{}.{:03} \033[34;1m[{}({}:{})]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000, process_name.representable_view(), thread.pid().value(), thread.tid().value()); - }); - } else { - builder.appendff("{}.{:03} \033[34;1m[Kernel]\033[0m: ", time.truncated_seconds(), time.nanoseconds_within_second() / 1000000); - } - } else { - builder.appendff("\033[34;1m[Kernel]\033[0m: "); - } -# endif - - MUST(vformat(builder, fmtstr, params)); - builder.append('\n'); - - auto const string = builder.string_view(); - kernelputstr(string.characters_without_null_termination(), string.length()); -} - -void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams& params) -{ - // FIXME: Try to avoid memory allocations further to prevent faulting - // at OOM conditions. - - StringBuilder builder; -# ifdef AK_OS_SERENITY - if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) { - auto& thread = *Kernel::Thread::current(); - thread.process().name().with([&](auto& process_name) { - builder.appendff("[{}({}:{})]: ", process_name.representable_view(), thread.pid().value(), thread.tid().value()); - }); - } else { - builder.appendff("[Kernel]: "); - } -# endif - - MUST(vformat(builder, fmtstr, params)); - builder.append('\n'); - - auto const string = builder.string_view(); - kernelcriticalputstr(string.characters_without_null_termination(), string.length()); -} - -#endif - template struct Formatter; template struct Formatter; template struct Formatter; diff --git a/AK/Format.h b/AK/Format.h index 0212d419f64..695522d3453 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -14,11 +14,8 @@ #include #include #include - -#ifndef KERNEL -# include -# include -#endif +#include +#include namespace AK { @@ -225,7 +222,6 @@ public: char fill = ' ', SignMode sign_mode = SignMode::OnlyIfNeeded); -#ifndef KERNEL ErrorOr put_f80( long double value, u8 base = 10, @@ -251,7 +247,6 @@ public: char fill = ' ', SignMode sign_mode = SignMode::OnlyIfNeeded, RealNumberDisplayMode = RealNumberDisplayMode::Default); -#endif ErrorOr put_hexdump( ReadonlyBytes, @@ -267,7 +262,6 @@ public: private: StringBuilder& m_builder; -#ifndef KERNEL ErrorOr put_f64_with_precision( double value, u8 base, @@ -280,7 +274,6 @@ private: char fill, SignMode sign_mode, RealNumberDisplayMode); -#endif }; class TypeErasedFormatParams { @@ -532,7 +525,6 @@ struct Formatter : StandardFormatter { ErrorOr format(FormatBuilder&, bool); }; -#ifndef KERNEL template<> struct Formatter : StandardFormatter { ErrorOr format(FormatBuilder&, float value); @@ -558,7 +550,6 @@ struct Formatter : StandardFormatter { ErrorOr format(FormatBuilder&, long double value); }; -#endif template<> struct Formatter : Formatter { @@ -573,7 +564,6 @@ struct Formatter : Formatter { ErrorOr vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&); -#if !defined(KERNEL) void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false); template @@ -592,7 +582,7 @@ void outln(FILE* file, CheckedFormatString&& fmtstr, Parameters c inline void outln(FILE* file) { fputc('\n', file); } -# ifndef AK_OS_ANDROID +#ifndef AK_OS_ANDROID template void out(CheckedFormatString&& fmtstr, Parameters const&... parameters) { @@ -614,7 +604,7 @@ template void warnln(CheckedFormatString&& fmtstr, Parameters const&... parameters) { outln(stderr, move(fmtstr), parameters...); } inline void warnln() { outln(stderr); } -# else // v Android ^ No Android +#else // v Android ^ No Android enum class LogLevel { Debug, Info, @@ -656,21 +646,19 @@ void warnln(CheckedFormatString&& fmtstr, Parameters const&... pa inline void warnln() { warnln(""); } void set_log_tag_name(char const*); -# endif // AK_OS_ANDROID +#endif // AK_OS_ANDROID -# define outln_if(flag, fmt, ...) \ - do { \ - if constexpr (flag) \ - outln(fmt, ##__VA_ARGS__); \ - } while (0) +#define outln_if(flag, fmt, ...) \ + do { \ + if constexpr (flag) \ + outln(fmt, ##__VA_ARGS__); \ + } while (0) -# define warnln_if(flag, fmt, ...) \ - do { \ - if constexpr (flag) \ - warnln(fmt, ##__VA_ARGS__); \ - } while (0) - -#endif +#define warnln_if(flag, fmt, ...) \ + do { \ + if constexpr (flag) \ + warnln(fmt, ##__VA_ARGS__); \ + } while (0) void vdbg(StringView fmtstr, TypeErasedFormatParams&, bool newline = false); @@ -693,28 +681,6 @@ inline void dbgln() { dbgln(""); } void set_debug_enabled(bool); void set_rich_debug_enabled(bool); -#ifdef KERNEL -void vdmesgln(StringView fmtstr, TypeErasedFormatParams&); - -template -void dmesgln(CheckedFormatString&& fmt, Parameters const&... parameters) -{ - VariadicFormatParams variadic_format_params { parameters... }; - vdmesgln(fmt.view(), variadic_format_params); -} - -void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams&); - -// be very careful to not cause any allocations here, since we could be in -// a very unstable situation -template -void critical_dmesgln(CheckedFormatString&& fmt, Parameters const&... parameters) -{ - VariadicFormatParams variadic_format_params { parameters... }; - v_critical_dmesgln(fmt.view(), variadic_format_params); -} -#endif - template class FormatIfSupported { public: @@ -765,16 +731,12 @@ template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Error const& error) { -#if defined(AK_OS_SERENITY) && defined(KERNEL) - return Formatter::format(builder, "Error(errno={})"sv, error.code()); -#else if (error.is_syscall()) return Formatter::format(builder, "{}: {} (errno={})"sv, error.string_literal(), strerror(error.code()), error.code()); if (error.is_errno()) return Formatter::format(builder, "{} (errno={})"sv, strerror(error.code()), error.code()); return Formatter::format(builder, "{}"sv, error.string_literal()); -#endif } }; @@ -803,16 +765,11 @@ struct Formatter> : Formatter { } // namespace AK #if USING_AK_GLOBALLY -# ifdef KERNEL -using AK::critical_dmesgln; -using AK::dmesgln; -# else using AK::out; using AK::outln; using AK::warn; using AK::warnln; -# endif using AK::dbg; using AK::dbgln; diff --git a/AK/Forward.h b/AK/Forward.h index afc4e18dbdb..475b878ecf0 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -122,17 +122,6 @@ class NonnullOwnPtr; template class Optional; -#ifdef KERNEL -template -class NonnullLockRefPtr; - -template -struct LockRefPtrTraits; - -template> -class LockRefPtr; -#endif - template class RefPtr; @@ -210,10 +199,4 @@ using AK::Utf8CodePointIterator; using AK::Utf8View; using AK::Vector; -# ifdef KERNEL -using AK::LockRefPtr; -using AK::LockRefPtrTraits; -using AK::NonnullLockRefPtr; -# endif - #endif diff --git a/AK/Function.h b/AK/Function.h index d3732cdb2a7..7643b227325 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -66,13 +66,8 @@ public: using FunctionType = Out(In...); using ReturnType = Out; -#ifdef KERNEL - constexpr static auto AccommodateExcessiveAlignmentRequirements = false; - constexpr static size_t ExcessiveAlignmentThreshold = alignof(void*); -#else constexpr static auto AccommodateExcessiveAlignmentRequirements = true; constexpr static size_t ExcessiveAlignmentThreshold = 16; -#endif Function() = default; Function(nullptr_t) @@ -261,18 +256,14 @@ private: } VERIFY(m_call_nesting_level == 0); using WrapperType = CallableWrapper; -#ifndef KERNEL if constexpr (alignof(Callable) > inline_alignment || sizeof(WrapperType) > inline_capacity) { *bit_cast(&m_storage) = new WrapperType(forward(callable)); m_kind = FunctionKind::Outline; } else { -#endif static_assert(sizeof(WrapperType) <= inline_capacity); new (m_storage) WrapperType(forward(callable)); m_kind = FunctionKind::Inline; -#ifndef KERNEL } -#endif if (callable_kind == CallableKind::FunctionObject) m_size = sizeof(WrapperType); else @@ -307,13 +298,8 @@ private: mutable Atomic m_call_nesting_level { 0 }; static constexpr size_t inline_alignment = max(alignof(CallableWrapperBase), alignof(CallableWrapperBase*)); -#ifndef KERNEL // Empirically determined to fit most lambdas and functions. static constexpr size_t inline_capacity = 4 * sizeof(void*); -#else - // FIXME: Try to decrease this. - static constexpr size_t inline_capacity = 6 * sizeof(void*); -#endif alignas(inline_alignment) u8 m_storage[inline_capacity]; }; diff --git a/AK/GenericLexer.cpp b/AK/GenericLexer.cpp index 09c912cb31f..dabeba3705f 100644 --- a/AK/GenericLexer.cpp +++ b/AK/GenericLexer.cpp @@ -5,15 +5,12 @@ */ #include +#include #include #include #include #include - -#ifndef KERNEL -# include -# include -#endif +#include namespace AK { // Consume a number of characters @@ -210,7 +207,6 @@ template ErrorOr GenericLexer::consume_decimal_integer(); template ErrorOr GenericLexer::consume_decimal_integer(); template ErrorOr GenericLexer::consume_decimal_integer(); -#ifndef KERNEL Optional GenericLexer::consume_and_unescape_string(char escape_char) { auto view = consume_quoted_string(escape_char); @@ -292,6 +288,5 @@ auto GenericLexer::decode_single_or_paired_surrogate(bool combine_surrogate_pair retreat(6); return *high_surrogate; } -#endif } diff --git a/AK/GenericLexer.h b/AK/GenericLexer.h index 89e6368e63a..71cfccef00b 100644 --- a/AK/GenericLexer.h +++ b/AK/GenericLexer.h @@ -92,14 +92,12 @@ public: return true; } -#ifndef KERNEL bool consume_specific(ByteString next) = delete; bool consume_specific(String const& next) { return consume_specific(next.bytes_as_string_view()); } -#endif constexpr bool consume_specific(char const* next) { @@ -128,9 +126,7 @@ public: StringView consume_until(char const*); StringView consume_until(StringView); StringView consume_quoted_string(char escape_char = 0); -#ifndef KERNEL Optional consume_and_unescape_string(char escape_char = '\\'); -#endif template ErrorOr consume_decimal_integer(); @@ -139,9 +135,7 @@ public: UnicodeEscapeOverflow, }; -#ifndef KERNEL Result consume_escaped_code_point(bool combine_surrogate_pairs = true); -#endif constexpr void ignore(size_t count = 1) { @@ -228,10 +222,8 @@ protected: size_t m_index { 0 }; private: -#ifndef KERNEL Result decode_code_point(); Result decode_single_or_paired_surrogate(bool combine_surrogate_pairs); -#endif }; class LineTrackingLexer : public GenericLexer { diff --git a/AK/Hex.cpp b/AK/Hex.cpp index 3bd1902d891..87141f8e687 100644 --- a/AK/Hex.cpp +++ b/AK/Hex.cpp @@ -34,17 +34,6 @@ ErrorOr decode_hex(StringView input) return { move(output) }; } -#ifdef KERNEL -ErrorOr> encode_hex(ReadonlyBytes const input) -{ - StringBuilder output(input.size() * 2); - - for (auto ch : input) - TRY(output.try_appendff("{:02x}", ch)); - - return Kernel::KString::try_create(output.string_view()); -} -#else ByteString encode_hex(ReadonlyBytes const input) { StringBuilder output(input.size() * 2); @@ -54,6 +43,5 @@ ByteString encode_hex(ReadonlyBytes const input) return output.to_byte_string(); } -#endif } diff --git a/AK/Hex.h b/AK/Hex.h index 6c56480166c..5bd2f1e84db 100644 --- a/AK/Hex.h +++ b/AK/Hex.h @@ -7,15 +7,10 @@ #pragma once #include +#include #include #include -#ifdef KERNEL -# include -#else -# include -#endif - namespace AK { constexpr u8 decode_hex_digit(char digit) @@ -31,11 +26,7 @@ constexpr u8 decode_hex_digit(char digit) ErrorOr decode_hex(StringView); -#ifdef KERNEL -ErrorOr> encode_hex(ReadonlyBytes); -#else ByteString encode_hex(ReadonlyBytes); -#endif } diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index a32653a2e2b..e3a844e81ec 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -6,21 +6,15 @@ #pragma once +#include #include #include #include #include +#include #include #include -#ifdef KERNEL -# include -# include -#else -# include -# include -#endif - namespace AK { class [[gnu::packed]] IPv4Address { @@ -57,16 +51,6 @@ public: return octet(SubnetClass(i)); } -#ifdef KERNEL - ErrorOr> to_string() const - { - return Kernel::KString::formatted("{}.{}.{}.{}", - octet(SubnetClass::A), - octet(SubnetClass::B), - octet(SubnetClass::C), - octet(SubnetClass::D)); - } -#else ByteString to_byte_string() const { return ByteString::formatted("{}.{}.{}.{}", @@ -93,7 +77,6 @@ public: octet(SubnetClass::C), octet(SubnetClass::D)); } -#endif static Optional from_string(StringView string) { @@ -166,15 +149,6 @@ struct Traits : public DefaultTraits { static unsigned hash(IPv4Address const& address) { return secure_sip_hash(static_cast(address.to_u32())); } }; -#ifdef KERNEL -template<> -struct Formatter : Formatter { - ErrorOr format(FormatBuilder& builder, IPv4Address value) - { - return Formatter::format(builder, TRY(value.to_string())->view()); - } -}; -#else template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, IPv4Address value) @@ -182,7 +156,6 @@ struct Formatter : Formatter { return Formatter::format(builder, value.to_byte_string()); } }; -#endif } diff --git a/AK/IPv6Address.h b/AK/IPv6Address.h index 2a3c9ea6f18..995bdd0add5 100644 --- a/AK/IPv6Address.h +++ b/AK/IPv6Address.h @@ -8,19 +8,13 @@ #include #include +#include #include +#include +#include #include #include -#ifdef KERNEL -# include -# include -#else -# include -#endif -#include -#include - namespace AK { class [[gnu::packed]] IPv6Address { @@ -48,28 +42,16 @@ public: constexpr u16 operator[](int i) const { return group(i); } -#ifdef KERNEL - ErrorOr> to_string() const -#else ErrorOr to_string() const -#endif { if (is_zero()) { -#ifdef KERNEL - return Kernel::KString::try_create("::"sv); -#else return "::"_string; -#endif } StringBuilder builder; if (is_ipv4_mapped()) { -#ifdef KERNEL - return Kernel::KString::formatted("::ffff:{}.{}.{}.{}", m_data[12], m_data[13], m_data[14], m_data[15]); -#else return String::formatted("::ffff:{}.{}.{}.{}", m_data[12], m_data[13], m_data[14], m_data[15]); -#endif } // Find the start of the longest span of 0 values @@ -112,11 +94,7 @@ public: i++; } -#ifdef KERNEL - return Kernel::KString::try_create(builder.string_view()); -#else return builder.to_string(); -#endif } static Optional from_string(StringView string) @@ -274,15 +252,6 @@ struct Traits : public DefaultTraits { static unsigned hash(IPv6Address const& address) { return sip_hash_bytes<4, 8>({ &address.to_in6_addr_t(), sizeof(address.to_in6_addr_t()) }); } }; -#ifdef KERNEL -template<> -struct Formatter : Formatter { - ErrorOr format(FormatBuilder& builder, IPv6Address const& value) - { - return Formatter::format(builder, TRY(value.to_string())->view()); - } -}; -#else template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, IPv6Address const& value) @@ -290,7 +259,6 @@ struct Formatter : Formatter { return Formatter::format(builder, TRY(value.to_string())); } }; -#endif } diff --git a/AK/IntrusiveDetails.h b/AK/IntrusiveDetails.h index 1a86543693b..180979b3739 100644 --- a/AK/IntrusiveDetails.h +++ b/AK/IntrusiveDetails.h @@ -8,9 +8,6 @@ #include -#ifdef KERNEL -# include -#endif namespace AK::Detail { template @@ -23,13 +20,6 @@ struct SubstituteIntrusiveContainerType> { using Type = RefPtr; }; -#ifdef KERNEL -template -struct SubstituteIntrusiveContainerType> { - using Type = LockRefPtr; -}; -#endif - template struct SelfReferenceIfNeeded { Container reference = nullptr; diff --git a/AK/IntrusiveList.h b/AK/IntrusiveList.h index b671a7a11c0..202745564f0 100644 --- a/AK/IntrusiveList.h +++ b/AK/IntrusiveList.h @@ -13,10 +13,6 @@ #include #include -#ifdef KERNEL -# include -#endif - namespace AK::Detail { template> @@ -436,22 +432,6 @@ public: [[nodiscard]] NonnullRefPtr take_last() { return *IntrusiveList, member>::take_last(); } }; -#ifdef KERNEL -// Specialise IntrusiveList for NonnullLockRefPtr -// By default, intrusive lists cannot contain null entries anyway, so switch to LockRefPtr -// and just make the user-facing functions deref the pointers. - -template> T::*member> -class IntrusiveList, member> : public IntrusiveList, member> { -public: - [[nodiscard]] NonnullLockRefPtr first() const { return *IntrusiveList, member>::first(); } - [[nodiscard]] NonnullLockRefPtr last() const { return *IntrusiveList, member>::last(); } - - [[nodiscard]] NonnullLockRefPtr take_first() { return *IntrusiveList, member>::take_first(); } - [[nodiscard]] NonnullLockRefPtr take_last() { return *IntrusiveList, member>::take_last(); } -}; -#endif - } namespace AK { diff --git a/AK/JsonArraySerializer.h b/AK/JsonArraySerializer.h index 383d420a9ec..93be8dc0e78 100644 --- a/AK/JsonArraySerializer.h +++ b/AK/JsonArraySerializer.h @@ -8,12 +8,9 @@ #pragma once #include +#include #include -#ifndef KERNEL -# include -#endif - namespace AK { template @@ -43,14 +40,12 @@ public: JsonArraySerializer(JsonArraySerializer const&) = delete; -#ifndef KERNEL ErrorOr add(JsonValue const& value) { TRY(begin_item()); value.serialize(m_builder); return {}; } -#endif ErrorOr add(StringView value) { @@ -67,7 +62,6 @@ public: return {}; } -#ifndef KERNEL ErrorOr add(ByteString const& value) { TRY(begin_item()); @@ -82,7 +76,6 @@ public: } return {}; } -#endif ErrorOr add(char const* value) { diff --git a/AK/JsonObject.cpp b/AK/JsonObject.cpp index 8ac0cce83a5..fa7628dd131 100644 --- a/AK/JsonObject.cpp +++ b/AK/JsonObject.cpp @@ -108,7 +108,6 @@ Optional JsonObject::get_bool(StringView key) const return {}; } -#if !defined(KERNEL) Optional JsonObject::get_byte_string(StringView key) const { auto maybe_value = get(key); @@ -116,7 +115,6 @@ Optional JsonObject::get_byte_string(StringView key) const return maybe_value->as_string(); return {}; } -#endif Optional JsonObject::get_object(StringView key) const { @@ -134,7 +132,6 @@ Optional JsonObject::get_array(StringView key) const return {}; } -#if !defined(KERNEL) Optional JsonObject::get_double_with_precision_loss(StringView key) const { auto maybe_value = get(key); @@ -150,7 +147,6 @@ Optional JsonObject::get_float_with_precision_loss(StringView key) const return maybe_value->get_float_with_precision_loss(); return {}; } -#endif bool JsonObject::has(StringView key) const { diff --git a/AK/JsonObject.h b/AK/JsonObject.h index e6df653cb84..5d360b039fb 100644 --- a/AK/JsonObject.h +++ b/AK/JsonObject.h @@ -74,17 +74,13 @@ public: Optional get_addr(StringView key) const; Optional get_bool(StringView key) const; -#if !defined(KERNEL) Optional get_byte_string(StringView key) const; -#endif Optional get_object(StringView key) const; Optional get_array(StringView key) const; -#if !defined(KERNEL) Optional get_double_with_precision_loss(StringView key) const; Optional get_float_with_precision_loss(StringView key) const; -#endif void set(ByteString const& key, JsonValue value); diff --git a/AK/JsonObjectSerializer.h b/AK/JsonObjectSerializer.h index d5f858830a3..7162ff6d80a 100644 --- a/AK/JsonObjectSerializer.h +++ b/AK/JsonObjectSerializer.h @@ -9,12 +9,9 @@ #include #include +#include #include -#ifndef KERNEL -# include -#endif - namespace AK { template @@ -38,14 +35,12 @@ public: JsonObjectSerializer(JsonObjectSerializer const&) = delete; -#ifndef KERNEL ErrorOr add(StringView key, JsonValue const& value) { TRY(begin_item(key)); value.serialize(m_builder); return {}; } -#endif ErrorOr add(StringView key, StringView value) { @@ -62,7 +57,6 @@ public: return {}; } -#ifndef KERNEL ErrorOr add(StringView key, ByteString const& value) { TRY(begin_item(key)); @@ -77,7 +71,6 @@ public: } return {}; } -#endif ErrorOr add(StringView key, char const* value) { @@ -164,7 +157,6 @@ public: return {}; } -#ifndef KERNEL ErrorOr add(StringView key, float value) { TRY(begin_item(key)); @@ -184,7 +176,6 @@ public: TRY(m_builder.appendff("{}", value)); return {}; } -#endif ErrorOr> add_array(StringView key) { diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 239077b247c..1cb59775a26 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -211,11 +211,6 @@ ErrorOr JsonParser::parse_number() } auto fallback_to_double_parse = [&]() -> ErrorOr { -#ifdef KERNEL -# error JSONParser is currently not available for the Kernel because it disallows floating point. \ - If you want to make this KERNEL compatible you can just make this fallback_to_double \ - function fail with an error in KERNEL mode. -#endif // FIXME: Since we know all the characters so far are ascii digits (and one . or e) we could // use that in the floating point parser. diff --git a/AK/JsonValue.h b/AK/JsonValue.h index fc6b84099d9..a173bc547dc 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -7,10 +7,6 @@ #pragma once -#ifdef KERNEL -# error "JsonValue does not propagate allocation failures, so it is not safe to use in the kernel." -#endif - #include #include #include diff --git a/AK/Math.h b/AK/Math.h index 99e839c6c04..77932d4edef 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -13,10 +13,6 @@ #include #include -#ifdef KERNEL -# error "Including AK/Math.h from the Kernel is never correct! Floating point is disabled." -#endif - namespace AK { template diff --git a/AK/Memory.h b/AK/Memory.h index 6b5bd69608f..3cd85fd37d2 100644 --- a/AK/Memory.h +++ b/AK/Memory.h @@ -8,12 +8,7 @@ #pragma once #include - -#if defined(KERNEL) -# include -#else -# include -#endif +#include ALWAYS_INLINE void fast_u32_copy(u32* dest, u32 const* src, size_t count) { diff --git a/AK/NoAllocationGuard.h b/AK/NoAllocationGuard.h index 27289a7bd60..8cc3c846bad 100644 --- a/AK/NoAllocationGuard.h +++ b/AK/NoAllocationGuard.h @@ -9,10 +9,7 @@ #include #include -#if defined(KERNEL) -# include -# include -#elif defined(AK_OS_SERENITY) +#if defined(AK_OS_SERENITY) # include #endif @@ -37,9 +34,7 @@ public: private: static bool get_thread_allocation_state() { -#if defined(KERNEL) - return Processor::current_thread()->get_allocation_enabled(); -#elif defined(AK_OS_SERENITY) +#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 @@ -49,9 +44,7 @@ private: static void set_thread_allocation_state(bool value) { -#if defined(KERNEL) - Processor::current_thread()->set_allocation_enabled(value); -#elif defined(AK_OS_SERENITY) +#if defined(AK_OS_SERENITY) s_allocation_enabled = value; #else (void)value; diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index e8ab1ab139e..ecb94cae329 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -136,8 +136,6 @@ private: T* m_ptr = nullptr; }; -#if !defined(KERNEL) - template inline NonnullOwnPtr adopt_own(T& object) { @@ -150,15 +148,13 @@ requires(IsConstructible) inline NonnullOwnPtr make(Args&&... arg return NonnullOwnPtr(NonnullOwnPtr::Adopt, *new T(forward(args)...)); } -# ifdef AK_COMPILER_APPLE_CLANG +#ifdef AK_COMPILER_APPLE_CLANG // FIXME: Remove once P0960R3 is available in Apple Clang. template inline NonnullOwnPtr make(Args&&... args) { return NonnullOwnPtr(NonnullOwnPtr::Adopt, *new T { forward(args)... }); } -# endif - #endif // Use like `adopt_nonnull_own_or_enomem(new (nothrow) T(args...))`. @@ -220,11 +216,9 @@ struct Formatter> : Formatter { } #if USING_AK_GLOBALLY -# if !defined(KERNEL) +using AK::adopt_nonnull_own_or_enomem; using AK::adopt_own; using AK::make; -# endif -using AK::adopt_nonnull_own_or_enomem; using AK::NonnullOwnPtr; using AK::try_make; #endif diff --git a/AK/NumericLimits.h b/AK/NumericLimits.h index 30db889cf3a..df04433b070 100644 --- a/AK/NumericLimits.h +++ b/AK/NumericLimits.h @@ -110,7 +110,6 @@ struct NumericLimits { static constexpr size_t digits() { return __CHAR_BIT__ * sizeof(long long); } }; -#ifndef KERNEL template<> struct NumericLimits { static constexpr float lowest() { return -__FLT_MAX__; } @@ -143,7 +142,6 @@ struct NumericLimits { static constexpr bool is_signed() { return true; } static constexpr size_t digits() { return __LDBL_MANT_DIG__; } }; -#endif } diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index ffaa6108576..12db1b35fb1 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -9,12 +9,9 @@ #include #include #include +#include #include - -#ifndef KERNEL -# include -# include -#endif +#include #ifdef AK_OS_SERENITY extern "C" size_t strlen(char const*); @@ -162,7 +159,6 @@ ALWAYS_INLINE int print_decimal(PutChFunc putch, CharType*& bufptr, u64 number, return field_width; } -#ifndef KERNEL template ALWAYS_INLINE int print_double(PutChFunc putch, CharType*& bufptr, double number, bool always_sign, bool left_pad, bool zero_pad, u32 field_width, u32 precision, bool trailing_zeros) { @@ -220,7 +216,6 @@ ALWAYS_INLINE int print_double(PutChFunc putch, CharType*& bufptr, double number return length; } -#endif template ALWAYS_INLINE int print_octal_number(PutChFunc putch, CharType*& bufptr, u64 number, bool alternate_form, bool left_pad, bool zero_pad, u32 field_width, bool has_precision, u32 precision) { @@ -349,14 +344,12 @@ struct PrintfImpl { // FIXME: Narrow characters should be converted to wide characters on the fly and vice versa. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wprintf.html -#ifndef KERNEL if (state.long_qualifiers) { wchar_t const* sp = NextArgument()(ap); if (!sp) sp = L"(null)"; return print_string(m_putch, m_bufptr, sp, wcslen(sp), state.left_pad, state.field_width, state.dot, state.precision, state.has_precision); } -#endif char const* sp = NextArgument()(ap); if (!sp) sp = "(null)"; @@ -398,7 +391,6 @@ struct PrintfImpl { { return print_hex(m_putch, m_bufptr, NextArgument()(ap), false, false, state.left_pad, state.zero_pad, 16, false, 1); } -#ifndef KERNEL ALWAYS_INLINE int format_g(ModifierState const& state, ArgumentListRefT ap) const { // FIXME: Exponent notation @@ -408,7 +400,6 @@ struct PrintfImpl { { return print_double(m_putch, m_bufptr, NextArgument()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.precision, true); } -#endif ALWAYS_INLINE int format_o(ModifierState const& state, ArgumentListRefT ap) const { return print_octal_number(m_putch, m_bufptr, NextArgument()(ap), state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision); @@ -592,10 +583,8 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, IdentityType* buffe PRINTF_IMPL_DELEGATE_TO_IMPL(X); PRINTF_IMPL_DELEGATE_TO_IMPL(c); PRINTF_IMPL_DELEGATE_TO_IMPL(d); -#ifndef KERNEL PRINTF_IMPL_DELEGATE_TO_IMPL(f); PRINTF_IMPL_DELEGATE_TO_IMPL(g); -#endif PRINTF_IMPL_DELEGATE_TO_IMPL(i); PRINTF_IMPL_DELEGATE_TO_IMPL(n); PRINTF_IMPL_DELEGATE_TO_IMPL(o); diff --git a/AK/Singleton.h b/AK/Singleton.h index f3c57e5f206..b1a0d5527f9 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -9,11 +9,7 @@ #include #include #include -#ifdef KERNEL -# include -# include -# include -#elif defined(AK_OS_WINDOWS) +#ifdef AK_OS_WINDOWS // Forward declare to avoid pulling Windows.h into every file in existence. extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long); # ifndef sched_yield @@ -37,17 +33,6 @@ struct SingletonInstanceCreator { } }; -#ifdef KERNEL - -template -struct SingletonInstanceCreator> { - static Kernel::SpinlockProtected* create() - { - return new Kernel::SpinlockProtected {}; - } -}; -#endif - template::create> class Singleton { AK_MAKE_NONCOPYABLE(Singleton); @@ -62,9 +47,6 @@ public: T* obj = obj_var.load(AK::memory_order_acquire); if (FlatPtr(obj) <= 0x1) { // If this is the first time, see if we get to initialize it -#ifdef KERNEL - Kernel::ScopedCritical critical; -#endif if constexpr (allow_create) { if (obj == nullptr && obj_var.compare_exchange_strong(obj, (T*)0x1, AK::memory_order_acq_rel)) { // We're the first one @@ -75,11 +57,7 @@ public: } // Someone else was faster, wait until they're done while (obj == (T*)0x1) { -#ifdef KERNEL - Kernel::Processor::wait_check(); -#else sched_yield(); -#endif obj = obj_var.load(AK::memory_order_acquire); } if constexpr (allow_create) { diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h index 319752cb204..9c600eb9472 100644 --- a/AK/SinglyLinkedList.h +++ b/AK/SinglyLinkedList.h @@ -181,7 +181,6 @@ public: return {}; } -#ifndef KERNEL template void append(U&& value) { @@ -193,7 +192,6 @@ public: { MUST(try_prepend(forward(value))); } -#endif bool contains_slow(T const& value) const { @@ -266,7 +264,6 @@ public: return {}; } -#ifndef KERNEL template void insert_before(Iterator iterator, U&& value) { @@ -278,7 +275,6 @@ public: { MUST(try_insert_after(iterator, forward(value))); } -#endif void remove(Iterator& iterator) { diff --git a/AK/SipHash.cpp b/AK/SipHash.cpp index fada0b2dccc..1ca6bdc8bb6 100644 --- a/AK/SipHash.cpp +++ b/AK/SipHash.cpp @@ -5,17 +5,12 @@ */ #include +#include #include #include #include #include -#ifdef KERNEL -# include -#else -# include -#endif - namespace AK { ALWAYS_INLINE constexpr u64 rotate_left(u64 x, u64 bits) @@ -137,12 +132,8 @@ static void do_siphash(ReadonlyBytes input, u128 key, Bytes output) struct SipHashKey { SipHashKey() { -#ifdef KERNEL - key = Kernel::get_good_random(); -#else // get_random is assumed to be secure, otherwise SipHash doesn't deliver on its promises! key = get_random(); -#endif } constexpr u128 operator*() const { return key; } u128 key; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index bf91f4a3879..bb337e326f0 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -201,11 +201,9 @@ requires(!IsIntegral) __DEFINE_GENERIC_ABS(int, 0, abs); __DEFINE_GENERIC_ABS(long, 0L, labs); __DEFINE_GENERIC_ABS(long long, 0LL, llabs); -#ifndef KERNEL __DEFINE_GENERIC_ABS(float, 0.0F, fabsf); __DEFINE_GENERIC_ABS(double, 0.0, fabs); __DEFINE_GENERIC_ABS(long double, 0.0L, fabsl); -#endif #undef __DEFINE_GENERIC_ABS diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index cdf8d2f5f62..1ec72b8492c 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -6,20 +6,17 @@ */ #include +#include #include +#include #include #include #include #include #include +#include #include -#ifndef KERNEL -# include -# include -# include -#endif - namespace AK { inline ErrorOr StringBuilder::will_append(size_t size) @@ -143,7 +140,6 @@ ErrorOr StringBuilder::to_byte_buffer() const return ByteBuffer::copy(data(), length()); } -#ifndef KERNEL ByteString StringBuilder::to_byte_string() const { if (is_empty()) @@ -170,7 +166,6 @@ ErrorOr StringBuilder::to_fly_string() const { return FlyString::from_utf8(string_view()); } -#endif u8* StringBuilder::data() { @@ -230,7 +225,6 @@ void StringBuilder::append_code_point(u32 code_point) } } -#ifndef KERNEL ErrorOr StringBuilder::try_append(Utf16View const& utf16_view) { for (size_t i = 0; i < utf16_view.length_in_code_units();) { @@ -246,7 +240,6 @@ void StringBuilder::append(Utf16View const& utf16_view) { MUST(try_append(utf16_view)); } -#endif ErrorOr StringBuilder::try_append(Utf32View const& utf32_view) { diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 923adfedb62..59995754c8a 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -32,9 +32,7 @@ public: ~StringBuilder() = default; ErrorOr try_append(StringView); -#ifndef KERNEL ErrorOr try_append(Utf16View const&); -#endif ErrorOr try_append(Utf32View const&); ErrorOr try_append_code_point(u32); ErrorOr try_append(char); @@ -49,9 +47,7 @@ public: ErrorOr try_append_escaped_for_json(StringView); void append(StringView); -#ifndef KERNEL void append(Utf16View const&); -#endif void append(Utf32View const&); void append(char); void append_code_point(u32); @@ -69,9 +65,7 @@ public: MUST(vformat(*this, fmtstr.view(), variadic_format_params)); } -#ifndef KERNEL [[nodiscard]] ByteString to_byte_string() const; -#endif [[nodiscard]] String to_string_without_validation() const; ErrorOr to_string() const; diff --git a/AK/StringFloatingPointConversions.h b/AK/StringFloatingPointConversions.h index 819743675a1..04cb0d18782 100644 --- a/AK/StringFloatingPointConversions.h +++ b/AK/StringFloatingPointConversions.h @@ -6,12 +6,6 @@ #pragma once -#ifdef KERNEL -# error This file should not be included in the KERNEL, as doubles should not appear in the \ - kernel code, although the conversion currently does not use any floating point \ - computations. -#endif - #include #include diff --git a/AK/StringUtils.cpp b/AK/StringUtils.cpp index baadb05163f..148531bdcfa 100644 --- a/AK/StringUtils.cpp +++ b/AK/StringUtils.cpp @@ -5,7 +5,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include +#include #include #include #include @@ -13,14 +15,7 @@ #include #include #include - -#ifdef KERNEL -# include -#else -# include -# include -# include -#endif +#include namespace AK { @@ -237,7 +232,6 @@ template Optional convert_to_uint_from_octal(StringView str, TrimWhitespace template Optional convert_to_uint_from_octal(StringView str, TrimWhitespace); template Optional convert_to_uint_from_octal(StringView str, TrimWhitespace); -#ifndef KERNEL template Optional convert_to_floating_point(StringView str, TrimWhitespace trim_whitespace) { @@ -252,7 +246,6 @@ Optional convert_to_floating_point(StringView str, TrimWhitespace trim_whites template Optional convert_to_floating_point(StringView str, TrimWhitespace); template Optional convert_to_floating_point(StringView str, TrimWhitespace); -#endif bool equals_ignoring_ascii_case(StringView a, StringView b) { @@ -469,7 +462,6 @@ Optional find_any_of(StringView haystack, StringView needles, SearchDire return {}; } -#ifndef KERNEL ByteString to_snakecase(StringView str) { auto should_insert_underscore = [&](auto i, auto current_char) { @@ -589,7 +581,6 @@ ErrorOr replace(String const& haystack, StringView needle, StringView re auto resulting_builder = replace_into_builder(source_bytes, needle, replacement, replace_mode, *maybe_first); return resulting_builder.to_string(); } -#endif // TODO: Benchmark against KMP (AK/MemMem.h) and switch over if it's faster for short strings too size_t count(StringView str, StringView needle) diff --git a/AK/StringUtils.h b/AK/StringUtils.h index 1f29fdff748..7bbe54b2515 100644 --- a/AK/StringUtils.h +++ b/AK/StringUtils.h @@ -82,10 +82,8 @@ template Optional convert_to_uint_from_hex(StringView, TrimWhitespace = TrimWhitespace::Yes); template Optional convert_to_uint_from_octal(StringView, TrimWhitespace = TrimWhitespace::Yes); -#ifndef KERNEL template Optional convert_to_floating_point(StringView, TrimWhitespace = TrimWhitespace::Yes); -#endif bool equals_ignoring_ascii_case(StringView, StringView); bool ends_with(StringView a, StringView b, CaseSensitivity); bool starts_with(StringView, StringView, CaseSensitivity); diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 7d23e1aa3a6..40c054e3940 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -6,22 +6,18 @@ #include #include +#include +#include #include +#include #include +#include #include #include #include -#ifndef KERNEL -# include -# include -# include -# include -#endif - namespace AK { -#ifndef KERNEL StringView::StringView(String const& string) : m_characters(reinterpret_cast(string.bytes().data())) , m_length(string.bytes().size()) @@ -45,7 +41,6 @@ StringView::StringView(DeprecatedFlyString const& string) , m_length(string.length()) { } -#endif StringView::StringView(ByteBuffer const& buffer) : m_characters((char const*)buffer.data()) @@ -207,7 +202,6 @@ bool StringView::equals_ignoring_ascii_case(StringView other) const return StringUtils::equals_ignoring_ascii_case(*this, other); } -#ifndef KERNEL ByteString StringView::to_lowercase_string() const { return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull(); @@ -222,7 +216,6 @@ ByteString StringView::to_titlecase_string() const { return StringUtils::to_titlecase(*this); } -#endif StringView StringView::substring_view_starting_from_substring(StringView substring) const { @@ -254,8 +247,6 @@ bool StringView::copy_characters_to_buffer(char* buffer, size_t buffer_size) con return characters_to_copy == m_length; } -#ifndef KERNEL - bool StringView::operator==(ByteString const& string) const { return *this == string.view(); @@ -267,7 +258,6 @@ ByteString StringView::replace(StringView needle, StringView replacement, Replac { return StringUtils::replace(*this, needle, replacement, replace_mode); } -#endif Vector StringView::find_all(StringView needle) const { diff --git a/AK/StringView.h b/AK/StringView.h index 285b832a2bf..edaf0a08c75 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -48,20 +48,16 @@ public: } StringView(ByteBuffer const&); -#ifndef KERNEL StringView(String const&); StringView(FlyString const&); StringView(ByteString const&); StringView(DeprecatedFlyString const&); -#endif explicit StringView(ByteBuffer&&) = delete; -#ifndef KERNEL explicit StringView(String&&) = delete; explicit StringView(FlyString&&) = delete; explicit StringView(ByteString&&) = delete; explicit StringView(DeprecatedFlyString&&) = delete; -#endif template StringType> StringView& operator=(StringType&&) = delete; @@ -110,11 +106,9 @@ public: [[nodiscard]] StringView trim(StringView characters, TrimMode mode = TrimMode::Both) const { return StringUtils::trim(*this, characters, mode); } [[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); } -#ifndef KERNEL [[nodiscard]] ByteString to_lowercase_string() const; [[nodiscard]] ByteString to_uppercase_string() const; [[nodiscard]] ByteString to_titlecase_string() const; -#endif [[nodiscard]] Optional find(char needle, size_t start = 0) const { @@ -285,9 +279,7 @@ public: return m_length == 1 && *m_characters == c; } -#ifndef KERNEL bool operator==(ByteString const&) const; -#endif [[nodiscard]] constexpr int compare(StringView other) const { @@ -327,18 +319,14 @@ public: constexpr bool operator>=(StringView other) const { return compare(other) >= 0; } -#ifndef KERNEL [[nodiscard]] ByteString to_byte_string() const; -#endif [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } -#ifndef KERNEL [[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode) const; -#endif [[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); @@ -370,10 +358,8 @@ public: template Optional to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const { -#ifndef KERNEL if constexpr (IsFloatingPoint) return StringUtils::convert_to_floating_point(*this, trim_whitespace); -#endif if constexpr (IsSigned) return StringUtils::convert_to_int(*this, trim_whitespace); else diff --git a/AK/Time.cpp b/AK/Time.cpp index e869b515f94..d016e930d3a 100644 --- a/AK/Time.cpp +++ b/AK/Time.cpp @@ -6,15 +6,8 @@ #include #include - -// Make a reasonable guess as to which timespec/timeval definition to use. -// It doesn't really matter, since both are identical. -#ifdef KERNEL -# include -#else -# include -# include -#endif +#include +#include namespace AK { @@ -207,7 +200,6 @@ Duration Duration::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanos return Duration { seconds + extra_seconds, nanoseconds }; } -#ifndef KERNEL namespace { static Duration now_time_from_clock(clockid_t clock_id) { @@ -237,6 +229,4 @@ UnixDateTime UnixDateTime::now_coarse() return UnixDateTime { now_time_from_clock(CLOCK_REALTIME_COARSE) }; } -#endif - } diff --git a/AK/Time.h b/AK/Time.h index 580f26e9c4c..7c06bcc84b5 100644 --- a/AK/Time.h +++ b/AK/Time.h @@ -12,20 +12,8 @@ #include #include #include - -#if defined(AK_OS_SERENITY) && defined(KERNEL) -# include -# include - -// We need a Badge for some MonotonicTime operations. -namespace Kernel { -class TimeManagement; -} - -#else -# include -# include -#endif +#include +#include namespace AK { @@ -450,10 +438,8 @@ public: // Subtracting two UNIX times yields their time difference. constexpr Duration operator-(UnixDateTime const& other) const { return m_offset - other.m_offset; } -#ifndef KERNEL [[nodiscard]] static UnixDateTime now(); [[nodiscard]] static UnixDateTime now_coarse(); -#endif constexpr bool operator==(UnixDateTime const& other) const { @@ -479,10 +465,8 @@ public: constexpr MonotonicTime& operator=(MonotonicTime const&) = default; constexpr MonotonicTime& operator=(MonotonicTime&&) = default; -#ifndef KERNEL [[nodiscard]] static MonotonicTime now(); [[nodiscard]] static MonotonicTime now_coarse(); -#endif [[nodiscard]] i64 seconds() const { return m_offset.to_seconds(); } [[nodiscard]] i64 milliseconds() const { return m_offset.to_milliseconds(); } @@ -503,20 +487,6 @@ public: constexpr MonotonicTime operator-(Duration const& other) const { return MonotonicTime { m_offset - other }; } constexpr Duration operator-(MonotonicTime const& other) const { return m_offset - other.m_offset; } -#ifdef KERNEL - // Required in the Kernel in order to create monotonic time information from hardware timers. - [[nodiscard]] static MonotonicTime from_hardware_time(Badge, time_t seconds, long nanoseconds) - { - return MonotonicTime { Duration::from_timespec({ seconds, nanoseconds }) }; - } - - // "Start" is whenever the hardware timers started counting (e.g. for HPET it's most certainly boot). - [[nodiscard]] Duration time_since_start(Badge) - { - return m_offset; - } -#endif - private: constexpr explicit MonotonicTime(Duration offset) : Detail::UnawareTime(offset) diff --git a/AK/Traits.h b/AK/Traits.h index f098f50e32e..d1b817514ad 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -47,7 +47,6 @@ struct Traits : public DefaultTraits { } }; -#ifndef KERNEL template struct Traits : public DefaultTraits { static constexpr bool is_trivial() { return true; } @@ -60,7 +59,6 @@ struct Traits : public DefaultTraits { return u64_hash(bit_cast(value)); } }; -#endif template requires(IsPointer && !Detail::IsPointerOfType) struct Traits : public DefaultTraits { diff --git a/AK/Trie.h b/AK/Trie.h index c8f00577a7f..c138fdaff39 100644 --- a/AK/Trie.h +++ b/AK/Trie.h @@ -232,10 +232,8 @@ private: if constexpr (requires(MetadataType t) { { t.copy() } -> SpecializationOf; }) return Optional { TRY(metadata->copy()) }; -#ifndef KERNEL else return Optional { MetadataType(metadata.value()) }; -#endif } static ErrorOr skip_to_next_iterator(auto& state, auto& current_node) diff --git a/AK/Types.h b/AK/Types.h index cb110da0981..de00fccb4dd 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -17,20 +17,18 @@ using i32 = __INT32_TYPE__; using i16 = __INT16_TYPE__; using i8 = __INT8_TYPE__; -#ifndef KERNEL using f32 = float; static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128); using f64 = double; static_assert(__DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024); -# if __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384 -# define AK_HAS_FLOAT_80 1 +#if __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384 +# define AK_HAS_FLOAT_80 1 using f80 = long double; -# elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 -# define AK_HAS_FLOAT_128 1 +#elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 +# define AK_HAS_FLOAT_128 1 using f128 = long double; -# endif #endif namespace AK::Detail { diff --git a/AK/UUID.cpp b/AK/UUID.cpp index 7c147971a5e..925716dd39f 100644 --- a/AK/UUID.cpp +++ b/AK/UUID.cpp @@ -76,27 +76,6 @@ UUID::UUID(StringView uuid_string_view, Endianness endianness) VERIFY_NOT_REACHED(); } -#ifdef KERNEL -ErrorOr> UUID::to_string() const -{ - StringBuilder builder(36); - auto nibble0 = TRY(encode_hex(m_uuid_buffer.span().trim(4))); - TRY(builder.try_append(nibble0->view())); - TRY(builder.try_append('-')); - auto nibble1 = TRY(encode_hex(m_uuid_buffer.span().slice(4).trim(2))); - TRY(builder.try_append(nibble1->view())); - TRY(builder.try_append('-')); - auto nibble2 = TRY(encode_hex(m_uuid_buffer.span().slice(6).trim(2))); - TRY(builder.try_append(nibble2->view())); - TRY(builder.try_append('-')); - auto nibble3 = TRY(encode_hex(m_uuid_buffer.span().slice(8).trim(2))); - TRY(builder.try_append(nibble3->view())); - TRY(builder.try_append('-')); - auto nibble4 = TRY(encode_hex(m_uuid_buffer.span().slice(10).trim(6))); - TRY(builder.try_append(nibble4->view())); - return Kernel::KString::try_create(builder.string_view()); -} -#else ErrorOr UUID::to_string() const { auto buffer_span = m_uuid_buffer.span(); @@ -112,7 +91,6 @@ ErrorOr UUID::to_string() const TRY(builder.try_append(encode_hex(buffer_span.slice(10, 6)))); return builder.to_string(); } -#endif bool UUID::is_zero() const { diff --git a/AK/UUID.h b/AK/UUID.h index 8a739318e0c..7a5b1734fea 100644 --- a/AK/UUID.h +++ b/AK/UUID.h @@ -8,15 +8,10 @@ #include #include +#include #include #include -#ifdef KERNEL -# include -#else -# include -#endif - namespace AK { class UUID { @@ -33,11 +28,7 @@ public: bool operator==(const UUID&) const = default; -#ifdef KERNEL - ErrorOr> to_string() const; -#else ErrorOr to_string() const; -#endif bool is_zero() const; private: diff --git a/AK/Utf8View.h b/AK/Utf8View.h index e1b1ae70ccf..0c25dce1707 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -7,14 +7,11 @@ #pragma once +#include #include #include #include -#ifndef KERNEL -# include -#endif - namespace AK { class Utf8View; @@ -71,14 +68,12 @@ public: { } -#ifndef KERNEL explicit Utf8View(ByteString& string) : m_string(string.view()) { } explicit Utf8View(ByteString&&) = delete; -#endif enum class AllowSurrogates { Yes, @@ -238,7 +233,6 @@ private: mutable bool m_have_length { false }; }; -#ifndef KERNEL class DeprecatedStringCodePointIterator { public: Optional next() @@ -272,7 +266,6 @@ private: ByteString m_string; Utf8CodePointIterator m_it; }; -#endif template<> struct Formatter : Formatter { @@ -282,9 +275,7 @@ struct Formatter : Formatter { } #if USING_AK_GLOBALLY -# ifndef KERNEL using AK::DeprecatedStringCodePointIterator; -# endif using AK::Utf8CodePointIterator; using AK::Utf8View; #endif diff --git a/AK/Vector.h b/AK/Vector.h index 52db632ce18..4cc87fb7dd5 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -226,8 +226,6 @@ public: return false; } -#ifndef KERNEL - template void insert(size_t index, U&& value) requires(CanBePlacedInsideVector) @@ -252,8 +250,6 @@ public: MUST(try_extend(other)); } -#endif - ALWAYS_INLINE void append(T&& value) { if constexpr (contains_reference) @@ -268,12 +264,10 @@ public: MUST(try_append(T(value))); } -#ifndef KERNEL void append(StorageType const* values, size_t count) { MUST(try_append(values, count)); } -#endif template ALWAYS_INLINE void unchecked_append(U&& value) @@ -296,7 +290,6 @@ public: m_size += count; } -#ifndef KERNEL template void empend(Args&&... args) requires(!contains_reference) @@ -321,8 +314,6 @@ public: MUST(try_prepend(values, count)); } -#endif - // FIXME: What about assigning from a vector with lower inline capacity? Vector& operator=(Vector&& other) { diff --git a/AK/kmalloc.cpp b/AK/kmalloc.cpp index 926a3e88277..a24444d7e2b 100644 --- a/AK/kmalloc.cpp +++ b/AK/kmalloc.cpp @@ -7,7 +7,7 @@ #include -#if defined(AK_OS_SERENITY) && !defined(KERNEL) +#if defined(AK_OS_SERENITY) # include diff --git a/AK/kmalloc.h b/AK/kmalloc.h index 533ffd73d8a..74822c50d19 100644 --- a/AK/kmalloc.h +++ b/AK/kmalloc.h @@ -9,22 +9,17 @@ #include #include +#include +#include -#if defined(KERNEL) -# include -#else -# include -# include - -# define kcalloc calloc -# define kmalloc malloc -# define kmalloc_good_size malloc_good_size +#define kcalloc calloc +#define kmalloc malloc +#define kmalloc_good_size malloc_good_size inline void kfree_sized(void* ptr, size_t) { free(ptr); } -#endif #ifndef AK_OS_SERENITY # include diff --git a/AK/kstdio.h b/AK/kstdio.h index 2e2a05ac217..6d8478b5440 100644 --- a/AK/kstdio.h +++ b/AK/kstdio.h @@ -9,17 +9,13 @@ #include #ifdef AK_OS_SERENITY -# ifdef KERNEL -# include -# else -# include -# include +# include +# include extern "C" { void dbgputstr(char const*, size_t); int sprintf(char* buf, char const* fmt, ...) __attribute__((format(printf, 2, 3))); int snprintf(char* buffer, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4))); } -# endif #else # include inline void dbgputstr(char const* characters, size_t length) diff --git a/Userland/Libraries/LibCrypto/Authentication/GHash.h b/Userland/Libraries/LibCrypto/Authentication/GHash.h index ff4d8552800..2839d3300c5 100644 --- a/Userland/Libraries/LibCrypto/Authentication/GHash.h +++ b/Userland/Libraries/LibCrypto/Authentication/GHash.h @@ -7,14 +7,11 @@ #pragma once #include +#include #include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Authentication { void galois_multiply(u32 (&z)[4], u32 const (&x)[4], u32 const (&y)[4]); @@ -47,12 +44,10 @@ public: constexpr static size_t digest_size() { return TagType::Size; } -#ifndef KERNEL ByteString class_name() const { return "GHash"; } -#endif TagType process(ReadonlyBytes aad, ReadonlyBytes cipher); diff --git a/Userland/Libraries/LibCrypto/Authentication/HMAC.h b/Userland/Libraries/LibCrypto/Authentication/HMAC.h index 29e353c6e8b..c9baee936c9 100644 --- a/Userland/Libraries/LibCrypto/Authentication/HMAC.h +++ b/Userland/Libraries/LibCrypto/Authentication/HMAC.h @@ -7,15 +7,12 @@ #pragma once #include +#include #include #include #include #include -#ifndef KERNEL -# include -#endif - constexpr static auto IPAD = 0x36; constexpr static auto OPAD = 0x5c; @@ -72,7 +69,6 @@ public: m_outer_hasher.update(m_key_data + m_inner_hasher.block_size(), m_outer_hasher.block_size()); } -#ifndef KERNEL ByteString class_name() const { StringBuilder builder; @@ -80,7 +76,6 @@ public: builder.append(m_inner_hasher.class_name()); return builder.to_byte_string(); } -#endif private: void derive_key(u8 const* key, size_t length) diff --git a/Userland/Libraries/LibCrypto/Cipher/AES.cpp b/Userland/Libraries/LibCrypto/Cipher/AES.cpp index 1c63e5abb17..b3b8a2dfb3d 100644 --- a/Userland/Libraries/LibCrypto/Cipher/AES.cpp +++ b/Userland/Libraries/LibCrypto/Cipher/AES.cpp @@ -23,7 +23,6 @@ constexpr void swap_keys(u32* keys, size_t i, size_t j) keys[j] = temp; } -#ifndef KERNEL ByteString AESCipherBlock::to_byte_string() const { StringBuilder builder; @@ -39,7 +38,6 @@ ByteString AESCipherKey::to_byte_string() const builder.appendff("{:02x}", m_rd_keys[i]); return builder.to_byte_string(); } -#endif void AESCipherKey::expand_encrypt_key(ReadonlyBytes user_key, size_t bits) { diff --git a/Userland/Libraries/LibCrypto/Cipher/AES.h b/Userland/Libraries/LibCrypto/Cipher/AES.h index 835188c17cc..2672579669a 100644 --- a/Userland/Libraries/LibCrypto/Cipher/AES.h +++ b/Userland/Libraries/LibCrypto/Cipher/AES.h @@ -7,16 +7,13 @@ #pragma once +#include #include #include #include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Cipher { struct AESCipherBlock : public CipherBlock { @@ -47,9 +44,7 @@ public: m_data[i] ^= ivec[i]; } -#ifndef KERNEL ByteString to_byte_string() const; -#endif private: constexpr static size_t data_size() { return sizeof(m_data); } @@ -63,9 +58,7 @@ struct AESCipherKey : public CipherKey { virtual void expand_decrypt_key(ReadonlyBytes user_key, size_t bits) override; static bool is_valid_key_size(size_t bits) { return bits == 128 || bits == 192 || bits == 256; } -#ifndef KERNEL ByteString to_byte_string() const; -#endif u32 const* round_keys() const { @@ -119,12 +112,10 @@ public: virtual void encrypt_block(BlockType const& in, BlockType& out) override; virtual void decrypt_block(BlockType const& in, BlockType& out) override; -#ifndef KERNEL virtual ByteString class_name() const override { return "AES"; } -#endif protected: AESCipherKey m_key; diff --git a/Userland/Libraries/LibCrypto/Cipher/Cipher.h b/Userland/Libraries/LibCrypto/Cipher/Cipher.h index 392ae537d3a..4215fdea4e5 100644 --- a/Userland/Libraries/LibCrypto/Cipher/Cipher.h +++ b/Userland/Libraries/LibCrypto/Cipher/Cipher.h @@ -111,9 +111,7 @@ public: virtual void encrypt_block(BlockType const& in, BlockType& out) = 0; virtual void decrypt_block(BlockType const& in, BlockType& out) = 0; -#ifndef KERNEL virtual ByteString class_name() const = 0; -#endif protected: virtual ~Cipher() = default; diff --git a/Userland/Libraries/LibCrypto/Cipher/Mode/CBC.h b/Userland/Libraries/LibCrypto/Cipher/Mode/CBC.h index 00c97495a9f..6123d4f0270 100644 --- a/Userland/Libraries/LibCrypto/Cipher/Mode/CBC.h +++ b/Userland/Libraries/LibCrypto/Cipher/Mode/CBC.h @@ -6,14 +6,11 @@ #pragma once +#include #include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Cipher { template @@ -28,7 +25,6 @@ public: { } -#ifndef KERNEL virtual ByteString class_name() const override { StringBuilder builder; @@ -36,7 +32,6 @@ public: builder.append("_CBC"sv); return builder.to_byte_string(); } -#endif virtual size_t IV_length() const override { diff --git a/Userland/Libraries/LibCrypto/Cipher/Mode/CTR.h b/Userland/Libraries/LibCrypto/Cipher/Mode/CTR.h index 7420d82ea25..5889f7c2796 100644 --- a/Userland/Libraries/LibCrypto/Cipher/Mode/CTR.h +++ b/Userland/Libraries/LibCrypto/Cipher/Mode/CTR.h @@ -6,14 +6,11 @@ #pragma once +#include #include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Cipher { /* @@ -103,7 +100,6 @@ public: { } -#ifndef KERNEL virtual ByteString class_name() const override { StringBuilder builder; @@ -111,7 +107,6 @@ public: builder.append("_CTR"sv); return builder.to_byte_string(); } -#endif virtual size_t IV_length() const override { diff --git a/Userland/Libraries/LibCrypto/Cipher/Mode/GCM.h b/Userland/Libraries/LibCrypto/Cipher/Mode/GCM.h index 9c9d549223b..20ad8e390a3 100644 --- a/Userland/Libraries/LibCrypto/Cipher/Mode/GCM.h +++ b/Userland/Libraries/LibCrypto/Cipher/Mode/GCM.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -14,10 +15,6 @@ #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Cipher { using IncrementFunction = IncrementInplace; @@ -43,7 +40,6 @@ public: m_ghash = Authentication::GHash(m_auth_key); } -#ifndef KERNEL virtual ByteString class_name() const override { StringBuilder builder; @@ -51,7 +47,6 @@ public: builder.append("_GCM"sv); return builder.to_byte_string(); } -#endif virtual size_t IV_length() const override { diff --git a/Userland/Libraries/LibCrypto/Cipher/Mode/Mode.h b/Userland/Libraries/LibCrypto/Cipher/Mode/Mode.h index 8278942f6cf..92ebd278d8f 100644 --- a/Userland/Libraries/LibCrypto/Cipher/Mode/Mode.h +++ b/Userland/Libraries/LibCrypto/Cipher/Mode/Mode.h @@ -33,9 +33,7 @@ public: return ByteBuffer::create_uninitialized(input_size + T::block_size() - remainder); } -#ifndef KERNEL virtual ByteString class_name() const = 0; -#endif T& cipher() { diff --git a/Userland/Libraries/LibCrypto/Hash/BLAKE2b.h b/Userland/Libraries/LibCrypto/Hash/BLAKE2b.h index 05d3a8d4fb5..fadfba1303a 100644 --- a/Userland/Libraries/LibCrypto/Hash/BLAKE2b.h +++ b/Userland/Libraries/LibCrypto/Hash/BLAKE2b.h @@ -6,13 +6,10 @@ #pragma once +#include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Hash { namespace BLAKE2bConstants { @@ -43,12 +40,10 @@ public: static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); } static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); } -#ifndef KERNEL virtual ByteString class_name() const override { return "BLAKE2b"; } -#endif virtual void reset() override { diff --git a/Userland/Libraries/LibCrypto/Hash/HashFunction.h b/Userland/Libraries/LibCrypto/Hash/HashFunction.h index 4848b947a37..0400378e37a 100644 --- a/Userland/Libraries/LibCrypto/Hash/HashFunction.h +++ b/Userland/Libraries/LibCrypto/Hash/HashFunction.h @@ -54,9 +54,7 @@ public: virtual void reset() = 0; -#ifndef KERNEL virtual ByteString class_name() const = 0; -#endif protected: virtual ~HashFunction() = default; diff --git a/Userland/Libraries/LibCrypto/Hash/HashManager.h b/Userland/Libraries/LibCrypto/Hash/HashManager.h index f2fc526877b..bbf71839c9a 100644 --- a/Userland/Libraries/LibCrypto/Hash/HashManager.h +++ b/Userland/Libraries/LibCrypto/Hash/HashManager.h @@ -196,14 +196,12 @@ public: [&](auto& hash) { hash.reset(); }); } -#ifndef KERNEL virtual ByteString class_name() const override { return m_algorithm.visit( [&](Empty const&) -> ByteString { return "UninitializedHashManager"; }, [&](auto const& hash) { return hash.class_name(); }); } -#endif inline HashKind kind() const { diff --git a/Userland/Libraries/LibCrypto/Hash/MD5.h b/Userland/Libraries/LibCrypto/Hash/MD5.h index a732dcb99a2..229393c339f 100644 --- a/Userland/Libraries/LibCrypto/Hash/MD5.h +++ b/Userland/Libraries/LibCrypto/Hash/MD5.h @@ -6,13 +6,10 @@ #pragma once +#include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Hash { namespace MD5Constants { @@ -55,12 +52,10 @@ public: virtual DigestType digest() override; virtual DigestType peek() override; -#ifndef KERNEL virtual ByteString class_name() const override { return "MD5"; } -#endif static DigestType hash(u8 const* data, size_t length) { diff --git a/Userland/Libraries/LibCrypto/Hash/SHA1.h b/Userland/Libraries/LibCrypto/Hash/SHA1.h index d70e5fc7b32..47ca6477b91 100644 --- a/Userland/Libraries/LibCrypto/Hash/SHA1.h +++ b/Userland/Libraries/LibCrypto/Hash/SHA1.h @@ -6,12 +6,9 @@ #pragma once +#include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Hash { namespace SHA1Constants { @@ -51,12 +48,10 @@ public: static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); } static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); } -#ifndef KERNEL virtual ByteString class_name() const override { return "SHA1"; } -#endif virtual void reset() override { diff --git a/Userland/Libraries/LibCrypto/Hash/SHA2.h b/Userland/Libraries/LibCrypto/Hash/SHA2.h index 87509ae0211..1a4f30bbcdd 100644 --- a/Userland/Libraries/LibCrypto/Hash/SHA2.h +++ b/Userland/Libraries/LibCrypto/Hash/SHA2.h @@ -6,13 +6,10 @@ #pragma once +#include #include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::Hash { namespace SHA256Constants { @@ -99,12 +96,10 @@ public: static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); } static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); } -#ifndef KERNEL virtual ByteString class_name() const override { return ByteString::formatted("SHA{}", DigestSize * 8); } -#endif virtual void reset() override { @@ -151,12 +146,10 @@ public: static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); } static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); } -#ifndef KERNEL virtual ByteString class_name() const override { return ByteString::formatted("SHA{}", DigestSize * 8); } -#endif virtual void reset() override { @@ -203,12 +196,10 @@ public: static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); } static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); } -#ifndef KERNEL virtual ByteString class_name() const override { return ByteString::formatted("SHA{}", DigestSize * 8); } -#endif virtual void reset() override { diff --git a/Userland/Libraries/LibCrypto/PK/PK.h b/Userland/Libraries/LibCrypto/PK/PK.h index dc1bf91cef4..8018e6810bd 100644 --- a/Userland/Libraries/LibCrypto/PK/PK.h +++ b/Userland/Libraries/LibCrypto/PK/PK.h @@ -7,12 +7,9 @@ #pragma once #include +#include #include -#ifndef KERNEL -# include -#endif - namespace Crypto::PK { template @@ -95,9 +92,7 @@ public: virtual void sign(ReadonlyBytes in, Bytes& out) = 0; virtual void verify(ReadonlyBytes in, Bytes& out) = 0; -#ifndef KERNEL virtual ByteString class_name() const = 0; -#endif virtual size_t output_size() const = 0; diff --git a/Userland/Libraries/LibCrypto/PK/RSA.h b/Userland/Libraries/LibCrypto/PK/RSA.h index 584e00e2ffd..e8863c93c18 100644 --- a/Userland/Libraries/LibCrypto/PK/RSA.h +++ b/Userland/Libraries/LibCrypto/PK/RSA.h @@ -206,12 +206,10 @@ public: virtual void sign(ReadonlyBytes in, Bytes& out) override; virtual void verify(ReadonlyBytes in, Bytes& out) override; -#ifndef KERNEL virtual ByteString class_name() const override { return "RSA"; } -#endif virtual size_t output_size() const override { @@ -242,12 +240,11 @@ public: virtual void sign(ReadonlyBytes, Bytes&) override; virtual void verify(ReadonlyBytes, Bytes&) override; -#ifndef KERNEL virtual ByteString class_name() const override { return "RSA_PKCS1-EME"; } -#endif + virtual size_t output_size() const override { return m_public_key.length(); diff --git a/Userland/Libraries/LibTest/TestMain.cpp b/Userland/Libraries/LibTest/TestMain.cpp index 0eace12ed28..2059817123a 100644 --- a/Userland/Libraries/LibTest/TestMain.cpp +++ b/Userland/Libraries/LibTest/TestMain.cpp @@ -9,11 +9,7 @@ #include #include -#ifdef KERNEL -# define TEST_MAIN test_main -#else -# define TEST_MAIN main -#endif +#define TEST_MAIN main int TEST_MAIN(int argc, char** argv) {