From 03c64b950b62e88de431234cde1764d134c8bd2f Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 22 May 2023 19:54:59 +0300 Subject: [PATCH] BAN: Errors.h can be included from userspace --- BAN/include/BAN/Errors.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/BAN/include/BAN/Errors.h b/BAN/include/BAN/Errors.h index d4e2c70656..3a00435958 100644 --- a/BAN/include/BAN/Errors.h +++ b/BAN/include/BAN/Errors.h @@ -1,12 +1,13 @@ #pragma once #include +#include #include #include #include -#if defined(__is_kernel) +#ifdef __is_kernel #include #include #define MUST(expr) ({ auto&& e = expr; if (e.is_error()) Kernel::panic("{}", e.error()); e.release_value(); }) @@ -24,29 +25,37 @@ namespace BAN class Error { +#ifdef __is_kernel private: static constexpr uint64_t kernel_error_mask = uint64_t(1) << 63; +#endif public: +#ifdef __is_kernel static Error from_error_code(Kernel::ErrorCode error) { return Error((uint64_t)error | kernel_error_mask); } +#endif static Error from_errno(int error) { return Error(error); } +#ifdef __is_kernel Kernel::ErrorCode kernel_error() const { return (Kernel::ErrorCode)(m_error_code & ~kernel_error_mask); } +#endif uint64_t get_error_code() const { return m_error_code; } BAN::StringView get_message() const { +#ifdef __is_kernel if (m_error_code & kernel_error_mask) return Kernel::error_string(kernel_error()); +#endif return strerror(m_error_code); } @@ -132,7 +141,7 @@ namespace BAN void release_value() { } private: - Error m_data { Error::from_error_code(Kernel::ErrorCode::None) }; + Error m_data { Error::from_errno(0) }; bool m_has_error { false }; };