1 // Copyright 2009 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.
10 #define nil ((void*)0)
11 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
13 typedef uint32_t uint32;
14 typedef uint64_t uint64;
15 typedef uintptr_t uintptr;
18 * The beginning of the per-goroutine structure,
19 * as defined in ../pkg/runtime/runtime.h.
20 * Just enough to edit these two fields.
30 * Arguments to the _cgo_thread_start call.
31 * Also known to ../pkg/runtime/runtime.h.
33 typedef struct ThreadStart ThreadStart;
42 * Called by 5c/6c/8c world.
43 * Makes a local copy of the ThreadStart and
44 * calls _cgo_sys_thread_start(ts).
46 extern void (*_cgo_thread_start)(ThreadStart *ts);
49 * Creates a new operating system thread without updating any Go state
52 extern void (*_cgo_sys_thread_create)(void* (*func)(void*), void* arg);
55 * Creates the new operating system thread (OS, arch dependent).
57 void _cgo_sys_thread_start(ThreadStart *ts);
60 * Waits for the Go runtime to be initialized (OS dependent).
61 * If runtime.SetCgoTraceback is used to set a context function,
62 * calls the context function and returns the context value.
64 uintptr_t _cgo_wait_runtime_init_done(void);
67 * Call fn in the 6c world.
69 void crosscall_amd64(void (*fn)(void), void (*setg_gcc)(void*), void *g);
72 * Call fn in the 8c world.
74 void crosscall_386(void (*fn)(void));
77 * Prints error then calls abort. For linux and android.
79 void fatalf(const char* format, ...);
82 * Registers the current mach thread port for EXC_BAD_ACCESS processing.
84 void darwin_arm_init_thread_exception_port(void);
87 * Starts a mach message server processing EXC_BAD_ACCESS.
89 void darwin_arm_init_mach_exception_handler(void);
92 * The cgo context function. See runtime.SetCgoTraceback.
97 extern void (*(_cgo_get_context_function(void)))(struct context_arg*);
100 * The argument for the cgo traceback callback. See runtime.SetCgoTraceback.
102 struct cgoTracebackArg {
104 uintptr_t SigContext;
110 * TSAN support. This is only useful when building with
111 * CGO_CFLAGS="-fsanitize=thread" CGO_LDFLAGS="-fsanitize=thread" go install
114 #if defined(__has_feature)
115 # if __has_feature(thread_sanitizer)
118 #elif defined(__SANITIZE_THREAD__)
124 // These must match the definitions in yesTsanProlog in cmd/cgo/out.go.
125 // In general we should call _cgo_tsan_acquire when we enter C code,
126 // and call _cgo_tsan_release when we return to Go code.
127 // This is only necessary when calling code that might be instrumented
128 // by TSAN, which mostly means system library calls that TSAN intercepts.
129 // See the comment in cmd/cgo/out.go for more details.
131 long long _cgo_sync __attribute__ ((common));
133 extern void __tsan_acquire(void*);
134 extern void __tsan_release(void*);
136 __attribute__ ((unused))
137 static void _cgo_tsan_acquire() {
138 __tsan_acquire(&_cgo_sync);
141 __attribute__ ((unused))
142 static void _cgo_tsan_release() {
143 __tsan_release(&_cgo_sync);
146 #else // !defined(CGO_TSAN)
148 #define _cgo_tsan_acquire()
149 #define _cgo_tsan_release()
151 #endif // !defined(CGO_TSAN)