COMP 3000 Essay 1 2010 Question 2: Difference between revisions

From Soma-notes
Sblais2 (talk | contribs)
Sblais2 (talk | contribs)
Line 24: Line 24:
'''Figure 1. The simplified flow of a system call using the interrupt method'''
'''Figure 1. The simplified flow of a system call using the interrupt method'''
[[File:Figure1.gif]]
[[File:Figure1.gif]]
Here is an example of syscall to invoke a system call:
#include <linux/unistd.h>
#include <sys/syscall.h>
#define _NR_getjiffies  320      -> This is the
int main()
{
    long jiffies;
   
    jiffies = syscall(_NR_getjiffies);
    printf( "Current jiffies is %lx\n", jiffies );
    return 0;
}


= References =
= References =

Revision as of 19:39, 8 October 2010

Question

How do the available system calls in modern versions of the Linux Kernel (2.6.30+) compare with the system calls available in the earliest versions of UNIX? How has the system call interface been expanded, and why? Focus on major changes or extensions in functionality.

Answer

System Calls

Overview

A system call is a mean by which programs in the user space can access kernel services. Systems calls vary from operating system to operating system, although the underlying concepts tends to be the same. In general, a process is not supposed to be able to access the kernel directly. It cannot access kernel memory and it can't call kernel functions. The hardware of the CPU prevents this (called "protected mode"). System calls are an exception to this rule. For example, older x86 processors used an interrupt mechanism to go from user-space to kernel-space, but newer processor (PentiumII+) provided instructions that optimize this transition (using sysenter and sysexit instructions).

The Linux operating system (2.6.30+) contains hundreds of system calls. They are roughly grouped into 5 major categories: Process Control, File Management, Device Management, Information Maintenance and Comminution.


System call Index numbers

Each system calls are identified by an index number. For example, the index number of the sys_read is 3. These numbers are located in the file /arch/i386/include/asm/unistd.h. You can find the association between numbers and names in the sys_call_table, for example in arch/i386/kernel/entry.S.

Linux system call interface (SCI)

Using the interrupt method

Each system call is multiplexed into the kernel through a single entry point. The EAX register is used to identify the particular system that should be called. The system call is specified in the c library. When the c library has loaded the system call index and any arguments, a software interrupt is invoked (int 0x80), which results in the execution of the system_call function. This function handles all system calls, as identified by the contents of the EAX register. After a few system checks, the actual system call is invoked using the "system_call_table" and the system call index contained in EAX. Upon return from the system call, syscall_exit is eventually reached, and a call to resume_userspace transitions back to user-space. It then goes back to the user application.


Figure 1. The simplified flow of a system call using the interrupt method

Here is an example of syscall to invoke a system call:

  1. include <linux/unistd.h>
  2. include <sys/syscall.h>
  1. define _NR_getjiffies 320 -> This is the

int main() {

   long jiffies;
   
   jiffies = syscall(_NR_getjiffies);
   printf( "Current jiffies is %lx\n", jiffies );
   return 0;

}

References

Here is the original manual --Lmundt 18:29, 7 October 2010 (UTC) http://cm.bell-labs.com/cm/cs/who/dmr/1stEdman.html

The Linux KErnel Module Programming Guide by http://www.faqs.org/docs/kernel/x931.html