Unreliable Guide To Hacking The Linux Kernel

Paul Rusty Russell

      
     

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
2.1. User Context
2.2. Hardware Interrupts (Hard IRQs)
2.3. Software Interrupt Context: Bottom Halves, Tasklets, softirqs
3. Some Basic Rules
4. ioctls: Not writing a new system call
5. Recipes for Deadlock
6. Common Routines
6.1. printk() include/linux/kernel.h
6.2. copy_[to/from]_user() / get_user() / put_user() include/asm/uaccess.h
6.3. kmalloc()/kfree() include/linux/slab.h
6.4. current include/asm/current.h
6.5. udelay()/mdelay() include/asm/delay.h include/linux/delay.h
6.6. cpu_to_be32()/be32_to_cpu()/cpu_to_le32()/le32_to_cpu() include/asm/byteorder.h
6.7. local_irq_save()/local_irq_restore() include/asm/system.h
6.8. local_bh_disable()/local_bh_enable() include/asm/softirq.h
6.9. smp_processor_id()/cpu_[number/logical]_map() include/asm/smp.h
6.10. __init/__exit/__initdata include/linux/init.h
6.11. __initcall()/module_init() include/linux/init.h
6.12. module_exit() include/linux/init.h
6.13. MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT include/linux/module.h
7. Wait Queues include/linux/wait.h
7.1. Declaring
7.2. Queuing
7.3. Waking Up Queued Tasks
8. Atomic Operations
9. Symbols
9.1. EXPORT_SYMBOL() include/linux/module.h
9.2. EXPORT_NO_SYMBOLS include/linux/module.h
9.3. EXPORT_SYMBOL_GPL() include/linux/module.h
10. Routines and Conventions
10.1. Double-linked lists include/linux/list.h
10.2. Return Conventions
10.3. Breaking Compilation
10.4. Initializing structure members
10.5. GNU Extensions
10.6. C++
10.7. #if
11. Putting Your Stuff in the Kernel
12. Kernel Cantrips
13. Thanks