github.com/panjjo/go@v0.0.0-20161104043856-d62b31386338/src/runtime/cgo/gcc_linux_mips64x.c (about) 1 // Copyright 2016 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 // +build linux 7 // +build mips64 mips64le 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 void (*setg_gcc)(void*); 18 19 void 20 _cgo_sys_thread_start(ThreadStart *ts) 21 { 22 pthread_attr_t attr; 23 sigset_t ign, oset; 24 pthread_t p; 25 size_t size; 26 int err; 27 28 sigfillset(&ign); 29 pthread_sigmask(SIG_SETMASK, &ign, &oset); 30 31 // Not sure why the memset is necessary here, 32 // but without it, we get a bogus stack size 33 // out of pthread_attr_getstacksize. C'est la Linux. 34 memset(&attr, 0, sizeof attr); 35 pthread_attr_init(&attr); 36 size = 0; 37 pthread_attr_getstacksize(&attr, &size); 38 // Leave stacklo=0 and set stackhi=size; mstack will do the rest. 39 ts->g->stackhi = size; 40 err = pthread_create(&p, &attr, threadentry, ts); 41 42 pthread_sigmask(SIG_SETMASK, &oset, nil); 43 44 if (err != 0) { 45 fatalf("pthread_create failed: %s", strerror(err)); 46 } 47 } 48 49 extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g); 50 static void* 51 threadentry(void *v) 52 { 53 ThreadStart ts; 54 55 ts = *(ThreadStart*)v; 56 free(v); 57 58 crosscall1(ts.fn, setg_gcc, (void*)ts.g); 59 return nil; 60 } 61 62 void 63 x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) 64 { 65 pthread_attr_t attr; 66 size_t size; 67 68 setg_gcc = setg; 69 pthread_attr_init(&attr); 70 pthread_attr_getstacksize(&attr, &size); 71 g->stacklo = (uintptr)&attr - size + 4096; 72 pthread_attr_destroy(&attr); 73 74 if (x_cgo_inittls) { 75 x_cgo_inittls(tlsg, tlsbase); 76 } 77 }