How to traverse kernel threads?

Yue Chen ycyc321 at gmail.com
Sat Mar 21 22:12:29 UTC 2015


Thanks for the quick reply.

What I am trying to achieve is to get the stack starting and ending address
of a kernel module.
I think it could be got from

struct thread *td
td->td_kstack
td->td_kstack + td->td_kstack_pages * PAGE_SIZE

So I need to get the ``td'' first.
Maybe there is another way to get it other than traversing?

On Sat, Mar 21, 2015 at 6:02 PM, Mateusz Guzik <mjguzik at gmail.com> wrote:

> On Sat, Mar 21, 2015 at 05:54:24PM -0400, Yue Chen wrote:
> > Dear all,
> >
> > Is there an easy way to traverse all the kernel threads (including
> > modules') in a FreeBSD kernel module?
> > The resulting structure would be `` struct thread * ''.
> >
>
> Well if you read kthread_add you can see you just need to traverse
> threads linked into proc0.
>
> Chances are you also want to traverse kernel process (see kproc_create).
>
> The real question though is what are you trying to achieve.
>
> --
> Mateusz Guzik <mjguzik gmail.com>
>


More information about the freebsd-hackers mailing list