skip to main content
article

Checking type safety of foreign function calls

Published:12 June 2005Publication History
Skip Abstract Section

Abstract

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.

References

  1. ANSI. Programming languages -- C, 1999. ISO/IEC 9899:1999.]]Google ScholarGoogle Scholar
  2. D. M. Beazley. SWIG: An easy to use tool for integrating scripting languages with C and C++,.]]Google ScholarGoogle Scholar
  3. N. Benton and A. Kennedy, editors. BABEL'01: First International Workshop on Multi-Language Infrastructure and Interoperability, volume 59 of Electronic Notes in Theoretical Computer Science, Firenze, Italy, Sept. 2001. http://www.elsevier.nl/locate/entcs/volume59.html.]]Google ScholarGoogle Scholar
  4. M. Blume. No-Longer-Foreign: Teaching an ML compiler to speak C "natively". In Benton and Kennedy babel01. http://www.elsevier.nl/locate/entcs/volume59.html.]]Google ScholarGoogle Scholar
  5. S. Chandra and T. W. Reps. Physical Type Checking for C. In Proceedings of the ACM SIGPLAN/SIGSOFT Workshop on Program Analysis for Software Tools and Engineering, pages 66--75, Toulouse, France, Sept. 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. A. S. Christensen, A. Møller, and M. I. Schwartzbach. Precise Analysis of String Expressions. In R. Cousot, editor, Static Analysis, 10th International Symposium, volume 2694 of Lecture Notes in Computer Science, pages 1--18, San Diego, CA, USA, June 2003. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. R. DeLine and M. Fähndrich. The Fugue Protocol Checker: Is your software Baroque? Technical Report MSR-TR-2004-07, Microsoft Research, Jan. 2004.]]Google ScholarGoogle Scholar
  8. S. Finne, D. Leijen, E. Meijer, and S. P. Jones. Calling hell from heaven and heaven from hell. In Proceedings of the fourth ACM SIGPLAN International Conference on Functional Programming, pages 114--125, Paris, France, Sept. 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. K. Fisher, R. Pucella, and J. Reppy. A framework for interoperability. In Benton and Kennedy {3}. http://www.elsevier.nl/locate/entcs/volume59.html.]]Google ScholarGoogle Scholar
  10. M. Furr and J. S. Foster. Checking Type Safety of Foreign Function Calls. Technical Report CS-TR-4627, University of Maryland, Computer Science Department, Nov. 2004.]]Google ScholarGoogle Scholar
  11. C. Gould, Z. Su, and P. Devanbu. Static Checking of Dynamically Generated Queries in Database Applications. In Proceedings of the 26th International Conference on Software Engineering, pages 645--654, Edinburgh, Scotland, UK, May 2004.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. D. N. Gray, J. Hotchkiss, S. LaForge, A. Shalit, and T. Weinberg. Modern Languages and Microsoft's Component Object Model. Communications of the ACM, 41(5):55--65, May 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. J. Hamilton. Interlanguage Object Sharing with SOM. In Proceedings of the Usenix 1996 Annual Technical Conference, San Diego, California, Jan. 1996.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. J. Hamilton. Language Integration in the Common Language Runtime. ACM SIGPLAN Notices, 38(2):19--28, Feb. 2003.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. L. Huelsbergen. A Portable C Interface for Standard ML of New Jersey. http://www.smlnj.org//doc/SMLNJ-C/smlnj-c.ps, 1996.]]Google ScholarGoogle Scholar
  16. X. Leroy. The Objective Caml system, Aug. 2004. Release 3.08, http://caml.inria.fr/distrib/ocaml-3.08/ocaml-3.08-refman.pdf.]]Google ScholarGoogle Scholar
  17. S. Liang. The Java Native Interface: Programmer's Guide and Specification. Addison-Wesley, 1999.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. E. Meijer, N. Perry, and A. van Yzendoorn. Scripting .NET using Mondrian. In J. L. Knudsen, editor, ECOOP 2001 - Object-Oriented Programming, 15th European Conference, volume 2072 of Lecture Notes in Computer Science, pages 150--164, Budapest, Hungary, June 2001. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. G. Necula, S. McPeak, and W. Weimer. CCured: Type-Safe Retrofitting of Legacy Code. In Proceedings of the 29th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 128--139, Portland, Oregon, Jan. 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. G. C. Necula, S. McPeak, S. P. Rahul, and W. Weimer. CIL: Intermediate Language and Tools for Analysis and Transformation of C Programs. In R. N. Horspool, editor, Compiler Construction, 11th International Conference, volume 2304 of Lecture Notes in Computer Science, pages 213--228, Grenoble, France, Apr. 2002. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. D. Rémy. Typechecking records and variants in a natural extension of ML. In Proceedings of the 16th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 77--88, Austin, Texas, Jan. 1989.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. V. Trifonov and Z. Shao. Safe and Principled Language Interoperation. In D. Swierstra, editor, 8th European Symposium on Programming, volume 1576 of Lecture Notes in Computer Science, pages 128--146, Amsterdam, The Netherlands, Mar. 1999. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Checking type safety of foreign function calls

                Recommendations

                Comments

                Login options

                Check if you have access through your login credentials or your institution to get full access on this article.

                Sign in

                Full Access

                • Published in

                  cover image ACM SIGPLAN Notices
                  ACM SIGPLAN Notices  Volume 40, Issue 6
                  Proceedings of the 2005 ACM SIGPLAN conference on Programming language design and implementation
                  June 2005
                  325 pages
                  ISSN:0362-1340
                  EISSN:1558-1160
                  DOI:10.1145/1064978
                  Issue’s Table of Contents
                  • cover image ACM Conferences
                    PLDI '05: Proceedings of the 2005 ACM SIGPLAN conference on Programming language design and implementation
                    June 2005
                    338 pages
                    ISBN:1595930566
                    DOI:10.1145/1065010

                  Copyright © 2005 ACM

                  Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

                  Publisher

                  Association for Computing Machinery

                  New York, NY, United States

                  Publication History

                  • Published: 12 June 2005

                  Check for updates

                  Qualifiers

                  • article

                PDF Format

                View or Download as a PDF file.

                PDF

                eReader

                View online with eReader.

                eReader