#pragma once
#include <stdint.h>
#include <stddef.h>
// XFESystem-owned ABI between the zero-library kernel and Microsoft's complete
// NativeAOT runtime. All pointers describe native resources, never managed objects.
// Memory protection bits are read=1, write=2, execute=4. Wait follows the Microsoft
// PAL values: signalled=0, timeout=258, failure=UINT32_MAX.
typedef uint32_t (*XfeRuntimeThreadEntry)(void*);
struct XfeRuntimeLimitedContext {
uint64_t ip,rsp,rbp,rax,rbx,rdx,r12,r13,r14,r15;
};
struct XfeRuntimeInterruptFrame {
uint64_t r15,r14,r13,r12,r11,r10,r9,r8,rsi,rdi,rbp,rdx,rcx,rbx,rax;
uint64_t vector,error,rip,cs,rflags,rsp,ss;
};
struct XfeRuntimePal {
uint32_t version;
uint32_t structure_bytes;
void* (*reserve)(uint64_t bytes, uint64_t alignment);
int (*commit)(void* address, uint64_t bytes);
int (*decommit)(void* address, uint64_t bytes);
int (*release)(void* address, uint64_t bytes);
int (*protect)(void* address, uint64_t bytes, uint32_t protection);
uint64_t (*physical_bytes)();
uint64_t (*free_physical_bytes)();
uint64_t (*monotonic_nanoseconds)();
uint64_t (*utc_filetime)();
uint64_t (*current_thread_id)();
int (*current_stack_bounds)(void** low, void** high);
int (*start_thread)(XfeRuntimeThreadEntry entry, void* context, uint64_t stack_bytes);
void (*sleep_milliseconds)(uint32_t milliseconds);
void (*yield)();
void* (*create_event)(int manual_reset, int initially_signalled);
int (*close_event)(void* event);
int (*set_event)(void* event);
int (*reset_event)(void* event);
uint32_t (*wait_event)(void* event, uint32_t milliseconds);
uint32_t (*wait_any)(void** events, uint32_t count, uint32_t milliseconds);
void (*attach_runtime_thread)(void* runtime_thread);
int (*request_gc_hijack)(void* runtime_thread);
void (*write)(const char* text, uint64_t bytes);
void (*fatal)(const char* reason);
};
#ifdef __cplusplus
extern "C" {
#endif
// Installation refuses incomplete contracts. A successful installation only
// validates callbacks; it is not proof of GC/EH/thread execution.
int XfeRuntimeInstallPal(const struct XfeRuntimePal* pal);
int XfeRuntimeInstallKernelPal(void);
int XfeRuntimeStart(void);
int XfeRuntimePalInstalled(void);
const struct XfeRuntimePal* XfeRuntimeGetPal(void);
// Called only for a stopped scheduler thread by the actual GC suspending thread.
// 1=safe transition or real stack hijack, 0=inconvenient context; retry after it
// runs, -1=invalid input. No successful return fabricates GC root safety.
int XfeRuntimeTryHijack(void* runtime_thread, const struct XfeRuntimeLimitedContext* context);
int XfeRuntimeDetachThread(void* runtime_thread);
int XfeRuntimeDispatchHardwareFault(struct XfeRuntimeInterruptFrame* frame,uint64_t fault_address,void* fxsave);
int XfeRuntimeClassifyDivideFault(const struct XfeRuntimeInterruptFrame* frame,uint32_t* exception_code);
#ifdef __cplusplus
}
#endif
#pragma once
#include <stdint.h>
#include <stddef.h>
// XFESystem-owned ABI between the zero-library kernel and Microsoft's complete
// NativeAOT runtime. All pointers describe native resources, never managed objects.
// Memory protection bits are read=1, write=2, execute=4. Wait follows the Microsoft
// PAL values: signalled=0, timeout=258, failure=UINT32_MAX.
typedef uint32_t (*XfeRuntimeThreadEntry)(void*);
struct XfeRuntimeLimitedContext {
uint64_t ip,rsp,rbp,rax,rbx,rdx,r12,r13,r14,r15;
};
struct XfeRuntimeInterruptFrame {
uint64_t r15,r14,r13,r12,r11,r10,r9,r8,rsi,rdi,rbp,rdx,rcx,rbx,rax;
uint64_t vector,error,rip,cs,rflags,rsp,ss;
};
struct XfeRuntimePal {
uint32_t version;
uint32_t structure_bytes;
void* (*reserve)(uint64_t bytes, uint64_t alignment);
int (*commit)(void* address, uint64_t bytes);
int (*decommit)(void* address, uint64_t bytes);
int (*release)(void* address, uint64_t bytes);
int (*protect)(void* address, uint64_t bytes, uint32_t protection);
uint64_t (*physical_bytes)();
uint64_t (*free_physical_bytes)();
uint64_t (*monotonic_nanoseconds)();
uint64_t (*utc_filetime)();
uint64_t (*current_thread_id)();
int (*current_stack_bounds)(void** low, void** high);
int (*start_thread)(XfeRuntimeThreadEntry entry, void* context, uint64_t stack_bytes);
void (*sleep_milliseconds)(uint32_t milliseconds);
void (*yield)();
void* (*create_event)(int manual_reset, int initially_signalled);
int (*close_event)(void* event);
int (*set_event)(void* event);
int (*reset_event)(void* event);
uint32_t (*wait_event)(void* event, uint32_t milliseconds);
uint32_t (*wait_any)(void** events, uint32_t count, uint32_t milliseconds);
void (*attach_runtime_thread)(void* runtime_thread);
int (*request_gc_hijack)(void* runtime_thread);
void (*write)(const char* text, uint64_t bytes);
void (*fatal)(const char* reason);
};
#ifdef __cplusplus
extern "C" {
#endif
// Installation refuses incomplete contracts. A successful installation only
// validates callbacks; it is not proof of GC/EH/thread execution.
int XfeRuntimeInstallPal(const struct XfeRuntimePal* pal);
int XfeRuntimeInstallKernelPal(void);
int XfeRuntimeStart(void);
int XfeRuntimePalInstalled(void);
const struct XfeRuntimePal* XfeRuntimeGetPal(void);
// Called only for a stopped scheduler thread by the actual GC suspending thread.
// 1=safe transition or real stack hijack, 0=inconvenient context; retry after it
// runs, -1=invalid input. No successful return fabricates GC root safety.
int XfeRuntimeTryHijack(void* runtime_thread, const struct XfeRuntimeLimitedContext* context);
int XfeRuntimeDetachThread(void* runtime_thread);
int XfeRuntimeDispatchHardwareFault(struct XfeRuntimeInterruptFrame* frame,uint64_t fault_address,void* fxsave);
int XfeRuntimeClassifyDivideFault(const struct XfeRuntimeInterruptFrame* frame,uint32_t* exception_code);
#ifdef __cplusplus
}
#endif