1 // Copyright 2014 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.
13 #define USE_LIBFFI_CLOSURES
16 #endif /* defined(USE_LIBFFI) */
18 /* Declare C functions with the names used to call from Go. */
20 void makeFuncFFI(void *cif
, void *impl
)
21 __asm__ (GOSYM_PREFIX
"reflect.makeFuncFFI");
23 #ifdef USE_LIBFFI_CLOSURES
25 /* The function that we pass to ffi_prep_closure_loc. This calls the Go
26 function ffiCall with the pointer to the arguments, the results area,
27 and the closure structure. */
29 extern void FFICallbackGo(void *result
, void **args
, ffi_go_closure
*closure
)
30 __asm__ (GOSYM_PREFIX
"reflect.FFICallbackGo");
32 extern void makefuncfficanrecover(Slice
)
33 __asm__ (GOSYM_PREFIX
"runtime.makefuncfficanrecover");
35 extern void makefuncreturning(void)
36 __asm__ (GOSYM_PREFIX
"runtime.makefuncreturning");
38 static void ffi_callback (ffi_cif
*, void *, void **, void *)
39 __asm__ ("reflect.ffi_callback");
42 ffi_callback (ffi_cif
* cif
__attribute__ ((unused
)), void *results
,
43 void **args
, void *closure
)
49 /* This function is called from some series of FFI closure functions
50 called by a Go function. We want to see whether the caller of
51 the closure functions can recover. Look up the stack and skip
53 n
= runtime_callers (1, &locs
[0], sizeof locs
/ sizeof locs
[0], true);
54 for (i
= 0; i
< n
; i
++)
58 if (locs
[i
].function
.len
== 0)
60 if (locs
[i
].function
.len
< 4)
62 name
= locs
[i
].function
.str
;
63 if (name
[0] != 'f' || name
[1] != 'f' || name
[2] != 'i' || name
[3] != '_')
70 s
.__values
= (void *) &locs
[i
];
73 makefuncfficanrecover (s
);
76 FFICallbackGo(results
, args
, closure
);
82 /* Allocate an FFI closure and arrange to call ffi_callback. */
85 makeFuncFFI(void *cif
, void *impl
)
87 ffi_prep_go_closure(impl
, (ffi_cif
*)cif
, ffi_callback
);
90 #else /* !defined(USE_LIBFFI_CLOSURES) */
93 makeFuncFFI(void *cif
__attribute__ ((unused
)),
94 void *impl
__attribute__ ((unused
)))
96 runtime_panicstring ("libgo built without FFI does not support "