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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build wasm && js
     5  
     6  package sbrkalloc
     7  
     8  import (
     9  	"github.com/primecitizens/pcz/std/core/abi"
    10  	"github.com/primecitizens/pcz/std/core/alloc/sbrkalloc/bindings"
    11  )
    12  
    13  func init() {
    14  	// web browsers provides a default 16MB memry, not matching
    15  	// the actual size of the wasm blob.
    16  	for i, iter := 0, abi.ModuleIter(0); ; i++ {
    17  		md, ok := iter.Nth(i)
    18  		if !ok {
    19  			break
    20  		}
    21  
    22  		if md.HasMain == 1 {
    23  			_start = md.End
    24  			break
    25  		}
    26  	}
    27  
    28  	if _start == 0 {
    29  		_start = uintptr(Sbrk(0))
    30  		base = _start
    31  		end = _start
    32  	} else {
    33  		base = _start
    34  		end = uintptr(Sbrk(0))
    35  	}
    36  
    37  	lastFree = nil
    38  }
    39  
    40  func resetMemoryDataView() {
    41  	bindings.ResetMemoryDataView()
    42  }