| 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 |
// The declaration of crosscall2 is: |
| 13 |
// void crosscall2(void (*fn)(void *), void *, int); |
| 14 |
// |
| 15 |
// We need to export the symbol crosscall2 in order to support |
| 16 |
// callbacks from shared libraries. This applies regardless of |
| 17 |
// linking mode. |
| 18 |
// |
| 19 |
// Compatibility note: SWIG uses crosscall2 in exactly one situation: |
| 20 |
// to call _cgo_panic using the pattern shown below. We need to keep |
| 21 |
// that pattern working. In particular, crosscall2 actually takes four |
| 22 |
// arguments, but it works to call it with three arguments when |
| 23 |
// calling _cgo_panic. |
| 24 |
// |
| 25 |
//go:cgo_export_static crosscall2 |
| 26 |
//go:cgo_export_dynamic crosscall2 |
| 27 |
|
| 28 |
// Panic. The argument is converted into a Go string. |
| 29 |
|
| 30 |
// Call like this in code compiled with gcc: |
| 31 |
// struct { const char *p; } a; |
| 32 |
// a.p = /* string to pass to panic */; |
| 33 |
// crosscall2(_cgo_panic, &a, sizeof a); |
| 34 |
// /* The function call will not return. */ |
| 35 |
|
| 36 |
// TODO: We should export a regular C function to panic, change SWIG |
| 37 |
// to use that instead of the above pattern, and then we can drop |
| 38 |
// backwards-compatibility from crosscall2 and stop exporting it. |
| 39 |
|
| 40 |
//go:linkname _runtime_cgo_panic_internal runtime._cgo_panic_internal |
| 41 |
func _runtime_cgo_panic_internal(p *byte) |
| 42 |
|
| 43 |
//go:linkname _cgo_panic _cgo_panic |
| 44 |
//go:cgo_export_static _cgo_panic |
| 45 |
//go:cgo_export_dynamic _cgo_panic |
| 46 |
func _cgo_panic(a *struct{ cstr *byte }) { |
| 47 |
_runtime_cgo_panic_internal(a.cstr) |
| 48 |
} |
| 49 |
|
| 50 |
//go:cgo_import_static x_cgo_init |
| 51 |
//go:linkname x_cgo_init x_cgo_init |
| 52 |
//go:linkname _cgo_init _cgo_init |
| 53 |
var x_cgo_init byte |
| 54 |
var _cgo_init = &x_cgo_init |
| 55 |
|
| 56 |
//go:cgo_import_static x_cgo_thread_start |
| 57 |
//go:linkname x_cgo_thread_start x_cgo_thread_start |
| 58 |
//go:linkname _cgo_thread_start _cgo_thread_start |
| 59 |
var x_cgo_thread_start byte |
| 60 |
var _cgo_thread_start = &x_cgo_thread_start |
| 61 |
|
| 62 |
// Creates a new system thread without updating any Go state. |
| 63 |
// |
| 64 |
// This method is invoked during shared library loading to create a new OS |
| 65 |
// thread to perform the runtime initialization. This method is similar to |
| 66 |
// _cgo_sys_thread_start except that it doesn't update any Go state. |
| 67 |
|
| 68 |
//go:cgo_import_static x_cgo_sys_thread_create |
| 69 |
//go:linkname x_cgo_sys_thread_create x_cgo_sys_thread_create |
| 70 |
//go:linkname _cgo_sys_thread_create _cgo_sys_thread_create |
| 71 |
var x_cgo_sys_thread_create byte |
| 72 |
var _cgo_sys_thread_create = &x_cgo_sys_thread_create |
| 73 |
|
| 74 |
// Indicates whether a dummy thread key has been created or not. |
| 75 |
// |
| 76 |
// When calling go exported function from C, we register a destructor |
| 77 |
// callback, for a dummy thread key, by using pthread_key_create. |
| 78 |
|
| 79 |
//go:cgo_import_static x_cgo_pthread_key_created |
| 80 |
//go:linkname x_cgo_pthread_key_created x_cgo_pthread_key_created |
| 81 |
//go:linkname _cgo_pthread_key_created _cgo_pthread_key_created |
| 82 |
var x_cgo_pthread_key_created byte |
| 83 |
var _cgo_pthread_key_created = &x_cgo_pthread_key_created |
| 84 |
|
| 85 |
// Export crosscall2 to a c function pointer variable. |
| 86 |
// Used to dropm in pthread key destructor, while C thread is exiting. |
| 87 |
|
| 88 |
//go:cgo_import_static x_crosscall2_ptr |
| 89 |
//go:linkname x_crosscall2_ptr x_crosscall2_ptr |
| 90 |
//go:linkname _crosscall2_ptr _crosscall2_ptr |
| 91 |
var x_crosscall2_ptr byte |
| 92 |
var _crosscall2_ptr = &x_crosscall2_ptr |
| 93 |
|
| 94 |
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2. |
| 95 |
// It's for the runtime package to call at init time. |
| 96 |
func set_crosscall2() |
| 97 |
|
| 98 |
//go:linkname _set_crosscall2 runtime.set_crosscall2 |
| 99 |
var _set_crosscall2 = set_crosscall2 |
| 100 |
|
| 101 |
// Store the g into the thread-specific value. |
| 102 |
// So that pthread_key_destructor will dropm when the thread is exiting. |
| 103 |
|
| 104 |
//go:cgo_import_static x_cgo_bindm |
| 105 |
//go:linkname x_cgo_bindm x_cgo_bindm |
| 106 |
//go:linkname _cgo_bindm _cgo_bindm |
| 107 |
var x_cgo_bindm byte |
| 108 |
var _cgo_bindm = &x_cgo_bindm |
| 109 |
|
| 110 |
// Notifies that the runtime has been initialized. |
| 111 |
// |
| 112 |
// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done) |
| 113 |
// to ensure that the runtime has been initialized before the CGO call is |
| 114 |
// executed. This is necessary for shared libraries where we kickoff runtime |
| 115 |
// initialization in a separate thread and return without waiting for this |
| 116 |
// thread to complete the init. |
| 117 |
|
| 118 |
//go:cgo_import_static x_cgo_notify_runtime_init_done |
| 119 |
//go:linkname x_cgo_notify_runtime_init_done x_cgo_notify_runtime_init_done |
| 120 |
//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done |
| 121 |
var x_cgo_notify_runtime_init_done byte |
| 122 |
var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done |
| 123 |
|
| 124 |
// Sets the traceback, context, and symbolizer functions. See |
| 125 |
// runtime.SetCgoTraceback. |
| 126 |
|
| 127 |
//go:cgo_import_static x_cgo_set_traceback_functions |
| 128 |
//go:linkname x_cgo_set_traceback_functions x_cgo_set_traceback_functions |
| 129 |
//go:linkname _cgo_set_traceback_functions _cgo_set_traceback_functions |
| 130 |
var x_cgo_set_traceback_functions byte |
| 131 |
var _cgo_set_traceback_functions = &x_cgo_set_traceback_functions |
| 132 |
|
| 133 |
// Call the traceback function registered with x_cgo_set_traceback_functions. |
| 134 |
|
| 135 |
//go:cgo_import_static x_cgo_call_traceback_function |
| 136 |
//go:linkname x_cgo_call_traceback_function x_cgo_call_traceback_function |
| 137 |
//go:linkname _cgo_call_traceback_function _cgo_call_traceback_function |
| 138 |
var x_cgo_call_traceback_function byte |
| 139 |
var _cgo_call_traceback_function = &x_cgo_call_traceback_function |
| 140 |
|
| 141 |
// Call the symbolizer function registered with x_cgo_set_symbolizer_functions. |
| 142 |
|
| 143 |
//go:cgo_import_static x_cgo_call_symbolizer_function |
| 144 |
//go:linkname x_cgo_call_symbolizer_function x_cgo_call_symbolizer_function |
| 145 |
//go:linkname _cgo_call_symbolizer_function _cgo_call_symbolizer_function |
| 146 |
var x_cgo_call_symbolizer_function byte |
| 147 |
var _cgo_call_symbolizer_function = &x_cgo_call_symbolizer_function |
| 148 |
|
| 149 |
// Calls a libc function to execute background work injected via libc |
| 150 |
// interceptors, such as processing pending signals under the thread |
| 151 |
// sanitizer. |
| 152 |
// |
| 153 |
// Left as a nil pointer if no libc interceptors are expected. |
| 154 |
|
| 155 |
//go:cgo_import_static _cgo_yield |
| 156 |
//go:linkname _cgo_yield _cgo_yield |
| 157 |
var _cgo_yield unsafe.Pointer |
| 158 |
|
| 159 |
//go:cgo_export_static _cgo_topofstack |
| 160 |
//go:cgo_export_dynamic _cgo_topofstack |
| 161 |
|
| 162 |
// x_cgo_getstackbound gets the thread's C stack size and |
| 163 |
// set the G's stack bound based on the stack size. |
| 164 |
|
| 165 |
//go:cgo_import_static x_cgo_getstackbound |
| 166 |
//go:linkname x_cgo_getstackbound x_cgo_getstackbound |
| 167 |
//go:linkname _cgo_getstackbound _cgo_getstackbound |
| 168 |
var x_cgo_getstackbound byte |
| 169 |
var _cgo_getstackbound = &x_cgo_getstackbound |