From owner-freebsd-current@freebsd.org Wed Aug 2 10:14:11 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 6F98EDCC00D; Wed, 2 Aug 2017 10:14:11 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citapm.icyb.net.ua (citapm.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 946B483684; Wed, 2 Aug 2017 10:14:10 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citapm.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id NAA20807; Wed, 02 Aug 2017 13:14:08 +0300 (EEST) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1dcqfH-000Pzq-V3; Wed, 02 Aug 2017 13:14:07 +0300 To: FreeBSD Hackers , FreeBSD Current From: Andriy Gapon Subject: order of executing MOD_LOAD and registering module sysctl-s Message-ID: <62e7ab4d-8956-545e-b204-4fb63cfe5fbf@FreeBSD.org> Date: Wed, 2 Aug 2017 13:13:11 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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:14:11 -0000 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); -- Andriy Gapon