skip to main content
research-article

A theory of platform-dependent low-level software

Published:07 January 2008Publication History
Skip Abstract Section

Abstract

The C language definition leaves the sizes and layouts of types partially unspecified. When a C program makes assumptions about type layout, its semantics is defined only on platforms (C compilers and the underlying hardware) on which those assumptions hold. Previous work on formalizing C-like languages has ignored this issue, either by assuming that programs do not make such assumptions or by assuming that all valid programs target only one platform. In the latter case, the platform's choices are hard-wired in the language semantics.

In this paper, we present a practically-motivated model for a C-like language in which the memory layouts of types are left largely unspecified. The dynamic semantics is parameterized by a platform's layout policy and makes manifest the consequence of platform-dependent (i.e., unspecified) steps. A type-and-effect system produces a layout constraint: a logic formula encoding layout conditions under which the program is memory-safe. We prove that if a program type-checks, it is memory-safe on all platforms satisfying its constraint.

Based on our theory, we have implemented a tool that discovers unportable layout assumptions in C programs. Our approach should generalize to other kinds of platform-dependent assumptions.

References

  1. Amal Ahmed and David Walker. The logical approach to stack typing. In International Workshop on Types in Language Design and Implementation, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Aleph One Limited. The ARMLinux Book Online, Chapter 10. 2005. http://www.aleph1.co.uk/armlinux/book.Google ScholarGoogle Scholar
  3. Robert M. Amadio and Luca Cardelli. Subtyping recursive types. ACM Transactions on Programming Languages and Systems, 15 (4), 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. David F. Bacon. Kava: a Java dialect with a uniform object model for lightweight classes. Concurrency and Computation: Practice and Experience, 15 (3--5), 2003.Google ScholarGoogle ScholarCross RefCross Ref
  5. Sandrine Blazy, Zaynah Dargaye, and Xavier Leroy. Formal verification of a C compiler front-end. In 14th International Symposium on Formal Methods, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. C Standard 1999. ISO/IEC 9899:1999, International Standard-Programming Languages-C. International Standards Organization, 1999.Google ScholarGoogle Scholar
  7. Satish Chandra and Tom Reps. Physical type checking for C. In Workshop on Program Analysis for Software Tools and Engineering, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Juan Chen, Dinghao Wu, Andrew W. Appel, and Hai Fang. A provably sound TAL for back-end optimization. In ACM Conference on Programming Language Design and Implementation, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Jeremy Condit, Matthew Harren, Scott McPeak, George Necula, and Westley Weimer. CCured in the real world. In ACM Conference on Programming Language Design and Implementation, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Jeremy Condit, Matthew Harren, Zachary Anderson, David Gay, and George Necula. Dependent types for low-level programming. In European Symposium on Programming, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Karl Crary. Toward a foundational typed assembly language. In 30th ACM Symposium on Principles of Programming Languages, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Dinakar Dhurjati, Sumant Kowshik, and Vikram Adve. SAFECode: Enforcing alias analysis for weakly typed languages. In ACM Conference on Programming Language Design and Implementation, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Dan Grossman. Type-safe multithreading in Cyclone. In International Workshop on Types in Language Design and Implementation, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Dan Grossman. Quantified types in imperative languages. ACM Transactions on Programming Languages and Systems, 28 (3), 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. Region-based memory management in Cyclone. In ACM Conference on Programming Language Design and Implementation, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Thomas Hallgren, Mark P. Jones, Rebekah Leslie, and Andrew Tolmach. A principled approach to operating system construction in Haskell. In 10th ACM International Conference on Functional Programming, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Nadeem A. Hamid, Zhong Shao, Valery Trifonov, Stefan Monnier, and Zhaozhong Ni. A syntactic approach to foundational proof-carrying code. Journal of Automated Reasoning, 31 (3--4), 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. IBM. Developing embedded software for the IBM PowerPC 970FX processor. Application Note 970, IBM, 2004. http://www.ibm.com/chips/techlib/.Google ScholarGoogle Scholar
  19. Trevor Jim, Greg Morrisett, Dan Grossman, Michael Hicks, James Cheney, and Yanling Wang. Cyclone: A safe dialect of C. In USENIX Annual Technical Conference, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Xavier Leroy. Formal certification of a compiler back-end. In 33rd ACM Symposium on Principles of Programming Languages, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Robert Love. Linux Kernel Development, Second Edition. Novell Press, 2005. Page 328. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Brad Martin, Anita Rettinger, and Jasmit Singh. Multiplatform porting to 64 bits. Dr. Dobb's Journal, 2005.Google ScholarGoogle Scholar
  23. Antoine Mine. Field-sensitive value analysis of embedded c programs with union types and pointer arithmetics. In Conference on Language, Compilers, and Tool Support for Embedded Systems, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From System F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21 (3), 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. George Necula. Proof-carrying code. In 24th ACM Symposium on Principles of Programming Languages, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. George Necula, Scott McPeak, Shree Prakash Rahul, and Westley Weimer. CIL: Intermediate language and tools for analysis and transformation of C programs. In Conference on Compiler Construction, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. George Necula, Scott McPeak, and Westley Weimer. CCured: Type-safe retrofitting of legacy code. In 29th ACM Symposium on Principles of Programming Languages, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. George Necula, Jeremy Condit, Matthew Harren, Scott McPeak, and Westley Weimer. CCured: Type-safe retrofitting of legacy software. ACM Transactions on Programming Languages and Systems, 27 (3), 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Marius Nita, Dan Grossman, and Craig Chambers. A theory of platform-dependent low-level software (extended version). 2007. Available at http://www.cs.washington.edu/homes/marius/papers/tpd/.Google ScholarGoogle Scholar
  30. Michael Norrish. C formalised in HOL. PhD thesis, University of Cambridge, 1998.Google ScholarGoogle Scholar
  31. Leaf Petersen, Robert Harper, Karl Crary, and Frank Pfenning. A type theory for memory allocation and data layout. In 30th ACM Symposium on Principles of Programming Languages, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Norman Ramsey, Simon~Peyton Jones, and Christian Lindig. The C-language specification version 2.0, 2005. http://www.cminusminus.org/extern/man2.pdf.Google ScholarGoogle Scholar
  33. Micahel Siff, Satish Chandra, Thomas Ball, Krishna Kunchithapadam, and Thomas Reps. Coping with type casts in C. In 7th European Software Engineering Conference 7th ACM Symposium on the Foundations of Software Engineering, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Robert P. Wilson and Monica S. Lam. Efficient context-sensitive pointer analysis for C programs. In ACM Conference on Programming Language Design and Implementation, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A theory of platform-dependent low-level software

                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 43, Issue 1
                  POPL '08
                  January 2008
                  420 pages
                  ISSN:0362-1340
                  EISSN:1558-1160
                  DOI:10.1145/1328897
                  Issue’s Table of Contents
                  • cover image ACM Conferences
                    POPL '08: Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
                    January 2008
                    448 pages
                    ISBN:9781595936899
                    DOI:10.1145/1328438

                  Copyright © 2008 ACM

                  Publisher

                  Association for Computing Machinery

                  New York, NY, United States

                  Publication History

                  • Published: 7 January 2008

                  Check for updates

                  Qualifiers

                  • research-article

                PDF Format

                View or Download as a PDF file.

                PDF

                eReader

                View online with eReader.

                eReader
                About Cookies On This Site

                We use cookies to ensure that we give you the best experience on our website.

                Learn more

                Got it!