From 5ca407665085a7fbdf07917934032820657c5a81 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 11:13:24 +0100 Subject: [PATCH 01/40] WIP: decode some `Memory*` --- src/Wasm/Binary/Decode.hs | 4 ++++ src/Wasm/Syntax/AST.hs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/Wasm/Binary/Decode.hs b/src/Wasm/Binary/Decode.hs index 8fc8645..8162204 100644 --- a/src/Wasm/Binary/Decode.hs +++ b/src/Wasm/Binary/Decode.hs @@ -258,6 +258,10 @@ getMathPrefix = do 0x05 -> return $ Convert $ I64ConvertOp Int.TruncUSatF32 0x06 -> return $ Convert $ I64ConvertOp Int.TruncSSatF64 0x07 -> return $ Convert $ I64ConvertOp Int.TruncUSatF64 + 0x0B -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 + return $ MemoryFill + 0x0A -> do 0 <- getWord8 + return $ MemoryCopy _ -> fail (printf "getMathPrefix: illegal op %d" byte) diff --git a/src/Wasm/Syntax/AST.hs b/src/Wasm/Syntax/AST.hs index 19a9bad..e80055e 100644 --- a/src/Wasm/Syntax/AST.hs +++ b/src/Wasm/Syntax/AST.hs @@ -94,6 +94,8 @@ data InstrF (phrase :: * -> *) fix | Store StoreOp | MemorySize | MemoryGrow + | MemoryFill + | MemoryCopy | Const (Literal phrase) | Test TestOp | Compare CompareOp From 59e7ffc155a272c248cb06739bd29a0fdffeda3a Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 11:39:01 +0100 Subject: [PATCH 02/40] administrative impl also corrected textual syntax for `Memory{Size,Grow}` to be conforming with https://webassembly.github.io/spec/core/text/instructions.html#memory-instructions --- src/Wasm/Syntax/AST.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Wasm/Syntax/AST.hs b/src/Wasm/Syntax/AST.hs index e80055e..9ca5bf9 100644 --- a/src/Wasm/Syntax/AST.hs +++ b/src/Wasm/Syntax/AST.hs @@ -137,6 +137,8 @@ instance (NFData1 phrase) => NFData1 (InstrF phrase) where Store op -> rnf op MemorySize -> () MemoryGrow -> () + MemoryFill -> () + MemoryCopy -> () Const lit -> rnfLift lit Test op -> rnf op Compare op -> rnf op @@ -221,6 +223,10 @@ instance (Show1 phrase) => Show1 (InstrF phrase) where showString "MemorySize" MemoryGrow -> showString "MemoryGrow" + MemoryFill -> + showString "MemoryFill" + MemoryCopy -> + showString "MemoryCopy" Const lit -> showString "Const " . showLiftPrec 11 lit @@ -322,12 +328,14 @@ showWasm d ((value -> Fix instr):instrs) = go instr . showString "\n" . showWasm Store (MemoryOp I64Type x y (Just Pack8)) -> showString "i64.store8 " . showsPrec d x . showString " " . showsPrec d y Store (MemoryOp I64Type x y (Just Pack16)) -> showString "i64.store16 " . showsPrec d x . showString " " . showsPrec d y Store (MemoryOp I64Type x y (Just Pack32)) -> showString "i64.store32 " . showsPrec d x . showString " " . showsPrec d y - MemorySize -> showString "memory_size" - MemoryGrow -> showString "memory_grow" - Const (value -> I32 x) -> showString "i32.const " . showsPrec d x - Const (value -> I64 x) -> showString "i64.const " . showsPrec d x - Const (value -> F32 x) -> showString "f32.const " . showsPrec d x - Const (value -> F64 x) -> showString "f64.const " . showsPrec d x + MemorySize -> showString "memory.size" + MemoryGrow -> showString "memory.grow" + MemoryFill -> showString "memory.fill" + MemoryCopy -> showString "memory.copy" + Const (value -> I32 x) -> showString "i32.const " . showsPrec d x + Const (value -> I64 x) -> showString "i64.const " . showsPrec d x + Const (value -> F32 x) -> showString "f32.const " . showsPrec d x + Const (value -> F64 x) -> showString "f64.const " . showsPrec d x Unary (I32UnaryOp Clz) -> showString "i32.clz" Unary (I32UnaryOp Ctz) -> showString "i32.ctz" Unary (I32UnaryOp Popcnt) -> showString "i32.popcnt" From 474460cf434a5a47c33ec14003703fc4a23814aa Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 11:56:45 +0100 Subject: [PATCH 03/40] encoding and DSL --- src/Wasm/Binary/Decode.hs | 4 ++-- src/Wasm/Binary/Encode.hs | 9 +++++++++ src/Wasm/Syntax/DSL.hs | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Wasm/Binary/Decode.hs b/src/Wasm/Binary/Decode.hs index 8162204..c16267f 100644 --- a/src/Wasm/Binary/Decode.hs +++ b/src/Wasm/Binary/Decode.hs @@ -258,10 +258,10 @@ getMathPrefix = do 0x05 -> return $ Convert $ I64ConvertOp Int.TruncUSatF32 0x06 -> return $ Convert $ I64ConvertOp Int.TruncSSatF64 0x07 -> return $ Convert $ I64ConvertOp Int.TruncUSatF64 - 0x0B -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 - return $ MemoryFill 0x0A -> do 0 <- getWord8 return $ MemoryCopy + 0x0B -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 + return $ MemoryFill _ -> fail (printf "getMathPrefix: illegal op %d" byte) diff --git a/src/Wasm/Binary/Encode.hs b/src/Wasm/Binary/Encode.hs index b0d348f..1fa26ea 100644 --- a/src/Wasm/Binary/Encode.hs +++ b/src/Wasm/Binary/Encode.hs @@ -384,6 +384,15 @@ putInstr = flip (.) unFix $ \case MemoryGrow -> do putWord8 0x40 putWord8 0x00 + MemoryFill -> do + putWord8 0xFC + putWord8 0x0B + putWord8 0x00 + MemoryCopy -> do + putWord8 0xFC + putWord8 0x0A + putWord8 0x00 + putWord8 0x00 -- Constants. Const (value -> I32 val) -> do diff --git a/src/Wasm/Syntax/DSL.hs b/src/Wasm/Syntax/DSL.hs index cd2b90e..6819122 100644 --- a/src/Wasm/Syntax/DSL.hs +++ b/src/Wasm/Syntax/DSL.hs @@ -78,6 +78,8 @@ class Monad (WasmM t) => Wasm t where -- Memory operators. memory_size :: WasmM t () memory_grow :: WasmM t () + memory_fill :: WasmM t () + memory_copy :: WasmM t () -- Constants. i32_const :: Int32 -> WasmM t () @@ -306,6 +308,8 @@ instance Applicative f => Wasm [Instr f] where -- Memory operators. memory_size = WasmM $ tell [Fix $ MemorySize] memory_grow = WasmM $ tell [Fix $ MemoryGrow] + memory_fill = WasmM $ tell [Fix $ MemoryFill] + memory_copy = WasmM $ tell [Fix $ MemoryCopy] -- Constants. i32_const x = WasmM $ tell [Fix $ Const (pure (I32 x))] From 306b0c67151fc3db5ae2e0cf2989cdc3bf3a3404 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 13:06:46 +0100 Subject: [PATCH 04/40] first shot at `MemoryFill` semantics does not follow https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-fill yet --- src/Wasm/Exec/Eval.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index d409b7d..00179ec 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -479,6 +479,15 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do Right () -> oldSize k (I32 result : vs') es + (MemoryFill, I32 cnt : v : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do + inst <- getFrameInst + mem <- lift $ memory inst (0 @@ at) + let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) + eres <- lift $ lift $ runExceptT $ mapM_ (\off -> Memory.storePacked Pack8 mem addr off v) [0 .. pred cnt] + case eres of + Right () -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (Const v, vs) -> {-# SCC step_Const #-} k (value v : vs) es From 5c7c12f9edd9932193809588d219436ad9d55240 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 13:38:23 +0100 Subject: [PATCH 05/40] implement semantics for MemoryCopy not adhering to https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-copy yet --- src/Wasm/Exec/Eval.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 00179ec..34fcbed 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -488,6 +488,17 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do Right () -> k vs' es Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do + inst <- getFrameInst + mem <- lift $ memory inst (0 @@ at) + let addr_dst = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) + let addr_src = fromIntegral $ i64_extend_u_i32 (fromIntegral src) + eres <- lift $ lift $ runExceptT $ + mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) [0 .. pred cnt] + case eres of + Right () -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (Const v, vs) -> {-# SCC step_Const #-} k (value v : vs) es From ca0574c2f6cda865837444ca6c5b92d52fe979e6 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 13:57:59 +0100 Subject: [PATCH 06/40] touchups --- src/Wasm/Exec/Eval.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 34fcbed..95a8e05 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -488,11 +488,10 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do Right () -> k vs' es Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) - (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do + (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - let addr_dst = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) - let addr_src = fromIntegral $ i64_extend_u_i32 (fromIntegral src) + let [addr_dst, addr_src] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] eres <- lift $ lift $ runExceptT $ mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) [0 .. pred cnt] case eres of From 993f4c39c491c0f16f940c9429f8eaf4cfef6b73 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 14:37:38 +0100 Subject: [PATCH 07/40] implement memory presence test for `MemoryFill` --- src/Wasm/Exec/Eval.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 95a8e05..ee3c491 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -479,6 +479,15 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do Right () -> oldSize k (I32 result : vs') es + (MemoryFill, I32 0 : _ : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do + inst <- getFrameInst + mem <- lift $ memory inst (0 @@ at) + let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) + eres <- lift $ lift $ runExceptT $ Memory.loadPacked Pack8 ZX mem addr 0 I32Type + case eres of + Right _ -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (MemoryFill, I32 cnt : v : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) From b814f134885fb8b239f4675b88c0e5587d39c880 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 14:53:30 +0100 Subject: [PATCH 08/40] check addresses for 0-size `MemoryCopy` --- src/Wasm/Exec/Eval.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index ee3c491..f21e67a 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -497,6 +497,16 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do Right () -> k vs' es Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (MemoryCopy, I32 0 : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do + inst <- getFrameInst + mem <- lift $ memory inst (0 @@ at) + let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] + eres <- lift $ lift $ runExceptT $ + mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) addrs + case eres of + Right () -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) From 53203cbfbe544aa3e41d4783722b09995b3d1c1e Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 17 Dec 2021 15:08:59 +0100 Subject: [PATCH 09/40] implement directionality for `MemoryCopy` --- src/Wasm/Exec/Eval.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index f21e67a..8feed7e 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -511,8 +511,9 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) let [addr_dst, addr_src] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] + let range = if dst < src then [0 .. pred cnt] else tail $ enumFromThenTo cnt (pred cnt) 0 eres <- lift $ lift $ runExceptT $ - mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) [0 .. pred cnt] + mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) range case eres of Right () -> k vs' es Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) From 66c75105580485658aeca1fe8e9ad2ec6a5f43fe Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 02:02:22 +0100 Subject: [PATCH 10/40] add tests for `memory.fill` and `memory.copy` this is shamelessly frobbed from https://github.com/WebAssembly/testsuite/blob/main/bulk.wast (the official test suite) but shortened to only those two instructions --- test/wast/memory-fill-copy.wast | 111 ++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/wast/memory-fill-copy.wast diff --git a/test/wast/memory-fill-copy.wast b/test/wast/memory-fill-copy.wast new file mode 100644 index 0000000..ddc8338 --- /dev/null +++ b/test/wast/memory-fill-copy.wast @@ -0,0 +1,111 @@ +;; segment syntax +(module + (memory 1) + (data "foo")) + +(module + (table 3 funcref) + (elem funcref (ref.func 0) (ref.null func) (ref.func 1)) + (func) + (func)) + +;; memory.fill +(module + (memory 1) + + (func (export "fill") (param i32 i32 i32) + (memory.fill + (local.get 0) + (local.get 1) + (local.get 2))) + + (func (export "load8_u") (param i32) (result i32) + (i32.load8_u (local.get 0))) +) + +;; Basic fill test. +(invoke "fill" (i32.const 1) (i32.const 0xff) (i32.const 3)) +(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0)) +(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xff)) +(assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0xff)) +(assert_return (invoke "load8_u" (i32.const 3)) (i32.const 0xff)) +(assert_return (invoke "load8_u" (i32.const 4)) (i32.const 0)) + +;; Fill value is stored as a byte. +(invoke "fill" (i32.const 0) (i32.const 0xbbaa) (i32.const 2)) +(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xaa)) +(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xaa)) + +;; Fill all of memory +(invoke "fill" (i32.const 0) (i32.const 0) (i32.const 0x10000)) + +;; Out-of-bounds writes trap, and nothing is written +(assert_trap (invoke "fill" (i32.const 0xff00) (i32.const 1) (i32.const 0x101)) + "out of bounds memory access") +(assert_return (invoke "load8_u" (i32.const 0xff00)) (i32.const 0)) +(assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0)) + +;; Succeed when writing 0 bytes at the end of the region. +(invoke "fill" (i32.const 0x10000) (i32.const 0) (i32.const 0)) + +;; Writing 0 bytes outside the memory traps. +(assert_trap (invoke "fill" (i32.const 0x10001) (i32.const 0) (i32.const 0)) + "out of bounds memory access") + + +;; memory.copy +(module + (memory (data "\aa\bb\cc\dd")) + + (func (export "copy") (param i32 i32 i32) + (memory.copy + (local.get 0) + (local.get 1) + (local.get 2))) + + (func (export "load8_u") (param i32) (result i32) + (i32.load8_u (local.get 0))) +) + +;; Non-overlapping copy. +(invoke "copy" (i32.const 10) (i32.const 0) (i32.const 4)) + +(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0)) +(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xaa)) +(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xbb)) +(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc)) +(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd)) +(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0)) + +;; Overlap, source > dest +(invoke "copy" (i32.const 8) (i32.const 10) (i32.const 4)) +(assert_return (invoke "load8_u" (i32.const 8)) (i32.const 0xaa)) +(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0xbb)) +(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xcc)) +(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xdd)) +(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc)) +(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd)) + +;; Overlap, source < dest +(invoke "copy" (i32.const 10) (i32.const 7) (i32.const 6)) +(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0)) +(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xaa)) +(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xbb)) +(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xcc)) +(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0xdd)) +(assert_return (invoke "load8_u" (i32.const 15)) (i32.const 0xcc)) +(assert_return (invoke "load8_u" (i32.const 16)) (i32.const 0)) + +;; Copy ending at memory limit is ok. +(invoke "copy" (i32.const 0xff00) (i32.const 0) (i32.const 0x100)) +(invoke "copy" (i32.const 0xfe00) (i32.const 0xff00) (i32.const 0x100)) + +;; Succeed when copying 0 bytes at the end of the region. +(invoke "copy" (i32.const 0x10000) (i32.const 0) (i32.const 0)) +(invoke "copy" (i32.const 0) (i32.const 0x10000) (i32.const 0)) + +;; Copying 0 bytes outside the memory traps. +(assert_trap (invoke "copy" (i32.const 0x10001) (i32.const 0) (i32.const 0)) + "out of bounds memory access") +(assert_trap (invoke "copy" (i32.const 0) (i32.const 0x10001) (i32.const 0)) + "out of bounds memory access") From 8af63477b893636444c1b741e769f76d34c6f2e2 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 14:52:19 +0100 Subject: [PATCH 11/40] pull in more tests (also bulk memory ones) --- default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 889ff70..644127b 100644 --- a/default.nix +++ b/default.nix @@ -21,8 +21,8 @@ let spec-tests = pkgs.fetchFromGitHub { owner = "WebAssembly"; repo = "testsuite"; - rev = "35c50bf6fbb002cfdc1227b0af731bdcaf877714"; - sha256 = "0difcpya5i7fc4xdrysx49186x9vh5yhm88dqpmfppj7ddj39l9i"; + rev = "6aacfd8929504d8e02a5144a14d184196ede6790"; + sha256 = "sha256-HrnTpIEVN3H9P4fuSBUkaMpNdMxa2pbfp1iPElJLlUM"; }; drv = pkgs.haskellPackages.developPackage { From 3d25da06b6c30951a80ee5b6c28d0b54082a7a24 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:16:11 +0100 Subject: [PATCH 12/40] typo --- test/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Main.hs b/test/Main.hs index 2aa1a6e..c561f93 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -13,7 +13,7 @@ main :: IO () main = do mwasmPath <- lookupEnv "WASM_SPEC_TESTS" testDir <- case mwasmPath of - Nothing -> error "Please define WASM_SPEC_TESTS to point to .../WebAssebly/spec/test/core" + Nothing -> error "Please define WASM_SPEC_TESTS to point to .../WebAssembly/spec/test/core" Just path -> return path putStrLn $ "Using wasm spec test directory: " ++ testDir files <- listDirectory testDir From c1fbd7405dfe00df40a4025df2d5edbfa06a9a4d Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:23:55 +0100 Subject: [PATCH 13/40] moderenise --- test/Main.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index c561f93..9fbcc83 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -14,16 +14,18 @@ main = do mwasmPath <- lookupEnv "WASM_SPEC_TESTS" testDir <- case mwasmPath of Nothing -> error "Please define WASM_SPEC_TESTS to point to .../WebAssembly/spec/test/core" - Just path -> return path + Just path -> pure path putStrLn $ "Using wasm spec test directory: " ++ testDir files <- listDirectory testDir let wastFiles = flip concatMap files $ \file -> [ testDir ++ "/" ++ file | ".wast" `isSuffixOf` file - && "inline-module.wast" /= file - -- We aren't going to bother fully supporting - -- Unicode function names in the reference interpreter yet. - && "names.wast" /= file + && file `notElem` + [ "inline-module.wast" + -- We aren't going to bother fully supporting + -- Unicode function names in the reference interpreter yet. + , "names.wast" + ] ] defaultMain $ testGroup "main" From 48618fb71bf86f43702ceded5f98eb228eba4666 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:29:44 +0100 Subject: [PATCH 14/40] excude `bulk.wast` for now --- test/Main.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Main.hs b/test/Main.hs index 9fbcc83..b73d7bd 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -25,6 +25,8 @@ main = do -- We aren't going to bother fully supporting -- Unicode function names in the reference interpreter yet. , "names.wast" + -- These contain features that `winter` won't accept yet + , "bulk.wast" ] ] From 6df7ecb71fb9176f755c80bc29c47687f56a52e9 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:38:35 +0100 Subject: [PATCH 15/40] accept bulk-memory instrs --- test/Wat2Wasm.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Wat2Wasm.hs b/test/Wat2Wasm.hs index 51267cf..cab28f7 100644 --- a/test/Wat2Wasm.hs +++ b/test/Wat2Wasm.hs @@ -13,7 +13,7 @@ wat2Wasm contents = do wasm <- emptyTempFile "." "test.wasm" writeFile wat contents (exit, _out, err) <- - readProcessWithExitCode "wat2wasm" [wat, "-o", wasm] "" + readProcessWithExitCode "wat2wasm" [wat, "--enable-bulk-memory", "-o", wasm] "" case exit of ExitSuccess -> do res <- BL.readFile wasm From 8d9b4843b35e78f8f381124d74a1f6ed3f956b66 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:45:16 +0100 Subject: [PATCH 16/40] ooops --- src/Wasm/Binary/Decode.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Wasm/Binary/Decode.hs b/src/Wasm/Binary/Decode.hs index c16267f..d26cb64 100644 --- a/src/Wasm/Binary/Decode.hs +++ b/src/Wasm/Binary/Decode.hs @@ -258,9 +258,9 @@ getMathPrefix = do 0x05 -> return $ Convert $ I64ConvertOp Int.TruncUSatF32 0x06 -> return $ Convert $ I64ConvertOp Int.TruncSSatF64 0x07 -> return $ Convert $ I64ConvertOp Int.TruncUSatF64 - 0x0A -> do 0 <- getWord8 + 0x0A -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 return $ MemoryCopy - 0x0B -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 + 0x0B -> do 0 <- getWord8 return $ MemoryFill _ -> fail (printf "getMathPrefix: illegal op %d" byte) From eae8e8a4da48c2cea9969d0ff04c7c7ff176a950 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 15:57:17 +0100 Subject: [PATCH 17/40] add to exclude list --- test/Main.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Main.hs b/test/Main.hs index b73d7bd..a4f6da9 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -27,6 +27,25 @@ main = do , "names.wast" -- These contain features that `winter` won't accept yet , "bulk.wast" + , "ref_null.wast" + , "memory_init.wast" + , "table_fill.wast" + , "table_copy.wast" + , "ref_null.wast" + , "table_get.wast" + , "table_grow.wast" + , "table.wast" + , "ref_is_null.wast" + , "ref_func.wast" + , "imports.wast" + , "br_table.wast" + , "table_init.wast" + , "table_set.wast" + , "global.wast" + , "linking.wast" + , "unreached-valid.wast" + , "" + , "" ] ] From 6ef420d11a3397d9dfa229b1c07a67e78d611d4c Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 16:06:28 +0100 Subject: [PATCH 18/40] fix list --- test/Main.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index a4f6da9..74a51b7 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -27,25 +27,25 @@ main = do , "names.wast" -- These contain features that `winter` won't accept yet , "bulk.wast" - , "ref_null.wast" , "memory_init.wast" - , "table_fill.wast" - , "table_copy.wast" , "ref_null.wast" , "table_get.wast" , "table_grow.wast" , "table.wast" , "ref_is_null.wast" , "ref_func.wast" + , "unreached-valid.wast" , "imports.wast" , "br_table.wast" + , "table_size.wast" + , "table_fill.wast" , "table_init.wast" , "table_set.wast" + , "table_copy.wast" , "global.wast" , "linking.wast" - , "unreached-valid.wast" - , "" - , "" + , "binary-leb128.wast" + , "exports.wast" ] ] From 979e0dfed6f1b235ef695fb4fe7d569873ad077a Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 16:16:43 +0100 Subject: [PATCH 19/40] exclude more --- test/Main.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Main.hs b/test/Main.hs index 74a51b7..2bc3d42 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -35,6 +35,7 @@ main = do , "ref_is_null.wast" , "ref_func.wast" , "unreached-valid.wast" + , "exports.wast" , "imports.wast" , "br_table.wast" , "table_size.wast" @@ -45,7 +46,10 @@ main = do , "global.wast" , "linking.wast" , "binary-leb128.wast" - , "exports.wast" + , "elem.wast" + , "call_indirect.wast" + , "binary.wast" + , "select.wast" ] ] From e67949da8ab9ba7b2ebe0e12a86636fd0ab9a148 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 16:58:44 +0100 Subject: [PATCH 20/40] run MVP suite too --- default.nix | 12 +++++++++++- test/Main.hs | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 644127b..47d1557 100644 --- a/default.nix +++ b/default.nix @@ -18,6 +18,13 @@ let +spec-tests-mvp = pkgs.fetchFromGitHub { + owner = "WebAssembly"; + repo = "testsuite"; + rev = "35c50bf6fbb002cfdc1227b0af731bdcaf877714"; + sha256 = "0difcpya5i7fc4xdrysx49186x9vh5yhm88dqpmfppj7ddj39l9i"; + }; + spec-tests = pkgs.fetchFromGitHub { owner = "WebAssembly"; repo = "testsuite"; @@ -48,4 +55,7 @@ drv = pkgs.haskellPackages.developPackage { inherit returnShellEnv; }; -in drv.overrideAttrs(old: { WASM_SPEC_TESTS = "${spec-tests}"; }) +in drv.overrideAttrs(old: + { WASM_SPEC_TESTS_MVP = "${spec-tests-mvp}"; + WASM_SPEC_TESTS = "${spec-tests}"; + }) diff --git a/test/Main.hs b/test/Main.hs index 2bc3d42..8ac9973 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -11,11 +11,29 @@ import Spec as Spec (tests) main :: IO () main = do + mwasmPathMVP <- lookupEnv "WASM_SPEC_TESTS_MVP" + testDirMVP <- case mwasmPathMVP of + Nothing -> error "Please define WASM_SPEC_TESTS_MVP to point to .../WebAssembly/spec/test/core" + Just path -> pure path mwasmPath <- lookupEnv "WASM_SPEC_TESTS" testDir <- case mwasmPath of Nothing -> error "Please define WASM_SPEC_TESTS to point to .../WebAssembly/spec/test/core" Just path -> pure path + putStrLn $ "Using wasm MVP spec test directory: " ++ testDirMVP putStrLn $ "Using wasm spec test directory: " ++ testDir + + files <- listDirectory testDirMVP + let wastFilesMVP = flip concatMap files $ \file -> + [ testDirMVP ++ "/" ++ file + | ".wast" `isSuffixOf` file + && file `notElem` + [ "inline-module.wast" + -- We aren't going to bother fully supporting + -- Unicode function names in the reference interpreter yet. + , "names.wast" + ] + ] + files <- listDirectory testDir let wastFiles = flip concatMap files $ \file -> [ testDir ++ "/" ++ file @@ -56,5 +74,6 @@ main = do defaultMain $ testGroup "main" [ Property.tests , Unit.tests + , Spec.tests wastFilesMVP , Spec.tests wastFiles ] From 144370ec29a7443e1296b0191f7d50909a04c7a8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 17:09:48 +0100 Subject: [PATCH 21/40] create two apec groups --- test/Main.hs | 4 ++-- test/Spec.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index 8ac9973..cb44d8d 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -74,6 +74,6 @@ main = do defaultMain $ testGroup "main" [ Property.tests , Unit.tests - , Spec.tests wastFilesMVP - , Spec.tests wastFiles + , Spec.tests "spec MVP" wastFilesMVP + , Spec.tests "spec" wastFiles ] diff --git a/test/Spec.hs b/test/Spec.hs index e604134..e6567c9 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -17,8 +17,8 @@ import Wasm.Util.Float (floatToBits, doubleToBits) import SpecTest (spectest) import Wat2Wasm (wat2Wasm) -tests :: [FilePath] -> TestTree -tests files = testGroup "spec" $ map prep files +tests :: String -> [FilePath] -> TestTree +tests name files = testGroup name $ map prep files where prep file = testCaseSteps file $ \step -> do input <- Prelude.readFile file From e19b91242fb202fba713dfca9481faf58e84c405 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 17:29:44 +0100 Subject: [PATCH 22/40] this seems to fail originally --- test/Main.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Main.hs b/test/Main.hs index cb44d8d..c00acc9 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -31,6 +31,7 @@ main = do -- We aren't going to bother fully supporting -- Unicode function names in the reference interpreter yet. , "names.wast" + , "elem.wast" ] ] From 106003c8af5b3756fff419c982e77cdc9024c919 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 23:09:31 +0100 Subject: [PATCH 23/40] allow zero-sized write past memory end --- src/Wasm/Exec/Eval.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 8feed7e..f4de7d7 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -59,6 +59,7 @@ import Prelude hiding (lookup, elem) import Text.Show (showListWith) import Wasm.Exec.EvalNumeric +import Wasm.Runtime.Memory (pageSize) import qualified Wasm.Runtime.Func as Func import qualified Wasm.Runtime.Global as Global import Wasm.Runtime.Instance @@ -483,10 +484,15 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) - eres <- lift $ lift $ runExceptT $ Memory.loadPacked Pack8 ZX mem addr 0 I32Type - case eres of - Right _ -> k vs' es - Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + -- Zero len with offset out-of-bounds at the end of memory is allowed + sz <- lift $ lift $ Memory.size mem + if pageSize * sz == addr + then k vs' es + else do + eres <- lift $ lift $ runExceptT $ Memory.loadPacked Pack8 ZX mem addr 0 I32Type + case eres of + Right _ -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) (MemoryFill, I32 cnt : v : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do inst <- getFrameInst From 66d09e7ca35be1ab2c2d3af5bdcac484d8037836 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 18 Dec 2021 23:29:40 +0100 Subject: [PATCH 24/40] export `pageSize` --- src/Wasm/Exec/Eval.hs | 4 ++-- src/Wasm/Runtime/Memory.hs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index f4de7d7..9b9df81 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -483,12 +483,12 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do (MemoryFill, I32 0 : _ : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) -- Zero len with offset out-of-bounds at the end of memory is allowed sz <- lift $ lift $ Memory.size mem - if pageSize * sz == addr + if pageSize * sz == dst then k vs' es else do + let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) eres <- lift $ lift $ runExceptT $ Memory.loadPacked Pack8 ZX mem addr 0 I32Type case eres of Right _ -> k vs' es diff --git a/src/Wasm/Runtime/Memory.hs b/src/Wasm/Runtime/Memory.hs index f6b62ba..9043cc0 100644 --- a/src/Wasm/Runtime/Memory.hs +++ b/src/Wasm/Runtime/Memory.hs @@ -24,6 +24,7 @@ module Wasm.Runtime.Memory , loadValue , exportMemory , importMemory + , pageSize ) where import Control.Exception From 76757f7e0d1cb22c433217a5bca56e0e19023dab Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 00:03:17 +0100 Subject: [PATCH 25/40] trap when wrapping around --- src/Wasm/Exec/Eval.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 9b9df81..da7dff3 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -59,7 +59,6 @@ import Prelude hiding (lookup, elem) import Text.Show (showListWith) import Wasm.Exec.EvalNumeric -import Wasm.Runtime.Memory (pageSize) import qualified Wasm.Runtime.Func as Func import qualified Wasm.Runtime.Global as Global import Wasm.Runtime.Instance @@ -485,7 +484,7 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do mem <- lift $ memory inst (0 @@ at) -- Zero len with offset out-of-bounds at the end of memory is allowed sz <- lift $ lift $ Memory.size mem - if pageSize * sz == dst + if Memory.pageSize * sz == dst then k vs' es else do let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) @@ -497,11 +496,14 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do (MemoryFill, I32 cnt : v : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) - eres <- lift $ lift $ runExceptT $ mapM_ (\off -> Memory.storePacked Pack8 mem addr off v) [0 .. pred cnt] - case eres of - Right () -> k vs' es - Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + let [addr, count] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, cnt] + if addr + count > 2^32 + then k vs' (Trapping (memoryErrorString Memory.MemoryBoundsError) @@ at : es) + else do + eres <- lift $ lift $ runExceptT $ mapM_ (\off -> Memory.storePacked Pack8 mem addr off v) [0 .. pred cnt] + case eres of + Right () -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) (MemoryCopy, I32 0 : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst From 4e19a9b483c7602ad0188ca1d34c86a4cbaa901e Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 01:27:22 +0100 Subject: [PATCH 26/40] perform early range-end checks --- src/Wasm/Exec/Eval.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index da7dff3..8c44080 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -518,9 +518,10 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - let [addr_dst, addr_src] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] + let [addr_dst, addr_src, count] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src, cnt] let range = if dst < src then [0 .. pred cnt] else tail $ enumFromThenTo cnt (pred cnt) 0 eres <- lift $ lift $ runExceptT $ + mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) [addr_dst + pred count, addr_src + pred count] mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) range case eres of Right () -> k vs' es From 82254f1ed53d12f042a373fd9b9961a577a64fa3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 01:29:36 +0100 Subject: [PATCH 27/40] simplify --- src/Wasm/Exec/Eval.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 8c44080..8af8cc4 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -521,8 +521,8 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do let [addr_dst, addr_src, count] = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src, cnt] let range = if dst < src then [0 .. pred cnt] else tail $ enumFromThenTo cnt (pred cnt) 0 eres <- lift $ lift $ runExceptT $ - mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) [addr_dst + pred count, addr_src + pred count] - mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) range + mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem (addr + pred count) 0 I32Type) [addr_dst, addr_src] + >> mapM_ (\off -> Memory.loadPacked Pack8 ZX mem addr_src off I32Type >>= Memory.storePacked Pack8 mem addr_dst off) range case eres of Right () -> k vs' es Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) From b890cf068f1058ebbf4cec5250df84d91fcedaab Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 01:51:18 +0100 Subject: [PATCH 28/40] loosen zero len with dest offset directly beyond --- src/Wasm/Exec/Eval.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 8af8cc4..afa3f78 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -508,12 +508,17 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do (MemoryCopy, I32 0 : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] - eres <- lift $ lift $ runExceptT $ - mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) addrs - case eres of - Right () -> k vs' es - Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + -- Zero len with dest offset out-of-bounds at the end of memory is allowed + sz <- lift $ lift $ Memory.size mem + if Memory.pageSize * sz == dst + then k vs' es + else do + let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] + eres <- lift $ lift $ runExceptT $ + mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) addrs + case eres of + Right () -> k vs' es + Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst From 846bbf20e7e4ba9861fa6168be01809985e51b71 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 02:08:34 +0100 Subject: [PATCH 29/40] validate src too --- src/Wasm/Exec/Eval.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index afa3f78..583b621 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -510,7 +510,7 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do mem <- lift $ memory inst (0 @@ at) -- Zero len with dest offset out-of-bounds at the end of memory is allowed sz <- lift $ lift $ Memory.size mem - if Memory.pageSize * sz == dst + if Memory.pageSize * sz >= dst && Memory.pageSize * sz >= src then k vs' es else do let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] From d99970c0a40ba406a952a09015c921a2a48b6f83 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 02:25:06 +0100 Subject: [PATCH 30/40] simplify --- src/Wasm/Exec/Eval.hs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 583b621..562c08e 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -484,14 +484,9 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do mem <- lift $ memory inst (0 @@ at) -- Zero len with offset out-of-bounds at the end of memory is allowed sz <- lift $ lift $ Memory.size mem - if Memory.pageSize * sz == dst + if Memory.pageSize * sz >= dst then k vs' es - else do - let addr = fromIntegral $ i64_extend_u_i32 (fromIntegral dst) - eres <- lift $ lift $ runExceptT $ Memory.loadPacked Pack8 ZX mem addr 0 I32Type - case eres of - Right _ -> k vs' es - Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + else k vs' (Trapping (memoryErrorString Memory.MemoryBoundsError) @@ at : es) (MemoryFill, I32 cnt : v : I32 dst : vs') -> {-# SCC step_MemoryFill #-} do inst <- getFrameInst From 1cf9f32e1edae825ac67eb08adea678eea0a55d7 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 02:27:57 +0100 Subject: [PATCH 31/40] simplify zero-range `MemoryCopy` too --- src/Wasm/Exec/Eval.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Wasm/Exec/Eval.hs b/src/Wasm/Exec/Eval.hs index 562c08e..ee62896 100644 --- a/src/Wasm/Exec/Eval.hs +++ b/src/Wasm/Exec/Eval.hs @@ -503,17 +503,11 @@ step(Code cs cfg vs (e:es)) = (`runReaderT` cfg) $ do (MemoryCopy, I32 0 : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst mem <- lift $ memory inst (0 @@ at) - -- Zero len with dest offset out-of-bounds at the end of memory is allowed + -- Zero len with src/dest offset out-of-bounds at the end of memory is allowed sz <- lift $ lift $ Memory.size mem if Memory.pageSize * sz >= dst && Memory.pageSize * sz >= src then k vs' es - else do - let addrs = fromIntegral . i64_extend_u_i32 . fromIntegral <$> [dst, src] - eres <- lift $ lift $ runExceptT $ - mapM_ (\addr -> Memory.loadPacked Pack8 ZX mem addr 0 I32Type) addrs - case eres of - Right () -> k vs' es - Left exn -> k vs' (Trapping (memoryErrorString exn) @@ at : es) + else k vs' (Trapping (memoryErrorString Memory.MemoryBoundsError) @@ at : es) (MemoryCopy, I32 cnt : I32 src : I32 dst : vs') -> {-# SCC step_MemoryCopy #-} do inst <- getFrameInst From 07673a964c5e2ce735739bb8e188a344093f7c4f Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 02:48:06 +0100 Subject: [PATCH 32/40] remove test/wasm and test/wast --- test/wasm/binary-module.wasm | Bin 39 -> 0 bytes test/wasm/data-offset.wasm | Bin 45 -> 0 bytes test/wasm/elem-offset.wasm | Bin 61 -> 0 bytes test/wasm/export-func-multi.wasm | Bin 36 -> 0 bytes test/wasm/export-func-named.wasm | Bin 34 -> 0 bytes test/wasm/export-func.wasm | Bin 34 -> 0 bytes test/wasm/export-global.wasm | Bin 37 -> 0 bytes test/wasm/export-memory-multi.wasm | Bin 30 -> 0 bytes test/wasm/export-memory.wasm | Bin 22 -> 0 bytes test/wasm/export-table.wasm | Bin 28 -> 0 bytes test/wasm/global.wasm | Bin 136 -> 0 bytes test/wasm/import-func-no-param.wasm | Bin 27 -> 0 bytes test/wasm/import-func-type.wasm | Bin 32 -> 0 bytes test/wasm/import-func.wasm | Bin 112 -> 0 bytes test/wasm/import-global-getglobal.wasm | Bin 31 -> 0 bytes test/wasm/import-global.wasm | Bin 47 -> 0 bytes test/wasm/import-memory.wasm | Bin 21 -> 0 bytes test/wasm/import-table.wasm | Bin 22 -> 0 bytes test/wasm/memory-init-max-size.wasm | Bin 14 -> 0 bytes test/wasm/memory-init-size.wasm | Bin 13 -> 0 bytes test/wasm/memory-segment-1.wasm | Bin 35 -> 0 bytes test/wasm/memory-segment-long.wasm | Bin 3909 -> 0 bytes test/wasm/memory-segment-many.wasm | Bin 55 -> 0 bytes test/wasm/memory-segment-multi-string.wasm | Bin 38 -> 0 bytes test/wasm/module-empty.wasm | Bin 8 -> 0 bytes test/wasm/module-name.wasm | Bin 46 -> 0 bytes test/wasm/start-named.wasm | Bin 27 -> 0 bytes test/wasm/start.wasm | Bin 27 -> 0 bytes test/wasm/table-named.wasm | Bin 63 -> 0 bytes test/wasm/table.wasm | Bin 63 -> 0 bytes test/wasm/type-empty-param.wasm | Bin 14 -> 0 bytes test/wasm/type-empty.wasm | Bin 14 -> 0 bytes test/wasm/type-multi-param.wasm | Bin 18 -> 0 bytes test/wasm/type-no-param.wasm | Bin 15 -> 0 bytes test/wasm/type.wasm | Bin 16 -> 0 bytes test/wast/binary-module.wast | 17 ---- test/wast/data-offset.wast | 5 - test/wast/elem-offset.wast | 6 -- test/wast/export-func-multi.wast | 4 - test/wast/export-func-named.wast | 3 - test/wast/export-func.wast | 3 - test/wast/export-global.wast | 4 - test/wast/export-memory-multi.wast | 4 - test/wast/export-memory.wast | 3 - test/wast/export-table.wast | 3 - test/wast/global.wast | 15 --- test/wast/import-func-no-param.wast | 1 - test/wast/import-func-type.wast | 3 - test/wast/import-func.wast | 10 -- test/wast/import-global-getglobal.wast | 3 - test/wast/import-global.wast | 5 - test/wast/import-memory.wast | 2 - test/wast/import-table.wast | 2 - test/wast/memory-fill-copy.wast | 111 --------------------- test/wast/memory-init-max-size.wast | 1 - test/wast/memory-init-size.wast | 1 - test/wast/memory-segment-1.wast | 2 - test/wast/memory-segment-long.wast | 13 --- test/wast/memory-segment-many.wast | 6 -- test/wast/memory-segment-multi-string.wast | 3 - test/wast/module-empty.wast | 1 - test/wast/start-named.wast | 3 - test/wast/start.wast | 3 - test/wast/table-named.wast | 5 - test/wast/table.wast | 5 - test/wast/type-empty-param.wast | 1 - test/wast/type-empty.wast | 1 - test/wast/type-multi-param.wast | 1 - test/wast/type-no-param.wast | 1 - test/wast/type.wast | 1 - 70 files changed, 252 deletions(-) delete mode 100644 test/wasm/binary-module.wasm delete mode 100644 test/wasm/data-offset.wasm delete mode 100644 test/wasm/elem-offset.wasm delete mode 100644 test/wasm/export-func-multi.wasm delete mode 100644 test/wasm/export-func-named.wasm delete mode 100644 test/wasm/export-func.wasm delete mode 100644 test/wasm/export-global.wasm delete mode 100644 test/wasm/export-memory-multi.wasm delete mode 100644 test/wasm/export-memory.wasm delete mode 100644 test/wasm/export-table.wasm delete mode 100644 test/wasm/global.wasm delete mode 100644 test/wasm/import-func-no-param.wasm delete mode 100644 test/wasm/import-func-type.wasm delete mode 100644 test/wasm/import-func.wasm delete mode 100644 test/wasm/import-global-getglobal.wasm delete mode 100644 test/wasm/import-global.wasm delete mode 100644 test/wasm/import-memory.wasm delete mode 100644 test/wasm/import-table.wasm delete mode 100644 test/wasm/memory-init-max-size.wasm delete mode 100644 test/wasm/memory-init-size.wasm delete mode 100644 test/wasm/memory-segment-1.wasm delete mode 100644 test/wasm/memory-segment-long.wasm delete mode 100644 test/wasm/memory-segment-many.wasm delete mode 100644 test/wasm/memory-segment-multi-string.wasm delete mode 100644 test/wasm/module-empty.wasm delete mode 100644 test/wasm/module-name.wasm delete mode 100644 test/wasm/start-named.wasm delete mode 100644 test/wasm/start.wasm delete mode 100644 test/wasm/table-named.wasm delete mode 100644 test/wasm/table.wasm delete mode 100644 test/wasm/type-empty-param.wasm delete mode 100644 test/wasm/type-empty.wasm delete mode 100644 test/wasm/type-multi-param.wasm delete mode 100644 test/wasm/type-no-param.wasm delete mode 100644 test/wasm/type.wasm delete mode 100644 test/wast/binary-module.wast delete mode 100644 test/wast/data-offset.wast delete mode 100644 test/wast/elem-offset.wast delete mode 100644 test/wast/export-func-multi.wast delete mode 100644 test/wast/export-func-named.wast delete mode 100644 test/wast/export-func.wast delete mode 100644 test/wast/export-global.wast delete mode 100644 test/wast/export-memory-multi.wast delete mode 100644 test/wast/export-memory.wast delete mode 100644 test/wast/export-table.wast delete mode 100644 test/wast/global.wast delete mode 100644 test/wast/import-func-no-param.wast delete mode 100644 test/wast/import-func-type.wast delete mode 100644 test/wast/import-func.wast delete mode 100644 test/wast/import-global-getglobal.wast delete mode 100644 test/wast/import-global.wast delete mode 100644 test/wast/import-memory.wast delete mode 100644 test/wast/import-table.wast delete mode 100644 test/wast/memory-fill-copy.wast delete mode 100644 test/wast/memory-init-max-size.wast delete mode 100644 test/wast/memory-init-size.wast delete mode 100644 test/wast/memory-segment-1.wast delete mode 100644 test/wast/memory-segment-long.wast delete mode 100644 test/wast/memory-segment-many.wast delete mode 100644 test/wast/memory-segment-multi-string.wast delete mode 100644 test/wast/module-empty.wast delete mode 100644 test/wast/start-named.wast delete mode 100644 test/wast/start.wast delete mode 100644 test/wast/table-named.wast delete mode 100644 test/wast/table.wast delete mode 100644 test/wast/type-empty-param.wast delete mode 100644 test/wast/type-empty.wast delete mode 100644 test/wast/type-multi-param.wast delete mode 100644 test/wast/type-no-param.wast delete mode 100644 test/wast/type.wast diff --git a/test/wasm/binary-module.wasm b/test/wasm/binary-module.wasm deleted file mode 100644 index 1809ddeefde9dd1a3b755ba2de7ef5fb21a6a5e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 39 ucmZQbEY4+QU|?WmWlUgTtY>CoWMJoDWXVm;%wu5S;$UQBaJ*B)&kX=)e+9Jw diff --git a/test/wasm/data-offset.wasm b/test/wasm/data-offset.wasm deleted file mode 100644 index 0fb56ac5a92fac4f033515a1630a99a0369b5b98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 45 zcmZQbEY4+QU|?Y4VPsCr&u30bEMl%_U}a`xU}R%stY>g! diff --git a/test/wasm/elem-offset.wasm b/test/wasm/elem-offset.wasm deleted file mode 100644 index 58e31634509d1e20ab366e3ebcd90ba8b45101f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 61 zcmV~$!3}^g3CoWMF4yWXxk=;9_HBVQ^&N1^`0#0}TKG diff --git a/test/wasm/export-func.wasm b/test/wasm/export-func.wasm deleted file mode 100644 index 643646ca32732cf9a6b735d085d5d7558aca0624..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 34 ocmV~$3km=b6ac|pj}({W06yjZWrq2dfY||&q*h~}3#}N~KSA3AEdT%j diff --git a/test/wasm/export-global.wasm b/test/wasm/export-global.wasm deleted file mode 100644 index 6e18fd5c1debf76ca0ba63ba0e74f7e4e8d2c5cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 37 qcmZQbEY4+QU|?Y5W2$FxWZB?M5CyIP diff --git a/test/wasm/export-memory-multi.wasm b/test/wasm/export-memory-multi.wasm deleted file mode 100644 index 9bb092073727026ba30ab23a1f4547d8632709a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30 icmZQbEY4+QU|?WnW@KPw=VxNcP0clAVgOM_Obh@$xdc)G diff --git a/test/wasm/export-memory.wasm b/test/wasm/export-memory.wasm deleted file mode 100644 index 8c10f92e12d55029f9c2f0019ac795c09f72ea57..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 dcmZQbEY4+QU|?WnW@KPwXJ=&2P0eLu0019D0-yi@ diff --git a/test/wasm/export-table.wasm b/test/wasm/export-table.wasm deleted file mode 100644 index b6bbf94b1a59fb8a69342bb4bfd28845f55e4855..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28 jcmZQbEY4+QU|?WjVJu)^VCP}v$gPYoNleN~Wn=&VKl%kG diff --git a/test/wasm/global.wasm b/test/wasm/global.wasm deleted file mode 100644 index 06aeeb201de96beabf0a02849fcef14b6193c6b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 136 zcmZQbEY4+QU|?YKWMNLr&*#cCHi}Qr$xlkmVXkL@h?tqcMCu?SX$Up7P!WWh8U{9F xj(P@1M(#QWCnoM%24@Ba2M6vN1{a_$Kp^12UC*G*0F+f`1j;Hi0i~3gxdAfj9!LNH diff --git a/test/wasm/import-func-no-param.wasm b/test/wasm/import-func-no-param.wasm deleted file mode 100644 index 3040a504ece33652c1cf44bdb4e7864352155eb6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27 icmZQbEY4+QU|?WmVN76PVB%(EPRq|{PD(6dU;qF$p9D4l diff --git a/test/wasm/import-func-type.wasm b/test/wasm/import-func-type.wasm deleted file mode 100644 index 34c47471dbf7af6a2888117c3eece690c1c6afab..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 ncmZQbEY4+QU|?Y6WK3YGudA(LtY_k8WKPS^XHH5iVqgFOXa)wg diff --git a/test/wasm/import-func.wasm b/test/wasm/import-func.wasm deleted file mode 100644 index 261c1384dbe7acdf31084400b3f2d9e6b87af9e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 112 zcmXZOK@Ng25CzcxJ1y7X4r;uC_n4YW=mKl#ETO$RB(iyVh;< diff --git a/test/wasm/memory-init-max-size.wasm b/test/wasm/memory-init-max-size.wasm deleted file mode 100644 index c2150074333c16461b083f80a1faf7b12f7668db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14 VcmZQbEY4+QU|?WnVPs@v0ss$H0Z{+| diff --git a/test/wasm/memory-init-size.wasm b/test/wasm/memory-init-size.wasm deleted file mode 100644 index 67d6849c74838975793d0355a2fcc483d91b53ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13 UcmZQbEY4+QU|?WnW@KOl01f^DO#lD@ diff --git a/test/wasm/memory-segment-1.wasm b/test/wasm/memory-segment-1.wasm deleted file mode 100644 index 997006327939e85441599947fb5bd008f18d801d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 35 ocmZQbEY4+QU|?WnVFUthVMYc=25#Pr)SR4r9fk7zqMQ^(095w|aR2}S diff --git a/test/wasm/memory-segment-long.wasm b/test/wasm/memory-segment-long.wasm deleted file mode 100644 index a460b3a60cf7ca734be3ce4d486be07b75008904..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3909 zcmeIzRZhe}7{Kv%x0FJWWpQ8J-JRm@u8X_7a|DjS5eO&X1#ST0Ht;WmWPw0<;-#H0 zzf99kI~nPG!qm>1Cfj-9T~_(7P66pT;w4i1t>%jicx}6l%X6Is6-X2F@0+j#{w3y zgk`K?6>C_>1~##UZR}tdd)UVT4snEIjA9Jqn7|~Q_^yMl9UbUI7rN1dUi6_K0~o{* VhB1Pl62gD=Zzcp5!7QI<;1wOzmtX(@ diff --git a/test/wasm/memory-segment-many.wasm b/test/wasm/memory-segment-many.wasm deleted file mode 100644 index 015b8d4762c70545db95569db2275badefe498c8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 55 zcmZQbEY4+QU|?WnW@KRG)?i_9WZ-7X$YgM2;bzT9&B@7UaOC1A3`N2BX(G`}Dz#+e{)rjl9RV^8s717<8kx{d1;_2i*;ve#A9oD~L;wH) diff --git a/test/wasm/start-named.wasm b/test/wasm/start-named.wasm deleted file mode 100644 index 0e1132c07636cc2f7e3ab1bae6f476a6b3534c83..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27 icmZQbEY4+QU|?WmVN76PU}j=u;9z9nVqs)r;06FD>H*XM diff --git a/test/wasm/start.wasm b/test/wasm/start.wasm deleted file mode 100644 index 0e1132c07636cc2f7e3ab1bae6f476a6b3534c83..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27 icmZQbEY4+QU|?WmVN76PU}j=u;9z9nVqs)r;06FD>H*XM diff --git a/test/wasm/table-named.wasm b/test/wasm/table-named.wasm deleted file mode 100644 index 554d248bdbaa362b0a75cad4d691bb2f415c32dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 63 zcmWN{u?>JQ3`N2BZBq~%I2WZ@Ni_Y=~cwu#6`wx L)($sv32yQS{ip@* diff --git a/test/wasm/table.wasm b/test/wasm/table.wasm deleted file mode 100644 index 554d248bdbaa362b0a75cad4d691bb2f415c32dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 63 zcmWN{u?>JQ3`N2BZBq~%I2WZ@Ni_Y=~cwu#6`wx L)($sv32yQS{ip@* diff --git a/test/wasm/type-empty-param.wasm b/test/wasm/type-empty-param.wasm deleted file mode 100644 index 044cf4c82e3909bc7bf63874913e12e3145fadef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14 VcmZQbEY4+QU|?WmVN76P000nH0jU50 diff --git a/test/wasm/type-empty.wasm b/test/wasm/type-empty.wasm deleted file mode 100644 index 044cf4c82e3909bc7bf63874913e12e3145fadef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14 VcmZQbEY4+QU|?WmVN76P000nH0jU50 diff --git a/test/wasm/type-multi-param.wasm b/test/wasm/type-multi-param.wasm deleted file mode 100644 index d042a90df2f693aef469248e5a1d0b8a5bfef744..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18 ZcmZQbEY4+QU|?Y6U`$}HudQLM1ppnA1Ev4~ diff --git a/test/wasm/type-no-param.wasm b/test/wasm/type-no-param.wasm deleted file mode 100644 index 5fce444cdf92966845aee2cacc78d4f951cc7ccb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15 WcmZQbEY4+QU|?WmWlUgTtOo!Rh5{-8 diff --git a/test/wasm/type.wasm b/test/wasm/type.wasm deleted file mode 100644 index f6e1cb211b9413b5325f14cf8705f5e04f28a083..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 XcmZQbEY4+QU|?WmV@zPIXRHSR6}SSc diff --git a/test/wast/binary-module.wast b/test/wast/binary-module.wast deleted file mode 100644 index e0df856..0000000 --- a/test/wast/binary-module.wast +++ /dev/null @@ -1,17 +0,0 @@ -(module binary - "\00asm" ;; magic - "\01\00\00\00" ;; version - "\01\05" ;; type section, 5 bytes - "\01\60\00\01\7f" ;; 1 type, function, no params, i32 result - "\03\02" ;; function section, 2 bytes - "\01\00" ;; 1 function, type 0 - "\07\08" ;; export section, 8 bytes - "\01\04main\00\00" ;; 1 export, function 0, named "main" - "\0a\08" ;; code section, 8 bytes - "\01\06" ;; 1 function, 6 bytes - "\00" ;; 0 locals - "\41" ;; i32.const - "\dc\7c" ;; -420 - "\0f" ;; return - "\0b" ;; end (of function) -) diff --git a/test/wast/data-offset.wast b/test/wast/data-offset.wast deleted file mode 100644 index dfa6dad..0000000 --- a/test/wast/data-offset.wast +++ /dev/null @@ -1,5 +0,0 @@ -(module - (import "foo" "bar" (global i32)) - (memory 1) - (global i32 i32.const 1) - (data (get_global 0) "hi")) diff --git a/test/wast/elem-offset.wast b/test/wast/elem-offset.wast deleted file mode 100644 index 44721f8..0000000 --- a/test/wast/elem-offset.wast +++ /dev/null @@ -1,6 +0,0 @@ -(module - (import "foo" "bar" (global i32)) - (global i32 i32.const 1) - (func) - (table 2 anyfunc) - (elem (get_global 0) 0)) diff --git a/test/wast/export-func-multi.wast b/test/wast/export-func-multi.wast deleted file mode 100644 index 30d2231..0000000 --- a/test/wast/export-func-multi.wast +++ /dev/null @@ -1,4 +0,0 @@ -(module - (func (nop)) - (export "a" (func 0)) - (export "b" (func 0))) diff --git a/test/wast/export-func-named.wast b/test/wast/export-func-named.wast deleted file mode 100644 index 8ebe599..0000000 --- a/test/wast/export-func-named.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (func $n (result i32) (i32.const 0)) - (export "n" (func $n))) diff --git a/test/wast/export-func.wast b/test/wast/export-func.wast deleted file mode 100644 index 1892a22..0000000 --- a/test/wast/export-func.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (func (nop)) - (export "nop" (func 0))) diff --git a/test/wast/export-global.wast b/test/wast/export-global.wast deleted file mode 100644 index bdffc6b..0000000 --- a/test/wast/export-global.wast +++ /dev/null @@ -1,4 +0,0 @@ -(module - (global i32 (i32.const 0)) - (global (mut f32) (f32.const 0)) - (export "global0" (global 0))) diff --git a/test/wast/export-memory-multi.wast b/test/wast/export-memory-multi.wast deleted file mode 100644 index d00acc5..0000000 --- a/test/wast/export-memory-multi.wast +++ /dev/null @@ -1,4 +0,0 @@ -(module - (memory 1) - (export "mem1" (memory 0)) - (export "mem2" (memory 0))) diff --git a/test/wast/export-memory.wast b/test/wast/export-memory.wast deleted file mode 100644 index eec9809..0000000 --- a/test/wast/export-memory.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (memory 1) - (export "mem" (memory 0))) diff --git a/test/wast/export-table.wast b/test/wast/export-table.wast deleted file mode 100644 index 12c926f..0000000 --- a/test/wast/export-table.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (table 0 anyfunc) - (export "my_table" (table 0))) diff --git a/test/wast/global.wast b/test/wast/global.wast deleted file mode 100644 index 5a94ca9..0000000 --- a/test/wast/global.wast +++ /dev/null @@ -1,15 +0,0 @@ -(module - (import "foo" "i32_global" (global i32)) - (import "foo" "i64_global" (global i64)) - (import "foo" "f32_global" (global f32)) - (import "foo" "f64_global" (global f64)) - - (global i32 (i32.const 1)) - (global i64 (i64.const 2)) - (global f32 (f32.const 3)) - (global f64 (f64.const 4)) - - (global i32 (get_global 0)) - (global i64 (get_global 1)) - (global f32 (get_global 2)) - (global f64 (get_global 3))) diff --git a/test/wast/import-func-no-param.wast b/test/wast/import-func-no-param.wast deleted file mode 100644 index 9302e92..0000000 --- a/test/wast/import-func-no-param.wast +++ /dev/null @@ -1 +0,0 @@ -(module (import "foo" "bar" (func))) diff --git a/test/wast/import-func-type.wast b/test/wast/import-func-type.wast deleted file mode 100644 index 9f31b90..0000000 --- a/test/wast/import-func-type.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (type (func (param i32 i64 f32 f64) (result i32))) - (import "foo" "bar" (func (type 0)))) diff --git a/test/wast/import-func.wast b/test/wast/import-func.wast deleted file mode 100644 index a999e01..0000000 --- a/test/wast/import-func.wast +++ /dev/null @@ -1,10 +0,0 @@ -(module - ;; unnamed - (import "foo" "bar" (func (param i32) (result i64))) - - ;; named - (import "stdio" "print" (func $print_i32 (param i32))) - (import "math" "add" (func $add_i32 (param i32 i32) (result i32))) - (import "test" "f32" (func $f32 (param f32) (result f32))) - (import "test" "f64" (func $f64 (param f64) (result f64))) - (import "test" "i64" (func $i64 (param i64) (result i64)))) diff --git a/test/wast/import-global-getglobal.wast b/test/wast/import-global-getglobal.wast deleted file mode 100644 index fb6a5fb..0000000 --- a/test/wast/import-global-getglobal.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (import "a" "global" (global i32)) - (global i32 (get_global 0))) diff --git a/test/wast/import-global.wast b/test/wast/import-global.wast deleted file mode 100644 index 216ae32..0000000 --- a/test/wast/import-global.wast +++ /dev/null @@ -1,5 +0,0 @@ -(module - (import "foo" "1" (global i32)) - (import "foo" "2" (global i64)) - (import "foo" "3" (global f32)) - (import "foo" "4" (global f64))) diff --git a/test/wast/import-memory.wast b/test/wast/import-memory.wast deleted file mode 100644 index 8d22fd6..0000000 --- a/test/wast/import-memory.wast +++ /dev/null @@ -1,2 +0,0 @@ -(module - (import "foo" "2" (memory 0 2))) diff --git a/test/wast/import-table.wast b/test/wast/import-table.wast deleted file mode 100644 index 90b2603..0000000 --- a/test/wast/import-table.wast +++ /dev/null @@ -1,2 +0,0 @@ -(module - (import "foo" "2" (table 0 10 anyfunc))) diff --git a/test/wast/memory-fill-copy.wast b/test/wast/memory-fill-copy.wast deleted file mode 100644 index ddc8338..0000000 --- a/test/wast/memory-fill-copy.wast +++ /dev/null @@ -1,111 +0,0 @@ -;; segment syntax -(module - (memory 1) - (data "foo")) - -(module - (table 3 funcref) - (elem funcref (ref.func 0) (ref.null func) (ref.func 1)) - (func) - (func)) - -;; memory.fill -(module - (memory 1) - - (func (export "fill") (param i32 i32 i32) - (memory.fill - (local.get 0) - (local.get 1) - (local.get 2))) - - (func (export "load8_u") (param i32) (result i32) - (i32.load8_u (local.get 0))) -) - -;; Basic fill test. -(invoke "fill" (i32.const 1) (i32.const 0xff) (i32.const 3)) -(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0)) -(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xff)) -(assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0xff)) -(assert_return (invoke "load8_u" (i32.const 3)) (i32.const 0xff)) -(assert_return (invoke "load8_u" (i32.const 4)) (i32.const 0)) - -;; Fill value is stored as a byte. -(invoke "fill" (i32.const 0) (i32.const 0xbbaa) (i32.const 2)) -(assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xaa)) -(assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xaa)) - -;; Fill all of memory -(invoke "fill" (i32.const 0) (i32.const 0) (i32.const 0x10000)) - -;; Out-of-bounds writes trap, and nothing is written -(assert_trap (invoke "fill" (i32.const 0xff00) (i32.const 1) (i32.const 0x101)) - "out of bounds memory access") -(assert_return (invoke "load8_u" (i32.const 0xff00)) (i32.const 0)) -(assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0)) - -;; Succeed when writing 0 bytes at the end of the region. -(invoke "fill" (i32.const 0x10000) (i32.const 0) (i32.const 0)) - -;; Writing 0 bytes outside the memory traps. -(assert_trap (invoke "fill" (i32.const 0x10001) (i32.const 0) (i32.const 0)) - "out of bounds memory access") - - -;; memory.copy -(module - (memory (data "\aa\bb\cc\dd")) - - (func (export "copy") (param i32 i32 i32) - (memory.copy - (local.get 0) - (local.get 1) - (local.get 2))) - - (func (export "load8_u") (param i32) (result i32) - (i32.load8_u (local.get 0))) -) - -;; Non-overlapping copy. -(invoke "copy" (i32.const 10) (i32.const 0) (i32.const 4)) - -(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0)) -(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xaa)) -(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xbb)) -(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc)) -(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd)) -(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0)) - -;; Overlap, source > dest -(invoke "copy" (i32.const 8) (i32.const 10) (i32.const 4)) -(assert_return (invoke "load8_u" (i32.const 8)) (i32.const 0xaa)) -(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0xbb)) -(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xcc)) -(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xdd)) -(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc)) -(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd)) - -;; Overlap, source < dest -(invoke "copy" (i32.const 10) (i32.const 7) (i32.const 6)) -(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0)) -(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xaa)) -(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xbb)) -(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xcc)) -(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0xdd)) -(assert_return (invoke "load8_u" (i32.const 15)) (i32.const 0xcc)) -(assert_return (invoke "load8_u" (i32.const 16)) (i32.const 0)) - -;; Copy ending at memory limit is ok. -(invoke "copy" (i32.const 0xff00) (i32.const 0) (i32.const 0x100)) -(invoke "copy" (i32.const 0xfe00) (i32.const 0xff00) (i32.const 0x100)) - -;; Succeed when copying 0 bytes at the end of the region. -(invoke "copy" (i32.const 0x10000) (i32.const 0) (i32.const 0)) -(invoke "copy" (i32.const 0) (i32.const 0x10000) (i32.const 0)) - -;; Copying 0 bytes outside the memory traps. -(assert_trap (invoke "copy" (i32.const 0x10001) (i32.const 0) (i32.const 0)) - "out of bounds memory access") -(assert_trap (invoke "copy" (i32.const 0) (i32.const 0x10001) (i32.const 0)) - "out of bounds memory access") diff --git a/test/wast/memory-init-max-size.wast b/test/wast/memory-init-max-size.wast deleted file mode 100644 index ee01c49..0000000 --- a/test/wast/memory-init-max-size.wast +++ /dev/null @@ -1 +0,0 @@ -(module (memory 1 2)) diff --git a/test/wast/memory-init-size.wast b/test/wast/memory-init-size.wast deleted file mode 100644 index 4503196..0000000 --- a/test/wast/memory-init-size.wast +++ /dev/null @@ -1 +0,0 @@ -(module (memory 1)) diff --git a/test/wast/memory-segment-1.wast b/test/wast/memory-segment-1.wast deleted file mode 100644 index 69bc049..0000000 --- a/test/wast/memory-segment-1.wast +++ /dev/null @@ -1,2 +0,0 @@ -(module - (memory (data "hello, world!"))) diff --git a/test/wast/memory-segment-long.wast b/test/wast/memory-segment-long.wast deleted file mode 100644 index a0836fd..0000000 --- a/test/wast/memory-segment-long.wast +++ /dev/null @@ -1,13 +0,0 @@ -;; This is a regression test to ensure we read and parse integer tokens ASAP. -;; Otherwise the memory that is used to store them may be reused. In this case, -;; the very long data segment strings were causing the strings that store the -;; initial size and max size to be clobbered. -(module - (memory 1 65535) - (data (i32.const 8) "\10\01\00\00") - (data (i32.const 16) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\03 \02 \02 \02 \02 \02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\01`\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d5\08\d5\08\d5\08\d5\08\d5\08\d5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d6\08\d6\08\d6\08\d6\08\d6\08\d6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\04\c0\04\c0\04\c0\04\c0\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") - (data (i32.const 784) " \05\00\00") - (data (i32.const 800) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00\07\00\00\00\08\00\00\00\t\00\00\00\n\00\00\00\0b\00\00\00\0c\00\00\00\0d\00\00\00\0e\00\00\00\0f\00\00\00\10\00\00\00\11\00\00\00\12\00\00\00\13\00\00\00\14\00\00\00\15\00\00\00\16\00\00\00\17\00\00\00\18\00\00\00\19\00\00\00\1a\00\00\00\1b\00\00\00\1c\00\00\00\1d\00\00\00\1e\00\00\00\1f\00\00\00 \00\00\00!\00\00\00\"\00\00\00#\00\00\00$\00\00\00%\00\00\00&\00\00\00\'\00\00\00(\00\00\00)\00\00\00*\00\00\00+\00\00\00,\00\00\00-\00\00\00.\00\00\00/\00\00\000\00\00\001\00\00\002\00\00\003\00\00\004\00\00\005\00\00\006\00\00\007\00\00\008\00\00\009\00\00\00:\00\00\00;\00\00\00<\00\00\00=\00\00\00>\00\00\00?\00\00\00@\00\00\00a\00\00\00b\00\00\00c\00\00\00d\00\00\00e\00\00\00f\00\00\00g\00\00\00h\00\00\00i\00\00\00j\00\00\00k\00\00\00l\00\00\00m\00\00\00n\00\00\00o\00\00\00p\00\00\00q\00\00\00r\00\00\00s\00\00\00t\00\00\00u\00\00\00v\00\00\00w\00\00\00x\00\00\00y\00\00\00z\00\00\00[\00\00\00\\\00\00\00]\00\00\00^\00\00\00_\00\00\00`\00\00\00a\00\00\00b\00\00\00c\00\00\00d\00\00\00e\00\00\00f\00\00\00g\00\00\00h\00\00\00i\00\00\00j\00\00\00k\00\00\00l\00\00\00m\00\00\00n\00\00\00o\00\00\00p\00\00\00q\00\00\00r\00\00\00s\00\00\00t\00\00\00u\00\00\00v\00\00\00w\00\00\00x\00\00\00y\00\00\00z\00\00\00{\00\00\00|\00\00\00}\00\00\00~\00\00\00\7f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") - (data (i32.const 2336) "0\0b\00\00") - (data (i32.const 2352) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00\07\00\00\00\08\00\00\00\t\00\00\00\n\00\00\00\0b\00\00\00\0c\00\00\00\0d\00\00\00\0e\00\00\00\0f\00\00\00\10\00\00\00\11\00\00\00\12\00\00\00\13\00\00\00\14\00\00\00\15\00\00\00\16\00\00\00\17\00\00\00\18\00\00\00\19\00\00\00\1a\00\00\00\1b\00\00\00\1c\00\00\00\1d\00\00\00\1e\00\00\00\1f\00\00\00 \00\00\00!\00\00\00\"\00\00\00#\00\00\00$\00\00\00%\00\00\00&\00\00\00\'\00\00\00(\00\00\00)\00\00\00*\00\00\00+\00\00\00,\00\00\00-\00\00\00.\00\00\00/\00\00\000\00\00\001\00\00\002\00\00\003\00\00\004\00\00\005\00\00\006\00\00\007\00\00\008\00\00\009\00\00\00:\00\00\00;\00\00\00<\00\00\00=\00\00\00>\00\00\00?\00\00\00@\00\00\00A\00\00\00B\00\00\00C\00\00\00D\00\00\00E\00\00\00F\00\00\00G\00\00\00H\00\00\00I\00\00\00J\00\00\00K\00\00\00L\00\00\00M\00\00\00N\00\00\00O\00\00\00P\00\00\00Q\00\00\00R\00\00\00S\00\00\00T\00\00\00U\00\00\00V\00\00\00W\00\00\00X\00\00\00Y\00\00\00Z\00\00\00[\00\00\00\\\00\00\00]\00\00\00^\00\00\00_\00\00\00`\00\00\00A\00\00\00B\00\00\00C\00\00\00D\00\00\00E\00\00\00F\00\00\00G\00\00\00H\00\00\00I\00\00\00J\00\00\00K\00\00\00L\00\00\00M\00\00\00N\00\00\00O\00\00\00P\00\00\00Q\00\00\00R\00\00\00S\00\00\00T\00\00\00U\00\00\00V\00\00\00W\00\00\00X\00\00\00Y\00\00\00Z\00\00\00{\00\00\00|\00\00\00}\00\00\00~\00\00\00\7f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") -) diff --git a/test/wast/memory-segment-many.wast b/test/wast/memory-segment-many.wast deleted file mode 100644 index 3dd5422..0000000 --- a/test/wast/memory-segment-many.wast +++ /dev/null @@ -1,6 +0,0 @@ -(module - (memory 1) - (data (i32.const 0) "hi") - (data (i32.const 4) "hello") - (data (i32.const 10) "goodbye") - (data (i32.const 20) "adios")) diff --git a/test/wast/memory-segment-multi-string.wast b/test/wast/memory-segment-multi-string.wast deleted file mode 100644 index 5c434d1..0000000 --- a/test/wast/memory-segment-multi-string.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (memory - (data "hi" "there" "how" "are" "you"))) diff --git a/test/wast/module-empty.wast b/test/wast/module-empty.wast deleted file mode 100644 index 3af8f25..0000000 --- a/test/wast/module-empty.wast +++ /dev/null @@ -1 +0,0 @@ -(module) diff --git a/test/wast/start-named.wast b/test/wast/start-named.wast deleted file mode 100644 index 16aa37d..0000000 --- a/test/wast/start-named.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (start $foo) - (func $foo)) diff --git a/test/wast/start.wast b/test/wast/start.wast deleted file mode 100644 index fa4a380..0000000 --- a/test/wast/start.wast +++ /dev/null @@ -1,3 +0,0 @@ -(module - (start 0) - (func)) diff --git a/test/wast/table-named.wast b/test/wast/table-named.wast deleted file mode 100644 index 5d693db..0000000 --- a/test/wast/table-named.wast +++ /dev/null @@ -1,5 +0,0 @@ -(module - (func $f (param i32)) - (func $g (param i32 i64)) - (func $h (result i64) (i64.const 0)) - (table anyfunc (elem $f $f $g $h))) diff --git a/test/wast/table.wast b/test/wast/table.wast deleted file mode 100644 index 4d0c897..0000000 --- a/test/wast/table.wast +++ /dev/null @@ -1,5 +0,0 @@ -(module - (func (param i32)) - (func (param i32 i64)) - (func (result i64) i64.const 0) - (table anyfunc (elem 0 0 1 2))) diff --git a/test/wast/type-empty-param.wast b/test/wast/type-empty-param.wast deleted file mode 100644 index 69a7cf4..0000000 --- a/test/wast/type-empty-param.wast +++ /dev/null @@ -1 +0,0 @@ -(module (type (func (param)))) diff --git a/test/wast/type-empty.wast b/test/wast/type-empty.wast deleted file mode 100644 index d75fc4c..0000000 --- a/test/wast/type-empty.wast +++ /dev/null @@ -1 +0,0 @@ -(module (type (func))) diff --git a/test/wast/type-multi-param.wast b/test/wast/type-multi-param.wast deleted file mode 100644 index a617687..0000000 --- a/test/wast/type-multi-param.wast +++ /dev/null @@ -1 +0,0 @@ -(module (type (func (param i32 f32 f64) (result f32)))) diff --git a/test/wast/type-no-param.wast b/test/wast/type-no-param.wast deleted file mode 100644 index b3fc19e..0000000 --- a/test/wast/type-no-param.wast +++ /dev/null @@ -1 +0,0 @@ -(module (type (func (result i32)))) diff --git a/test/wast/type.wast b/test/wast/type.wast deleted file mode 100644 index 6d915a8..0000000 --- a/test/wast/type.wast +++ /dev/null @@ -1 +0,0 @@ -(module (type (func (param i32) (result i32)))) From a9b38a42a5de5d999cebcbe1cc0675b5ea358125 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 02:57:10 +0100 Subject: [PATCH 33/40] elim warning --- test/Main.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index c00acc9..b0695c3 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -22,8 +22,8 @@ main = do putStrLn $ "Using wasm MVP spec test directory: " ++ testDirMVP putStrLn $ "Using wasm spec test directory: " ++ testDir - files <- listDirectory testDirMVP - let wastFilesMVP = flip concatMap files $ \file -> + filesMVP <- listDirectory testDirMVP + let wastFilesMVP = flip concatMap filesMVP $ \file -> [ testDirMVP ++ "/" ++ file | ".wast" `isSuffixOf` file && file `notElem` From 355c6fc0a7a3204036a3a02157e1407f986d187d Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 03:02:58 +0100 Subject: [PATCH 34/40] Update src/Wasm/Binary/Decode.hs --- src/Wasm/Binary/Decode.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wasm/Binary/Decode.hs b/src/Wasm/Binary/Decode.hs index d26cb64..acda424 100644 --- a/src/Wasm/Binary/Decode.hs +++ b/src/Wasm/Binary/Decode.hs @@ -259,7 +259,7 @@ getMathPrefix = do 0x06 -> return $ Convert $ I64ConvertOp Int.TruncSSatF64 0x07 -> return $ Convert $ I64ConvertOp Int.TruncUSatF64 0x0A -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 - return $ MemoryCopy + return MemoryCopy 0x0B -> do 0 <- getWord8 return $ MemoryFill _ -> fail (printf "getMathPrefix: illegal op %d" byte) From 96e5a294738f9a8d1e97dc1b129998ae5180aa6b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 19 Dec 2021 03:03:33 +0100 Subject: [PATCH 35/40] Update src/Wasm/Binary/Decode.hs --- src/Wasm/Binary/Decode.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wasm/Binary/Decode.hs b/src/Wasm/Binary/Decode.hs index acda424..f05bdd8 100644 --- a/src/Wasm/Binary/Decode.hs +++ b/src/Wasm/Binary/Decode.hs @@ -261,7 +261,7 @@ getMathPrefix = do 0x0A -> do (0, 0) <- (,) <$> getWord8 <*> getWord8 return MemoryCopy 0x0B -> do 0 <- getWord8 - return $ MemoryFill + return MemoryFill _ -> fail (printf "getMathPrefix: illegal op %d" byte) From 338cdec5393e1964803f917a2a0fd4b2464fb032 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 20 Dec 2021 10:57:45 +0100 Subject: [PATCH 36/40] Update default.nix Co-authored-by: Bas van Dijk --- default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 47d1557..ee738dc 100644 --- a/default.nix +++ b/default.nix @@ -56,6 +56,6 @@ drv = pkgs.haskellPackages.developPackage { }; in drv.overrideAttrs(old: - { WASM_SPEC_TESTS_MVP = "${spec-tests-mvp}"; - WASM_SPEC_TESTS = "${spec-tests}"; + { WASM_SPEC_TESTS_MVP = spec-tests-mvp; + WASM_SPEC_TESTS = spec-tests; }) From 5373bf27a9b694b2e5803e3aac67f7368c499314 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 20 Dec 2021 14:06:13 +0100 Subject: [PATCH 37/40] simplify --- src/Wasm/Binary/Encode.hs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Wasm/Binary/Encode.hs b/src/Wasm/Binary/Encode.hs index 1fa26ea..c702452 100644 --- a/src/Wasm/Binary/Encode.hs +++ b/src/Wasm/Binary/Encode.hs @@ -385,14 +385,9 @@ putInstr = flip (.) unFix $ \case putWord8 0x40 putWord8 0x00 MemoryFill -> do - putWord8 0xFC - putWord8 0x0B - putWord8 0x00 + mapM_ putWord8 [0xFC, 0x0B, 0x00] MemoryCopy -> do - putWord8 0xFC - putWord8 0x0A - putWord8 0x00 - putWord8 0x00 + mapM_ putWord8 [0xFC, 0x0A, 0x00, 0x00] -- Constants. Const (value -> I32 val) -> do From 4817a69f1f37b21f3928fbc1ac0f1741f65f26ff Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 20 Dec 2021 19:11:07 +0100 Subject: [PATCH 38/40] repair the problem which happened with `elem.wast` (from MVP) when adding `--enable-bulk-memory` by making it possible to pass language flags per suite --- test/Main.hs | 5 ++--- test/Spec.hs | 6 +++--- test/Wat2Wasm.hs | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/test/Main.hs b/test/Main.hs index b0695c3..d4e2233 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -31,7 +31,6 @@ main = do -- We aren't going to bother fully supporting -- Unicode function names in the reference interpreter yet. , "names.wast" - , "elem.wast" ] ] @@ -75,6 +74,6 @@ main = do defaultMain $ testGroup "main" [ Property.tests , Unit.tests - , Spec.tests "spec MVP" wastFilesMVP - , Spec.tests "spec" wastFiles + , Spec.tests [] "spec MVP" wastFilesMVP + , Spec.tests ["--enable-bulk-memory"] "spec" wastFiles ] diff --git a/test/Spec.hs b/test/Spec.hs index e6567c9..b64fb80 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -17,8 +17,8 @@ import Wasm.Util.Float (floatToBits, doubleToBits) import SpecTest (spectest) import Wat2Wasm (wat2Wasm) -tests :: String -> [FilePath] -> TestTree -tests name files = testGroup name $ map prep files +tests :: [String] -> String -> [FilePath] -> TestTree +tests languageFlags name files = testGroup name $ map prep files where prep file = testCaseSteps file $ \step -> do input <- Prelude.readFile file @@ -26,7 +26,7 @@ tests name files = testGroup name $ map prep files parseWastFile @(Winter Phrase) @IO file input (M.singleton "spectest" 1) (IM.singleton 1 inst) - wat2Wasm step valListEq assertFailure + (wat2Wasm languageFlags) step valListEq assertFailure valListEq :: [Value] -> [Value] -> Bool valListEq vs1 vs2 = diff --git a/test/Wat2Wasm.hs b/test/Wat2Wasm.hs index cab28f7..25aea0c 100644 --- a/test/Wat2Wasm.hs +++ b/test/Wat2Wasm.hs @@ -7,18 +7,18 @@ import System.Exit import System.IO.Temp import System.Process -wat2Wasm :: String -> IO ByteString -wat2Wasm contents = do +wat2Wasm :: [String] -> String -> IO ByteString +wat2Wasm languageFlags contents = do wat <- emptyTempFile "." "test.wat" wasm <- emptyTempFile "." "test.wasm" writeFile wat contents (exit, _out, err) <- - readProcessWithExitCode "wat2wasm" [wat, "--enable-bulk-memory", "-o", wasm] "" + readProcessWithExitCode "wat2wasm" (wat : languageFlags <> ["-o", wasm]) "" case exit of - ExitSuccess -> do + ExitSuccess -> do res <- BL.readFile wasm removeFile wat removeFile wasm - return res + pure res ExitFailure _ -> fail err From 220b7ee600fb739c033ceef6ad24d0642019fe49 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 20 Dec 2021 19:16:53 +0100 Subject: [PATCH 39/40] bump version --- winter.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winter.cabal b/winter.cabal index 8dc77de..9756aa0 100644 --- a/winter.cabal +++ b/winter.cabal @@ -1,10 +1,10 @@ Cabal-Version: 2.2 Name: winter -Version: 1.0.0 +Version: 1.1.0 Synopsis: Haskell port of the WebAssembly OCaml reference interpreter License: MIT License-file: LICENSE -Copyright: 2018-2019 DFINITY Stiftung +Copyright: 2018-2021 DFINITY Stiftung Author: Enzo Haussecker , John Wiegley Maintainer: Enzo Haussecker , John Wiegley Stability: Experimental From 618f679c7d8f9584a902081701b96edb34183f2d Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 21 Dec 2021 01:12:47 +0100 Subject: [PATCH 40/40] update URLs --- winter.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winter.cabal b/winter.cabal index 9756aa0..8b37619 100644 --- a/winter.cabal +++ b/winter.cabal @@ -9,8 +9,8 @@ Author: Enzo Haussecker , John Wiegley , John Wiegley Stability: Experimental Category: Interpreter -Homepage: https://github.com/dfinity/winter -Bug-Reports: https://github.com/dfinity/winter/issues +Homepage: https://github.com/dfinity-side-projects/winter +Bug-Reports: https://github.com/dfinity-side-projects/winter/issues Build-Type: Simple Common generic