libc+libluna: Move libluna hooks out of libc and into a central place in libluna
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ff952cfe16
commit
cc72a1655d
@ -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);
|
||||
}
|
||||
|
@ -18,17 +18,3 @@ extern "C"
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
}
|
||||
|
||||
Result<void*> 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<void> release_pages_impl(void* address, usize count)
|
||||
{
|
||||
long rc = syscall(SYS_munmap, address, count * PAGE_SIZE);
|
||||
if (rc < 0) { return err((int)-rc); }
|
||||
return {};
|
||||
}
|
||||
|
@ -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})
|
||||
|
@ -1,11 +0,0 @@
|
||||
#include <luna/Attributes.h>
|
||||
#include <luna/SourceLocation.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
_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();
|
||||
}
|
36
libluna/src/ImplPOSIX.cpp
Normal file
36
libluna/src/ImplPOSIX.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* POSIX userspace implementation of libluna hooks. */
|
||||
|
||||
#include <luna/Attributes.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/SourceLocation.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
_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<void*> 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<void> release_pages_impl(void* address, usize count)
|
||||
{
|
||||
int rc = munmap(address, count * PAGE_SIZE);
|
||||
if (rc < 0) { return err(errno); }
|
||||
return {};
|
||||
}
|
Loading…
Reference in New Issue
Block a user