github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/runtime/cgo/gcc_netbsd_arm.c (about) 1 // Copyright 2013 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 <sys/types.h> 6 #include <pthread.h> 7 #include <signal.h> 8 #include <string.h> 9 #include "libcgo.h" 10 11 static void *threadentry(void*); 12 13 static void (*setmg_gcc)(void*, void*); 14 15 void 16 x_cgo_init(G *g, void (*setmg)(void*, void*)) 17 { 18 pthread_attr_t attr; 19 size_t size; 20 21 setmg_gcc = setmg; 22 pthread_attr_init(&attr); 23 pthread_attr_getstacksize(&attr, &size); 24 g->stackguard = (uintptr)&attr - size + 4096; 25 pthread_attr_destroy(&attr); 26 } 27 28 29 void 30 _cgo_sys_thread_start(ThreadStart *ts) 31 { 32 pthread_attr_t attr; 33 sigset_t ign, oset; 34 pthread_t p; 35 size_t size; 36 int err; 37 38 sigfillset(&ign); 39 pthread_sigmask(SIG_SETMASK, &ign, &oset); 40 41 pthread_attr_init(&attr); 42 pthread_attr_getstacksize(&attr, &size); 43 ts->g->stackguard = size; 44 err = pthread_create(&p, &attr, threadentry, ts); 45 46 pthread_sigmask(SIG_SETMASK, &oset, nil); 47 48 if (err != 0) { 49 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); 50 abort(); 51 } 52 } 53 54 extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), void *g, void *m); 55 static void* 56 threadentry(void *v) 57 { 58 ThreadStart ts; 59 60 ts = *(ThreadStart*)v; 61 free(v); 62 63 ts.g->stackbase = (uintptr)&ts; 64 65 /* 66 * _cgo_sys_thread_start set stackguard to stack size; 67 * change to actual guard pointer. 68 */ 69 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; 70 71 crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); 72 return nil; 73 }