@@ -104,6 +104,9 @@ let check_limits {min; max} range at msg =
104104 require (I64. le_u min max) at
105105 " size minimum must not be greater than maximum"
106106
107+ let check_pagetype (PageT ps ) at =
108+ require (ps = 0x10000 || ps = 1 ) at " page size must be 1 or 64KiB"
109+
107110let check_numtype (c : context ) (t : numtype ) at =
108111 ()
109112
@@ -196,13 +199,14 @@ let check_globaltype (c : context) (gt : globaltype) at =
196199 check_valtype c t at
197200
198201let check_memorytype (c : context ) (mt : memorytype ) at =
199- let MemoryT (at_, lim) = mt in
202+ let MemoryT (at_, lim, pt ) = mt in
200203 let sz, s =
201204 match at_ with
202205 | I32AT -> 0x1_0000L , " 2^16 pages (4 GiB) for i32"
203206 | I64AT -> 0x1_0000_0000_0000L , " 2^48 pages (256 TiB) for i64"
204207 in
205- check_limits lim sz at (" memory size must be at most " ^ s)
208+ check_limits lim sz at (" memory size must be at most " ^ s);
209+ check_pagetype pt at
206210
207211let check_tabletype (c : context ) (tt : tabletype ) at =
208212 let TableT (at_, lim, t) = tt in
@@ -384,7 +388,7 @@ let check_memop (c : context) (memop : ('t, 's) memop) ty_size get_sz at =
384388 in
385389 require (1 lsl memop.align > = 1 && 1 lsl memop.align < = size) at
386390 " alignment must not be larger than natural" ;
387- let MemoryT (at_, _lim) = memory c (0l @@ at) in
391+ let MemoryT (at_, _lim, _pt ) = memory c (0l @@ at) in
388392 if at_ = I32AT then
389393 require (I64. lt_u memop.offset 0x1_0000_0000L ) at
390394 " offset out of range" ;
@@ -648,60 +652,60 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
648652 [] --> [] , []
649653
650654 | Load (x , memop ) ->
651- let MemoryT (at, _lim) = memory c x in
655+ let MemoryT (at, _lim, _pt ) = memory c x in
652656 let t = check_memop c memop num_size (Lib.Option. map fst) e.at in
653657 [NumT (numtype_of_addrtype at)] --> [NumT t], []
654658
655659 | Store (x , memop ) ->
656- let MemoryT (at, _lim) = memory c x in
660+ let MemoryT (at, _lim, _pt ) = memory c x in
657661 let t = check_memop c memop num_size (fun sz -> sz) e.at in
658662 [NumT (numtype_of_addrtype at); NumT t] --> [] , []
659663
660664 | VecLoad (x , memop ) ->
661- let MemoryT (at, _lim) = memory c x in
665+ let MemoryT (at, _lim, _pt ) = memory c x in
662666 let t = check_memop c memop vec_size (Lib.Option. map fst) e.at in
663667 [NumT (numtype_of_addrtype at)] --> [VecT t], []
664668
665669 | VecStore (x , memop ) ->
666- let MemoryT (at, _lim) = memory c x in
670+ let MemoryT (at, _lim, _pt ) = memory c x in
667671 let t = check_memop c memop vec_size (fun _ -> None ) e.at in
668672 [NumT (numtype_of_addrtype at); VecT t] --> [] , []
669673
670674 | VecLoadLane (x , memop , i ) ->
671- let MemoryT (at, _lim) = memory c x in
675+ let MemoryT (at, _lim, _pt ) = memory c x in
672676 let t = check_memop c memop vec_size (fun sz -> Some sz) e.at in
673677 require (I8. to_int_u i < vec_size t / Pack. packed_size memop.pack) e.at
674678 " invalid lane index" ;
675679 [NumT (numtype_of_addrtype at); VecT t] --> [VecT t], []
676680
677681 | VecStoreLane (x , memop , i ) ->
678- let MemoryT (at, _lim) = memory c x in
682+ let MemoryT (at, _lim, _pt ) = memory c x in
679683 let t = check_memop c memop vec_size (fun sz -> Some sz) e.at in
680684 require (I8. to_int_u i < vec_size t / Pack. packed_size memop.pack) e.at
681685 " invalid lane index" ;
682686 [NumT (numtype_of_addrtype at); VecT t] --> [] , []
683687
684688 | MemorySize x ->
685- let MemoryT (at, _lim) = memory c x in
689+ let MemoryT (at, _lim, _pt ) = memory c x in
686690 [] --> [NumT (numtype_of_addrtype at)], []
687691
688692 | MemoryGrow x ->
689- let MemoryT (at, _lim) = memory c x in
693+ let MemoryT (at, _lim, _pt ) = memory c x in
690694 [NumT (numtype_of_addrtype at)] --> [NumT (numtype_of_addrtype at)], []
691695
692696 | MemoryFill x ->
693- let MemoryT (at, _lim) = memory c x in
697+ let MemoryT (at, _lim, _pt ) = memory c x in
694698 [NumT (numtype_of_addrtype at); NumT I32T ;
695699 NumT (numtype_of_addrtype at)] --> [] , []
696700
697701 | MemoryCopy (x , y )->
698- let MemoryT (at1, _lib1) = memory c x in
699- let MemoryT (at2, _lib2) = memory c y in
702+ let MemoryT (at1, _pt, _lib1) = memory c x in
703+ let MemoryT (at2, _pt, _lib2) = memory c y in
700704 [NumT (numtype_of_addrtype at1); NumT (numtype_of_addrtype at2);
701705 NumT (numtype_of_addrtype (min at1 at2))] --> [] , []
702706
703707 | MemoryInit (x , y ) ->
704- let MemoryT (at, _lib) = memory c x in
708+ let MemoryT (at, _pt, _lib) = memory c x in
705709 let () = data c y in
706710 [NumT (numtype_of_addrtype at); NumT I32T ; NumT I32T ] --> [] , []
707711
@@ -1071,7 +1075,7 @@ let check_datamode (c : context) (mode : segmentmode) =
10711075 match mode.it with
10721076 | Passive -> ()
10731077 | Active (x , offset ) ->
1074- let MemoryT (at, _) = memory c x in
1078+ let MemoryT (at, _, _ ) = memory c x in
10751079 check_const c offset (NumT (numtype_of_addrtype at))
10761080 | Declarative -> assert false
10771081
0 commit comments