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