github.com/primecitizens/pcz/std@v0.2.1/core/alloc/sbrkalloc/sbrk_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2023 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build wasm
     9  
    10  package sbrkalloc
    11  
    12  import (
    13  	"unsafe"
    14  
    15  	"github.com/primecitizens/pcz/std/core/arch"
    16  )
    17  
    18  // Sbrk
    19  //
    20  //go:nosplit
    21  func Sbrk(size uintptr) unsafe.Pointer {
    22  	i := int32(divRoundUp(size, arch.DefaultPhysPageSize))
    23  	i = growMemory(i)
    24  	if i < 0 {
    25  		return nil
    26  	}
    27  	resetMemoryDataView()
    28  	return unsafe.Pointer(uintptr(i) * arch.DefaultPhysPageSize)
    29  }
    30  
    31  // growMemory is a simple wrapper for wasm instruction memory.grow.
    32  //
    33  // When return value >= 0, it is the previous size (in pages).
    34  func growMemory(pages int32) int32