Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp52798lqe; Tue, 26 Mar 2024 20:24:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGcfP3b+CBDpeUFPuvjcdj31vdKyTAwHU+WQs41wmQQuK61kPmZH86TyLbVltLgs7oCOrb8TrCBWY/qPtyVpijH/zdfseQvf6DeTVDCg== X-Google-Smtp-Source: AGHT+IEdabBfcULoBRQtIpdAXr2OF9yIynIfNL61GA1ks/gyAE8C/FhZHOOYqjL3c9ZHd2mViAoB X-Received: by 2002:a05:6102:305:b0:476:dcdf:96d7 with SMTP id 5-20020a056102030500b00476dcdf96d7mr2574443vsa.17.1711509872797; Tue, 26 Mar 2024 20:24:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711509872; cv=pass; d=google.com; s=arc-20160816; b=lqTDoFJPmRu20pZVbFdoH1F7sTacyGzgLS5RqPGWc4tLgSwYBqL6EV0K2+2mxYJeKx UysWHGAvRyVxw+uTamCSudfPanDQklKjN8vL5ANS7E+n+3pSxp/xgbj8i6sdTIkyprx+ R51NAPcxPG/IM4rjiQSk5/Esjg1MADS3cGfARgrl8xN7Q5Nc8u4Fspb8z4CpfJwbTpcW jlQ35RCqYek6cXo9b/m+ULgEyb7hIeQOF/lnBa9Qgn1L/3ODsmmb2UerjRmKNuj1h2UN rOibhuCxNAbIT3J+CvbwlCt0R2COYtS/02E0Aqjo5ISHzZ380kMdXB2PqHbvQAa+IS7P ZM+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TdCnxy848WA8LUn6hf+mVOuOXAd6/0/8vKwia4QjL5k=; fh=Ohk1ck+ZpfyEj1osw26VQzNEOLY9/38aGFQifrXZyLY=; b=h2erU4H4Fr/gdIdombOtK4gl4EzNJPNkwj6WHh9lAepKn6arxPa7it0Fjx/zUEQxBb COvMUXstCOoKmZBRI+nOJ3CBlUHhC5qU50xFVghdlNI0d8e7zFKgrcGIkoROSYCgSp4L Un767Rrh/AbTxiBzE6oJUnZ+qFp0Fej+jL9FK1b9YDqbt1lZQ0cFKBIiWfd3WQ4rtSae HdcD/CdlM3kGvjC6H0BUY84b7lZHrTEmqyqrEbuMDhh98TNlleYDkKHm/BjZT/VWd23S RipIs+J18/TyRw74pld4Ix+STeEpTUlqfoNpn/OYDYqtSF7bHKAi8p0XRCtrmDv73sR/ zCiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XWbN2nOc; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-120257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z37-20020a05620a262500b0078a4e457384si2514931qko.455.2024.03.26.20.24.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 20:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XWbN2nOc; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-120257-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 784951C24045 for ; Wed, 27 Mar 2024 03:24:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDE3D23775; Wed, 27 Mar 2024 03:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XWbN2nOc" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 753DC241E9; Wed, 27 Mar 2024 03:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711509844; cv=none; b=sHPbMUBk9R5xKJnMHpgBc6beYIPDvTuxxdvaQSRxm4LUNj263EQokL9KjmDbWx3JUm4fXH9ea/Ef72kR1mMv2sBNFCI2xhLrw4MN62PkwVkoYGc2ypGHtbCs5fYuIfMdexmfuc6O8L0o3BUF5VHrSLpdzMHhpNG70VsalbBWET4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711509844; c=relaxed/simple; bh=rXsZKc9VdNaDW2hlrhw/V/PAjFJZllDwToJz511SSzY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nmDi7aQWQtOyS7c0/B+WoCp1MdWM5ocuci1Pi9jVds/ntA9XRcVxfi39yv5IZpq4PRt1AZITC0EmeG5Aa9QzvZD5J058DNRQp2VtdQjxAQXvwTXadB3AyhJoREh7TT3prHAk6+Mv+3h6e5Ryg5gPR4xAqBjM1HAIUWl7ktdi7pY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XWbN2nOc; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e0025ef1efso41045515ad.1; Tue, 26 Mar 2024 20:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711509843; x=1712114643; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TdCnxy848WA8LUn6hf+mVOuOXAd6/0/8vKwia4QjL5k=; b=XWbN2nOcwh+foaCqPo855NmAt8923nR85WXLNcKkdjL8L28Ps5vOqYPq6W+Of6G4Yj DFiZVdrpO1JMzZ1RyBESWReHb9RynW80Qou7zeQHeP9USS4UwfjStnY2d1aIf6q1oTuO 5a+uZb1vkXhFMg7yZH476erOJDO8HaDMkxx0PV+NBHngsk1oUmcEn6S/n/bevRO+rh8Z reIsZ5hM8w3hARxcPqyA17IIA/VyAzRyZS063Gvnxisr4yPdpLrYb2xI5CRl1PSY0uJI WYAUwBXFB36VyJY6CFOh3dXYBmz2TKBvlvmgjIF7pwHzN78spoj5yckG7fpv1emyCHUg ohkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711509843; x=1712114643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TdCnxy848WA8LUn6hf+mVOuOXAd6/0/8vKwia4QjL5k=; b=ThrsSnmqAmdupWirB2ksT+c9I8OTzH+RHnN0LI6wFqnzSya/+QpJbInr5xl+IFQtCz 6rsX+GL/152wDXHOVvKwcHquuOvh3PCNINteeF8WpSwluj/Va/kJygrY23iUTumLvGpW LkCZwDUE75w5Iw+zFapoTf9HK0PEpErsEjOjKddhHBY2XE17o9OkO9wwYMR1zg0P5OR8 L3AgN/7DZlECcubuwRgenksabfVZmfdGElm3Ocsud5tulkOd3cdE5v3oHhHQ1q2A1zuO HzDfz90LY8gA1YCGrt2DqbNNgWpUrAa/oND25pbR5l1g+1Ey7vHbbiJX6Y4Qy/UE4lZq xGVw== X-Forwarded-Encrypted: i=1; AJvYcCUOO2PWNyIOxg0JpS91tnEaSIOaYxQvAN2yWmmo0IbvVFKNgJdOdQKPXnglPzrJpp0GdKST5yBxBKr2iAFx6SfMrfuifGkAxVDdQC0P X-Gm-Message-State: AOJu0Yzi4BOOSVrqqWwxC+pqvFr38M+XBIB/3cm6Eog0igIFY+Kldyza 1U0YYoSdcUrEqbS+6nthDHefnw/5kWgGMO1yJtFhx9zToZUAeU5NvI0gtqpN X-Received: by 2002:a17:902:900a:b0:1dc:cbaa:f5dd with SMTP id a10-20020a170902900a00b001dccbaaf5ddmr2759536plp.39.1711509842651; Tue, 26 Mar 2024 20:24:02 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id y1-20020a17090322c100b001e043df262dsm7729090plg.33.2024.03.26.20.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 20:24:02 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH 2/2] samples: rust: add in-place initialisation sample Date: Wed, 27 Mar 2024 00:23:37 -0300 Message-Id: <20240327032337.188938-3-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327032337.188938-1-wedsonaf@gmail.com> References: <20240327032337.188938-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wedson Almeida Filho This is a modified version of rust_minimal that is initialised in-place. Signed-off-by: Wedson Almeida Filho --- samples/rust/Kconfig | 11 ++++++++++ samples/rust/Makefile | 1 + samples/rust/rust_inplace.rs | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 samples/rust/rust_inplace.rs diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index b0f74a81c8f9..59f44a8b6958 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -20,6 +20,17 @@ config SAMPLE_RUST_MINIMAL If unsure, say N. +config SAMPLE_RUST_INPLACE + tristate "Minimal in-place" + help + This option builds the Rust minimal module with in-place + initialisation. + + To compile this as a module, choose M here: + the module will be called rust_inplace. + + If unsure, say N. + config SAMPLE_RUST_PRINT tristate "Printing macros" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 03086dabbea4..791fc18180e9 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o +obj-$(CONFIG_SAMPLE_RUST_INPLACE) += rust_inplace.o obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs diff --git a/samples/rust/rust_inplace.rs b/samples/rust/rust_inplace.rs new file mode 100644 index 000000000000..ba8d051cac56 --- /dev/null +++ b/samples/rust/rust_inplace.rs @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust minimal in-place sample. + +use kernel::prelude::*; + +module! { + type: RustInPlace, + name: "rust_inplace", + author: "Rust for Linux Contributors", + description: "Rust minimal in-place sample", + license: "GPL", +} + +#[pin_data(PinnedDrop)] +struct RustInPlace { + numbers: Vec, +} + +impl kernel::InPlaceModule for RustInPlace { + fn init(_module: &'static ThisModule) -> impl PinInit { + pr_info!("Rust minimal sample (init)\n"); + pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); + try_pin_init!(Self { + numbers: { + let mut numbers = Vec::new(); + numbers.push(72, GFP_KERNEL)?; + numbers.push(108, GFP_KERNEL)?; + numbers.push(200, GFP_KERNEL)?; + numbers + }, + }) + } +} + +#[pinned_drop] +impl PinnedDrop for RustInPlace { + fn drop(self: Pin<&mut Self>) { + pr_info!("My numbers are {:?}\n", self.numbers); + pr_info!("Rust minimal inplace sample (exit)\n"); + } +} -- 2.34.1