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