Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Virtualization Technology A first look at some aspects of Intel’s ‘Vanderpool’ initiative.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
CS 497C – Introduction to UNIX Lecture 11: - The File System Chin-Chih Chang
The Unix File System. What are the three parts of every file on a Unix filesystem? And where is each stored? Filename - stored in directories Inode -
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
On working with LKMs Using Linux Kernel Modules to quickly export privileged kernel information to ordinary users.
CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
GNU/Linux Filesystem 1 st AUT GNU/Linux Festival Computer Engineering & IT Department Bahador Bakhshi.
Linux+ Guide to Linux Certification, Second Edition
The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller.
CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.
Chapter 5 Accessing Files and Directories. How Directories Get Created OS installation: usr, dev, etc, export, kernel and others places to store installation.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to a Programming Environment
Russell Taylor Lecturer in Computing & Business Studies.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Software Documentation Written By: Ian Sommerville Presentation By: Stephen Lopez-Couto.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Linux Operations and Administration
1. This presentation covers :  User Interface Administration  Files System and Services Management 2.
CprE 288 – Quick intro for compiling C in Linux
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to Shell Script Programming
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 4 Manage Software for SUSE Linux Enterprise Server.
Linux in More Detail Shirley Moore CPS5401 August 29,
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
CPS120: Introduction to Computer Science Operating Systems Nell Dale John Lewis.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Linux+ Guide to Linux Certification, Second Edition
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
Linux Operations and Administration
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
UNIX (Linux) Introduction Module-1. OS Kernel In computing, the kernel is the central component of OS. It is a bridge between applications and the actual.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Lecture One. Objective: Provide description of the Command-Line Editor of Linux operating system. Enable students to understand the practical side of.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
Λειτουργικά Συστήματα - Lab1 Γιάννης Πετράκης. The Operating System  Unix is a layered operating system  The innermost layer is the hardware that provides.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Visual Programming Borland Delphi. Developing Applications Borland Delphi is an object-oriented, visual programming environment to develop 32-bit applications.
Department of Computer Engineering
SUSE Linux Enterprise Desktop Administration
CS/COE 0447 (term 2181) Jarrett Billingsley
Proc File System Sadi Evren SEKER.
Guide To UNIX Using Linux Third Edition
The Linux Operating System
Introduction to Programming the WWW I
Software Documentation
Introduction Paul Flynn
Linux Shell Script Programming
Intro to PHP.
Presentation transcript:

Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules

Fewer keystrokes? If you want to run a program you wrote that resides in your current directory, you normally have to type the full pathname: $./myprog But you can adjust your logon-settings so you won’t have to specify the directory: $ myprog You just need to edit your ‘.bash_profile’

Environment variables You can view your present ‘environment’ using the ‘set’ command, like this: $ set | more Look for the line that begins with ‘PATH=‘ This line tells your command-shell (‘bash’) which directories it should search to find a program whose name you entered, so you can add ‘.’ (the current directory) to PATH

The ‘PATH=‘ variable Your ‘PATH’ environment-variable gets initialized each time you login Its value is setup by your ‘.bash_profile’ This hidden file is your ‘home’ directrory You can view it using the ‘cat’ command: You can also edit it (e.g., with ‘vi’) – but be very careful if you do so!

Including ‘.’ in your PATH If you want your command-shell to search for programs in your current directory, you can edit the ‘PATH=‘ line in.bash_profile Example: change the line that says PATH=$PATH:$HOME/bin so that it looks like this: PATH=$PATH:.:$HOME/bin

Notice: ‘$HOME/bin’ You can create a new subdirectoy (named ‘bin’) in your home directory, and use it as a place to put your often-used programs (such as tools like ‘newmod’ and ‘mmake’) Then, after you execute the ‘.bash_profile’ script, you can run those programs from any directory, without having to type a full pathname -- ‘bash’ will now find them!

A word about ‘wizards’ We will be writing lots of modules We can ‘automate’ the boilerplate We should write a ‘wizard’ program It will save us LOTS of time!

Our ‘newmod’ example The ‘newmod.cpp’ application creates the bare minimum of module source-code It’s an example of a ‘wizard’ tool – but it’s not as useful as it could be, since the code it creates doesn’t really DO anything Tonight we learn to use a better ‘wizard’, one that will prove very useful in studying the way the new Linux kernel 2.6 works

Types of files UNIX systems implement ordinary files for semi-permanent storage of programs/data But UNIX systems also implement several kinds of ‘special’ files (such as device-files and symbolic links) which enable users to employ familiar commands and functions (e.g., open(), read(), write(), and close()) when working with other kinds of objects

Pseudo-files Among the various types of ‘special’ files are the so-called ‘pseudo’ files Unlike ordinary files which hold information that is ‘static’, the pseudo-files don’t ‘store’ any information at all – but they ‘produce’ information that is created dynamically at the moment when they are being read Traditionally they’re known as ‘/proc’ files

Text in ‘/proc’ files Usually the data produced by reading from a ‘/proc’ file consists of pure ASCII text (a few exceptions exist, however) This means you can view the contents of a ‘/proc’ file without having to write a special application program – just use ‘cat’! For example: $ cat /proc/version

More ‘/proc’ examples $ cat /proc/cpuinfo $ cat /proc/modules $ cat /proc/meminfo $ cat /proc/iomem $ cat /proc/devices $ cat /proc/self/maps [Read the ‘man-page’ for details: $ man proc ]

Create your own pseudo-files You can use our ‘newinfo.cpp’ wizard to create ‘boilerplate’ code for a module that will create a new pseudo-file when you ‘install’ the module into a running kernel The module’s ‘payload’ is a function that will get called by the operating system if an application tries to ‘read’ from that file The ‘get_info()’ function has full privileges!

An example: ‘jiffies.c’ There is a volatile kernel variable (named ‘jiffies’) that keeps track of elapsed time It is used by the task-scheduler to decide when to perform a task-switch It increments 100 times/sec (kernel 2.4) It’s normally inaccessible to user programs But we can create a ‘/proc’ file that will let us view the ‘jiffies’ value at any moment

Edit the ‘get_info()’ function Just replace the statement: len += sprintf( buf+len, “%s\n”, modname ); with this statement: len += sprintf( buf+len, “ jiffies = %d \n”, jiffies ); Compile and install the module, then type: $ cat /proc/jiffies

In-class exercise #1 Try creating your own ‘jiffies’ pseudo-file 1) use ‘newinfo’ to build your ‘boilerplate’ 2) edit one line in your module’s ‘get_info’ 3) compile your module (using ‘mmake’) 4) install your ‘jiffies.ko’ kernel-object 5) use the ‘cat’ command to see jiffies

A more important example Control Register Cr4 This Pentium register contains a collection of flag-bits which enable or disable special architectural extensions to the CPU (as documented in Intel’s Software Developer Manual, vol3) movl %cr4, %ebx# privileged instruction Among the flag-bits in this register are two which affect how the Pentium translatres virtual memory-address into physical memory-addresses. We’ll need to know how these are set!

Our ‘cr4.c’ module We’ve written a module that will create a pseudo-file (named ‘/proc/cr4’) that can let us view the contents of Control Register 4 $ cat /proc/cr4 You can download our module’s code from the class website and try it out You can learn what all the flag-bits mean by reading Intel’s Developer Manual online

In-class exercise #2 Revise the source-code in the ‘cr4.c’ file so that it will display the meanings of each flag-bit in register CR4 For example, your ‘/proc/cr4’ file should print output that looks like this: cr4 = D0 PSE=1 PAE=0 VME=0 (but show ALL of the implemented bits)