aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/kstd/CMakeLists.txt16
-rw-r--r--libs/kstd/include/kstd/bits/os.hpp25
-rw-r--r--libs/kstd/src/bits/os.cpp6
-rw-r--r--libs/kstd/src/cstdlib.cpp18
-rw-r--r--libs/kstd/src/cstring.cpp10
-rw-r--r--libs/kstd/src/libc/stdlib.cpp11
-rw-r--r--libs/kstd/src/libc/string.cpp15
-rw-r--r--src/kstd.cpp6
8 files changed, 61 insertions, 46 deletions
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt
index 666a5d7..75c2315 100644
--- a/libs/kstd/CMakeLists.txt
+++ b/libs/kstd/CMakeLists.txt
@@ -1,10 +1,15 @@
add_library("kstd" STATIC)
add_library("libs::kstd" ALIAS "kstd")
+set(KSTD_LIBC_SYMBOLS
+ "abort"
+ "strlen"
+)
+
target_sources("kstd" PRIVATE
"src/bits/os.cpp"
- "src/cstdlib.cpp"
- "src/cstring.cpp"
+ "src/libc/stdlib.cpp"
+ "src/libc/string.cpp"
"src/mutex.cpp"
)
@@ -27,7 +32,6 @@ target_include_directories("kstd" PUBLIC
"include"
)
-target_link_options("kstd" INTERFACE
- "-Wl,--undefined=abort"
- "-Wl,--undefined=strlen"
-) \ No newline at end of file
+list(TRANSFORM KSTD_LIBC_SYMBOLS PREPEND "-Wl,--undefined=")
+
+target_link_options("kstd" INTERFACE ${KSTD_LIBC_SYMBOLS}) \ No newline at end of file
diff --git a/libs/kstd/include/kstd/bits/os.hpp b/libs/kstd/include/kstd/bits/os.hpp
index 7f5fcc8..0474f16 100644
--- a/libs/kstd/include/kstd/bits/os.hpp
+++ b/libs/kstd/include/kstd/bits/os.hpp
@@ -6,10 +6,29 @@
namespace kstd::os
{
- auto abort() -> bool;
+ /**
+ * @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 = std::source_location::current()) -> void;
-}
+ 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/src/bits/os.cpp b/libs/kstd/src/bits/os.cpp
index fb64202..e6edbfd 100644
--- a/libs/kstd/src/bits/os.cpp
+++ b/libs/kstd/src/bits/os.cpp
@@ -2,9 +2,9 @@
namespace kstd::os
{
- [[gnu::weak]]
- auto abort() -> bool
+ [[gnu::weak, noreturn]]
+ auto abort() -> void
{
- return false;
+ os::panic("Abort called.");
}
} // namespace kstd::os \ No newline at end of file
diff --git a/libs/kstd/src/cstdlib.cpp b/libs/kstd/src/cstdlib.cpp
deleted file mode 100644
index 8fb5f63..0000000
--- a/libs/kstd/src/cstdlib.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "kstd/bits/os.hpp"
-
-namespace kstd
-{
-
- extern "C"
- {
- [[noreturn]] auto abort() -> void
- {
- if (!kstd::os::abort())
- {
- os::panic("System abort handler returned.");
- }
- __builtin_trap();
- }
- }
-
-} // namespace kstd \ No newline at end of file
diff --git a/libs/kstd/src/cstring.cpp b/libs/kstd/src/cstring.cpp
deleted file mode 100644
index 5419b7d..0000000
--- a/libs/kstd/src/cstring.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <algorithm>
-#include <cstddef>
-
-extern "C"
-{
- auto strlen(const char * string) -> std::size_t
- {
- return std::distance(string, std::ranges::find(string, nullptr, '\0'));
- }
-}
diff --git a/libs/kstd/src/libc/stdlib.cpp b/libs/kstd/src/libc/stdlib.cpp
new file mode 100644
index 0000000..fe1bc95
--- /dev/null
+++ b/libs/kstd/src/libc/stdlib.cpp
@@ -0,0 +1,11 @@
+#include "kstd/bits/os.hpp"
+
+namespace kstd::libc
+{
+
+ extern "C"
+ {
+ [[noreturn]] auto abort() -> void { kstd::os::abort(); }
+ }
+
+} // namespace kstd::libc \ No newline at end of file
diff --git a/libs/kstd/src/libc/string.cpp b/libs/kstd/src/libc/string.cpp
new file mode 100644
index 0000000..c6b3847
--- /dev/null
+++ b/libs/kstd/src/libc/string.cpp
@@ -0,0 +1,15 @@
+#include <algorithm>
+#include <cstddef>
+
+namespace kstd::libc
+{
+
+ extern "C"
+ {
+ auto strlen(const char * string) -> std::size_t
+ {
+ return std::distance(string, std::ranges::find(string, nullptr, '\0'));
+ }
+ }
+
+} // namespace kstd::libc \ No newline at end of file
diff --git a/src/kstd.cpp b/src/kstd.cpp
index 77155af..2149c12 100644
--- a/src/kstd.cpp
+++ b/src/kstd.cpp
@@ -5,12 +5,6 @@
namespace kstd::os
{
- auto abort() -> bool
- {
- panic("Abort called.");
- return true;
- }
-
auto panic(std::string_view message, std::source_location location) -> void
{
teachos::system::panic(message, location);