callbacks.go RawHistoryFolder
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//go:build darwin || linux
6
7package fakecgo
8
9import _ "unsafe"
10
11// TODO: decide if we need _runtime_cgo_panic_internal
12
13//go:linkname x_cgo_init_trampoline x_cgo_init_trampoline
14//go:linkname _cgo_init _cgo_init
15var x_cgo_init_trampoline byte
16var _cgo_init = &x_cgo_init_trampoline
17
18// Creates a new system thread without updating any Go state.
19//
20// This method is invoked during shared library loading to create a new OS
21// thread to perform the runtime initialization. This method is similar to
22// _cgo_sys_thread_start except that it doesn't update any Go state.
23
24//go:linkname x_cgo_thread_start_trampoline x_cgo_thread_start_trampoline
25//go:linkname _cgo_thread_start _cgo_thread_start
26var x_cgo_thread_start_trampoline byte
27var _cgo_thread_start = &x_cgo_thread_start_trampoline
28
29// Notifies that the runtime has been initialized.
30//
31// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done)
32// to ensure that the runtime has been initialized before the CGO call is
33// executed. This is necessary for shared libraries where we kickoff runtime
34// initialization in a separate thread and return without waiting for this
35// thread to complete the init.
36
37//go:linkname x_cgo_notify_runtime_init_done_trampoline x_cgo_notify_runtime_init_done_trampoline
38//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
39var x_cgo_notify_runtime_init_done_trampoline byte
40var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done_trampoline
41
42// TODO: decide if we need x_cgo_set_context_function
43// TODO: decide if we need _cgo_yield
44
45var (
46 // In Go 1.20 the race detector was rewritten to pure Go
47 // on darwin. This means that when CGO_ENABLED=0 is set
48 // fakecgo is built with race detector code. This is not
49 // good since this code is pretending to be C. The go:norace
50 // pragma is not enough, since it only applies to the native
51 // ABIInternal function. The ABIO wrapper (which is necessary,
52 // since all references to text symbols from assembly will use it)
53 // does not inherit the go:norace pragma, so it will still be
54 // instrumented by the race detector.
55 //
56 // To circumvent this issue, using closure calls in the
57 // assembly, which forces the compiler to use the ABIInternal
58 // native implementation (which has go:norace) instead.
59 threadentry_call = threadentry
60 x_cgo_init_call = x_cgo_init
61 x_cgo_setenv_call = x_cgo_setenv
62 x_cgo_unsetenv_call = x_cgo_unsetenv
63 x_cgo_thread_start_call = x_cgo_thread_start
64)