Unreliable Guide To Hacking The Linux Kernel

Rusty Russell


This is the first release of this document as part of the kernel tarball.

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.

Table of Contents

1. Introduction
2. The Players
User Context
Hardware Interrupts (Hard IRQs)
Software Interrupt Context: Softirqs and Tasklets
3. Some Basic Rules
4. ioctls: Not writing a new system call
5. Recipes for Deadlock
6. Common Routines
printk() include/linux/kernel.h
copy_[to/from]_user() / get_user() / put_user() include/linux/uaccess.h
kmalloc()/kfree() include/linux/slab.h
current include/asm/current.h
mdelay()/udelay() include/asm/delay.h include/linux/delay.h
cpu_to_be32()/be32_to_cpu()/cpu_to_le32()/le32_to_cpu() include/asm/byteorder.h
local_irq_save()/local_irq_restore() include/linux/irqflags.h
local_bh_disable()/local_bh_enable() include/linux/interrupt.h
smp_processor_id() include/asm/smp.h
__init/__exit/__initdata include/linux/init.h
__initcall()/module_init() include/linux/init.h
module_exit() include/linux/init.h
try_module_get()/module_put() include/linux/module.h
7. Wait Queues include/linux/wait.h
Waking Up Queued Tasks
8. Atomic Operations
9. Symbols
EXPORT_SYMBOL() include/linux/export.h
EXPORT_SYMBOL_GPL() include/linux/export.h
10. Routines and Conventions
Double-linked lists include/linux/list.h
Return Conventions
Breaking Compilation
Initializing structure members
GNU Extensions
11. Putting Your Stuff in the Kernel
12. Kernel Cantrips
13. Thanks