diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/runtime/cgo/gcc_windows_386.c | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/runtime/cgo/gcc_windows_386.c')
-rw-r--r-- | src/runtime/cgo/gcc_windows_386.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/runtime/cgo/gcc_windows_386.c b/src/runtime/cgo/gcc_windows_386.c new file mode 100644 index 000000000..acd038ccd --- /dev/null +++ b/src/runtime/cgo/gcc_windows_386.c @@ -0,0 +1,61 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <process.h> +#include <stdlib.h> +#include <stdio.h> +#include "libcgo.h" + +static void threadentry(void*); + +/* 1MB is default stack size for 32-bit Windows. + Allocation granularity on Windows is typically 64 KB. + The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */ +#define STACKSIZE (1*1024*1024) + +void +x_cgo_init(G *g) +{ + int tmp; + g->stacklo = (uintptr)&tmp - STACKSIZE + 8*1024; +} + + +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + uintptr_t thandle; + + thandle = _beginthread(threadentry, 0, ts); + if(thandle == -1) { + fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno); + abort(); + } +} + +static void +threadentry(void *v) +{ + ThreadStart ts; + + ts = *(ThreadStart*)v; + free(v); + + ts.g->stackhi = (uintptr)&ts; + ts.g->stacklo = (uintptr)&ts - STACKSIZE + 8*1024; + + /* + * Set specific keys in thread local storage. + */ + asm volatile ( + "movl %0, %%fs:0x14\n" // MOVL tls0, 0x14(FS) + "movl %%fs:0x14, %%eax\n" // MOVL 0x14(FS), tmp + "movl %1, 0(%%eax)\n" // MOVL g, 0(FS) + :: "r"(ts.tls), "r"(ts.g) : "%eax" + ); + + crosscall_386(ts.fn); +} |