github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/runtime/cgo/gcc_freebsd_arm.c (about) 1 // Copyright 2012 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 <machine/sysarch.h> 7 #include <sys/signalvar.h> 8 #include <pthread.h> 9 #include <signal.h> 10 #include <string.h> 11 #include "libcgo.h" 12 #include "libcgo_unix.h" 13 14 #ifdef ARM_TP_ADDRESS 15 // ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 16 // and is known to runtime.read_tls_fallback. Verify it with 17 // cpp. 18 #if ARM_TP_ADDRESS != 0xffff1000 19 #error Wrong ARM_TP_ADDRESS! 20 #endif 21 #endif 22 23 static void *threadentry(void*); 24 25 static void (*setg_gcc)(void*); 26 27 void 28 x_cgo_init(G *g, void (*setg)(void*)) 29 { 30 pthread_attr_t attr; 31 size_t size; 32 33 setg_gcc = setg; 34 pthread_attr_init(&attr); 35 pthread_attr_getstacksize(&attr, &size); 36 g->stacklo = (uintptr)&attr - size + 4096; 37 pthread_attr_destroy(&attr); 38 } 39 40 void 41 _cgo_sys_thread_start(ThreadStart *ts) 42 { 43 pthread_attr_t attr; 44 sigset_t ign, oset; 45 pthread_t p; 46 size_t size; 47 int err; 48 49 SIGFILLSET(ign); 50 pthread_sigmask(SIG_SETMASK, &ign, &oset); 51 52 pthread_attr_init(&attr); 53 pthread_attr_getstacksize(&attr, &size); 54 // Leave stacklo=0 and set stackhi=size; mstart will do the rest. 55 ts->g->stackhi = size; 56 err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); 57 58 pthread_sigmask(SIG_SETMASK, &oset, nil); 59 60 if (err != 0) { 61 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); 62 abort(); 63 } 64 } 65 66 extern void crosscall_arm1(void (*fn)(void), void (*setg_gcc)(void*), void *g); 67 static void* 68 threadentry(void *v) 69 { 70 ThreadStart ts; 71 72 ts = *(ThreadStart*)v; 73 free(v); 74 75 crosscall_arm1(ts.fn, setg_gcc, (void*)ts.g); 76 return nil; 77 }