@@ -13,43 +13,52 @@ extern "C" {
13
13
/// Corresponding intrinsic to wasm's [`memory.size` instruction][instr]
14
14
///
15
15
/// 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).
17
17
///
18
18
/// 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.
22
23
///
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
24
25
#[ inline]
25
26
#[ cfg_attr( test, assert_instr( "memory.size" , mem = 0 ) ) ]
26
27
#[ 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
30
35
}
31
- llvm_memory_size ( 0 )
32
36
}
33
37
34
38
/// Corresponding intrinsic to wasm's [`memory.grow` instruction][instr]
35
39
///
36
40
/// 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.
40
45
///
41
46
/// 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.
45
51
///
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
47
53
#[ inline]
48
54
#[ cfg_attr( test, assert_instr( "memory.grow" , mem = 0 ) ) ]
49
55
#[ 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
53
63
}
54
- llvm_memory_grow ( 0 , delta)
55
64
}
0 commit comments