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_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
37 pthread_attr_getstacksize(&attr, &size);
38
39 // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
40 ts->g->stackhi = size;
41 err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
42
43 pthread_sigmask(SIG_SETMASK, &oset, nil);
44
45 if (err != 0) {
46 fatalf("pthread_create failed: %s", strerror(err));
47 }
48 }
49
50 extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
51 static void*
52 threadentry(void *v)
53 {
54 ThreadStart ts;
55
56 ts = *(ThreadStart*)v;
57 free(v);
58
59 crosscall1(ts.fn, setg_gcc, (void*)ts.g);
60 return nil;
61 }
62
View as plain text