tags:

views:

97

answers:

2

Now I know that developing an app that goes into kernel space should be avoided - its hard to debug, complex etc.... with that off the table what are some advantages to moving an app from user space to the kernel? after all if there were no plus sides it would never be done...what are some?

+1  A: 

You get the chance for a tiny bug in your program to scribble all over memory and corrupt the entire system and all its processes and functions. If you are lucky, the system will crash.

msw
+1  A: 

Some possible advantages:

  • system calls might be faster (i.e. lower latencies), as the CPU doesn't have to switch from application mode into kernel mode. (This is not necessarily true, as the CPU might make a finer distinction than simply "user space" and "kernel space". Intel x86 CPUs for example have a ring model encompassing 4 distinct privilege levels.) 1)

  • you might get direct access to the system's hardware via memory and I/O ports.

  • you might be able to suppress task switching, if you need to do something without being interrupted

  • you might be able to circumvent security mechanisms enforced by the operating system (e.g. read/modify other processes' memory). (Malware could take advantage of this if it gets installed as a kernel-mode device driver.)

(And of course, as you are aware, there's many many disadvantages and security risks. The distinction between application space and kernel space is there for good reasons.)


1) See e.g. the article Making system calls from kernel space from Linux mag:

For example, a high-performance Web server may wish to reside in the kernel for increased throughput and lower latency. However, there is also a safety tradeoff [...]

stakx
ok that puts a little perspective around it, the second reason seems to be the only drive I can think of that would drive a team to put it in kernel space.
jtzero
You can arrange for direct access to the system's hardware in userspace, too (at least for I/O ports and device memory regions). Interrupt service routines can't be done that way, though.
caf