Text file
src/runtime/cgo/gcc_dragonfly_amd64.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 #include <sys/types.h>
6 #include <sys/signalvar.h>
7 #include <pthread.h>
8 #include <signal.h>
9 #include <string.h>
10 #include "libcgo.h"
11 #include "libcgo_unix.h"
12
13 static void* threadentry(void*);
14 static void (*setg_gcc)(void*);
15
16 void
17 x_cgo_init(G *g, void (*setg)(void*))
18 {
19 setg_gcc = setg;
20 _cgo_set_stacklo(g, NULL);
21 }
22
23 void
24 _cgo_sys_thread_start(ThreadStart *ts)
25 {
26 pthread_attr_t attr;
27 sigset_t ign, oset;
28 pthread_t p;
29 size_t size;
30 int err;
31
32 SIGFILLSET(ign);
33 pthread_sigmask(SIG_SETMASK, &ign, &oset);
34
35 pthread_attr_init(&attr);
36 pthread_attr_getstacksize(&attr, &size);
37
38 // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
39 ts->g->stackhi = size;
40 err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
41
42 pthread_sigmask(SIG_SETMASK, &oset, nil);
43
44 if (err != 0) {
45 fatalf("pthread_create failed: %s", strerror(err));
46 }
47 }
48
49 extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
50 static void*
51 threadentry(void *v)
52 {
53 ThreadStart ts;
54
55 ts = *(ThreadStart*)v;
56 free(v);
57
58 crosscall1(ts.fn, setg_gcc, (void*)ts.g);
59 return nil;
60 }
61
View as plain text