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