Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Mar 2015 20:49:20 +0100
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Yue Chen <ycyc321@gmail.com>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, Oliver Pinter <oliver.pinter@hardenedbsd.org>, Benjamin Kaduk <bjk@freebsd.org>
Subject:   Re: How to traverse kernel threads?
Message-ID:  <20150327194920.GB18158@dft-labs.eu>
In-Reply-To: <CAKtBrB6ZF2FVExmDd%2Bt8yFpN0H7xHwaieWgvryR535Vc2cNBjw@mail.gmail.com>
References:  <CAKtBrB4h13ZFJ=V0fvkDeTG-L6=e5Uz9%2BHfYc8vY523Y3X6N0A@mail.gmail.com> <20150321220246.GE14650@dft-labs.eu> <CAKtBrB5KNqt6UJ1R_BQpPfTvQZdUzGvZZtT7Uz5qd4VrrfgEdw@mail.gmail.com> <20150321232622.GF14650@dft-labs.eu> <alpine.GSO.1.10.1503221644440.22210@multics.mit.edu> <CAPQ4ffuszSi%2B_SopJdCkoFr4OoY9=BZVbO6oo_s0sKrn8Rgjrw@mail.gmail.com> <CAKtBrB6ZF2FVExmDd%2Bt8yFpN0H7xHwaieWgvryR535Vc2cNBjw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Mar 27, 2015 at 02:35:55PM -0400, Yue Chen wrote:
> When using the following code on kernel module loading:
> ------------------------------------------------------------------------------------------
> struct thread *td = kdb_thr_first();
> td = kdb_thr_next(td);
> ------------------------------------------------------------------------------------------
> The kernel panics.
> 

Panics how?

Also you can easily see these functions don't lock anything, so it would
be assumed you took appropriate locks.

Except it seems there routines are supposed to be only used when
execution is 'frozen' (e.g. when escaped to the debugger).

> 
> And when printing all threads in proc0 (all kernel threads?):
> ------------------------------------------------------------------------------------------
> struct proc *p = pfind(0);
> FOREACH_THREAD_IN_PROC(p, td) {
>     uprintf("td: %x\n", td);
> }
> 

proc0 is an exported symbol, no need to pfind.

> td = curthread;
> uprintf("cur td: %x\n", td);
> ------------------------------------------------------------------------------------------
> The ``curthread'' (from this kernel module running the above code) is not
> in the 0 process group.
> 

There is no 'curthread from kernel module'.

My guess is you do this work from module initializator, and in that case
curthread is the thread which loads the module, and such a thread is
definitely not linked into proc0.

Still nobody knows what you are trying to do.

-- 
Mateusz Guzik <mjguzik gmail.com>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150327194920.GB18158>