Skip to content

Commit

Permalink
orbis-kernel: kalloc: reduce shared memory size
Browse files Browse the repository at this point in the history
add detailed log on failure
  • Loading branch information
DHrpcs3 committed Oct 14, 2024
1 parent 66890b5 commit 6259005
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions orbis-kernel/src/KernelContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <bit>
#include <chrono>
#include <csignal>
#include <cstdio>
#include <mutex>
#include <sys/mman.h>
#include <thread>
#include <unistd.h>

static const std::uint64_t g_allocProtWord = 0xDEADBEAFBADCAFE1;
static constexpr auto kHeapBaseAddress = 0x00000600'0000'0000;
static constexpr auto kHeapSize = 0x10'0000'0000;
static constexpr std::uintptr_t kHeapBaseAddress = 0x00000600'0000'0000;
static constexpr auto kHeapSize = 0x1'0000'0000;
static constexpr int kDebugHeap = 0;

namespace orbis {
Expand All @@ -21,11 +22,22 @@ thread_local Thread *g_currentThread;
KernelContext &g_context = *[]() -> KernelContext * {
// Allocate global shared kernel memory
// TODO: randomize for hardening and reduce size
auto ptr = mmap(reinterpret_cast<void *>(kHeapBaseAddress), kHeapSize,
auto ptr = mmap(std::bit_cast<void *>(kHeapBaseAddress), kHeapSize,
PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
if (ptr == MAP_FAILED)
if (ptr == MAP_FAILED) {
perror("mmap failed");
FILE *maps = fopen("/proc/self/maps", "r");
char *line = nullptr;
std::size_t size = 0;
while (getline(&line, &size, maps) > 0) {
std::printf("%s", line);
}

free(line);
fclose(maps);
std::abort();
}

return new (ptr) KernelContext;
}();
Expand Down

0 comments on commit 6259005

Please sign in to comment.