mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
Everywhere: Remove all KERNEL #define
s
This commit is contained in:
parent
de99dd2c89
commit
5ca2f4dfd7
Notes:
sideshowbarker
2024-07-16 23:17:55 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/5ca2f4dfd7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/195
73 changed files with 116 additions and 808 deletions
|
@ -33,9 +33,7 @@
|
||||||
# define ERRORLN warnln
|
# define ERRORLN warnln
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
#if defined(EXECINFO_BACKTRACE)
|
||||||
|
|
||||||
# if defined(EXECINFO_BACKTRACE)
|
|
||||||
namespace {
|
namespace {
|
||||||
ALWAYS_INLINE void dump_backtrace()
|
ALWAYS_INLINE void dump_backtrace()
|
||||||
{
|
{
|
||||||
|
@ -83,30 +81,28 @@ ALWAYS_INLINE void dump_backtrace()
|
||||||
free(syms);
|
free(syms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void ak_verification_failed(char const* message)
|
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;
|
bool colorize_output = true;
|
||||||
# elif defined(AK_OS_WINDOWS)
|
#elif defined(AK_OS_WINDOWS)
|
||||||
bool colorize_output = false;
|
bool colorize_output = false;
|
||||||
# else
|
#else
|
||||||
bool colorize_output = isatty(STDERR_FILENO) == 1;
|
bool colorize_output = isatty(STDERR_FILENO) == 1;
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
if (colorize_output)
|
if (colorize_output)
|
||||||
ERRORLN("\033[31;1mVERIFICATION FAILED\033[0m: {}", message);
|
ERRORLN("\033[31;1mVERIFICATION FAILED\033[0m: {}", message);
|
||||||
else
|
else
|
||||||
ERRORLN("VERIFICATION FAILED: {}", message);
|
ERRORLN("VERIFICATION FAILED: {}", message);
|
||||||
|
|
||||||
# if defined(EXECINFO_BACKTRACE)
|
#if defined(EXECINFO_BACKTRACE)
|
||||||
dump_backtrace();
|
dump_backtrace();
|
||||||
# endif
|
#endif
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -6,19 +6,15 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(KERNEL)
|
|
||||||
# include <Kernel/Library/Assertions.h>
|
|
||||||
#else
|
|
||||||
extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*);
|
extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*);
|
||||||
# define __stringify_helper(x) #x
|
#define __stringify_helper(x) #x
|
||||||
# define __stringify(x) __stringify_helper(x)
|
#define __stringify(x) __stringify_helper(x)
|
||||||
# define VERIFY(expr) \
|
#define VERIFY(expr) \
|
||||||
(__builtin_expect(!(expr), 0) \
|
(__builtin_expect(!(expr), 0) \
|
||||||
? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \
|
? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \
|
||||||
: (void)0)
|
: (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 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;
|
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() 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_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 */
|
#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
|
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef KERNEL
|
#include <AK/ByteString.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
# include <AK/ByteString.h>
|
#include <cxxabi.h>
|
||||||
# include <AK/StringView.h>
|
|
||||||
# include <cxxabi.h>
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -26,8 +24,6 @@ inline ByteString demangle(StringView name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
using AK::demangle;
|
using AK::demangle;
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -134,7 +134,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
void append(U&& value)
|
void append(U&& value)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +145,6 @@ public:
|
||||||
{
|
{
|
||||||
MUST(try_prepend(forward<U>(value)));
|
MUST(try_prepend(forward<U>(value)));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] bool contains_slow(T const& value) const
|
[[nodiscard]] bool contains_slow(T const& value) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,20 +6,11 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <AK/Format.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code)
|
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);
|
return Error::from_string_view(string_literal);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
26
AK/Error.h
26
AK/Error.h
|
@ -9,13 +9,8 @@
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Try.h>
|
#include <AK/Try.h>
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
|
#include <errno.h>
|
||||||
#if defined(AK_OS_SERENITY) && defined(KERNEL)
|
#include <string.h>
|
||||||
# include <errno_codes.h>
|
|
||||||
#else
|
|
||||||
# include <errno.h>
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -36,7 +31,6 @@ public:
|
||||||
// the Error::from_string_view method!
|
// the Error::from_string_view method!
|
||||||
static Error from_string_view_or_print_error_and_return_errno(StringView string_literal, int code);
|
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)
|
static Error from_syscall(StringView syscall_name, int rc)
|
||||||
{
|
{
|
||||||
return Error(syscall_name, rc);
|
return Error(syscall_name, rc);
|
||||||
|
@ -52,14 +46,11 @@ public:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Error copy(Error const& error)
|
static Error copy(Error const& error)
|
||||||
{
|
{
|
||||||
return Error(error);
|
return Error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
// NOTE: Prefer `from_string_literal` when directly typing out an error message:
|
// NOTE: Prefer `from_string_literal` when directly typing out an error message:
|
||||||
//
|
//
|
||||||
// return Error::from_string_literal("Class: Some failure");
|
// return Error::from_string_literal("Class: Some failure");
|
||||||
|
@ -78,15 +69,10 @@ public:
|
||||||
{
|
{
|
||||||
return from_string_view(string);
|
return from_string_view(string);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool operator==(Error const& other) const
|
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;
|
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; }
|
int code() const { return m_code; }
|
||||||
|
@ -94,7 +80,6 @@ public:
|
||||||
{
|
{
|
||||||
return m_code != 0;
|
return m_code != 0;
|
||||||
}
|
}
|
||||||
#ifndef KERNEL
|
|
||||||
bool is_syscall() const
|
bool is_syscall() const
|
||||||
{
|
{
|
||||||
return m_syscall;
|
return m_syscall;
|
||||||
|
@ -103,7 +88,6 @@ public:
|
||||||
{
|
{
|
||||||
return m_string_literal;
|
return m_string_literal;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Error(int code)
|
Error(int code)
|
||||||
|
@ -112,7 +96,6 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef KERNEL
|
|
||||||
Error(StringView string_literal)
|
Error(StringView string_literal)
|
||||||
: m_string_literal(string_literal)
|
: m_string_literal(string_literal)
|
||||||
{
|
{
|
||||||
|
@ -124,20 +107,15 @@ private:
|
||||||
, m_syscall(true)
|
, m_syscall(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Error(Error const&) = default;
|
Error(Error const&) = default;
|
||||||
Error& operator=(Error const&) = default;
|
Error& operator=(Error const&) = default;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
StringView m_string_literal;
|
StringView m_string_literal;
|
||||||
#endif
|
|
||||||
|
|
||||||
int m_code { 0 };
|
int m_code { 0 };
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
bool m_syscall { false };
|
bool m_syscall { false };
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename E>
|
template<typename T, typename E>
|
||||||
|
|
|
@ -9,12 +9,10 @@
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/IntegralMath.h>
|
#include <AK/IntegralMath.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/Math.h>
|
|
||||||
#endif
|
|
||||||
#ifndef __SIZEOF_INT128__
|
#ifndef __SIZEOF_INT128__
|
||||||
# include <AK/UFixedBigInt.h>
|
# include <AK/UFixedBigInt.h>
|
||||||
# include <AK/UFixedBigIntDivision.h>
|
# include <AK/UFixedBigIntDivision.h>
|
||||||
|
@ -45,13 +43,11 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<FloatingPoint F>
|
template<FloatingPoint F>
|
||||||
FixedPoint(F value)
|
FixedPoint(F value)
|
||||||
: m_value(round_to<Underlying>(value * (static_cast<Underlying>(1) << precision)))
|
: m_value(round_to<Underlying>(value * (static_cast<Underlying>(1) << precision)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
template<size_t P, typename U>
|
template<size_t P, typename U>
|
||||||
explicit constexpr FixedPoint(FixedPoint<P, U> const& other)
|
explicit constexpr FixedPoint(FixedPoint<P, U> const& other)
|
||||||
|
@ -59,13 +55,11 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<FloatingPoint F>
|
template<FloatingPoint F>
|
||||||
explicit ALWAYS_INLINE operator F() const
|
explicit ALWAYS_INLINE operator F() const
|
||||||
{
|
{
|
||||||
return (F)m_value * pow<F>(0.5, precision);
|
return (F)m_value * pow<F>(0.5, precision);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
template<Integral I>
|
template<Integral I>
|
||||||
explicit constexpr operator I() const
|
explicit constexpr operator I() const
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#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 <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
122
AK/Format.cpp
122
AK/Format.cpp
|
@ -8,34 +8,24 @@
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/GenericLexer.h>
|
#include <AK/GenericLexer.h>
|
||||||
#include <AK/IntegralMath.h>
|
#include <AK/IntegralMath.h>
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <AK/StringFloatingPointConversions.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#if defined(AK_OS_SERENITY) && !defined(KERNEL)
|
#if defined(AK_OS_SERENITY)
|
||||||
# include <serenity.h>
|
# include <serenity.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Tasks/Process.h>
|
|
||||||
# include <Kernel/Tasks/Thread.h>
|
|
||||||
# include <Kernel/Time/TimeManagement.h>
|
|
||||||
#else
|
|
||||||
# include <AK/LexicalPath.h>
|
|
||||||
# include <math.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <string.h>
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(AK_OS_ANDROID)
|
#if defined(AK_OS_ANDROID)
|
||||||
# include <android/log.h>
|
# include <android/log.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/StringFloatingPointConversions.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class FormatParser : public GenericLexer {
|
class FormatParser : public GenericLexer {
|
||||||
|
@ -452,7 +442,6 @@ ErrorOr<void> FormatBuilder::put_fixed_point(
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
static ErrorOr<void> round_up_digits(StringBuilder& digits_builder)
|
static ErrorOr<void> round_up_digits(StringBuilder& digits_builder)
|
||||||
{
|
{
|
||||||
auto digits_buffer = TRY(digits_builder.to_byte_buffer());
|
auto digits_buffer = TRY(digits_builder.to_byte_buffer());
|
||||||
|
@ -746,8 +735,6 @@ ErrorOr<void> FormatBuilder::put_f80(
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill)
|
ErrorOr<void> FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill)
|
||||||
{
|
{
|
||||||
auto put_char_view = [&](auto i) -> ErrorOr<void> {
|
auto put_char_view = [&](auto i) -> ErrorOr<void> {
|
||||||
|
@ -991,7 +978,6 @@ ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value)
|
||||||
return formatter.format(builder, value ? "true"sv : "false"sv);
|
return formatter.format(builder, value ? "true"sv : "false"sv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value)
|
ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value)
|
||||||
{
|
{
|
||||||
u8 base;
|
u8 base;
|
||||||
|
@ -1070,9 +1056,7 @@ ErrorOr<void> Formatter<float>::format(FormatBuilder& builder, float value)
|
||||||
|
|
||||||
template ErrorOr<void> FormatBuilder::put_f32_or_f64<float>(float, u8, bool, bool, bool, Align, size_t, Optional<size_t>, char, SignMode, RealNumberDisplayMode);
|
template ErrorOr<void> FormatBuilder::put_f32_or_f64<float>(float, u8, bool, bool, bool, Align, size_t, Optional<size_t>, char, SignMode, RealNumberDisplayMode);
|
||||||
template ErrorOr<void> FormatBuilder::put_f32_or_f64<double>(double, u8, bool, bool, bool, Align, size_t, Optional<size_t>, char, SignMode, RealNumberDisplayMode);
|
template ErrorOr<void> FormatBuilder::put_f32_or_f64<double>(double, u8, bool, bool, bool, Align, size_t, Optional<size_t>, char, SignMode, RealNumberDisplayMode);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
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));
|
dbgln("vout() failed ({} written out of {}), error was {} ({})", retval, string.length(), error, strerror(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef AK_OS_ANDROID
|
#ifdef AK_OS_ANDROID
|
||||||
static char const* s_log_tag_name = "Serenity";
|
static char const* s_log_tag_name = "Serenity";
|
||||||
|
@ -1129,25 +1112,24 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
// FIXME: Deduplicate with Core::Process:get_name()
|
// FIXME: Deduplicate with Core::Process:get_name()
|
||||||
[[gnu::used]] static ByteString process_name_helper()
|
[[gnu::used]] static ByteString process_name_helper()
|
||||||
{
|
{
|
||||||
# if defined(AK_OS_SERENITY)
|
#if defined(AK_OS_SERENITY)
|
||||||
char buffer[BUFSIZ] = {};
|
char buffer[BUFSIZ] = {};
|
||||||
int rc = get_process_name(buffer, BUFSIZ);
|
int rc = get_process_name(buffer, BUFSIZ);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
return ByteString {};
|
return ByteString {};
|
||||||
return StringView { buffer, strlen(buffer) };
|
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) };
|
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();
|
auto const* progname = getprogname();
|
||||||
return StringView { progname, strlen(progname) };
|
return StringView { progname, strlen(progname) };
|
||||||
# else
|
#else
|
||||||
// FIXME: Implement process_name_helper() for other platforms.
|
// FIXME: Implement process_name_helper() for other platforms.
|
||||||
return StringView {};
|
return StringView {};
|
||||||
# endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringView process_name_for_logging()
|
static StringView process_name_for_logging()
|
||||||
|
@ -1165,7 +1147,6 @@ static StringView process_name_for_logging()
|
||||||
}
|
}
|
||||||
return process_name;
|
return process_name;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool is_debug_enabled = true;
|
static bool is_debug_enabled = true;
|
||||||
|
|
||||||
|
@ -1195,21 +1176,7 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
if (is_rich_debug_enabled) {
|
if (is_rich_debug_enabled) {
|
||||||
#ifdef KERNEL
|
#ifndef AK_OS_WINDOWS
|
||||||
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)
|
|
||||||
auto process_name = process_name_for_logging();
|
auto process_name = process_name_for_logging();
|
||||||
if (!process_name.is_empty()) {
|
if (!process_name.is_empty()) {
|
||||||
struct timespec ts = {};
|
struct timespec ts = {};
|
||||||
|
@ -1240,14 +1207,6 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
||||||
#endif
|
#endif
|
||||||
auto const string = builder.string_view();
|
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
|
#ifdef AK_OS_ANDROID
|
||||||
__android_log_write(ANDROID_LOG_DEBUG, s_log_tag_name, string.characters_without_null_termination());
|
__android_log_write(ANDROID_LOG_DEBUG, s_log_tag_name, string.characters_without_null_termination());
|
||||||
#else
|
#else
|
||||||
|
@ -1255,61 +1214,6 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
||||||
#endif
|
#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<unsigned char, void>;
|
template struct Formatter<unsigned char, void>;
|
||||||
template struct Formatter<unsigned short, void>;
|
template struct Formatter<unsigned short, void>;
|
||||||
template struct Formatter<unsigned int, void>;
|
template struct Formatter<unsigned int, void>;
|
||||||
|
|
57
AK/Format.h
57
AK/Format.h
|
@ -14,11 +14,8 @@
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <stdio.h>
|
||||||
#ifndef KERNEL
|
#include <string.h>
|
||||||
# include <stdio.h>
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -225,7 +222,6 @@ public:
|
||||||
char fill = ' ',
|
char fill = ' ',
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> put_f80(
|
ErrorOr<void> put_f80(
|
||||||
long double value,
|
long double value,
|
||||||
u8 base = 10,
|
u8 base = 10,
|
||||||
|
@ -251,7 +247,6 @@ public:
|
||||||
char fill = ' ',
|
char fill = ' ',
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
||||||
RealNumberDisplayMode = RealNumberDisplayMode::Default);
|
RealNumberDisplayMode = RealNumberDisplayMode::Default);
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> put_hexdump(
|
ErrorOr<void> put_hexdump(
|
||||||
ReadonlyBytes,
|
ReadonlyBytes,
|
||||||
|
@ -267,7 +262,6 @@ public:
|
||||||
private:
|
private:
|
||||||
StringBuilder& m_builder;
|
StringBuilder& m_builder;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> put_f64_with_precision(
|
ErrorOr<void> put_f64_with_precision(
|
||||||
double value,
|
double value,
|
||||||
u8 base,
|
u8 base,
|
||||||
|
@ -280,7 +274,6 @@ private:
|
||||||
char fill,
|
char fill,
|
||||||
SignMode sign_mode,
|
SignMode sign_mode,
|
||||||
RealNumberDisplayMode);
|
RealNumberDisplayMode);
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeErasedFormatParams {
|
class TypeErasedFormatParams {
|
||||||
|
@ -532,7 +525,6 @@ struct Formatter<bool> : StandardFormatter {
|
||||||
ErrorOr<void> format(FormatBuilder&, bool);
|
ErrorOr<void> format(FormatBuilder&, bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<float> : StandardFormatter {
|
struct Formatter<float> : StandardFormatter {
|
||||||
ErrorOr<void> format(FormatBuilder&, float value);
|
ErrorOr<void> format(FormatBuilder&, float value);
|
||||||
|
@ -558,7 +550,6 @@ struct Formatter<long double> : StandardFormatter {
|
||||||
|
|
||||||
ErrorOr<void> format(FormatBuilder&, long double value);
|
ErrorOr<void> format(FormatBuilder&, long double value);
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<nullptr_t> : Formatter<FlatPtr> {
|
struct Formatter<nullptr_t> : Formatter<FlatPtr> {
|
||||||
|
@ -573,7 +564,6 @@ struct Formatter<nullptr_t> : Formatter<FlatPtr> {
|
||||||
|
|
||||||
ErrorOr<void> vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&);
|
ErrorOr<void> vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&);
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
|
@ -592,7 +582,7 @@ void outln(FILE* file, CheckedFormatString<Parameters...>&& fmtstr, Parameters c
|
||||||
|
|
||||||
inline void outln(FILE* file) { fputc('\n', file); }
|
inline void outln(FILE* file) { fputc('\n', file); }
|
||||||
|
|
||||||
# ifndef AK_OS_ANDROID
|
#ifndef AK_OS_ANDROID
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
void out(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
void out(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||||
{
|
{
|
||||||
|
@ -614,7 +604,7 @@ template<typename... Parameters>
|
||||||
void warnln(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters) { outln(stderr, move(fmtstr), parameters...); }
|
void warnln(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters) { outln(stderr, move(fmtstr), parameters...); }
|
||||||
|
|
||||||
inline void warnln() { outln(stderr); }
|
inline void warnln() { outln(stderr); }
|
||||||
# else // v Android ^ No Android
|
#else // v Android ^ No Android
|
||||||
enum class LogLevel {
|
enum class LogLevel {
|
||||||
Debug,
|
Debug,
|
||||||
Info,
|
Info,
|
||||||
|
@ -656,22 +646,20 @@ void warnln(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... pa
|
||||||
inline void warnln() { warnln(""); }
|
inline void warnln() { warnln(""); }
|
||||||
|
|
||||||
void set_log_tag_name(char const*);
|
void set_log_tag_name(char const*);
|
||||||
# endif // AK_OS_ANDROID
|
#endif // AK_OS_ANDROID
|
||||||
|
|
||||||
# define outln_if(flag, fmt, ...) \
|
#define outln_if(flag, fmt, ...) \
|
||||||
do { \
|
do { \
|
||||||
if constexpr (flag) \
|
if constexpr (flag) \
|
||||||
outln(fmt, ##__VA_ARGS__); \
|
outln(fmt, ##__VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# define warnln_if(flag, fmt, ...) \
|
#define warnln_if(flag, fmt, ...) \
|
||||||
do { \
|
do { \
|
||||||
if constexpr (flag) \
|
if constexpr (flag) \
|
||||||
warnln(fmt, ##__VA_ARGS__); \
|
warnln(fmt, ##__VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void vdbg(StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
void vdbg(StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
|
@ -693,28 +681,6 @@ inline void dbgln() { dbgln(""); }
|
||||||
void set_debug_enabled(bool);
|
void set_debug_enabled(bool);
|
||||||
void set_rich_debug_enabled(bool);
|
void set_rich_debug_enabled(bool);
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
void vdmesgln(StringView fmtstr, TypeErasedFormatParams&);
|
|
||||||
|
|
||||||
template<typename... Parameters>
|
|
||||||
void dmesgln(CheckedFormatString<Parameters...>&& fmt, Parameters const&... parameters)
|
|
||||||
{
|
|
||||||
VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> 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<typename... Parameters>
|
|
||||||
void critical_dmesgln(CheckedFormatString<Parameters...>&& fmt, Parameters const&... parameters)
|
|
||||||
{
|
|
||||||
VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
|
|
||||||
v_critical_dmesgln(fmt.view(), variadic_format_params);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class FormatIfSupported {
|
class FormatIfSupported {
|
||||||
public:
|
public:
|
||||||
|
@ -765,16 +731,12 @@ template<>
|
||||||
struct Formatter<Error> : Formatter<FormatString> {
|
struct Formatter<Error> : Formatter<FormatString> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
|
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
|
||||||
{
|
{
|
||||||
#if defined(AK_OS_SERENITY) && defined(KERNEL)
|
|
||||||
return Formatter<FormatString>::format(builder, "Error(errno={})"sv, error.code());
|
|
||||||
#else
|
|
||||||
if (error.is_syscall())
|
if (error.is_syscall())
|
||||||
return Formatter<FormatString>::format(builder, "{}: {} (errno={})"sv, error.string_literal(), strerror(error.code()), error.code());
|
return Formatter<FormatString>::format(builder, "{}: {} (errno={})"sv, error.string_literal(), strerror(error.code()), error.code());
|
||||||
if (error.is_errno())
|
if (error.is_errno())
|
||||||
return Formatter<FormatString>::format(builder, "{} (errno={})"sv, strerror(error.code()), error.code());
|
return Formatter<FormatString>::format(builder, "{} (errno={})"sv, strerror(error.code()), error.code());
|
||||||
|
|
||||||
return Formatter<FormatString>::format(builder, "{}"sv, error.string_literal());
|
return Formatter<FormatString>::format(builder, "{}"sv, error.string_literal());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -803,16 +765,11 @@ struct Formatter<Optional<T>> : Formatter<FormatString> {
|
||||||
} // namespace AK
|
} // namespace AK
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
# ifdef KERNEL
|
|
||||||
using AK::critical_dmesgln;
|
|
||||||
using AK::dmesgln;
|
|
||||||
# else
|
|
||||||
using AK::out;
|
using AK::out;
|
||||||
using AK::outln;
|
using AK::outln;
|
||||||
|
|
||||||
using AK::warn;
|
using AK::warn;
|
||||||
using AK::warnln;
|
using AK::warnln;
|
||||||
# endif
|
|
||||||
|
|
||||||
using AK::dbg;
|
using AK::dbg;
|
||||||
using AK::dbgln;
|
using AK::dbgln;
|
||||||
|
|
17
AK/Forward.h
17
AK/Forward.h
|
@ -122,17 +122,6 @@ class NonnullOwnPtr;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Optional;
|
class Optional;
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
template<typename T>
|
|
||||||
class NonnullLockRefPtr;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct LockRefPtrTraits;
|
|
||||||
|
|
||||||
template<typename T, typename PtrTraits = LockRefPtrTraits<T>>
|
|
||||||
class LockRefPtr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class RefPtr;
|
class RefPtr;
|
||||||
|
|
||||||
|
@ -210,10 +199,4 @@ using AK::Utf8CodePointIterator;
|
||||||
using AK::Utf8View;
|
using AK::Utf8View;
|
||||||
using AK::Vector;
|
using AK::Vector;
|
||||||
|
|
||||||
# ifdef KERNEL
|
|
||||||
using AK::LockRefPtr;
|
|
||||||
using AK::LockRefPtrTraits;
|
|
||||||
using AK::NonnullLockRefPtr;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -66,13 +66,8 @@ public:
|
||||||
using FunctionType = Out(In...);
|
using FunctionType = Out(In...);
|
||||||
using ReturnType = Out;
|
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 auto AccommodateExcessiveAlignmentRequirements = true;
|
||||||
constexpr static size_t ExcessiveAlignmentThreshold = 16;
|
constexpr static size_t ExcessiveAlignmentThreshold = 16;
|
||||||
#endif
|
|
||||||
|
|
||||||
Function() = default;
|
Function() = default;
|
||||||
Function(nullptr_t)
|
Function(nullptr_t)
|
||||||
|
@ -261,18 +256,14 @@ private:
|
||||||
}
|
}
|
||||||
VERIFY(m_call_nesting_level == 0);
|
VERIFY(m_call_nesting_level == 0);
|
||||||
using WrapperType = CallableWrapper<Callable>;
|
using WrapperType = CallableWrapper<Callable>;
|
||||||
#ifndef KERNEL
|
|
||||||
if constexpr (alignof(Callable) > inline_alignment || sizeof(WrapperType) > inline_capacity) {
|
if constexpr (alignof(Callable) > inline_alignment || sizeof(WrapperType) > inline_capacity) {
|
||||||
*bit_cast<CallableWrapperBase**>(&m_storage) = new WrapperType(forward<Callable>(callable));
|
*bit_cast<CallableWrapperBase**>(&m_storage) = new WrapperType(forward<Callable>(callable));
|
||||||
m_kind = FunctionKind::Outline;
|
m_kind = FunctionKind::Outline;
|
||||||
} else {
|
} else {
|
||||||
#endif
|
|
||||||
static_assert(sizeof(WrapperType) <= inline_capacity);
|
static_assert(sizeof(WrapperType) <= inline_capacity);
|
||||||
new (m_storage) WrapperType(forward<Callable>(callable));
|
new (m_storage) WrapperType(forward<Callable>(callable));
|
||||||
m_kind = FunctionKind::Inline;
|
m_kind = FunctionKind::Inline;
|
||||||
#ifndef KERNEL
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (callable_kind == CallableKind::FunctionObject)
|
if (callable_kind == CallableKind::FunctionObject)
|
||||||
m_size = sizeof(WrapperType);
|
m_size = sizeof(WrapperType);
|
||||||
else
|
else
|
||||||
|
@ -307,13 +298,8 @@ private:
|
||||||
mutable Atomic<u16> m_call_nesting_level { 0 };
|
mutable Atomic<u16> m_call_nesting_level { 0 };
|
||||||
|
|
||||||
static constexpr size_t inline_alignment = max(alignof(CallableWrapperBase), alignof(CallableWrapperBase*));
|
static constexpr size_t inline_alignment = max(alignof(CallableWrapperBase), alignof(CallableWrapperBase*));
|
||||||
#ifndef KERNEL
|
|
||||||
// Empirically determined to fit most lambdas and functions.
|
// Empirically determined to fit most lambdas and functions.
|
||||||
static constexpr size_t inline_capacity = 4 * sizeof(void*);
|
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];
|
alignas(inline_alignment) u8 m_storage[inline_capacity];
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/GenericLexer.h>
|
#include <AK/GenericLexer.h>
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <AK/Utf16View.h>
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
# include <AK/Utf16View.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
// Consume a number of characters
|
// Consume a number of characters
|
||||||
|
@ -210,7 +207,6 @@ template ErrorOr<i32> GenericLexer::consume_decimal_integer<i32>();
|
||||||
template ErrorOr<u64> GenericLexer::consume_decimal_integer<u64>();
|
template ErrorOr<u64> GenericLexer::consume_decimal_integer<u64>();
|
||||||
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
|
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
Optional<ByteString> GenericLexer::consume_and_unescape_string(char escape_char)
|
Optional<ByteString> GenericLexer::consume_and_unescape_string(char escape_char)
|
||||||
{
|
{
|
||||||
auto view = consume_quoted_string(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);
|
retreat(6);
|
||||||
return *high_surrogate;
|
return *high_surrogate;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,14 +92,12 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
bool consume_specific(ByteString next) = delete;
|
bool consume_specific(ByteString next) = delete;
|
||||||
|
|
||||||
bool consume_specific(String const& next)
|
bool consume_specific(String const& next)
|
||||||
{
|
{
|
||||||
return consume_specific(next.bytes_as_string_view());
|
return consume_specific(next.bytes_as_string_view());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr bool consume_specific(char const* next)
|
constexpr bool consume_specific(char const* next)
|
||||||
{
|
{
|
||||||
|
@ -128,9 +126,7 @@ public:
|
||||||
StringView consume_until(char const*);
|
StringView consume_until(char const*);
|
||||||
StringView consume_until(StringView);
|
StringView consume_until(StringView);
|
||||||
StringView consume_quoted_string(char escape_char = 0);
|
StringView consume_quoted_string(char escape_char = 0);
|
||||||
#ifndef KERNEL
|
|
||||||
Optional<ByteString> consume_and_unescape_string(char escape_char = '\\');
|
Optional<ByteString> consume_and_unescape_string(char escape_char = '\\');
|
||||||
#endif
|
|
||||||
template<Integral T>
|
template<Integral T>
|
||||||
ErrorOr<T> consume_decimal_integer();
|
ErrorOr<T> consume_decimal_integer();
|
||||||
|
|
||||||
|
@ -139,9 +135,7 @@ public:
|
||||||
UnicodeEscapeOverflow,
|
UnicodeEscapeOverflow,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
Result<u32, UnicodeEscapeError> consume_escaped_code_point(bool combine_surrogate_pairs = true);
|
Result<u32, UnicodeEscapeError> consume_escaped_code_point(bool combine_surrogate_pairs = true);
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr void ignore(size_t count = 1)
|
constexpr void ignore(size_t count = 1)
|
||||||
{
|
{
|
||||||
|
@ -228,10 +222,8 @@ protected:
|
||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef KERNEL
|
|
||||||
Result<u32, UnicodeEscapeError> decode_code_point();
|
Result<u32, UnicodeEscapeError> decode_code_point();
|
||||||
Result<u32, UnicodeEscapeError> decode_single_or_paired_surrogate(bool combine_surrogate_pairs);
|
Result<u32, UnicodeEscapeError> decode_single_or_paired_surrogate(bool combine_surrogate_pairs);
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LineTrackingLexer : public GenericLexer {
|
class LineTrackingLexer : public GenericLexer {
|
||||||
|
|
12
AK/Hex.cpp
12
AK/Hex.cpp
|
@ -34,17 +34,6 @@ ErrorOr<ByteBuffer> decode_hex(StringView input)
|
||||||
return { move(output) };
|
return { move(output) };
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> 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)
|
ByteString encode_hex(ReadonlyBytes const input)
|
||||||
{
|
{
|
||||||
StringBuilder output(input.size() * 2);
|
StringBuilder output(input.size() * 2);
|
||||||
|
@ -54,6 +43,5 @@ ByteString encode_hex(ReadonlyBytes const input)
|
||||||
|
|
||||||
return output.to_byte_string();
|
return output.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
11
AK/Hex.h
11
AK/Hex.h
|
@ -7,15 +7,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Library/KString.h>
|
|
||||||
#else
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
constexpr u8 decode_hex_digit(char digit)
|
constexpr u8 decode_hex_digit(char digit)
|
||||||
|
@ -31,11 +26,7 @@ constexpr u8 decode_hex_digit(char digit)
|
||||||
|
|
||||||
ErrorOr<ByteBuffer> decode_hex(StringView);
|
ErrorOr<ByteBuffer> decode_hex(StringView);
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(ReadonlyBytes);
|
|
||||||
#else
|
|
||||||
ByteString encode_hex(ReadonlyBytes);
|
ByteString encode_hex(ReadonlyBytes);
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,15 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/SipHash.h>
|
#include <AK/SipHash.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <AK/Error.h>
|
|
||||||
# include <Kernel/Library/KString.h>
|
|
||||||
#else
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
# include <AK/String.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class [[gnu::packed]] IPv4Address {
|
class [[gnu::packed]] IPv4Address {
|
||||||
|
@ -57,16 +51,6 @@ public:
|
||||||
return octet(SubnetClass(i));
|
return octet(SubnetClass(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> 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
|
ByteString to_byte_string() const
|
||||||
{
|
{
|
||||||
return ByteString::formatted("{}.{}.{}.{}",
|
return ByteString::formatted("{}.{}.{}.{}",
|
||||||
|
@ -93,7 +77,6 @@ public:
|
||||||
octet(SubnetClass::C),
|
octet(SubnetClass::C),
|
||||||
octet(SubnetClass::D));
|
octet(SubnetClass::D));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static Optional<IPv4Address> from_string(StringView string)
|
static Optional<IPv4Address> from_string(StringView string)
|
||||||
{
|
{
|
||||||
|
@ -166,15 +149,6 @@ struct Traits<IPv4Address> : public DefaultTraits<IPv4Address> {
|
||||||
static unsigned hash(IPv4Address const& address) { return secure_sip_hash(static_cast<u64>(address.to_u32())); }
|
static unsigned hash(IPv4Address const& address) { return secure_sip_hash(static_cast<u64>(address.to_u32())); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
template<>
|
|
||||||
struct Formatter<IPv4Address> : Formatter<StringView> {
|
|
||||||
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
|
||||||
{
|
|
||||||
return Formatter<StringView>::format(builder, TRY(value.to_string())->view());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<IPv4Address> : Formatter<StringView> {
|
struct Formatter<IPv4Address> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
||||||
|
@ -182,7 +156,6 @@ struct Formatter<IPv4Address> : Formatter<StringView> {
|
||||||
return Formatter<StringView>::format(builder, value.to_byte_string());
|
return Formatter<StringView>::format(builder, value.to_byte_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,19 +8,13 @@
|
||||||
|
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/IPv4Address.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <AK/Error.h>
|
|
||||||
# include <Kernel/Library/KString.h>
|
|
||||||
#else
|
|
||||||
# include <AK/String.h>
|
|
||||||
#endif
|
|
||||||
#include <AK/IPv4Address.h>
|
|
||||||
#include <AK/StringBuilder.h>
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class [[gnu::packed]] IPv6Address {
|
class [[gnu::packed]] IPv6Address {
|
||||||
|
@ -48,28 +42,16 @@ public:
|
||||||
|
|
||||||
constexpr u16 operator[](int i) const { return group(i); }
|
constexpr u16 operator[](int i) const { return group(i); }
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const
|
|
||||||
#else
|
|
||||||
ErrorOr<String> to_string() const
|
ErrorOr<String> to_string() const
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (is_zero()) {
|
if (is_zero()) {
|
||||||
#ifdef KERNEL
|
|
||||||
return Kernel::KString::try_create("::"sv);
|
|
||||||
#else
|
|
||||||
return "::"_string;
|
return "::"_string;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
if (is_ipv4_mapped()) {
|
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]);
|
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
|
// Find the start of the longest span of 0 values
|
||||||
|
@ -112,11 +94,7 @@ public:
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
#ifdef KERNEL
|
|
||||||
return Kernel::KString::try_create(builder.string_view());
|
|
||||||
#else
|
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<IPv6Address> from_string(StringView string)
|
static Optional<IPv6Address> from_string(StringView string)
|
||||||
|
@ -274,15 +252,6 @@ struct Traits<IPv6Address> : public DefaultTraits<IPv6Address> {
|
||||||
static unsigned hash(IPv6Address const& address) { return sip_hash_bytes<4, 8>({ &address.to_in6_addr_t(), sizeof(address.to_in6_addr_t()) }); }
|
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<IPv6Address> : Formatter<StringView> {
|
|
||||||
ErrorOr<void> format(FormatBuilder& builder, IPv6Address const& value)
|
|
||||||
{
|
|
||||||
return Formatter<StringView>::format(builder, TRY(value.to_string())->view());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<IPv6Address> : Formatter<StringView> {
|
struct Formatter<IPv6Address> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, IPv6Address const& value)
|
ErrorOr<void> format(FormatBuilder& builder, IPv6Address const& value)
|
||||||
|
@ -290,7 +259,6 @@ struct Formatter<IPv6Address> : Formatter<StringView> {
|
||||||
return Formatter<StringView>::format(builder, TRY(value.to_string()));
|
return Formatter<StringView>::format(builder, TRY(value.to_string()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
|
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Library/LockRefPtr.h>
|
|
||||||
#endif
|
|
||||||
namespace AK::Detail {
|
namespace AK::Detail {
|
||||||
|
|
||||||
template<typename T, typename Container>
|
template<typename T, typename Container>
|
||||||
|
@ -23,13 +20,6 @@ struct SubstituteIntrusiveContainerType<T, NonnullRefPtr<T>> {
|
||||||
using Type = RefPtr<T>;
|
using Type = RefPtr<T>;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
template<typename T>
|
|
||||||
struct SubstituteIntrusiveContainerType<T, NonnullLockRefPtr<T>> {
|
|
||||||
using Type = LockRefPtr<T>;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename Container, bool _IsRaw>
|
template<typename Container, bool _IsRaw>
|
||||||
struct SelfReferenceIfNeeded {
|
struct SelfReferenceIfNeeded {
|
||||||
Container reference = nullptr;
|
Container reference = nullptr;
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Library/LockRefPtr.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK::Detail {
|
namespace AK::Detail {
|
||||||
|
|
||||||
template<typename T, typename Container = RawPtr<T>>
|
template<typename T, typename Container = RawPtr<T>>
|
||||||
|
@ -436,22 +432,6 @@ public:
|
||||||
[[nodiscard]] NonnullRefPtr<T> take_last() { return *IntrusiveList<T, RefPtr<T>, member>::take_last(); }
|
[[nodiscard]] NonnullRefPtr<T> take_last() { return *IntrusiveList<T, RefPtr<T>, 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<class T, SubstitutedIntrusiveListNode<T, NonnullLockRefPtr<T>> T::*member>
|
|
||||||
class IntrusiveList<T, NonnullLockRefPtr<T>, member> : public IntrusiveList<T, LockRefPtr<T>, member> {
|
|
||||||
public:
|
|
||||||
[[nodiscard]] NonnullLockRefPtr<T> first() const { return *IntrusiveList<T, LockRefPtr<T>, member>::first(); }
|
|
||||||
[[nodiscard]] NonnullLockRefPtr<T> last() const { return *IntrusiveList<T, LockRefPtr<T>, member>::last(); }
|
|
||||||
|
|
||||||
[[nodiscard]] NonnullLockRefPtr<T> take_first() { return *IntrusiveList<T, LockRefPtr<T>, member>::take_first(); }
|
|
||||||
[[nodiscard]] NonnullLockRefPtr<T> take_last() { return *IntrusiveList<T, LockRefPtr<T>, member>::take_last(); }
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
|
@ -8,12 +8,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
|
#include <AK/JsonValue.h>
|
||||||
#include <AK/Try.h>
|
#include <AK/Try.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/JsonValue.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
|
@ -43,14 +40,12 @@ public:
|
||||||
|
|
||||||
JsonArraySerializer(JsonArraySerializer const&) = delete;
|
JsonArraySerializer(JsonArraySerializer const&) = delete;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> add(JsonValue const& value)
|
ErrorOr<void> add(JsonValue const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item());
|
TRY(begin_item());
|
||||||
value.serialize(m_builder);
|
value.serialize(m_builder);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> add(StringView value)
|
ErrorOr<void> add(StringView value)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +62,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> add(ByteString const& value)
|
ErrorOr<void> add(ByteString const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item());
|
TRY(begin_item());
|
||||||
|
@ -82,7 +76,6 @@ public:
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> add(char const* value)
|
ErrorOr<void> add(char const* value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,7 +108,6 @@ Optional<bool> JsonObject::get_bool(StringView key) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
Optional<ByteString> JsonObject::get_byte_string(StringView key) const
|
Optional<ByteString> JsonObject::get_byte_string(StringView key) const
|
||||||
{
|
{
|
||||||
auto maybe_value = get(key);
|
auto maybe_value = get(key);
|
||||||
|
@ -116,7 +115,6 @@ Optional<ByteString> JsonObject::get_byte_string(StringView key) const
|
||||||
return maybe_value->as_string();
|
return maybe_value->as_string();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Optional<JsonObject const&> JsonObject::get_object(StringView key) const
|
Optional<JsonObject const&> JsonObject::get_object(StringView key) const
|
||||||
{
|
{
|
||||||
|
@ -134,7 +132,6 @@ Optional<JsonArray const&> JsonObject::get_array(StringView key) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
Optional<double> JsonObject::get_double_with_precision_loss(StringView key) const
|
Optional<double> JsonObject::get_double_with_precision_loss(StringView key) const
|
||||||
{
|
{
|
||||||
auto maybe_value = get(key);
|
auto maybe_value = get(key);
|
||||||
|
@ -150,7 +147,6 @@ Optional<float> JsonObject::get_float_with_precision_loss(StringView key) const
|
||||||
return maybe_value->get_float_with_precision_loss();
|
return maybe_value->get_float_with_precision_loss();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool JsonObject::has(StringView key) const
|
bool JsonObject::has(StringView key) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,17 +74,13 @@ public:
|
||||||
Optional<FlatPtr> get_addr(StringView key) const;
|
Optional<FlatPtr> get_addr(StringView key) const;
|
||||||
Optional<bool> get_bool(StringView key) const;
|
Optional<bool> get_bool(StringView key) const;
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
Optional<ByteString> get_byte_string(StringView key) const;
|
Optional<ByteString> get_byte_string(StringView key) const;
|
||||||
#endif
|
|
||||||
|
|
||||||
Optional<JsonObject const&> get_object(StringView key) const;
|
Optional<JsonObject const&> get_object(StringView key) const;
|
||||||
Optional<JsonArray const&> get_array(StringView key) const;
|
Optional<JsonArray const&> get_array(StringView key) const;
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
Optional<double> get_double_with_precision_loss(StringView key) const;
|
Optional<double> get_double_with_precision_loss(StringView key) const;
|
||||||
Optional<float> get_float_with_precision_loss(StringView key) const;
|
Optional<float> get_float_with_precision_loss(StringView key) const;
|
||||||
#endif
|
|
||||||
|
|
||||||
void set(ByteString const& key, JsonValue value);
|
void set(ByteString const& key, JsonValue value);
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,9 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/JsonArraySerializer.h>
|
#include <AK/JsonArraySerializer.h>
|
||||||
|
#include <AK/JsonValue.h>
|
||||||
#include <AK/Try.h>
|
#include <AK/Try.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/JsonValue.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
|
@ -38,14 +35,12 @@ public:
|
||||||
|
|
||||||
JsonObjectSerializer(JsonObjectSerializer const&) = delete;
|
JsonObjectSerializer(JsonObjectSerializer const&) = delete;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> add(StringView key, JsonValue const& value)
|
ErrorOr<void> add(StringView key, JsonValue const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item(key));
|
TRY(begin_item(key));
|
||||||
value.serialize(m_builder);
|
value.serialize(m_builder);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> add(StringView key, StringView value)
|
ErrorOr<void> add(StringView key, StringView value)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +57,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> add(StringView key, ByteString const& value)
|
ErrorOr<void> add(StringView key, ByteString const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item(key));
|
TRY(begin_item(key));
|
||||||
|
@ -77,7 +71,6 @@ public:
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> add(StringView key, char const* value)
|
ErrorOr<void> add(StringView key, char const* value)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +157,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> add(StringView key, float value)
|
ErrorOr<void> add(StringView key, float value)
|
||||||
{
|
{
|
||||||
TRY(begin_item(key));
|
TRY(begin_item(key));
|
||||||
|
@ -184,7 +176,6 @@ public:
|
||||||
TRY(m_builder.appendff("{}", value));
|
TRY(m_builder.appendff("{}", value));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<JsonArraySerializer<Builder>> add_array(StringView key)
|
ErrorOr<JsonArraySerializer<Builder>> add_array(StringView key)
|
||||||
{
|
{
|
||||||
|
|
|
@ -211,11 +211,6 @@ ErrorOr<JsonValue> JsonParser::parse_number()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fallback_to_double_parse = [&]() -> ErrorOr<JsonValue> {
|
auto fallback_to_double_parse = [&]() -> ErrorOr<JsonValue> {
|
||||||
#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
|
// 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.
|
// use that in the floating point parser.
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# error "JsonValue does not propagate allocation failures, so it is not safe to use in the kernel."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <AK/ByteString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
#include <AK/StdLibExtraDetails.h>
|
#include <AK/StdLibExtraDetails.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# error "Including AK/Math.h from the Kernel is never correct! Floating point is disabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<FloatingPoint T>
|
template<FloatingPoint T>
|
||||||
|
|
|
@ -8,12 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <string.h>
|
||||||
#if defined(KERNEL)
|
|
||||||
# include <Kernel/Library/StdLib.h>
|
|
||||||
#else
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ALWAYS_INLINE void fast_u32_copy(u32* dest, u32 const* src, size_t count)
|
ALWAYS_INLINE void fast_u32_copy(u32* dest, u32 const* src, size_t count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,10 +9,7 @@
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
|
|
||||||
#if defined(KERNEL)
|
#if defined(AK_OS_SERENITY)
|
||||||
# include <Kernel/Arch/Processor.h>
|
|
||||||
# include <Kernel/Heap/kmalloc.h>
|
|
||||||
#elif defined(AK_OS_SERENITY)
|
|
||||||
# include <mallocdefs.h>
|
# include <mallocdefs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -37,9 +34,7 @@ public:
|
||||||
private:
|
private:
|
||||||
static bool get_thread_allocation_state()
|
static bool get_thread_allocation_state()
|
||||||
{
|
{
|
||||||
#if defined(KERNEL)
|
#if defined(AK_OS_SERENITY)
|
||||||
return Processor::current_thread()->get_allocation_enabled();
|
|
||||||
#elif defined(AK_OS_SERENITY)
|
|
||||||
// This extern thread-local lives in our LibC, which doesn't exist on other systems.
|
// This extern thread-local lives in our LibC, which doesn't exist on other systems.
|
||||||
return s_allocation_enabled;
|
return s_allocation_enabled;
|
||||||
#else
|
#else
|
||||||
|
@ -49,9 +44,7 @@ private:
|
||||||
|
|
||||||
static void set_thread_allocation_state(bool value)
|
static void set_thread_allocation_state(bool value)
|
||||||
{
|
{
|
||||||
#if defined(KERNEL)
|
#if defined(AK_OS_SERENITY)
|
||||||
Processor::current_thread()->set_allocation_enabled(value);
|
|
||||||
#elif defined(AK_OS_SERENITY)
|
|
||||||
s_allocation_enabled = value;
|
s_allocation_enabled = value;
|
||||||
#else
|
#else
|
||||||
(void)value;
|
(void)value;
|
||||||
|
|
|
@ -136,8 +136,6 @@ private:
|
||||||
T* m_ptr = nullptr;
|
T* m_ptr = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline NonnullOwnPtr<T> adopt_own(T& object)
|
inline NonnullOwnPtr<T> adopt_own(T& object)
|
||||||
{
|
{
|
||||||
|
@ -150,15 +148,13 @@ requires(IsConstructible<T, Args...>) inline NonnullOwnPtr<T> make(Args&&... arg
|
||||||
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *new T(forward<Args>(args)...));
|
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *new T(forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef AK_COMPILER_APPLE_CLANG
|
#ifdef AK_COMPILER_APPLE_CLANG
|
||||||
// FIXME: Remove once P0960R3 is available in Apple Clang.
|
// FIXME: Remove once P0960R3 is available in Apple Clang.
|
||||||
template<class T, class... Args>
|
template<class T, class... Args>
|
||||||
inline NonnullOwnPtr<T> make(Args&&... args)
|
inline NonnullOwnPtr<T> make(Args&&... args)
|
||||||
{
|
{
|
||||||
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *new T { forward<Args>(args)... });
|
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *new T { forward<Args>(args)... });
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Use like `adopt_nonnull_own_or_enomem(new (nothrow) T(args...))`.
|
// Use like `adopt_nonnull_own_or_enomem(new (nothrow) T(args...))`.
|
||||||
|
@ -220,11 +216,9 @@ struct Formatter<NonnullOwnPtr<T>> : Formatter<T const*> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
# if !defined(KERNEL)
|
using AK::adopt_nonnull_own_or_enomem;
|
||||||
using AK::adopt_own;
|
using AK::adopt_own;
|
||||||
using AK::make;
|
using AK::make;
|
||||||
# endif
|
|
||||||
using AK::adopt_nonnull_own_or_enomem;
|
|
||||||
using AK::NonnullOwnPtr;
|
using AK::NonnullOwnPtr;
|
||||||
using AK::try_make;
|
using AK::try_make;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -110,7 +110,6 @@ struct NumericLimits<unsigned long long> {
|
||||||
static constexpr size_t digits() { return __CHAR_BIT__ * sizeof(long long); }
|
static constexpr size_t digits() { return __CHAR_BIT__ * sizeof(long long); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<>
|
template<>
|
||||||
struct NumericLimits<float> {
|
struct NumericLimits<float> {
|
||||||
static constexpr float lowest() { return -__FLT_MAX__; }
|
static constexpr float lowest() { return -__FLT_MAX__; }
|
||||||
|
@ -143,7 +142,6 @@ struct NumericLimits<long double> {
|
||||||
static constexpr bool is_signed() { return true; }
|
static constexpr bool is_signed() { return true; }
|
||||||
static constexpr size_t digits() { return __LDBL_MANT_DIG__; }
|
static constexpr size_t digits() { return __LDBL_MANT_DIG__; }
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,9 @@
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <wchar.h>
|
||||||
#ifndef KERNEL
|
|
||||||
# include <math.h>
|
|
||||||
# include <wchar.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef AK_OS_SERENITY
|
#ifdef AK_OS_SERENITY
|
||||||
extern "C" size_t strlen(char const*);
|
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;
|
return field_width;
|
||||||
}
|
}
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename PutChFunc, typename CharType>
|
template<typename PutChFunc, typename CharType>
|
||||||
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)
|
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;
|
return length;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
template<typename PutChFunc, typename CharType>
|
template<typename PutChFunc, typename CharType>
|
||||||
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)
|
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.
|
// 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/printf.html
|
||||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wprintf.html
|
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wprintf.html
|
||||||
#ifndef KERNEL
|
|
||||||
if (state.long_qualifiers) {
|
if (state.long_qualifiers) {
|
||||||
wchar_t const* sp = NextArgument<wchar_t const*>()(ap);
|
wchar_t const* sp = NextArgument<wchar_t const*>()(ap);
|
||||||
if (!sp)
|
if (!sp)
|
||||||
sp = L"(null)";
|
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);
|
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<char const*>()(ap);
|
char const* sp = NextArgument<char const*>()(ap);
|
||||||
if (!sp)
|
if (!sp)
|
||||||
sp = "(null)";
|
sp = "(null)";
|
||||||
|
@ -398,7 +391,6 @@ struct PrintfImpl {
|
||||||
{
|
{
|
||||||
return print_hex(m_putch, m_bufptr, NextArgument<u64>()(ap), false, false, state.left_pad, state.zero_pad, 16, false, 1);
|
return print_hex(m_putch, m_bufptr, NextArgument<u64>()(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
|
ALWAYS_INLINE int format_g(ModifierState const& state, ArgumentListRefT ap) const
|
||||||
{
|
{
|
||||||
// FIXME: Exponent notation
|
// FIXME: Exponent notation
|
||||||
|
@ -408,7 +400,6 @@ struct PrintfImpl {
|
||||||
{
|
{
|
||||||
return print_double(m_putch, m_bufptr, NextArgument<double>()(ap), state.always_sign, state.left_pad, state.zero_pad, state.field_width, state.precision, true);
|
return print_double(m_putch, m_bufptr, NextArgument<double>()(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
|
ALWAYS_INLINE int format_o(ModifierState const& state, ArgumentListRefT ap) const
|
||||||
{
|
{
|
||||||
return print_octal_number(m_putch, m_bufptr, NextArgument<u32>()(ap), state.alternate_form, state.left_pad, state.zero_pad, state.field_width, state.has_precision, state.precision);
|
return print_octal_number(m_putch, m_bufptr, NextArgument<u32>()(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<CharType>* buffe
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(X);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(X);
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(c);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(c);
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(d);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(d);
|
||||||
#ifndef KERNEL
|
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(f);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(f);
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(g);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(g);
|
||||||
#endif
|
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(i);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(i);
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(n);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(n);
|
||||||
PRINTF_IMPL_DELEGATE_TO_IMPL(o);
|
PRINTF_IMPL_DELEGATE_TO_IMPL(o);
|
||||||
|
|
|
@ -9,11 +9,7 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/Atomic.h>
|
#include <AK/Atomic.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#ifdef KERNEL
|
#ifdef AK_OS_WINDOWS
|
||||||
# include <Kernel/Arch/Processor.h>
|
|
||||||
# include <Kernel/Library/ScopedCritical.h>
|
|
||||||
# include <Kernel/Locking/SpinlockProtected.h>
|
|
||||||
#elif defined(AK_OS_WINDOWS)
|
|
||||||
// Forward declare to avoid pulling Windows.h into every file in existence.
|
// Forward declare to avoid pulling Windows.h into every file in existence.
|
||||||
extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
|
extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
|
||||||
# ifndef sched_yield
|
# ifndef sched_yield
|
||||||
|
@ -37,17 +33,6 @@ struct SingletonInstanceCreator {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
|
|
||||||
template<typename T, Kernel::LockRank Rank>
|
|
||||||
struct SingletonInstanceCreator<Kernel::SpinlockProtected<T, Rank>> {
|
|
||||||
static Kernel::SpinlockProtected<T, Rank>* create()
|
|
||||||
{
|
|
||||||
return new Kernel::SpinlockProtected<T, Rank> {};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create>
|
template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create>
|
||||||
class Singleton {
|
class Singleton {
|
||||||
AK_MAKE_NONCOPYABLE(Singleton);
|
AK_MAKE_NONCOPYABLE(Singleton);
|
||||||
|
@ -62,9 +47,6 @@ public:
|
||||||
T* obj = obj_var.load(AK::memory_order_acquire);
|
T* obj = obj_var.load(AK::memory_order_acquire);
|
||||||
if (FlatPtr(obj) <= 0x1) {
|
if (FlatPtr(obj) <= 0x1) {
|
||||||
// If this is the first time, see if we get to initialize it
|
// If this is the first time, see if we get to initialize it
|
||||||
#ifdef KERNEL
|
|
||||||
Kernel::ScopedCritical critical;
|
|
||||||
#endif
|
|
||||||
if constexpr (allow_create) {
|
if constexpr (allow_create) {
|
||||||
if (obj == nullptr && obj_var.compare_exchange_strong(obj, (T*)0x1, AK::memory_order_acq_rel)) {
|
if (obj == nullptr && obj_var.compare_exchange_strong(obj, (T*)0x1, AK::memory_order_acq_rel)) {
|
||||||
// We're the first one
|
// We're the first one
|
||||||
|
@ -75,11 +57,7 @@ public:
|
||||||
}
|
}
|
||||||
// Someone else was faster, wait until they're done
|
// Someone else was faster, wait until they're done
|
||||||
while (obj == (T*)0x1) {
|
while (obj == (T*)0x1) {
|
||||||
#ifdef KERNEL
|
|
||||||
Kernel::Processor::wait_check();
|
|
||||||
#else
|
|
||||||
sched_yield();
|
sched_yield();
|
||||||
#endif
|
|
||||||
obj = obj_var.load(AK::memory_order_acquire);
|
obj = obj_var.load(AK::memory_order_acquire);
|
||||||
}
|
}
|
||||||
if constexpr (allow_create) {
|
if constexpr (allow_create) {
|
||||||
|
|
|
@ -181,7 +181,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
void append(U&& value)
|
void append(U&& value)
|
||||||
{
|
{
|
||||||
|
@ -193,7 +192,6 @@ public:
|
||||||
{
|
{
|
||||||
MUST(try_prepend(forward<U>(value)));
|
MUST(try_prepend(forward<U>(value)));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool contains_slow(T const& value) const
|
bool contains_slow(T const& value) const
|
||||||
{
|
{
|
||||||
|
@ -266,7 +264,6 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
void insert_before(Iterator iterator, U&& value)
|
void insert_before(Iterator iterator, U&& value)
|
||||||
{
|
{
|
||||||
|
@ -278,7 +275,6 @@ public:
|
||||||
{
|
{
|
||||||
MUST(try_insert_after(iterator, forward<U>(value)));
|
MUST(try_insert_after(iterator, forward<U>(value)));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void remove(Iterator& iterator)
|
void remove(Iterator& iterator)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,17 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/ByteReader.h>
|
#include <AK/ByteReader.h>
|
||||||
|
#include <AK/Random.h>
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
#include <AK/SipHash.h>
|
#include <AK/SipHash.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <AK/UFixedBigInt.h>
|
#include <AK/UFixedBigInt.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Security/Random.h>
|
|
||||||
#else
|
|
||||||
# include <AK/Random.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr u64 rotate_left(u64 x, u64 bits)
|
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 {
|
struct SipHashKey {
|
||||||
SipHashKey()
|
SipHashKey()
|
||||||
{
|
{
|
||||||
#ifdef KERNEL
|
|
||||||
key = Kernel::get_good_random<u128>();
|
|
||||||
#else
|
|
||||||
// get_random is assumed to be secure, otherwise SipHash doesn't deliver on its promises!
|
// get_random is assumed to be secure, otherwise SipHash doesn't deliver on its promises!
|
||||||
key = get_random<u128>();
|
key = get_random<u128>();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
constexpr u128 operator*() const { return key; }
|
constexpr u128 operator*() const { return key; }
|
||||||
u128 key;
|
u128 key;
|
||||||
|
|
|
@ -201,11 +201,9 @@ requires(!IsIntegral<T>)
|
||||||
__DEFINE_GENERIC_ABS(int, 0, abs);
|
__DEFINE_GENERIC_ABS(int, 0, abs);
|
||||||
__DEFINE_GENERIC_ABS(long, 0L, labs);
|
__DEFINE_GENERIC_ABS(long, 0L, labs);
|
||||||
__DEFINE_GENERIC_ABS(long long, 0LL, llabs);
|
__DEFINE_GENERIC_ABS(long long, 0LL, llabs);
|
||||||
#ifndef KERNEL
|
|
||||||
__DEFINE_GENERIC_ABS(float, 0.0F, fabsf);
|
__DEFINE_GENERIC_ABS(float, 0.0F, fabsf);
|
||||||
__DEFINE_GENERIC_ABS(double, 0.0, fabs);
|
__DEFINE_GENERIC_ABS(double, 0.0, fabs);
|
||||||
__DEFINE_GENERIC_ABS(long double, 0.0L, fabsl);
|
__DEFINE_GENERIC_ABS(long double, 0.0L, fabsl);
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef __DEFINE_GENERIC_ABS
|
#undef __DEFINE_GENERIC_ABS
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
|
#include <AK/FlyString.h>
|
||||||
#include <AK/PrintfImplementation.h>
|
#include <AK/PrintfImplementation.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/UnicodeUtils.h>
|
#include <AK/UnicodeUtils.h>
|
||||||
|
#include <AK/Utf16View.h>
|
||||||
#include <AK/Utf32View.h>
|
#include <AK/Utf32View.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
# include <AK/FlyString.h>
|
|
||||||
# include <AK/Utf16View.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
inline ErrorOr<void> StringBuilder::will_append(size_t size)
|
inline ErrorOr<void> StringBuilder::will_append(size_t size)
|
||||||
|
@ -143,7 +140,6 @@ ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
|
||||||
return ByteBuffer::copy(data(), length());
|
return ByteBuffer::copy(data(), length());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString StringBuilder::to_byte_string() const
|
ByteString StringBuilder::to_byte_string() const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
|
@ -170,7 +166,6 @@ ErrorOr<FlyString> StringBuilder::to_fly_string() const
|
||||||
{
|
{
|
||||||
return FlyString::from_utf8(string_view());
|
return FlyString::from_utf8(string_view());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
u8* StringBuilder::data()
|
u8* StringBuilder::data()
|
||||||
{
|
{
|
||||||
|
@ -230,7 +225,6 @@ void StringBuilder::append_code_point(u32 code_point)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
|
ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < utf16_view.length_in_code_units();) {
|
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));
|
MUST(try_append(utf16_view));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ErrorOr<void> StringBuilder::try_append(Utf32View const& utf32_view)
|
ErrorOr<void> StringBuilder::try_append(Utf32View const& utf32_view)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,9 +32,7 @@ public:
|
||||||
~StringBuilder() = default;
|
~StringBuilder() = default;
|
||||||
|
|
||||||
ErrorOr<void> try_append(StringView);
|
ErrorOr<void> try_append(StringView);
|
||||||
#ifndef KERNEL
|
|
||||||
ErrorOr<void> try_append(Utf16View const&);
|
ErrorOr<void> try_append(Utf16View const&);
|
||||||
#endif
|
|
||||||
ErrorOr<void> try_append(Utf32View const&);
|
ErrorOr<void> try_append(Utf32View const&);
|
||||||
ErrorOr<void> try_append_code_point(u32);
|
ErrorOr<void> try_append_code_point(u32);
|
||||||
ErrorOr<void> try_append(char);
|
ErrorOr<void> try_append(char);
|
||||||
|
@ -49,9 +47,7 @@ public:
|
||||||
ErrorOr<void> try_append_escaped_for_json(StringView);
|
ErrorOr<void> try_append_escaped_for_json(StringView);
|
||||||
|
|
||||||
void append(StringView);
|
void append(StringView);
|
||||||
#ifndef KERNEL
|
|
||||||
void append(Utf16View const&);
|
void append(Utf16View const&);
|
||||||
#endif
|
|
||||||
void append(Utf32View const&);
|
void append(Utf32View const&);
|
||||||
void append(char);
|
void append(char);
|
||||||
void append_code_point(u32);
|
void append_code_point(u32);
|
||||||
|
@ -69,9 +65,7 @@ public:
|
||||||
MUST(vformat(*this, fmtstr.view(), variadic_format_params));
|
MUST(vformat(*this, fmtstr.view(), variadic_format_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] ByteString to_byte_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] String to_string_without_validation() const;
|
[[nodiscard]] String to_string_without_validation() const;
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
|
|
|
@ -6,12 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#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 <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
|
#include <AK/FloatingPointStringConversions.h>
|
||||||
#include <AK/MemMem.h>
|
#include <AK/MemMem.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
@ -13,14 +15,7 @@
|
||||||
#include <AK/StringUtils.h>
|
#include <AK/StringUtils.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <string.h>
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Library/StdLib.h>
|
|
||||||
#else
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
# include <AK/FloatingPointStringConversions.h>
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -237,7 +232,6 @@ template Optional<u16> convert_to_uint_from_octal(StringView str, TrimWhitespace
|
||||||
template Optional<u32> convert_to_uint_from_octal(StringView str, TrimWhitespace);
|
template Optional<u32> convert_to_uint_from_octal(StringView str, TrimWhitespace);
|
||||||
template Optional<u64> convert_to_uint_from_octal(StringView str, TrimWhitespace);
|
template Optional<u64> convert_to_uint_from_octal(StringView str, TrimWhitespace);
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<T> convert_to_floating_point(StringView str, TrimWhitespace trim_whitespace)
|
Optional<T> convert_to_floating_point(StringView str, TrimWhitespace trim_whitespace)
|
||||||
{
|
{
|
||||||
|
@ -252,7 +246,6 @@ Optional<T> convert_to_floating_point(StringView str, TrimWhitespace trim_whites
|
||||||
|
|
||||||
template Optional<double> convert_to_floating_point(StringView str, TrimWhitespace);
|
template Optional<double> convert_to_floating_point(StringView str, TrimWhitespace);
|
||||||
template Optional<float> convert_to_floating_point(StringView str, TrimWhitespace);
|
template Optional<float> convert_to_floating_point(StringView str, TrimWhitespace);
|
||||||
#endif
|
|
||||||
|
|
||||||
bool equals_ignoring_ascii_case(StringView a, StringView b)
|
bool equals_ignoring_ascii_case(StringView a, StringView b)
|
||||||
{
|
{
|
||||||
|
@ -469,7 +462,6 @@ Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDire
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString to_snakecase(StringView str)
|
ByteString to_snakecase(StringView str)
|
||||||
{
|
{
|
||||||
auto should_insert_underscore = [&](auto i, auto current_char) {
|
auto should_insert_underscore = [&](auto i, auto current_char) {
|
||||||
|
@ -589,7 +581,6 @@ ErrorOr<String> replace(String const& haystack, StringView needle, StringView re
|
||||||
auto resulting_builder = replace_into_builder(source_bytes, needle, replacement, replace_mode, *maybe_first);
|
auto resulting_builder = replace_into_builder(source_bytes, needle, replacement, replace_mode, *maybe_first);
|
||||||
return resulting_builder.to_string();
|
return resulting_builder.to_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: Benchmark against KMP (AK/MemMem.h) and switch over if it's faster for short strings too
|
// 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)
|
size_t count(StringView str, StringView needle)
|
||||||
|
|
|
@ -82,10 +82,8 @@ template<typename T = unsigned>
|
||||||
Optional<T> convert_to_uint_from_hex(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
Optional<T> convert_to_uint_from_hex(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
||||||
template<typename T = unsigned>
|
template<typename T = unsigned>
|
||||||
Optional<T> convert_to_uint_from_octal(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
Optional<T> convert_to_uint_from_octal(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
||||||
#ifndef KERNEL
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<T> convert_to_floating_point(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
Optional<T> convert_to_floating_point(StringView, TrimWhitespace = TrimWhitespace::Yes);
|
||||||
#endif
|
|
||||||
bool equals_ignoring_ascii_case(StringView, StringView);
|
bool equals_ignoring_ascii_case(StringView, StringView);
|
||||||
bool ends_with(StringView a, StringView b, CaseSensitivity);
|
bool ends_with(StringView a, StringView b, CaseSensitivity);
|
||||||
bool starts_with(StringView, StringView, CaseSensitivity);
|
bool starts_with(StringView, StringView, CaseSensitivity);
|
||||||
|
|
|
@ -6,22 +6,18 @@
|
||||||
|
|
||||||
#include <AK/AnyOf.h>
|
#include <AK/AnyOf.h>
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
|
#include <AK/DeprecatedFlyString.h>
|
||||||
#include <AK/Find.h>
|
#include <AK/Find.h>
|
||||||
|
#include <AK/FlyString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
# include <AK/DeprecatedFlyString.h>
|
|
||||||
# include <AK/FlyString.h>
|
|
||||||
# include <AK/String.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
StringView::StringView(String const& string)
|
StringView::StringView(String const& string)
|
||||||
: m_characters(reinterpret_cast<char const*>(string.bytes().data()))
|
: m_characters(reinterpret_cast<char const*>(string.bytes().data()))
|
||||||
, m_length(string.bytes().size())
|
, m_length(string.bytes().size())
|
||||||
|
@ -45,7 +41,6 @@ StringView::StringView(DeprecatedFlyString const& string)
|
||||||
, m_length(string.length())
|
, m_length(string.length())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
StringView::StringView(ByteBuffer const& buffer)
|
StringView::StringView(ByteBuffer const& buffer)
|
||||||
: m_characters((char const*)buffer.data())
|
: 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);
|
return StringUtils::equals_ignoring_ascii_case(*this, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString StringView::to_lowercase_string() const
|
ByteString StringView::to_lowercase_string() const
|
||||||
{
|
{
|
||||||
return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull();
|
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);
|
return StringUtils::to_titlecase(*this);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
StringView StringView::substring_view_starting_from_substring(StringView substring) const
|
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;
|
return characters_to_copy == m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
|
|
||||||
bool StringView::operator==(ByteString const& string) const
|
bool StringView::operator==(ByteString const& string) const
|
||||||
{
|
{
|
||||||
return *this == string.view();
|
return *this == string.view();
|
||||||
|
@ -267,7 +258,6 @@ ByteString StringView::replace(StringView needle, StringView replacement, Replac
|
||||||
{
|
{
|
||||||
return StringUtils::replace(*this, needle, replacement, replace_mode);
|
return StringUtils::replace(*this, needle, replacement, replace_mode);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector<size_t> StringView::find_all(StringView needle) const
|
Vector<size_t> StringView::find_all(StringView needle) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,20 +48,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView(ByteBuffer const&);
|
StringView(ByteBuffer const&);
|
||||||
#ifndef KERNEL
|
|
||||||
StringView(String const&);
|
StringView(String const&);
|
||||||
StringView(FlyString const&);
|
StringView(FlyString const&);
|
||||||
StringView(ByteString const&);
|
StringView(ByteString const&);
|
||||||
StringView(DeprecatedFlyString const&);
|
StringView(DeprecatedFlyString const&);
|
||||||
#endif
|
|
||||||
|
|
||||||
explicit StringView(ByteBuffer&&) = delete;
|
explicit StringView(ByteBuffer&&) = delete;
|
||||||
#ifndef KERNEL
|
|
||||||
explicit StringView(String&&) = delete;
|
explicit StringView(String&&) = delete;
|
||||||
explicit StringView(FlyString&&) = delete;
|
explicit StringView(FlyString&&) = delete;
|
||||||
explicit StringView(ByteString&&) = delete;
|
explicit StringView(ByteString&&) = delete;
|
||||||
explicit StringView(DeprecatedFlyString&&) = delete;
|
explicit StringView(DeprecatedFlyString&&) = delete;
|
||||||
#endif
|
|
||||||
|
|
||||||
template<OneOf<String, FlyString, ByteString, DeprecatedFlyString, ByteBuffer> StringType>
|
template<OneOf<String, FlyString, ByteString, DeprecatedFlyString, ByteBuffer> StringType>
|
||||||
StringView& operator=(StringType&&) = delete;
|
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(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); }
|
[[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_lowercase_string() const;
|
||||||
[[nodiscard]] ByteString to_uppercase_string() const;
|
[[nodiscard]] ByteString to_uppercase_string() const;
|
||||||
[[nodiscard]] ByteString to_titlecase_string() const;
|
[[nodiscard]] ByteString to_titlecase_string() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
|
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
|
||||||
{
|
{
|
||||||
|
@ -285,9 +279,7 @@ public:
|
||||||
return m_length == 1 && *m_characters == c;
|
return m_length == 1 && *m_characters == c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
bool operator==(ByteString const&) const;
|
bool operator==(ByteString const&) const;
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr int compare(StringView other) const
|
[[nodiscard]] constexpr int compare(StringView other) const
|
||||||
{
|
{
|
||||||
|
@ -327,18 +319,14 @@ public:
|
||||||
|
|
||||||
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
|
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] ByteString to_byte_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] bool is_whitespace() const
|
[[nodiscard]] bool is_whitespace() const
|
||||||
{
|
{
|
||||||
return StringUtils::is_whitespace(*this);
|
return StringUtils::is_whitespace(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode) const;
|
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode) const;
|
||||||
#endif
|
|
||||||
[[nodiscard]] size_t count(StringView needle) const
|
[[nodiscard]] size_t count(StringView needle) const
|
||||||
{
|
{
|
||||||
return StringUtils::count(*this, needle);
|
return StringUtils::count(*this, needle);
|
||||||
|
@ -370,10 +358,8 @@ public:
|
||||||
template<Arithmetic T>
|
template<Arithmetic T>
|
||||||
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
|
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
|
||||||
{
|
{
|
||||||
#ifndef KERNEL
|
|
||||||
if constexpr (IsFloatingPoint<T>)
|
if constexpr (IsFloatingPoint<T>)
|
||||||
return StringUtils::convert_to_floating_point<T>(*this, trim_whitespace);
|
return StringUtils::convert_to_floating_point<T>(*this, trim_whitespace);
|
||||||
#endif
|
|
||||||
if constexpr (IsSigned<T>)
|
if constexpr (IsSigned<T>)
|
||||||
return StringUtils::convert_to_int<T>(*this, trim_whitespace);
|
return StringUtils::convert_to_int<T>(*this, trim_whitespace);
|
||||||
else
|
else
|
||||||
|
|
14
AK/Time.cpp
14
AK/Time.cpp
|
@ -6,15 +6,8 @@
|
||||||
|
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
// Make a reasonable guess as to which timespec/timeval definition to use.
|
#include <time.h>
|
||||||
// It doesn't really matter, since both are identical.
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/UnixTypes.h>
|
|
||||||
#else
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -207,7 +200,6 @@ Duration Duration::from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanos
|
||||||
return Duration { seconds + extra_seconds, nanoseconds };
|
return Duration { seconds + extra_seconds, nanoseconds };
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
namespace {
|
namespace {
|
||||||
static Duration now_time_from_clock(clockid_t clock_id)
|
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) };
|
return UnixDateTime { now_time_from_clock(CLOCK_REALTIME_COARSE) };
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
34
AK/Time.h
34
AK/Time.h
|
@ -12,20 +12,8 @@
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#if defined(AK_OS_SERENITY) && defined(KERNEL)
|
#include <time.h>
|
||||||
# include <Kernel/API/POSIX/sys/time.h>
|
|
||||||
# include <Kernel/API/POSIX/time.h>
|
|
||||||
|
|
||||||
// We need a Badge<TimeManagement> for some MonotonicTime operations.
|
|
||||||
namespace Kernel {
|
|
||||||
class TimeManagement;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -450,10 +438,8 @@ public:
|
||||||
// Subtracting two UNIX times yields their time difference.
|
// Subtracting two UNIX times yields their time difference.
|
||||||
constexpr Duration operator-(UnixDateTime const& other) const { return m_offset - other.m_offset; }
|
constexpr Duration operator-(UnixDateTime const& other) const { return m_offset - other.m_offset; }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] static UnixDateTime now();
|
[[nodiscard]] static UnixDateTime now();
|
||||||
[[nodiscard]] static UnixDateTime now_coarse();
|
[[nodiscard]] static UnixDateTime now_coarse();
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr bool operator==(UnixDateTime const& other) const
|
constexpr bool operator==(UnixDateTime const& other) const
|
||||||
{
|
{
|
||||||
|
@ -479,10 +465,8 @@ public:
|
||||||
constexpr MonotonicTime& operator=(MonotonicTime const&) = default;
|
constexpr MonotonicTime& operator=(MonotonicTime const&) = default;
|
||||||
constexpr MonotonicTime& operator=(MonotonicTime&&) = default;
|
constexpr MonotonicTime& operator=(MonotonicTime&&) = default;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
[[nodiscard]] static MonotonicTime now();
|
[[nodiscard]] static MonotonicTime now();
|
||||||
[[nodiscard]] static MonotonicTime now_coarse();
|
[[nodiscard]] static MonotonicTime now_coarse();
|
||||||
#endif
|
|
||||||
|
|
||||||
[[nodiscard]] i64 seconds() const { return m_offset.to_seconds(); }
|
[[nodiscard]] i64 seconds() const { return m_offset.to_seconds(); }
|
||||||
[[nodiscard]] i64 milliseconds() const { return m_offset.to_milliseconds(); }
|
[[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 MonotonicTime operator-(Duration const& other) const { return MonotonicTime { m_offset - other }; }
|
||||||
constexpr Duration operator-(MonotonicTime const& other) const { return m_offset - other.m_offset; }
|
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<Kernel::TimeManagement>, 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<Kernel::TimeManagement>)
|
|
||||||
{
|
|
||||||
return m_offset;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr explicit MonotonicTime(Duration offset)
|
constexpr explicit MonotonicTime(Duration offset)
|
||||||
: Detail::UnawareTime(offset)
|
: Detail::UnawareTime(offset)
|
||||||
|
|
|
@ -47,7 +47,6 @@ struct Traits<T> : public DefaultTraits<T> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<FloatingPoint T>
|
template<FloatingPoint T>
|
||||||
struct Traits<T> : public DefaultTraits<T> {
|
struct Traits<T> : public DefaultTraits<T> {
|
||||||
static constexpr bool is_trivial() { return true; }
|
static constexpr bool is_trivial() { return true; }
|
||||||
|
@ -60,7 +59,6 @@ struct Traits<T> : public DefaultTraits<T> {
|
||||||
return u64_hash(bit_cast<u64>(value));
|
return u64_hash(bit_cast<u64>(value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public DefaultTraits<T> {
|
requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public DefaultTraits<T> {
|
||||||
|
|
|
@ -232,10 +232,8 @@ private:
|
||||||
|
|
||||||
if constexpr (requires(MetadataType t) { { t.copy() } -> SpecializationOf<ErrorOr>; })
|
if constexpr (requires(MetadataType t) { { t.copy() } -> SpecializationOf<ErrorOr>; })
|
||||||
return Optional<MetadataType> { TRY(metadata->copy()) };
|
return Optional<MetadataType> { TRY(metadata->copy()) };
|
||||||
#ifndef KERNEL
|
|
||||||
else
|
else
|
||||||
return Optional<MetadataType> { MetadataType(metadata.value()) };
|
return Optional<MetadataType> { MetadataType(metadata.value()) };
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> skip_to_next_iterator(auto& state, auto& current_node)
|
static ErrorOr<void> skip_to_next_iterator(auto& state, auto& current_node)
|
||||||
|
|
|
@ -17,20 +17,18 @@ using i32 = __INT32_TYPE__;
|
||||||
using i16 = __INT16_TYPE__;
|
using i16 = __INT16_TYPE__;
|
||||||
using i8 = __INT8_TYPE__;
|
using i8 = __INT8_TYPE__;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
using f32 = float;
|
using f32 = float;
|
||||||
static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128);
|
static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128);
|
||||||
|
|
||||||
using f64 = double;
|
using f64 = double;
|
||||||
static_assert(__DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024);
|
static_assert(__DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024);
|
||||||
|
|
||||||
# if __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384
|
#if __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384
|
||||||
# define AK_HAS_FLOAT_80 1
|
# define AK_HAS_FLOAT_80 1
|
||||||
using f80 = long double;
|
using f80 = long double;
|
||||||
# elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384
|
#elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384
|
||||||
# define AK_HAS_FLOAT_128 1
|
# define AK_HAS_FLOAT_128 1
|
||||||
using f128 = long double;
|
using f128 = long double;
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AK::Detail {
|
namespace AK::Detail {
|
||||||
|
|
22
AK/UUID.cpp
22
AK/UUID.cpp
|
@ -76,27 +76,6 @@ UUID::UUID(StringView uuid_string_view, Endianness endianness)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> 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<String> UUID::to_string() const
|
ErrorOr<String> UUID::to_string() const
|
||||||
{
|
{
|
||||||
auto buffer_span = m_uuid_buffer.span();
|
auto buffer_span = m_uuid_buffer.span();
|
||||||
|
@ -112,7 +91,6 @@ ErrorOr<String> UUID::to_string() const
|
||||||
TRY(builder.try_append(encode_hex(buffer_span.slice(10, 6))));
|
TRY(builder.try_append(encode_hex(buffer_span.slice(10, 6))));
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool UUID::is_zero() const
|
bool UUID::is_zero() const
|
||||||
{
|
{
|
||||||
|
|
11
AK/UUID.h
11
AK/UUID.h
|
@ -8,15 +8,10 @@
|
||||||
|
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
# include <Kernel/Library/KString.h>
|
|
||||||
#else
|
|
||||||
# include <AK/String.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class UUID {
|
class UUID {
|
||||||
|
@ -33,11 +28,7 @@ public:
|
||||||
|
|
||||||
bool operator==(const UUID&) const = default;
|
bool operator==(const UUID&) const = default;
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const;
|
|
||||||
#else
|
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
#endif
|
|
||||||
bool is_zero() const;
|
bool is_zero() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -7,14 +7,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class Utf8View;
|
class Utf8View;
|
||||||
|
@ -71,14 +68,12 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
explicit Utf8View(ByteString& string)
|
explicit Utf8View(ByteString& string)
|
||||||
: m_string(string.view())
|
: m_string(string.view())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Utf8View(ByteString&&) = delete;
|
explicit Utf8View(ByteString&&) = delete;
|
||||||
#endif
|
|
||||||
|
|
||||||
enum class AllowSurrogates {
|
enum class AllowSurrogates {
|
||||||
Yes,
|
Yes,
|
||||||
|
@ -238,7 +233,6 @@ private:
|
||||||
mutable bool m_have_length { false };
|
mutable bool m_have_length { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
class DeprecatedStringCodePointIterator {
|
class DeprecatedStringCodePointIterator {
|
||||||
public:
|
public:
|
||||||
Optional<u32> next()
|
Optional<u32> next()
|
||||||
|
@ -272,7 +266,6 @@ private:
|
||||||
ByteString m_string;
|
ByteString m_string;
|
||||||
Utf8CodePointIterator m_it;
|
Utf8CodePointIterator m_it;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Utf8View> : Formatter<StringView> {
|
struct Formatter<Utf8View> : Formatter<StringView> {
|
||||||
|
@ -282,9 +275,7 @@ struct Formatter<Utf8View> : Formatter<StringView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
# ifndef KERNEL
|
|
||||||
using AK::DeprecatedStringCodePointIterator;
|
using AK::DeprecatedStringCodePointIterator;
|
||||||
# endif
|
|
||||||
using AK::Utf8CodePointIterator;
|
using AK::Utf8CodePointIterator;
|
||||||
using AK::Utf8View;
|
using AK::Utf8View;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -226,8 +226,6 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
void insert(size_t index, U&& value)
|
void insert(size_t index, U&& value)
|
||||||
requires(CanBePlacedInsideVector<U>)
|
requires(CanBePlacedInsideVector<U>)
|
||||||
|
@ -252,8 +250,6 @@ public:
|
||||||
MUST(try_extend(other));
|
MUST(try_extend(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ALWAYS_INLINE void append(T&& value)
|
ALWAYS_INLINE void append(T&& value)
|
||||||
{
|
{
|
||||||
if constexpr (contains_reference)
|
if constexpr (contains_reference)
|
||||||
|
@ -268,12 +264,10 @@ public:
|
||||||
MUST(try_append(T(value)));
|
MUST(try_append(T(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
void append(StorageType const* values, size_t count)
|
void append(StorageType const* values, size_t count)
|
||||||
{
|
{
|
||||||
MUST(try_append(values, count));
|
MUST(try_append(values, count));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
ALWAYS_INLINE void unchecked_append(U&& value)
|
ALWAYS_INLINE void unchecked_append(U&& value)
|
||||||
|
@ -296,7 +290,6 @@ public:
|
||||||
m_size += count;
|
m_size += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
void empend(Args&&... args)
|
void empend(Args&&... args)
|
||||||
requires(!contains_reference)
|
requires(!contains_reference)
|
||||||
|
@ -321,8 +314,6 @@ public:
|
||||||
MUST(try_prepend(values, count));
|
MUST(try_prepend(values, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// FIXME: What about assigning from a vector with lower inline capacity?
|
// FIXME: What about assigning from a vector with lower inline capacity?
|
||||||
Vector& operator=(Vector&& other)
|
Vector& operator=(Vector&& other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
|
|
||||||
#if defined(AK_OS_SERENITY) && !defined(KERNEL)
|
#if defined(AK_OS_SERENITY)
|
||||||
|
|
||||||
# include <AK/Assertions.h>
|
# include <AK/Assertions.h>
|
||||||
|
|
||||||
|
|
15
AK/kmalloc.h
15
AK/kmalloc.h
|
@ -9,22 +9,17 @@
|
||||||
|
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
|
#include <new>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if defined(KERNEL)
|
#define kcalloc calloc
|
||||||
# include <Kernel/Heap/kmalloc.h>
|
#define kmalloc malloc
|
||||||
#else
|
#define kmalloc_good_size malloc_good_size
|
||||||
# include <new>
|
|
||||||
# include <stdlib.h>
|
|
||||||
|
|
||||||
# define kcalloc calloc
|
|
||||||
# define kmalloc malloc
|
|
||||||
# define kmalloc_good_size malloc_good_size
|
|
||||||
|
|
||||||
inline void kfree_sized(void* ptr, size_t)
|
inline void kfree_sized(void* ptr, size_t)
|
||||||
{
|
{
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef AK_OS_SERENITY
|
#ifndef AK_OS_SERENITY
|
||||||
# include <AK/Types.h>
|
# include <AK/Types.h>
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
|
|
||||||
#ifdef AK_OS_SERENITY
|
#ifdef AK_OS_SERENITY
|
||||||
# ifdef KERNEL
|
|
||||||
# include <Kernel/kstdio.h>
|
|
||||||
# else
|
|
||||||
# include <AK/Types.h>
|
# include <AK/Types.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -19,7 +16,6 @@ void dbgputstr(char const*, size_t);
|
||||||
int sprintf(char* buf, char const* fmt, ...) __attribute__((format(printf, 2, 3)));
|
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)));
|
int snprintf(char* buffer, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
#else
|
#else
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
inline void dbgputstr(char const* characters, size_t length)
|
inline void dbgputstr(char const* characters, size_t length)
|
||||||
|
|
|
@ -7,14 +7,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteReader.h>
|
#include <AK/ByteReader.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibCrypto/Hash/HashFunction.h>
|
#include <LibCrypto/Hash/HashFunction.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Authentication {
|
namespace Crypto::Authentication {
|
||||||
|
|
||||||
void galois_multiply(u32 (&z)[4], u32 const (&x)[4], u32 const (&y)[4]);
|
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; }
|
constexpr static size_t digest_size() { return TagType::Size; }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString class_name() const
|
ByteString class_name() const
|
||||||
{
|
{
|
||||||
return "GHash";
|
return "GHash";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
TagType process(ReadonlyBytes aad, ReadonlyBytes cipher);
|
TagType process(ReadonlyBytes aad, ReadonlyBytes cipher);
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr static auto IPAD = 0x36;
|
constexpr static auto IPAD = 0x36;
|
||||||
constexpr static auto OPAD = 0x5c;
|
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());
|
m_outer_hasher.update(m_key_data + m_inner_hasher.block_size(), m_outer_hasher.block_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString class_name() const
|
ByteString class_name() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -80,7 +76,6 @@ public:
|
||||||
builder.append(m_inner_hasher.class_name());
|
builder.append(m_inner_hasher.class_name());
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void derive_key(u8 const* key, size_t length)
|
void derive_key(u8 const* key, size_t length)
|
||||||
|
|
|
@ -23,7 +23,6 @@ constexpr void swap_keys(u32* keys, size_t i, size_t j)
|
||||||
keys[j] = temp;
|
keys[j] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString AESCipherBlock::to_byte_string() const
|
ByteString AESCipherBlock::to_byte_string() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -39,7 +38,6 @@ ByteString AESCipherKey::to_byte_string() const
|
||||||
builder.appendff("{:02x}", m_rd_keys[i]);
|
builder.appendff("{:02x}", m_rd_keys[i]);
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void AESCipherKey::expand_encrypt_key(ReadonlyBytes user_key, size_t bits)
|
void AESCipherKey::expand_encrypt_key(ReadonlyBytes user_key, size_t bits)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,16 +7,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCrypto/Cipher/Cipher.h>
|
#include <LibCrypto/Cipher/Cipher.h>
|
||||||
#include <LibCrypto/Cipher/Mode/CBC.h>
|
#include <LibCrypto/Cipher/Mode/CBC.h>
|
||||||
#include <LibCrypto/Cipher/Mode/CTR.h>
|
#include <LibCrypto/Cipher/Mode/CTR.h>
|
||||||
#include <LibCrypto/Cipher/Mode/GCM.h>
|
#include <LibCrypto/Cipher/Mode/GCM.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Cipher {
|
namespace Crypto::Cipher {
|
||||||
|
|
||||||
struct AESCipherBlock : public CipherBlock {
|
struct AESCipherBlock : public CipherBlock {
|
||||||
|
@ -47,9 +44,7 @@ public:
|
||||||
m_data[i] ^= ivec[i];
|
m_data[i] ^= ivec[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString to_byte_string() const;
|
ByteString to_byte_string() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr static size_t data_size() { return sizeof(m_data); }
|
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;
|
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; }
|
static bool is_valid_key_size(size_t bits) { return bits == 128 || bits == 192 || bits == 256; }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
ByteString to_byte_string() const;
|
ByteString to_byte_string() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
u32 const* round_keys() const
|
u32 const* round_keys() const
|
||||||
{
|
{
|
||||||
|
@ -119,12 +112,10 @@ public:
|
||||||
virtual void encrypt_block(BlockType const& in, BlockType& out) override;
|
virtual void encrypt_block(BlockType const& in, BlockType& out) override;
|
||||||
virtual void decrypt_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
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "AES";
|
return "AES";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AESCipherKey m_key;
|
AESCipherKey m_key;
|
||||||
|
|
|
@ -111,9 +111,7 @@ public:
|
||||||
virtual void encrypt_block(BlockType const& in, BlockType& out) = 0;
|
virtual void encrypt_block(BlockType const& in, BlockType& out) = 0;
|
||||||
virtual void decrypt_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;
|
virtual ByteString class_name() const = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~Cipher() = default;
|
virtual ~Cipher() = default;
|
||||||
|
|
|
@ -6,14 +6,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibCrypto/Cipher/Mode/Mode.h>
|
#include <LibCrypto/Cipher/Mode/Mode.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Cipher {
|
namespace Crypto::Cipher {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -28,7 +25,6 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -36,7 +32,6 @@ public:
|
||||||
builder.append("_CBC"sv);
|
builder.append("_CBC"sv);
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual size_t IV_length() const override
|
virtual size_t IV_length() const override
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,14 +6,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibCrypto/Cipher/Mode/Mode.h>
|
#include <LibCrypto/Cipher/Mode/Mode.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Cipher {
|
namespace Crypto::Cipher {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -103,7 +100,6 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -111,7 +107,6 @@ public:
|
||||||
builder.append("_CTR"sv);
|
builder.append("_CTR"sv);
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual size_t IV_length() const override
|
virtual size_t IV_length() const override
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Memory.h>
|
#include <AK/Memory.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -14,10 +15,6 @@
|
||||||
#include <LibCrypto/Cipher/Mode/CTR.h>
|
#include <LibCrypto/Cipher/Mode/CTR.h>
|
||||||
#include <LibCrypto/Verification.h>
|
#include <LibCrypto/Verification.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Cipher {
|
namespace Crypto::Cipher {
|
||||||
|
|
||||||
using IncrementFunction = IncrementInplace;
|
using IncrementFunction = IncrementInplace;
|
||||||
|
@ -43,7 +40,6 @@ public:
|
||||||
m_ghash = Authentication::GHash(m_auth_key);
|
m_ghash = Authentication::GHash(m_auth_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -51,7 +47,6 @@ public:
|
||||||
builder.append("_GCM"sv);
|
builder.append("_GCM"sv);
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual size_t IV_length() const override
|
virtual size_t IV_length() const override
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,9 +33,7 @@ public:
|
||||||
return ByteBuffer::create_uninitialized(input_size + T::block_size() - remainder);
|
return ByteBuffer::create_uninitialized(input_size + T::block_size() - remainder);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const = 0;
|
virtual ByteString class_name() const = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
T& cipher()
|
T& cipher()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <LibCrypto/Hash/HashFunction.h>
|
#include <LibCrypto/Hash/HashFunction.h>
|
||||||
#include <LibCrypto/Hash/SHA2.h>
|
#include <LibCrypto/Hash/SHA2.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Hash {
|
namespace Crypto::Hash {
|
||||||
|
|
||||||
namespace BLAKE2bConstants {
|
namespace BLAKE2bConstants {
|
||||||
|
@ -43,12 +40,10 @@ public:
|
||||||
static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
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()); }
|
static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "BLAKE2b";
|
return "BLAKE2b";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void reset() override
|
virtual void reset() override
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,9 +54,7 @@ public:
|
||||||
|
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const = 0;
|
virtual ByteString class_name() const = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~HashFunction() = default;
|
virtual ~HashFunction() = default;
|
||||||
|
|
|
@ -196,14 +196,12 @@ public:
|
||||||
[&](auto& hash) { hash.reset(); });
|
[&](auto& hash) { hash.reset(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return m_algorithm.visit(
|
return m_algorithm.visit(
|
||||||
[&](Empty const&) -> ByteString { return "UninitializedHashManager"; },
|
[&](Empty const&) -> ByteString { return "UninitializedHashManager"; },
|
||||||
[&](auto const& hash) { return hash.class_name(); });
|
[&](auto const& hash) { return hash.class_name(); });
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
inline HashKind kind() const
|
inline HashKind kind() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibCrypto/Hash/HashFunction.h>
|
#include <LibCrypto/Hash/HashFunction.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Hash {
|
namespace Crypto::Hash {
|
||||||
|
|
||||||
namespace MD5Constants {
|
namespace MD5Constants {
|
||||||
|
@ -55,12 +52,10 @@ public:
|
||||||
virtual DigestType digest() override;
|
virtual DigestType digest() override;
|
||||||
virtual DigestType peek() override;
|
virtual DigestType peek() override;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "MD5";
|
return "MD5";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static DigestType hash(u8 const* data, size_t length)
|
static DigestType hash(u8 const* data, size_t length)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,12 +6,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <LibCrypto/Hash/HashFunction.h>
|
#include <LibCrypto/Hash/HashFunction.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Hash {
|
namespace Crypto::Hash {
|
||||||
|
|
||||||
namespace SHA1Constants {
|
namespace SHA1Constants {
|
||||||
|
@ -51,12 +48,10 @@ public:
|
||||||
static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
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()); }
|
static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "SHA1";
|
return "SHA1";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void reset() override
|
virtual void reset() override
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCrypto/Hash/HashFunction.h>
|
#include <LibCrypto/Hash/HashFunction.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::Hash {
|
namespace Crypto::Hash {
|
||||||
|
|
||||||
namespace SHA256Constants {
|
namespace SHA256Constants {
|
||||||
|
@ -99,12 +96,10 @@ public:
|
||||||
static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
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()); }
|
static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return ByteString::formatted("SHA{}", DigestSize * 8);
|
return ByteString::formatted("SHA{}", DigestSize * 8);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void reset() override
|
virtual void reset() override
|
||||||
{
|
{
|
||||||
|
@ -151,12 +146,10 @@ public:
|
||||||
static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
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()); }
|
static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return ByteString::formatted("SHA{}", DigestSize * 8);
|
return ByteString::formatted("SHA{}", DigestSize * 8);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void reset() override
|
virtual void reset() override
|
||||||
{
|
{
|
||||||
|
@ -203,12 +196,10 @@ public:
|
||||||
static DigestType hash(ByteBuffer const& buffer) { return hash(buffer.data(), buffer.size()); }
|
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()); }
|
static DigestType hash(StringView buffer) { return hash((u8 const*)buffer.characters_without_null_termination(), buffer.length()); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return ByteString::formatted("SHA{}", DigestSize * 8);
|
return ByteString::formatted("SHA{}", DigestSize * 8);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void reset() override
|
virtual void reset() override
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,12 +7,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <LibCrypto/ASN1/DER.h>
|
#include <LibCrypto/ASN1/DER.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
# include <AK/ByteString.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Crypto::PK {
|
namespace Crypto::PK {
|
||||||
|
|
||||||
template<typename ExportableKey>
|
template<typename ExportableKey>
|
||||||
|
@ -95,9 +92,7 @@ public:
|
||||||
virtual void sign(ReadonlyBytes in, Bytes& out) = 0;
|
virtual void sign(ReadonlyBytes in, Bytes& out) = 0;
|
||||||
virtual void verify(ReadonlyBytes in, Bytes& out) = 0;
|
virtual void verify(ReadonlyBytes in, Bytes& out) = 0;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const = 0;
|
virtual ByteString class_name() const = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual size_t output_size() const = 0;
|
virtual size_t output_size() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -206,12 +206,10 @@ public:
|
||||||
virtual void sign(ReadonlyBytes in, Bytes& out) override;
|
virtual void sign(ReadonlyBytes in, Bytes& out) override;
|
||||||
virtual void verify(ReadonlyBytes in, Bytes& out) override;
|
virtual void verify(ReadonlyBytes in, Bytes& out) override;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "RSA";
|
return "RSA";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual size_t output_size() const override
|
virtual size_t output_size() const override
|
||||||
{
|
{
|
||||||
|
@ -242,12 +240,11 @@ public:
|
||||||
virtual void sign(ReadonlyBytes, Bytes&) override;
|
virtual void sign(ReadonlyBytes, Bytes&) override;
|
||||||
virtual void verify(ReadonlyBytes, Bytes&) override;
|
virtual void verify(ReadonlyBytes, Bytes&) override;
|
||||||
|
|
||||||
#ifndef KERNEL
|
|
||||||
virtual ByteString class_name() const override
|
virtual ByteString class_name() const override
|
||||||
{
|
{
|
||||||
return "RSA_PKCS1-EME";
|
return "RSA_PKCS1-EME";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
virtual size_t output_size() const override
|
virtual size_t output_size() const override
|
||||||
{
|
{
|
||||||
return m_public_key.length();
|
return m_public_key.length();
|
||||||
|
|
|
@ -9,11 +9,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibTest/TestSuite.h>
|
#include <LibTest/TestSuite.h>
|
||||||
|
|
||||||
#ifdef KERNEL
|
#define TEST_MAIN main
|
||||||
# define TEST_MAIN test_main
|
|
||||||
#else
|
|
||||||
# define TEST_MAIN main
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int TEST_MAIN(int argc, char** argv)
|
int TEST_MAIN(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue