...

Text file src/pkg/runtime/cgo/gcc_windows_amd64.c

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

View as plain text