[ Pobierz całość w formacie PDF ]
.Only herethe required services are in another, previously loaded module.As each module isloaded, the kernel modi es the kernel symbol table, adding to it all of the resourcesor symbols exported by the newly loaded module.This means that, when the nextmodule is loaded, it has access to the services of the already loaded modules.When an attempt is made to unload a module, the kernel needs to know that themodule is unused and it needs some way of notifying the module that it is about tobe unloaded.That way the module will be able to free up any system resources thatit has allocated, for example kernel memory or interrupts, before it is removed fromthe kernel.When the module is unloaded, the kernel removes any symbols that thatmodule exported into the kernel symbol table.Apart from the ability of a loaded module to crash the operating system by beingbadly written, it presents another danger.What happens if you load a module builtfor an earlier or later kernel than the one that you are now running? This maycause a problem if, say, the module makes a call to a kernel routine and supplies thewrong arguments.The kernel can optionally protect against this by making rigorousversion checks on the module as it is loaded.12.1 Loading a ModuleThere are two ways that a kernel module can be loaded.The rst way is to use theinsmod command to manually insert the it into the kernel.The second, and muchmore clever way, is to load the module as it is needed; this is known as demandloading.When the kernel discovers the need for a module, for example when thekerneld is in theuser mounts a le system that is not in the kernel, the kernel will request that themodules packagealong with kernel daemon kerneld attempts to load the appropriate module.insmod, lsmodThe kernel daemon is a normal user process albeit with super user privileges.Whenand rmmod.it is started up, usually at system boot time, it opens up an Inter-Process Communi-cation IPC channel to the kernel.This link is used by the kernel to send messagesSee include -to the kerneld asking for various tasks to be performed.Kerneld's major functionlinux kerneld.his to load and unload kernel modules but it is also capable of other tasks such asstarting up the PPP link over serial line when it is needed and closing it down when itis not.Kerneld does not perform these tasks itself, it runs the neccessary programssuch as insmod to do the work.Kerneld is just an agent of the kernel, schedulingwork on its behalf. gmodule_list module modulenext nextref refsymtab symtabname name"fat" "vfat"size sizeaddr addrstate state*cleanup() *cleanup()symbol_table symbol_tablesize sizen_symbols n_symbolsn_refs n_refssymbols symbolsreferences referencesFigure 12.1: The List of Kernel ModulesThe insmod utility must nd the requested kernel module that it is to load.Demandloaded kernel modules are normally kept in lib modules kernel-version.Thekernel modules are linked object les just like other programs in the system exceptthat they are linked as a relocatable images.That is, images that are not linkedto run from a particular address.They can be either a.out or elf format objectles.insmod makes a privileged system call to nd the kernel's exported symbols.See sys get -These are kept in pairs containing the symbol's name and its value, for example its kernel syms inkernel module.caddress.The kernel's exported symbol table is held in the rst module data structurein the list of modules maintained by the kernel and pointed at by the module listSee include -pointer.Only speci cally entered symbols are added into the table, which is builtlinux module.hwhen the kernel is compiled and linked, not every symbol in the kernel is exportedto its modules.An example symbol is ` ` request irq' ' which is the kernel routinethat must be called when a driver wishes to take control of a particular systeminterrupt.In my current kernel, this has a value of 0x0010cd30.You can easily seethe exported kernel symbols and their values by looking at proc ksyms or by usingthe ksyms utility.The ksyms utility can either show you all of the exported kernelsymbols or only those symbols exported by loaded modules.insmod reads the moduleinto its virtual memory and xes up its unresolved references to kernel routines andresources using the exported symbols from the kernel.This xing up takes the formof patching the module image in memory.insmod physically writes the address ofthe symbol into the appropriate place in the module.When insmod has xed up the module's references to exported kernel symbols, it asksthe kernel for enough space to hold the new kernel, again using a privileged systemcall.The kernel allocates a new module data structure and enough kernel memorySee sys -to hold the new module and puts it at the end of the kernel modules list.The newcreate modulemodule is marked as UNINITIALIZED.Figure 12.1 shows the list of kernel modulesin kernel -after two modules, VFAT and VFAT have been loaded into the kernel.Not shown in themodule.c. pdiagram is the rst module on the list, which is a pseudo-module that is only thereto hold the kernel's exported symbol table.You can use the command lsmod to listall of the loaded kernel modules and their interdependencies.lsmod simply reformatsproc modules which is built from the list of kernel module data structures.Thememory that the kernel allocates for it is mapped into the insmod process's addressspace so that it can access it.insmod copies the module into the allocated space andrelocates it so that it will run from the kernel address that it has been allocated.This must happen as the module cannot expect to be loaded at the same addresstwice let alone into the same address in two di erent Linux systems.Again, thisrelocation involves patching the module image with the appropriate addresses.The new module also exports symbols to the kernel and insmod builds a table ofthese exported images.Every kernel module must contain module initialization andmodule cleanup routines and these symbols are deliberately not exported but insmodmust know the addresses of them so that it can pass them to the kernel.All beingSee sys init -well, insmod is now ready to initialize the module and it makes a privileged system callmodule inpassing the kernel the addresses of the module's initialization and cleanup routines.kernel -module.c.When a new module is added into the kernel, it must update the kernel's set ofsymbols and modify the modules that are being used by the new module.Modulesthat have other modules dependent on them must maintain a list of references at theend of their symbol table and pointed at by their module data structure.Figure 12.1shows that the VFAT le system module is dependent on the FAT le system module.So, the FAT module contains a reference to the VFAT module; the reference wasadded when the VFAT module was loaded.The kernel calls the modules initializationroutine and, if it is successful it carries on installing the module.The module'scleanup routine address is stored in it's module data structure and it will be calledby the kernel when that module is unloaded.Finally, the module's state is set toRUNNING.12.2 Unloading a ModuleModules can be removed using the rmmod command but demand loaded modules areautomatically removed from the system by kerneld when they are no longer beingused.Every time its idle timer expires, kerneld makes a system call requestingthat all unused demand loaded modules are removed from the system.The timer'svalue is set when you start kerneld; my kerneld checks every 180 seconds [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • czarkowski.pev.pl
  •