Re: kernel thread support - LWP's

Andi Kleen (ak@muc.de)
Sun, 18 Jul 1999 19:48:15 +0200


On Sun, Jul 18, 1999 at 06:27:14PM +0200, Jeff Dike wrote:
> > What you're beginning is a very old flame war: the fork+exec vs
> > CreateProcess(10+options) argument
>
> I don't think so. I'm not trying to combine fork+exec. I'm trying just to
> safely do fork. In the user-mode kernel, everything runs in a single address
> space. When a process forks, the call is modified to clone sharing a bunch of
> things. The new child can't be allowed to run. If it did, it would mess up
> the address space that really belongs to its parent. This is why a
> CLONED_STOPPED flag would be very pleasant.

>
> Instead of accusing me of starting a flame war, why don't you show me some
> code that's a nice a tacking a CLONED_STOPPED into clone_flags?

I just wanted to point out that it is dangerous ground.

Alan did already, but I repeat it:

[Given the glibc2 clone wrapper; untested]

void start_stopped_thread(void (*func)(void *), void *arg, void *stack)
{
struct arg {
void (*func)(void *);
void *real_arg;
} a;
pid_t pid;
int status;
a.func = func;
a.real_arg = arg;
pid = clone( trampoline, &a, stack, CLONE_VM | ... );
waitpid(pid, &status, WUNTRACED);
if (WIFSTOPPED(status)) {
...
}

}

void trampoline( void * f)
{
struct arg *a = (struct arg *) f;
kill(getpid(),SIGSTP);
a->func(a->real_arg);
}

It is essentially the same work the kernel would do for a CLONE_STOPPED, just
in user space.

-Andi

-- 
This is like TV. I don't like TV.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/