How to traverse kernel threads?

Yue Chen ycyc321 at gmail.com
Fri Mar 27 18:36:26 UTC 2015


When using the following code on kernel module loading:
------------------------------------------------------------------------------------------
struct thread *td = kdb_thr_first();
td = kdb_thr_next(td);
------------------------------------------------------------------------------------------
The kernel panics.


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);
}

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.



On Sun, Mar 22, 2015 at 4:58 PM, Oliver Pinter <
oliver.pinter at hardenedbsd.org> wrote:

> Probably take a look at DDB:
>
> https://github.com/HardenedBSD/hardenedBSD/blob/hardened/current/master/sys/ddb/db_thread.c#L88
>
> On Sun, Mar 22, 2015 at 9:45 PM, Benjamin Kaduk <bjk at freebsd.org> wrote:
> > On Sat, 21 Mar 2015, Mateusz Guzik wrote:
> >
> >> But once more the real question is what are you trying to do. I don't
> >> see any use for stack info of random threads.
> >
> > One thing that comes to mind is for live binary-patching the kernel, to
> > confirm that no thread is currently in a routine which would be patched.
> >
> > -Ben
> > _______________________________________________
> > freebsd-hackers at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > To unsubscribe, send any mail to "
> freebsd-hackers-unsubscribe at freebsd.org"
>


More information about the freebsd-hackers mailing list