From 47b935e2c85a794d60c22e8d96f53c0a2d364977 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 9 Jul 2026 13:55:03 +0200 Subject: kstd: rename kstd header to include hpp --- kapi/kapi/acpi.hpp | 4 ++-- kapi/kapi/boot_module/boot_module_registry.hpp | 2 +- kapi/kapi/cio.hpp | 2 +- kapi/kapi/cpu.hpp | 4 ++-- kapi/kapi/devices/bus.hpp | 8 ++++---- kapi/kapi/devices/device.hpp | 4 ++-- kapi/kapi/devices/manager.hpp | 2 +- kapi/kapi/memory/address.hpp | 4 ++-- kapi/kapi/memory/chunk.hpp | 2 +- kapi/kapi/memory/layout.hpp | 2 +- kapi/kapi/memory/page_mapper.hpp | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) (limited to 'kapi') diff --git a/kapi/kapi/acpi.hpp b/kapi/kapi/acpi.hpp index 885fcde1..eb82c781 100644 --- a/kapi/kapi/acpi.hpp +++ b/kapi/kapi/acpi.hpp @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include #include diff --git a/kapi/kapi/boot_module/boot_module_registry.hpp b/kapi/kapi/boot_module/boot_module_registry.hpp index fc3590fc..fdba0740 100644 --- a/kapi/kapi/boot_module/boot_module_registry.hpp +++ b/kapi/kapi/boot_module/boot_module_registry.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include diff --git a/kapi/kapi/cio.hpp b/kapi/kapi/cio.hpp index 9bbf7fa7..5c4cc8b7 100644 --- a/kapi/kapi/cio.hpp +++ b/kapi/kapi/cio.hpp @@ -3,7 +3,7 @@ #include // IWYU pragma: export -#include +#include #include #include diff --git a/kapi/kapi/cpu.hpp b/kapi/kapi/cpu.hpp index deaf5cd7..41e00e40 100644 --- a/kapi/kapi/cpu.hpp +++ b/kapi/kapi/cpu.hpp @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include #include diff --git a/kapi/kapi/devices/bus.hpp b/kapi/kapi/devices/bus.hpp index 59f49f73..8e2b5acf 100644 --- a/kapi/kapi/devices/bus.hpp +++ b/kapi/kapi/devices/bus.hpp @@ -5,10 +5,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/kapi/kapi/devices/device.hpp b/kapi/kapi/devices/device.hpp index 70cf01f3..104d7b8e 100644 --- a/kapi/kapi/devices/device.hpp +++ b/kapi/kapi/devices/device.hpp @@ -3,8 +3,8 @@ // IWYU pragma: private, include -#include -#include +#include +#include #include diff --git a/kapi/kapi/devices/manager.hpp b/kapi/kapi/devices/manager.hpp index c9b90b4e..c317b61e 100644 --- a/kapi/kapi/devices/manager.hpp +++ b/kapi/kapi/devices/manager.hpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include diff --git a/kapi/kapi/memory/address.hpp b/kapi/kapi/memory/address.hpp index 9231cfc6..d176d2b8 100644 --- a/kapi/kapi/memory/address.hpp +++ b/kapi/kapi/memory/address.hpp @@ -3,8 +3,8 @@ // IWYU pragma: private, include -#include -#include +#include +#include #include #include diff --git a/kapi/kapi/memory/chunk.hpp b/kapi/kapi/memory/chunk.hpp index 485a890d..36d83b2e 100644 --- a/kapi/kapi/memory/chunk.hpp +++ b/kapi/kapi/memory/chunk.hpp @@ -3,7 +3,7 @@ // IWYU pragma: private, include -#include +#include #include #include diff --git a/kapi/kapi/memory/layout.hpp b/kapi/kapi/memory/layout.hpp index 733fa960..5f720a51 100644 --- a/kapi/kapi/memory/layout.hpp +++ b/kapi/kapi/memory/layout.hpp @@ -5,7 +5,7 @@ #include -#include +#include namespace kapi::memory { diff --git a/kapi/kapi/memory/page_mapper.hpp b/kapi/kapi/memory/page_mapper.hpp index fb600b2d..579c14fd 100644 --- a/kapi/kapi/memory/page_mapper.hpp +++ b/kapi/kapi/memory/page_mapper.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include -- cgit v1.2.3 From f54e09351a967da21f863fd2d3b17ffd24d3ee87 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 12 Jul 2026 15:24:40 +0200 Subject: kernel: integrate kstd system_error facility --- kapi/kapi/filesystem.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'kapi') diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp index 3bd9aaf4..02f174e9 100644 --- a/kapi/kapi/filesystem.hpp +++ b/kapi/kapi/filesystem.hpp @@ -1,9 +1,11 @@ #ifndef TEACHOS_KAPI_FILESYSTEM_HPP #define TEACHOS_KAPI_FILESYSTEM_HPP +#include #include #include +#include #include namespace kapi::filesystem @@ -39,7 +41,7 @@ namespace kapi::filesystem @return A file descriptor on success, -1 on failure. @qualifier kernel-defined */ - auto open(std::string_view path) -> kstd::ssize_t; + auto open(std::string_view path) -> std::expected; /** @brief Closes a @p file_descriptor. -- cgit v1.2.3 From 3dc0df78f96dae38a54208d78e14f977f085b9bb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 12 Jul 2026 21:37:50 +0200 Subject: kapi: enforce stricter error handling --- kapi/kapi/filesystem.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'kapi') diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp index 02f174e9..5346a96d 100644 --- a/kapi/kapi/filesystem.hpp +++ b/kapi/kapi/filesystem.hpp @@ -2,7 +2,6 @@ #define TEACHOS_KAPI_FILESYSTEM_HPP #include -#include #include #include @@ -22,23 +21,23 @@ namespace kapi::filesystem @brief Mounts a filesystem from the specified @p source at the specified @p target path. @param source The source device or filesystem to mount. @param target The target mount point. - @return 0 on success, -1 on failure. + @return Nothing on success, an error code otherwise. @qualifier kernel-defined */ - auto mount(std::string_view source, std::string_view target) -> kstd::ssize_t; + auto mount(std::string_view source, std::string_view target) -> std::expected; /** @brief Unmounts a filesystem from the specified @p target path. @param target The target mount point to unmount. - @return 0 on success, -1 on failure. + @return Nothing on success, an error code otherwise. @qualifier kernel-defined */ - auto umount(std::string_view target) -> kstd::ssize_t; + auto umount(std::string_view target) -> std::expected; /** @brief Opens a file at the specified @p path. @param path The path to the file to open. - @return A file descriptor on success, -1 on failure. + @return A file descriptor on success, an error code otherwise. @qualifier kernel-defined */ auto open(std::string_view path) -> std::expected; @@ -46,30 +45,30 @@ namespace kapi::filesystem /** @brief Closes a @p file_descriptor. @param file_descriptor The file descriptor to close. - @return 0 on success, -1 on failure. + @return Nothing on success, an error code otherwise . @qualifier kernel-defined */ - auto close(size_t file_descriptor) -> kstd::ssize_t; + auto close(size_t file_descriptor) -> std::expected; /** @brief Reads @p size bytes into @p buffer from a @p file_descriptor. @param file_descriptor The file descriptor to read from. @param buffer The buffer to store the read data. @param size The number of bytes to read. - @return The number of bytes read on success, -1 on failure. + @return The number of bytes read on success, an error code otherwise. @qualifier kernel-defined */ - auto read(size_t file_descriptor, void * buffer, size_t size) -> kstd::ssize_t; + auto read(size_t file_descriptor, void * buffer, size_t size) -> std::expected; /** @brief Writes @p size bytes from @p buffer to a @p file_descriptor. @param file_descriptor The file descriptor to write to. @param buffer The buffer containing the data to write. @param size The number of bytes to write. - @return The number of bytes written on success, -1 on failure. + @return The number of bytes written on success, an error code otherwise. @qualifier kernel-defined */ - auto write(size_t file_descriptor, void const * buffer, size_t size) -> kstd::ssize_t; + auto write(size_t file_descriptor, void const * buffer, size_t size) -> std::expected; } // namespace kapi::filesystem #endif // TEACHOS_KAPI_FILESYSTEM_HPP \ No newline at end of file -- cgit v1.2.3 From 48b95e0b46e32f35ea6f16f41ab99286856292bf Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 13 Jul 2026 12:00:39 +0200 Subject: kapi: extend panic formatting --- kapi/kapi/system.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'kapi') diff --git a/kapi/kapi/system.hpp b/kapi/kapi/system.hpp index 8a20af94..f7dd4d7c 100644 --- a/kapi/kapi/system.hpp +++ b/kapi/kapi/system.hpp @@ -1,8 +1,15 @@ #ifndef TEACHOS_KAPI_SYSTEM_HPP #define TEACHOS_KAPI_SYSTEM_HPP +#include +#include + +#include +#include #include +#include #include +#include namespace kapi::system { @@ -10,6 +17,26 @@ namespace kapi::system //! @addtogroup kapi-system-kernel-defined //! @{ + template + struct panic_format_string + { + kstd::format_string format; + std::source_location location; + + template + consteval panic_format_string(char const (&format)[Size], // NOLINT + std::source_location location = std::source_location::current()) + : format{format} + , location{location} + {} + + consteval panic_format_string(std::string_view const & format, + std::source_location location = std::source_location::current()) + : format{format} + , location{location} + {} + }; + //! Terminate kernel execution with the given error message. //! //! This function terminates the execution of the kernel and attempts to issue the given error message to the user. @@ -17,6 +44,14 @@ namespace kapi::system //! @param message The message associated with the panic [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; + //! Termite kernel execution with the given error message and error code. + //! + //! This function terminates the execution of the kernel and attempts to issue the given error message to the user. + //! @param message The message associated with the panic. + //! @param error The erro code associated with the panic. + [[noreturn]] auto panic(std::string_view message, kstd::error_code error, + std::source_location = std::source_location::current()) -> void; + //! @} // end group kernel-defined //! @addtogroup kapi-system-platform-defined @@ -26,6 +61,15 @@ namespace kapi::system auto memory_initialized() -> void; //! @} // end group platform-defined + // + template + [[noreturn]] auto panic(panic_format_string...> format, + FormatArguments &&... arguments) + { + auto buffer = std::array{}; + auto [_, length] = kstd::format_to(std::span{buffer}, format.format, std::forward(arguments)...); + panic(std::string_view{buffer.data(), length}, format.location); + } } // namespace kapi::system -- cgit v1.2.3