I could easily have squeezed a few more chapters into this book. I could have added a chapter about creating new file systems, or about adding new protocol stacks (as if there's a need for that -- you'd have to dig underground to find a protocol stack not supported by Linux). I could have added explanations of the kernel mechanisms we haven't touched upon, such as bootstrapping or the disk interface.
However, I chose not to. My purpose in writing this book was to provide initiation into the mysteries of kernel module programming and to teach the common techniques for that purpose. For people seriously interested in kernel programming, I recommend Juan-Mariano de Goyeneche's list of kernel resources . Also, as Linus said, the best way to learn the kernel is to read the source code yourself.
If you're interested in more examples of short kernel modules, I recommend Phrack magazine. Even if you're not interested in security, and as a programmer you should be, the kernel modules there are good examples of what you can do inside the kernel, and they're short enough not to require too much effort to understand.
I hope I have helped you in your quest to become a better programmer, or at least to have fun through technology. And, if you do write useful kernel modules, I hope you publish them under the GPL, so I can use them too.
Index
Symbols
-
/etc/conf.modules,
How Do Modules Get Into The Kernel?
/etc/modules.conf,
How Do Modules Get Into The Kernel?
/proc filesystem,
The /proc File System
/proc/interrupts,
Interrupt Handlers
/proc/ksyms,
Functions available to modules,
Name Space,
Common Pitfalls
/proc/meminfo,
The /proc File System
/proc/modules,
How Do Modules Get Into The Kernel?,
The /proc File System
2.2 changes,
Changes between 2.0 and 2.2
_IO,
Talking to Device Files (writes and IOCTLs)}
_IOR,
Talking to Device Files (writes and IOCTLs)}
_IOW,
Talking to Device Files (writes and IOCTLs)}
_IOWR,
Talking to Device Files (writes and IOCTLs)}
_NSIG_WORDS,
Changes between 2.0 and 2.2
__exit,
Hello World (part 3): The __init and __exit Macros
__init,
Hello World (part 3): The __init and __exit Macros
__initdata,
Hello World (part 3): The __init and __exit Macros
__initfunction(),
Hello World (part 3): The __init and __exit Macros
__NO_VERSION__,
Modules Spanning Multiple Files
A
-
asm
-
-
uaccess.h,
Changes between 2.0 and 2.2
asm/uaccess.h,
Changes between 2.0 and 2.2
B
-
BH_IMMEDIATE,
Interrupt Handlers
blocking processes,
Blocking Processes
blocking, how to avoid,
Replacing printk
bottom half,
Interrupt Handlers
busy,
Replacing printk
C
-
carnivore
-
-
large,
Common Pitfalls
cleanup_module(),
Hello, World (part 1): The Simplest Module
close,
Changes between 2.0 and 2.2
code space,
Code space
coffee,
Major and Minor Numbers
CPU
-
-
multiple,
Symmetrical Multi-Processing
crontab,
Scheduling Tasks
ctrl-c,
Replacing printk
current task,
Replacing printk
D
-
DEFAULT_MESSAGE_LOGLEVEL,
Introducing printk()
defining ioctls,
Talking to Device Files (writes and IOCTLs)}
device file
-
-
character,
Character Device Drivers
device files
E
-
EAGAIN,
Replacing printk
EINTR,
Replacing printk
elf_i386,
Modules Spanning Multiple Files
ENTRY(system call),
System Calls
entry.S,
System Calls
F
-
file,
The file structure
filesystem
-
-
/proc,
The /proc File System
registration,
Using /proc For Input
filesystem registration,
Using /proc For Input
file_operations,
The file_operations Structure
file_operations structure,
Using /proc For Input
flush,
Changes between 2.0 and 2.2
G
-
get_user,
Using /proc For Input,
Changes between 2.0 and 2.2
H
-
handlers
-
-
interrupt,
Interrupt Handlers
housekeeping,
Scheduling Tasks
Hurd,
Code space
I
-
inb,
Keyboards on the Intel Architecture
init_module(),
Hello, World (part 1): The Simplest Module
inode,
The file structure,
The /proc File System
inode_operations structure,
Using /proc For Input
input
-
-
using /proc for,
Using /proc For Input
insmod,
Compiling Kernel Modules,
System Calls
Intel architecture
-
-
keyboard,
Keyboards on the Intel Architecture
interrupt 0x80,
System Calls
interrupt handlers,
Interrupt Handlers
interruptible_sleep_on,
Replacing printk
interrupts,
Changes between 2.0 and 2.2
-
-
disabling,
Common Pitfalls
ioctl,
Talking to Device Files (writes and IOCTLs)}
-
-
defining,
Talking to Device Files (writes and IOCTLs)}
official assignment,
Talking to Device Files (writes and IOCTLs)}
irqs,
Changes between 2.0 and 2.2
K
-
kernel
-
-
versions,
Changes between 2.0 and 2.2
kernel versions,
Writing Modules for Multiple Kernel Versions
kerneld,
How Do Modules Get Into The Kernel?
kernel/_version,
Modules Spanning Multiple Files
KERNEL_VERSION,
Writing Modules for Multiple Kernel Versions
keyboard,
Keyboards on the Intel Architecture
kmod,
How Do Modules Get Into The Kernel?
L
-
ld,
Modules Spanning Multiple Files
libraries
-
-
standard,
Common Pitfalls
library function,
Functions available to modules
LINUX_VERSION_CODE,
Writing Modules for Multiple Kernel Versions
M
-
major number,
Major and Minor Numbers
-
-
dynamic allocation,
Registering A Device
mark_bh,
Interrupt Handlers
memory segments,
Using /proc For Input
microkernel,
Code space
minor number,
Major and Minor Numbers
mknod,
Major and Minor Numbers
modem,
Talking to Device Files (writes and IOCTLs)}
module
-
-
parameters,
Changes between 2.0 and 2.2
module parameters,
Changes between 2.0 and 2.2
module.h,
Modules Spanning Multiple Files
modules.conf
- MODULE_AUTHOR(), Hello World (part 4): Licensing and Module Documentation module_cleanup, Scheduling Tasks MODULE_DESCRIPTION(), Hello World (part 4): Licensing and Module Documentation module_exit, Hello World (part 2) module_init, Hello World (part 2) module_interruptible_sleep_on, Replacing printk MODULE_LICENSE(), Hello World (part 4): Licensing and Module Documentation MODULE_PARM, Changes between 2.0 and 2.2 module_permissions, Using /proc For Input module_sleep_on, Replacing printk, Scheduling Tasks MODULE_SUPPORTED_DEVICE(), Hello World (part 4): Licensing and Module Documentation module_wake_up, Replacing printk MOD_DEC_USE_COUNT, Unregistering A Device MOD_INC_USE_COUNT, Unregistering A Device, System Calls MOD_IN_USE, Unregistering A Device monolithic kernel, Code space multi-processing, Symmetrical Multi-Processing multi-tasking, Replacing printk multitasking, Replacing printk
N
-
namespace pollution,
Name Space
Neutrino,
Code space
non-blocking,
Replacing printk
O
-
official ioctl assignment,
Talking to Device Files (writes and IOCTLs)}
O_NONBLOCK,
Replacing printk
P
-
permission,
Using /proc For Input
pointer
-
-
current,
Using /proc For Input
printk
-
-
replacing,
Replacing printk
printk(),
Introducing printk()
proc
-
-
using for input,
Using /proc For Input
proc file
-
-
ksyms,
Common Pitfalls
processes
-
-
blocking,
Blocking Processes
killing,
Replacing printk
waking up,
Replacing printk
processing
-
-
multi,
Symmetrical Multi-Processing
proc_dir_entry,
Using /proc For Input
proc_register,
The /proc File System,
Changes between 2.0 and 2.2
proc_register_dynamic,
The /proc File System,
Changes between 2.0 and 2.2
putting processes to sleep,
Replacing printk
put_user,
Using /proc For Input,
Changes between 2.0 and 2.2
Q
-
queue_task,
Scheduling Tasks,
Interrupt Handlers,
Changes between 2.0 and 2.2
queue_task_irq,
Interrupt Handlers,
Changes between 2.0 and 2.2
R
-
read,
Changes between 2.0 and 2.2
-
-
in the kernel,
Using /proc For Input
reference count,
Scheduling Tasks
refund policy,
Common Pitfalls
register_chrdev,
Registering A Device
request_irq(),
Interrupt Handlers
rmmod,
System Calls,
Scheduling Tasks
-
-
preventing,
Unregistering A Device
S
-
SA_INTERRUPT,
Interrupt Handlers
SA_SHIRQ,
Interrupt Handlers
scheduler,
Replacing printk
scheduling tasks,
Scheduling Tasks
segment
-
-
memory,
Using /proc For Input
serial port,
Talking to Device Files (writes and IOCTLs)}
shutdown,
System Calls
SIGINT,
Replacing printk
signal,
Replacing printk
signals,
Changes between 2.0 and 2.2
sleep
-
-
putting processes to,
Replacing printk
sleep_on,
Replacing printk,
Scheduling Tasks
SMP,
Symmetrical Multi-Processing,
Changes between 2.0 and 2.2
source file
-
-
chardev.c,
Talking to Device Files (writes and IOCTLs)}
chardev.h,
Talking to Device Files (writes and IOCTLs)}
hello-1.c,
Hello, World (part 1): The Simplest Module
hello-2.c,
Hello World (part 2)
hello-3.c,
Hello World (part 3): The __init and __exit Macros
hello-4.c,
Hello World (part 4): Licensing and Module Documentation
hello-5.c,
Passing Command Line Arguments to a Module
intrpt.c,
Keyboards on the Intel Architecture
ioctl.c,
Talking to Device Files (writes and IOCTLs)}
print_string.c,
Replacing printk
procfs.c,
System Calls
sched.c,
Scheduling Tasks
sleep.c,
Replacing printk
start.c,
Modules Spanning Multiple Files
stop.c,
Modules Spanning Multiple Files
source files
-
-
multiple,
Modules Spanning Multiple Files
ssize_t,
Changes between 2.0 and 2.2
standard libraries,
Common Pitfalls
strace,
Functions available to modules,
System Calls
struct
-
-
tty,
Replacing printk
struct file_operations,
Using /proc For Input
struct inode_operations,
Using /proc For Input
structure
-
-
file_operations,
Changes between 2.0 and 2.2
symbol table,
Name Space
symmetrical multi-processing,
Symmetrical Multi-Processing,
Changes between 2.0 and 2.2
sync,
System Calls
system call,
Functions available to modules,
System Calls
-
-
open,
System Calls
system calls,
System Calls
sys_call_table,
System Calls
sys_open,
System Calls
T
-
task,
Scheduling Tasks
-
-
current,
Replacing printk
tasks
-
-
scheduling,
Scheduling Tasks
TASK_INTERRUPTIBLE,
Replacing printk
tq_immediate,
Interrupt Handlers
tq_struct,
Scheduling Tasks
tq_timer,
Scheduling Tasks
tty_structure,
Replacing printk
V
-
version.h,
Modules Spanning Multiple Files
W
-
waking up processes,
Replacing printk
write,
Changes between 2.0 and 2.2
-
-
in the kernel,
Using /proc For Input
本文档详细介绍了Linux内核模块编程的基础知识和技术要点,包括如何编写简单的内核模块、设备文件交互、中断处理等内容,并提供了实用的示例代码。

被折叠的 条评论
为什么被折叠?



