kernel space and user space
Introduction
The Linux system divides itself into two parts, the core software, which is kernel, also known as kernel space, and the other part is a normal application, which is called user space.
Linux simplifies the segmentation mechanism so that the virtual address is always consistent with the linear address, so the virtual address space for Linux is also 0~4g. The Linux kernel divides this 4G-byte space into two parts. The highest 1G bytes (from virtual addresses 0xc0000000 to 0xFFFFFFFF) are used by the kernel, which is called "kernel space". Instead, the lower 3G bytes (from the virtual address 0x00000000 to 0xBFFFFFFF) are used by each process, called "User space." Because each process can enter the kernel through system calls, the Linux kernel is shared by all processes within the system. Thus, from a specific process perspective, each process can have a virtual space of 4G bytes.
Linux uses level two protection: level 0 for kernel use, and 3 for user programs. As you can see (it is not possible to represent a graph), each process has its own private user space (0~3G), which is invisible to other processes in the system. The highest 1GB bytes virtual kernel space is shared by all processes and the kernel.
Kernel space is the kernel code and data, while the process of user space is stored in the user program code and data. Both the kernel space and the user space are in virtual space.
Although kernel space occupies up to 1GB bytes in each virtual space, mapping to physical memory always starts with the lowest address (0x00000000). For kernel space, the address map is a very simple linear mapping, 0xc0000000 is the physical address and linear address between the amount of displacement, in the Linux code is called Page_offset.
Reciprocal Effects
Now, more and more applications need to write kernel-level and user-level programs to accomplish specific tasks together, typically in the following pattern: first, the Kernel service program takes advantage of the privileges and services provided by the kernel space to receive, process, and cache data, and then writes the user program to interact with the previously completed kernel service program. Specifically, you can use the user program to configure kernel service program parameters, extract the data provided by the kernel service program, of course, you can also enter the processing data to the kernel service program.
Typical applications include: NetFilter (Kernel service Program: firewall) vs iptable (User-level program: Rule Setup program), IPSEC (kernel service Program: VPN protocol section) vs IKE (User-level program: VPN key negotiation processing) And, of course, a large number of device drivers and the corresponding application software. These applications are both kernel-level and user-level programs that perform specific tasks together by exchanging information with each other.
Interaction
In the development of device driver, kernel function module and other system level development, it is necessary to interact information between kernel and user state. Linux provides a variety of ways to interact with the kernel state and the user state for different situations. This includes kernel boot parameters, module parameters and Sysfs, Sysctl, System calls, NetLink, Procfs, Seq_file, Debugfs, and RELAYFS, among other things, such as BRK () system calls, signals, memory mapping mechanisms, and so on.
Android Deep Exploration with Hal Drive Development (Vol. 1)--sixth chapter essay