github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/runtime/cgo/gcc_windows_386.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 "libcgo.h"
    11  
    12  static void threadentry(void*);
    13  
    14  void
    15  x_cgo_init(G *g)
    16  {
    17  }
    18  
    19  
    20  void
    21  _cgo_sys_thread_start(ThreadStart *ts)
    22  {
    23  	uintptr_t thandle;
    24  
    25  	thandle = _beginthread(threadentry, 0, ts);
    26  	if(thandle == -1) {
    27  		fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
    28  		abort();
    29  	}
    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  		"movl %0, %%fs:0x14\n"	// MOVL tls0, 0x14(FS)
    47  		"movl %%fs:0x14, %%eax\n"	// MOVL 0x14(FS), tmp
    48  		"movl %1, 0(%%eax)\n"	// MOVL g, 0(FS)
    49  		:: "r"(ts.tls), "r"(ts.g) : "%eax"
    50  	);
    51  	
    52  	crosscall_386(ts.fn);
    53  }