<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Chapter 12. Kernel Cantrips</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><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="ch11.html" title="Chapter 11. Putting Your Stuff in the Kernel" /><link rel="next" href="ch13.html" title="Chapter 13. Thanks" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 12. Kernel Cantrips</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch11.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch13.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 12. Kernel Cantrips"><div class="titlepage"><div><div><h2 class="title"><a id="cantrips"></a>Chapter 12. Kernel Cantrips</h2></div></div></div><p> Some favorites from browsing the source. Feel free to add to this list. </p><p> <code class="filename">arch/x86/include/asm/delay.h:</code> </p><pre class="programlisting"> #define ndelay(n) (__builtin_constant_p(n) ? \ ((n) > 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \ __ndelay(n)) </pre><p> <code class="filename">include/linux/fs.h</code>: </p><pre class="programlisting"> /* * Kernel pointers have redundant information, so we can use a * scheme where we can return either an error code or a dentry * pointer with the same return value. * * This should be a per-architecture thing, to allow different * error and pointer decisions. */ #define ERR_PTR(err) ((void *)((long)(err))) #define PTR_ERR(ptr) ((long)(ptr)) #define IS_ERR(ptr) ((unsigned long)(ptr) > (unsigned long)(-1000)) </pre><p> <code class="filename">arch/x86/include/asm/uaccess_32.h:</code> </p><pre class="programlisting"> #define copy_to_user(to,from,n) \ (__builtin_constant_p(n) ? \ __constant_copy_to_user((to),(from),(n)) : \ __generic_copy_to_user((to),(from),(n))) </pre><p> <code class="filename">arch/sparc/kernel/head.S:</code> </p><pre class="programlisting"> /* * Sun people can't spell worth damn. "compatability" indeed. * At least we *know* we can't spell, and use a spell-checker. */ /* Uh, actually Linus it is I who cannot spell. Too much murky * Sparc assembly will do this to ya. */ C_LABEL(cputypvar): .asciz "compatability" /* Tested on SS-5, SS-10. Probably someone at Sun applied a spell-checker. */ .align 4 C_LABEL(cputypvar_sun4m): .asciz "compatible" </pre><p> <code class="filename">arch/sparc/lib/checksum.S:</code> </p><pre class="programlisting"> /* Sun, you just can't beat me, you just can't. Stop trying, * give up. I'm serious, I am going to kick the living shit * out of you, game over, lights out. */ </pre></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch11.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch13.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 11. Putting Your Stuff in the Kernel </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 13. Thanks</td></tr></table></div></body></html>