Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ let limits uN s =
let max = opt uN has_max s in
at, {min; max}

let memorylimits uN s =
let flags = byte s in
require (flags land 0xf2 = 0) s (pos s - 1) "malformed limits flags";
let has_max = (flags land 1 = 1) in
let at = if flags land 4 = 4 then I64AT else I32AT in
let has_paget = (flags land 8 = 8) in
let min = uN s in
let max = opt uN has_max s in
let ps = if has_paget then Int32.to_int(u32 s) else 16 in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I notice the cast, I think PageT should carry an int32. The abstract syntax usually tries to reflect value ranges as precisely as it can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's getting to be annoying. Given that it's a log representation now, should we use something even tighter, like a byte (even though it's encoded as an LEB)?

at, {min; max}, (PageT ps)

let tagtype s =
zero s;
TagT (typeuse idx s)
Expand All @@ -295,8 +306,8 @@ let globaltype s =
GlobalT (mut, t)

let memorytype s =
let at, lim = limits u64 s in
MemoryT (at, lim, PageT 16) (* TODO(custom-page-sizes) *)
let at, lim, pt = memorylimits u64 s in
MemoryT (at, lim, pt)

let tabletype s =
let t = reftype s in
Expand Down
7 changes: 6 additions & 1 deletion interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,19 @@ struct
let flags = flag (max <> None) 0 + flag (at = I64AT) 2 in
byte flags; u64 min; opt u64 max

let memorylimits at {min; max} (PageT ps) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: Symmetrically here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't quite understand what this comment means.

let flags = flag (max <> None) 0 + flag (at = I64AT) 2 + flag (ps <> 16) 3 in
let ps_opt = if ps <> 16 then Some (Int32.of_int ps) else None in
byte flags; u64 min; opt u64 max; opt u32 ps_opt

let tagtype = function
| TagT ut -> u32 0x00l; typeuse u32 ut

let globaltype = function
| GlobalT (mut, t) -> valtype t; mutability mut

let memorytype = function
| MemoryT (at, lim, pt) -> limits at lim (* TODO(custom-page-sizes) *)
| MemoryT (at, lim, pt) -> memorylimits at lim pt

let tabletype = function
| TableT (at, lim, t) -> reftype t; limits at lim
Expand Down
2 changes: 1 addition & 1 deletion test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
(module binary
"\00asm" "\01\00\00\00"
"\05\02\01" ;; memory section with one entry
"\08" ;; malformed memory limits flag
"\10" ;; malformed memory limits flag
)
"malformed limits flags"
)
Expand Down
6 changes: 3 additions & 3 deletions test/core/custom-page-sizes/custom-page-sizes-invalid.wast
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

;; Power of two page size that cannot fit in a u64 to exercise checks against
;; shift overflow.
(assert_malformed
(assert_invalid
(module binary
"\00asm" "\01\00\00\00"
"\05\04\01" ;; Memory section
Expand All @@ -104,12 +104,12 @@
(module
(memory (import "m" "small-pages-memory") 0 (pagesize 65536))
)
"memory types incompatible"
"incompatible import type"
)

(assert_unlinkable
(module
(memory (import "m" "large-pages-memory") 0 (pagesize 1))
)
"memory types incompatible"
"incompatible import type"
)
Loading