aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/acpi.hpp4
-rw-r--r--kapi/kapi/boot_module/boot_module_registry.hpp2
-rw-r--r--kapi/kapi/cio.hpp2
-rw-r--r--kapi/kapi/cpu.hpp4
-rw-r--r--kapi/kapi/devices/bus.hpp8
-rw-r--r--kapi/kapi/devices/device.hpp4
-rw-r--r--kapi/kapi/devices/manager.hpp2
-rw-r--r--kapi/kapi/filesystem.hpp27
-rw-r--r--kapi/kapi/memory/address.hpp4
-rw-r--r--kapi/kapi/memory/chunk.hpp2
-rw-r--r--kapi/kapi/memory/layout.hpp2
-rw-r--r--kapi/kapi/memory/page_mapper.hpp2
-rw-r--r--kapi/kapi/system.hpp44
13 files changed, 76 insertions, 31 deletions
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 <acpi/acpi.hpp>
-#include <kstd/memory>
-#include <kstd/units>
+#include <kstd/memory.hpp>
+#include <kstd/units.hpp>
#include <string_view>
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 <kapi/boot_module/boot_module.hpp>
-#include <kstd/vector>
+#include <kstd/vector.hpp>
#include <cstddef>
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 <kapi/cio/output_device.hpp> // IWYU pragma: export
-#include <kstd/format>
+#include <kstd/format.hpp>
#include <optional>
#include <string_view>
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 <kapi/memory.hpp>
-#include <kstd/format>
-#include <kstd/memory>
+#include <kstd/format.hpp>
+#include <kstd/memory.hpp>
#include <cstdint>
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 <kapi/devices/device.hpp>
-#include <kstd/memory>
-#include <kstd/print>
-#include <kstd/string>
-#include <kstd/vector>
+#include <kstd/memory.hpp>
+#include <kstd/print.hpp>
+#include <kstd/string.hpp>
+#include <kstd/vector.hpp>
#include <atomic>
#include <cstddef>
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 <kapi/devices.hpp>
-#include <kstd/memory>
-#include <kstd/string>
+#include <kstd/memory.hpp>
+#include <kstd/string.hpp>
#include <cstddef>
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 <kapi/devices/device.hpp>
-#include <kstd/memory>
+#include <kstd/memory.hpp>
#include <cstddef>
#include <string_view>
diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp
index 3bd9aaf4..5346a96d 100644
--- a/kapi/kapi/filesystem.hpp
+++ b/kapi/kapi/filesystem.hpp
@@ -1,9 +1,10 @@
#ifndef TEACHOS_KAPI_FILESYSTEM_HPP
#define TEACHOS_KAPI_FILESYSTEM_HPP
-#include <kstd/unikstd.h>
+#include <kstd/system_error.hpp>
#include <cstddef>
+#include <expected>
#include <string_view>
namespace kapi::filesystem
@@ -20,54 +21,54 @@ 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<void, kstd::error_code>;
/**
@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<void, kstd::error_code>;
/**
@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) -> kstd::ssize_t;
+ auto open(std::string_view path) -> std::expected<std::size_t, kstd::error_code>;
/**
@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<void, kstd::error_code>;
/**
@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<std::size_t, kstd::error_code>;
/**
@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<std::size_t, kstd::error_code>;
} // namespace kapi::filesystem
#endif // TEACHOS_KAPI_FILESYSTEM_HPP \ No newline at end of file
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 <kapi/memory.hpp>
-#include <kstd/format>
-#include <kstd/units>
+#include <kstd/format.hpp>
+#include <kstd/units.hpp>
#include <bit>
#include <compare>
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 <kapi/memory.hpp>
-#include <kstd/units>
+#include <kstd/units.hpp>
#include <compare>
#include <cstddef>
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 <kapi/memory/address.hpp>
-#include <kstd/units>
+#include <kstd/units.hpp>
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 <kapi/memory/frame.hpp>
#include <kapi/memory/page.hpp>
-#include <kstd/ext/bitfield_enum>
+#include <kstd/ext/bitfield_enum.hpp>
#include <cstddef>
#include <cstdint>
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 <kstd/format.hpp>
+#include <kstd/system_error.hpp>
+
+#include <array>
+#include <cstddef>
#include <source_location>
+#include <span>
#include <string_view>
+#include <type_traits>
namespace kapi::system
{
@@ -10,6 +17,26 @@ namespace kapi::system
//! @addtogroup kapi-system-kernel-defined
//! @{
+ template<typename... FormatArguments>
+ struct panic_format_string
+ {
+ kstd::format_string<FormatArguments...> format;
+ std::source_location location;
+
+ template<std::size_t Size>
+ 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<typename... FormatArguments>
+ [[noreturn]] auto panic(panic_format_string<std::type_identity_t<FormatArguments>...> format,
+ FormatArguments &&... arguments)
+ {
+ auto buffer = std::array<char, 512uz>{};
+ auto [_, length] = kstd::format_to(std::span{buffer}, format.format, std::forward<FormatArguments>(arguments)...);
+ panic(std::string_view{buffer.data(), length}, format.location);
+ }
} // namespace kapi::system