Execute a program in kernel space in Linux
Asked Answered
M

7

10

If I want to execute a user program (not a kernel module) in Linux kernel space, what options do I have?

I have looked at KML(kernel mode linux) but that is specific to IA-32 architecture. I want a solution which is cross platform and can work on embedded linux systems.

Medicate answered 20/7, 2010 at 12:38 Comment(1)
Why does this program need to run in kernel mode?Heteropterous
H
7

User programs don't execute in kernel space - that's what makes them user programs.

If you want to execute code in kernel space you have two options: build it in to the kernel, or load it with a kernel module.

Hydrometallurgy answered 20/7, 2010 at 13:59 Comment(1)
By user program I mean a program compiled to run in user space i.e by exec* system calls or any other way. Kernel Model Linux or KML enables us to run these programs in linux kernel space without any modifications but it is specific to IA32 architecture. I am looking which can work on multiple architectures.Medicate
H
6

call_usrmodehelper

Hornback answered 9/8, 2010 at 6:29 Comment(1)
I'm a little late to the game, but I was just looking up the same thing, and this would be the correct answer. To be precise, this is how you cause a userspace program to start from kernel space, which is what I would believe the OP's original intent.Main
M
5

You wrote in another question that you are a newcomer to kernel programming. Using KML is highly unconventional, and will be far more complicated that doing things in the standard way. That will make your learning that much more difficult. I would suggest that your best option is reevaluate why you want to run a user space app in kernel space and find way not to do it.

There may be a good reason to do such a thing, but it's not clear to me what that reason could be. One thing you should understand with kernel development is that just because something is possible, it's not necessarily something that should be done.

If you really want a cross platform solution, you'll have to write it yourself. The only architectures supported by KML are IA32 and AMD64.

Mikamikado answered 20/7, 2010 at 18:22 Comment(0)
P
3

Kernel programming is pretty much by definition platform specific, since kernels for different platforms are all different.

Proviso answered 20/7, 2010 at 13:0 Comment(0)
G
3

Take a look at FemtoLinux. Basically, it is a KML for embedded systems and embedded processors such as ARM and MIPS

Grudging answered 29/7, 2010 at 18:25 Comment(1)
Where can i get femtolinux. They dont have download link there.Medicate
B
0

If you want to start a user program from kernel space, take a look at run_init_process(). It's the way kernel run the init program.

Bowstring answered 5/2, 2018 at 11:26 Comment(0)
S
0

You could execute it the same way the bootloader executes the operating system (remember, an operating system is just one or more programs executed on top of the kernel). Per standard operation, the bootloader transfers execution to the kernel program along with a selection of parameters, just like a CLI program, and then loads the /init executable or whatever is specified by the rdinit parameter as the main application of the operating system; in reality this could be any program, provided that all required concurrent processes (a.k.a. "services") for that application are running, as is demonstrated by the fact that the original /init program was a shell script that concurrently launched those required processes.

See also:

FYI: I'm well aware that this question is more than ten years old and thus either answered or dropped, despite that this solution was even available at that time, so "this is for posterity..."

Seward answered 1/12, 2021 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.