This source file includes following definitions.
- x_cgo_init
- _cgo_sys_thread_start
- threadentry
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include "libcgo.h"
static void threadentry(void*);
#define STACKSIZE (1*1024*1024)
void
x_cgo_init(G *g)
{
int tmp;
g->stackguard = (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->stackbase = (uintptr)&ts;
ts.g->stackguard = (uintptr)&ts - STACKSIZE + 8*1024;
asm volatile (
"movl %0, %%fs:0x14\n"
"movl %%fs:0x14, %%eax\n"
"movl %1, 0(%%eax)\n"
"movl %2, 4(%%eax)\n"
:: "r"(ts.tls), "r"(ts.g), "r"(ts.m) : "%eax"
);
crosscall_386(ts.fn);
}