From patchwork Fri Oct 18 14:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08236D30011 for ; Fri, 18 Oct 2024 14:44:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCH-0008Cl-Tt; Fri, 18 Oct 2024 10:43:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCE-0008By-8e for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCC-0002aU-RZ for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzN3eaQprVpp54M3KGLNllwys/lfpHPukyEKJkQaBx8=; b=BGQ2llHOl26IlSiNpVMUCGStO+jg911aqzDV4bn78LcgRjb94FFk3zIdZT4wG49xOZVdAg 4K66iC6Ve0NCrGp6Mw6ujispKqDcoYbAZkV3ANhk7c8XkJ6M42Z8VW0guTgtZ2HoMhFJiS U06Y0Yo3c+OsL1gYLHoNcjcAegsvN6k= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-J1TnjE_7Nqmaw8fHiE1twg-1; Fri, 18 Oct 2024 10:43:15 -0400 X-MC-Unique: J1TnjE_7Nqmaw8fHiE1twg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d4d51b4efso1048993f8f.3 for ; Fri, 18 Oct 2024 07:43:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262593; x=1729867393; 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=OzN3eaQprVpp54M3KGLNllwys/lfpHPukyEKJkQaBx8=; b=ADNct4qOoFchLuM4BBvQGmEn71Ewl0MdEoa1aGNt2faEv2Y1XBWqdoHzVU2cnVBP7o 5MYgLfLpB0cXGbgO5YWjmXQIWrR9+LwwqZLQRjl0T/TVqK2l9xLXuNTX0b7kt7E9qLZK 8oKRPuvadZ31vdkrFjy8SK7cVFG5XajCGdJr7/pKwS0vLKJHB+/7BOvEIMlluDMMuXAy YT6e3Q7tP3PG8qk4KjjBbDDQjTbfrzKeLQsX4t6cSecYM37gKCJmij2aANaPqy/1sjIK ZqEVkMKwsFahCr8NFrzSqcwpnrwrZO4rJXW6xvhcCSMqnXpCofOCPSWNfDxRS/XARSo5 /4Yg== X-Gm-Message-State: AOJu0YzroF+RPeayLg04vyR1Yf6jGiVzG7aENuWYyCo4STKJO0BfSJkY ThgFag4sUDV4Q4/HwVvvlH4zh/n2VMAhvTZCnwheh0E4samZ+TK+Jxou+zEpJclNrk+/NUVz/yn rCuhW/96CrnkpfKXaiKB4aE03WY538635+7EgHQ52JcTlxYXXpR4X38zjHpEsl4HkX9ZXRahuPx mcJFGLOSLPbMGHFLSdGouaDeB8EIUl9QpPRCjjQeE= X-Received: by 2002:a5d:4581:0:b0:37d:492c:4f54 with SMTP id ffacd0b85a97d-37ea21de09fmr1880695f8f.3.1729262592683; Fri, 18 Oct 2024 07:43:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQRzme0GwT0Pno2T65dD4dsZfkWgwu+d7+hO5ptwthRcIWEkT2p4FCDwDmj5hQMm+CY5FCLQ== X-Received: by 2002:a5d:4581:0:b0:37d:492c:4f54 with SMTP id ffacd0b85a97d-37ea21de09fmr1880673f8f.3.1729262592173; Fri, 18 Oct 2024 07:43:12 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf027b94sm2133165f8f.2.2024.10.18.07.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 01/13] meson: import rust module into a global variable Date: Fri, 18 Oct 2024 16:42:53 +0200 Message-ID: <20241018144306.954716-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- meson.build | 1 + rust/qemu-api-macros/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d26690ce204..ffd78b6cbb3 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ meson.add_postconf_script(find_program('scripts/symlink-install-tree.py')) not_found = dependency('', required: false) keyval = import('keyval') +rust = import('rust') ss = import('sourceset') fs = import('fs') diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.build index 517b9a4d2d5..24325dea5c2 100644 --- a/rust/qemu-api-macros/meson.build +++ b/rust/qemu-api-macros/meson.build @@ -2,7 +2,7 @@ quote_dep = dependency('quote-1-rs', native: true) syn_dep = dependency('syn-2-rs', native: true) proc_macro2_dep = dependency('proc-macro2-1-rs', native: true) -_qemu_api_macros_rs = import('rust').proc_macro( +_qemu_api_macros_rs = rust.proc_macro( 'qemu_api_macros', files('src/lib.rs'), override_options: ['rust_std=2021', 'build.rust_std=2021'], From patchwork Fri Oct 18 14:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B806FD30011 for ; Fri, 18 Oct 2024 14:44:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCI-0008D4-Hx; Fri, 18 Oct 2024 10:43:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCG-0008CP-P0 for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCF-0002ap-Al for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Xom1H6H23cG8iLdLE19Xrgp9EKPUggp4mB/uXhjCxk=; b=CW2PofvbbDv19zvnM9QZFb1tSPD/o4jylCkvHEqxO/zS8VotCzwUlAqBTNC88K9NX2nBHL RqEEwSe7TFsw0eA/8MPp60+ixk7RFPFWbEb2iDqXALmK8V8xYjeI7jy3bHJh2gxIA2hoBR VlQboi24N/02zSD5YCVqauQZOQNERH0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-F-XR9L1CPO2eOFqusBTH5w-1; Fri, 18 Oct 2024 10:43:17 -0400 X-MC-Unique: F-XR9L1CPO2eOFqusBTH5w-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d49887a2cso1309871f8f.0 for ; Fri, 18 Oct 2024 07:43:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262596; x=1729867396; 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=5Xom1H6H23cG8iLdLE19Xrgp9EKPUggp4mB/uXhjCxk=; b=B13nSvifqY1dxBDDXUUbTTb+nENIBcPgjzHNrkOMXB3XHKixAvbCgymGG9KzgpPCX8 q+sSfLWryfXmY3oEG2Mv2a+psASXuCTDVq4gEvlX/xtEDKKCxRDbeJW2vtx5DlYv3mCk 1mIws8JEBDN49TUTV9hve5oBi7EDuiwFjP64NF9VhheqIRmQeUobQmMl2tOqtnBvd3Ds EOZst3f9tYsNLzcfZmdLG+yRn12OvtulS+fkqys5cdYcGlK4foLzGuEoRzJ9sxQq92an OcsOEVP+1A/a2aVJMYNBL8zqP/H2hv37kiIlZI4wU6Hr78Mv5T+Q20ybxGW0/FX/YElg fsSw== X-Gm-Message-State: AOJu0Ywmq84F2+cBwqREwFRia4OBp3iy7mHw2z+pS5MnOuChPUTa4p+h Iw5rQJLO7NHHqcmaO8ClUBJjJzb54SblqCXhUo2BQztusfOpkp6FABBh6+VteDfg2eY6AjSgt7G iyqY4rCg8mYwENdajG6Mu0bFxE0kBK9OKnwTMhr4VtvotBUZAsoun55wdkx4Yr21MXpLhGGCeJL 6D/juMJZLUytZa7DUz4F0FPGTZ8i8je3Zml4UvuyY= X-Received: by 2002:a05:6000:e83:b0:374:cee6:c298 with SMTP id ffacd0b85a97d-37d93e2492bmr4913953f8f.21.1729262595657; Fri, 18 Oct 2024 07:43:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiNvFYNTzSJFI2vzWwu5T2zeEXAoX5XqUlpsHH7HUk4zF9Tnq3Jlf66qMF5bC/jbxDxDFVtg== X-Received: by 2002:a05:6000:e83:b0:374:cee6:c298 with SMTP id ffacd0b85a97d-37d93e2492bmr4913928f8f.21.1729262595159; Fri, 18 Oct 2024 07:43:15 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf06d3casm2104298f8f.48.2024.10.18.07.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 02/13] meson: remove repeated search for rust_root_crate.sh Date: Fri, 18 Oct 2024 16:42:54 +0200 Message-ID: <20241018144306.954716-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Avoid repeated lines of the form Program scripts/rust/rust_root_crate.sh found: YES (/home/pbonzini/work/upstream/qemu/scripts/rust/rust_root_crate.sh) in the meson logs. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index ffd78b6cbb3..f85bc22fbdd 100644 --- a/meson.build +++ b/meson.build @@ -3977,6 +3977,7 @@ endif feature_to_c = find_program('scripts/feature_to_c.py') +rust_root_crate = find_program('scripts/rust/rust_root_crate.sh') if host_os == 'darwin' entitlement = find_program('scripts/entitlement.sh') @@ -4078,7 +4079,7 @@ foreach target : target_dirs if crates.length() > 0 rlib_rs = custom_target('rust_' + target.underscorify() + '.rs', output: 'rust_' + target.underscorify() + '.rs', - command: [find_program('scripts/rust/rust_root_crate.sh')] + crates, + command: [rust_root_crate, crates], capture: true, build_by_default: true, build_always_stale: true) From patchwork Fri Oct 18 14:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED048D30011 for ; Fri, 18 Oct 2024 14:44:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCM-0008Df-1e; Fri, 18 Oct 2024 10:43:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCK-0008DE-0I for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCI-0002b3-Cc for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jd0gmtcBQzLINXkp+X79ep9Gkfj1tGWs8hU6aYifJxw=; b=UsrJJMY91BkRYNXsvSpW7nS4Bm1UI1kOhTarILnYch9aGpYccbQDC1D1JHp8CgjyophBnV KemZKY7WEMwHiaUqETkABijSh+SIVww2lOorHtjKhnsUL7SZcgJC446KHeF64Q3Gg7NZSO EMZqe/yV4yLGQ36ZP39YMtt7yF3RrxA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-AUkuFRABOoKB4c2dYzv9-A-1; Fri, 18 Oct 2024 10:43:20 -0400 X-MC-Unique: AUkuFRABOoKB4c2dYzv9-A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315af466d9so12917725e9.3 for ; Fri, 18 Oct 2024 07:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262599; x=1729867399; 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=Jd0gmtcBQzLINXkp+X79ep9Gkfj1tGWs8hU6aYifJxw=; b=JGxEuMiHvWIajTp+WeFwsnBxtQgMr1gAOfMOHWHGf6EJrinQRbpZorxjDjFgHmxhrx /43L52honhRoPtGx3tjh9TcJUP4VdGvdutF4cdka7vHQNmb7yIs2Vf/W3bXODUExTWV9 /tw7+fmh4bnproXNbKPiyctwis+5oTwrIQBYrtCCzEM2mUZjvJ2eP2bFNmvMfXQbflop NqcqhrdJjB3mKACZuiAr4kmDWPumE5YjopPN8PXqvk4I301Z0oVsEa3GMVGxbIQdzBDo jBpbfx4SFSSPgmDgmB067FH7Jv1oUEtensVZj52BOvAfTY81dYOqVhnW5LDEpDo+kRyV hWnw== X-Gm-Message-State: AOJu0YygJhck0i+GdB8yOIlg3eY59EbeoVil0tt0PHv4lPbWe9dAPGA+ UbtHtg4nah2XVm+4fRs1e8pl2eybfbjEi8ktNgoI3NV4UHcoRpMkPsVJXj0fsaOWCdNXOty7VZo KcimlNKTTypIA2TKKuwBSOlV1yqmGBzm2/pSMLAB6JN3+DoTbWnZ0izjYDAp4KS3uSKNM6b09sX YkWAzbqXbjyHMrRcVjAgvuKY8Hk3aZzztTiJAwPjk= X-Received: by 2002:a05:600c:354e:b0:42b:a7c7:5667 with SMTP id 5b1f17b1804b1-431616a3a15mr20835685e9.25.1729262598556; Fri, 18 Oct 2024 07:43:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBlwSkyu6zYc2SdwTjWIXH0OuA20A1PK/mET2YotKr6f9GSxkvXqsT905efB/NKciY/uQCoA== X-Received: by 2002:a05:600c:354e:b0:42b:a7c7:5667 with SMTP id 5b1f17b1804b1-431616a3a15mr20835435e9.25.1729262598034; Fri, 18 Oct 2024 07:43:18 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160e0a887sm25991095e9.23.2024.10.18.07.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 03/13] meson: pass rustc_args when building all crates Date: Fri, 18 Oct 2024 16:42:55 +0200 Message-ID: <20241018144306.954716-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org rustc_args is needed to smooth the difference in warnings between the various versions of rustc. Always include those arguments. Signed-off-by: Paolo Bonzini --- meson.build | 18 +++++++++++------- rust/qemu-api/meson.build | 2 +- rust/qemu-api/src/device_class.rs | 10 ++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index f85bc22fbdd..44f3bf34931 100644 --- a/meson.build +++ b/meson.build @@ -3317,6 +3317,17 @@ endif genh += configure_file(output: 'config-host.h', configuration: config_host_data) +if have_rust and have_system + rustc_args = run_command( + find_program('scripts/rust/rustc_args.py'), + '--config-headers', meson.project_build_root() / 'config-host.h', + capture : true, + check: true).stdout().strip().split() + rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] + add_project_arguments(rustc_args, native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') +endif + hxtool = find_program('scripts/hxtool') shaderinclude = find_program('scripts/shaderinclude.py') qapi_gen = find_program('scripts/qapi-gen.py') @@ -3909,12 +3920,6 @@ common_all = static_library('common', dependencies: common_ss.all_dependencies()) if have_rust and have_system - rustc_args = run_command( - find_program('scripts/rust/rustc_args.py'), - '--config-headers', meson.project_build_root() / 'config-host.h', - capture : true, - check: true).stdout().strip().split() - rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] bindgen_args = [ '--disable-header-comment', '--raw-line', '// @generated', @@ -4087,7 +4092,6 @@ foreach target : target_dirs rlib_rs, dependencies: target_rust.dependencies(), override_options: ['rust_std=2021', 'build.rust_std=2021'], - rust_args: rustc_args, rust_abi: 'c') arch_deps += declare_dependency(link_whole: [rlib]) endif diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index c72d34b607d..42ea815fa5a 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -10,7 +10,7 @@ _qemu_api_rs = static_library( ), override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', - rust_args: rustc_args + [ + rust_args: [ '--cfg', 'MESON', # '--cfg', 'feature="allocator"', ], diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 1ea95beb78d..b6b68cf9ce2 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -16,10 +16,12 @@ macro_rules! device_class_init { ) { let mut dc = ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::DeviceClass>()).unwrap(); - dc.as_mut().realize = $realize_fn; - dc.as_mut().vmsd = &$vmsd; - $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + unsafe { + dc.as_mut().realize = $realize_fn; + dc.as_mut().vmsd = &$vmsd; + $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); + $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + } } }; } From patchwork Fri Oct 18 14:42:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDC4FD30016 for ; Fri, 18 Oct 2024 14:45:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCO-0008EK-08; Fri, 18 Oct 2024 10:43:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCM-0008Dg-QD for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCL-0002bH-F0 for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YnWs6TCqS8/kK1EZwGdItbHdFaXUR6Q2fvMJR0lbNSc=; b=UVv9V4CfxhZ2djLR7+D1Tz5Tsmi6VxKxWeYt7eGKKqp96k5WSrWncVQyKoIartXKd7Q3wn 19/qjRhjKOnFPqg088KFwO0TeAgnaxYBYzMrTZZAIde8lIf8G+vUXISOm+MTWx4LQmtx5w QDrCFMJXMf6xzT3sN2mQ4CUS1CQdeIs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-mDp0fhS6PvK_f76_ViecYw-1; Fri, 18 Oct 2024 10:43:23 -0400 X-MC-Unique: mDp0fhS6PvK_f76_ViecYw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-431518ae047so16264075e9.0 for ; Fri, 18 Oct 2024 07:43:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262601; x=1729867401; 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=YnWs6TCqS8/kK1EZwGdItbHdFaXUR6Q2fvMJR0lbNSc=; b=OT5DpkH5VEHXVaqJ+E81RwqlOKfmmKZmmGYm54SRXzmH70NUQ3lzhXziomfCk8oBaK 1heIHTv12cjgrcoNJuJUuqyiH1BkwencWBbC1W5WAL1l5uoIKz5NPnzUkJpLaS0OPFkm Sv3aP9cuY0nkTrvgLZ9YghRN6EnZ6X8xg1L3rIPFtSeVSS4PNhb6g/cBc4yDK/4V5Wop 9SndxV5S5XR46F9qARZzxkYmGqfoilYfis3uqq9lwiZS8vhz2gu0G+mKK7ia1Ll3dmCi 1nazOTvsTRlF+hmGbQo5kkcWSOZAgVQQAr6aDL4/5mlO9qpS9N44mYflpjseA5pWnRoJ dY6Q== X-Gm-Message-State: AOJu0Yy0qECRew13GhgfCpns6y3mDvxzUeBPAV6Qx/asL4vN++atgumz 6jvT3Q+SxhE2s9KSTQqs6Mn07qlP2ROqHFsKbHmbZwokQsSC9onB70tJIgzT1iLwFcFmtdZ+Jom r2Ft9hNqi9B8jO1VL4GJeu9P1pzviDwKb8VVetRxF7BNxhVdNIA0lqPHpqp/ne7M+I/DTPRS0yx RExwswe5yZw2N/ZHh4FUB58sjbzz41/ttXL0AMdfg= X-Received: by 2002:a05:600c:4fd2:b0:431:15f1:421d with SMTP id 5b1f17b1804b1-43158760531mr48904955e9.16.1729262601451; Fri, 18 Oct 2024 07:43:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlJfRDHgpGcAwHn5SwM3qN01kA1iAScDSzLvZG2bCO5VvRaQSsnb/rAzMOkv976pB31/NZrw== X-Received: by 2002:a05:600c:4fd2:b0:431:15f1:421d with SMTP id 5b1f17b1804b1-43158760531mr48904665e9.16.1729262600903; Fri, 18 Oct 2024 07:43:20 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160e4424asm25788395e9.32.2024.10.18.07.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 04/13] rust: do not use --no-size_t-is-usize Date: Fri, 18 Oct 2024 16:42:56 +0200 Message-ID: <20241018144306.954716-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This not necessary and makes it harder to write code that is portable between 32- and 64-bit systems: it adds extra casts even though size_of, align_of or offset_of already return the right type. Signed-off-by: Paolo Bonzini --- meson.build | 1 - rust/qemu-api/src/definitions.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 44f3bf34931..48f82fd4ba6 100644 --- a/meson.build +++ b/meson.build @@ -3932,7 +3932,6 @@ if have_rust and have_system '--no-doc-comments', '--use-core', '--with-derive-default', - '--no-size_t-is-usize', '--no-layout-tests', '--no-prepend-enum-name', '--allowlist-file', meson.project_source_root() + '/include/.*', diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 60bd3f8aaa6..0b681c593f2 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -81,13 +81,13 @@ macro_rules! type_info { } else { ::core::ptr::null_mut() }, - instance_size: ::core::mem::size_of::<$t>() as $crate::bindings::size_t, - instance_align: ::core::mem::align_of::<$t>() as $crate::bindings::size_t, + instance_size: ::core::mem::size_of::<$t>(), + instance_align: ::core::mem::align_of::<$t>(), instance_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_INIT, instance_post_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_POST_INIT, instance_finalize: <$t as $crate::definitions::ObjectImpl>::INSTANCE_FINALIZE, abstract_: <$t as $crate::definitions::ObjectImpl>::ABSTRACT, - class_size: ::core::mem::size_of::<<$t as $crate::definitions::ObjectImpl>::Class>() as $crate::bindings::size_t, + class_size: ::core::mem::size_of::<<$t as $crate::definitions::ObjectImpl>::Class>(), class_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::Class>::CLASS_INIT, class_base_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::Class>::CLASS_BASE_INIT, class_data: ::core::ptr::null_mut(), From patchwork Fri Oct 18 14:42:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A11BDD30011 for ; Fri, 18 Oct 2024 14:44:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCS-0008Ex-Jl; Fri, 18 Oct 2024 10:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCR-0008Ep-4d for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCP-0002bT-3x for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WDMAh1URWn4hp3LDQ7fEvPpcwUuvxbAfyftmYDYSiMc=; b=D5tkVH3/vBSi7v76mciUD0E/7wrzGJt92Rde/5xwOfUUp0yqJfb8C/pfLEGKYNw6zbvswG DM40j0BF5FSIkBHnA24/g0xAz9X9jVLbdI61Rx5A52f0C0AqjKvDcnF4xPHPIp0dhP0CAU 23S5g6k6rXJ4Br11Bbq/ncrLQHA2feo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-2uyLSTu9OHyFDlzxhhvN9w-1; Fri, 18 Oct 2024 10:43:26 -0400 X-MC-Unique: 2uyLSTu9OHyFDlzxhhvN9w-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43151e4ef43so15662145e9.3 for ; Fri, 18 Oct 2024 07:43:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262605; x=1729867405; 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=WDMAh1URWn4hp3LDQ7fEvPpcwUuvxbAfyftmYDYSiMc=; b=fYcfOf2u8gjvSTqNSwRWcZykFR9GIeDsJY4CO/vd0B95zGvawBxlNQnPw/6x1gAHa1 kSI8/3d/xcJiy+q4ZrF2lKiYiDxAoTNXMQDWYzeBQhZ7Bapdd0p7UhCRE/IqDekULhCI sLONq5ioUT7BLUsyOBh3dIfEy7NZuHpp4Uhvvk+gL+NmJsfEU3blte+ypN11StDBaw6W tgZZcOaPUAQxhZnevckgMjwcRXAasUofEcKAit1eEmn9Xd4FDu7krcy4Sn+aOCDgz99s OyOsP2Xys6l3UWGT6vx+P4ri61+3r/89QD+GHhRg8NfSXKepw26R+OUULuQMPY+jERe1 fTSg== X-Gm-Message-State: AOJu0YzptlA/savxUoFBoQl8e5edyCov++Er80JLhfvUKUzMRwsrFHLP f1It8luhSgkGjyrSNzmn1ZFLTRsr6ItVdYbfPhl2S1td7k9f0I3ahI5Jz9GaF/+ogZPhwz6qZvB bY8VQ5VtvkDT+tk+oB8bPMUY8l4LA4Vwnsa2g7qSTIs3BWIk3caNivueGXbxVXPcO/tN3xuB905 hEwqvKfqplyZf2+IU3t60mWvVJQRQEDtV0GCyK9Js= X-Received: by 2002:a05:600c:3b9b:b0:42c:b037:5f9d with SMTP id 5b1f17b1804b1-43161636f67mr21257745e9.3.1729262604562; Fri, 18 Oct 2024 07:43:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgFOSJSlu0kfDBE4750eBymTbwtcY3y4QPANHcUJmBCnVByjmrBD8GQoTgQMmm+G1JonIaqA== X-Received: by 2002:a05:600c:3b9b:b0:42c:b037:5f9d with SMTP id 5b1f17b1804b1-43161636f67mr21257455e9.3.1729262603953; Fri, 18 Oct 2024 07:43:23 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf027e49sm2162410f8f.3.2024.10.18.07.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 05/13] rust: remove uses of #[no_mangle] Date: Fri, 18 Oct 2024 16:42:57 +0200 Message-ID: <20241018144306.954716-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Mangled symbols do not cause any issue; disabling mangling is only useful if C headers reference the Rust function, which is not the case here. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/hw/char/pl011/src/device.rs | 5 ----- rust/hw/char/pl011/src/device_class.rs | 2 -- rust/hw/char/pl011/src/memory_ops.rs | 2 -- rust/qemu-api/src/definitions.rs | 1 - rust/qemu-api/src/device_class.rs | 2 -- 5 files changed, 12 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c7193b41bee..2b43f5e0939 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -514,7 +514,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { unsafe { debug_assert!(!opaque.is_null()); @@ -530,7 +529,6 @@ pub fn update(&self) { /// readable/writeable from one thread at any time. /// /// The buffer and size arguments must also be valid. -#[no_mangle] pub unsafe extern "C" fn pl011_receive( opaque: *mut core::ffi::c_void, buf: *const u8, @@ -554,7 +552,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) { unsafe { debug_assert!(!opaque.is_null()); @@ -566,7 +563,6 @@ pub fn update(&self) { /// # Safety /// /// We expect the FFI user of this function to pass a valid pointer for `chr`. -#[no_mangle] pub unsafe extern "C" fn pl011_create( addr: u64, irq: qemu_irq, @@ -589,7 +585,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_init(obj: *mut Object) { unsafe { debug_assert!(!obj.is_null()); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index b7ab31af02d..2ad80451e87 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -46,7 +46,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut *mut Error) { unsafe { assert!(!dev.is_null()); @@ -60,7 +59,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { unsafe { assert!(!dev.is_null()); diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 8d066ebf6d0..5a5320e66c3 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -22,7 +22,6 @@ }, }; -#[no_mangle] unsafe extern "C" fn pl011_read( opaque: *mut core::ffi::c_void, addr: hwaddr, @@ -44,7 +43,6 @@ } } -#[no_mangle] unsafe extern "C" fn pl011_write( opaque: *mut core::ffi::c_void, addr: hwaddr, diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 0b681c593f2..49ac59af123 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -53,7 +53,6 @@ extern "C" fn __load() { #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() = { extern "C" fn __load() { - #[no_mangle] unsafe extern "C" fn $func() { $body } diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index b6b68cf9ce2..2219b9f73d0 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -9,7 +9,6 @@ #[macro_export] macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { - #[no_mangle] pub unsafe extern "C" fn $func( klass: *mut $crate::bindings::ObjectClass, _: *mut ::core::ffi::c_void, @@ -103,7 +102,6 @@ const fn _calc_prop_len() -> usize { ] } - #[no_mangle] pub static mut $ident: $crate::device_class::Properties = $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_properties); }; } From patchwork Fri Oct 18 14:42:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64D8BD30011 for ; Fri, 18 Oct 2024 14:46:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCT-0008FV-HX; Fri, 18 Oct 2024 10:43:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCS-0008FI-SH for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCR-0002bf-7X for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9v8sd7Ub7nOvHg864QFQKFIxnhnYovhgbjN7vbVz0Rw=; b=ZiIuq1irw6etBjw9kFjw425RauLJZMHcvGjWn+FcNje2hvVTKbwPQEB7+J7xqM9BC2Bn1v sEn+sfPlGpCZBRNL1ZyeK9VgT+duWtyK+zsvJHbKAWZNPlmBUltvw9kP0lYhTLxFtQjOXN eQmI9un7LlNmwQza25Kv4WH+WaeOWCU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-AaCNfGBePx6LJpZAiuW5JA-1; Fri, 18 Oct 2024 10:43:29 -0400 X-MC-Unique: AaCNfGBePx6LJpZAiuW5JA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315b7b0c16so13556545e9.1 for ; Fri, 18 Oct 2024 07:43:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262607; x=1729867407; 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=9v8sd7Ub7nOvHg864QFQKFIxnhnYovhgbjN7vbVz0Rw=; b=S1xiONTkmRhJ4XL3iIaPWZp/LOpE7bPBdIXwx+nanQ2HFFLJ85DUyjSgGsPYr5z36C ritKmIQ09PH+THV3ngEgcMqJ30GLeXoClF/5xKJFt8eCdHWRFQPwihGjEU/pVZKnbfeC 8BVccnii2KOAGo2ZzLf7l34TFr5Ghv4VhDYru4N0ZN0YMI7lhir/IGaPoguv2+1eeIaK Uz/7NnQNX1AMchCjYC+dbwh/BlgXpfjoc/psCZOH7dmg260bj3zGfR9ucE+XWfL+5WIO j5QyIPoz9bnZa0uj+bP+lsb19uWzeVmnWcRh0JM6K2INld65lEBWRQwVd3GmQ6xJ0+Zo +obQ== X-Gm-Message-State: AOJu0YzXMX9cEZAaMB8p4t5xx8MKGVKRK5DipNMtc/OJVELVDhkWpiK3 lFlGO+i0V2R5MQ3Q14ooRRng70Yo+rzyocta8555433z4sIJEROzrdHBwVflh7R4+CDWn25HhSZ NL7R9+wBJrFl81Nohxb5hRshFiQRKjwNHCKvnzB/aVdt2qTo2ukivkBnnVofG+sMNHoXKVv0Mw7 WxP9Lsuki3CjLIezcPaZFl4C0oAuu4D5j54Vt4eMk= X-Received: by 2002:adf:fd0a:0:b0:37d:398f:44f9 with SMTP id ffacd0b85a97d-37eab70f77amr1699550f8f.32.1729262607341; Fri, 18 Oct 2024 07:43:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmsK1ZtNUDZD6+1/uyzepMga6cblRrFvNPDyjj7DVWRl3MAM1pPE31ixHScSep2apNPCRBew== X-Received: by 2002:adf:fd0a:0:b0:37d:398f:44f9 with SMTP id ffacd0b85a97d-37eab70f77amr1699529f8f.32.1729262606868; Fri, 18 Oct 2024 07:43:26 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160e0a87csm25800275e9.25.2024.10.18.07.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 06/13] rust: remove unused macro module_init! Date: Fri, 18 Oct 2024 16:42:58 +0200 Message-ID: <20241018144306.954716-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Registering the object is now done by the #[derive(Object)] macro. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/definitions.rs | 43 -------------------------------- 1 file changed, 43 deletions(-) diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs index 49ac59af123..73ef9a52c1b 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -27,49 +27,6 @@ pub trait Class { >; } -#[macro_export] -macro_rules! module_init { - ($func:expr, $type:expr) => { - #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] - #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() = { - extern "C" fn __load() { - unsafe { - $crate::bindings::register_module_init(Some($func), $type); - } - } - - __load - }; - }; - (qom: $func:ident => $body:block) => { - // NOTE: To have custom identifiers for the ctor func we need to either supply - // them directly as a macro argument or create them with a proc macro. - #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] - #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() = { - extern "C" fn __load() { - unsafe extern "C" fn $func() { - $body - } - - unsafe { - $crate::bindings::register_module_init( - Some($func), - $crate::bindings::module_init_type::MODULE_INIT_QOM, - ); - } - } - - __load - }; - }; -} - #[macro_export] macro_rules! type_info { ($t:ty) => { From patchwork Fri Oct 18 14:42:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45767D30016 for ; Fri, 18 Oct 2024 14:44:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCX-0008GA-41; Fri, 18 Oct 2024 10:43:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCU-0008Fm-Re for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCT-0002bu-Eb for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N3ZGFZCOt9HiQmv1wD8oI7UdgNkjvngz4i7GVqBANIg=; b=AOuQPjrsNhoDoNSNEPcFJef6DC10tU8Wt/yoil9szOaA8z2QbSDPkLh3+9EoSY8T4gpQLV y4UjVUPnMs1igeUfuhFYBhgLlHdsNe7t6pR/1kM0DTORB4kF+DwmLG/mauiQSVuxHRoVNU e9/jJWefcV4SWpfZxILcYJ1BamsMv1w= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-AMYfJVEXPlSWQxN61EDy1w-1; Fri, 18 Oct 2024 10:43:31 -0400 X-MC-Unique: AMYfJVEXPlSWQxN61EDy1w-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d5606250aso917623f8f.2 for ; Fri, 18 Oct 2024 07:43:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262610; x=1729867410; 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=N3ZGFZCOt9HiQmv1wD8oI7UdgNkjvngz4i7GVqBANIg=; b=WurmeD0CnFEu6XigJrrfGFvPZHRfdZSiA8Pj8/7bNHh0tbm78/ICEDtR/4heBQ4QUN heo3r5Wd0gERFek8q8phj2xW+ePd3tg0WsAIha35q9JDUfJKk/8WcEgZredJTAKVWxtO CwFS3eAQ/8e8Q5f5vgicsyzdaIeSnZz6riGD0uq6KYYOv/ZOx9YfGDS3Fqbr2xf0oppq MUa3eoP4rQ7EqMSfiqvU6XgRPf1/PYW4+IkFdt0kQcCKR//ii/wPicQYMawFaY5wcP9V YdOeibP6TXU74GM6j6ARSzGr9vXOfcxiVJsLtWmCyfcCaE9da73tRP7nvhudvienREK9 1mdw== X-Gm-Message-State: AOJu0YziqKm5DD+5BNYq3CbtdULqpqOVBADyloSaDPzFU4yXtlPtmQO0 F+80j45ubRH718HxD/FNvh4YSRkvfzIvyYIWom9pziDjyWF+Zn6v3PTWmDk4/9Tr84X3oOs19TC I3jJijm0Po+lhJiLHb+mZnesQFAeC8P97lyOxT6m0x29U3gEOs7llx8/n/1qoncj+KfDF6yUq6b UdGHLqHfThK0J4WnmnDGnPfYtMaFWURYPvQjtbq7E= X-Received: by 2002:a5d:6584:0:b0:374:c8a0:5d05 with SMTP id ffacd0b85a97d-37eb48a0e89mr1998099f8f.50.1729262609969; Fri, 18 Oct 2024 07:43:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGagS9xiAKzTdiLATFMcGlrIZguRVzRWLmQLtwxnyytzlSVFTD30748AR31pdmE4FdmUCEm6g== X-Received: by 2002:a5d:6584:0:b0:374:c8a0:5d05 with SMTP id ffacd0b85a97d-37eb48a0e89mr1998077f8f.50.1729262609558; Fri, 18 Oct 2024 07:43:29 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf11a5e2sm2084249f8f.105.2024.10.18.07.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 07/13] rust: modernize #[derive(Object)] for ELF platforms Date: Fri, 18 Oct 2024 16:42:59 +0200 Message-ID: <20241018144306.954716-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Some newer ABI implementations do not provide .ctors; and while some linkers rewrite .ctors into .init_array, not all of them do. Use the newer .init_array ABI, which works more reliably, and apply it to all non-Apple, non-Windows platforms. This is similar to how the ctor crate operates; without this change, "#[derive(Object)]" does not work on Fedora 41. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/qemu-api-macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib.rs index 59aba592d9a..be8874caea1 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -16,8 +16,8 @@ pub fn derive_object(input: TokenStream) -> TokenStream { let expanded = quote! { #[allow(non_upper_case_globals)] #[used] - #[cfg_attr(target_os = "linux", link_section = ".ctors")] - #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")] + #[cfg_attr(not(any(target_vendor = "apple", target_os = "windows")), link_section = ".init_array")] + #[cfg_attr(target_vendor = "apple", link_section = "__DATA,__mod_init_func")] #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")] pub static #module_static: extern "C" fn() = { extern "C" fn __register() { From patchwork Fri Oct 18 14:43:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5591D30011 for ; Fri, 18 Oct 2024 14:45:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCb-0008GS-8K; Fri, 18 Oct 2024 10:43:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCZ-0008GK-JM for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCX-0002c4-Ot for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F8wsQjPMVjjwkNzJ9IhojZy7e4Mf2LiRo455TrrTrnI=; b=idP0dWmRiogSCu2GREtgl00sT8CvGMCOEt9MZ2m8mhfN1sg3jrVGFu1z6FNBFawqSpgFWa znXLIIosm8IX+NfCtad8Qct4uXXmcP3M5ZLnqrOJo532u38OiVh0jWw2QFPZ3C3S+BMfaX epsHCR8qUBZnNbCqQI5+VSwZCJW3SJs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-0PXKJf3gP0uGlMVxKDj0iQ-1; Fri, 18 Oct 2024 10:43:35 -0400 X-MC-Unique: 0PXKJf3gP0uGlMVxKDj0iQ-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4314c6ca114so16201745e9.1 for ; Fri, 18 Oct 2024 07:43:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262613; x=1729867413; 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=F8wsQjPMVjjwkNzJ9IhojZy7e4Mf2LiRo455TrrTrnI=; b=L46sTPRgOU2L2uqA08rGa3qh6wE7JKNXThiK0+BOIlN7oIiM9P4N1c1dTprW76S7j+ NiUSRMAtZnYkCMYqMt3Mdv1zvkCc7j/7x7Ltm05fyg5W+Bk+qOlyQcCppI1CiT1LX3lM ehzjGSlcEF6Dway5hvSLvXKEFrLPGqkDzhgk7hjIMdw679pPTxtXHX0Pn1j2syK478gp bLdKJhkzNwhHeiS/wZ71/Ci1P95v7uZcvMucc/N6rPLXNhLDzSkIVRlfWRSZ68TVJKiF 9aeha0pGEomt7YjFgljx2gY8IrCOWVjfnokWRZiHA6WtEJkmU8qSGzNkPYzjZVGozfYJ Lb6A== X-Gm-Message-State: AOJu0YxHaHwamTzdtuzF6Qd9qaZs575v4MdWmD5MhfpxCrvgfdSAfIjf KOfzVT4Wf7SzSpyH2uSyR+2/QaALKVtVMSguxZDijk0i7jogqiRacsUR5C+pffyAOIsNya/9kiA Pt7/Jcpb7wcIovQkm2hbRhfuSvzSZIgPHKdFGz8aVidVCwaM2yF2tO8TRNZSO34eLf7sGSjCOue ePjnLSivtoW6aeqcEvl+kimH9i7nHF8x+hW2UqadE= X-Received: by 2002:a05:600c:5489:b0:431:52b7:a499 with SMTP id 5b1f17b1804b1-4316164da71mr21554675e9.20.1729262613507; Fri, 18 Oct 2024 07:43:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhMiAaB0ldr+lLd7iVP/vR/2nGp/Lzj18G8C6vG+kacqvRIvPQvUf7/m33/omq2CEfVBEFgQ== X-Received: by 2002:a05:600c:5489:b0:431:52b7:a499 with SMTP id 5b1f17b1804b1-4316164da71mr21554465e9.20.1729262613052; Fri, 18 Oct 2024 07:43:33 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf04a694sm2142439f8f.33.2024.10.18.07.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 08/13] rust: build integration test for the qemu_api crate Date: Fri, 18 Oct 2024 16:43:00 +0200 Message-ID: <20241018144306.954716-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Adjust the integration test to compile with a subset of QEMU object files, and make it actually create an object of the class it defines. Follow the Rust filesystem conventions, where tests go in tests/ if they use the library in the same way any other code would. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- meson.build | 10 ++++- rust/qemu-api/meson.build | 20 +++++++-- rust/qemu-api/src/tests.rs | 49 ---------------------- rust/qemu-api/tests/tests.rs | 78 ++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 53 deletions(-) delete mode 100644 rust/qemu-api/src/tests.rs create mode 100644 rust/qemu-api/tests/tests.rs diff --git a/meson.build b/meson.build index 48f82fd4ba6..e50a7edf6ea 100644 --- a/meson.build +++ b/meson.build @@ -3324,7 +3324,15 @@ if have_rust and have_system capture : true, check: true).stdout().strip().split() rustc_args += ['-D', 'unsafe_op_in_unsafe_fn'] - add_project_arguments(rustc_args, native: false, language: 'rust') + + # Apart from procedural macros, our Rust executables will often link + # with C code, so include all the libraries that C code needs. This + # is safe; https://github.com/rust-lang/rust/pull/54675 says that + # passing -nodefaultlibs to the linker "was more ideological to + # start with than anything". + add_project_arguments(rustc_args + ['-C', 'default-linker-libraries'], + native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') endif diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 42ea815fa5a..d24e0c0725e 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -14,11 +14,25 @@ _qemu_api_rs = static_library( '--cfg', 'MESON', # '--cfg', 'feature="allocator"', ], - dependencies: [ - qemu_api_macros, - ], ) qemu_api = declare_dependency( link_with: _qemu_api_rs, + dependencies: qemu_api_macros, ) + +# Rust executable do not support objects, so add an intermediate step. +rust_qemu_api_objs = static_library( + 'rust_qemu_api_objs', + objects: [libqom.extract_all_objects(recursive: false), + libhwcore.extract_all_objects(recursive: false)]) + +rust.test('rust-qemu-api-integration', + static_library( + 'rust_qemu_api_integration', + 'tests/tests.rs', + override_options: ['rust_std=2021', 'build.rust_std=2021'], + link_whole: [rust_qemu_api_objs, libqemuutil]), + + dependencies: [qemu_api, qemu_api_macros], + suite: ['unit', 'rust']) diff --git a/rust/qemu-api/src/tests.rs b/rust/qemu-api/src/tests.rs deleted file mode 100644 index df54edbd4e2..00000000000 --- a/rust/qemu-api/src/tests.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use crate::{ - bindings::*, declare_properties, define_property, device_class_init, vm_state_description, -}; - -#[test] -fn test_device_decl_macros() { - // Test that macros can compile. - vm_state_description! { - VMSTATE, - name: c"name", - unmigratable: true, - } - - #[repr(C)] - pub struct DummyState { - pub char_backend: CharBackend, - pub migrate_clock: bool, - } - - declare_properties! { - DUMMY_PROPERTIES, - define_property!( - c"chardev", - DummyState, - char_backend, - unsafe { &qdev_prop_chr }, - CharBackend - ), - define_property!( - c"migrate-clk", - DummyState, - migrate_clock, - unsafe { &qdev_prop_bool }, - bool - ), - } - - device_class_init! { - dummy_class_init, - props => DUMMY_PROPERTIES, - realize_fn => None, - reset_fn => None, - vmsd => VMSTATE, - } -} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs new file mode 100644 index 00000000000..57bab62772d --- /dev/null +++ b/rust/qemu-api/tests/tests.rs @@ -0,0 +1,78 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::ffi::CStr; + +use qemu_api::{ + bindings::*, declare_properties, define_property, + definitions::Class, + definitions::ObjectImpl, + device_class_init, vm_state_description, +}; + +#[test] +fn test_device_decl_macros() { + // Test that macros can compile. + vm_state_description! { + VMSTATE, + name: c"name", + unmigratable: true, + } + + #[repr(C)] + #[derive(qemu_api_macros::Object)] + pub struct DummyState { + pub _parent: DeviceState, + pub migrate_clock: bool, + } + + #[repr(C)] + pub struct DummyClass { + pub _parent: DeviceClass, + } + + declare_properties! { + DUMMY_PROPERTIES, + define_property!( + c"migrate-clk", + DummyState, + migrate_clock, + unsafe { &qdev_prop_bool }, + bool + ), + } + + device_class_init! { + dummy_class_init, + props => DUMMY_PROPERTIES, + realize_fn => None, + legacy_reset_fn => None, + vmsd => VMSTATE, + } + + impl ObjectImpl for DummyState { + type Class = DummyClass; + const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; + const TYPE_NAME: &'static CStr = c"dummy"; + const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_DEVICE); + const ABSTRACT: bool = false; + const INSTANCE_INIT: Option = None; + const INSTANCE_POST_INIT: Option = None; + const INSTANCE_FINALIZE: Option = None; + } + + impl Class for DummyClass { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + > = Some(dummy_class_init); + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), + > = None; + } + + unsafe { + module_call_init(module_init_type::MODULE_INIT_QOM); + object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); + } +} From patchwork Fri Oct 18 14:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2B56D30011 for ; Fri, 18 Oct 2024 14:45:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCd-0008Gw-3l; Fri, 18 Oct 2024 10:43:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCb-0008Gj-QU for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCa-0002cD-7K for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KJ9hL0B7RAY1pA3mAAYh7QRZKmrXfTFSuloe8GbmWow=; b=cKh9UQsy74Xui9Qn2/rmuh5iTTnzGEhrlJzBLtp1r432QoGYrvV049KupeyVoJTfrI3GOW PaHzjhzXhv9QCujrq15SCRzC37iFXD2iniSu1VqaF9G4vjZ1ePB3heHqWzuxjqehonk9KG JzXqcL2zoukh/Lk1poDeYUGJnNUcB7A= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-235-M2HA-QtJNjSSiC7yB5LdIw-1; Fri, 18 Oct 2024 10:43:38 -0400 X-MC-Unique: M2HA-QtJNjSSiC7yB5LdIw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315c1b5befso13542805e9.1 for ; Fri, 18 Oct 2024 07:43:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262617; x=1729867417; 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=KJ9hL0B7RAY1pA3mAAYh7QRZKmrXfTFSuloe8GbmWow=; b=R7BdJlSYG+FqMZhuefAxsWA+JBilwbs7DZAQREOdkxx0uIelCKpXUmIZYOR3xVFOEd X2Kw7haHtHTpsMwuMNlH+iLIsmxZ7JWQlUrbL3rrr+8m4jJxcF6PiH0WtWBISY8Pq3rM SWfXCLfuk6iQc16EbrjFInh5McBJKmdH2o6U29icjbokCc0Ue7G/Hd66mukoPcgQ7046 KdAE8eoVKspE+RhEK5yZ8iGtfNd8VuD+6wbqmz+4rWYE5NinRkEX/1l1q8fI3wNtzJJR Z8ZI+9gkCJ+xtYSWASpJG8gZ4kIHxUKirTggu6ot+hs1NuoOtB7AORV/WAUZ9KMSbLMW mOHQ== X-Gm-Message-State: AOJu0Yx00UX4xF06fIar23LjXmdiAfgfDUjNA3AjD4VBJGHRr6cJTNtq aJG8DtyrdL5ffw78098MOSTkNFBDrYua8vIr1n5mc0vR2TwB3R6mOEbvRrq5N54iBGCIsqg4Fir Cxmi+c+3sO/zt7K/CW+3t0cn1kXf3pMUcPwMKpjJmRFMPPv0n9yNm5jV2s4EgYaO/K1SgsavRhA Yxj5ArZm6CdGbIA8HRr9X9dqqOLTM2X7VzqE/tz+s= X-Received: by 2002:a05:600c:1c03:b0:431:3bf9:3ebb with SMTP id 5b1f17b1804b1-431616898a5mr21939355e9.24.1729262616711; Fri, 18 Oct 2024 07:43:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/2cIUiEBADCILiY5g85Eusx16/mEEHLBs7CDCit4oBcI9vX6pe+Zt6icYGYffc8B+zKocKg== X-Received: by 2002:a05:600c:1c03:b0:431:3bf9:3ebb with SMTP id 5b1f17b1804b1-431616898a5mr21939075e9.24.1729262616252; Fri, 18 Oct 2024 07:43:36 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431606c6be6sm29414975e9.31.2024.10.18.07.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 09/13] rust: clean up define_property macro Date: Fri, 18 Oct 2024 16:43:01 +0200 Message-ID: <20241018144306.954716-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use the "struct update" syntax to initialize most of the fields to zero, and simplify the handmade type-checking of $name. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/qemu-api/src/device_class.rs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 2219b9f73d0..5aba426d243 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -29,44 +29,27 @@ macro_rules! device_class_init { macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = $defval:expr$(,)*) => { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr = $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr = $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: false, - defval: $crate::bindings::Property__bindgen_ty_1 { i: 0 }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; } From patchwork Fri Oct 18 14:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8B25D30016 for ; Fri, 18 Oct 2024 14:44:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCh-0008Hj-KF; Fri, 18 Oct 2024 10:43:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCg-0008HX-3n for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCe-0002cS-Gk for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q6fXeEeyQn++bTLgXgQsS/yFO40vxiI7losxFrd52jU=; b=MqD6ZYNY7v1ub4PulnxZIskQslR4ifssMmXmddnuP5aeNVFX4qgXXd3Tzj1uZmkXGRK3ER OtYn2byI1Ahl/NcriE5/qCkuJyCDOWmaw65DeppKR5xBfSF6yIRL/jRhMb4mZd1L0Th/gn P3iFmP3fWEAxA0LklErVTnu6fY0a8FM= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-_rtPBCsLPh29ujAv61_1fA-1; Fri, 18 Oct 2024 10:43:42 -0400 X-MC-Unique: _rtPBCsLPh29ujAv61_1fA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-431518ae047so16265445e9.0 for ; Fri, 18 Oct 2024 07:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262620; x=1729867420; 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=Q6fXeEeyQn++bTLgXgQsS/yFO40vxiI7losxFrd52jU=; b=PWgA5te4MBF84uJEK7/0i9zSzEOEbiYG9+4cokqkSjc/XU1BAnXWw5T0YngwLCMbOw 0NZtiatWvlXaeVkUj2/hXKVgtSJXsswTqmDTav441cU17bI/vKoUCMjalCfn6Yr8JeDU +nluJXOos16rJI607EUMTKkHyOEQV/nQUTcVhHMcqcSZz3Cor7p27Eu0pptWHfM3QYWB TKZfbz68ItnxpDw3QuXhpnynOvrIKQnlfqK08iyE8/Hy1XqBVYeYyL4XHHr/kUFX0I0P 3c+zD0CNzJby2RdFANlVNZPgVJza5OtWtyrnIzwW8Jau+UeWulHC8a1NYiAgRKLeQWGN U7gg== X-Gm-Message-State: AOJu0YyQBPzEnvg2QL3U30CMObDhYDLRq1SqPyHI1XutxRJ+ndLGMYbx T2HZtK7nDPDnHWfZNzuRjewaZFix/7ruHYknX7f9W5A5hRVNFrp6RLJIcYgk0kiLExP8NjtYWak 1yo0leEHDeYA5bqFbf45WmUtVAbpCXF/zmB/oxn/l2UN0LImNCeDLchZkQseEl9Yj495rCdt9rm hZHF1QTL/drKLqHYWnPuDbVDGNmOiKV4I89iDqPbg= X-Received: by 2002:a05:600c:4fcd:b0:431:4e33:98b6 with SMTP id 5b1f17b1804b1-43161624d76mr17988475e9.5.1729262620282; Fri, 18 Oct 2024 07:43:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKy+uR3ApXqAZBoEmjUeistu/R6u060V5naxL17li2eQl4agU2Fbf8Ya7MPvzQodZVoVCXwg== X-Received: by 2002:a05:600c:4fcd:b0:431:4e33:98b6 with SMTP id 5b1f17b1804b1-43161624d76mr17987435e9.5.1729262619392; Fri, 18 Oct 2024 07:43:39 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160dc9365sm25846115e9.11.2024.10.18.07.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 10/13] qdev: make properties array "const" Date: Fri, 18 Oct 2024 16:43:02 +0200 Message-ID: <20241018144306.954716-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Constify all accesses to qdev properties, except for the ObjectPropertyAccessor itself. This makes it possible to place them in read-only memory, and also lets Rust bindings switch from "static mut" arrays to "static"; which is advantageous, because mutable statics are highly discouraged. Signed-off-by: Paolo Bonzini --- include/hw/qdev-core.h | 4 ++-- include/hw/qdev-properties.h | 4 ++-- hw/core/qdev-properties.c | 26 +++++++++++++------------- system/qdev-monitor.c | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index aa97c34a4be..f9fa291cc63 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -132,7 +132,7 @@ struct DeviceClass { * ensures a compile-time error if someone attempts to assign * dc->props directly. */ - Property *props_; + const Property *props_; /** * @user_creatable: Can user instantiate with -device / device_add? @@ -935,7 +935,7 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); * you attempt to add an existing property defined by a parent class. * To modify an inherited property you need to use???? */ -void device_class_set_props(DeviceClass *dc, Property *props); +void device_class_set_props(DeviceClass *dc, const Property *props); /** * device_class_set_parent_realize() - set up for chaining realize fns diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 09aa04ca1e2..26ebd230685 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -37,7 +37,7 @@ struct PropertyInfo { int (*print)(Object *obj, Property *prop, char *dest, size_t len); void (*set_default_value)(ObjectProperty *op, const Property *prop); ObjectProperty *(*create)(ObjectClass *oc, const char *name, - Property *prop); + const Property *prop); ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyRelease *release; @@ -223,7 +223,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, * On error, store error in @errp. Static properties access data in a struct. * The type of the QOM property is derived from prop->info. */ -void qdev_property_add_static(DeviceState *dev, Property *prop); +void qdev_property_add_static(DeviceState *dev, const Property *prop); /** * qdev_alias_all_properties: Create aliases on source for all target properties diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 86a583574dd..315196bd85a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -749,7 +749,7 @@ const PropertyInfo qdev_prop_array = { /* --- public helpers --- */ -static Property *qdev_prop_walk(Property *props, const char *name) +static const Property *qdev_prop_walk(const Property *props, const char *name) { if (!props) { return NULL; @@ -763,10 +763,10 @@ static Property *qdev_prop_walk(Property *props, const char *name) return NULL; } -static Property *qdev_prop_find(DeviceState *dev, const char *name) +static const Property *qdev_prop_find(DeviceState *dev, const char *name) { ObjectClass *class; - Property *prop; + const Property *prop; /* device properties */ class = object_get_class(OBJECT(dev)); @@ -840,7 +840,7 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value) void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) { - Property *prop; + const Property *prop; prop = qdev_prop_find(dev, name); object_property_set_str(OBJECT(dev), name, @@ -956,7 +956,7 @@ const PropertyInfo qdev_prop_size = { /* --- object link property --- */ static ObjectProperty *create_link_property(ObjectClass *oc, const char *name, - Property *prop) + const Property *prop) { return object_class_property_add_link(oc, name, prop->link_type, prop->offset, @@ -969,7 +969,7 @@ const PropertyInfo qdev_prop_link = { .create = create_link_property, }; -void qdev_property_add_static(DeviceState *dev, Property *prop) +void qdev_property_add_static(DeviceState *dev, const Property *prop) { Object *obj = OBJECT(dev); ObjectProperty *op; @@ -980,7 +980,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop) field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); object_property_set_description(obj, prop->name, prop->info->description); @@ -994,7 +994,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop) } static void qdev_class_add_property(DeviceClass *klass, const char *name, - Property *prop) + const Property *prop) { ObjectClass *oc = OBJECT_CLASS(klass); ObjectProperty *op; @@ -1007,7 +1007,7 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name, field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); } if (prop->set_default) { prop->info->set_default_value(op, prop); @@ -1046,7 +1046,7 @@ static void qdev_get_legacy_property(Object *obj, Visitor *v, * Do not use this in new code! QOM Properties added through this interface * will be given names in the "legacy" namespace. */ -static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) +static void qdev_class_add_legacy_property(DeviceClass *dc, const Property *prop) { g_autofree char *name = NULL; @@ -1058,12 +1058,12 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) name = g_strdup_printf("legacy-%s", prop->name); object_class_property_add(OBJECT_CLASS(dc), name, "str", prop->info->print ? qdev_get_legacy_property : prop->info->get, - NULL, NULL, prop); + NULL, NULL, (Property *)prop); } -void device_class_set_props(DeviceClass *dc, Property *props) +void device_class_set_props(DeviceClass *dc, const Property *props) { - Property *prop; + const Property *prop; dc->props_ = props; for (prop = props; prop && prop->name; prop++) { diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 44994ea0e16..c346ea6ae4b 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -751,7 +751,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) -static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, +static void qdev_print_props(Monitor *mon, DeviceState *dev, const Property *props, int indent) { if (!props) From patchwork Fri Oct 18 14:43:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04DACD30016 for ; Fri, 18 Oct 2024 14:44:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCl-0008IH-M0; Fri, 18 Oct 2024 10:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCj-0008I7-Uo for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCi-0002cf-EL for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qr5dagb8vQ3bDNxUa7EXxPicbCEKo86t7f8oVBzNrBQ=; b=NJ585F2RaXAio8Jvs/TP1RzYogFcOy9juwoojw1zPTKN6pvkXYanKCyENBExGELVe3vWJj FvcaZaOPPUAN4o0v+ZEIrfv66Pf+9Zr+GPPcfjW1tAqlbLYQxFmBA/IqC1sX1N+uOhQdgC TIfZGE21XOZo1Cd8f6abt94w31CcJmo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-oVX88SV4Oi-gKGNpQ1mjFA-1; Fri, 18 Oct 2024 10:43:46 -0400 X-MC-Unique: oVX88SV4Oi-gKGNpQ1mjFA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4316655b2f1so1362215e9.0 for ; Fri, 18 Oct 2024 07:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262623; x=1729867423; 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=Qr5dagb8vQ3bDNxUa7EXxPicbCEKo86t7f8oVBzNrBQ=; b=FQf6sKO1veG3TBMduMAJr9c5s9Bb2aYJ8Ybz3BeD20wdO2ekyKgiiiKvlrEOT14SJM QuYnYpREHA1l2ptE67AKxbWyr1TrWBF45nk5m/nwr26q8ZXNEp7fRLDE7yOd8fufkXOd XOjPjj1qgHBBjuDzWJvCtHrsnv4vo3h4patrUoEW03BTyprZULOi3ORm/tftwR4HIwec 9lAYliJnEBECH78gKeWxSNwKelNDCnAGE5mGK7VXqpSYQnRQVLa2obhqkZALO2xtFXh+ Xcr1EBTOrQ48lllOQoV5oVXtL8ag+dO9+GqhvGRTGAWVUBbZWwFs6vLqKcLpXPdTEEts YtEQ== X-Gm-Message-State: AOJu0YzL3/dIEVgymYlyHatxN4+YJEdTBIDfVxVXumaRqdRQyUEqI81s uqdaZYyayKRv55CkyruHaNCUTr7FnVf9/qbouOwOsjuj61IEWUQSUMgZkIXgs1PCvmn/juG5/ny M239nK9ceefy8S3Zanec7VL+7D77L8yCluRoqQ1Q/6ZSnijvQ12zNeMWxd0eFKCXMaXoBFT7SOK SXTS/3gDb4K+sJGmuURcapAR6hs5PSZ6LY7V0Q8fo= X-Received: by 2002:a05:600c:5124:b0:431:5bf2:2d4 with SMTP id 5b1f17b1804b1-431616a388cmr21866525e9.29.1729262623500; Fri, 18 Oct 2024 07:43:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaSGjlQKknbJVwEuYZZVU30k72n+n1WrGSyD7f5FtRHRlGzfUZq+z8LuJhOKtRYpMnY/7QIA== X-Received: by 2002:a05:600c:5124:b0:431:5bf2:2d4 with SMTP id 5b1f17b1804b1-431616a388cmr21866275e9.29.1729262623079; Fri, 18 Oct 2024 07:43:43 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160dbe7c5sm25845785e9.6.2024.10.18.07.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 11/13] rust: make properties array immutable Date: Fri, 18 Oct 2024 16:43:03 +0200 Message-ID: <20241018144306.954716-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now that device_class_set_props() takes a const pointer, the only part of "define_property!" that needs to be non-const is the call to try_into(). This in turn will only break if offset_of returns a value with the most significant bit set (i.e. a struct size that is >=2^31 or >= 2^63, respectively on 32- and 64-bit system), which is impossible. Just use a cast and clean everything up to remove the run-time initialization. This also removes a use of OnceLock, which was only stabilized in 1.70.0. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/qemu-api/src/device_class.rs | 42 ++++++------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index 5aba426d243..d885f2fcf19 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,10 +2,6 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use std::sync::OnceLock; - -use crate::bindings::Property; - #[macro_export] macro_rules! device_class_init { ($func:ident, props => $props:ident, realize_fn => $realize_fn:expr, legacy_reset_fn => $legacy_reset_fn:expr, vmsd => $vmsd:ident$(,)*) => { @@ -19,7 +15,7 @@ macro_rules! device_class_init { dc.as_mut().realize = $realize_fn; dc.as_mut().vmsd = &$vmsd; $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_mut_ptr()); + $crate::bindings::device_class_set_props(dc.as_mut(), $props.as_ptr()); } } }; @@ -32,9 +28,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } @@ -45,47 +39,27 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } } }; } -#[repr(C)] -pub struct Properties(pub OnceLock<[Property; N]>, pub fn() -> [Property; N]); - -impl Properties { - pub fn as_mut_ptr(&mut self) -> *mut Property { - _ = self.0.get_or_init(self.1); - self.0.get_mut().unwrap().as_mut_ptr() - } -} - #[macro_export] macro_rules! declare_properties { ($ident:ident, $($prop:expr),*$(,)*) => { - - const fn _calc_prop_len() -> usize { + pub static $ident: [$crate::bindings::Property; { let mut len = 1; $({ _ = stringify!($prop); len += 1; })* len - } - const PROP_LEN: usize = _calc_prop_len(); - - fn _make_properties() -> [$crate::bindings::Property; PROP_LEN] { - [ - $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, - ] - } - - pub static mut $ident: $crate::device_class::Properties = $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_properties); + }] = [ + $($prop),*, + unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, + ]; }; } From patchwork Fri Oct 18 14:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 192FDD30016 for ; Fri, 18 Oct 2024 14:44:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCp-0008RE-PQ; Fri, 18 Oct 2024 10:43:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCo-0008Pl-Bo for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCm-0002cq-HD for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=emK1BbhOeZN8ln9uEXMUETGvQfGIAyHdSO+Caj5JSUY=; b=VzxXptx0AME2MDa6lD6BGgLKV+JR68MIADGH3g5sMetZyu6nWN4zbp7WI0ewyjQ9cXUQ03 01KfjTj23v8eXwExtuGP7+kgvv6SDXHjOQdyoxhCfhYazd1uRCpiKBJp+SEw/5JMs3njaH sRHcvz3PJhEATVgw5TUErc6o3rALsBM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-Q41-OngaMRuwIi_ugl6-AQ-1; Fri, 18 Oct 2024 10:43:49 -0400 X-MC-Unique: Q41-OngaMRuwIi_ugl6-AQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d4af408dcso1212220f8f.0 for ; Fri, 18 Oct 2024 07:43:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262627; x=1729867427; 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=emK1BbhOeZN8ln9uEXMUETGvQfGIAyHdSO+Caj5JSUY=; b=FstKgFs5RglPXs49mJyF1T1rjo8LhVGVWgYhoksHUY/FmXcmqqNanP3OOpTNQLWF7N r/PMg+ySku9xu3kcHK69bqRJYQHVN8IWtxruUYT4GgkaWKZ9F0Pm2p48ADs8hN+q0c4D VZ4iqGDDytM5g8elJHaDQY4KW0YeTtLYFI/LAgAorrLC887mOj5BdEHMwjpEi6zBAIYR nTDD2OdqaoqBXUuIx/8w7pa4Fu7AOeQtzgC16qeIZnYDpSh5nSr/CPzJFfPkoNsg1j/9 jwvIH88iKzegO8E/Ouh1TpUFTCpPuc4nSRUe6Ez6BpTlbF0swBCzr+G9+43Zws5ZFQcW 8A8Q== X-Gm-Message-State: AOJu0Ywp5qzTRq3IwEtWplfU3FvORBBxaJJep4DXGLAVDLwau9VunJH9 Y8kqnQ4sbleJFJVCV8p5uigPzzb7jA3dcHk8FwvEA/fh9qFvXIXL7JldnKMk6emRchCtUTwMT2G iymORaT8uTuoJCb25kQHEsHURxUgVAmQArXk6moc34lJcOw5ft6jetjZNIt+n+R0a7E55qRuE1j Xq1mnJxkOVzDd7ZBDluHvhnwpp059feeuXpvbw9x4= X-Received: by 2002:adf:e38f:0:b0:37c:ce58:5a1a with SMTP id ffacd0b85a97d-37eb48942f4mr1981611f8f.54.1729262627233; Fri, 18 Oct 2024 07:43:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHch1i06pVAPnRkPkyas0oKandPSHmPSRHHeGgmz15lUrNXqa+PTJNkp74byPNyhiiSAqbEg== X-Received: by 2002:adf:e38f:0:b0:37c:ce58:5a1a with SMTP id ffacd0b85a97d-37eb48942f4mr1981588f8f.54.1729262626708; Fri, 18 Oct 2024 07:43:46 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf0861d2sm2105397f8f.56.2024.10.18.07.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 12/13] rust: provide safe wrapper for MaybeUninit::zeroed() Date: Fri, 18 Oct 2024 16:43:04 +0200 Message-ID: <20241018144306.954716-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org MaybeUninit::zeroed() is handy, but it introduces unsafe (and has a pretty heavy syntax in general). Introduce a trait that provides the same functionality while staying within safe Rust. In addition, MaybeUninit::zeroed() is not available as a "const" function until Rust 1.75.0, so this also prepares for having handwritten implementations of the trait until we can assume that version. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/hw/char/pl011/src/device_class.rs | 8 ++++++-- rust/hw/char/pl011/src/memory_ops.rs | 11 +++++++---- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/device_class.rs | 8 ++++---- rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/zeroable.rs | 23 +++++++++++++++++++++++ 6 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 rust/qemu-api/src/zeroable.rs diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 2ad80451e87..78fa1cdd5b6 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -4,7 +4,11 @@ use core::ptr::NonNull; -use qemu_api::{bindings::*, definitions::ObjectImpl}; +use qemu_api::{ + bindings::*, + definitions::ObjectImpl, + zeroable::Zeroable, +}; use crate::device::PL011State; @@ -12,7 +16,7 @@ pub static VMSTATE_PL011: VMStateDescription = VMStateDescription { name: PL011State::TYPE_INFO.name, unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() } + ..Zeroable::ZERO }; qemu_api::declare_properties! { diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index 5a5320e66c3..24ac9c870c1 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -2,9 +2,12 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::{mem::MaybeUninit, ptr::NonNull}; +use core::ptr::NonNull; -use qemu_api::bindings::*; +use qemu_api::{ + bindings::*, + zeroable::Zeroable +}; use crate::device::PL011State; @@ -14,11 +17,11 @@ read_with_attrs: None, write_with_attrs: None, endianness: device_endian::DEVICE_NATIVE_ENDIAN, - valid: unsafe { MaybeUninit::::zeroed().assume_init() }, + valid: Zeroable::ZERO, impl_: MemoryRegionOps__bindgen_ty_2 { min_access_size: 4, max_access_size: 4, - ..unsafe { MaybeUninit::::zeroed().assume_init() } + ..Zeroable::ZERO }, }; diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index d24e0c0725e..5fa4a08e76b 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,6 +5,7 @@ _qemu_api_rs = static_library( 'src/lib.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/zeroable.rs', ], {'.' : bindings_rs}, ), diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index d885f2fcf19..ed2d7ce1a54 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -31,7 +31,7 @@ macro_rules! define_property { offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.into() }, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) => { @@ -41,7 +41,7 @@ macro_rules! define_property { info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; } @@ -58,7 +58,7 @@ macro_rules! declare_properties { len }] = [ $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed().assume_init() }, + $crate::zeroable::Zeroable::ZERO, ]; }; } @@ -79,7 +79,7 @@ macro_rules! vm_state_description { $vname.as_ptr() },)* unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::VMStateDescription>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO }; } } diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e72fb4b4bb1..91b9459235b 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -29,6 +29,7 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod definitions; pub mod device_class; +pub mod zeroable; #[cfg(test)] mod tests; diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs new file mode 100644 index 00000000000..927c634b48f --- /dev/null +++ b/rust/qemu-api/src/zeroable.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/// Encapsulates the requirement that +/// `MaybeUninit::::zeroed().assume_init()` does not cause +/// undefined behavior. +/// +/// SAFETY: do not add this trait to a type unless all-zeroes is +/// a valid value for the type. In particular, remember that raw +/// pointers can be zero, but references and `NonNull` cannot +/// unless wrapped with `Option<>`. +pub unsafe trait Zeroable: Default { + /// SAFETY: If the trait was added to a type, then by definition + /// this is safe. + const ZERO: Self = unsafe { + ::core::mem::MaybeUninit::::zeroed().assume_init() + }; +} + +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::Property {} +unsafe impl Zeroable for crate::bindings::VMStateDescription {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} From patchwork Fri Oct 18 14:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13841888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66004D30016 for ; Fri, 18 Oct 2024 14:45:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1oCu-0008SE-5w; Fri, 18 Oct 2024 10:44:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCs-0008Rv-HM for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1oCq-0002d1-WE for qemu-devel@nongnu.org; Fri, 18 Oct 2024 10:43:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729262636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NsHsr8EGNkWFqpcJthGt4kDzKJbhQ29fHJHg6UgTL0s=; b=EK1racNa6fWMtSTqkRperfW0Uzw+qTdVDl1p7SQO7WpurjwG0UJcInhYhSSkkaWhHailH8 DwXnu8eDaMqSlPy26r2eRC/FNaHyyE6/0+gp6zQb4hGrlRLhlpnCvLgS5O1z2Eo03qzwwN /jx3x9SHhkIrnf9QslWO2/yRMQEXmjk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-ohHSrTy1OEKQF0FBErNjfw-1; Fri, 18 Oct 2024 10:43:53 -0400 X-MC-Unique: ohHSrTy1OEKQF0FBErNjfw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d4854fa0eso1262965f8f.2 for ; Fri, 18 Oct 2024 07:43:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729262631; x=1729867431; 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=NsHsr8EGNkWFqpcJthGt4kDzKJbhQ29fHJHg6UgTL0s=; b=Trkmywp5rkq+Pk8tEo32eEvhsDvRfRfIYqQCGRryuTHrdhu2Cx8E823OV34f44jghD SUCNocmCrElzwJR+D9ULGfuevKjFZxmZo7u5ROMi00g2Jfx7vSVRPazqSx2ROb6/tcXh jCbgeY1ileDwDMmSZPR84gt4Vz71dHDjJkplZXjxC8gIysNnhhlaWYIefnv58/1wbkgr 3tAH+IRmht4QYlchgZzlV7jNIqBkMk4bGbj1UZqI7+EKQNTMiDt7qgjWjsdYAtGQZMRp xvcqI9uQl0oIcE1EgeZtI4IvPbsnpyssNglw9TK+nKoois3KzVDVbU2vLR3gSEw58JjA JuiQ== X-Gm-Message-State: AOJu0YyYhILvRzzRRxHU5tg3SMqVibPBqCdLv5FqvqwUPoTY+L3pr1xX KZojtfyG5DGCPyRHfw9OZY7EjsQZ3PP+S71eahtLr8MyBEenS+W+snx8/kKq/YxPhKYOEW2J+9n dcbf/+GGSS+92HbtwEMPhWuRc1eZg/ePft2jwVQvTtq1K4KO6fc7UXX5ClRbg/JFSCPEne3217N 4ekRB/+yOODb/xKFGfepFkCjA+cEuzra2UFIUoHNc= X-Received: by 2002:adf:fe90:0:b0:374:d25f:101 with SMTP id ffacd0b85a97d-37eab7436eamr1778397f8f.18.1729262630865; Fri, 18 Oct 2024 07:43:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrXyip2B7LtCCXl5ep7RbXpHD6dbB/qSAaWohU2BHqVRE/wd2lXAFuBppiS2iDX/opSMiIXw== X-Received: by 2002:adf:fe90:0:b0:374:d25f:101 with SMTP id ffacd0b85a97d-37eab7436eamr1778373f8f.18.1729262630362; Fri, 18 Oct 2024 07:43:50 -0700 (PDT) Received: from avogadro.local ([151.95.144.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ecf069298sm2121359f8f.39.2024.10.18.07.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 07:43:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Junjie Mao Subject: [PATCH 13/13] rust: do not use TYPE_CHARDEV unnecessarily Date: Fri, 18 Oct 2024 16:43:05 +0200 Message-ID: <20241018144306.954716-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018144306.954716-1-pbonzini@redhat.com> References: <20241018144306.954716-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.016, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the invocation of qdev_prop_set_chr(), "chardev" is the name of a property rather than a type and has to match the name of the property in device_class.rs. Do not use TYPE_CHARDEV here, just like in the C version of pl011_create. Signed-off-by: Paolo Bonzini Reviewed-by: Junjie Mao --- rust/hw/char/pl011/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2b43f5e0939..0f6918dd224 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -572,7 +572,7 @@ pub fn update(&self) { let dev: *mut DeviceState = qdev_new(PL011State::TYPE_INFO.name); let sysbus: *mut SysBusDevice = dev.cast::(); - qdev_prop_set_chr(dev, bindings::TYPE_CHARDEV.as_ptr(), chr); + qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr); sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq);