diff options
| author | Arseney300 <Arseney300@gmail.com> | 2026-04-12 02:01:25 +0700 |
|---|---|---|
| committer | Arseney300 <Arseney300@gmail.com> | 2026-04-12 02:01:25 +0700 |
| commit | 2496ffd6d97c3ccd3e325687442d31ab035479a1 (patch) | |
| tree | 5d176669f823182fe74261f076dc11c8e8f88025 /kernel/lib/string.cpp | |
| parent | 496246c92dabe6757480147016490ea6ae43bb66 (diff) | |
bastion: add freestanding C++ standard library (libcxx)feature/freestanding-libcxx
Header-only implementation of a C++ standard library subset for the
freestanding kernel, using Clang builtins wherever possible. Provides
19 public headers (~35 internal files): type_traits, utility, memory,
algorithm, functional, concepts, array, string_view, span, optional,
expected, variant, tuple, bit, limits, new, initializer_list, cstdint,
cstddef, and source_location.
Integration changes:
- kernel/Makefile: add -Ilib/libcxx/include to include path
- kernel/lib/string.cpp: add memchr and strncmp (needed by string_view)
- kernel/lib/cxxabi.cpp: guard placement new against <new> header conflict
- kernel/include/kernel/kernel.h: Panic() now uses std::source_location
- kernel/core/kernel.cpp: Panic() implementation updated to match
Builds cleanly on both x86_64 and aarch64 with zero new warnings.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'kernel/lib/string.cpp')
| -rw-r--r-- | kernel/lib/string.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/lib/string.cpp b/kernel/lib/string.cpp index 3bd60fa..1365147 100644 --- a/kernel/lib/string.cpp +++ b/kernel/lib/string.cpp @@ -75,4 +75,22 @@ char* strncpy(char* dest, const char* src, size_t n) { return dest; } +void* memchr(const void* s, int c, size_t n) { + auto* p = static_cast<const uint8_t*>(s); + auto uc = static_cast<uint8_t>(c); + for (size_t i = 0; i < n; i++) + if (p[i] == uc) return const_cast<void*>(static_cast<const void*>(p + i)); + return nullptr; +} + +int strncmp(const char* s1, const char* s2, size_t n) { + const auto* u1 = reinterpret_cast<const uint8_t*>(s1); + const auto* u2 = reinterpret_cast<const uint8_t*>(s2); + for (size_t i = 0; i < n; i++) { + if (u1[i] != u2[i]) return static_cast<int>(u1[i]) - static_cast<int>(u2[i]); + if (u1[i] == 0) break; + } + return 0; +} + } // extern "C" |
