8#ifndef PEDIGREE_KERNEL_PROCESSOR_HOSTED_PLATFORM_H
9#define PEDIGREE_KERNEL_PROCESSOR_HOSTED_PLATFORM_H
16namespace HostedPlatform {
17inline size_t pageSize() {
18 const long result = sysconf(_SC_PAGESIZE);
19 return result > 0 ?
static_cast<size_t>(result) : 0;
22template <
class Context>
23inline uintptr_t instructionPointer(
const Context* context) {
24#if defined(__APPLE__) && defined(__aarch64__)
25 return context->uc_mcontext->__ss.__pc;
26#elif defined(__APPLE__) && defined(__x86_64__)
27 return context->uc_mcontext->__ss.__rip;
28#elif defined(__linux__) && defined(__x86_64__)
29 return context->uc_mcontext.gregs[REG_RIP];
31#error Unsupported hosted ucontext platform
35template <
class Context>
36inline uintptr_t stackPointer(
const Context* context) {
37#if defined(__APPLE__) && defined(__aarch64__)
38 return context->uc_mcontext->__ss.__sp;
39#elif defined(__APPLE__) && defined(__x86_64__)
40 return context->uc_mcontext->__ss.__rsp;
41#elif defined(__linux__) && defined(__x86_64__)
42 return context->uc_mcontext.gregs[REG_RSP];
44#error Unsupported hosted ucontext platform
48template <
class Context>
49inline uintptr_t basePointer(
const Context* context) {
50#if defined(__APPLE__) && defined(__aarch64__)
51 return context->uc_mcontext->__ss.__fp;
52#elif defined(__APPLE__) && defined(__x86_64__)
53 return context->uc_mcontext->__ss.__rbp;
54#elif defined(__linux__) && defined(__x86_64__)
55 return context->uc_mcontext.gregs[REG_RBP];
57#error Unsupported hosted ucontext platform