From nobody Tue Nov 14 21:11:32 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 4SVJrN3f87z50sNT; Tue, 14 Nov 2023 21:11:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SVJrN389Bz3Bn6; Tue, 14 Nov 2023 21:11:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699996292; 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; bh=TGMsMT7q/eIud0poKm97nTdwYypHVJ5D7eEhUDoVQh4=; b=lokULtpJ7uefPBRT1uRyErK9LAeKrxu8PsfyEaKM4kkkHs4qHFgHnqoi/106uXNZyo6ZLu zg57zPh6/V1GpbMrpsazCdEAOcBmJQewUCbpMWagUeraLno43MOMm6Td2watfFmHCob4hw AHv5LpDIUr97C2sJc272VpIvkoQgbigKZFomabjiavgVHlbumIUmC4Yiwlm/1lqzBYDTJA tLw+QHGS/qXdBsM0QJPLkdTW+3T6wAumG5els/H8HR/sp/wCrKYa/Qbp4HiIowEoI84lcR Wr13Eqpob7RLHB9zKcaPUErZCLHA+F5AFBkk0nldyPd+6beHBJ3XlnB030vbpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699996292; 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; bh=TGMsMT7q/eIud0poKm97nTdwYypHVJ5D7eEhUDoVQh4=; b=QvuS89PjlyUKf7FHHU1croJAxueV9946/EYW84NrZEFHRdlcWHZ0laBWyGnWPkpbV2Vcwi 3NQCxVjDVbVW9s/QnxIsDvuHTb6/RGtPXrNE9KJxojVw7A9hEQjLOEvDEf1ueQKz4TwMZs wQvqFPHqIWvluEBHFkdJgDJ+TfM3niPhxYgibsKUMa9nwZ1RZmTOKmJG8UKK4fICgAWSYu StF1gyu5jyP1WQ8kb4wkWgWA7ZeXUh2aUr313zE5Ip5MpVEwHIFs/hoFHCDS5pEUiOIi6u sVmO11w+R714PHy6EPMGvufBwxVqzvHQjl7aFInBGcbp5sV4InT4zVhcGFqd1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699996292; a=rsa-sha256; cv=none; b=kr4P6Qy0R1uFCR71u4Fn3i7zGumnuu8OPTlmf7cziD5bZLd1JXTe4eMH4pjyEmo3YO3gZz 8SpvAVVsMWDmR5SmfRbY581ZwG6cydxKKvciig1QnbCAbUd9krhl2Z11Dn88VrtQ5keYnS eu8pEj7T85Yw/xsaxGZwFmPI7MNtubSM9/BzfOAMRhJAS3XOSLxv519qt0O1qcmP3vCSPj tJ1gmXq1Jx5zKYZn6RwqJtsML48A718puhz65j/XSXCr44ilgM1euLZIrw6ZmEYi8d84KS 3huKgbEp8i7sW2sSur3PJLQqLf+8fWBtInSFz/lSABrTXdw2lR6vFEYr1UsXTw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SVJrN2C5Vz14MY; Tue, 14 Nov 2023 21:11:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AELBWFZ067837; Tue, 14 Nov 2023 21:11:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AELBWJn067834; Tue, 14 Nov 2023 21:11:32 GMT (envelope-from git) Date: Tue, 14 Nov 2023 21:11:32 GMT Message-Id: <202311142111.3AELBWJn067834@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "George V. Neville-Neil" Subject: git: b2e41172bdc0 - main - A skeleton kernel module suitable for creating new such modules. 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gnn X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b2e41172bdc00f177f7de4d4f4963cc4d99a3178 Auto-Submitted: auto-generated 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 + +/* + * 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. + */ + +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 + */ + +DECLARE_MODULE(skel, skel_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); +