...
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 ignore
6
7#ifdef WIN32
8// A Windows DLL is unable to call an arbitrary function in
9// the main executable. Work around that by making the main
10// executable pass the callback function pointer to us.
11void (*goCallback)(void);
12__declspec(dllexport) void setCallback(void *f)
13{
14 goCallback = (void (*)())f;
15}
16__declspec(dllexport) void sofunc(void);
17#elif defined(_AIX)
18// AIX doesn't allow the creation of a shared object with an
19// undefined symbol. It's possible to bypass this problem by
20// using -Wl,-G and -Wl,-brtl option which allows run-time linking.
21// However, that's not how most of AIX shared object works.
22// Therefore, it's better to consider goCallback as a pointer and
23// to set up during an init function.
24void (*goCallback)(void);
25void setCallback(void *f) { goCallback = f; }
26#else
27extern void goCallback(void);
28void setCallback(void *f) { (void)f; }
29#endif
30
31// OpenBSD and older Darwin lack TLS support
32#if !defined(__OpenBSD__) && !defined(__APPLE__)
33__thread int tlsvar = 12345;
34#endif
35
36void sofunc(void)
37{
38 goCallback();
39}
View as plain text