Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
BoundarySpan.hpp File Reference

Always-on validation for JS-supplied pointer+length pairs at the WASM boundary. More...

#include "../core/Types.hpp"
#include <cstdint>
#include <cstdio>
Include dependency graph for BoundarySpan.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  esengine
namespace  esengine::detail

Functions

bool esengine::detail::boundaryContains (uintptr_t ptr, u64 bytes, uintptr_t *base, u64 *size)
void esengine::setBoundaryRegion (uintptr_t base, usize size)
 Declare the region a native host lets JS address (its heap arena).
template<typename T>
const T * esengine::boundarySpan (uintptr_t ptr, u64 count, const char *what)
 Validates a JS-supplied pointer to count elements of T and returns it typed.
template<typename T>
T * esengine::boundarySpanMut (uintptr_t ptr, u64 count, const char *what)
 Mutable variant of boundarySpan, for entry points that WRITE into a JS buffer.

Variables

uintptr_t esengine::detail::g_boundaryBase = 0
usize esengine::detail::g_boundarySize = 0

Detailed Description

Always-on validation for JS-supplied pointer+length pairs at the WASM boundary.

A uintptr_t + count from JS is a bare claim about linear memory. Trusting it blindly lets a wrong count (or a 0 from a failed malloc / an undefined that coerced) read garbage or — on write paths — silently corrupt unrelated engine state inside the sandbox. These helpers are the single boundary gate: null-checked, overflow-checked, and range-checked against the actual wasm heap size. They are ALWAYS ON (never compiled out in release); on failure they log and return nullptr so the entry point degrades instead of hitting UB.

Author
ESEngine Team
Date
2026

Definition in file BoundarySpan.hpp.