Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ expr:
( <type>.<binop> <expr> <expr> )
( <type>.<relop> <expr> <expr> )
( <type>.<cvtop>/<type> <expr> )
( page_size )
( memory_size )
( grow_memory <expr> )

Expand Down
1 change: 0 additions & 1 deletion ml-proto/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 0 additions & 2 deletions ml-proto/host/params.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
let page_size = 4096L

let has_feature = fun str -> match str with
(* We always support this feature :-). *)
| "wasm" -> true
Expand Down
3 changes: 1 addition & 2 deletions ml-proto/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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, []) }
Expand Down
1 change: 0 additions & 1 deletion ml-proto/host/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion ml-proto/spec/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
1 change: 0 additions & 1 deletion ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions ml-proto/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion ml-proto/spec/eval.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions ml-proto/spec/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ml-proto/spec/memory.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/memory_trap.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
)
)

Expand Down
14 changes: 4 additions & 10 deletions ml-proto/test/resizing.wast
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down