@@ -13,43 +13,52 @@ extern "C" {
1313/// Corresponding intrinsic to wasm's [`memory.size` instruction][instr]
1414///
1515/// This function, when called, will return the current memory size in units of
16- /// pages.
16+ /// pages. The current WebAssembly page size is 65536 bytes (64 KB).
1717///
1818/// The argument `mem` is the numerical index of which memory to return the
19- /// size of. Note that currently wasm only supports one memory, so specifying
20- /// a nonzero value will likely result in a runtime validation error of the
21- /// wasm module.
19+ /// size of. Note that currently the WebAssembly specification only supports one
20+ /// memory, so it is required that zero is passed in. The argument is present to
21+ /// be forward-compatible with future WebAssembly revisions. If a nonzero
22+ /// argument is passed to this function it will currently unconditionally abort.
2223///
23- /// [instr]: https ://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
24+ /// [instr]: http ://webassembly. github.io/spec/core/exec/instructions.html#exec-memory-size
2425#[ inline]
2526#[ cfg_attr( test, assert_instr( "memory.size" , mem = 0 ) ) ]
2627#[ rustc_args_required_const( 0 ) ]
27- pub unsafe fn size ( mem : i32 ) -> i32 {
28- if mem != 0 {
29- :: intrinsics:: abort ( ) ;
28+ #[ stable( feature = "simd_wasm32" , since = "1.33.0" ) ]
29+ pub fn memory_size ( mem : u32 ) -> usize {
30+ unsafe {
31+ if mem != 0 {
32+ :: intrinsics:: abort ( ) ;
33+ }
34+ llvm_memory_size ( 0 ) as usize
3035 }
31- llvm_memory_size ( 0 )
3236}
3337
3438/// Corresponding intrinsic to wasm's [`memory.grow` instruction][instr]
3539///
3640/// This function, when called, will attempt to grow the default linear memory
37- /// by the specified `delta` of pages. If memory is successfully grown then the
38- /// previous size of memory, in pages, is returned. If memory cannot be grown
39- /// then -1 is returned.
41+ /// by the specified `delta` of pages. The current WebAssembly page size is
42+ /// 65536 bytes (64 KB). If memory is successfully grown then the previous size
43+ /// of memory, in pages, is returned. If memory cannot be grown then
44+ /// `usize::max_value()` is returned.
4045///
4146/// The argument `mem` is the numerical index of which memory to return the
42- /// size of. Note that currently wasm only supports one memory, so specifying
43- /// a nonzero value will likely result in a runtime validation error of the
44- /// wasm module.
47+ /// size of. Note that currently the WebAssembly specification only supports one
48+ /// memory, so it is required that zero is passed in. The argument is present to
49+ /// be forward-compatible with future WebAssembly revisions. If a nonzero
50+ /// argument is passed to this function it will currently unconditionally abort.
4551///
46- /// [instr]: https ://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
52+ /// [instr]: http ://webassembly. github.io/spec/core/exec/instructions.html#exec-memory-grow
4753#[ inline]
4854#[ cfg_attr( test, assert_instr( "memory.grow" , mem = 0 ) ) ]
4955#[ rustc_args_required_const( 0 ) ]
50- pub unsafe fn grow ( mem : i32 , delta : i32 ) -> i32 {
51- if mem != 0 {
52- :: intrinsics:: abort ( ) ;
56+ #[ stable( feature = "simd_wasm32" , since = "1.33.0" ) ]
57+ pub fn memory_grow ( mem : u32 , delta : usize ) -> usize {
58+ unsafe {
59+ if mem != 0 {
60+ :: intrinsics:: abort ( ) ;
61+ }
62+ llvm_memory_grow ( 0 , delta as i32 ) as isize as usize
5363 }
54- llvm_memory_grow ( 0 , delta)
5564}
0 commit comments