blob: 14a409f5ebbaa7900d9e07f9cc79393e75b95ad4 [file] [log] [blame]
Russ Cox133a1582009-10-03 10:37:12 -07001// 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#include <pthread.h>
6#include "libcgo.h"
7
8static void* threadentry(void*);
9
10void
11initcgo(void)
12{
13}
14
15void
16libcgo_sys_thread_start(ThreadStart *ts)
17{
18 pthread_attr_t attr;
19 pthread_t p;
20 size_t size;
21
22 pthread_attr_init(&attr);
23 pthread_attr_getstacksize(&attr, &size);
24 ts->g->stackguard = size;
25 pthread_create(&p, &attr, threadentry, ts);
26}
27
28static void*
29threadentry(void *v)
30{
31 ThreadStart ts;
32
33 ts = *(ThreadStart*)v;
34 free(v);
35
36 ts.g->stackbase = (uintptr)&ts;
37
38 /*
39 * libcgo_sys_thread_start set stackguard to stack size;
40 * change to actual guard pointer.
41 */
42 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
43
44 crosscall_amd64(ts.m, ts.g, ts.fn);
45 return nil;
46}