From patchwork Thu Dec 12 16:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13905612 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7823226555; Thu, 12 Dec 2024 16:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734021299; cv=none; b=D2eUHPtQgsPRVE7ZTdA4o9BWYj2KjDrTQD/KPwZDNHkJQMsE2fHVw5rmpW5BkCsoaQlI28vkbcIpcze8C3SHSmn7NEiESt6EDdzgXHplL54tjbydOenlCx9f/Lvw8aj8XmdJoXQo6PE7sziPu5Jmhcn6XCwMQ+4Xp9iFEu3+kzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734021299; c=relaxed/simple; bh=qnI9EdwsG9kMkRPvMWH3A7l2tEEs2+Fz3s89mI50uEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FX8Bo6GaXQHGxQbumqoMuBK0sl+KBoy6LMjghLYrLMrS+TWnLxif5YDzc9pBP2GaesgdtMX2ZPwK3hKdDKLqE+3Ru9fyDJICebe+kbDHLYKmqvNTxMnCYDreZsz+MkQkcDsezVaZf51k3UkCc4Hi0pIBN2Bcarf3l5sdaG2mLKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T0JK/dyz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T0JK/dyz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF02C4CED0; Thu, 12 Dec 2024 16:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734021299; bh=qnI9EdwsG9kMkRPvMWH3A7l2tEEs2+Fz3s89mI50uEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0JK/dyzmUprEY8p5NkKPpaYSffbPTefJaMy2enyX+EMt1inLdNNB9iGbVR5E7/zo aOtL7nh+LbEJMuWuqAC1IVTCXKRCvu/nj2ObiH5JFzzy7Ren4qlpdwtzXdbRpw9mUM FCJvlTjJZdKRQ8fmtkjgV+hUoYaDUHNVj07J7lTgYmZsQgQoEZoMGVUMe+F1+xr5DH fEQ4AsJSSnK6Lk7jlvK+q+WRNDx3sr09rq8xQkgQwmxNY19vItbstVQHXLvukPfJIE RVuH4QdVNMczKTh46JJwScawl8+9mDgFzqTagt52MZhnT751PUH6/mhk6+aEwKhCJA IAlZn6X4eNe5Q== From: Danilo Krummrich To: gregkh@linuxfoundation.org, rafael@kernel.org, bhelgaas@google.com, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, tmgross@umich.edu, a.hindborg@samsung.com, aliceryhl@google.com, airlied@gmail.com, fujita.tomonori@gmail.com, lina@asahilina.net, pstanner@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, robh@kernel.org, daniel.almeida@collabora.com, saravanak@google.com, dirk.behme@de.bosch.com, j@jannau.net, fabien.parent@linaro.org, chrisi.schrefl@gmail.com, paulmck@kernel.org Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, rcu@vger.kernel.org, Danilo Krummrich Subject: [PATCH v6 01/16] rust: module: add trait `ModuleMetadata` Date: Thu, 12 Dec 2024 17:33:32 +0100 Message-ID: <20241212163357.35934-2-dakr@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212163357.35934-1-dakr@kernel.org> References: <20241212163357.35934-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to access static metadata of a Rust kernel module, add the `ModuleMetadata` trait. In particular, this trait provides the name of a Rust kernel module as specified by the `module!` macro. Signed-off-by: Danilo Krummrich --- rust/kernel/lib.rs | 6 ++++++ rust/macros/module.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index e1065a7551a3..61b82b78b915 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -116,6 +116,12 @@ fn init(module: &'static ThisModule) -> impl init::PinInit { } } +/// Metadata attached to a [`Module`] or [`InPlaceModule`]. +pub trait ModuleMetadata { + /// The name of the module as specified in the `module!` macro. + const NAME: &'static crate::str::CStr; +} + /// Equivalent to `THIS_MODULE` in the C API. /// /// C header: [`include/linux/init.h`](srctree/include/linux/init.h) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 2587f41b0d39..cdf94f4982df 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -228,6 +228,10 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { kernel::ThisModule::from_ptr(core::ptr::null_mut()) }}; + impl kernel::ModuleMetadata for {type_} {{ + const NAME: &'static kernel::str::CStr = kernel::c_str!(\"{name}\"); + }} + // Double nested modules, since then nobody can access the public items inside. mod __module_init {{ mod __module_init {{