From nobody Wed Nov 15 05:52:27 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SVXPV2fJwz50wfK; Wed, 15 Nov 2023 05:52:30 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SVXPV2Btyz3CfF; Wed, 15 Nov 2023 05:52:30 +0000 (UTC) (envelope-from kevans@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700027550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZGMZNnlXFZTsuP4gBhDSj3CggJQ0Pa9CGyZBLZTqsqA=; b=gb9nKmsRMmIWRIWbHIxLCQYCn1W5bSAQ2Md8UycHdyTAtOiDcu0+3hTnz7OToDGUsOpx3N 9GAYRQggSxQboy10tSZz+F19/woAjYvGOTG6/oONbAGWmWFXEKeM6ELar7QoT/mr3EhEP1 VZ60qaksrhx9E2Dnn3AeJqYz3mp/bEqntoUHQIhlglt2EtHKVeaDJZSSoXznpWzVQHJbRR 96NRtGhUegMmDvd7S2XH986Gmj7nKtWeaxIRFyPVAoL1Q80a8Vg5qcJNwhf0KMfjiL5vMP 7iRZx1OItwjPXtkmqdeWw001H8dj2aBOGGGzZgKs2Q3NrLapRw9RbKZt3Vyqng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700027550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZGMZNnlXFZTsuP4gBhDSj3CggJQ0Pa9CGyZBLZTqsqA=; b=xdvfIGoWgaE4XsfggHH3yh0nJOWcgDZk9EGREYnUJV0MV4qCmro0qjWputIpXFVtmOGBO2 TT/LUa3w3gXIMjyg4Vm6ok/sA3x/pF4zdvEIMaiYthE0R/pSJ4Nv3w7lgbxkb23BcJi1RL 85E+KZtAKhc+gxSAw4SCo07vaBWIfwU+Fz/nVFvFoUrBZsbwQ89rFhvTyErEv53BRRAsIp 9X/wOrvbw044M3rKVZ+vroBTuGgwMvwsGps2vukFQKZp1vQyq0U8wQnFryTUNrjX302+VI pTAilRjy1KaFdNNFqckavab0Wr9M+2HiUc5kHhWLihyXT4tZNzm8p7Q4cPQd8w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700027550; a=rsa-sha256; cv=none; b=vBs+tfjx6iFDj1eNdhISb56OqCA3ke+iJRILbmkbg+yFVydegxtkCoz1/oQcPr1lRxhPC1 7v97K7qtHasq/ck46IIVsKdWeseWfo10HqrTuGxGKNNYzH5HegVgrqHFtM1IR8rpPNHbuD U8alDU/g5YkaVjubMdBAb1EZrvh2rUT3Rl7XUykOSBvLG8YdKOREuNznmX8yXtGc9Luokm wssLn4IJleJlaGitFtjPDCreSv4yi4W3VoTT0EMROYCkLkcAFkWiGyLYU9+Z8BNXikk3by ROX6qB74K1e02PDAeDNh0zQXvZCchKvPbFaWl3BxcCrYTiDrZgZLdY0Ubaiqgg== Received: from [10.9.4.95] (unknown [209.182.120.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: kevans/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4SVXPT5lTKz1Ksy; Wed, 15 Nov 2023 05:52:29 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Message-ID: <3d9f647b-ad52-4dad-90e5-021ff95f25b9@FreeBSD.org> Date: Tue, 14 Nov 2023 23:52:27 -0600 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: git: b2e41172bdc0 - main - A skeleton kernel module suitable for creating new such modules. Content-Language: en-US To: "George V. Neville-Neil" , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202311142111.3AELBWJn067834@gitrepo.freebsd.org> From: Kyle Evans In-Reply-To: <202311142111.3AELBWJn067834@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/14/23 15:11, George V. Neville-Neil wrote: > The branch main has been updated by gnn: > > URL: https://cgit.FreeBSD.org/src/commit/?id=b2e41172bdc00f177f7de4d4f4963cc4d99a3178 > > commit b2e41172bdc00f177f7de4d4f4963cc4d99a3178 > Author: George V. Neville-Neil > AuthorDate: 2023-10-05 20:05:31 +0000 > Commit: George V. Neville-Neil > CommitDate: 2023-11-14 21:08:13 +0000 > > A skeleton kernel module suitable for creating new such modules. > --- > share/examples/modules/Makefile | 6 +++ > share/examples/modules/skel.c | 87 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 93 insertions(+) > > diff --git a/share/examples/modules/Makefile b/share/examples/modules/Makefile > new file mode 100644 > index 000000000000..0f0a2fb01e8a > --- /dev/null > +++ b/share/examples/modules/Makefile > @@ -0,0 +1,6 @@ > +.PATH: ${SRCTOP}/sys/skel > + > +KMOD= skel > +SRCS= skel.c > + > +.include > diff --git a/share/examples/modules/skel.c b/share/examples/modules/skel.c > new file mode 100644 > index 000000000000..fc99e13ab444 > --- /dev/null > +++ b/share/examples/modules/skel.c > @@ -0,0 +1,87 @@ > +/*- > + * SPDX-License-Identifier: BSD-2-Clause > + * > + * Copyright (c) 2023 George V. Neville-Neil > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > + * SUCH DAMAGE. > + * > + */ > + > +/* > + * SKEL Loadable Kernel Module for the FreeBSD Operating System > + * > + * The SKEL module is meant to act as a skeleton for creating new > + * kernel modules. > + * > + * This module can be loaded and unloaded from * FreeBSD and is for > + * use in teaching as well. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > + sys/systm.h should be after sys/{param,types}.h with the rest sorrted alphabetically after that. > +/* > + * Every module can hav ea module specific piece of code that is > + * executed whenever the module is loaded or unloaded. The following > + * is a trivial example that prints a message on the console whenever > + * the module is loaded or unloaded. > + */ > + "hav ea" -> "have a" > +static int > +skel_mod_event(module_t mod, int type, void *data) > +{ > + > + switch (type) { > + case MOD_LOAD: > + printf("SKEL module loading.\n"); > + return (0); > + case MOD_UNLOAD: > + printf("SKEL module unloadin.\n"); > + return (0); > + } > + return (EOPNOTSUPP); > +} > + > +/* > + * Modules can have associated data and the module data also contains > + * an entry for the function called by the kernel on load and unload. > + */ > + > +static moduledata_t skel_mod = { > + "skel", > + skel_mod_event, > + NULL, > +}; > + > +/* > + * Each module is declared with its name and module data. The > + * ordering arguments at the end put this module into the device > + * driver class, which is sufficient for our needs. The complete list > + * of modules types and ording can be found in sys/kernel.h > + */ > + "modules" -> "module" "ording" -> "ordering" It probably makese sense to stylize sys/kernel.h as either or src/sys/sys/kernel.h to make it clear that we're either referencing a relative path that could be found inside your standard include path, or a location in the tree that one can quickly browse to. > +DECLARE_MODULE(skel, skel_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); > + Thanks, Kyle Evans