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.

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Drivers and the kernel1-1 Drivers and the kernel UNIX system has three layers: m The hardware m The operating system kernel m The user-level programs Kernel.
Computer System Laboratory
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
CIS238/DL1 Chapter 15 Rebuilding the Linux Kernel Preparing the Source Code Locating the Source Code Installing the Source Code Read the Documentation.
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.
Project #2, Linux Kernel Modifications CS-502 Fall Programming Project #2 Linux Kernel Hacking CS-502 Operating Systems Fall 2006.
Build Linux Kernel, Add a New System Call to Linux Young Chi-Min
Project #1, Linux Kernel Modifications CS-502 Fall Programming Project #1 Linux Kernel Hacking CS-502, Operating Systems Fall 2007.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Operating Systems Lab. (#2) University of Tehran – ECE Dept. Fall 2005 Reza Shokri
NCHU System & Network Lab Lab 3 System Call Operating System Lab.
National Taiwan University OS Project 0 & 1 Advisor: Dr. Chih-Wen Hsueh Student: Tang-Hsun Tu 台灣大學 網媒所 / 資工所 Wireless Networking and Embedded Systems Laboratory.
Nachos Project 1 Start-up and System call
LOGO Linux Installation. Linux Distribution Including shells, libraries, tools, compiler, servers, applications. Redhat, Fedora, Mandrake, SuSE, Debian,
Linux Project 中央大學資工系 碩士二年級 江瑞敏. Outline How to compile linux kernel How to add a new system call Some Projects Example and Way to Solve it – System Call.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
Lecture 2 Linux Basic Commands,Shell and Make September 8, 2015 Kyu Ho Park.
System Calls: A Kernel Project Hunter Bell CS Fall
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.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
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.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
System Calls. The Linux we use is: Linux-Mandrake 7.0. In this project, you are going to change some kernel files and recompile the kernel. After you.
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.
CS 6560 Operating System Design Lecture 5: System Calls Interrupts.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
1 Week 7 System Calls, Kernel Threads, Kernel Debugging Sarah Diesburg Florida State University.
National Taiwan University OS Project 0 & 1 Advisor: Dr. Chih-Wen Hsueh Student: Tang-Hsun Tu 台灣大學 網媒所 / 資工所 Wireless Networking and Embedded Systems Laboratory.
Hp education services education.hp.com hp education services education.hp.com 1 HP World/Interex 2002 Linux Kernel Configuration and Patching Chris Cooper.
OS Project 0 February 25, Outline  Linux Installation  Linux Kernel Compilation  System Call Development  Kernel Modules / 452.
LOGO Linux Installation. Linux Distribution Including shells, libraries, tools, compiler, servers, applications. Redhat, Fedora, Mandrake, SuSE, Debian,
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Multiple File Compilation and linking By Bhumik Sapara.
Kernel Exercise 5 Brandon Cline Stuart Fischer Rachel Langhans Brian Minter Adam Stasio.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
Embedded Software Design Week II Linux Intro Linux Kernel.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 3: Adding System Calls to OS/161 Dr. Xiao Qin Auburn University.
Spring 2007 Vmware and Linux kernel COMS W4118 Columbia University.
Rebuilding Linux Kernel Dedicated to penguin lovers everywhere 26 September 20161Rebuilding kernel by Visakh M R.
Introduction to GCC Department of Radio Physics and Electronics ILug-Cal Introduction to GCC Department of Radio Physics and Electronics, Calcutta University.
Add a New System Call to Linux
The make utility (original presentation courtesy of Alark Joshi)
Lecture 2 Linux Basic Commands,Shell and Make
Operating System Kernel Compilation
OS – Ex 1 Nezer J. Zaidenberg.
OS Homework 1 February 22, 2017.
Drivers and the kernel UNIX system has three layers: Kernel
Linux Kernel Module Programming
Compiling from source code
Compiling from source code
Operating System Kernel Compilation
Intro to Kernel Modules and /proc
chapter 2 - Hello World Model
Comments, Prototypes, Headers & Multiple Source Files
Build A New Kernel and Add New System Calls in A Linux OS
COP 4343 Unix System Administration
CS 6560 Operating System Design
Lab 4 Kernel Module Operating System Lab.
CS 6560 Operating System Design Kernel Loadable Modules
Computer System Laboratory
Introduction to Linux device driver
Operating System Kernel Compilation
Presentation transcript:

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

Compile your own Linux kernel Get the source The Linux Kernel Archives ftp://linux.cis.nctu.edu.tw/kernel/( 交大資科 ) ( 中山大學 )

Compile your own Linux kernel Steps: Get the kernel source from ftp Installing the kernel source code - kernel source is put in /usr/src - #cd /usr/src - #tar xvzf linux-2.4.x.tar.gz make mroproper (Cleanup /usr/src/linux/ 目錄所有.o 的 object file, dependencies and kernel ’ s.config)

Compile your own Linux kernel Steps: Setup the kernel configuration make config or menuconfig or xconfig #make dep #make clean #make bzImage #make modules #make modules_install (Modules will be installed in /lib/modules/2.4.x) #make install

Compile your own Linux kernel Edit Bootloader Configuration File -- /etc/lilo.conf # lilo ( 完成 )

Add a New System Call Edit : /usr/src/linux/include/asm/unistd.h #define __NR_exit 1 #define __NR_fork 2 …… #define __NR_lremovexattr 236 #define __NR_fremovexattr 237 #define __NR_hello 239 add #defines for you new system calls at the end

Add a New System Call Edit the file : /usr/src/linux/arch/i386/kernel/entry.S.data ENTRY(sys_call_table).long SYMBOL_NAME(sys_ni_syscall) /* 0.long SYMBOL_NAME(sys_exit).long SYMBOL_NAME(sys_fork) ….long SYMBOL_NAME(sys_ni_syscall).long SYMBOL_NAME(sys_hello).rept NR_syscalls-(.-sys_call_table)/4.long SYMBOL_NAME(sys_ni_syscall).endr

Add a New System Call Definition your source code files (hello.c and hello.h) About Header file Machine architecture independent system calls and functions are kept under linux/include/linux Machine architecture dependent ones are kept under linux/include/asm

Add a New System Call Modify the Makefile in the directory you placed your.c file so that your code gets compiled and linked in properly Modify the Makefile line to have a.o of your source code For example. Adding hello.o O_OBJS += …. Hello.o

Add a New System Call Example : hello.c and hello.h hello.h(assuming hello.h is under inux/include/linux) #ifndef __LINUX_HELLO_H #define __LINUX_HELLO_H #include #endif

Add a New System Call hello.c hello.c (system call implementation) #include Asmlinkage int sys_hello(){ printk(KERN_EMERG “ hello\n ” ); return 0; }

Add a New System Call User application App.c #include _syscall0(int, hello); int main(){ hello(); return 0; } p.s if compiler error mv /usr/include/linux /usr/include/linux.bak mv /usr/iinclude/asm /usr/include/asm.bak ln – s /usr/src/linux/include/linux /usr/include/linux ln – s /usr/src/linux/include/asm /usr/include/asm

Add a New System Call There are some macros defined for this in The format is “ _ syscallN(return type, function name,arg1 type,arg1 name … ) ” where “ N ” is the number of parameters. For example : _syscall1(int, hello, int, a)

The Simple Kernel Module A Kernel Module must have at least two functions : “ start ” (initialization) function called init_module() which is called when the module is insmoded into kernel. “ end ” (cleanup) function called clean_module() which is called just before it is rmmoded.

Compiling Kernel Modules A kernel module should be compiled with the – c flag. A kernel modules must be compiled with the optimization flag, -O because the kernel make extensive use of inline function Define symbols using gcc ’ s – D option : __KERNEL__ : tells the header files that the code will be run in kernel mode. MODULE: tells the header files to give the appropriate definitions for a kernel module.

Adding System Call by Module CC = gcc CFLAGS = -O -D__KERNEL__ -DMODULE -Wall all: hello.o hello.o: hello.c $(CC) $(CFLAGS) -c hello.c-o hello.o install: /sbin/insmod hello.o remove: /sbin/rmmod hello

Adding System Call by Module #include /* for kernel function */ #include /* for module */ #include /* for system calls */ #include “hello.h“ extern void *sys_call_table[]; void (*orig_sys_call)(void); /* my system call */ int hello(unsignedlong arg) { printk( KERN_EMERG "Hello System Call: %d\n", arg); return 0; }

Adding System Call by Module /* init function, called when loaded */ int init_module(void) { printk(KERN_EMERG“hello module installed\n"); orig_sys_call= sys_call_table[SYS_hello]; /* backup the original system call*/ sys_call_table[SYS_hello] = hello ; /* replace with my system call */ return 0; } void cleanup_module(void) { printk(KERN_EMERG“hello module uninstalled\n"); sys_call_table[SYS_hello] = orig_sys_call; /* restore the original system call */ } /* try to remove thieline */ MODULE_LICENSE("GPL");

Adding System Call by Module #ifndef __HELLO_H__ #define __HELLO_H__ #include /* NR_syscalls is the system call table size, it is 256. Its definition is in linux/include/linux/sys.h. my system call uses the last one, its number is 255 */ #define __NR_hello (NR_syscalls -1) #define SYS_hello (NR_syscalls -1) #endif

Reference all.html all.html e/note1/syscall.html e/note1/syscall.html The Linux Kernel Module Programming Guide 鳥哥的 Linux 私房菜 鳥哥的 Linux 私房菜