From e22c2dcad410504c65d8ccba0ab66d96cf0c61a1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 19 Dec 2025 11:55:48 +0100 Subject: kstd: clean up OS interface split --- libs/kstd/CMakeLists.txt | 8 +++++-- libs/kstd/include/kstd/bits/os.hpp | 34 ------------------------------ libs/kstd/include/kstd/bits/print_sink.hpp | 19 +++++++++++++++++ libs/kstd/include/kstd/os/error.hpp | 34 ++++++++++++++++++++++++++++++ libs/kstd/include/kstd/os/print.hpp | 14 ++++++++++++ libs/kstd/include/kstd/print | 15 +++---------- libs/kstd/src/bits/os.cpp | 10 --------- libs/kstd/src/libc/stdlib.cpp | 2 +- libs/kstd/src/os/error.cpp | 12 +++++++++++ 9 files changed, 89 insertions(+), 59 deletions(-) delete mode 100644 libs/kstd/include/kstd/bits/os.hpp create mode 100644 libs/kstd/include/kstd/bits/print_sink.hpp create mode 100644 libs/kstd/include/kstd/os/error.hpp create mode 100644 libs/kstd/include/kstd/os/print.hpp delete mode 100644 libs/kstd/src/bits/os.cpp create mode 100644 libs/kstd/src/os/error.cpp (limited to 'libs') diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index 0814a5b..1f140f6 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -8,9 +8,11 @@ set(KSTD_LIBC_SYMBOLS ) target_sources("kstd" PRIVATE - "src/bits/os.cpp" "src/libc/stdlib.cpp" "src/libc/string.cpp" + + "src/os/error.cpp" + "src/mutex.cpp" ) @@ -22,12 +24,14 @@ target_sources("kstd" PUBLIC "include/kstd/bits/format_specs.hpp" "include/kstd/bits/format_string.hpp" "include/kstd/bits/formatter.hpp" - "include/kstd/bits/os.hpp" "include/kstd/bits/shared_ptr.hpp" "include/kstd/bits/unique_ptr.hpp" "include/kstd/ext/bitfield_enum" + "include/kstd/os/error.hpp" + "include/kstd/os/print.hpp" + "include/kstd/asm_ptr" "include/kstd/format" "include/kstd/memory" diff --git a/libs/kstd/include/kstd/bits/os.hpp b/libs/kstd/include/kstd/bits/os.hpp deleted file mode 100644 index 0474f16..0000000 --- a/libs/kstd/include/kstd/bits/os.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef KSTD_OS_HPP -#define KSTD_OS_HPP - -#include -#include - -namespace kstd::os -{ - /** - * @brief Handle an unrecoverable library error. - * - * The operating system kernel may choose to implement this function in order to try to perform additional cleanup - * before terminating execution. If the kernel does not implement this function, the default implementation will be - * chosen. This default implementation doest nothing. - */ - [[noreturn]] - auto abort() -> void; - - /** - * @brief Terminate execution of the operating system. - * - * The operating system must implement this function. This function must terminate the execution of the operating - * system kernel as is. It may choose to restart the kernel or to halt execution entirely. The implementation must - * guarantee that execution never return from this function. - * - * @param message A message describing the reason for termination of execution. - * @param where The source code location at which the panic was triggered. In general, no argument shall be provided - * for this parameter, thus implicitly capturing the location at which the call originates. - */ - [[noreturn]] - auto panic(std::string_view message, std::source_location where = std::source_location::current()) -> void; -} // namespace kstd::os - -#endif \ No newline at end of file diff --git a/libs/kstd/include/kstd/bits/print_sink.hpp b/libs/kstd/include/kstd/bits/print_sink.hpp new file mode 100644 index 0000000..0e0955c --- /dev/null +++ b/libs/kstd/include/kstd/bits/print_sink.hpp @@ -0,0 +1,19 @@ +#ifndef KSTD_BITS_PRINT_SINK_HPP +#define KSTD_BITS_PRINT_SINK_HPP + +// IWYU pragma: private, include + +#include + +namespace kstd +{ + + enum struct print_sink + { + stdout, + stderr, + }; + +} // namespace kstd + +#endif \ No newline at end of file diff --git a/libs/kstd/include/kstd/os/error.hpp b/libs/kstd/include/kstd/os/error.hpp new file mode 100644 index 0000000..9d43fb1 --- /dev/null +++ b/libs/kstd/include/kstd/os/error.hpp @@ -0,0 +1,34 @@ +#ifndef KSTD_OS_ERROR_HPP +#define KSTD_OS_ERROR_HPP + +#include +#include + +namespace kstd::os +{ + /** + * @brief Handle an unrecoverable library error. + * + * The operating system kernel may choose to implement this function in order to try to perform additional cleanup + * before terminating execution. If the kernel does not implement this function, the default implementation will be + * chosen. This default implementation doest nothing. + */ + [[noreturn]] + auto abort() -> void; + + /** + * @brief Terminate execution of the operating system. + * + * The operating system must implement this function. This function must terminate the execution of the operating + * system kernel as is. It may choose to restart the kernel or to halt execution entirely. The implementation must + * guarantee that execution never return from this function. + * + * @param message A message describing the reason for termination of execution. + * @param where The source code location at which the panic was triggered. In general, no argument shall be provided + * for this parameter, thus implicitly capturing the location at which the call originates. + */ + [[noreturn]] + auto panic(std::string_view message, std::source_location where = std::source_location::current()) -> void; +} // namespace kstd::os + +#endif \ No newline at end of file diff --git a/libs/kstd/include/kstd/os/print.hpp b/libs/kstd/include/kstd/os/print.hpp new file mode 100644 index 0000000..f189042 --- /dev/null +++ b/libs/kstd/include/kstd/os/print.hpp @@ -0,0 +1,14 @@ +#ifndef KSTD_OS_PRINT_HPP +#define KSTD_OS_PRINT_HPP + +#include "kstd/bits/formatter.hpp" +#include "kstd/bits/print_sink.hpp" + +#include + +namespace kstd::os +{ + auto vprint(print_sink sink, std::string_view format, kstd::format_args args) -> void; +} // namespace kstd::os + +#endif \ No newline at end of file diff --git a/libs/kstd/include/kstd/print b/libs/kstd/include/kstd/print index df42997..ffafda9 100644 --- a/libs/kstd/include/kstd/print +++ b/libs/kstd/include/kstd/print @@ -1,26 +1,17 @@ #ifndef KSTD_PRINT #define KSTD_PRINT +#include "bits/print_sink.hpp" // IWYU pragma: export +#include "os/print.hpp" + #include #include -#include #include namespace kstd { - enum struct print_sink - { - stdout, - stderr, - }; - - namespace os - { - auto vprint(print_sink sink, std::string_view format, kstd::format_args args) -> void; - } // namespace os - //! @qualifier kernel-defined //! Format the given string using the given arguments and print it to the currently active output device. //! diff --git a/libs/kstd/src/bits/os.cpp b/libs/kstd/src/bits/os.cpp deleted file mode 100644 index e6edbfd..0000000 --- a/libs/kstd/src/bits/os.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "kstd/bits/os.hpp" - -namespace kstd::os -{ - [[gnu::weak, noreturn]] - auto abort() -> void - { - os::panic("Abort called."); - } -} // namespace kstd::os \ No newline at end of file diff --git a/libs/kstd/src/libc/stdlib.cpp b/libs/kstd/src/libc/stdlib.cpp index a0f062a..4a5c91f 100644 --- a/libs/kstd/src/libc/stdlib.cpp +++ b/libs/kstd/src/libc/stdlib.cpp @@ -1,4 +1,4 @@ -#include "kstd/bits/os.hpp" +#include "kstd/os/error.hpp" namespace kstd::libc { diff --git a/libs/kstd/src/os/error.cpp b/libs/kstd/src/os/error.cpp new file mode 100644 index 0000000..b82158d --- /dev/null +++ b/libs/kstd/src/os/error.cpp @@ -0,0 +1,12 @@ +#include "kstd/os/error.hpp" + +namespace kstd::os +{ + + [[gnu::weak, noreturn]] + auto abort() -> void + { + os::panic("Abort called."); + } + +} // namespace kstd::os \ No newline at end of file -- cgit v1.2.3