Skip to content

Commit 2599d3c

Browse files
dtigCommit Bot
authored andcommitted
[wasm] Fix incorrect check for growing shared WebAssembly.memory
Bug: chromium:1010272 Change-Id: Ieff61089255ee088fad45f15a0f1a8f93eeec94b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1869077 Commit-Queue: Deepti Gandluri <[email protected]> Reviewed-by: Andreas Haas <[email protected]> Cr-Commit-Position: refs/heads/master@{#64525}
1 parent db579b2 commit 2599d3c

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/wasm/wasm-objects.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,12 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate,
10301030
new_pages);
10311031
// Broadcasting the update should update this memory object too.
10321032
CHECK_NE(*old_buffer, memory_object->array_buffer());
1033-
CHECK_EQ(new_byte_length, memory_object->array_buffer().byte_length());
1033+
// This is a less than check, as it is not guaranteed that the SAB
1034+
// length here will be equal to the stashed length above as calls to
1035+
// grow the same memory object can come in from different workers.
1036+
// It is also possible that a call to Grow was in progress when
1037+
// handling this call.
1038+
CHECK_LE(new_byte_length, memory_object->array_buffer().byte_length());
10341039
return static_cast<int32_t>(old_pages); // success
10351040
}
10361041
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --wasm-grow-shared-memory --experimental-wasm-threads
6+
7+
const kNumWorkers = 100;
8+
const kNumMessages = 50;
9+
10+
function AllocMemory(initial, maximum = initial) {
11+
return new WebAssembly.Memory({initial : initial, maximum : maximum, shared : true});
12+
}
13+
14+
(function RunTest() {
15+
let worker = [];
16+
for (let w = 0; w < kNumWorkers; w++) {
17+
worker[w] = new Worker(
18+
`onmessage =
19+
function(msg) {
20+
msg.memory.grow(1);
21+
}`, {type : 'string'});
22+
}
23+
24+
for (let i = 0; i < kNumMessages; i++) {
25+
let memory = AllocMemory(1, 128);
26+
for (let w = 0; w < kNumWorkers; w++) {
27+
worker[w].postMessage({memory : memory});
28+
}
29+
}
30+
})();

0 commit comments

Comments
 (0)