diff options
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 8fc595034..51cc24d01 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -2295,31 +2295,34 @@ private: } Flow visitMemorySize(MemorySize* curr) { NOTE_ENTER("MemorySize"); - return Literal(int32_t(instance.memorySize)); + return Literal::makeFromUInt64(instance.memorySize, + instance.wasm.memory.indexType); } Flow visitMemoryGrow(MemoryGrow* curr) { NOTE_ENTER("MemoryGrow"); - auto fail = Literal(int32_t(-1)); + auto indexType = instance.wasm.memory.indexType; + auto fail = Literal::makeFromUInt64(-1, indexType); Flow flow = this->visit(curr->delta); if (flow.breaking()) { return flow; } - int32_t ret = instance.memorySize; - uint32_t delta = flow.getSingleValue().geti32(); - if (delta > uint32_t(-1) / Memory::kPageSize) { + Flow ret = Literal::makeFromUInt64(instance.memorySize, indexType); + uint64_t delta = flow.getSingleValue().getInteger(); + if (delta > uint32_t(-1) / Memory::kPageSize && indexType == Type::i32) { return fail; } - if (instance.memorySize >= uint32_t(-1) - delta) { + if (instance.memorySize >= uint32_t(-1) - delta && + indexType == Type::i32) { return fail; } - uint32_t newSize = instance.memorySize + delta; + auto newSize = instance.memorySize + delta; if (newSize > instance.wasm.memory.max) { return fail; } instance.externalInterface->growMemory( instance.memorySize * Memory::kPageSize, newSize * Memory::kPageSize); instance.memorySize = newSize; - return Literal(int32_t(ret)); + return ret; } Flow visitMemoryInit(MemoryInit* curr) { NOTE_ENTER("MemoryInit"); @@ -2342,7 +2345,7 @@ private: assert(curr->segment < instance.wasm.memory.segments.size()); Memory::Segment& segment = instance.wasm.memory.segments[curr->segment]; - Address destVal(uint32_t(dest.getSingleValue().geti32())); + Address destVal(dest.getSingleValue().getInteger()); Address offsetVal(uint32_t(offset.getSingleValue().geti32())); Address sizeVal(uint32_t(size.getSingleValue().geti32())); @@ -2353,12 +2356,11 @@ private: if ((uint64_t)offsetVal + sizeVal > segment.data.size()) { trap("out of bounds segment access in memory.init"); } - if ((uint64_t)destVal + sizeVal > - (uint64_t)instance.memorySize * Memory::kPageSize) { + if (destVal + sizeVal > instance.memorySize * Memory::kPageSize) { trap("out of bounds memory access in memory.init"); } for (size_t i = 0; i < sizeVal; ++i) { - Literal addr(uint32_t(destVal + i)); + Literal addr(destVal + i); instance.externalInterface->store8( instance.getFinalAddressWithoutOffset(addr, 1), segment.data[offsetVal + i]); @@ -2387,14 +2389,15 @@ private: NOTE_EVAL1(dest); NOTE_EVAL1(source); NOTE_EVAL1(size); - Address destVal(uint32_t(dest.getSingleValue().geti32())); - Address sourceVal(uint32_t(source.getSingleValue().geti32())); - Address sizeVal(uint32_t(size.getSingleValue().geti32())); - - if ((uint64_t)sourceVal + sizeVal > - (uint64_t)instance.memorySize * Memory::kPageSize || - (uint64_t)destVal + sizeVal > - (uint64_t)instance.memorySize * Memory::kPageSize) { + Address destVal(dest.getSingleValue().getInteger()); + Address sourceVal(source.getSingleValue().getInteger()); + Address sizeVal(size.getSingleValue().getInteger()); + + if (sourceVal + sizeVal > instance.memorySize * Memory::kPageSize || + destVal + sizeVal > instance.memorySize * Memory::kPageSize || + // FIXME: better/cheaper way to detect wrapping? + sourceVal + sizeVal < sourceVal || sourceVal + sizeVal < sizeVal || + destVal + sizeVal < destVal || destVal + sizeVal < sizeVal) { trap("out of bounds segment access in memory.copy"); } @@ -2409,11 +2412,9 @@ private: } for (int64_t i = start; i != end; i += step) { instance.externalInterface->store8( - instance.getFinalAddressWithoutOffset(Literal(uint32_t(destVal + i)), - 1), + instance.getFinalAddressWithoutOffset(Literal(destVal + i), 1), instance.externalInterface->load8s( - instance.getFinalAddressWithoutOffset( - Literal(uint32_t(sourceVal + i)), 1))); + instance.getFinalAddressWithoutOffset(Literal(sourceVal + i), 1))); } return {}; } @@ -2434,19 +2435,16 @@ private: NOTE_EVAL1(dest); NOTE_EVAL1(value); NOTE_EVAL1(size); - Address destVal(uint32_t(dest.getSingleValue().geti32())); - Address sizeVal(uint32_t(size.getSingleValue().geti32())); + Address destVal(dest.getSingleValue().getInteger()); + Address sizeVal(size.getSingleValue().getInteger()); - if ((uint64_t)destVal + sizeVal > - (uint64_t)instance.memorySize * Memory::kPageSize) { + if (destVal + sizeVal > instance.memorySize * Memory::kPageSize) { trap("out of bounds memory access in memory.fill"); } uint8_t val(value.getSingleValue().geti32()); for (size_t i = 0; i < sizeVal; ++i) { instance.externalInterface->store8( - instance.getFinalAddressWithoutOffset(Literal(uint32_t(destVal + i)), - 1), - val); + instance.getFinalAddressWithoutOffset(Literal(destVal + i), 1), val); } return {}; } |