Sparse

From Linux PARISC Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "= Sparse = Sparse is a tool to do compile-time checks on C code. Sparse can create a parse tree of C code, similar to a GCC frontend. Using this parse tree, it is possible to...")
 
m
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
= Sparse =
 
 
 
Sparse is a tool to do compile-time checks on C code. Sparse can create a parse tree of C code, similar to a GCC frontend. Using this parse tree, it is possible to create additional compile-time checks of source code, in addition to what regular C provides.  
 
Sparse is a tool to do compile-time checks on C code. Sparse can create a parse tree of C code, similar to a GCC frontend. Using this parse tree, it is possible to create additional compile-time checks of source code, in addition to what regular C provides.  
  
For example, a system call can be passed a userspace pointer. In regular C, this will simply be a `void *`. However, the kernel cannot directly dereference this pointer. There is no syntax to denote this restriction in regular C, and if a kernel developer makes a mistake, s/he will only discover it at runtime, probably in the form of a kernel crash. Sparse allows a developer to encode this restriction by annotating the pointer as `void __user *`, where `__user` denotes a separate address space.
+
For example, a system call can be passed a userspace pointer. In regular C, this will simply be a <tt>void *</tt>. However, the kernel cannot directly dereference this pointer. There is no syntax to denote this restriction in regular C, and if a kernel developer makes a mistake, s/he will only discover it at runtime, probably in the form of a kernel crash. Sparse allows a developer to encode this restriction by annotating the pointer as <tt>void __user *</tt>, where <tt>__user</tt> denotes a separate address space.
  
 
There are currently three address spaces recognized by the kernel:
 
There are currently three address spaces recognized by the kernel:
  
* User address space, annotated with `__user`
+
* User address space, annotated with <tt>__user</tt>
 
* Kernel address space, no annotation
 
* Kernel address space, no annotation
* I/O memory address space, annotated with `__iomem`
+
* I/O memory address space, annotated with <tt>__iomem</tt>
  
These are defined in `include/linux/compiler.h`
+
These are defined in <tt>include/linux/compiler.h</tt>
  
 
More information about sparse can be found at http://www.linuxjournal.com/article.php?sid=7272 and http://kerneltrap.org/node/view/3848. The sparse mailing list is at http://vger.kernel.org/vger-lists.html#linux-sparse
 
More information about sparse can be found at http://www.linuxjournal.com/article.php?sid=7272 and http://kerneltrap.org/node/view/3848. The sparse mailing list is at http://vger.kernel.org/vger-lists.html#linux-sparse
  
The sparse source code is kept in [[http://www.bkbits.net/|BitKeeper]] at bk://kernel.bkbits.net/torvalds/sparse, snapshots can be found at http://www.codemonkey.org.uk/projects/bitkeeper/sparse/
+
The sparse source code is kept in [http://www.bkbits.net/ BitKeeper] at bk://kernel.bkbits.net/torvalds/sparse, snapshots can be found at http://www.codemonkey.org.uk/projects/bitkeeper/sparse/

Latest revision as of 20:59, 30 May 2014

Sparse is a tool to do compile-time checks on C code. Sparse can create a parse tree of C code, similar to a GCC frontend. Using this parse tree, it is possible to create additional compile-time checks of source code, in addition to what regular C provides.

For example, a system call can be passed a userspace pointer. In regular C, this will simply be a void *. However, the kernel cannot directly dereference this pointer. There is no syntax to denote this restriction in regular C, and if a kernel developer makes a mistake, s/he will only discover it at runtime, probably in the form of a kernel crash. Sparse allows a developer to encode this restriction by annotating the pointer as void __user *, where __user denotes a separate address space.

There are currently three address spaces recognized by the kernel:

  • User address space, annotated with __user
  • Kernel address space, no annotation
  • I/O memory address space, annotated with __iomem

These are defined in include/linux/compiler.h

More information about sparse can be found at http://www.linuxjournal.com/article.php?sid=7272 and http://kerneltrap.org/node/view/3848. The sparse mailing list is at http://vger.kernel.org/vger-lists.html#linux-sparse

The sparse source code is kept in BitKeeper at bk://kernel.bkbits.net/torvalds/sparse, snapshots can be found at http://www.codemonkey.org.uk/projects/bitkeeper/sparse/

Personal tools