2010-04-06 00:44:05 -06:00
|
|
|
// 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.
|
|
|
|
|
2010-12-08 12:33:17 -07:00
|
|
|
#define WIN64_LEAN_AND_MEAN
|
2010-04-06 00:44:05 -06:00
|
|
|
#include <windows.h>
|
|
|
|
#include "libcgo.h"
|
|
|
|
|
|
|
|
static void *threadentry(void*);
|
|
|
|
|
2010-12-08 12:33:17 -07:00
|
|
|
/* From what I've read 2MB is default for 64-bit Linux.
|
2010-04-06 00:44:05 -06:00
|
|
|
Allocation granularity on Windows is typically 64 KB. */
|
2010-12-08 12:33:17 -07:00
|
|
|
#define STACKSIZE (2*1024*1024)
|
2010-04-06 00:44:05 -06:00
|
|
|
|
2010-12-08 14:35:05 -07:00
|
|
|
static void
|
|
|
|
xinitcgo(void)
|
2010-04-06 00:44:05 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-08 14:35:05 -07:00
|
|
|
void (*initcgo)(void) = xinitcgo;
|
|
|
|
|
2010-04-06 00:44:05 -06:00
|
|
|
void
|
|
|
|
libcgo_sys_thread_start(ThreadStart *ts)
|
|
|
|
{
|
2010-09-27 07:44:56 -06:00
|
|
|
ts->g->stackguard = STACKSIZE;
|
|
|
|
_beginthread(threadentry, STACKSIZE, ts);
|
2010-04-06 00:44:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void*
|
|
|
|
threadentry(void *v)
|
|
|
|
{
|
2010-09-27 07:44:56 -06:00
|
|
|
ThreadStart ts;
|
2011-07-19 08:47:33 -06:00
|
|
|
void *tls0;
|
2010-09-27 07:44:56 -06:00
|
|
|
|
|
|
|
ts = *(ThreadStart*)v;
|
|
|
|
free(v);
|
|
|
|
|
|
|
|
ts.g->stackbase = (uintptr)&ts;
|
|
|
|
|
|
|
|
/*
|
2011-06-29 01:37:56 -06:00
|
|
|
* libcgo_sys_thread_start set stackguard to stack size;
|
|
|
|
* change to actual guard pointer.
|
|
|
|
*/
|
2010-09-27 07:44:56 -06:00
|
|
|
ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
|
|
|
|
|
2011-06-29 01:37:56 -06:00
|
|
|
/*
|
|
|
|
* Set specific keys in thread local storage.
|
|
|
|
*/
|
2011-07-19 08:47:33 -06:00
|
|
|
tls0 = (void*)LocalAlloc(LPTR, 64);
|
2011-06-29 01:37:56 -06:00
|
|
|
asm volatile (
|
2011-07-19 08:47:33 -06:00
|
|
|
"movq %0, %%gs:0x58\n" // MOVL tls0, 0x58(GS)
|
2011-06-29 01:37:56 -06:00
|
|
|
"movq %%gs:0x58, %%rax\n" // MOVQ 0x58(GS), tmp
|
2011-07-19 08:47:33 -06:00
|
|
|
"movq %1, 0(%%rax)\n" // MOVQ g, 0(GS)
|
|
|
|
"movq %2, 8(%%rax)\n" // MOVQ m, 8(GS)
|
|
|
|
:: "r"(tls0), "r"(ts.g), "r"(ts.m) : "%rax"
|
2011-06-29 01:37:56 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
crosscall_amd64(ts.fn);
|
2010-09-27 07:44:56 -06:00
|
|
|
return nil;
|
2010-04-06 00:44:05 -06:00
|
|
|
}
|