Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/cgo/gcc_windows_386.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  
    16  void
    17  x_cgo_init(G *g)
    18  {
    19  }
    20  
    21  
    22  void
    23  _cgo_sys_thread_start(ThreadStart *ts)
    24  {
    25  	uintptr_t thandle;
    26  
    27  	thandle = _beginthread(threadentry, 0, ts);
    28  	if(thandle == -1) {
    29  		fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
    30  		abort();
    31  	}
    32  }
    33  
    34  static void
    35  threadentry(void *v)
    36  {
    37  	ThreadStart ts;
    38  
    39  	ts = *(ThreadStart*)v;
    40  	free(v);
    41  
    42  	// minit queries stack bounds from the OS.
    43  
    44  	/*
    45  	 * Set specific keys in thread local storage.
    46  	 */
    47  	asm volatile (
    48  		"movl %0, %%fs:0x14\n"	// MOVL tls0, 0x14(FS)
    49  		"movl %%fs:0x14, %%eax\n"	// MOVL 0x14(FS), tmp
    50  		"movl %1, 0(%%eax)\n"	// MOVL g, 0(FS)
    51  		:: "r"(ts.tls), "r"(ts.g) : "%eax"
    52  	);
    53  	
    54  	crosscall_386(ts.fn);
    55  }
    56  

View as plain text