github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/callback.c (about)

     1  #include "_cgo_export.h"
     2  
     3  extern void crosscall2(void (*fn)(void *, int), void *, int, int);
     4  extern int _cgo_wait_runtime_init_done();
     5  
     6  void *get_crosscall2addr() {
     7      return crosscall2;
     8  }
     9  
    10  void *get_cgo_wait_runtime_init_done_addr() {
    11      return _cgo_wait_runtime_init_done;
    12  }
    13  
    14  void callbackfn(void *wrapper, void *fn) {
    15      int ctxt = _cgo_wait_runtime_init_done();
    16       struct {
    17         void *fn;
    18      } __attribute__((__packed__)) a;
    19      a.fn = fn;
    20      crosscall2((void (*)(void *, int))wrapper, &a, sizeof(a), ctxt);
    21  }