From owner-freebsd-threads@FreeBSD.ORG Thu Aug 30 21:20:39 2007 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7242416A41B for ; Thu, 30 Aug 2007 21:20:39 +0000 (UTC) (envelope-from jin@george.lbl.gov) Received: from smtp117.sbc.mail.sp1.yahoo.com (smtp117.sbc.mail.sp1.yahoo.com [69.147.64.90]) by mx1.freebsd.org (Postfix) with SMTP id 456E013C48A for ; Thu, 30 Aug 2007 21:20:39 +0000 (UTC) (envelope-from jin@george.lbl.gov) Received: (qmail 29050 invoked from network); 30 Aug 2007 21:20:38 -0000 Received: from unknown (HELO ?192.168.1.238?) (jinmtb@sbcglobal.net@67.111.218.125 with plain) by smtp117.sbc.mail.sp1.yahoo.com with SMTP; 30 Aug 2007 21:20:38 -0000 X-YMail-OSG: xyPvLToVM1lFDdgigf0Hrh3CJYzCs.AOLm3t9eDBNuy9Rm.IC5DNBndtpcfl0Ek7mbiUJDpwVg-- Message-ID: <46D734A1.2090700@george.lbl.gov> Date: Thu, 30 Aug 2007 14:20:33 -0700 From: Jin Guojun User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20061027 X-Accept-Language: zh, zh-CN, en MIME-Version: 1.0 To: threads@freebsd.org References: <46B245D5.1050606@george.lbl.gov> <20070803090530.GH2738@deviant.kiev.zoral.com.ua> In-Reply-To: <20070803090530.GH2738@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: hackers@freebsd.org Subject: How TLS is used in Kernel thread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2007 21:20:39 -0000 By looking through _pthread_create() code and find it uses a magic cookie -- TLS -- created by rtld_allocate_tls(), and passed into kernel by sysarch() via _tcb_set() / _kcb_set(). The information seems to be set by rtld (ld-elf.so.1) in digest_phdr() under tag PT_TLS. But it is very magic for where the TLS object is created and how it is passed to digest_phdr(). The whole object passed into kernel (as sd.gsbase) looks like this: TCB: ______________________________ | TLS | TCB | |______________|_______________| Can someone give some basic exaplain on following questions? 1) What TLS stand for? 2) Where TLS object is created? (below is the tls assigned, but I couls not find where ph is from) case PT_TLS: obj->tlsindex = 1; obj->tlssize = ph->p_memsz; obj->tlsalign = ph->p_align; obj->tlsinitsize = ph->p_filesz; obj->tlsinit = (void*) ph->p_vaddr; 3) Where in kernel the TLS is used for thread operation? Thanks in advance, -Jin