37 lines
952 B
C++
37 lines
952 B
C++
|
/* 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 {};
|
||
|
}
|