Closed aashah closed 2 years ago
See https://github.com/golang/go/issues/49633, which suggests a much simpler solution of passing the address of the cgo.Handle through the C code.
Well, this is indeed an unthought of problem, thank you very much for your hard work :)
The last argument to hs_scan is "void*", a pointer to an abitrary context. "hsScan" incorrectly uses "unsafe.Pointer(h)" when h is not a pointer. This can cause fatal runtime error when Go passes arguments across the Go <-> C boundaries. The runtime error does not happen all the time, as it usually "looks" like a pointer. This makes it difficult to reproduce.
We can fix this by actually passing a real pointer (of our
cgo.Handle
) and dereferencing the pointer within the callback. I did a quick audit, and think I updated all places where we use the callback.I did not audit other parts of the API spec that take in a
void*
arg.Thanks @adonovan for helping with most of the analysis.
Below is a small snippet of the fatal runtime panic: