From owner-freebsd-current@freebsd.org Wed Aug 2 10:41:49 2017 Return-Path: Delivered-To: freebsd-current@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 7966DDCCB7C; Wed, 2 Aug 2017 10:41:49 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 455B8848B4; Wed, 2 Aug 2017 10:41:49 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 2FF30260179; Wed, 2 Aug 2017 12:41:47 +0200 (CEST) Subject: Re: order of executing MOD_LOAD and registering module sysctl-s To: Andriy Gapon , FreeBSD Hackers , FreeBSD Current References: <62e7ab4d-8956-545e-b204-4fb63cfe5fbf@FreeBSD.org> From: Hans Petter Selasky Message-ID: Date: Wed, 2 Aug 2017 12:39:36 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <62e7ab4d-8956-545e-b204-4fb63cfe5fbf@FreeBSD.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Aug 2017 10:41:49 -0000 On 08/02/17 12:13, Andriy Gapon wrote: > > As far as I understand a module initialization routine is executed via the > sysinit mechanism. Specifically, module_register_init is set up as the sysinit > function for every module and it calls MOD_EVENT(mod, MOD_LOAD) to invoke the > module event handler. > > In linker_load_file() I see the following code: > linker_file_register_sysctls(lf); > linker_file_sysinit(lf); > > I think that this means that any statically declared sysctl-s in the module > would be registered before the module receives the MOD_LOAD event. > It's possible that some of the sysctl-s could have procedures as handlers and > they might access data that is supposed to be initialized by the module event > handler. > > So, for example, running sysctl -a at just the right moment during the loading > of a module might end up in an expected behavior (including a crash). > > Is my interpretation of how the code works correct? > Can the order of linker_file_sysinit and linker_file_register_sysctls be changed > without a great risk? > > Thank you! > > P.S. > The same applies to: > linker_file_sysuninit(file); > linker_file_unregister_sysctls(file); > Hi, Not sure if this answers your question. If a SYSCTL() is TUNABLE, it's procedure can be called when the sysctl is created. Else the SYSCTL() procedure callback might be called right after it's registered. I think there is an own subsystem in sys/kernel.h which takes care of the actual SYSCTL() creation/destruction - after the linker is involved. --HPS