#include <errno.h>
#include "libcgo.h"
+#include "libcgo_windows.h"
+
+// Ensure there's one symbol marked __declspec(dllexport).
+// If there are no exported symbols, the unfortunate behavior of
+// the binutils linker is to also strip the relocations table,
+// resulting in non-PIE binary. The other option is the
+// --export-all-symbols flag, but we don't need to export all symbols
+// and this may overflow the export table (#40795).
+// See https://sourceware.org/bugzilla/show_bug.cgi?id=19011
+__declspec(dllexport) int _cgo_dummy_export;
static volatile LONG runtime_init_once_gate = 0;
static volatile LONG runtime_init_once_done = 0;
void
x_cgo_sys_thread_create(void (*func)(void*), void* arg) {
- uintptr_t thandle;
-
- thandle = _beginthread(func, 0, arg);
- if(thandle == -1) {
- fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
- abort();
- }
+ _cgo_beginthread(func, arg);
}
int
LeaveCriticalSection(&runtime_init_cs);
return ret;
}
+
+void _cgo_beginthread(void (*func)(void*), void* arg) {
+ uintptr_t thandle;
+
+ thandle = _beginthread(func, 0, arg);
+ if (thandle == -1) {
+ fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
+ abort();
+ }
+}
void
_cgo_sys_thread_start(ThreadStart *ts)
{
- uintptr_t thandle;
-
- thandle = _beginthread(threadentry, 0, ts);
- if(thandle == -1) {
- fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
- abort();
- }
+ _cgo_beginthread(threadentry, ts);
}
static void
"movl %1, 0(%%eax)\n" // MOVL g, 0(FS)
:: "r"(ts.tls), "r"(ts.g) : "%eax"
);
-
+
crosscall_386(ts.fn);
}
void
_cgo_sys_thread_start(ThreadStart *ts)
{
- uintptr_t thandle;
-
- thandle = _beginthread(threadentry, 0, ts);
- if(thandle == -1) {
- fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
- abort();
- }
+ _cgo_beginthread(threadentry, ts);
}
static void
void
_cgo_sys_thread_start(ThreadStart *ts)
{
- uintptr_t thandle;
-
- thandle = _beginthread(threadentry, 0, ts);
- if(thandle == -1) {
- fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
- abort();
- }
+ _cgo_beginthread(threadentry, ts);
}
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Ensure there's one symbol marked __declspec(dllexport).
-// If there are no exported symbols, the unfortunate behavior of
-// the binutils linker is to also strip the relocations table,
-// resulting in non-PIE binary. The other option is the
-// --export-all-symbols flag, but we don't need to export all symbols
-// and this may overflow the export table (#40795).
-// See https://sourceware.org/bugzilla/show_bug.cgi?id=19011
-__declspec(dllexport) int _cgo_dummy_export;
+// Call _beginthread, aborting on failure.
+void _cgo_beginthread(void (*func)(void*), void* arg);