1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;3.&#160;Some Basic Rules</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="basics-softirqs.html" title="Software Interrupt Context: Softirqs and Tasklets"><link rel="next" href="ioctls.html" title="Chapter&#160;4.&#160;ioctls: Not writing a new system call"></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;3.&#160;Some Basic Rules</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="basics-softirqs.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="ioctls.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="basic-rules"></a>Chapter&#160;3.&#160;Some Basic Rules</h1></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">No memory protection</span></dt><dd><p>
2      If you corrupt memory, whether in user context or
3      interrupt context, the whole machine will crash.  Are you
4      sure you can't do what you want in userspace?
5     </p></dd><dt><span class="term">No floating point or <acronym class="acronym">MMX</acronym></span></dt><dd><p>
6      The <acronym class="acronym">FPU</acronym> context is not saved; even in user
7      context the <acronym class="acronym">FPU</acronym> state probably won't
8      correspond with the current process: you would mess with some
9      user process' <acronym class="acronym">FPU</acronym> state.  If you really want
10      to do this, you would have to explicitly save/restore the full
11      <acronym class="acronym">FPU</acronym> state (and avoid context switches).  It
12      is generally a bad idea; use fixed point arithmetic first.
13     </p></dd><dt><span class="term">A rigid stack limit</span></dt><dd><p>
14      Depending on configuration options the kernel stack is about 3K to 6K for most 32-bit architectures: it's
15      about 14K on most 64-bit archs, and often shared with interrupts
16      so you can't use it all.  Avoid deep recursion and huge local
17      arrays on the stack (allocate them dynamically instead).
18     </p></dd><dt><span class="term">The Linux kernel is portable</span></dt><dd><p>
19      Let's keep it that way.  Your code should be 64-bit clean,
20      and endian-independent.  You should also minimize CPU
21      specific stuff, e.g. inline assembly should be cleanly
22      encapsulated and minimized to ease porting.  Generally it
23      should be restricted to the architecture-dependent part of
24      the kernel tree.
25     </p></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="basics-softirqs.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="ioctls.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Software Interrupt Context: Softirqs and Tasklets&#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;4.&#160;ioctls: Not writing a new system call</td></tr></table></div></body></html>
26