Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between kernel and user mode programming?

I would like to know how a kernel programmer thinks about memory vs user mode programmer. I would also like to know a few differences between kernel programming and user mode programming.

like image 290
mousey Avatar asked May 22 '10 06:05

mousey


2 Answers

User mode programming refers to programming under the protection, supervision, and abstraction mechanisms of the operating system kernel. e.g: in user mode you can't write disk sectors, as they are "hidden" under the file system APIs. You can't write to physical memory addresses, as the kernel is in control of translating between virtual and physical memory, altough you can reserve memory for your own needs. Also, altough you can go low level (assembly) you can't execute instructions that are privileged, for example, trying to mess with processor caches, TBLs, and MMU.

Kernel programming allows you to program the system for low-level duties without any restriction. Hardware drivers for example cannot be programmed under user mode since they need to access hardware directly to do I/O, map memory regions,etc.

Of course you can't think kernel-mode as "less restricted" and go to develop applications in KM. Many system facilities for application programming are not available under KM, as the libraries required to interact with the user run in usermode. Also, those usermode libraries won't link to a kernel module.

This distinction may be more or less defined depending on the operating system. KM/UM is a nonsense in DOS, where programs were allowed to access system resources freely (at least in 8086/88 real mode -- this is not the case with DOS Extenders).

like image 96
Hernán Avatar answered Oct 07 '22 01:10

Hernán


See Jeffs article on Understanding User and Kernel Mode

like image 45
stacker Avatar answered Oct 06 '22 23:10

stacker