Re: Do kernel threads need their own stack?
Brent Baccala (email@example.com)
Wed, 18 Jul 2001 12:04:52 -0400
Petr Vandrovec wrote:
> On 18 Jul 01 at 3:16, Brent Baccala wrote:
> > The first thing I notice is that this function refers not only to the
> > clone flags in ebx, but also to a "newsp" in ecx - and ecx went
> > completely unmentioned in kernel_thread()! A disassembly of
> > Anyway, I'm confused. My analysis might be wrong, since I don't spend
> > that much time in the Linux kernel, but bottom line - doesn't
> > kernel_thread() need to allocate stack space for the child? I mean,
> > even if everything else is shared, doesn't the child at least need it's
> > own stack?
> ecx specifies where userspace stack lives, not kernel space one, and
> each process gets its own kernel stack automagically. As you must not
> ever return to userspace from kernel_thread(), it is not a problem.
> Because of exiting from kernel_thread() to userspace is not trivial
> task, I do not think that is worth of effort.
OK, now I see it. The kernel stack lives at the top of the task
structure, which is allocated as a full page at the beginning of
do_fork(), then type cast down to a struct task_struct. The copy_thread
code looks past the end of the task_struct and sets up esp0 to point to
the end of the page.
For news from freesoft.org, subscribe to firstname.lastname@example.org:
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to email@example.com
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/