Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, sep = '
return '(' + makeSetTempDouble(0, 'double', value) + ',' +
makeSetValue(ptr, pos, makeGetTempDouble(0, 'i32'), 'i32', noNeedFirst, ignore, align, ',') + ',' +
makeSetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), makeGetTempDouble(1, 'i32'), 'i32', noNeedFirst, ignore, align, ',') + ')';
} else if (!WASM_BIGINT && type == 'i64') {
} else if (type == 'i64' && (!WASM_BIGINT || !MEMORY64)) {
// If we lack either BigInt support or Memory64 then we must fall back to an
// unaligned read of a 64-bit value: without BigInt we do not have HEAP64,
// and without Memory64 i64 fields are not guaranteed to be aligned to 64
// bits, so HEAP64[ptr>>3] might be broken.
return '(tempI64 = [' + splitI64(value) + '],' +
makeSetValue(ptr, pos, 'tempI64[0]', 'i32', noNeedFirst, ignore, align, ',') + ',' +
makeSetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), 'tempI64[1]', 'i32', noNeedFirst, ignore, align, ',') + ')';
Expand Down
15 changes: 14 additions & 1 deletion test/other/test_parseTools.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
void test_makeGetValue(int32_t* ptr);
int test_receiveI64ParamAsI53(int64_t arg1, int64_t arg2);
int test_receiveI64ParamAsDouble(int64_t arg1, int64_t arg2);
void test_makeSetValue_i64(int64_t* ptr);

#define MAX_SAFE_INTEGER (1ll << 53)
#define MIN_SAFE_INTEGER (-MAX_SAFE_INTEGER)
Expand Down Expand Up @@ -41,6 +42,18 @@ int main() {
rtn = test_receiveI64ParamAsDouble(MIN_SAFE_INTEGER - 1, 0);
printf("rtn = %d\n", rtn);

printf("done\n");
printf("\ntest_makeSetValue_i64\n");
// Test an unaligned read of an i64 in JS. To do that, get an unaligned
// pointer. i64s are only 32-bit aligned, but we can't rely on the address to
// happen to be unaligned here, so actually force an unaligned address (one
// of the iterations will be unaligned).
char buffer[16];
for (size_t i = 0; i < 8; i += 4) {
int64_t* unaligned_i64 = (int64_t*)(buffer + i);
test_makeSetValue_i64(unaligned_i64);
printf("i64 = 0x%llx\n", *unaligned_i64);
}

printf("\ndone\n");
return 0;
}
6 changes: 5 additions & 1 deletion test/other/test_parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ mergeInto(LibraryManager.library, {
val = {{{ makeGetValue('ptr', '0', 'i32*') }}};
out('ptr: ' + val.toString(16))
assert(val == 0xedcba988);
}
},

test_makeSetValue_i64: function(ptr) {
{{{ makeSetValue('ptr', '0', 0x12345678AB, 'i64') }}};
},
});
5 changes: 5 additions & 0 deletions test/other/test_parseTools.out
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ test_receiveI64ParamAsDouble:
arg1: -9007199254740992
arg2: 0
rtn = 0

test_makeSetValue_i64
i64 = 0x12345678ab
i64 = 0x12345678ab

done
3 changes: 3 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5290,6 +5290,9 @@ def test(args):
'main_thread': (['-sPTHREAD_POOL_SIZE=5'],),
# using proxy_to_pthread also works, of course
'proxy_to_pthread': (['-sPROXY_TO_PTHREAD', '-sINITIAL_MEMORY=32MB', '-DPROXYING'],),
# using BigInt support affects the ABI, and should not break things. (this
# could be tested on either thread; do the main thread for simplicity)
'bigint': (['-sPTHREAD_POOL_SIZE=5', '-sWASM_BIGINT'],),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify test/other/test_parseTools.js to test this fix more directly/precisely?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test there now.

})
@requires_threads
def test_wasmfs_fetch_backend(self, args):
Expand Down