Checking type safety of foreign function calls

被引:29
作者
Furr, M [1 ]
Foster, JS [1 ]
机构
[1] Univ Maryland, College Pk, MD 20742 USA
关键词
foreign function interface; FFI; foreign function calls; representational type; multi-lingual type system; multi-lingual type inference; flow-sensitive type system; dataflow analysis; OCaml;
D O I
10.1145/1064978.1065019
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
We present a multi-lingual type inference system for checking type safety across a foreign function interface. The goal of our system is to prevent foreign function calls from introducing type and memory safety violations into an otherwise safe language. Our system targets OCaml's FFI to C, which is relatively lightweight and illustrates some interesting challenges in multi-lingual type inference. The type language in our system embeds OCaml types in C types and vice-versa, which allows us to track type information accurately even through the foreign language, where the original types are lost. Our system uses representational types that can model multiple OCaml types, because C programs can observe that many OCaml types have the same physical representation. Furthermore, because C has a low-level view of OCaml data, our inference system includes a dataflow analysis to track memory offsets and tag information. Finally, our type system includes garbage collection information to ensure that pointers from the FFI to the OCaml heap are tracked properly. We have implemented our inference system and applied it to a small set of benchmarks. Our results show that programmers do misuse these interfaces, and our implementation has found several bugs and questionable coding practices in our benchmarks.
引用
收藏
页码:62 / 72
页数:11
相关论文
共 10 条
[1]  
[Anonymous], P ICFP ICFP 99
[2]  
*ANSI, 1999, PROGR LANG C
[3]  
BEAZLEY DM, SWIG EASY TOOL INTEG
[4]  
BENTON N, 2001, BABEL 01 1 INT WORKS, V59
[5]  
BLUME M, LONGER FOREIGN TEACH
[6]  
CHANDRA S, 1999, P ACM SIGPLAN SIGSOF, P66
[7]  
Christensen AS, 2003, LECT NOTES COMPUT SC, V2694, P1
[8]  
DeLine Rob, 2004, The Fugue Protocol Technical Report MSR-TR-2004-07. Checker: Is Your Software Baroque?
[9]   Modern languages and Microsoft's Component Object Model [J].
Gray, DN ;
Hotchkiss, J ;
LaForge, S ;
Shalit, A ;
Weinberg, T .
COMMUNICATIONS OF THE ACM, 1998, 41 (05) :55-65
[10]   Language integration in the common language runtime [J].
Hamilton, J .
ACM SIGPLAN NOTICES, 2003, 38 (02) :19-28