Operating system principle (i)--the principle and implementation of system call

Source: Internet
Author: User

System invocation: Principle and implementation

1. What is a system call

In a computer, a system call (English: System call), also known as an "invoke", refers to a service running in the consumer space that requests the operating system kernel to run with higher privileges. System calls provide an interface between the user program and the operating system (that is, the system call is the interface for user programs and kernel interactions).

The state of the operating system is divided into the tubular (core State) and the configuration (user state). Most system interactive operational requirements are performed in the kernel state. such as device IO operations or interprocess communication. Privileged directives: a class of special instructions that can only be run under a kernel mentality and not run in a user state. Different operating system privilege directives vary, but in general are primarily hardware-related directives. The user program runs only in the user state and sometimes requires access to the system's core functionality, which is used by the system call interface.

Over and over again is these words:

Applications sometimes require dangerous, highly privileged instructions, which can be dangerous if they are safely handed over to the user program (for example, a process may modify the memory area of another process to prevent it from running), but it cannot completely give these permissions. As a result of the system call, dangerous instructions are packaged as system calls, and the user program can only invoke and not be able to run those dangerous instructions. In addition, computer hardware resources are limited, in order to better manage these resources, all resources are controlled by the operating system, the process can only request these resources to the operating system. The operating system is the only entry for these resources, which is the system call.

2. Overview of System Call implementation methods

The methods for adding system calls in XV6 are:

1) in the sysproc.c file, add the implementation function of the system call to be added;

2) in the syscall.h file, define the location of the system call vector that points to the implementation function;

3) in the user.h file, define the functions that can be called in the shell;

4) in the syscall.c file, the external definition (external define) a function linking the kernel and the shell, using the position in "Step 2)" To add this function to the system call vector;

5) in USys. S file, use macro to connect the user's call request and implementation function;

6) in the defs.h file, add a foreground statement for the system call you added.

3. Actual operation

Add the system call "halt" for XV6 to complete the shutdown function.

A. In the sysproc.c file, add the implementation function for the system call that you want to add, adding the following code:

int sys_halt (void) {    char"Shutdown";      for (; *p; p++)        outb (0x8900, *p);     return 0 ;}

B. In the syscall.h file, define the location of the system call vector that points to the implementation function, and add the following code:

#define Sys_halt  22

C. In the user.h file, define the functions that can be called in the shell;

int Halt (void);

D. In the syscall.c file, add the following code:

extern int sys_halt (void);

and in the static int (*syscalls []) (void), add the following:

[Sys_halt]    Sys_halt,

E. in USys. Add in S:

SYSCALL (Halt)

Complete.

Note:

This article refers to the following address, if interested, to access the original address.

Reference Blog: http://yalongyang.com/2012/10/xv6-add-system-call/

Reference Blog: http://www.ithao123.cn/content-6299692.html

Reference Answer: HTTP://STACKOVERFLOW.COM/QUESTIONS/8021774/HOW-DO-I-ADD-A-SYSTEM-CALL-UTILITY-IN-XV6

  

Operating system principle (i)--the principle and implementation of system call

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.