diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index cef9bd27..0112746b 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -413,9 +413,3 @@ extern "C" return f; } } - -void debug_log_impl(const char* format, va_list ap) -{ - vfprintf(stderr, format, ap); - fputc('\n', stderr); -} diff --git a/libc/src/sys/mman.cpp b/libc/src/sys/mman.cpp index 2ac4f3cc..ca38884b 100644 --- a/libc/src/sys/mman.cpp +++ b/libc/src/sys/mman.cpp @@ -18,17 +18,3 @@ extern "C" __errno_return(rc, int); } } - -Result allocate_pages_impl(usize count) -{ - long rc = syscall(SYS_mmap, nullptr, count * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS); - if (rc < 0) { return err((int)-rc); } - return (void*)rc; -} - -Result release_pages_impl(void* address, usize count) -{ - long rc = syscall(SYS_munmap, address, count * PAGE_SIZE); - if (rc < 0) { return err((int)-rc); } - return {}; -} diff --git a/libluna/CMakeLists.txt b/libluna/CMakeLists.txt index 3d1f3cee..e0bac9cf 100644 --- a/libluna/CMakeLists.txt +++ b/libluna/CMakeLists.txt @@ -29,8 +29,8 @@ set(FREESTANDING_SOURCES set(SOURCES ${FREESTANDING_SOURCES} - src/Check.cpp src/CppABI.cpp + src/ImplPOSIX.cpp ) add_library(luna-freestanding ${FREESTANDING_SOURCES}) diff --git a/libluna/src/Check.cpp b/libluna/src/Check.cpp deleted file mode 100644 index edd1df74..00000000 --- a/libluna/src/Check.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -#include -#include - -_weak [[noreturn]] bool __check_failed(SourceLocation location, const char* expr) -{ - fprintf(stderr, "Check failed at %s:%d in %s: %s\n", location.file(), location.line(), location.function(), expr); - abort(); -} diff --git a/libluna/src/ImplPOSIX.cpp b/libluna/src/ImplPOSIX.cpp new file mode 100644 index 00000000..ba799a32 --- /dev/null +++ b/libluna/src/ImplPOSIX.cpp @@ -0,0 +1,36 @@ +/* POSIX userspace implementation of libluna hooks. */ + +#include +#include +#include + +#include +#include +#include +#include + +_weak [[noreturn]] bool __check_failed(SourceLocation location, const char* expr) +{ + fprintf(stderr, "Check failed at %s:%d in %s: %s\n", location.file(), location.line(), location.function(), expr); + abort(); +} + +void debug_log_impl(const char* format, va_list ap) +{ + vfprintf(stderr, format, ap); + fputc('\n', stderr); +} + +Result allocate_pages_impl(usize count) +{ + void* rc = mmap(nullptr, count * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (rc == MAP_FAILED) { return err(errno); } + return rc; +} + +Result release_pages_impl(void* address, usize count) +{ + int rc = munmap(address, count * PAGE_SIZE); + if (rc < 0) { return err(errno); } + return {}; +}