Files
kaguya 9a9b91c940 user: implement mlibc as the libc, finally.
It's finally done..

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
2026-05-02 03:31:49 -04:00

32 lines
743 B
C++

#include <stdint.h>
#include <string.h>
#include <mlibc/debug.hpp>
#include <mlibc/stack_protector.hpp>
uintptr_t __stack_chk_guard = 0;
namespace mlibc {
void initStackGuard(void *entropy) {
if(entropy != nullptr) {
memcpy(&__stack_chk_guard, entropy, sizeof(__stack_chk_guard));
} else {
// If no entropy is available, set it to the terminator canary
__stack_chk_guard = 0;
__stack_chk_guard |= ('\n' << 16);
__stack_chk_guard |= (255 << 24);
}
}
} // namespace mlibc
extern "C" [[noreturn]] void __stack_chk_fail() {
mlibc::panicLogger() << "Stack smashing detected!" << frg::endlog;
__builtin_unreachable();
}
extern "C" [[noreturn, gnu::visibility("hidden")]] void __stack_chk_fail_local() {
__stack_chk_fail();
};