peroksid
peroksid

Reputation: 357

Call do_fork inside kernel

For some experimental purposes i need to create a child kernel process without shared memory. As i know, the kthread_create and kernel_thread routines is always call do_fork with CLONE_VM. But i need to call do_fork without CLONE_VM

I have found in arch/x86_64/kernel/process.c(x86_64 is a suitable architecture for the experiment):

asmlinkage long sys_fork(struct pt_regs *regs)
{
        return do_fork(SIGCHLD, regs->rsp, regs, 0, NULL, NULL);
}

I think, i should call do_fork(SIGCHLD, regs->rsp, regs, 0, NULL, NULL). But i can't understand how to setup the pt_regs structure. I want to setup the structure based on registers of the current process. Is there is a function to fill pt_regs based on current process? Or maybe there is an different way how to create process with own memory inside kernel?

Upvotes: 0

Views: 834

Answers (2)

Tsyvarev
Tsyvarev

Reputation: 66348

Kernel's address space is always shared between processes. CLONE_VM flag affects only on user address space sharing.

So, if you need kernel process, just use kthread_create. Thread, created with this functions, is allowed to use only kernel address space.

Upvotes: 1

Oldest Software Guy
Oldest Software Guy

Reputation: 751

You need not fill out the pt_regs structure; the only thing used from it is the stack pointer of the user-space task. Routine names of the form sys_foo are always expecting user-space values; for example, any address value passed in MUST be a user-space address. On the other hand, worker routines formed like do_foo expect kernel-space values; never call sys_foo from inside the kernel.

Upvotes: 0

Related Questions