From 1b615a6667660b353c7719d805a0a40cdd948789 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 11 May 2017 19:53:29 -0700 Subject: ffi: a measure of safety for callbacks. We don't want, by default, for callbacks to capture delimited continuations across foreign code, or perpetrate non-local transfers across foreign code. Here, we take an approach similar for what was done in ftw_wrap. * ffi.c (s_exit_point): New global variable with internal linkage. (ffi_call_wrap): If s_exit_point isn't nil, then it means that the callback intercepted a nonlocal transfer and stored its exit point. We resume the transfer to that exit point instead of returning normally. (ffi_closure_dispatch_safe): New static function. (ffi_make_closure): Support a new argument which indicates whether to make a closure which uses ffi_closure_dispatch_safe, or ffi_closure_dispatch. (ffi_init): Update registration of ffi-make-closure intrinsic. * ffi.h (ffi_make_closure): Declaration updated. * share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): New function. (deffi-cb): Macro internals replaced by call to new function. (deffi-cb-safe): New macro. * txr.1: Documentation of ffi-make-closure updated. New deffi-cb-unsafe macro documented. --- ffi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ffi.h') diff --git a/ffi.h b/ffi.h index e11d8b51..8eb54a78 100644 --- a/ffi.h +++ b/ffi.h @@ -53,7 +53,7 @@ extern val ffi_type_s, ffi_call_desc_s, ffi_closure_s; val ffi_type_compile(val syntax); val ffi_make_call_desc(val ntotal, val nfixed, val rettype, val argtypes); -val ffi_make_closure(val fun, val call_desc); +val ffi_make_closure(val fun, val call_desc, val safe_p_in); mem_t *ffi_closure_get_fptr(val closure); val ffi_call_wrap(val ffi_call_desc, val fptr, val args); val ffi_typedef(val name, val type); -- cgit v1.2.3