github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/runtime/cgo/gcc_solaris_amd64.c (about) 1 // Copyright 2015 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 <pthread.h> 6 #include <string.h> 7 #include <signal.h> 8 #include <ucontext.h> 9 #include "libcgo.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*)) 16 { 17 ucontext_t ctx; 18 19 setg_gcc = setg; 20 if (getcontext(&ctx) != 0) 21 perror("runtime/cgo: getcontext failed"); 22 g->stacklo = (uintptr_t)ctx.uc_stack.ss_sp; 23 } 24 25 void 26 _cgo_sys_thread_start(ThreadStart *ts) 27 { 28 pthread_attr_t attr; 29 sigset_t ign, oset; 30 pthread_t p; 31 void *base; 32 size_t size; 33 int err; 34 35 sigfillset(&ign); 36 pthread_sigmask(SIG_SETMASK, &ign, &oset); 37 38 pthread_attr_init(&attr); 39 40 if (pthread_attr_getstack(&attr, &base, &size) != 0) 41 perror("runtime/cgo: pthread_attr_getstack failed"); 42 if (size == 0) { 43 ts->g->stackhi = 2 << 20; 44 if (pthread_attr_setstack(&attr, NULL, ts->g->stackhi) != 0) 45 perror("runtime/cgo: pthread_attr_setstack failed"); 46 } else { 47 ts->g->stackhi = size; 48 } 49 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 50 err = pthread_create(&p, &attr, threadentry, ts); 51 52 pthread_sigmask(SIG_SETMASK, &oset, nil); 53 54 if (err != 0) { 55 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); 56 abort(); 57 } 58 } 59 60 static void* 61 threadentry(void *v) 62 { 63 ThreadStart ts; 64 65 ts = *(ThreadStart*)v; 66 free(v); 67 68 /* 69 * Set specific keys. 70 */ 71 setg_gcc((void*)ts.g); 72 73 crosscall_amd64(ts.fn); 74 return nil; 75 }