|
linux.device.drivers
=====================
1. modules
-- insmod, insert a module in kernel, and run the init function which is specified by
module_init(<init func>);
-- rmmod, remove a module from kernel, and run the exit function which is specified by
module_exit(<exit func>);
modules vs applications
All event-driven applications can be implemented as modules.
module's exit function must undo everything the init function built up.(i.e. free resources)
But application may not always do those all.
A module, on the other hand, is linked only to the kernel, and the only functions it can call are the ones exported by the kernel;
an application can call functions it doesn't define, only if it is defined in shared lib.
2.
printk() is defined in kernel, but it do not support floating-point.
因为module没有lib可用,所以不要include那些常用的head file, i.e. stdarg.h
all head file can be included in module, is include/linux and include/asm
Concurrency in the Kernel
kernel code and driver code must be reentrant(可重入的)
'current' is the global item that can be used in kernel programing.
I.e.
printk(KERN_INFO "The process is \"%s\" (pid %i)\n",
current->comm, current->pid);
Kernel's stack size is only 4KB.
So if you need larger structures, just get memory by malloc instead of apply great buffer by automatic variables.
obj-m := module.o
module-objs := file1.o file2.o
all system calls has a same prefix: 'sys_' |
|