From 37614bb3f454e4ebc798ab4936039c77dac0947a Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 4 Oct 2021 16:17:33 -0700 Subject: [PATCH] [Memory64] embind C++ changes for 64-bit --- system/include/emscripten/val.h | 21 +++++++++++++++++++++ system/include/emscripten/wire.h | 3 ++- system/lib/embind/bind.cpp | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index a505121206279..5c381c749ab46 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace emscripten { @@ -189,10 +190,15 @@ namespace emscripten { union { unsigned u; float f; + #if __ILP32__ const void* p; + #endif } w[2]; double d; uint64_t u; + #if __LP64__ + const void* p; + #endif }; static_assert(sizeof(GenericWireType) == 8, "GenericWireType must be 8 bytes"); static_assert(alignof(GenericWireType) == 8, "GenericWireType must be 8-byte-aligned"); @@ -219,14 +225,29 @@ namespace emscripten { template void writeGenericWireType(GenericWireType*& cursor, T* wt) { + #if __ILP32__ cursor->w[0].p = wt; + #else + cursor->p = wt; + // FIXME: This requires the JS reading code to be audited to be compatible with it. + assert(false); + abort(); + #endif ++cursor; } template inline void writeGenericWireType(GenericWireType*& cursor, const memory_view& wt) { cursor->w[0].u = wt.size; + #if __ILP32__ cursor->w[1].p = wt.data; + #else + // FIXME: need to change GenericWireType such that it can store a 64-bit pointer? + // This requires the JS reading code to be audited to be compatible with it. + cursor->w[1].u = 0; + assert(false); + abort(); + #endif ++cursor; } diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index f669cf718d0ee..892118a2c2847 100644 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -400,7 +400,8 @@ namespace emscripten { return (std::is_floating_point::value && (sizeof(T) == 4 || sizeof(T) == 8)) || (std::is_integral::value && - (sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4)); + (sizeof(T) == 1 || sizeof(T) == 2 || + sizeof(T) == 4 || sizeof(T) == 8)); } } diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index df084a0cf5928..931bedc7eb427 100644 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -77,6 +77,9 @@ enum TypedArrayIndex { Uint32Array, Float32Array, Float64Array, + // Only available if WASM_BIGINT + Int64Array, + Uint64Array, }; template constexpr TypedArrayIndex getTypedArrayIndex() { @@ -86,7 +89,8 @@ template constexpr TypedArrayIndex getTypedArrayIndex() { : (sizeof(T) == 1 ? (std::is_signed::value ? Int8Array : Uint8Array) : (sizeof(T) == 2 ? (std::is_signed::value ? Int16Array : Uint16Array) - : (std::is_signed::value ? Int32Array : Uint32Array))); + : (sizeof(T) == 4 ? (std::is_signed::value ? Int32Array : Uint32Array) + : (std::is_signed::value ? Int64Array : Uint64Array)))); } template static void register_memory_view(const char* name) {