Source file src/runtime/sys_wasmx.go

     1  // Copyright 2018 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 (
    10  	"internal/goarch"
    11  	"internal/runtime/sys"
    12  	"unsafe"
    13  )
    14  
    15  type m0Stack struct {
    16  	_ [8192 * sys.StackGuardMultiplier]byte
    17  }
    18  
    19  var wasmStack m0Stack
    20  
    21  func wasmDiv()
    22  
    23  func wasmTruncS()
    24  func wasmTruncU()
    25  
    26  //go:wasmimport gojs runtime.wasmExit
    27  func wasmExit(code int32)
    28  
    29  // adjust Gobuf as it if executed a call to fn with context ctxt
    30  // and then stopped before the first instruction in fn.
    31  func gostartcall(buf *gobuf, fn, ctxt unsafe.Pointer) {
    32  	sp := buf.sp - retPCSize
    33  	pc := uint64(buf.pc)
    34  	if goarch.IsWasm32 != 0 {
    35  		pc |= uint64(buf.lr) << 32
    36  	}
    37  	*(*uint64)(unsafe.Pointer(sp)) = pc
    38  	buf.sp = sp
    39  	buf.pc = uintptr(fn)
    40  	if goarch.IsWasm32 != 0 {
    41  		buf.pc = funcValuePC(buf.pc)
    42  		buf.lr = uintptr(fn)
    43  	}
    44  	buf.ctxt = ctxt
    45  }
    46  
    47  func notInitialized() // defined in assembly, call notInitialized1
    48  
    49  // Called if a wasmexport function is called before runtime initialization
    50  //
    51  //go:nosplit
    52  func notInitialized1() {
    53  	writeErrStr("runtime: wasmexport function called before runtime initialization\n")
    54  	if isarchive || islibrary {
    55  		writeErrStr("\tcall _initialize first\n")
    56  	} else {
    57  		writeErrStr("\tcall _start first\n")
    58  	}
    59  }
    60  

View as plain text