github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/cgo/gcc_windows_amd64.c (about) 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. 4 5 #define WIN32_LEAN_AND_MEAN 6 #include <windows.h> 7 #include <process.h> 8 #include <stdlib.h> 9 #include <stdio.h> 10 #include <errno.h> 11 #include "libcgo.h" 12 #include "libcgo_windows.h" 13 14 static void threadentry(void*); 15 static void (*setg_gcc)(void*); 16 static DWORD *tls_g; 17 18 void 19 x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) 20 { 21 setg_gcc = setg; 22 tls_g = (DWORD *)tlsg; 23 } 24 25 26 void 27 _cgo_sys_thread_start(ThreadStart *ts) 28 { 29 _cgo_beginthread(threadentry, ts); 30 } 31 32 static void 33 threadentry(void *v) 34 { 35 ThreadStart ts; 36 37 ts = *(ThreadStart*)v; 38 free(v); 39 40 // minit queries stack bounds from the OS. 41 42 /* 43 * Set specific keys in thread local storage. 44 */ 45 asm volatile ( 46 "movq %0, %%gs:0(%1)\n" // MOVL tls0, 0(tls_g)(GS) 47 :: "r"(ts.tls), "r"(*tls_g) 48 ); 49 50 crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); 51 }