Text file
src/runtime/cgo/gcc_windows_386.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 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 unsigned long __stdcall threadentry(void*);
15 static void (*setg_gcc)(void*);
16 static DWORD *tls_g;
17
18 void
19 x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
20 {
21 setg_gcc = setg;
22 tls_g = (DWORD *)tlsg;
23 }
24
25 void
26 _cgo_sys_thread_start(ThreadStart *ts)
27 {
28 _cgo_beginthread(threadentry, ts);
29 }
30
31 extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
32 static unsigned long
33 __stdcall
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 "movl %0, %%fs:0(%1)\n" // MOVL tls0, 0(tls_g)(FS)
48 "movl %%fs:0(%1), %%eax\n" // MOVL 0(tls_g)(FS), tmp
49 "movl %2, 0(%%eax)\n" // MOVL g, 0(AX)
50 :: "r"(ts.tls), "r"(*tls_g), "r"(ts.g) : "%eax"
51 );
52
53 crosscall1(ts.fn, setg_gcc, ts.g);
54 return 0;
55 }
56
View as plain text