(C) High Speed Networks Lab, CIS, NCTU 1 Operating Systems, Spring 2002 Project #2 Adding a kernel module INSTRUCTOR: Prof. Ying-Dar Lin TAs: I-Wei Chen,

Slides:



Advertisements
Similar presentations
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Advertisements

Computer System Laboratory
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Stack buffer overflow
Processes CSCI 444/544 Operating Systems Fall 2008.
Introduction to Java Lab CS110A – Lab Section 004 Instructor: Duo Wei.
1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Add a New System Call to Linux. Hw1 Add a New System Call to Linux and Compile Kernel Add a New System Call to Linux by Kernel Module.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Tutorial and Demos on Linux Virtual Machine
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
NCHU System & Network Lab Lab 3 System Call Operating System Lab.
Operating System Program 5 I/O System DMA Device Driver.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CPT: Arrays of Pointers/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to illustrate the use of arrays.
Lecture 0 CIS 208 C Language Lab Wed. January 12, 2005.
Lecture-1 Compilation process
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
File ▪ File – Unit of logical storage – Aid in manipulating exact sector of file data ▪ Abstract view of secondary physical storage devices ▪ Without files.
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.
C Programming in Linux Jacob Chan. C/C++ and Java  Portable  Code written in one system and works in another  But in C, there are some libraries that.
Implementing System Calls CS552 Kartik Gopalan. CS552/BU/Spring2008 Steps in writing a system call 1.Create an entry for the system call in the kernel’s.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Navigating Directories
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.
USER DEFINED FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Introduction Systems Programming Overview  Systems programming is the programming activity to create software used by other programmers and users. System.
OPERATING SYSTEMS 1 - HARDWARE PIETER HARTEL 1. Hardware 2.
Interfacing Device Drivers with the Kernel
OS Project 0 February 25, Outline  Linux Installation  Linux Kernel Compilation  System Call Development  Kernel Modules / 452.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Arrays, Strings, and Memory. Command Line Arguments #include int main(int argc, char *argv[]) { int i; printf("Arg# Contents\n"); for (i = 0; i < argc;
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Add a New System Call to Linux
Hands on training session for core skills
OS Homework 1 February 22, 2017.
A bit of C programming Lecture 3 Uli Raich.
Homework Reading Machine Projects Labs PAL, pp ,
Program Execution in Linux
CSE 351 Section 1: HW 0 + Intro to C
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
Project1: Unix Shell using Multi-Processing
Assembly Language Programming I: Introduction
Processes in Unix, Linux, and Windows
Assembly Language Programming II: C Compiler Calling Sequences
The Designer.
Recitation 9: Processes, Signals, TSHLab
Lab 4 Kernel Module Operating System Lab.
Tutorial: The Programming Interface
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
Program Execution in Linux
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Arrays and Pointers (part 2)
EECE.4810/EECE.5730 Operating Systems
Recitation 9: Processes, Signals, TSHLab
Some codes for analysis and preparation for programming
Presentation transcript:

(C) High Speed Networks Lab, CIS, NCTU 1 Operating Systems, Spring 2002 Project #2 Adding a kernel module INSTRUCTOR: Prof. Ying-Dar Lin TAs: I-Wei Chen, Yi-Hsiang Lin

(C) High Speed Networks Lab, CIS, NCTU2 Agenda Purpose Purpose Assignment Assignment Report content Report content Deadline Deadline General steps to add a module in FreeBSD and Linux General steps to add a module in FreeBSD and Linux Testing programs Testing programs

(C) High Speed Networks Lab, CIS, NCTU3 Purpose Learning kernel modules - Dynamically load or unload functions - Can do anything that kernel code can do Learning kernel modules - Dynamically load or unload functions - Can do anything that kernel code can do The mechanism of kernel modules The mechanism of kernel modules Practice the “ system call ” again Practice the “ system call ” again Real-world implementations in FreeBSD and Linux Real-world implementations in FreeBSD and Linux

(C) High Speed Networks Lab, CIS, NCTU4 Assignment Platform : FreeBSD or Linux Platform : FreeBSD or Linux Adding a “ hello ” system call by using a kernel module The output of executing “./hello Yourname ” Adding a “ hello ” system call by using a kernel module The output of executing “./hello Yourname ” [239] Hello! Yourname is !! Ret=8 Notes: 1. [239] “ 239 ” is the system call number 2. “ Student ID ” should be written in kernel module. 3. Return code should be the last digital of your student ID (ex should return “ 8 ” ) Any extra functionality will get some bonus Any extra functionality will get some bonus Report: 50 % Report: 50 % Implementation: 50 % Implementation: 50 %

(C) High Speed Networks Lab, CIS, NCTU5 Report content 1. What ’ s kernel modules? How its work on Linux or FreeBSD? 2. What can be implemented as modules? And what cannot? 3. How to add a kernel module? 4. (*) Describe your extra functions.

(C) High Speed Networks Lab, CIS, NCTU6 Deadline Demo : Demo : 6/20(Thu) pm6:00-11:00 6/21(Fri) pm1:00-6:00 at 701 EECS Research Building Report : turn in when you demo Report : turn in when you demo

(C) High Speed Networks Lab, CIS, NCTU7 General steps to add a kernel module in FreeBSD(4.5-STABLE) 1. Edit /usr/share/examples/kld/syscall/module/syscall.c SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL); static int hello (struct proc *p, struct args *uap) { char buf[128]; printf ("Hello! Kernel!!\n"); printf ("Hello! Kernel!!\n"); sprintf(buf,"Hello! Kernel!!", uap->buf); strcpy(uap->buf, buf); sprintf(buf,"Hello! Kernel!!", uap->buf); strcpy(uap->buf, buf); p->p_retval[0] = 0; p->p_retval[0] = 0; return 0; return 0;} static struct sysent hello_sysent = { 1, /* sy_narg */ 1, /* sy_narg */ hello /* sy_call */ hello /* sy_call */}; 2. product kernel module file: syscall.ko

(C) High Speed Networks Lab, CIS, NCTU8 General steps to add a kernel module in Linux(RedHat 7.3) 1. edit /usr/src/linux-2.4/arch/i386/kernel/entry.S.long SYMBOL_NAME(sys_hello) 2. edit /usr/src/linux-2.4/include/asm-i386/unistd.h #define __NR_hello edit syscall.c asmlinkage long our_sys_hello(char *name) { char buf[128]; sprintf(buf,"Hello! %s!!\n", name); sprintf(buf,"Hello! %s!!\n", name);strcpy(name,buf); printk("(our_sys_hello)Hello! Kernel!!\n"); printk("(our_sys_hello)Hello! Kernel!!\n"); return 1; return 1;} 4. edit Makefile (Notice: replace the kernel version with “ uname -r ” ) 5. product kernel module file: syscall.o

(C) High Speed Networks Lab, CIS, NCTU9 Testing programs in FreeBSD 1. edit hello.c stat.version = sizeof(stat); modstat(modfind("syscall"), &stat); modstat(modfind("syscall"), &stat); syscall_num = stat.data.intval; syscall_num = stat.data.intval; syscall (syscall_num, argv[1]); syscall (syscall_num, argv[1]); printf("%s\n", argv[1]); printf("%s\n", argv[1]); 2. Loading kernel module % kldload./syscall.ko % kldload./syscall.ko 3. Testing %./hello einstein Hello! einstein!!

(C) High Speed Networks Lab, CIS, NCTU10 Testing programs in Linux 1. edit hello.c static inline _syscall1(int, hello, char *, buf) int main(int argc, char **argv) { printf("Before calling syscall hello(), argv[1]= %s\n", argv[1]); printf("return : %d\n", hello(argv[1])); printf("return : %d\n", hello(argv[1])); printf("After calling syscall hello(), argv[1]= %s\n", argv[1]); printf("After calling syscall hello(), argv[1]= %s\n", argv[1]); return 0; return 0;} 2. Loading kernel module % insmod syscall.o 3. Testing %./hello einstein Hello! einstein!!