From nobody Tue Jul 08 14:32:11 2025 X-Original-To: dev-commits-src-branches@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 4bc3Tm165lz614ns; Tue, 08 Jul 2025 14:32:12 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bc3Tl5lh9z49Mb; Tue, 08 Jul 2025 14:32:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751985131; 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=Bv0VES4LQmUAoUXlnG+iEGYZFlz0ipECt3r5KN6Egp0=; b=T2pyIwL1rVXZaEAmTu1bBkrDu+VN9DTQEYlTQN0pQ1NVmLGuAEe8j6mlW47tYeehlI3BrY Gufw//4yaRmbM2wAXRSW8IQBGEhlBVXCwft7OvdbmYv5EF7GqShuADqKL2cCr8syXM2TH7 Rzw31k8EXy37swGvZ2lGvbV8MkemiYa//Dg4HHxHNBSTFc7XmGXBRmbFjPmVr25uWyJVdn h19ImO+FqVB6fnQqXH9lcRuHnUUsArWLbZJM7fG1VLkemASOg4d6Z6nGEWblYAuCcPUI3r jQ+0udPzGlFIEOdpqMa+CGQqwm63sZ0HQgUuU4phzBjzZtsaHPJRQaktmne1fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751985131; 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=Bv0VES4LQmUAoUXlnG+iEGYZFlz0ipECt3r5KN6Egp0=; b=xBka7yeTSjp9G+bIefiCA6za2OSitcaCv7zyNl2yGBTOwvtON+1rUAB5naIOTwqYPcIfZs msfL43XBinc6MC+BITeNiswY7HLf6MjRo5G3Z3c5qh9PLmcXtiGwdWEvvE5eecMOvpRiDq PHM/E1fjKY5o1Ks4Kre7GxL7kT6mGhke7xmj0PTBo8GUElYOOdxYUb+CIDGyX+x4g4BaSw 41nNzft3w5ltc+rAlqPCkhUE9Slrv4lXqJGk64CJlAptxKUGc3VV4vhLomuYXg4mA5ftrr /gx7CDkcuFq25ya9LlvXFUH2i1jJ799agPdSrs2hqza/Ancf6v6WWl+tRz/V8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1751985131; a=rsa-sha256; cv=none; b=m7afMV2B8jOCOyguQP705uHSF0xtps5NCA9KPmkPQ0yLOszR5iaQKp8An/RgFSUCO1ayGq +EKPLIoX27ibMLLGVYEH1pbaW3XpUkJW8n4Y6LKhD8MNq27q3//i/VG6KHhtqPxB1pr6Je x7udutEB2CxiKQ4Bb7jV/LupxZOeYRlOa1+MlLSXLE4rtxR33IeKj1ZkpkkmCNau/eZhGC Jn5iyanaFzyIBRZJ+lIFhHmLn7rpoT6to9K1gQx6JchXanmowF6IEo5AB9wY6ki2/kVpgC lJi7jCWtE+kBV+rWMNPT/Yw6K0KdDAVJ5SfWAxqKOB63tKVYQJhx7SIVOG9Osw== 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 4bc3Tl5LM2zgn7; Tue, 08 Jul 2025 14:32:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 568EWBCT072031; Tue, 8 Jul 2025 14:32:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 568EWBYv072028; Tue, 8 Jul 2025 14:32:11 GMT (envelope-from git) Date: Tue, 8 Jul 2025 14:32:11 GMT Message-Id: <202507081432.568EWBYv072028@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: d9b415c9f1c8 - stable/14 - flua: add freebsd module implementing kldload/kldunload List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d9b415c9f1c8201e828dfc08640927eca8b2f64c Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=d9b415c9f1c8201e828dfc08640927eca8b2f64c commit d9b415c9f1c8201e828dfc08640927eca8b2f64c Author: Baptiste Daroussin AuthorDate: 2024-09-06 09:00:50 +0000 Commit: Baptiste Daroussin CommitDate: 2025-07-08 14:23:50 +0000 flua: add freebsd module implementing kldload/kldunload Reviewed by: markj, imp Approved by: imp Differential Revision: https://reviews.freebsd.org/D46558 --- etc/mtree/BSD.usr.dist | 4 + lib/flua/libfreebsd/Makefile | 3 + lib/flua/libfreebsd/sys/Makefile | 4 + lib/flua/libfreebsd/sys/linker/Makefile | 12 +++ .../libfreebsd/sys/linker/freebsd.sys.linker.3lua | 67 +++++++++++++ .../libfreebsd/sys/linker/lua_freebsd_sys_linker.c | 104 +++++++++++++++++++++ 6 files changed, 194 insertions(+) diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist index 70dbd2b0eef2..3ff04fe4e716 100644 --- a/etc/mtree/BSD.usr.dist +++ b/etc/mtree/BSD.usr.dist @@ -74,6 +74,10 @@ engines-3 .. flua + freebsd + sys + .. + .. .. i18n .. diff --git a/lib/flua/libfreebsd/Makefile b/lib/flua/libfreebsd/Makefile new file mode 100644 index 000000000000..6ed0451055ff --- /dev/null +++ b/lib/flua/libfreebsd/Makefile @@ -0,0 +1,3 @@ +SUBDIR+= sys + +.include diff --git a/lib/flua/libfreebsd/sys/Makefile b/lib/flua/libfreebsd/sys/Makefile new file mode 100644 index 000000000000..9f38294536f2 --- /dev/null +++ b/lib/flua/libfreebsd/sys/Makefile @@ -0,0 +1,4 @@ +SUBDIR+= linker + +.include + diff --git a/lib/flua/libfreebsd/sys/linker/Makefile b/lib/flua/libfreebsd/sys/linker/Makefile new file mode 100644 index 000000000000..318cc5078b33 --- /dev/null +++ b/lib/flua/libfreebsd/sys/linker/Makefile @@ -0,0 +1,12 @@ +SHLIB_NAME= linker.so +SHLIBDIR= ${LIBDIR}/flua/freebsd/sys + +SRCS+= lua_freebsd_sys_linker.c + +CFLAGS+= \ + -I${SRCTOP}/contrib/lua/src \ + -I${SRCTOP}/lib/liblua \ + +MAN= freebsd.sys.linker.3lua + +.include diff --git a/lib/flua/libfreebsd/sys/linker/freebsd.sys.linker.3lua b/lib/flua/libfreebsd/sys/linker/freebsd.sys.linker.3lua new file mode 100644 index 000000000000..0ab8f185388a --- /dev/null +++ b/lib/flua/libfreebsd/sys/linker/freebsd.sys.linker.3lua @@ -0,0 +1,67 @@ +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2024, Baptiste Daroussin +.\" +.\" 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. +.\" +.Dd September 6, 2024 +.Dt FREEBSD.SYS.LINKER 3lua +.Os +.Sh NAME +.Nm freebsd.sys.linker +.Nd Lua binding to +.Fx 's +Linker functions +.Sh SYNOPSIS +.Bd -literal +local linker = require('freebsd.sys.linker') +.Ed +.Pp +.Bl -tag -width XXXX -compact +.It Dv fileid, err, errno = linker.kldload(name) +.It Dv ok, err, errno = linker.kldunload(fileid|name) +.El +.Sh DESCRIPTION +The +.Nm +module is a binding to the +.Fx 's +linker functions. +List of functions: +.Bl -tag -width XXXX +.It Dv fileid, err = freebsd.sys.linker.kldload(name) +Load the kernel module named +.Fa name +and return the identifier +.Pq fileid +as an interger. +.It Dv ok, err, errno = freebsd.sys.linker.kldunload(fileid|name) +Unload the kernel module identifier either by +.Fa name +as a string, or +.Fa fileid +as an integer. +.El +.Sh SEE ALSO +.Xr kldload 2 , +.Xr kldunload 2 diff --git a/lib/flua/libfreebsd/sys/linker/lua_freebsd_sys_linker.c b/lib/flua/libfreebsd/sys/linker/lua_freebsd_sys_linker.c new file mode 100644 index 000000000000..a2dc3b487525 --- /dev/null +++ b/lib/flua/libfreebsd/sys/linker/lua_freebsd_sys_linker.c @@ -0,0 +1,104 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024, Baptiste Daroussin + * + * 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 REGENTS 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 REGENTS 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. + */ + + +#include +#include + +#include +#include +#include + +#include +#include +#include + +int luaopen_freebsd_sys_linker(lua_State *L); + +static int +lua_kldload(lua_State *L) +{ + const char *name; + int ret; + + name = luaL_checkstring(L, 1); + ret = kldload(name); + if (ret == -1) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + lua_pushinteger(L, errno); + return (3); + } + lua_pushinteger(L, ret); + return (1); +} + +static int +lua_kldunload(lua_State *L) +{ + const char *name; + int ret, fileid; + + if (lua_isinteger(L, 1)) { + fileid = lua_tointeger(L, 1); + } else { + name = luaL_checkstring(L, 1); + fileid = kldfind(name); + } + if (fileid == -1) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + lua_pushinteger(L, errno); + return (3); + } + ret = kldunload(fileid); + lua_pushinteger(L, ret); + if (ret == -1) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + lua_pushinteger(L, errno); + return (3); + } + lua_pushinteger(L, 0); + return (1); +} + +#define REG_SIMPLE(n) { #n, lua_ ## n } +static const struct luaL_Reg freebsd_sys_linker[] = { + REG_SIMPLE(kldload), + REG_SIMPLE(kldunload), + { NULL, NULL }, +}; +#undef REG_SIMPLE + +int +luaopen_freebsd_sys_linker(lua_State *L) +{ + luaL_newlib(L, freebsd_sys_linker); + + return (1); +}