...
Run Format

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
    13static void threadentry(void*);
    14
    15void
    16x_cgo_init(G *g)
    17{
    18}
    19
    20
    21void
    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
    33static void
    34threadentry(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		"movl %0, %%fs:0x14\n"	// MOVL tls0, 0x14(FS)
    48		"movl %%fs:0x14, %%eax\n"	// MOVL 0x14(FS), tmp
    49		"movl %1, 0(%%eax)\n"	// MOVL g, 0(FS)
    50		:: "r"(ts.tls), "r"(ts.g) : "%eax"
    51	);
    52	
    53	crosscall_386(ts.fn);
    54}

View as plain text