User space and kernel space (modules and applications)

Source: Internet
Author: User
User space and kernel space

In modern computer architectures, storage management usually includes protection mechanisms. The purpose of protection is to prevent a task in the system from accessing another or operating system storage area. For example, in the intelx86 system, the privileged protection mechanism is provided to restrict access to the storage area through the difference of the privileged level. Based on this architecture, the Linux operating system divides itself into: some core software is independent of common applications and runs at a high level of privilege, (Linux uses Intel's privileged level 3 to run the kernel .) They reside in protected memory space and have all the permissions to access hardware devices. Linux calls this a kernel space.

The other part is executed as an application in the user space. They can only see part of the system resources they are allowed to use, and cannot use certain specific system functions, can not directly access hardware, can not directly access the kernel space, of course, there are other specific use restrictions. (Linux uses Intel's privileged level 0 to run user programs .)

 

 

Kernel Modules and Applications

The kernel module is the code that allows the operating system kernel to load and execute as needed. This also means that the operating system can be detached without any need. They extend the features of the operating system kernel without restarting the system. For example, one of the kernel modules is the device driver module, which allows the operating system to correctly identify and use hardware devices installed on the system.

If there is no kernel module, we have to re-compile the kernel image of a Single Kernel Operating System to add new features.

(1) A user program generally starts from the main () function and executes a series of commands and ends the program after the command execution is complete. The kernel modules are a little different. The kernel module either starts from the init_module function or the function call specified by the macro module_init. This is the entry function of the kernel module. It tells the kernel module to provide functional extensions and prepare the kernel to call it as needed. After this is done, the function execution is complete. The module does nothing before being called by the kernel.

All modules can either call cleanup_module or use the function specified by the macro module_exit. This is the exit function of the module. It revokes everything done by the entry function. For example, you can deregister the function registered by the entry function. All modules must have entry functions and exit functions.

 

(2) An application can call undefined functions because external references can be parsed during the connection process to use the appropriate function library. A module is only connected to the kernel, therefore, it can only call functions with kernel Export (such as printk) without any accessible libraries.

 

(3) segment errors during application development are harmless and can always be traced to issues in the source code using the debugger. An error in the kernel module is fatal even if it is not correct to the entire system, or at least cause a fatal error to the current process.

(4) applications run in the user space. The processor prohibits direct access to hardware and unauthorized access to memory. The kernel module runs in the kernel space and can perform all operations.

(5) Generally, applications do not have to worry about changing their runtime environment due to other situations. kernel module programming must consider the handling of concurrency issues.

 

 

 

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.