github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/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  
    17  void
    18  x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
    19  {
    20  	setg_gcc = setg;
    21  }
    22  
    23  
    24  void
    25  _cgo_sys_thread_start(ThreadStart *ts)
    26  {
    27  	_cgo_beginthread(threadentry, ts);
    28  }
    29  
    30  static void
    31  threadentry(void *v)
    32  {
    33  	ThreadStart ts;
    34  
    35  	ts = *(ThreadStart*)v;
    36  	free(v);
    37  
    38  	// minit queries stack bounds from the OS.
    39  
    40  	/*
    41  	 * Set specific keys in thread local storage.
    42  	 */
    43  	asm volatile (
    44  	  "movq %0, %%gs:0x28\n"	// MOVL tls0, 0x28(GS)
    45  	  :: "r"(ts.tls)
    46  	);
    47  
    48  	crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g);
    49  }