1 / 9

Linux Loadable Module

Computer Science & Engineering Department. The University of Connecticut. 191 Auditorium Road, Box U-155. Storrs, CT 06269-3155. Linux Loadable Module. A. Paul Heely Jr. and Mike Stack. What are Modules?. Linux Kernel Monolithic Originally all functions were built in at compile time

osric
Download Presentation

Linux Loadable Module

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT 06269-3155 Linux Loadable Module A. Paul Heely Jr. and Mike Stack

  2. What are Modules? • Linux Kernel • Monolithic • Originally all functions were built in at compile time • Loadable Modules • Compile Object Files • Inserted and Removed from a Running Kernel • Run in the context of the Kernel • Contain any number of functions or types of data • Must contain an init_module() and cleanup_module function

  3. Why Use Modules • Why Use Modules at All? • Reduce size of running kernel • Network Protocol Drivers (TCP/IP, IPX, AppleTalk, etc) can be loaded only when needed • Single hardware device can provide different functionality • Parallel Port can be used for printing, zip drives, and “higher” speed networking (PLIP) • These cannot co-exist at the same time • Modules allow these to co-exist at different times without loading a new kernel • New devices can be added dynamically • Rot-13 device

  4. Loading Modules • 4 Steps In Loading a Module • Preparing the module • Allocating Kernel Memory • Copying the Module to the Kernel • Executing the Modules Init Function

  5. Preparing Modules • Handled by the module loader insmod • Module File Opened and Read Piece by Piece • header • text segment • data segment • text relocation information • data relocation information • symbol table • string table • Symbol Table Stored in a Binary Tree to Speedup Symbol Resolution

  6. Preparing Modules • External References Resolved • Kernel object or other modules • Symbol Table Updated • Text and Data Segments also Updated with Kernel address

  7. Allocating Memory, Copying, Module Init • Kernel Memory Allocation • create_module(): Kernel function • Passed module name and size • Returns address in Kernel where module will reside • Copying Module to Kernel Space • init_module(): Kernel function • Updates all offsets in the modules object code to reflect actual kernel location • Copies object code from user space to the kernel • Module Initialization • Final step, Kernel invokes the modules init_module() function

  8. Example Module • Rot-13 Encoding Device • New device added to running Linux System • Performs Rot-13 encoding/decoding on a character stream • Linux: The Choice of a GNU Generation becomes Yvahk: Gur Pubvpr bs TAH Trarengvba • New device can be opened, closed, and written • Handled the same as a “file” • Kernel maintains open count • Module cannot be removed while it is opened

  9. Conclusions • Loadable Modules Provide Simple Method of modifying a running Kernel • multiple drivers can share same hardware resource • Modules can be used to reduce a kernels size • seldom used drivers unloaded until needed • Trade Off between kernel size and performance • Loadable modules reduce size but require time to load.

More Related