...

Source file src/runtime/cgo/callbacks.go

     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, 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	//
    23	// Compatibility note: crosscall2 actually takes four arguments, but
    24	// it works to call it with three arguments when calling _cgo_panic.
    25	// That is supported for backward compatibility.
    26	//go:cgo_export_static crosscall2
    27	//go:cgo_export_dynamic crosscall2
    28	
    29	// Panic. The argument is converted into a Go string.
    30	
    31	// Call like this in code compiled with gcc:
    32	//   struct { const char *p; } a;
    33	//   a.p = /* string to pass to panic */;
    34	//   crosscall2(_cgo_panic, &a, sizeof a);
    35	//   /* The function call will not return.  */
    36	
    37	//go:linkname _runtime_cgo_panic_internal runtime._cgo_panic_internal
    38	func _runtime_cgo_panic_internal(p *byte)
    39	
    40	//go:linkname _cgo_panic _cgo_panic
    41	//go:cgo_export_static _cgo_panic
    42	//go:cgo_export_dynamic _cgo_panic
    43	//go:nosplit
    44	//go:norace
    45	func _cgo_panic(a unsafe.Pointer, n int32) {
    46		f := _runtime_cgo_panic_internal
    47		type funcval struct {
    48			pc unsafe.Pointer
    49		}
    50		fv := *(**funcval)(unsafe.Pointer(&f))
    51		_runtime_cgocallback(fv.pc, a, uintptr(n), 0)
    52	}
    53	
    54	//go:cgo_import_static x_cgo_init
    55	//go:linkname x_cgo_init x_cgo_init
    56	//go:linkname _cgo_init _cgo_init
    57	var x_cgo_init byte
    58	var _cgo_init = &x_cgo_init
    59	
    60	//go:cgo_import_static x_cgo_thread_start
    61	//go:linkname x_cgo_thread_start x_cgo_thread_start
    62	//go:linkname _cgo_thread_start _cgo_thread_start
    63	var x_cgo_thread_start byte
    64	var _cgo_thread_start = &x_cgo_thread_start
    65	
    66	// Creates a new system thread without updating any Go state.
    67	//
    68	// This method is invoked during shared library loading to create a new OS
    69	// thread to perform the runtime initialization. This method is similar to
    70	// _cgo_sys_thread_start except that it doesn't update any Go state.
    71	
    72	//go:cgo_import_static x_cgo_sys_thread_create
    73	//go:linkname x_cgo_sys_thread_create x_cgo_sys_thread_create
    74	//go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
    75	var x_cgo_sys_thread_create byte
    76	var _cgo_sys_thread_create = &x_cgo_sys_thread_create
    77	
    78	// Notifies that the runtime has been initialized.
    79	//
    80	// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done)
    81	// to ensure that the runtime has been initialized before the CGO call is
    82	// executed. This is necessary for shared libraries where we kickoff runtime
    83	// initialization in a separate thread and return without waiting for this
    84	// thread to complete the init.
    85	
    86	//go:cgo_import_static x_cgo_notify_runtime_init_done
    87	//go:linkname x_cgo_notify_runtime_init_done x_cgo_notify_runtime_init_done
    88	//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
    89	var x_cgo_notify_runtime_init_done byte
    90	var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done
    91	
    92	// Sets the traceback context function. See runtime.SetCgoTraceback.
    93	
    94	//go:cgo_import_static x_cgo_set_context_function
    95	//go:linkname x_cgo_set_context_function x_cgo_set_context_function
    96	//go:linkname _cgo_set_context_function _cgo_set_context_function
    97	var x_cgo_set_context_function byte
    98	var _cgo_set_context_function = &x_cgo_set_context_function
    99	
   100	// Calls a libc function to execute background work injected via libc
   101	// interceptors, such as processing pending signals under the thread
   102	// sanitizer.
   103	//
   104	// Left as a nil pointer if no libc interceptors are expected.
   105	
   106	//go:cgo_import_static _cgo_yield
   107	//go:linkname _cgo_yield _cgo_yield
   108	var _cgo_yield unsafe.Pointer
   109	
   110	//go:cgo_export_static _cgo_topofstack
   111	//go:cgo_export_dynamic _cgo_topofstack
   112	

View as plain text