About simple design system calls in the BSD system
Author: xie_minix
In the hierarchical structure of the operating system, the portion directly related to the machine hardware is usually placed in the innermost layer (interrupt processing, device driver), and puts a portion that is closely related to the user's relationship
The outermost layer (shell), puts the process scheduling, memory management, and file system in the middle layer. Starting from computer hardware, on the basis of the instruction system, first implement the innermost function,
So I got a first-level virtual machine that is strong than the hardware machine; the function of the intermediate layer is achieved by the first stage virtual machine, and the second level of virtual machine is obtained.
Charge, finally get a function of the strongest virtual machine, that is, the virtual machine in the user's eyes. This hierarchical structure makes the inner layer provide services for outer layers, and the outer layer passes the service provided in the inner layer.
Implementing the control of the computer, the less the relationship between the outer layer and the computer hardware, simplifies the user's use of the computer. This process of the outer layer calls the inner layer service is called the system.
transfer.
The following is a simple example, the user can call him to obtain the network adapter's access traffic, if the extension is slightly extension, the function can be more powerful.
* /
#include
#include
#include
#include
#include
#include
#include
#include
Extern strunt ifnet_head; / * IFNET structure team header. * /
INT SYS_XIECALL (Struct Proc * P, Void * V, Register_t * RetVal)
{
Struct Sys_XIECALL_ARGS * UAP = V;
/ *
Struct Sys_XIECALL_ARGS {
Syscallarg (u_short) Len;
Syscallarg (struct ifnet *) myifnet;
}
* /
Int error;
Struct IFNet * IFP;
U_INT SZ;
SZ = sizeof (struct ifnet); / * The length of the structure * /
TailQ_Foreach (IFP, & IFNET, IF_LIST) {/ * Traversed All IFNet * /
IF ((U_SHORT) == IFP-> if_index) {/ * len is the parameter passed when the user performs system call, ie the unique sequence number in the system of the device * /
IF ((Error = COPYOUT (IFP, Scarg (UAP, MyifNet), SZ))! = 0) / * Copy the entire IFNET structure to the user memory after search. * /
Return (Error);
Return (0); / * No error * /
}
}
Return (EINVAL); / * Nothing to find the error error of the system call. * /
}
/ *
The last joining line in /sys/kern/syscalls.master file
286 std {int sys_XIECALL (u_short len, struct ifnet * myifnet);
Note: 286 is in order, the previous system call is 285, specifically, how much is your system call, the new system call number is in the largest
Add 1 on the system call number 1.
Insert a line in / sys / conf / files file
Find this line: file kern / vNode_if.c. If you use vi, use the command: / file kern / vNode_if.c to find it, insert a line below:
File kern / sys_mysyscall.c
Since the changes to several files to be involved in an increase in a system interrupt, a single revision is very troublesome,
/ sys / kern has a tool: make, that is, execution: CD / SYS / KERN
Make
After completing the change of the relevant header files.
* /
/ * This article can be copied directly to the / src / sys / kern directory and name SYS_MYSYSCALL.C. The program is already
OpenBSD3.0 is lowered. * /