From owner-freebsd-questions@freebsd.org Mon Jan 2 12:56:44 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1721DC9B0A7 for ; Mon, 2 Jan 2017 12:56:44 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3568612F2 for ; Mon, 2 Jan 2017 12:56:42 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id v02CuMM8059588; Mon, 2 Jan 2017 23:56:22 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Mon, 2 Jan 2017 23:56:22 +1100 (EST) From: Ian Smith To: sdf cc: freebsd-questions@freebsd.org Subject: Re: when should we lock a process? In-Reply-To: Message-ID: <20170102233228.Q26979@sola.nimnet.asn.au> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jan 2017 12:56:44 -0000 In freebsd-questions Digest, Vol 657, Issue 1, Message: 10 On Mon, 2 Jan 2017 17:23:15 +0800 (CST) sdf wrote: > Hi, friends. Can you see me? > I am new here and i am reading freebsd 11.0's kernel code since these days. > I don't know the purpose of this line of code: > ================= > PROC_LOCK(p); > ================ > which is located at sys/kern/kern_exec.c line:394 function:do_execve(). > And let me paste its context here: > 387 /* > 388 * Lock the process and set the P_INEXEC flag to indicate that > 389 * it should be left alone until we're done here. This is > 390 * necessary to avoid race conditions - e.g. in ptrace() - > 391 * that might allow a local user to illicitly obtain elevated > 392 * privileges. > 393 */ > 394 PROC_LOCK(p); > 395 KASSERT((p->p_flag & P_INEXEC) == 0, > 396 ("%s(): process already has P_INEXEC flag", __func__)); > 397 p->p_flag |= P_INEXEC; > 398 PROC_UNLOCK(p); > > Could some one tell me when to lock a process? In another word, What > are we doing when we are locking a process. I can trace out its > definition but i want to know more. > ================================== > #define PROC_LOCK(p) mtx_lock(&(p)->p_mtx) > ================================== > > Thanks! > BTW: Is this maillist for kernel questions? If my question is not > suitable here, could you tell me which maillist is for kernel > developers? You will most likely find freebsd-hackers@freebsd.org a more suitable place for kernel (and other) code questions. https://lists.freebsd.org/mailman/listinfo/freebsd-hackers You can review the archives there; you may need to subscribe to post. All public FreeBSD lists: https://lists.freebsd.org/mailman/listinfo cheers, Ian