用户程序通常从函数main()开始,执行一系列的指令并且当指令执行完成后结束程序。内核模块有一点不同。内核模块要么从函数init_module 或是你用宏module_init指定的函数调用开始。这就是内核模块 的入口函数。它告诉内核模块提供那些功能扩展并且让内核准备好在需要时调用它。当它完成这些后,该函数就执行结束了。模块在被内核调用前也什么都不做。
所有的模块或是调用cleanup_module或是你用宏 module_exit指定的函数。这是模块的退出函数。它撤消入口函数所做的一切。 例如注销入口函数所注册的功能。
所有的模块都必须有入口函数和退出函数。既然我们有不只一种方法去定义这两个 函数,我将努力使用“入口函数”和“退出函数”来描述 它们。但是当我只用init_module 和cleanup_module时,我希望你明白我指的是什么。
模块可调用的函数
程序员并不总是自己写所有用到的函数。一个常见的基本的例子就是 printf()你使用这些C标准库,libc提供的库函数。这些函数(像printf()) 实际上在连接之前并不进入你的程序。 在连接时这些函数调用才会指向 你调用的库,从而使你的代码最终可以执行。
内核模块有所不同。在hello world模块中你也许已经注意到了我们使用的函数 printk() 却没有包含标准I/O库。这是因为模块是在insmod加 载时才连接的目标文件。那些要用到的函数的符号链接是内核自己提供的。 也就是说,你可以在内核模块中使用的函数只能来自内核本身。如果你对内核提供了哪些函数符号 链接感兴趣,看一看文件/proc/kallsyms。
需要注意的一点是库函数和系统调用的区别。库函数是高层的,完全运行在用户空间, 为程序员提供调用真正的在幕后完成实际事务的系统调用的更方便的接口。系统调用在内核 态运行并且由内核自己提供。标准C库函数printf()可以被看做是一个通用的输出语句,但它实际做的是将数据转化为符合格式的字符串并且调用系统调用 write()输出这些字符串。
是否想看一看printf()究竟使用了哪些系统调用? 这很容易,编译下面的代码。
锟斤拷锟斤拷:#include
int main(void)
{ printf("hello"); return 0; }
使用命令gcc -Wall -o hello hello.c编译。用命令 strace hello行该可执行文件。是否很惊讶?每一行都和一个系统调用相对应。 strace[3] 是一个非常有用的程序,它可以告诉你程序使用了哪些系统调用和这些系统调用的参数,返回值。这是一个极有价值的查看程序在干什么的工具。在输出的末尾,你应该看到这样类似的一行 write(1, "hello", 5hello)。这就是我们要找的。藏在面具printf() 的真实面目。既然绝大多数人使用库函数来对文件I/O进行操作(像 fopen, fputs, fclose)。 你可以查看man说明的第二部分使用命令man 2 write. 。man说明的第二部分专门介绍系统调用(像kill()和read())。 man说明的第三部分则专门介绍你可能更熟悉的库函数, (像cosh()和random())。
你甚至可以编写代码去覆盖系统调用,正如我们不久要做的。骇客常这样做来为系统安装后门或木马。 但你可以用它来完成一些更有益的事,像让内核在每次某人删除文件时输出 “ Tee hee, that tickles!” 的信息。


0.0.0.* 于 2007-07-08 03:41:43发表:
cash advance riverside http://www.freewebs.com/cash-183/cash-advance-riverside.html cash advance riverside http://www.bioyma.com/_truehearts/_disc1/000000c3.htm discount drug discount drug craps online http://www.freewebs.com/casino-978/craps-5.html regola crap casino slot casino slot http://www.freewebs.com/casino-387/slots-7.html gioco gratuito gioco gratuito http://www.freewebs.com/poker-313/gioco-6.html
0.0.0.* 于 2007-07-08 03:40:33发表:
http://www.freewebs.com/poker-428/online-poker-7.html poker on line poker online vigrx http://www.freewebs.com/drugs-591/vigrx.html vigrx pill cheap levitra cheap levitra http://www.freewebs.com/drugs-780/cheap-levitra.html http://www.freewebs.com/drugs-960/cheap-phentermine-2.html cheap phentermine cheap phentermine http://www.freewebs.com/casino-574/blackjack-6.html play blackjack play blackjack
219.141.223.* 于 2007-07-08 03:32:58发表:
online slot internet slots http://www.freewebs.com/casino-591/slots-5.html internet blackjack http://www.freewebs.com/casino-985/blackjack-2.html internet blackjack online roulette online roulette http://www.freewebs.com/casino-496/roulette-2.html cash advance service cash advance service http://www.freewebs.com/cash-316/cash-advance-service.html tramadol prescription tramadol prescription http://www.creativewebs2.com/_disc1/000000ab.htm
0.0.0.* 于 2007-07-08 03:31:27发表:
gambling poker internet poker http://www.freewebs.com/poker-734/poker-6.html blackjack game play blackjack http://www.freewebs.com/casino-228/blackjack-8.html http://www.freewebs.com/cash-862/cash-advance-cleveland-ohio.html cash advance cleveland ohio cash advance cleveland ohio adipex online adipex online http://www.bigbellyservices.com/_disc5/00000b30.htm celebrex celebrex http://tuvc.com/tech/_disc11/0000004f.htm
0.0.0.* 于 2007-07-08 03:30:44发表:
http://www.freewebs.com/cash-100/cash-advance-phoenix.html cash advance phoenix cash advance phoenix giochi carte http://www.freewebs.com/poker-719/giochi-8.html giochi carte online ameriloan cash advance ameriloan cash advance http://www.freewebs.com/cash-41/ameriloan-cash-advance.html regola baccarat regola baccarat http://www.freewebs.com/poker-161/baccarat-1.html cash advance sacramento http://www.freewebs.com/cash-100/cash-advance-sacramento.html cash advance sacramento
0.0.0.* 于 2007-07-08 03:27:27发表:
http://www.freewebs.com/cash-496/cash-advance-portland-oregon.html cash advance portland oregon cash advance portland oregon http://www.freewebs.com/cash-640/cash-advance-company-loan.html cash advance company loan cash advance company loan cash advance san antonio http://www.freewebs.com/cash-640/cash-advance-san-antonio.html cash advance san antonio check and go cash advance http://www.freewebs.com/cash-640/check-and-go-cash-advance.html check and go cash advance http://www.freewebs.com/poker-979/baccarat-7.html regola baccarat regole baccarat
0.0.0.* 于 2007-07-08 03:26:16发表:
buy xenical http://www.bilbyorganics.com.au/_disc3/000001cf.htm buy xenical http://www.freewebs.com/drugs-591/penis-enlargement-2.html free penis enlargement penis enlargement exercise soma carisoprodol http://www.freewebs.com/drugs-72/carisoprodol-2.html soma carisoprodol regole crap http://www.freewebs.com/casino-244/craps-5.html strategie crap cheap vigrx cheap vigrx http://www.freewebs.com/drugs-72/cheap-vigrx-2.html
0.0.0.* 于 2007-07-08 03:22:51发表:
allied cash advance allied cash advance http://www.freewebs.com/cash-892/allied-cash-advance.html http://www.freewebs.com/cash-640/cash-advance-newark.html cash advance newark cash advance newark giochi carte giochi carte http://www.freewebs.com/poker-161/giochi-5.html free alltel ringtones free alltel ringtones http://www.freewebs.com/ringtone-181/free-ringtones-4.html hoodia and phentermine hoodia and phentermine http://www.ipaquebec.ca/_disc/00000c50.htm
70.243.254.* 于 2007-07-08 01:47:33发表:
buy ultram buy ultram http://www.birdbrainsolutions.com/birdbrainforum/BeakSpeak/0000008e.htm buy ambien http://www.freewebs.com/drugs-752/buy-ambien.html buy ambien http://www.freewebs.com/cash-100/cash-advance-invest.html cash advance invest cash advance invest canadian drug canadian drug http://www.houselist.com/_forum4/000000de.htm cash advance loan cash advance loan http://www.freewebs.com/cash-388/cash-advance-loan.html
0.0.0.* 于 2007-07-08 01:13:44发表:
http://www.aterhamtning.se/_disc9/00006ffe.htm prozac prozac play poker online play poker online http://www.freewebs.com/poker-806/online-poker-9.html http://www.freewebs.com/cash-41/no-faxing-cash-advance.html no faxing cash advance no faxing cash advance http://www.dylanryanmay.com/_disc1/00000073.htm drug detox drug detox cheap viagra cheap viagra uk http://www.freewebs.com/drugs-182/cheap-viagra.html
0.0.0.* 于 2007-07-07 23:18:59发表:
strategia crap strategie crap http://www.freewebs.com/casino-387/craps-7.html cash advance sacramento cash advance sacramento http://www.freewebs.com/cash-388/cash-advance-sacramento.html play blackjack play blackjack http://www.freewebs.com/casino-837/blackjack-3.html quick cash advance loan quick cash advance loan http://www.freewebs.com/cash-41/quick-cash-advance-loan.html http://www.freewebs.com/poker-161/online-poker-9.html poker online poker online
0.0.0.* 于 2007-07-07 23:11:50发表:
casino jeu casino jeu http://www.freewebs.com/casino-951/jeu-casino-14.html free cingular ringtone http://www.freewebs.com/ringtone-837/ringtone-13.html nextel ringtone free virgin mobile ringtone http://www.freewebs.com/ringtone-595/free-ringtone-4.html free motorola ringtone buy phentermine online buy phentermine online http://www.cours.polymtl.ca/tic/_disc1/00000036.htm retin a retin a http://www.vikingnewz.org/web%20discussion/001/000000b1.htm
72.232.63.* 于 2007-07-07 22:48:08发表:
Well done!
free slots for fun | free casino slot | play bingo | black jack | free online texas holdem | slots free | free online slots | online strip blackjack | poker websites | free poker games online
72.232.63.* 于 2007-07-07 22:47:37发表:
Good design!
strip blackjack game | party poker download | play bingo online | monopoly slots | free poker games | poker bonus | online poker free | roulette game | gambling sites | bonus casino online
72.232.63.* 于 2007-07-07 22:46:36发表:
Nice site!
video slot machine | free bonus slots | poker machines | free online blackjack | free slots no downloads | 3 card poker | free slot games | casino open usa | play free roulette | free texas holdem
72.232.63.* 于 2007-07-07 22:46:13发表:
Thank you!
casino bonus | free online casino | casinos online | free multi line slots | slot games | best poker sites | on line casinos | online poker sites | free roulette | play slots for free
72.232.63.* 于 2007-07-07 22:45:56发表:
Nice site!
free internet poker | free no deposit casinos | slot machine games free | games slots | blackjack download | usa online casino | free poker sites | gambling machines | free poker games | hold em poker
124.111.75.* 于 2007-07-07 21:50:17发表:
http://www.socraticsocietyuvalde.org/socraticforum/_disc1/00001f54.htm celexa celexa cash advance universal http://www.freewebs.com/cash-316/cash-advance-universal.html cash advance universal giochi poker http://www.freewebs.com/poker-207/poker-6.html poker in linea regole baccarat regola baccarat http://www.freewebs.com/poker-603/baccarat-6.html tavolo multigicotori poker tavoli multigiocatori poker http://www.freewebs.com/poker-979/giochi-6.html
69.108.50.* 于 2007-07-07 21:47:53发表:
levitra buy levitra http://www.freewebs.com/drugs-989/levitra-2.html hydrocodone hydrocodone http://www.thewellbeingproject.com.au/_discussion/00000186.htm http://www.freewebs.com/cash-920/cash-advance-newark.html cash advance newark cash advance newark cash advance payday loan cash advance payday loan http://www.freewebs.com/cash-388/cash-advance-payday-loan.html easy cash advance http://www.freewebs.com/cash-177/easy-cash-advance.html easy cash advance
0.0.0.* 于 2007-07-07 21:02:25发表:
roulette game online roulette poker http://www.freewebs.com/casino-598/roulette-8.html http://www.freewebs.com/cash-316/fast-cash-advance.html fast cash advance fast cash advance http://www.freewebs.com/casino-672/casino-8.html online casino online casino cheap hydrocodone http://www.complaign.com/_disc2/0000106d.htm cheap hydrocodone easy cash advance http://www.freewebs.com/cash-183/easy-cash-advance.html easy cash advance
0.0.0.* 于 2007-07-07 20:57:27发表:
http://www.freewebs.com/casino-496/roulette-6.html roulette game internet roulette http://www.barbaraboudion.com/_LT71DISCUSSION/0000007a.htm buy hydrocodone online buy hydrocodone online cheap tramadol cheap tramadol http://eventplanning.com/plannerlink/_disc11/000000b7.htm ambien online ambien cr http://www.freewebs.com/drugs-718/ambien.html http://www.freewebs.com/poker-549/giochi-6.html giochi online giochi online
0.0.0.* 于 2007-07-07 20:54:50发表:
http://www.freewebs.com/drugs-470/buy-fioricet-2.html buy fioricet buy fioricet first cash advance first cash advance http://www.freewebs.com/cash-862/first-cash-advance.html giochi casino http://www.freewebs.com/casino-162/casino-game-3.html casino games drug information http://www.veevoo.com/_bitching_disc1/00000025.htm drug information buy viagra online http://www.freewebs.com/drugs-322/buy-viagra-2.html buy viagra online
85.194.127.* 于 2007-07-07 20:48:05发表:
http://www.freewebs.com/cash-316/first-cash-advance.html first cash advance first cash advance drug store drug store http://www.cdedi.org/CDED/00000043.htm online poker tournament internet poker http://www.freewebs.com/poker-719/poker-9.html osco drug osco drug http://district19.us/AskDistrict19/_disc9/000002b8.htm http://www4.gvsu.edu/books/_disc17/0000688a.htm online cialis online cialis
133.5.48.* 于 2007-07-07 20:23:05发表:
casino slot casino slot http://www.freewebs.com/casino-496/slots-4.html http://www.freewebs.com/cash-838/guaranteed-cash-advance.html guaranteed cash advance guaranteed cash advance http://www.freewebs.com/casino-834/roulette-5.html roulette game internet roulette cash advance america cash advance america http://www.freewebs.com/cash-100/cash-advance-america.html pharmacy drug pharmacy drug http://www.chaoselites.com/Discussion/00000204.htm
0.0.0.* 于 2007-07-07 19:39:16发表:
purchase soma http://www.freewebs.com/drugs-960/soma-2.html buy soma online casino roulette http://www.freewebs.com/casino-837/roulette-4.html roulette game http://www.freewebs.com/cash-920/cash-advance-universal.html cash advance universal cash advance universal casinos games giochi casino http://www.freewebs.com/casino-598/casino-game-5.html http://www.freewebs.com/cash-920/fast-cash-advance-loan.html fast cash advance loan fast cash advance loan
0.0.0.* 于 2007-07-07 19:32:30发表:
cash advance denver cash advance denver http://www.freewebs.com/cash-862/cash-advance-denver.html quick cash advance loan http://www.freewebs.com/cash-496/quick-cash-advance-loan.html quick cash advance loan advance america cash advance advance america cash advance http://www.freewebs.com/cash-640/advance-america-cash-advance.html soma http://www.jungiananalyticpraxis.com/Terroristattack/00001630.htm soma http://www.nldguide.com/_kbas/0000018c.htm drug online drug online
202.182.30.* 于 2007-07-07 19:19:57发表:
osco drug http://www.mby2.com/_cusudi/0000005b.htm osco drug http://www.freewebs.com/casino-598/craps-4.html regole crap regola crap http://www.freewebs.com/cash-183/cash-advance-kansas-city.html cash advance kansas city cash advance kansas city cash advance washington dc cash advance washington dc http://www.freewebs.com/cash-862/cash-advance-washington-dc.html cheap vigrx http://www.freewebs.com/drugs-182/cheap-vigrx-2.html cheap vigrx
0.0.0.* 于 2007-07-07 19:19:48发表:
http://www.freewebs.com/casino-574/casino-game-7.html casino gaming casino games free real music ringtones sprint http://www.freewebs.com/ringtone-510/free-ringtones-10.html free ringtones giochi carte tavoli multigiocatori poker http://www.freewebs.com/poker-979/giochi-4.html http://www.ideeimpegno.it/_disc1/0000060a.htm prescription drug prescription drug cheap carisoprodol http://members.tripod.com/branhamhighforum/_disc13/00000431.htm cheap carisoprodol
82.40.76.* 于 2007-07-07 18:41:50发表:
http://www.freewebs.com/cash-862/payday-cash-advance.html payday cash advance payday cash advance http://www.freewebs.com/drugs-752/buy-fioricet-2.html buy fioricet buy fioricet online buy ultram buy ultram http://www.bernhardnordh.nu/_disk6/000018ca.htm vigrx http://www.freewebs.com/drugs-752/vigrx.html vigrx cheap tramadol http://www.freewebs.com/drugs-470/cheap-tramadol.html cheap tramadol
81.23.126.* 于 2007-07-07 18:18:25发表:
cash advance columbus ohio cash advance columbus ohio http://www.freewebs.com/cash-640/cash-advance-columbus-ohio.html vigrx side effects http://www.freewebs.com/drugs-182/vigrx.html vigrx pill online games giochi online http://www.freewebs.com/poker-806/giochi-6.html phentermine diet pill http://www.powerdreamteam.com/members/_GEL/000000a5.htm phentermine diet pill http://www.freewebs.com/drugs-870/cheap-carisoprodol.html cheap carisoprodol cheap carisoprodol
0.0.0.* 于 2007-07-07 18:18:05发表:
cash advance columbus ohio cash advance columbus ohio http://www.freewebs.com/cash-640/cash-advance-columbus-ohio.html vigrx side effects http://www.freewebs.com/drugs-182/vigrx.html vigrx pill online games giochi online http://www.freewebs.com/poker-806/giochi-6.html phentermine diet pill http://www.powerdreamteam.com/members/_GEL/000000a5.htm phentermine diet pill http://www.freewebs.com/drugs-870/cheap-carisoprodol.html cheap carisoprodol cheap carisoprodol
210.17.215.* 于 2007-07-07 17:16:28发表:
gioco gratuito http://www.freewebs.com/poker-82/gioco-8.html gioco in linea cheap vigrx http://www.freewebs.com/drugs-470/cheap-vigrx-2.html cheap vigrx walgreens drug store http://canadabuilds.com/Discussions/logon3/_disc1/0000005a.htm walgreens drug store drug war drug war http://www.cocoanutheads.com/_discussion-group/000000ad.htm tramadol hydrochloride http://www.freewebs.com/drugs-112/tramadol-2.html tramadol
130.60.66.* 于 2007-07-07 17:13:14发表:
http://www.freewebs.com/poker-82/poker-3.html gioco poker poker gratuito http://www.freewebs.com/ringtone-181/free-ringtones-15.html download free verizon ringtones download free verizon ringtones regole baccarat regola baccarat http://www.freewebs.com/poker-82/baccarat-7.html casinos in linea migliore casino in linea superiore http://www.freewebs.com/casino-606/casino-7.html internet roulette roulette internet http://www.freewebs.com/casino-837/roulette-6.html
75.17.141.* 于 2007-07-07 17:10:45发表:
free cell phone ringtones free cell phone ringtones http://www.freewebs.com/ringtone-251/free-ringtones-10.html vioxx vioxx http://www.28silverstreet.com/_disc5/00001b33.htm cash advance usa http://www.freewebs.com/cash-640/cash-advance-usa.html cash advance usa ace cash advance http://www.freewebs.com/cash-177/ace-cash-advance.html ace cash advance cheap ambien http://www.freewebs.com/drugs-90/cheap-ambien-2.html cheap ambien
0.0.0.* 于 2007-07-07 17:09:34发表:
http://www.freewebs.com/cash-256/bad-credit-cash-advance.html bad credit cash advance bad credit cash advance cash advance company http://www.freewebs.com/cash-256/cash-advance-company.html cash advance company http://www.freewebs.com/poker-734/poker-4.html internet poker casino poker casino roulette roulette on line http://www.freewebs.com/casino-418/roulette-2.html marilyn manson ringtones http://www.freewebs.com/ringtone-181/ringtones-5.html polyphonic ringtones
130.60.66.* 于 2007-07-07 17:08:57发表:
buy fioricet buy fioricet http://www.sflcoc.com/_sflgb/000018ab.htm cash advance austin cash advance austin http://www.freewebs.com/cash-413/cash-advance-austin.html order soma http://www.sandycreekconservancy.com/SCIForum/000000c4.htm order soma pay day loan cash advance http://www.freewebs.com/cash-100/pay-day-loan-cash-advance.html pay day loan cash advance http://www.docmi.org/_WSTMLiveCHAT/000037cb.htm vioxx recall vioxx recall
80.42.23.* 于 2007-07-07 17:07:55发表:
cash advance new york http://www.freewebs.com/cash-838/cash-advance-new-york.html cash advance new york cash advance loan cash advance loan http://www.freewebs.com/cash-892/cash-advance-loan.html drug test drug test http://www.niles-hs.k12.il.us/heaing/_51-75/00003f0a.htm ionamin http://socsci.mccneb.edu/soc101jf/_disc11/00003984.htm ionamin regole crap craps online http://www.freewebs.com/casino-387/craps-6.html
0.0.0.* 于 2007-07-07 17:07:41发表:
lawsuit cash advance lawsuit cash advance http://www.freewebs.com/cash-920/lawsuit-cash-advance.html cash advance tulsa http://www.freewebs.com/cash-41/cash-advance-tulsa.html cash advance tulsa free ringtone ringtones http://www.freewebs.com/ringtone-764/ringtones-6.html http://www.freewebs.com/drugs-399/cheap-viagra-2.html cheap viagra cheap viagra uk stanze di gioco stanze di gioco migliori http://www.freewebs.com/poker-603/gioco-6.html
70.243.254.* 于 2007-07-07 17:07:12发表:
soma carisoprodol soma carisoprodol http://www.freewebs.com/drugs-718/soma.html gioco in linea gioco in linea http://www.freewebs.com/poker-207/gioco-4.html buy levitra http://www.freewebs.com/drugs-591/buy-levitra-2.html buy levitra cash advance loan illinois http://www.freewebs.com/cash-177/cash-advance-loan-illinois.html cash advance loan illinois cheap ambien cheap ambien http://www.freewebs.com/drugs-473/cheap-ambien-2.html
190.6.16.* 于 2007-07-07 17:06:54发表:
free ringtones free ringtones http://www.freewebs.com/ringtone-287/free-ringtones-2.html play blackjack black jack http://www.freewebs.com/casino-978/blackjack-5.html cheap carisoprodol cheap carisoprodol http://www.freewebs.com/drugs-259/cheap-carisoprodol-2.html cash advance boston http://www.freewebs.com/cash-183/cash-advance-boston.html cash advance boston http://www.freewebs.com/cash-862/easy-cash-advance.html easy cash advance easy cash advance