Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2373613004: [wasm] Fix bounds check of a store instruction after a grow_memory instruction (Closed)
Patch Set: Ben's review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | test/common/wasm/wasm-module-runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "src/wasm/encoder.h" 8 #include "src/wasm/encoder.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 16 matching lines...) Expand all
27 builder->WriteTo(buffer); 27 builder->WriteTo(buffer);
28 28
29 Isolate* isolate = CcTest::InitIsolateOnce(); 29 Isolate* isolate = CcTest::InitIsolateOnce();
30 HandleScope scope(isolate); 30 HandleScope scope(isolate);
31 testing::SetupIsolateForWasmModule(isolate); 31 testing::SetupIsolateForWasmModule(isolate);
32 int32_t result = testing::CompileAndRunWasmModule( 32 int32_t result = testing::CompileAndRunWasmModule(
33 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin); 33 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin);
34 CHECK_EQ(expected_result, result); 34 CHECK_EQ(expected_result, result);
35 } 35 }
36 36
37 void TestModuleException(Zone* zone, WasmModuleBuilder* builder) {
38 ZoneBuffer buffer(zone);
39 builder->WriteTo(buffer);
40
41 Isolate* isolate = CcTest::InitIsolateOnce();
42 HandleScope scope(isolate);
43 testing::SetupIsolateForWasmModule(isolate);
44 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
45 testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end(),
46 ModuleOrigin::kWasmOrigin);
47 CHECK(try_catch.HasCaught());
48 isolate->clear_pending_exception();
49 }
50
37 void ExportAs(WasmFunctionBuilder* f, const char* name) { 51 void ExportAs(WasmFunctionBuilder* f, const char* name) {
38 f->SetExported(); 52 f->SetExported();
39 f->SetName(name, static_cast<int>(strlen(name))); 53 f->SetName(name, static_cast<int>(strlen(name)));
40 } 54 }
41 55
42 void ExportAsMain(WasmFunctionBuilder* f) { 56 void ExportAsMain(WasmFunctionBuilder* f) {
43 static const char kMainName[] = "main"; 57 static const char kMainName[] = "main";
44 ExportAs(f, kMainName); 58 ExportAs(f, kMainName);
45 } 59 }
46 60
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 v8::internal::AccountingAllocator allocator; 274 v8::internal::AccountingAllocator allocator;
261 Zone zone(&allocator); 275 Zone zone(&allocator);
262 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 276 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
263 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 277 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
264 ExportAsMain(f); 278 ExportAsMain(f);
265 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), 279 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
266 WASM_I32V(12))}; 280 WASM_I32V(12))};
267 f->EmitCode(code, sizeof(code)); 281 f->EmitCode(code, sizeof(code));
268 TestModule(&zone, builder, 12); 282 TestModule(&zone, builder, 12);
269 } 283 }
284
285 TEST(Run_WasmModule_GrowMemOobOffset) {
286 static const int kPageSize = 0x10000;
287 // Initial memory size = 16 + GrowMemory(10)
288 static const int index = kPageSize * 17 + 4;
289 int value = 0xaced;
290 TestSignatures sigs;
291 v8::internal::AccountingAllocator allocator;
292 Zone zone(&allocator);
293
294 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
295 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
296 ExportAsMain(f);
297 byte code[] = {
298 WASM_GROW_MEMORY(WASM_I8(1)),
299 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value))};
300 f->EmitCode(code, sizeof(code));
301 TestModuleException(&zone, builder);
302 }
303
304 TEST(Run_WasmModule_GrowMemOobFixedIndex) {
305 static const int kPageSize = 0x10000;
306 // Initial memory size = 16 + GrowMemory(10)
307 static const int index = kPageSize * 26 + 4;
308 int value = 0xaced;
309 TestSignatures sigs;
310 Isolate* isolate = CcTest::InitIsolateOnce();
311 Zone zone(isolate->allocator());
312
313 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
314 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
315 ExportAsMain(f);
316 byte code[] = {
317 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
318 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value)),
319 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))};
320 f->EmitCode(code, sizeof(code));
321
322 HandleScope scope(isolate);
323 ZoneBuffer buffer(&zone);
324 builder->WriteTo(buffer);
325 testing::SetupIsolateForWasmModule(isolate);
326
327 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting(
328 isolate, &zone, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin);
329 CHECK(!instance.is_null());
330
331 // Initial memory size is 16 pages, should trap till index > MemSize on
332 // consecutive GrowMem calls
333 for (uint32_t i = 1; i < 5; i++) {
334 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(i), isolate)};
335 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
336 testing::RunWasmModuleForTesting(isolate, instance, 1, params,
337 ModuleOrigin::kWasmOrigin);
338 CHECK(try_catch.HasCaught());
339 isolate->clear_pending_exception();
340 }
341
342 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(1), isolate)};
343 int32_t result = testing::RunWasmModuleForTesting(
344 isolate, instance, 1, params, ModuleOrigin::kWasmOrigin);
345 CHECK(result == 0xaced);
346 }
347
348 TEST(Run_WasmModule_GrowMemOobVariableIndex) {
349 static const int kPageSize = 0x10000;
350 int value = 0xaced;
351 TestSignatures sigs;
352 Isolate* isolate = CcTest::InitIsolateOnce();
353 v8::internal::AccountingAllocator allocator;
354 Zone zone(&allocator);
355
356 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
357 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
358 ExportAsMain(f);
359 byte code[] = {
360 WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP,
361 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), WASM_I32V(value)),
362 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))};
363 f->EmitCode(code, sizeof(code));
364
365 HandleScope scope(isolate);
366 ZoneBuffer buffer(&zone);
367 builder->WriteTo(buffer);
368 testing::SetupIsolateForWasmModule(isolate);
369
370 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting(
371 isolate, &zone, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin);
372
373 CHECK(!instance.is_null());
374
375 // Initial memory size is 16 pages, should trap till index > MemSize on
376 // consecutive GrowMem calls
377 for (int i = 1; i < 5; i++) {
378 Handle<Object> params[1] = {
379 Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)};
380 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
381 testing::RunWasmModuleForTesting(isolate, instance, 1, params,
382 ModuleOrigin::kWasmOrigin);
383 CHECK(try_catch.HasCaught());
384 isolate->clear_pending_exception();
385 }
386
387 for (int i = 1; i < 5; i++) {
388 Handle<Object> params[1] = {
389 Handle<Object>(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
390 int32_t result = testing::RunWasmModuleForTesting(
391 isolate, instance, 1, params, ModuleOrigin::kWasmOrigin);
392 CHECK(result == 0xaced);
393 }
394
395 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
396 Handle<Object> params[1] = {
397 Handle<Object>(Smi::FromInt(25 * kPageSize), isolate)};
398 testing::RunWasmModuleForTesting(isolate, instance, 1, params,
399 ModuleOrigin::kWasmOrigin);
400 CHECK(try_catch.HasCaught());
401 isolate->clear_pending_exception();
402 }
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | test/common/wasm/wasm-module-runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698