fix memory growing behavior
This commit is contained in:
@@ -794,12 +794,12 @@ eval store FunctionInstance { funcType, moduleInstance, code = Function { localT
|
|||||||
step ctx@EvalCtx{ stack = (VI32 n:rest) } GrowMemory = do
|
step ctx@EvalCtx{ stack = (VI32 n:rest) } GrowMemory = do
|
||||||
let ref = memInstances store ! (memaddrs moduleInstance ! 0)
|
let ref = memInstances store ! (memaddrs moduleInstance ! 0)
|
||||||
MemoryInstance { memory, maxLen } <- readIORef ref
|
MemoryInstance { memory, maxLen } <- readIORef ref
|
||||||
let size = fromIntegral $ IOVector.length memory `div` pageSize
|
let size = fromIntegral $ IOVector.length memory `quot` pageSize
|
||||||
let growTo = size + fromIntegral n
|
let growTo = size + fromIntegral n
|
||||||
result <- (
|
result <- (
|
||||||
if fromMaybe True ((growTo <=) <$> maxLen)
|
if fromMaybe True ((growTo <=) <$> maxLen) && growTo <= 0xFFFF
|
||||||
then do
|
then do
|
||||||
mem' <- IOVector.grow memory $ growTo * pageSize
|
mem' <- IOVector.grow memory $ fromIntegral n * pageSize
|
||||||
writeIORef ref $ MemoryInstance mem' maxLen
|
writeIORef ref $ MemoryInstance mem' maxLen
|
||||||
return size
|
return size
|
||||||
else return $ -1
|
else return $ -1
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ compile file = do
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
files <- Directory.listDirectory "tests/samples"
|
files <- Directory.listDirectory "tests/samples"
|
||||||
-- let files = ["memory.wast"]
|
-- let files = ["resizing.wast"]
|
||||||
scriptTestCases <- (`mapM` files) $ \file -> do
|
scriptTestCases <- (`mapM` files) $ \file -> do
|
||||||
content <- LBS.readFile $ "tests/samples/" ++ file
|
content <- LBS.readFile $ "tests/samples/" ++ file
|
||||||
let Right script = Parser.parseScript <$> Lexer.scanner content
|
let Right script = Parser.parseScript <$> Lexer.scanner content
|
||||||
|
|||||||
Reference in New Issue
Block a user