From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1tmoPB-0007AN-Q1 for mharc-qemu-rust@gnu.org; Tue, 25 Feb 2025 01:26:57 -0500 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 1tmoP2-00079N-Pg; Tue, 25 Feb 2025 01:26:48 -0500 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmoOy-0001FC-6y; Tue, 25 Feb 2025 01:26:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1740464804; x=1772000804; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=gcnnrlfbep+3n+TB3ISdH1THmG3D+qNZIJZlMekACzU=; b=dewLFsTkOLOjK+Am0leJChEGEQjGBEohQzN0v+sE2MvZbRpTQZo3Kmut H9sev64XT18qgiSYCqLq+SBwInARGkyT5NtNYvjaVHGKK81nxYdqYxWW4 l36W5kB8yHEfVdzxZZACmgZNMdFNJHUEe/ImyeXvFg8mQeMUkZOp2z2nL iY4ILw5TD3SA3tDkbRHouYASQjXg0YtHQ+MKEB+NJhCBv6V6nKrywsWTU DVWCIRq/UTkMJer57uWpw5cBptQYJqz8hLEYdTTj3rsgo8Yuwc4qZqqo0 q5WLsJK4cdzwP7zK23kbpVlenhMZuhNxfvAlc4d+a0Zzo0DBkBbF7M1ji w==; X-CSE-ConnectionGUID: LDM/YHplQ6CAGY0+Dsulsg== X-CSE-MsgGUID: pi/tzc8iQT24LKXi/dXZ/A== X-IronPort-AV: E=McAfee;i="6700,10204,11355"; a="58796535" X-IronPort-AV: E=Sophos;i="6.13,313,1732608000"; d="scan'208";a="58796535" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2025 22:26:35 -0800 X-CSE-ConnectionGUID: SkpgLxr4QA+0WPx418/9xA== X-CSE-MsgGUID: Bk8iHQveTZ67NcWAQK1e+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,313,1732608000"; d="scan'208";a="116065015" Received: from liuzhao-optiplex-7080.sh.intel.com (HELO localhost) ([10.239.160.39]) by orviesa009.jf.intel.com with ESMTP; 24 Feb 2025 22:26:33 -0800 Date: Tue, 25 Feb 2025 14:46:10 +0800 From: Zhao Liu To: Paolo Bonzini Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org Subject: Re: [PATCH 06/15] rust: cell: add wrapper for FFI types Message-ID: References: <20250221170342.63591-1-pbonzini@redhat.com> <20250221170342.63591-7-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250221170342.63591-7-pbonzini@redhat.com> Received-SPF: pass client-ip=192.198.163.8; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Feb 2025 06:26:53 -0000 > + /// Creates a new opaque object with zeroed contents. > + /// > + /// # Safety > + /// > + /// Ultimately the pointer to the returned value will be dereferenced > + /// in another unsafe block, for example when passing it to a C function. > + /// However, this function is unsafe to "force" documenting whether a > + /// zero value is safe. > + pub const unsafe fn zeroed() -> Self { > + Self { > + value: UnsafeCell::new(MaybeUninit::uninit()), typo? MaybeUninit::zeroed() > + _pin: PhantomPinned, > + } > + } > + > + /// Returns a raw pointer to the opaque data. Maybe "a raw mutable pointer". > + pub const fn as_mut_ptr(&self) -> *mut T { > + UnsafeCell::get(&self.value).cast() > + } > + > + /// Returns a raw pointer to the opaque data. > + pub const fn as_ptr(&self) -> *const T { > + self.as_mut_ptr() as *const _ > + } > + > + /// Returns a raw pointer to the opaque data. What about "Returns a raw c_void type pointer"? (Because the descriptions of these three helpers are exactly the same! We can make them different.) zeroed > + pub const fn as_void_ptr(&self) -> *mut std::ffi::c_void { > + UnsafeCell::get(&self.value).cast() > + } > +} The whole idea is great! With the nit of zeroed fixed, Reviewed-by: Zhao Liu