Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/cgo/gcc_windows_amd64.c

Documentation: runtime/cgo

     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  	uintptr_t thandle;
    28  
    29  	thandle = _beginthread(threadentry, 0, ts);
    30  	if(thandle == -1) {
    31  		fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
    32  		abort();
    33  	}
    34  }
    35  
    36  static void
    37  threadentry(void *v)
    38  {
    39  	ThreadStart ts;
    40  
    41  	ts = *(ThreadStart*)v;
    42  	free(v);
    43  
    44  	// minit queries stack bounds from the OS.
    45  
    46  	/*
    47  	 * Set specific keys in thread local storage.
    48  	 */
    49  	asm volatile (
    50  	  "movq %0, %%gs:0x28\n"	// MOVL tls0, 0x28(GS)
    51  	  :: "r"(ts.tls)
    52  	);
    53  
    54  	crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g);
    55  }
    56  

View as plain text