mirror of
https://github.com/golang/go
synced 2024-11-16 21:04:45 -07:00
runtime/cgo: merge bodies of cgo_sys_thread_start on windows
The bodies of cgo_sys_thread_start (and x_cgo_sys_thread_create) are nearly identical on all of the windows ports. Create a single _cgo_beginthread implementation that contains the body and is used on all ports. This will reduce churn in an upcoming CL to add retry logic. We could theoretically have a single implementation of _cgo_sys_thread_start shared by all ports, but I keep them separate for ease of searching. Right now every single port implements this function in their gcc_GOOS_GOARCH.c file, so it is nice to keep this symmetry. _cgo_dummy_export must move out of libcgo_windows.h because it is a definition and the inclusion of libcgo_windows.h in multiple files creates duplicate definitions. For #52572. Change-Id: I9fa22009389349c754210274c7db2631b061f9c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/410354 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
840e99ed74
commit
91019cc13d
@ -13,6 +13,16 @@
|
||||
#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;
|
||||
@ -53,13 +63,7 @@ _cgo_maybe_run_preinit() {
|
||||
|
||||
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
|
||||
@ -123,3 +127,13 @@ void (*(_cgo_get_context_function(void)))(struct context_arg*) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,7 @@ x_cgo_init(G *g)
|
||||
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
|
||||
@ -50,6 +44,6 @@ threadentry(void *v)
|
||||
"movl %1, 0(%%eax)\n" // MOVL g, 0(FS)
|
||||
:: "r"(ts.tls), "r"(ts.g) : "%eax"
|
||||
);
|
||||
|
||||
|
||||
crosscall_386(ts.fn);
|
||||
}
|
||||
|
@ -24,13 +24,7 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
||||
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
|
||||
|
@ -23,13 +23,7 @@ x_cgo_init(G *g, void (*setg)(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);
|
||||
|
@ -2,11 +2,5 @@
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user