From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 21 22:12:28 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D459F286 for ; Sat, 21 Mar 2015 22:12:28 +0000 (UTC) Received: from mail-pa0-x233.google.com (mail-pa0-x233.google.com [IPv6:2607:f8b0:400e:c03::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A9A0C155 for ; Sat, 21 Mar 2015 22:12:28 +0000 (UTC) Received: by padcy3 with SMTP id cy3so146949692pad.3 for ; Sat, 21 Mar 2015 15:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=UcKJmj+N12hWQpOCNRDGDVMr11Ru/OPPuPwTOV9hhbQ=; b=On9LvyPAMESC/QvtLTg6n81Xh2V3TeS/tI2Hd2KgGp6Dc4bgNELpPVGtNqnd+R9AjS wFDRAwgM/ytB4tvAYoXyM2+1XyGc4XmAhdffoWDeLGyGtJqqGSYBQnOM/I0SFRHAAPl7 m+rlQfK2t059/Q1KIUoEIUKY2N/gLEtf2I2JH+73xe5ubTljh4zfBKA26rq+8/hJi8EE 2djbv3uzFFVvxPamZH5XNhJ0956J/UKc18K1PBttl64x89x0JOKL7QTC2ehkTFfBcWWD K4XvrcF2y1Vt/bJ/uhFHKQTMSyuCco7CjzbiVr3Oy1kV/fyvhnefUygJKJSCcsN6XyK1 OLxw== X-Received: by 10.68.248.8 with SMTP id yi8mr8006990pbc.56.1426975948119; Sat, 21 Mar 2015 15:12:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.179.203 with HTTP; Sat, 21 Mar 2015 15:11:57 -0700 (PDT) In-Reply-To: <20150321220246.GE14650@dft-labs.eu> References: <20150321220246.GE14650@dft-labs.eu> From: Yue Chen Date: Sat, 21 Mar 2015 18:11:57 -0400 Message-ID: Subject: Re: How to traverse kernel threads? To: Mateusz Guzik , Yue Chen , "freebsd-hackers@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Mar 2015 22:12:29 -0000 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 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 >