github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/unsafecgo/cgo/stub.go (about) 1 package cgo 2 3 /* 4 #cgo CXXFLAGS: -std=c++11 5 #cgo LDFLAGS: -lstdc++ 6 #include <stdio.h> 7 #include <time.h> 8 #include <unistd.h> 9 10 void do_usleep(size_t arg0, size_t arg1) { 11 nanosleep((const struct timespec[]){{1, 900000000L}}, NULL); 12 } 13 void unsafecgo_stub() {} 14 15 typedef void unsafecgo_trampoline_handler(size_t arg0, size_t arg1); 16 17 void unsafecgo_cgo_call(size_t fn, size_t arg0, size_t arg1) { 18 ((unsafecgo_trampoline_handler*)fn)(arg0, arg1); 19 } 20 */ 21 import "C" 22 import "unsafe" 23 24 var ( 25 Stub = C.unsafecgo_stub 26 Usleep = C.do_usleep 27 ) 28 29 func CGO() { 30 C.unsafecgo_stub() 31 } 32 33 func NonBlocking(fn *byte, arg0, arg1 uintptr) { 34 Blocking(fn, arg0, arg1) 35 //libcCall(unsafe.Pointer(fn), unsafe.Pointer(arg0)) 36 } 37 38 func Blocking(fn *byte, arg0, arg1 uintptr) { 39 C.unsafecgo_cgo_call((C.size_t)(uintptr(unsafe.Pointer(fn))), (C.size_t)(arg0), (C.size_t)(arg1)) 40 } 41 42 ////go:linkname libcCall runtime.libcCall 43 //func libcCall(fn, arg unsafe.Pointer) int32 44 45 func DoUsleep(useconds int64) { 46 C.do_usleep((C.size_t)(useconds), (C.size_t)(0)) 47 }