System Calls: A Kernel Project Hunter Bell CS-550-3 Fall 2003 1.

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

C Language.
Christo Wilson Project 2: User Programs in Pintos
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Introduction to C Programming in Unix Environment - II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015 Some slides.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
CS 4284 Systems Capstone Project 2 Hints Slides created by Jaishankar Sundararaman.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
Project #2, Linux Kernel Modifications CS-502 Fall Programming Project #2 Linux Kernel Hacking CS-502 Operating Systems Fall 2006.
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.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Advanced Programming in the UNIX Environment Hop Lee.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Project #1, Linux Kernel Modifications CS-502 Fall Programming Project #1 Linux Kernel Hacking CS-502, Operating Systems Fall 2007.
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit.
chap13 Chapter 13 Programming in the Large.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
ECE122 Feb. 22, Any question on Vehicle sample code?
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.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
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.
Operating Systems Process Creation
CS 6560 Operating System Design Lecture 5: System Calls Interrupts.
Chapter Six Introduction to Shell Script Programming.
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
OS Project 0 February 25, Outline  Linux Installation  Linux Kernel Compilation  System Call Development  Kernel Modules / 452.
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Kernel Exercise 5 Brandon Cline Stuart Fischer Rachel Langhans Brian Minter Adam Stasio.
Templates Where the TYPE is generic. Templates for functions Used when the you want to perform the same operation on different data types. The definition.
C:\Temp\Templates 4 5 Use This Main Program 6.
Interrupt-Driven I/O There are different types of interrupts –Hardware Generated by the 8259 PIC – signals the CPU to suspend execution of the current.
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.
CSNB334 Advanced Operating Systems 3. Kernel Structure and Organization Lecturer: Abdul Rahim Ahmad.
Lecture 7 Interrupt ,Trap and System Call
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
Chapter 7: User-Defined Functions II
Chapter 6 CS 3370 – C++ Functions.
Protection of System Resources
Command Line Arguments
Command line arguments
C Basics.
Programmazione I a.a. 2017/2018.
Instructor: Ioannis A. Vetsikas
Command-line Arguments
More on UART Interrupts; System Calls
Fork and Exec Unix Model
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
An Introduction to Java – Part I, language basics
Genesis: From Raw Hardware to Processes
Command Line Parameters
Procedure Activations
System Calls David Ferry CSCI 3500 – Operating Systems
Lecture 6: Multiprogramming and Context Switching
Implementing System Calls
Functions Reasons Concepts Passing arguments to a function
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

System Calls: A Kernel Project Hunter Bell CS Fall

Introduction System Call Linkage Generating a New Kernel Function Defining the System Call Number Rebuilding the Kernel Generation and Running of User-space Program Problem encountered with programming exercise 2

System Call Linkage Macro (called in user program) Stub (trap instruction) Sys_call_table User space Kernel Function Kernel/Supervisor Space 3

What is a Macro? In this case, a predefined function in the Operating System that can be called from user space Generates a system call stub with zero to five parameters For example, generating a system call stub with two parameters: _syscall2(type,name,type1,arg1,type2,arg2); This generates a stub that makes a system call to the kernel function with matching type and name with the argument signature provided 4

Generating a New Kernel Function Update System Call Number / Linkage Determine location of body for function Write code for new Function Rebuild Kernel to include new Function 5

Defining the System Call Number (entry.S) ENTRY(sys_call_table).long SYMBOL_NAME(sys_ni_syscall)/* 0 - old "setup()" system call*/.long SYMBOL_NAME(sys_exit).long SYMBOL_NAME(sys_fork).long SYMBOL_NAME(sys_read).long SYMBOL_NAME(sys_write).long SYMBOL_NAME(sys_open)/* 5 */ ….long SYMBOL_NAME(sys_ni_syscall)/* streams2 */.long SYMBOL_NAME(sys_vfork) /* 190 */.long SYMBOL_NAME(sys_pedagogictime) /*191 - Hunter Bell*/.rept NR_syscalls-191.long SYMBOL_NAME(sys_ni_syscall) F’n name # of f’ns 6

Defining the System Call Linkage (unistd.h) #define __NR_exit 1 #define __NR_fork 2 … #define __NR_vfork 190 #define __NR_pedagogictime 191 New entry in table - for generating a stub 7

Source Code for Kernel Function asmlinkage int sys_pedagogictime(int flag,struct timeval *thetime) { /*declarations*/ int write_failed; struct timeval *temp; /*verify we can write to user space*/ write_failed = verify_area(VERIFY_WRITE,thetime,sizeof(thetime)); if(!write_failed) { printk("skelcall: Cannot write into user space"); return 0; }/*end if*/ cli(); /*disable interrupts*/ 8

Source Code for Kernel Function cli(); /*disable interrupts*/ /* write into user space the values in xtime */ __copy_to_user(&thetime->tv_sec,&xtime.tv_sec,sizeof(xtime.tv_sec)); __copy_to_user(&thetime->tv_usec,&xtime.tv_usec,sizeof(xtime.tv_usec)); sti(); /*enable interrupts*/ /* verify we can read from user space*/ write_failed = verify_area(VERIFY_READ,thetime,sizeof(thetime)); if(!write_failed) { printk("skelcall: Cannot read from user space"); return 0; } /*copy back from user space into temporary variable for printing*/ temp = NULL; __copy_from_user(&temp->tv_sec,&thetime->tv_sec,sizeof(thetime->tv_sec)); __copy_from_user(&temp->tv_usec,&thetime->tv_usec,sizeof(thetime->tv_usec)); 9

Source Code for Kernel Function /*Print time if flag is true*/ if(flag) printk("%s",ctime(temp->tv_sec)); return (!(write_failed)); }//end pedagogictime 10

Rebuilding the Kernel 5 steps: make clean make oldconfig make depend make make bzImage 11

Rebuilding the Kernel (commands) CommandFunctionality make cleanRemoves old object files and other temporary files in kernel environment make oldconfig Generic form: make Defines logical environment for new kernel – in this case, the same as the older configuration make dependSpecifies compile-order of kernel files makeCompiles all kernel source code into an executable file make bzImage Generic form : make Creates a bootable image of the kernel 12

Generation and Running of User- space Program /* **************************************** * Hunter Bell - CS550 * exercise-5 (term project) * this program executes in user space and * makes a system call to kernel space ***************************************** */ #include int main(int argc, char * argv[]) { struct timeval *thetime = (struct timeval *) malloc(sizeof(struct timeval *)); int flag = 1; /* generate a stub for System call for int pedagogictime through a Macro*/ _syscall2(int,pedagogictime,int,flag,struct timeval *,thetime); return 0; }//end main 13

Summary – System Call Linkage Macro (called in user program) Stub (trap instruction) Sys_call_table User space Kernel Function 14

Problem encountered with creating kernel function memcpy_fromfs() and memcpy_tofs() did not compile, and a grep produced nothing 15

Summary System Call Linkage Generating a New Kernel Function Defining the System Call Number Rebuilding the Kernel Generation and Running of User-space Program 16