25#include <emscripten/heap.h>
48 *size =
static_cast<u64>(emscripten_get_heap_size());
58 if (
static_cast<u64>(ptr) <
static_cast<u64>(*base))
return false;
59 const u64 offset =
static_cast<u64>(ptr) -
static_cast<u64>(*base);
60 return offset <= *size && bytes <= *size - offset;
87 std::fprintf(stderr,
"[boundary] %s: null buffer pointer; rejected\n", what);
90 const u64 bytes = count *
static_cast<u64>(
sizeof(T));
91 if (count != 0 && bytes / count !=
sizeof(T)) {
92 std::fprintf(stderr,
"[boundary] %s: byte size overflows (count %llu); rejected\n",
93 what,
static_cast<unsigned long long>(count));
100 "[boundary] %s: span [%llu + %llu bytes] leaves the heap "
101 "(%llu bytes at %llu); rejected\n",
102 what,
static_cast<unsigned long long>(ptr),
103 static_cast<unsigned long long>(bytes),
104 static_cast<unsigned long long>(size),
105 static_cast<unsigned long long>(base));
108 return reinterpret_cast<const T*
>(ptr);
Core type definitions and utilities for ESEngine.
bool boundaryContains(uintptr_t ptr, u64 bytes, uintptr_t *base, u64 *size)
const T * boundarySpan(uintptr_t ptr, u64 count, const char *what)
Validates a JS-supplied pointer to count elements of T and returns it typed.
std::uint64_t u64
Unsigned 64-bit integer.
std::size_t usize
Size type for indexing and sizes.
T * boundarySpanMut(uintptr_t ptr, u64 count, const char *what)
Mutable variant of boundarySpan, for entry points that WRITE into a JS buffer.
void setBoundaryRegion(uintptr_t base, usize size)
Declare the region a native host lets JS address (its heap arena).