diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-28 18:31:39 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-28 18:31:39 +0100 |
| commit | 12dedc7e2e51390fdf2caec3700e75db19be1cd4 (patch) | |
| tree | 3dffc472cdc680417adf400026d626407d05dd04 /libs/kstd | |
| parent | 9535226376ea812007fbe8a2aaf6cf3ccb77c263 (diff) | |
| download | teachos-12dedc7e2e51390fdf2caec3700e75db19be1cd4.tar.xz teachos-12dedc7e2e51390fdf2caec3700e75db19be1cd4.zip | |
kstd: don't rely on newlib
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/bits/os.hpp | 2 | ||||
| -rw-r--r-- | libs/kstd/src/bits/os.cpp | 10 | ||||
| -rw-r--r-- | libs/kstd/src/cstdlib.cpp | 18 | ||||
| -rw-r--r-- | libs/kstd/src/cstring.cpp | 10 |
5 files changed, 48 insertions, 0 deletions
diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index ac9e78f..666a5d7 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -2,6 +2,9 @@ add_library("kstd" STATIC) add_library("libs::kstd" ALIAS "kstd") target_sources("kstd" PRIVATE + "src/bits/os.cpp" + "src/cstdlib.cpp" + "src/cstring.cpp" "src/mutex.cpp" ) @@ -23,3 +26,8 @@ target_sources("kstd" PUBLIC target_include_directories("kstd" PUBLIC "include" ) + +target_link_options("kstd" INTERFACE + "-Wl,--undefined=abort" + "-Wl,--undefined=strlen" +)
\ 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 0425b88..7f5fcc8 100644 --- a/libs/kstd/include/kstd/bits/os.hpp +++ b/libs/kstd/include/kstd/bits/os.hpp @@ -6,6 +6,8 @@ namespace kstd::os { + auto abort() -> bool; + [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; } diff --git a/libs/kstd/src/bits/os.cpp b/libs/kstd/src/bits/os.cpp new file mode 100644 index 0000000..fb64202 --- /dev/null +++ b/libs/kstd/src/bits/os.cpp @@ -0,0 +1,10 @@ +#include "kstd/bits/os.hpp" + +namespace kstd::os +{ + [[gnu::weak]] + auto abort() -> bool + { + return false; + } +} // namespace kstd::os
\ No newline at end of file diff --git a/libs/kstd/src/cstdlib.cpp b/libs/kstd/src/cstdlib.cpp new file mode 100644 index 0000000..8fb5f63 --- /dev/null +++ b/libs/kstd/src/cstdlib.cpp @@ -0,0 +1,18 @@ +#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 new file mode 100644 index 0000000..5419b7d --- /dev/null +++ b/libs/kstd/src/cstring.cpp @@ -0,0 +1,10 @@ +#include <algorithm> +#include <cstddef> + +extern "C" +{ + auto strlen(const char * string) -> std::size_t + { + return std::distance(string, std::ranges::find(string, nullptr, '\0')); + } +} |
