Home | History | Annotate | Download | only in runtime
      1 // Copyright 2014 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 package runtime
      6 
      7 import "unsafe"
      8 
      9 //go:cgo_export_static main
     10 
     11 // Filled in by runtime/cgo when linked into binary.
     12 
     13 //go:linkname _cgo_init _cgo_init
     14 //go:linkname _cgo_malloc _cgo_malloc
     15 //go:linkname _cgo_free _cgo_free
     16 //go:linkname _cgo_thread_start _cgo_thread_start
     17 //go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
     18 //go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
     19 
     20 var (
     21 	_cgo_init                     unsafe.Pointer
     22 	_cgo_malloc                   unsafe.Pointer
     23 	_cgo_free                     unsafe.Pointer
     24 	_cgo_thread_start             unsafe.Pointer
     25 	_cgo_sys_thread_create        unsafe.Pointer
     26 	_cgo_notify_runtime_init_done unsafe.Pointer
     27 )
     28 
     29 // iscgo is set to true by the runtime/cgo package
     30 var iscgo bool
     31 
     32 // cgoHasExtraM is set on startup when an extra M is created for cgo.
     33 // The extra M must be created before any C/C++ code calls cgocallback.
     34 var cgoHasExtraM bool
     35 
     36 // cgoUse is called by cgo-generated code (using go:linkname to get at
     37 // an unexported name). The calls serve two purposes:
     38 // 1) they are opaque to escape analysis, so the argument is considered to
     39 // escape to the heap.
     40 // 2) they keep the argument alive until the call site; the call is emitted after
     41 // the end of the (presumed) use of the argument by C.
     42 // cgoUse should not actually be called (see cgoAlwaysFalse).
     43 func cgoUse(interface{}) { throw("cgoUse should not be called") }
     44 
     45 // cgoAlwaysFalse is a boolean value that is always false.
     46 // The cgo-generated code says if cgoAlwaysFalse { cgoUse(p) }.
     47 // The compiler cannot see that cgoAlwaysFalse is always false,
     48 // so it emits the test and keeps the call, giving the desired
     49 // escape analysis result. The test is cheaper than the call.
     50 var cgoAlwaysFalse bool
     51