Home | History | Annotate | Download | only in cgo
      1 // Copyright 2011 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 cgo
      6 
      7 import "unsafe"
      8 
      9 // These utility functions are available to be called from code
     10 // compiled with gcc via crosscall2.
     11 
     12 // cgocallback is defined in runtime
     13 //go:linkname _runtime_cgocallback runtime.cgocallback
     14 func _runtime_cgocallback(unsafe.Pointer, unsafe.Pointer, uintptr)
     15 
     16 // The declaration of crosscall2 is:
     17 //   void crosscall2(void (*fn)(void *, int), void *, int);
     18 //
     19 // We need to export the symbol crosscall2 in order to support
     20 // callbacks from shared libraries. This applies regardless of
     21 // linking mode.
     22 //go:cgo_export_static crosscall2
     23 //go:cgo_export_dynamic crosscall2
     24 
     25 // Panic.  The argument is converted into a Go string.
     26 
     27 // Call like this in code compiled with gcc:
     28 //   struct { const char *p; } a;
     29 //   a.p = /* string to pass to panic */;
     30 //   crosscall2(_cgo_panic, &a, sizeof a);
     31 //   /* The function call will not return.  */
     32 
     33 //go:linkname _runtime_cgo_panic_internal runtime._cgo_panic_internal
     34 var _runtime_cgo_panic_internal byte
     35 
     36 //go:linkname _cgo_panic _cgo_panic
     37 //go:cgo_export_static _cgo_panic
     38 //go:cgo_export_dynamic _cgo_panic
     39 //go:nosplit
     40 //go:norace
     41 func _cgo_panic(a unsafe.Pointer, n int32) {
     42 	_runtime_cgocallback(unsafe.Pointer(&_runtime_cgo_panic_internal), a, uintptr(n))
     43 }
     44 
     45 //go:cgo_import_static x_cgo_init
     46 //go:linkname x_cgo_init x_cgo_init
     47 //go:linkname _cgo_init _cgo_init
     48 var x_cgo_init byte
     49 var _cgo_init = &x_cgo_init
     50 
     51 //go:cgo_import_static x_cgo_malloc
     52 //go:linkname x_cgo_malloc x_cgo_malloc
     53 //go:linkname _cgo_malloc _cgo_malloc
     54 var x_cgo_malloc byte
     55 var _cgo_malloc = &x_cgo_malloc
     56 
     57 //go:cgo_import_static x_cgo_free
     58 //go:linkname x_cgo_free x_cgo_free
     59 //go:linkname _cgo_free _cgo_free
     60 var x_cgo_free byte
     61 var _cgo_free = &x_cgo_free
     62 
     63 //go:cgo_import_static x_cgo_thread_start
     64 //go:linkname x_cgo_thread_start x_cgo_thread_start
     65 //go:linkname _cgo_thread_start _cgo_thread_start
     66 var x_cgo_thread_start byte
     67 var _cgo_thread_start = &x_cgo_thread_start
     68 
     69 // Creates a new system thread without updating any Go state.
     70 //
     71 // This method is invoked during shared library loading to create a new OS
     72 // thread to perform the runtime initialization.  This method is similar to
     73 // _cgo_sys_thread_start except that it doesn't update any Go state.
     74 
     75 //go:cgo_import_static x_cgo_sys_thread_create
     76 //go:linkname x_cgo_sys_thread_create x_cgo_sys_thread_create
     77 //go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
     78 var x_cgo_sys_thread_create byte
     79 var _cgo_sys_thread_create = &x_cgo_sys_thread_create
     80 
     81 // Notifies that the runtime has been intialized.
     82 //
     83 // We currently block at every CGO entry point (via _cgo_wait_runtime_init_done)
     84 // to ensure that the runtime has been initialized before the CGO call is
     85 // executed.  This is necessary for shared libraries where we kickoff runtime
     86 // initialization in a separate thread and return without waiting for this
     87 // thread to complete the init.
     88 
     89 //go:cgo_import_static x_cgo_notify_runtime_init_done
     90 //go:linkname x_cgo_notify_runtime_init_done x_cgo_notify_runtime_init_done
     91 //go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
     92 var x_cgo_notify_runtime_init_done byte
     93 var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done
     94 
     95 //go:cgo_export_static _cgo_topofstack
     96 //go:cgo_export_dynamic _cgo_topofstack
     97