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.

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

Linux device-driver issues
RT_FIFO, Device driver.
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CSCC69: Operating Systems
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
CS 450 MPX P ROJECT Introduction to MPX. I NTRODUCTION TO MPX The MPX module is divided into six modules Module R1: User Interface Module R2: Process.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Project 2 -- Linux Kernel Hacking CS-502 (EMC) Fall Project 2 Linux Kernel Hacking CS-502, Operating Systems Fall 2009 (EMC)
(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,
1 Reminders Project 1 due tomorrow by 6:00 Office hours in 006 today at 4:30 Start thinking about project groups (3 people) for the rest of the quarter.
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.
1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call.
Project #2, Linux Kernel Modifications CS-502 Fall Programming Project #2 Linux Kernel Hacking CS-502 Operating Systems Fall 2006.
Project #2 -- Kernel Hacking CS-3013 A-term Programming Project #2 Linux Kernel Hacking CS-3013, Operating Systems C-Term 2008 Due Monday, September.
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.
Tutorial and Demos on Linux Virtual Machine
Project #1, Linux Kernel Modifications CS-502 Fall Programming Project #1 Linux Kernel Hacking CS-502, Operating Systems Fall 2007.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
NCHU System & Network Lab Lab 3 System Call Operating System Lab.
Operating System Program 5 I/O System DMA Device Driver.
National Taiwan University OS Project 0 & 1 Advisor: Dr. Chih-Wen Hsueh Student: Tang-Hsun Tu 台灣大學 網媒所 / 資工所 Wireless Networking and Embedded Systems Laboratory.
For OS Experiments. What Do We Need? A Computer &
Heap Management. What is really stored on the heap? Housekeeping Users Data Buffer Next Block Data Housekeeping 0x7000 0x7008 int main() { int *x,*y;
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
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.
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.
CSE 451: Operating Systems Section 3: Project 0 recap, Project 1.
Operating Systems Process Creation
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.
OS Project 0 February 25, Outline  Linux Installation  Linux Kernel Compilation  System Call Development  Kernel Modules / 452.
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.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Kernel Exercise 5 Brandon Cline Stuart Fischer Rachel Langhans Brian Minter Adam Stasio.
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.
Lecture 7 Interrupt ,Trap and System Call
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Add a New System Call to Linux
OS – Ex 1 Nezer J. Zaidenberg.
OS Homework 1 February 22, 2017.
Makefiles.
Linux Kernel Module Programming
Linux Kernel Driver.
Want to play a game? – Linux Kernel Modules
CSC 253 Lecture 8.
Operation System Program 4
CSC 253 Lecture 8.
Discussions on HW2 Objectives
Build A New Kernel and Add New System Calls in A Linux OS
CS 6560 Operating System Design
Operation System Program 1
Lab 4 Kernel Module Operating System Lab.
CS 6560 Operating System Design Kernel Loadable Modules
Discussions on HW2 Objectives
Computer System Laboratory
Programming Project #2 Linux Kernel Hacking
Loadable Kernel Modules
Implementing System Calls
Presentation transcript:

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 with kernel.

Method of System Call Here are two methods developing our own system calls Using kernel module Modify the source code of linux directly

Kernel module Making system calls using kernel module Building system calls in kernel module is more flexible than modifying kernel. When we want to use our system call, just install our kernel modules; and if we don’t need it right away, just remove modules. Modifying kernel is not necessary. (But you still need to modify your kernel for O.S. project one.)

Kernel module Build your own module. You can put it in /drivers/misc/ ex: /usr/src/linux-2.6.xx/drivers/misc/ #cd /usr/src/linux-2.6.xx/drivers/misc/ #vim myservice.c

Kernel module #include /* We're doing kernel work */ #include #define __NR_mysyscall 253 /* define the number of our system call */ extern void *sys_call_table[]; /* system call table */ void (*orig_sys_call)(void); extern int errno;

Kernel module Our system call /* Our system call */ asmlinkage int mysyscall(int n) { printk("enter mysyscall()\n"); return 2*n; }

Kernel module Initial kernel module /* Initialize the module - replace the system call */ int init_module() { printk("Insert mysyscall module\n"); orig_sys_call = sys_call_table[__NR_mysyscall]; sys_call_table[__NR_mysyscall] = mysyscall; return 0; }

Kernel module clean kernel module /* Cleanup - unregister the appropriate file from /proc */ void cleanup_module() { printk("Remove mysyscall module\n"); sys_call_table[__NR_mysyscall] = orig_sys_call; }

Kernel module For sys_call_table, your should extern it in a file such as /arch/i386/kernel/i386_ksyms. extern void* sys_call_table[]; /*variable should be exported. */ EXPORT_SYMBOL(sys_call_table);

Kernel module Compile module #cd /usr/src/linux-2.6.x/drivers/misc/ #vi Makefile obj-m += myservice.o  add this #make -C /usr/src/linux-2.6.x SUBDIRS=$PWD modules #insmod myservice.ko #rmmod myservice.ko

Kernel module – User Pro. #include int mysyscall(int n){ return syscall( __NR_mysyscall, n); } int main() { mysyscall(0); return 0; }

Method of System Call Here are two methods developing our own system calls Using kernel module Modify the source code of linux directly

Build in Kernel In /usr/src/linux-2.6.x/kernel/, Create a new file myservice.c to define your system call.... #include //for linking a system call #include //for the printk long (*my_service)(int arg1, char* arg2) = NULL; EXPORT_SYMBOL(my_service); asmlinkage int sys_myservice (int arg1, char* arg2) { printk(KERN_EMERG “my service is running”); //kernel messages logged to /var/log/kernel/warnings return(1); }

Build in Kernel In /usr/src/linux-2.6.x/include/asm- i386/unistd.h, define an index for your system call. Your index should be the number after the last system call defined in the list. // This mean the end of the system call table. #define __NR_myservice 318

Build in Kernel In /usr/src/linux-2.6.x/include/asm- ’platform’/unistd.h, ( platform means your system, ex: asm-i386 ) define an index for your system call. Your index should be the number after the last system call defined in the list. // This mean the end of the system call table. #define __NR_myservice 318

Build in Kernel Also, you should increment the system call count. // This means the total number of system calls #define __NR_syscalls 319

Build in Kernel In /usr/src/linux-2.6.xxx/arch/’platform’/kernel/syscall_table.S, you should define a pointer to hold a reference to your system call routine. It is important that your data entry placement corresponds to the index you assigned to your system call.Linux version is and each version may have different place..long sys_myservice

Build in Kernel Add your system call to the Makefile in /usr/src/Linux-x.x.x/kernel/Makefile. Add your object after the other kernel objects have been declared. obj-y += myservice.o

Build in Kernel You also need to copy your edited unistd.h from /usr/src/linux-2.6.x/include/asm/ to /usr/include/kernel/ because it contains your system call’s index.

Build in Kernel – User Pro. #include #define __NR_myservice 318 //this is the return code from the system call extern errno; //this is a macro defined in unistd.h to help prototype sys calls _syscall2(int, myservice, int, arg1, char*, arg2); int main() { int i; i = myservice(1, "hi"); printf("%d\n",i); }

Notification If your module want to use the variable in kernel, you have to use the function EXPORT_SYMBOL() to export it. ex: int a; EXPORT_SYMBOL(a); printk can print messages in kernel, use dmesg to check.

Q&A Thanks for your attention.