Source file test/wasm32memlimit.dir/main.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  func currentMemory() int32
     8  func growMemory(pages int32) int32
     9  
    10  func main() {
    11  	// -T sets the first logical PC to 4 MiB. Use a small limit so
    12  	// the test can grow memory to the boundary.
    13  	const limit = 0x400000 / (64 << 10)
    14  	initial := currentMemory()
    15  	if initial == 0 || initial >= limit {
    16  		panic("unexpected initial memory size")
    17  	}
    18  	if growMemory(limit-initial+1) != -1 || currentMemory() != initial {
    19  		panic("memory grew past the logical PC range")
    20  	}
    21  	if growMemory(limit-initial) != initial || currentMemory() != limit {
    22  		panic("memory did not grow to the logical PC range")
    23  	}
    24  	if growMemory(1) != -1 || currentMemory() != limit {
    25  		panic("memory grew into the logical PC range")
    26  	}
    27  }
    28  

View as plain text