diff --git a/ml-proto/README.md b/ml-proto/README.md index 3e3c5b3190..310c06cf78 100644 --- a/ml-proto/README.md +++ b/ml-proto/README.md @@ -141,7 +141,6 @@ expr: ( . ) ( . ) ( ./ ) - ( page_size ) ( memory_size ) ( grow_memory ) diff --git a/ml-proto/host/lexer.mll b/ml-proto/host/lexer.mll index 57ae850f7c..1c141b63d0 100644 --- a/ml-proto/host/lexer.mll +++ b/ml-proto/host/lexer.mll @@ -243,7 +243,6 @@ rule token = parse | (fxx as t)".select" { SELECT ( floatop t Float32Op.Select Float64Op.Select) } | "unreachable" { UNREACHABLE } - | "page_size" { PAGE_SIZE } | "memory_size" { MEMORY_SIZE } | "grow_memory" { GROW_MEMORY } | "has_feature" { HAS_FEATURE } diff --git a/ml-proto/host/params.ml b/ml-proto/host/params.ml index 689dfbaa63..29fef66622 100644 --- a/ml-proto/host/params.ml +++ b/ml-proto/host/params.ml @@ -1,5 +1,3 @@ -let page_size = 4096L - let has_feature = fun str -> match str with (* We always support this feature :-). *) | "wasm" -> true diff --git a/ml-proto/host/parser.mly b/ml-proto/host/parser.mly index 8d8ec1c134..2f6fe4f979 100644 --- a/ml-proto/host/parser.mly +++ b/ml-proto/host/parser.mly @@ -165,7 +165,7 @@ let implicit_decl c t at = %token CONST UNARY BINARY COMPARE CONVERT %token FUNC TYPE PARAM RESULT LOCAL %token MODULE MEMORY SEGMENT IMPORT EXPORT TABLE -%token UNREACHABLE PAGE_SIZE MEMORY_SIZE GROW_MEMORY HAS_FEATURE +%token UNREACHABLE MEMORY_SIZE GROW_MEMORY HAS_FEATURE %token ASSERT_INVALID ASSERT_RETURN ASSERT_RETURN_NAN ASSERT_TRAP INVOKE %token EOF @@ -293,7 +293,6 @@ expr1 : | COMPARE expr expr { fun c -> compare ($1, $2 c, $3 c) } | CONVERT expr { fun c -> convert ($1, $2 c) } | UNREACHABLE { fun c -> unreachable } - | PAGE_SIZE { fun c -> host (PageSize, []) } | MEMORY_SIZE { fun c -> host (MemorySize, []) } | GROW_MEMORY expr { fun c -> host (GrowMemory, [$2 c]) } | HAS_FEATURE TEXT { fun c -> host (HasFeature $2, []) } diff --git a/ml-proto/host/script.ml b/ml-proto/host/script.ml index 4a8b80f204..cc71f2830a 100644 --- a/ml-proto/host/script.ml +++ b/ml-proto/host/script.ml @@ -48,7 +48,6 @@ let run_command cmd = trace "Initializing..."; let imports = Builtins.match_imports m in let host_params = { - Eval.page_size = Params.page_size; Eval.has_feature = Params.has_feature } in current_module := Some (Eval.init m imports host_params) diff --git a/ml-proto/spec/ast.ml b/ml-proto/spec/ast.ml index 72f56ee085..61d79ebe39 100644 --- a/ml-proto/spec/ast.ml +++ b/ml-proto/spec/ast.ml @@ -69,7 +69,6 @@ type memop = {ty : value_type; offset : Memory.offset; align : int option} type extop = {memop : memop; sz : Memory.mem_size; ext : Memory.extension} type wrapop = {memop : memop; sz : Memory.mem_size} type hostop = - | PageSize (* inquire host-defined page size *) | MemorySize (* inquire current size of linear memory *) | GrowMemory (* grow linear memory *) | HasFeature of string (* test for feature availability *) diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index 0dc2e29ddb..26e919f5f2 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -96,7 +96,6 @@ let type_cvt at = function * present in the module. *) let type_hostop = function - | PageSize -> ({ins = []; out = Some Int32Type}, true) | MemorySize -> ({ins = []; out = Some Int32Type}, true) | GrowMemory -> ({ins = [Int32Type]; out = None}, true) | HasFeature str -> ({ins = []; out = Some Int32Type}, false) diff --git a/ml-proto/spec/eval.ml b/ml-proto/spec/eval.ml index ebf43e3e74..3d8a3dd839 100644 --- a/ml-proto/spec/eval.ml +++ b/ml-proto/spec/eval.ml @@ -13,7 +13,6 @@ open Source type value = Values.value type import = value list -> value option type host_params = { - page_size : Memory.size; has_feature : string -> bool } @@ -280,10 +279,6 @@ and coerce et vo = and eval_hostop c hostop vs at = let host = c.instance.host in match hostop, vs with - | PageSize, [] -> - assert (I64.lt_u host.page_size (Int64.of_int32 Int32.max_int)); - Some (Int32 (Int64.to_int32 host.page_size)) - | MemorySize, [] -> let mem = memory c at in assert (I64.lt_u (Memory.size mem) (Int64.of_int32 Int32.max_int)); @@ -292,7 +287,7 @@ and eval_hostop c hostop vs at = | GrowMemory, [v] -> let mem = memory c at in let delta = address32 v at in - if I64.rem_u delta host.page_size <> 0L then + if I64.rem_u delta Memory.page_size <> 0L then Trap.error at "growing memory by non-multiple of page size"; let new_size = Int64.add (Memory.size mem) delta in if I64.lt_u new_size (Memory.size mem) then @@ -323,8 +318,6 @@ let add_export funcs ex = let init m imports host = assert (List.length imports = List.length m.it.Ast.imports); - assert (host.page_size > 0L); - assert (Lib.Int64.is_power_of_two host.page_size); let {memory; funcs; exports; _} = m.it in {module_ = m; imports; diff --git a/ml-proto/spec/eval.mli b/ml-proto/spec/eval.mli index 5ea292f0e6..71c4905757 100644 --- a/ml-proto/spec/eval.mli +++ b/ml-proto/spec/eval.mli @@ -6,7 +6,6 @@ type instance type value = Values.value type import = value list -> value option type host_params = { - page_size : Memory.size; has_feature : string -> bool } diff --git a/ml-proto/spec/memory.ml b/ml-proto/spec/memory.ml index 9f70257c0c..a6f31231eb 100644 --- a/ml-proto/spec/memory.ml +++ b/ml-proto/spec/memory.ml @@ -23,6 +23,7 @@ exception Type exception Bounds exception SizeOverflow +let page_size = 0x10000L (* 64 KiB *) (* * These limitations should be considered part of the host environment and not diff --git a/ml-proto/spec/memory.mli b/ml-proto/spec/memory.mli index d7595cebdf..0130d90205 100644 --- a/ml-proto/spec/memory.mli +++ b/ml-proto/spec/memory.mli @@ -17,6 +17,8 @@ exception Type exception Bounds exception SizeOverflow +val page_size : size + val create : size -> memory val init : memory -> segment list -> unit val size : memory -> size diff --git a/ml-proto/test/memory_trap.wast b/ml-proto/test/memory_trap.wast index e28321c7d3..d8e020b631 100644 --- a/ml-proto/test/memory_trap.wast +++ b/ml-proto/test/memory_trap.wast @@ -12,7 +12,7 @@ (export "overflow_memory_size" $overflow_memory_size) (func $overflow_memory_size - (grow_memory (i32.xor (i32.const -1) (i32.sub (page_size) (i32.const 1)))) + (grow_memory (i32.xor (i32.const -1) (i32.sub (i32.const 0x10000) (i32.const 1)))) ) ) diff --git a/ml-proto/test/resizing.wast b/ml-proto/test/resizing.wast index b93a51a781..52cf9f17ee 100644 --- a/ml-proto/test/resizing.wast +++ b/ml-proto/test/resizing.wast @@ -1,15 +1,10 @@ (module (memory 0) - - (export "power_of_two" $power_of_two) - (func $power_of_two (result i32) - (i32.popcnt (page_size)) - ) (export "round_up_to_page" $round_up_to_page) (func $round_up_to_page (param i32) (result i32) - (i32.and (i32.add (get_local 0) (i32.sub (page_size) (i32.const 1))) - (i32.sub (i32.const 0) (page_size))) + (i32.and (i32.add (get_local 0) (i32.const 0xFFFF)) + (i32.const 0xFFFF0000)) ) (export "load_at_zero" $load_at_zero) @@ -19,10 +14,10 @@ (func $store_at_zero (result i32) (i32.store (i32.const 0) (i32.const 2))) (export "load_at_page_size" $load_at_page_size) - (func $load_at_page_size (result i32) (i32.load (page_size))) + (func $load_at_page_size (result i32) (i32.load (i32.const 0x10000))) (export "store_at_page_size" $store_at_page_size) - (func $store_at_page_size (result i32) (i32.store (page_size) (i32.const 3))) + (func $store_at_page_size (result i32) (i32.store (i32.const 0x10000) (i32.const 3))) (export "grow" $grow) (func $grow (param $sz i32) @@ -36,7 +31,6 @@ (func $size (result i32) (memory_size)) ) -(assert_return (invoke "power_of_two") (i32.const 1)) (assert_return (invoke "size") (i32.const 0)) (assert_return (invoke "size_at_least" (i32.const 0)) (i32.const 1)) (assert_trap (invoke "store_at_zero") "out of bounds memory access")