Chapter Fifth System call notes
5.1 Communication with the kernel
System calls provide a middle tier between the user space and the hardware device.
The role of the middle layer:
Provides a hardware abstraction interface for user space, ensures system stability and security, and is the only legitimate entry for the kernel except for exceptions and falls.
5.2 API, POSIX, and C libraries
The API defines the programming interfaces used by the application (System calls can be implemented).
The relationship between API, POSIX, C library, and system calls:
The C library implements the main API for UNIX systems. In addition, the C library also provides most of the POSIX APIs.
5.3 System Call-syscall
5.3.1 System call number
When a user-space process executes a system call, it uses the system call number to indicate which system call to execute.
To ensure compatibility between 32-bit and 64-bit systems, system calls have different return value types in user space and kernel space: In user space is int, in kernel space is long.
Sys_ni_syscall (): Error number, which is responsible for "filling vacancies", returns-ENOSYS, specifically for invalid system calls.
5.3.2 Performance of system calls
5.4 System call handlers
User programs cannot directly execute kernel code, nor can they directly invoke code in kernel space.
The mechanism for notifying the kernel is a soft interrupt implementation: by throwing an exception that causes the system to switch to the kernel state to point to the exception handler, at which point the exception handler is the handler for the system call.
5.4.1 specifying the appropriate system call
EAX The Register delivery system call number to the kernel.
5.4.2 parameter passing
x86 system, Ebx,ecx,edx,esi,edi stores the first five parameters sequentially. The return value is stored in the EAX.
5.5 Implementation of system calls
5.5.1 Implementing system Calls
Simple, versatile, compatible, portable, robust
5.5.2 Parameter Validation
The most important check: whether the user-supplied pointer is valid.
The area of memory that points to is in the user space, in the address space of the process, in the access permission range of the memory.
5.6 System Call Context
(1) The kernel is in the process context when it executes system calls.
(2) The current pointer points to the present task, which is the process that raised the system call.
(3) In the context of the process, the kernel can hibernate and can be preempted.
(4) System_call () is responsible for switching to user space and letting the user continue execution when the system call returns.
5.6.1 The last step of binding a system call:
(1) Add the table entry in the system call table;
(2) The system call number is defined in <asm/unistd.h>;
(3) Compile into kernel image and put the relevant files under kernel/.
5.6.2 access system calls from user space
"Linux kernel Design and Implementation" chapter 5th book Finishing