github.com/moontrade/nogc@v0.1.7/alloc/tlsf/mem_tinygowasm.go (about)

     1  //go:build tinygo && tinygo.wasm
     2  // +build tinygo,tinygo.wasm
     3  
     4  package tlsf
     5  
     6  import (
     7  	"unsafe"
     8  )
     9  
    10  ////go:linkname gcMemcpy runtime.gcMemcpy
    11  //func gcMemcpy(dst, src unsafe.Pointer, n uintptr)
    12  
    13  //go:linkname Copy runtime.gcMemcpy
    14  func Copy(dst, src unsafe.Pointer, n uintptr)
    15  
    16  //go:linkname Move runtime.gcMemmove
    17  func Move(dst, src unsafe.Pointer, size uintptr)
    18  
    19  //func Memmove(dst, src unsafe.Pointer, size uintptr) {
    20  //	gcMemmove(dst, src, size)
    21  //}
    22  
    23  //go:linkname Zero runtime.gcZero
    24  func Zero(ptr unsafe.Pointer, size uintptr)
    25  
    26  //func Memzero(ptr unsafe.Pointer, size uintptr) {
    27  //	gcZero(ptr, size)
    28  //}
    29  
    30  type _bytes struct {
    31  	Data uintptr
    32  	Len  int
    33  	Cap  int
    34  }
    35  
    36  func zeroSlow(ptr unsafe.Pointer, size uintptr) {
    37  	b := *(*[]byte)(unsafe.Pointer(&_bytes{
    38  		Data: uintptr(ptr),
    39  		Len:  int(size),
    40  		Cap:  int(size),
    41  	}))
    42  	switch {
    43  	case size < 8:
    44  		for i := 0; i < len(b); i++ {
    45  			b[i] = 0
    46  		}
    47  	case size == 8:
    48  		*(*uint64)(unsafe.Pointer(&b[0])) = 0
    49  	default:
    50  		var i = 0
    51  		for ; i <= len(b)-8; i += 8 {
    52  			*(*uint64)(unsafe.Pointer(&b[i])) = 0
    53  		}
    54  		for ; i < len(b); i++ {
    55  			b[i] = 0
    56  		}
    57  	}
    58  }
    59  
    60  //go:linkname Equals runtime.gcMemequal
    61  func Equals(x, y unsafe.Pointer, size uintptr) bool