...
Run Format

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 WIN64_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		  "movq %0, %%gs:0x28\n"	// MOVL tls0, 0x28(GS)
    47		  "movq %%gs:0x28, %%rax\n" // MOVQ 0x28(GS), tmp
    48		  "movq %1, 0(%%rax)\n" // MOVQ g, 0(GS)
    49		  :: "r"(ts.tls), "r"(ts.g) : "%rax"
    50		);
    51	
    52		crosscall_amd64(ts.fn);
    53	}

View as plain text