26
Adding a System Call to the Linux Kernel Submitted by: Dishant Sharma ~ Deepak Giri ~ Pramod Verma Project – Operating Systems

Adding a System Call to Linux Kernel

Embed Size (px)

Citation preview

Page 1: Adding a System Call to Linux Kernel

Adding a System Callto the Linux Kernel

Submitted by:Dishant Sharma ~ Deepak Giri ~ Pramod Verma

Project – Operating Systems

Page 2: Adding a System Call to Linux Kernel

In this project, we willincorporate a new system call

into the Linux kernel, thereby expanding the functionality

of the operating system.

Page 3: Adding a System Call to Linux Kernel

•the system call interface provided by the Linux operating system, and

•how user programs communicate with the operating system kernel via the system call interface.

In this project, we will study:

Page 4: Adding a System Call to Linux Kernel

•the system call interface provided by the Linux operating system, and

•how user programs communicate with the operating system kernel via the system call interface.

In this project, we will study:

Page 5: Adding a System Call to Linux Kernel

•the system call interface provided by the Linux operating system, and

•how user programs communicate with the operating system kernel via the system call interface.

In this project, we will study:

Page 6: Adding a System Call to Linux Kernel

•Operating systems offer processes running in User Mode a set of interfaces to interact with hardware devices such as CPU, disks, printers, and so on.

•Unix systems implement most interfaces between User Mode processes and hardware devices by means of system calls issued to the kernel.

System Calls??

Page 7: Adding a System Call to Linux Kernel

•Operating systems offer processes running in User Mode a set of interfaces to interact with hardware devices such as CPU, disks, printers, and so on.

•Unix systems implement most interfaces between User Mode processes and hardware devices by means of system calls issued to the kernel.

System Calls??

Page 8: Adding a System Call to Linux Kernel

•Putting an extra layer between the application and the hardware has several advantages:▫ It makes programming easier, freeing users from

studying low-level programming characteristics of hardware devices.

▫ It greatly increases system security, since the kernel can check the correctness of the request at the interface level before attempting to satisfy it.

▫These interfaces make programs more portable since they can be compiled and executed correctly on any kernel that offers the same set of interfaces.

System Calls??

Page 9: Adding a System Call to Linux Kernel

•Putting an extra layer between the application and the hardware has several advantages:▫ It makes programming easier, freeing users from

studying low-level programming characteristics of hardware devices.

▫ It greatly increases system security, since the kernel can check the correctness of the request at the interface level before attempting to satisfy it.

▫These interfaces make programs more portable since they can be compiled and executed correctly on any kernel that offers the same set of interfaces.

System Calls??

Page 10: Adding a System Call to Linux Kernel

•Putting an extra layer between the application and the hardware has several advantages:▫ It makes programming easier, freeing users from

studying low-level programming characteristics of hardware devices.

▫ It greatly increases system security, since the kernel can check the correctness of the request at the interface level before attempting to satisfy it.

▫These interfaces make programs more portable since they can be compiled and executed correctly on any kernel that offers the same set of interfaces.

System Calls??

Page 11: Adding a System Call to Linux Kernel

•Putting an extra layer between the application and the hardware has several advantages:▫ It makes programming easier, freeing users from

studying low-level programming characteristics of hardware devices.

▫ It greatly increases system security, since the kernel can check the correctness of the request at the interface level before attempting to satisfy it.

▫These interfaces make programs more portable since they can be compiled and executed correctly on any kernel that offers the same set of interfaces.

System Calls??

Page 12: Adding a System Call to Linux Kernel

•A User Mode procedure call is performed by passing arguments to the called procedure either on stack or through registers, saving the current state and the value of the program counter, and jumping to the beginning of the code corresponding to the called procedure (the process continues to have the same privileges as before).

•System calls appear as procedure calls to user programs, but result in a change of execution context and privileges.

Page 13: Adding a System Call to Linux Kernel

•A User Mode procedure call is performed by passing arguments to the called procedure either on stack or through registers, saving the current state and the value of the program counter, and jumping to the beginning of the code corresponding to the called procedure (the process continues to have the same privileges as before).

•System calls appear as procedure calls to user programs, but result in a change of execution context and privileges.

Page 14: Adding a System Call to Linux Kernel

System Call in Linux(Intel 386 architecture)

In Linux, a system call is accomplished by•storing the system call number into the

EAX register,•storing arguments to the system call in

other hardware registers, and•executing a trap instruction

Page 15: Adding a System Call to Linux Kernel

•After the trap is executed, the system call number is used to index into a table of code pointers to obtain the starting address for the handler code implementing the system call.

•The process then jumps to this address and the privileges of the process are switched from user to kernel mode.

Page 16: Adding a System Call to Linux Kernel

•With the expanded privileges, the process can now execute kernel code that might include privileged instructions that cannot be executing in user mode.

•The kernel code can then perform the requested services (such as interacting with I/O devices) that cannot be performed in user mode.

Page 17: Adding a System Call to Linux Kernel

Building a New Kernel

Page 18: Adding a System Call to Linux Kernel

•If the source code package has been previously installed on your machine, the corresponding files might be available under /usr/src/linux-2.x

•If the package has not been installed earlier, it can be downloaded from http://kernel.org/

Step 1 – Obtain the kernel source code

Page 19: Adding a System Call to Linux Kernel

Step 2 – Configure, Compile & Install

• This will vary between the different kernel distributions, but some typical commands for building the kernel (after entering the directory where the kernel source code is stored) include:▫make xconfig▫make dep▫make bzImage

Page 20: Adding a System Call to Linux Kernel

Step 3 – Add Boot option

•The Linux OS typically uses utilities such as lilo and grub to maintain a list of portable kernels, from which the user can choose during machine boot-up.

Page 21: Adding a System Call to Linux Kernel

For systems supporting lilo

•Add an entry to lilo.conf, such as:image=/boot/bzImage.mykernellabel=mykernelroot=/dev/hda5read-only

(where /boot/bzImage.mykernel is the kernel image and mykernel is the lable associated with the new kernel)

Page 22: Adding a System Call to Linux Kernel

The project further ahead…

•extending the Kernel source•adding a System Call code to the kernel•using the new System Call from a user

program

Page 23: Adding a System Call to Linux Kernel

Questions!!

Page 24: Adding a System Call to Linux Kernel

Questions!!

Page 25: Adding a System Call to Linux Kernel

THANK YOU!

Page 26: Adding a System Call to Linux Kernel

THANK YOU!