Source file src/runtime/mem_wasmx.go

     1  // Copyright 2023 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  //go:build wasm || wasm32
     6  
     7  package runtime
     8  
     9  import "unsafe"
    10  
    11  func sbrk(n uintptr) unsafe.Pointer {
    12  	bl := bloc
    13  	if n > ^uintptr(0)-(physPageSize-1) {
    14  		return nil
    15  	}
    16  	n = memRound(n)
    17  	if n > ^uintptr(0)-bl {
    18  		return nil
    19  	}
    20  	if bl+n > blocMax {
    21  		grow := (bl + n - blocMax) / physPageSize
    22  		size := growMemory(int32(grow))
    23  		if size < 0 {
    24  			return nil
    25  		}
    26  		resetMemoryDataView()
    27  		blocMax = bl + n
    28  	}
    29  	bloc += n
    30  	return unsafe.Pointer(bl)
    31  }
    32  
    33  // Implemented in src/runtime/sys_wasm.s and src/runtime/sys_wasm32.s.
    34  func growMemory(pages int32) int32
    35  
    36  // Implemented in src/runtime/sys_wasmx.s.
    37  func currentMemory() int32
    38  

View as plain text