Build and run the runtime natively on Linux.

Shared runtime code now goes through runtime/platform/platform.h, implemented by platform/win32.c and a new
platform/linux.c: futex locks, a userfaultfd and PAGEMAP_SCAN write watch, signal-based async preemption, our own
fiber switch, and a SIGSEGV handler for the thaw and crash hooks. The window, input, menu and software keyboard get
SDL3 back ends beside the Win32 ones, with the swapchain (gfx_present.c) and input merging (input.c) shared. SHA-256
replaces BCrypt, ELF builds get their own override sections, and the build tools gain Linux branches.

On Linux the selftest and the gfx-abi, astc, nvn and window probes pass. probe-vkmem still fails: imported guest
memory cannot be write-watched on Linux, which the shadow buffers in vk_memory.c will address.
This commit is contained in:
Wellington Dias committed 2026-10-29 16:56:56 -03:00
1 parent c3b9a4e7f6
commit 1d51343ac1
102 files changed
+7721 -4424

No files matched your search

+3 -17
View File
@@ -12,17 +12,13 @@
// is also fixed at init; they are looked up only after the flat table misses.
#include "dispatch.h"
#include "host.h"
#include "platform/platform.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h>
#endif
#define TABLE_SPAN_LIMIT (1ull << 30) // guest bytes covered by the table, and its size in bytes
#define HOST_CAP 8192 // host function registry, power of two
@@ -92,21 +88,11 @@ void rt_register_host(uint64_t addr, GuestFn fn) {
}
static void *table_alloc(uint64_t bytes) {
#ifdef _WIN32
return VirtualAlloc(NULL, bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); // zero pages, backed on first write
#else
void *p = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
return p == MAP_FAILED ? NULL : p;
#endif
return plat_mem_alloc(bytes); // zero pages, backed on first write
}
static void table_seal(void *p, uint64_t bytes) {
#ifdef _WIN32
DWORD old;
if (!VirtualProtect(p, bytes, PAGE_READONLY, &old)) rt_fatal("dispatch: VirtualProtect failed (%lu)", GetLastError());
#else
if (mprotect(p, bytes, PROT_READ)) rt_fatal("dispatch: mprotect failed");
#endif
if (!plat_mem_protect((uint64_t)(uintptr_t)p, bytes, PLAT_PROT_READ)) rt_fatal("dispatch: sealing the table failed");
}
void rt_dispatch_init(const RtModule *mods, int count) {