...
1// Copyright 2014 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//go:build ppc64 || ppc64le
6
7#include <pthread.h>
8#include <string.h>
9#include <signal.h>
10#include "libcgo.h"
11#include "libcgo_unix.h"
12
13static void *threadentry(void*);
14
15void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
16static void (*setg_gcc)(void*);
17
18void
19x_cgo_init(G *g, void (*setg)(void*), void **tlsbase)
20{
21 setg_gcc = setg;
22 _cgo_set_stacklo(g, NULL);
23}
24
25void
26_cgo_sys_thread_start(ThreadStart *ts)
27{
28 pthread_attr_t attr;
29 sigset_t ign, oset;
30 pthread_t p;
31 size_t size;
32 int err;
33
34 sigfillset(&ign);
35 pthread_sigmask(SIG_SETMASK, &ign, &oset);
36
37 pthread_attr_init(&attr);
38 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
39 pthread_attr_getstacksize(&attr, &size);
40 // Leave stacklo=0 and set stackhi=size; mstart will do the rest.
41 ts->g->stackhi = size;
42 err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
43
44 pthread_sigmask(SIG_SETMASK, &oset, nil);
45
46 if (err != 0) {
47 fatalf("pthread_create failed: %s", strerror(err));
48 }
49}
50
51extern void crosscall_ppc64(void (*fn)(void), void *g);
52
53static void*
54threadentry(void *v)
55{
56 ThreadStart ts;
57
58 ts = *(ThreadStart*)v;
59 _cgo_tsan_acquire();
60 free(v);
61 _cgo_tsan_release();
62
63 // Save g for this thread in C TLS
64 setg_gcc((void*)ts.g);
65
66 crosscall_ppc64(ts.fn, (void*)ts.g);
67 return nil;
68}
View as plain text