1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;12.&#160;Kernel Cantrips</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="prev" href="submitting.html" title="Chapter&#160;11.&#160;Putting Your Stuff in the Kernel"><link rel="next" href="credits.html" title="Chapter&#160;13.&#160;Thanks"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;12.&#160;Kernel Cantrips</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="submitting.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="credits.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="cantrips"></a>Chapter&#160;12.&#160;Kernel Cantrips</h1></div></div></div><p>
2   Some favorites from browsing the source.  Feel free to add to this
3   list.
4  </p><p>
5   <code class="filename">arch/x86/include/asm/delay.h:</code>
6  </p><pre class="programlisting">
7#define ndelay(n) (__builtin_constant_p(n) ? \
8        ((n) &gt; 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \
9        __ndelay(n))
10  </pre><p>
11   <code class="filename">include/linux/fs.h</code>:
12  </p><pre class="programlisting">
13/*
14 * Kernel pointers have redundant information, so we can use a
15 * scheme where we can return either an error code or a dentry
16 * pointer with the same return value.
17 *
18 * This should be a per-architecture thing, to allow different
19 * error and pointer decisions.
20 */
21 #define ERR_PTR(err)    ((void *)((long)(err)))
22 #define PTR_ERR(ptr)    ((long)(ptr))
23 #define IS_ERR(ptr)     ((unsigned long)(ptr) &gt; (unsigned long)(-1000))
24</pre><p>
25   <code class="filename">arch/x86/include/asm/uaccess_32.h:</code>
26  </p><pre class="programlisting">
27#define copy_to_user(to,from,n)                         \
28        (__builtin_constant_p(n) ?                      \
29         __constant_copy_to_user((to),(from),(n)) :     \
30         __generic_copy_to_user((to),(from),(n)))
31  </pre><p>
32   <code class="filename">arch/sparc/kernel/head.S:</code>
33  </p><pre class="programlisting">
34/*
35 * Sun people can't spell worth damn. "compatability" indeed.
36 * At least we *know* we can't spell, and use a spell-checker.
37 */
38
39/* Uh, actually Linus it is I who cannot spell. Too much murky
40 * Sparc assembly will do this to ya.
41 */
42C_LABEL(cputypvar):
43        .asciz "compatibility"
44
45/* Tested on SS-5, SS-10. Probably someone at Sun applied a spell-checker. */
46        .align 4
47C_LABEL(cputypvar_sun4m):
48        .asciz "compatible"
49  </pre><p>
50   <code class="filename">arch/sparc/lib/checksum.S:</code>
51  </p><pre class="programlisting">
52        /* Sun, you just can't beat me, you just can't.  Stop trying,
53         * give up.  I'm serious, I am going to kick the living shit
54         * out of you, game over, lights out.
55         */
56  </pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="submitting.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="credits.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;11.&#160;Putting Your Stuff in the Kernel&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;13.&#160;Thanks</td></tr></table></div></body></html>
57