Skip to content

Commit 0d8929f

Browse files
authored
[Memory64] embind C++ changes for 64-bit (#15226)
1 parent 8be5c1d commit 0d8929f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

system/include/emscripten/val.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <emscripten/wire.h>
1616
#include <array>
1717
#include <vector>
18+
#include <climits>
1819

1920

2021
namespace emscripten {
@@ -189,10 +190,15 @@ namespace emscripten {
189190
union {
190191
unsigned u;
191192
float f;
193+
#if __ILP32__
192194
const void* p;
195+
#endif
193196
} w[2];
194197
double d;
195198
uint64_t u;
199+
#if __LP64__
200+
const void* p;
201+
#endif
196202
};
197203
static_assert(sizeof(GenericWireType) == 8, "GenericWireType must be 8 bytes");
198204
static_assert(alignof(GenericWireType) == 8, "GenericWireType must be 8-byte-aligned");
@@ -219,14 +225,29 @@ namespace emscripten {
219225

220226
template<typename T>
221227
void writeGenericWireType(GenericWireType*& cursor, T* wt) {
228+
#if __ILP32__
222229
cursor->w[0].p = wt;
230+
#else
231+
cursor->p = wt;
232+
// FIXME: This requires the JS reading code to be audited to be compatible with it.
233+
assert(false);
234+
abort();
235+
#endif
223236
++cursor;
224237
}
225238

226239
template<typename ElementType>
227240
inline void writeGenericWireType(GenericWireType*& cursor, const memory_view<ElementType>& wt) {
228241
cursor->w[0].u = wt.size;
242+
#if __ILP32__
229243
cursor->w[1].p = wt.data;
244+
#else
245+
// FIXME: need to change GenericWireType such that it can store a 64-bit pointer?
246+
// This requires the JS reading code to be audited to be compatible with it.
247+
cursor->w[1].u = 0;
248+
assert(false);
249+
abort();
250+
#endif
230251
++cursor;
231252
}
232253

system/include/emscripten/wire.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ namespace emscripten {
400400
return (std::is_floating_point<T>::value &&
401401
(sizeof(T) == 4 || sizeof(T) == 8)) ||
402402
(std::is_integral<T>::value &&
403-
(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4));
403+
(sizeof(T) == 1 || sizeof(T) == 2 ||
404+
sizeof(T) == 4 || sizeof(T) == 8));
404405
}
405406
}
406407

system/lib/embind/bind.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ enum TypedArrayIndex {
7777
Uint32Array,
7878
Float32Array,
7979
Float64Array,
80+
// Only available if WASM_BIGINT
81+
Int64Array,
82+
Uint64Array,
8083
};
8184

8285
template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
@@ -86,7 +89,8 @@ template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
8689
: (sizeof(T) == 1
8790
? (std::is_signed<T>::value ? Int8Array : Uint8Array)
8891
: (sizeof(T) == 2 ? (std::is_signed<T>::value ? Int16Array : Uint16Array)
89-
: (std::is_signed<T>::value ? Int32Array : Uint32Array)));
92+
: (sizeof(T) == 4 ? (std::is_signed<T>::value ? Int32Array : Uint32Array)
93+
: (std::is_signed<T>::value ? Int64Array : Uint64Array))));
9094
}
9195

9296
template <typename T> static void register_memory_view(const char* name) {

0 commit comments

Comments
 (0)