CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.

Slides:



Advertisements
Similar presentations
Easily retrieve data from the Baan database
Advertisements

Linux device-driver issues
Computer System Laboratory
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Versioning Extensions for Linux CS736 Spring 1999 J. Adam Butts Paramjit Oberoi.
Computer Science 635 Advanced Systems Programming Fall 2007 Professor Allan Cruse.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
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.
Using Virtualization to Teach Linux System Administration in Online Courses Jim Owens Community College of Vermont May 8, 2007.
The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller.
Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.
Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules.
CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 8: Implementing and Managing Printers.
Chapter 12 Reading assignment n From “Running Linux”, on reserve at PSU Main library (2-hour checkout) Chapter 1 (pages 1 through 41)Chapter 1 (pages 1.
Tutorial and Demos on Linux Virtual Machine
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
Microsoft ® Official Course Module 9 Configuring Applications.
Module 14: Configuring Print Resources and Printing Pools.
For OS Experiments. What Do We Need? A Computer &
Course Overview Sarah Diesburg  Bobby Roy COP 5641 / CIS 4930.
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
Chapter 7: WORKING WITH GROUPS
11 MANAGING AND DISTRIBUTING SOFTWARE BY USING GROUP POLICY Chapter 5.
Managing User Desktops with Group Policy
Course Overview Ted Baker  Andy Wang COP 5641 / CIS 4930.
Kernel Modules Giving your Linux more pop since 1995.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
CS 444 Introduction to Operating Systems
Troubleshooting and Performance
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
CSNB334 Advanced Operating Systems Course Introduction Lecturer: Abdul Rahim Ahmad.
Linux Kernel Management. Module 9 – Kernel Administration ♦ Overview The innermost layer of Linux operating system is the kernel, which is a thin layer.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
Course Overview Mark Stanovich COP 5641 / CIS 4930.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
DEVICE DRIVERS Presented by: Group 7. What are Device Drivers? Device driver or hardware driver is a program that manages the system’s interaction with.
Developments for tape CERN IT Department CH-1211 Genève 23 Switzerland t DSS Developments for tape CASTOR workshop 2012 Author: Steven Murray.
Security-Enhanced Linux Stephanie Stelling Center for Information Security Department of Computer Science University of Tulsa, Tulsa, OK
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
OPERATING SYSTEMS (OS) By the end of this lesson you will be able to explain: 1. What an OS is 2. The relationship between the OS & application programs.
Quality Education for a Healthier Scotland New Features of the Clinical Knowledge Publisher May 2016.
Virtual Memory Mohammad H. Mofrad February 23, 2016
Chap 1 ~ Introducing LINUX LINUX is a free-stable multi-user operating system that derives from UNIX operating system Benefits: 1) Linux is released under.
Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.
OS – Ex 1 Nezer J. Zaidenberg.
Open Source Software Development Environment
Easily retrieve data from the Baan database
Introduction to the Kernel and Device Drivers
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
An Introduction to Device Drivers
Lesson #7 MCTS Cert Guide Microsoft Windows 7, Configuring Chapter 7 Configuring Devices and Updates.
Intro to Kernel Modules and /proc
IS3440 Linux Security Unit 7 Securing the Linux Kernel
Kernel Structure and Infrastructure
CS 6560 Operating System Design
Outline Chapter 2 (cont) OS Design OS structure
CS 6560 Operating System Design Kernel Loadable Modules
Presentation transcript:

CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco

Instructor Contact Information Office: Harney Science Center – 212 Hours: Mon-Wed 6:30pm-7:15pm Tues-Thurs 2:30pm-3:15pm Phone: (415) Webpage: cs.usfca.edu/~cruse/

Course Textbooks Alessandro Rubini and Jonathan Corbet, Linux Device Drivers (Third Edition), O’Reilly & Associates, Inc (2005) M. Beck et al, Linux Kernel Programming (Third Edition), Addison-Wesley (2002)

‘Extensibility’ A modern OS needs the ability to evolve –Will need to support new devices –Will need to allow ‘bugs’ to be fixed –Will need to permit performance gains Else OS may suffer early obsolescence!

Two Extensibility Mechanisms ‘Open Source’ programming ‘Loadable’ kernel modules

Loadable Kernel Modules A great mechanism for OS ‘extensibility’ Also allows us to study how kernel works Kernel can be modified while it’s running No need to recompile and then reboot But inherently unsafe: any ‘bug’ can cause a system malfunction or a complete crash!

‘Superuser’ privileges Modifying a running kernel is ‘risky’ Only authorized ‘system administrators’ are allowed to install kernel modules Our classroom workstations will allow us some limited administrator privileges

‘insmod’ and ‘rmmod’ We are allowed to ‘install’ kernel objects: $ /sbin/insmod myLKM.ko We are allowed to ‘remove’ kernel objects: $ /sbin/rmmod myLKM Anyone is allowed to ‘list’ kernel objects: $ /sbin/lsmod

Creating a new LKM You can use any text-editor (e.g., ‘vi’ or ‘emacs’) to create the source-code (in C) for a Linux kernel module (e.g., mod.c) But a kernel module differs from a normal C application program (e.g., no ‘main()’ function) A kernel module cannot call any of the familiar functions from the standard C runtime libraries For any LKM, two entry-points are mandatory (i.e., ‘init_module()’ and ‘cleanup_module()’)

Normal module structure Two ‘module administration’ functions [these are required] plus Appropriate ‘module service’ functions [these are optional]

Required module functions int init_module( void ); // gets called during module installation void cleanup_module( void ); // gets called during module removal

A ‘minimal’ module We have written a ‘wizard’ application that automatically creates the C boilerplate for a new module: $ newmod It creates a source-file with the essential Linux header, the two required functions, and a ‘MODULE_LICENSE’ statement It uses ‘printk()’ for logging messages

How to compile an LKM The Linux kernel has been a moving target Each new version has introduced changes A big change in kernel 2.6 concerns how a kernel module gets compiled No longer independent of kernel’s options Requires a specially created ‘Makefile’ for the specific module(s) you wish to compile See the discussion in our LDD3 textbook

Format of the ‘Makefile’ ifneq ($(KERNELRELEASE),) obj-m := mymod.o else KERNELDIR := /lib/modules/$(shell uname –r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules endif

Inconveniences Your ‘Makefile’ has to be edited every time you create another new module Then, when you compile the new module, like this: $ make there are more than a half-dozen files that get created (some of them are ‘hidden’) in your current directory, but just one is the ‘.ko’ (kernel object) that you really wanted

Our ‘mmake’ tool Since we will be writing and compiling lots of modules during our course, we wrote a tool that conveniently automates the steps You simply type: $ mmake It creates the ‘Makefile’ you need, in your current directory, to compile all modules that reside in that directory Afterward it erases all the unneeded files!

Try it out As an in-class programming exercise, you are asked to ‘download’ our two developer tools newmod.cpp and mmake.cpp from the CS 635 website (under ‘Handouts’) Compile these two application-programs: $ make newmod $ make mmake Run ‘newmod’ to create a mimimal module Then run ‘mmake’ to compile that module

Kernel 2.6 options Numerous configuration options exist for recent versions of the Linux kernel (our workstations are using version ) Our System Administrator had to choose which specific features to ‘activate’ when this kernel was being compiled Which features got ‘enabled’ will have an impact on our kernel module programs

An example: TASK_SIZE Previous Linux versions (e.g., 2.2 and 2.4) normally implemented the user-memory and kernel-memory for each task within the same 4GB virtual address-space map, and this is still possible with kernel 2.6 But the default configuration for kernel 2.6 (in the Fedora Core 3 distribution) uses a different scheme in which user-memory and kernel-memory use separate maps

Traditional Linux kernel memory (1 GB) user memory (3 GB) 0xC x TASK_SIZE = 0xC (Upper-limit of user-space) PAGE_OFFSET = 0xC (Lower bound of kernel space)

The 4GB/4GB split user-memory (~4GB) kernel-memory (~4GB) fixed maps TASK_SIZE = 0xFF PAGE_OFFSET = 0x

In-Class Exercise #2 After you have successfully built, compiled and installed, then removed, your ‘minimal’ module, try adding some statements to its ‘init_module()’ function that will print useful information, like this: printk( “PAGE_OFFSET=%08X “, PAGE_OFFSET ); printk( “TASK_SIZE=%08X \n“, TASK_SIZE );

Summary Download newmod.cpp and mmake.cpp Compile these using ‘make’ Run ‘newmod mod’ to create ‘mod.c’ Run ‘mmake’ to compile ‘mod.c’ Install ‘mod.ko’ (and see printk-message) Remove ‘mod’ and add new statements Recompile and reinstall to see new info