From patchwork Thu Oct 24 14:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 13849138 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 3CBE5CE8E7C for ; Thu, 24 Oct 2024 14:06:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3yRW-0007Bb-Au; Thu, 24 Oct 2024 10:04:02 -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 1t3yRJ-00079A-G9 for qemu-devel@nongnu.org; Thu, 24 Oct 2024 10:03:53 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3yRH-0003xI-PG for qemu-devel@nongnu.org; Thu, 24 Oct 2024 10:03:49 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso122898066b.1 for ; Thu, 24 Oct 2024 07:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729778626; x=1730383426; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KCn73+YkWwVjQeZCOwMpqD8LHrnSQOeaidvNNKE/Tbg=; b=baid7ihQiUxezkPyj1QXwB7iZV9kJjX8e7B1tbK7Ir3ldidu/1+VEWdZHc8WHo2FRp lOeMwa8UxA/odZ+EXak0i+MzG3AYq2A4LnIxPNUYscf/h9E0uuEdkWkL8I0do3ffnkkL 6c0syXUeAVrZVvA1G1Qh3KtHWPd3EQn4/5IhJcqAaSJ+wx5f431gtR23/7bBBDQQyrff P/Y2jNK26K3MV0dcL/0bOx8oL7uAWjQUBOhvQy8KRxzB3TWId73cMH6uX+b+61EJlakk cgn5dyrB3iWa0pwKsMdYbuzFDkqXGdnll0nBF61FvR3RdPFXB8nZqCvjuWc5oI9Z4wqS Wyvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729778626; x=1730383426; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KCn73+YkWwVjQeZCOwMpqD8LHrnSQOeaidvNNKE/Tbg=; b=DtxC0al+DU9POHfJjIQMJHaCxP15tjkE5b1HkWuU1VE/J6QyeUVYnlgvo83RVZi3zM 8jdgaJsMkvpIHq20LdPUwyv8uCoESPo13SLmgTEmKpv32G/TTg/odEIVE29eMIoVOEME c4munONUoj6NGV2713lBgTjRR2ZkVg/7oLHyfStfi46YAnOZ71WMVjNi6p0CqEDIneXu Y0TwBcPBj4vKGW58tyYsEdmTdno5hvgjigMR7uIqU6uupGht6x2tsBOJdRr8JV8ThFvV JvEAcTh0tfm1qMJ1ORfqpTHoKHCt2DIX3tuGuqd424HCExnFQZFwOxgpTh7LlPeQsqiW +p4Q== X-Gm-Message-State: AOJu0YxoaTMn5BwEgVbda93XYdNUQe6aKYH9uejMMQ+T3QpqGFEe5wFa 8Xah0Dq0d8MHqC/f2aUfd83yxFZZbPc/z/Zw2it1R4OF8PGnO1iphpiwxxJ28Ng= X-Google-Smtp-Source: AGHT+IEwX1dxqhQrGkfgK6YAEvKzZoJXmTBgXHkYG5P2OIcSO99hXifidTHt70f2mij4Idcd1CeErg== X-Received: by 2002:a17:906:794b:b0:a99:8178:f7ed with SMTP id a640c23a62f3a-a9ad2711849mr199678366b.4.1729778623981; Thu, 24 Oct 2024 07:03:43 -0700 (PDT) Received: from [127.0.1.1] (adsl-113.37.6.2.tellas.gr. [37.6.2.113]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912f6878sm621407566b.86.2024.10.24.07.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 07:03:43 -0700 (PDT) From: Manos Pitsidianakis Date: Thu, 24 Oct 2024 17:03:05 +0300 Subject: [PATCH 07/11] rust/pl011: move pub callback decl to local scope MIME-Version: 1.0 Message-Id: <20241024-rust-round-2-v1-7-051e7a25b978@linaro.org> References: <20241024-rust-round-2-v1-0-051e7a25b978@linaro.org> In-Reply-To: <20241024-rust-round-2-v1-0-051e7a25b978@linaro.org> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Phil?= =?utf-8?q?ippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= , Thomas Huth , Junjie Mao , Junjie Mao , Zhao Liu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Gustavo Romero , Pierrick Bouvier X-Mailer: b4 0.15-dev-12fc5 X-Developer-Signature: v=1; a=openpgp-sha256; l=5176; i=manos.pitsidianakis@linaro.org; h=from:subject:message-id; bh=t89qGxVY7Bbmwy9c+qHVuDpEPvucQqPydBhWY3bNDGg=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgpvd0VCYlFLUy9aQU5Bd0FLQVhjcHgzQi9mZ 25RQWNzbVlnQm5HbE9qY1RxSXBLa0N5NGh3RFc5NEJjeUliaXFwCmdw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FUT09Cj1ybTNjCi0tLS0tRU5EIF BHUCBNRVNTQUdFLS0tLS0K X-Developer-Key: i=manos.pitsidianakis@linaro.org; a=openpgp; fpr=7C721DF9DB3CC7182311C0BF68BC211D47B421E1 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-ej1-x62e.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 extern "C" callbacks in instance_init() do not need to be public. Move them to local function scope instead. No functional change. Signed-off-by: Manos Pitsidianakis --- rust/hw/char/pl011/src/device.rs | 104 +++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 54 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 3aa055dee4b10866a624505a9d05ef1ab8182dce..75399fa6352916fa9cc24164af0ea2e20fe29399 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -219,6 +219,56 @@ unsafe fn instance_init(&mut self) { impl DeviceImpl for PL011State { fn realize(&mut self) { + /// # Safety + /// + /// 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. + unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { + unsafe { + debug_assert!(!opaque.is_null()); + let state = NonNull::new_unchecked(opaque.cast::()); + state.as_ref().can_receive().into() + } + } + /// # Safety + /// + /// 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. + /// + /// The buffer and size arguments must also be valid. + unsafe extern "C" fn pl011_receive( + opaque: *mut core::ffi::c_void, + buf: *const u8, + size: core::ffi::c_int, + ) { + unsafe { + debug_assert!(!opaque.is_null()); + let mut state = NonNull::new_unchecked(opaque.cast::()); + if state.as_ref().loopback_enabled() { + return; + } + if size > 0 { + debug_assert!(!buf.is_null()); + state.as_mut().put_fifo(c_uint::from(buf.read_volatile())) + } + } + } + + /// # Safety + /// + /// 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. + unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) { + unsafe { + debug_assert!(!opaque.is_null()); + let mut state = NonNull::new_unchecked(opaque.cast::()); + state.as_mut().event(event) + } + } + // SAFETY: self.char_backend has the correct size and alignment for a // CharBackend object, and its callbacks are of the correct types. unsafe { @@ -611,60 +661,6 @@ pub fn update(&self) { /// # Safety /// -/// 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()); - let state = NonNull::new_unchecked(opaque.cast::()); - state.as_ref().can_receive().into() - } -} - -/// # Safety -/// -/// 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. -/// -/// 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, - size: core::ffi::c_int, -) { - unsafe { - debug_assert!(!opaque.is_null()); - let mut state = NonNull::new_unchecked(opaque.cast::()); - if state.as_ref().loopback_enabled() { - return; - } - if size > 0 { - debug_assert!(!buf.is_null()); - state.as_mut().put_fifo(c_uint::from(buf.read_volatile())) - } - } -} - -/// # Safety -/// -/// 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()); - let mut state = NonNull::new_unchecked(opaque.cast::()); - state.as_mut().event(event) - } -} - -/// # 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(