From nobody Tue May 14 13:59:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87667+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87667+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1647528855; cv=none; d=zohomail.com; s=zohoarc; b=L9dZofA1igOdceY/igEJdSltN2wDLsb8vSMW5MIEMTmGVxj4pQNBJ82bJEMc3oxqKD+eq5r6C1mSz8/3fDp2/R3uOdK2vU1kDNsylpeC3F9hoj+glD4OZq4PiOWsl2Cr1ne7FJs/J8jiMv7JTzLVC3BGdh/3vnOf1/hRsfkX2Go= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647528855; h=Content-Type:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=GNStzVi87UDeUobxWX0hhdg4gEuPVUEOuNuTesZtXQY=; b=BcLmLduMdNZS0Ydll46waSK9+HPB0fSIlR+7zW+XtXhu+I0k8ldN/zTMG1z4S2bIK3KrFRXFjGgZsmMLzhVOnX5566pcZWqJiATXe/ko1ESdnlCFHQ6363fZacDIqA9w/xL5PGWUXtpZi7FG7AxojD7fYgnWCjBWObE1jWuLL1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87667+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 164752885540351.93117555515937; Thu, 17 Mar 2022 07:54:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eK2NYY1788612xsHAl6UXyhn; Thu, 17 Mar 2022 07:54:15 -0700 Subject: [edk2-devel] [Patch] Fix edkii-rust brach in edk2-staging To: devel@edk2.groups.io From: ayushdevel1325@gmail.com X-Originating-Location: Dhanbad, Jharkhand, IN (103.15.228.66) X-Originating-Platform: Linux Firefox 98 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Thu, 17 Mar 2022 07:54:14 -0700 Message-ID: Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ayushdevel1325@gmail.com X-Gm-Message-State: NntkAi9oxWVNluMqhRCLvoLOx1787277AA= Content-Type: multipart/alternative; boundary="BgmY9sSaGfF0KPi3bVic" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647528855; bh=LnJUazM4x2tg9lAMtDcxRA/p+ats/xL1L+XOwEnYm1o=; h=Content-Type:Date:From:Reply-To:Subject:To; b=DFrJ7RkUg4WKh7ePMRIAmgCnmISSHoi43VQgLT+q4LgeJZJd6vGx2juNR3YLUkTNwQj wFa4qH7do6ArRkKypbsxnfXhrl1mxqRc/m4mtCzpuJmaKfA1eXtl+8JTAwuWs8tn+7KV1 8gOzmTQWi0gMHp8NVFAhQ06RVGNJqApcjGk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1647528856098100002 --BgmY9sSaGfF0KPi3bVic Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: Ayush Singh Hello everyone, I am Ayush Singh, an applicant for for GSoC 2022. My Introduction can be fo= und here ( https://edk2.groups.io/g/devel/message/87637 ). To get myself acquainted with the project, I was trying to build the Rust t= ests in edkii-rust branch in edk2-staging and found out that due to changes= in the Rust Allocator API, *Test/TestRustLangLib* and *Test/RustLangApp* f= ail to build. Also, cargo now supports cross-compiling sysroot ( build-std = feature ( https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#b= uild-std ) ) so there is no need for cargo-xbuild. I have tried to fix *Test/TestRustLangLib* and would like someone to review= if it is correct. Here is the diff: diff --git a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs b/RustPkg/Lib= rary/UefiRustAllocationLib/src/lib.rs index f369e1bb17..6a65f0a5f9 100644 --- a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs +++ b/RustPkg/Library/UefiRustAllocationLib/src/lib.rs @@ -15,44 +15,42 @@ #![feature(alloc_layout_extra)] #![feature(allocator_api)] #![feature(alloc_error_handler)] - #![cfg_attr(not(test), no_std)] - #![allow(unused)] extern crate uefi_rust_panic_lib; -use core::alloc::{GlobalAlloc, Layout, Alloc}; -use r_efi::efi; -use r_efi::efi::{Status}; +use core::alloc::{GlobalAlloc, Layout}; use core::ffi::c_void; +use r_efi::efi; +use r_efi::efi::Status; pub struct MyAllocator; -static mut ST : *mut efi::SystemTable =3D core::ptr::null_mut(); -static mut BS : *mut efi::BootServices =3D core::ptr::null_mut(); +static mut ST: *mut efi::SystemTable =3D core::ptr::null_mut(); +static mut BS: *mut efi::BootServices =3D core::ptr::null_mut(); unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let size =3D layout.size(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let align =3D layout.align(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if align > 8 { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return core::ptr::null_mut(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let size =3D layout.size(); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let align =3D layout.align(); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if align > 8 { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = core::ptr::null_mut(); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let mut address : *mut c_void =3D core::ptr= ::null_mut(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let status =3D ((*BS).allocate_pool) ( -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi::MemoryType::BootServi= cesData, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 size, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &mut address as *mut *mut = c_void -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if status !=3D Status::SUCCESS { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return core::ptr::null_mut(); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 address as *mut u8 +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let mut address: *mut c_void = =3D core::ptr::null_mut(); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let status =3D ((*BS).allocate_= pool)( +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 efi::Me= moryType::BootServicesData, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 size, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &mut ad= dress as *mut *mut c_void, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if status !=3D Status::SUCCESS { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = core::ptr::null_mut(); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 address as *mut u8 } unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((*BS).free_pool) (ptr as *mut c_void); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((*BS).free_pool)(ptr as *mut c= _void); } } @@ -60,14 +58,13 @@ unsafe impl GlobalAlloc for MyAllocator { static ALLOCATOR: MyAllocator =3D MyAllocator; #[alloc_error_handler] -fn alloc_error_handler(layout: core::alloc::Layout) -> ! -{ +fn alloc_error_handler(layout: core::alloc::Layout) -> ! { loop {} } -pub extern fn init(system_table: *mut efi::SystemTable) { +pub extern "C" fn init(system_table: *mut efi::SystemTable) { unsafe { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ST =3D system_table; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BS =3D (*ST).boot_services; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ST =3D system_table; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BS =3D (*ST).boot_services; } } diff --git a/RustPkg/Test/HelloWorld/.cargo/config.toml b/RustPkg/Test/Hell= oWorld/.cargo/config.toml new file mode 100644 index 0000000000..3d6a3ff35c --- /dev/null +++ b/RustPkg/Test/HelloWorld/.cargo/config.toml @@ -0,0 +1,3 @@ +[unstable] +build-std =3D ["core", "compiler_builtins"] +build-std-features =3D ["compiler-builtins-mem"] diff --git a/RustPkg/Test/HelloWorld2/.cargo/config.toml b/RustPkg/Test/Hel= loWorld2/.cargo/config.toml new file mode 100644 index 0000000000..3d6a3ff35c --- /dev/null +++ b/RustPkg/Test/HelloWorld2/.cargo/config.toml @@ -0,0 +1,3 @@ +[unstable] +build-std =3D ["core", "compiler_builtins"] +build-std-features =3D ["compiler-builtins-mem"] diff --git a/RustPkg/Test/TestRustLangLib/.cargo/config.toml b/RustPkg/Test= /TestRustLangLib/.cargo/config.toml new file mode 100644 index 0000000000..422bf9d2ab --- /dev/null +++ b/RustPkg/Test/TestRustLangLib/.cargo/config.toml @@ -0,0 +1,3 @@ +[unstable] +build-std =3D ["core", "compiler_builtins", "alloc"] +build-std-features =3D ["compiler-builtins-mem"] diff --git a/RustPkg/Test/TestRustLangLib/src/lib.rs b/RustPkg/Test/TestRus= tLangLib/src/lib.rs index ee3a0d7cc8..888733232b 100644 --- a/RustPkg/Test/TestRustLangLib/src/lib.rs +++ b/RustPkg/Test/TestRustLangLib/src/lib.rs @@ -14,24 +14,22 @@ #![feature(alloc_layout_extra)] #![feature(allocator_api)] -#![feature(core_panic_info)] - +#![feature(slice_ptr_get)] #![cfg_attr(not(test), no_std)] - #![allow(unused)] mod mem; use r_efi::efi; -use r_efi::efi::{Status}; +use r_efi::efi::Status; -extern { -=C2=A0 fn AllocatePool (Size: usize) -> *mut c_void; -=C2=A0 fn FreePool (Buffer: *mut c_void); +extern "C" { +=C2=A0=C2=A0=C2=A0 fn AllocatePool(Size: usize) -> *mut c_void; +=C2=A0=C2=A0=C2=A0 fn FreePool(Buffer: *mut c_void); } -use core::panic::PanicInfo; use core::ffi::c_void; +use core::panic::PanicInfo; use core::mem::size_of; use core::mem::transmute; @@ -40,30 +38,22 @@ use core::slice; use core::slice::from_raw_parts; use core::slice::from_raw_parts_mut; -extern crate uefi_rust_panic_lib; extern crate uefi_rust_allocation_lib; +extern crate uefi_rust_panic_lib; extern crate alloc; -use alloc::vec::Vec; +use alloc::alloc::{handle_alloc_error, Allocator, Global, Layout}; use alloc::boxed::Box; -use alloc::{ -=C2=A0=C2=A0=C2=A0 alloc::{handle_alloc_error, Alloc, Global, Layout}, -}; - +use alloc::vec::Vec; #[no_mangle] #[export_name =3D "TestIntegerOverflow"] -pub extern fn test_integer_overflow ( -=C2=A0=C2=A0=C2=A0 buffer_size: usize, -=C2=A0=C2=A0=C2=A0 width : u32, -=C2=A0=C2=A0=C2=A0 height : u32, -=C2=A0=C2=A0=C2=A0 ) -> Status -{ +pub extern "C" fn test_integer_overflow(buffer_size: usize, width: u32, he= ight: u32) -> Status { let data_size =3D width * height * 4; if data_size as usize > buffer_size { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return Status::UNSUPPORTED; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return Status::UNSUPPORTED; } Status::SUCCESS @@ -71,26 +61,24 @@ pub extern fn test_integer_overflow ( #[no_mangle] #[export_name =3D "TestIntegerCheckedOverflow"] -pub extern fn test_integer_checked_overflow ( +pub extern "C" fn test_integer_checked_overflow( buffer_size: usize, -=C2=A0=C2=A0=C2=A0 width : u32, -=C2=A0=C2=A0=C2=A0 height : u32, -=C2=A0=C2=A0=C2=A0 ) -> Status -{ - +=C2=A0=C2=A0=C2=A0 width: u32, +=C2=A0=C2=A0=C2=A0 height: u32, +) -> Status { let mut data_size: u32 =3D 0; match width.checked_mul(height) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(size) =3D> {data_size =3D size}, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> {return Status::INVALID_PARAMETER= }, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(size) =3D> data_size =3D s= ize, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> return Status::INVALI= D_PARAMETER, } match data_size.checked_mul(4) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(size) =3D> {data_size =3D size}, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> {return Status::INVALID_PARAMETER= }, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(size) =3D> data_size =3D s= ize, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> return Status::INVALI= D_PARAMETER, } if data_size as usize > buffer_size { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return Status::UNSUPPORTED; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return Status::UNSUPPORTED; } Status::SUCCESS @@ -98,31 +86,27 @@ pub extern fn test_integer_checked_overflow ( #[no_mangle] #[export_name =3D "TestIntegerCast"] -pub extern fn test_integer_cast ( -=C2=A0=C2=A0=C2=A0 buffer_size: u64, -=C2=A0=C2=A0=C2=A0 ) -> u32 -{ -=C2=A0=C2=A0=C2=A0 let data_size : u32 =3D buffer_size as u32; +pub extern "C" fn test_integer_cast(buffer_size: u64) -> u32 { +=C2=A0=C2=A0=C2=A0 let data_size: u32 =3D buffer_size as u32; data_size } -extern { -=C2=A0 fn ExternInit(Data: *mut usize); +extern "C" { +=C2=A0=C2=A0=C2=A0 fn ExternInit(Data: *mut usize); } #[no_mangle] #[export_name =3D "TestUninitializedVariable"] -pub extern fn test_uninitializd_variable ( -=C2=A0=C2=A0=C2=A0 index: usize, -=C2=A0=C2=A0=C2=A0 ) -> usize -{ -=C2=A0=C2=A0=C2=A0 let mut data : usize =3D 1; +pub extern "C" fn test_uninitializd_variable(index: usize) -> usize { +=C2=A0=C2=A0=C2=A0 let mut data: usize =3D 1; if index > 10 { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D 0; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D 0; } -=C2=A0=C2=A0=C2=A0 unsafe { ExternInit (&mut data ); } +=C2=A0=C2=A0=C2=A0 unsafe { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ExternInit(&mut data); +=C2=A0=C2=A0=C2=A0 } data =3D data + 1; @@ -131,11 +115,8 @@ pub extern fn test_uninitializd_variable ( #[no_mangle] #[export_name =3D "TestArrayOutOfRange"] -pub extern fn test_array_out_of_range ( -=C2=A0=C2=A0=C2=A0 index: usize, -=C2=A0=C2=A0=C2=A0 ) -> usize -{ -=C2=A0=C2=A0=C2=A0 let mut data : [u8; 8] =3D [0; 8]; +pub extern "C" fn test_array_out_of_range(index: usize) -> usize { +=C2=A0=C2=A0=C2=A0 let mut data: [u8; 8] =3D [0; 8]; data[index] =3D 1; @@ -152,18 +133,21 @@ pub struct TestTable { #[no_mangle] #[export_name =3D "TestBufferOverflow"] -pub extern fn test_buffer_overflow ( +pub extern "C" fn test_buffer_overflow( buffer: &mut [u8; 0], buffer_size: usize, table: &TestTable, table_size: usize, -=C2=A0=C2=A0=C2=A0 ) -{ -=C2=A0=C2=A0=C2=A0 let mut dest =3D crate::mem::MemoryRegion::new(buffer a= s *mut [u8; 0] as usize as u64, buffer_size as u64); -=C2=A0=C2=A0=C2=A0 let mut source =3D crate::mem::MemoryRegion::new(&table= .value as *const [u8; 0] as usize as u64, table_size as u64); - -=C2=A0=C2=A0=C2=A0 for index in 0_u64 .. table.length as u64 { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dest.write_u8(index, source.read_u8(index)); +) { +=C2=A0=C2=A0=C2=A0 let mut dest =3D +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 crate::mem::MemoryRegion::new(b= uffer as *mut [u8; 0] as usize as u64, buffer_size as u64); +=C2=A0=C2=A0=C2=A0 let mut source =3D crate::mem::MemoryRegion::new( +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &table.value as *const [u8; 0] = as usize as u64, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 table_size as u64, +=C2=A0=C2=A0=C2=A0 ); + +=C2=A0=C2=A0=C2=A0 for index in 0_u64..table.length as u64 { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dest.write_u8(index, source.rea= d_u8(index)); } } @@ -177,59 +161,49 @@ pub struct TestTableFixed { #[no_mangle] #[export_name =3D "TestBufferOverflowFixed"] -pub extern fn test_buffer_overflow_fixed ( -=C2=A0=C2=A0=C2=A0 buffer: &mut [u8; 32], -=C2=A0=C2=A0=C2=A0 table: &TestTableFixed, -=C2=A0=C2=A0=C2=A0 ) -{ -=C2=A0=C2=A0=C2=A0 (*buffer)[0_usize..(table.length as usize)].copy_from_s= lice( -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &table.value[0_usize..(table.length as usiz= e)] -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ); +pub extern "C" fn test_buffer_overflow_fixed(buffer: &mut [u8; 32], table:= &TestTableFixed) { +=C2=A0=C2=A0=C2=A0 (*buffer)[0_usize..(table.length as usize)] +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .copy_from_slice(&table.value[0= _usize..(table.length as usize)]); } -fn get_buffer<'a> () -> Option<&'a mut TestTableFixed> -{ -=C2=A0=C2=A0=C2=A0 let ptr : *mut c_void =3D unsafe { AllocatePool (size_o= f::()) }; +fn get_buffer<'a>() -> Option<&'a mut TestTableFixed> { +=C2=A0=C2=A0=C2=A0 let ptr: *mut c_void =3D unsafe { AllocatePool(size_of:= :()) }; if ptr.is_null() { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return None; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return None; } -=C2=A0=C2=A0=C2=A0 let buffer : &mut TestTableFixed =3D unsafe { core::mem= ::transmute::<*mut c_void, &mut TestTableFixed>(ptr) }; +=C2=A0=C2=A0=C2=A0 let buffer: &mut TestTableFixed =3D +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsafe { core::mem::transmute::= <*mut c_void, &mut TestTableFixed>(ptr) }; Some(buffer) } -fn release_buffer (test_table : &mut TestTableFixed) -{ -=C2=A0 test_table.r#type =3D 0; -=C2=A0 unsafe { FreePool (test_table as *mut TestTableFixed as *mut c_void= ) ; } +fn release_buffer(test_table: &mut TestTableFixed) { +=C2=A0=C2=A0=C2=A0 test_table.r#type =3D 0; +=C2=A0=C2=A0=C2=A0 unsafe { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 FreePool(test_table as *mut Tes= tTableFixed as *mut c_void); +=C2=A0=C2=A0=C2=A0 } } #[no_mangle] #[export_name =3D "TestBufferDrop"] -pub extern fn test_buffer_drop ( - -=C2=A0=C2=A0=C2=A0 ) -{ -=C2=A0=C2=A0=C2=A0 match get_buffer () { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(buffer) =3D> { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 buffer.r#type =3D 1; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 release_buffer(buffer); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 drop (buffer); // This is requi= red. -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 //buffer.r#type =3D 1; // error -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> {}, +pub extern "C" fn test_buffer_drop() { +=C2=A0=C2=A0=C2=A0 match get_buffer() { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Some(buffer) =3D> { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 buffer.= r#type =3D 1; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 release= _buffer(buffer); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 drop(bu= ffer); // This is required. +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 //buffer.r#type =3D 1; // error +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 None =3D> {} } } #[no_mangle] #[export_name =3D "TestBufferBorrow"] -pub extern fn test_buffer_borrow ( -=C2=A0=C2=A0=C2=A0 test_table : &mut TestTableFixed -=C2=A0=C2=A0=C2=A0 ) -{ -=C2=A0=C2=A0=C2=A0 let test_table2 : &mut TestTableFixed =3D test_table; +pub extern "C" fn test_buffer_borrow(test_table: &mut TestTableFixed) { +=C2=A0=C2=A0=C2=A0 let test_table2: &mut TestTableFixed =3D test_table; test_table2.r#type =3D 1; -=C2=A0=C2=A0=C2=A0 let test_table3 : &mut [u8; 64] =3D &mut test_table.val= ue; +=C2=A0=C2=A0=C2=A0 let test_table3: &mut [u8; 64] =3D &mut test_table.valu= e; test_table3[63] =3D 0; //test_table2.r#type =3D 2; // error @@ -237,44 +211,38 @@ pub extern fn test_buffer_borrow ( #[no_mangle] #[export_name =3D "TestBufferAlloc"] -pub extern fn test_buffer_alloc ( - -=C2=A0=C2=A0=C2=A0 ) -{ +pub extern "C" fn test_buffer_alloc() { let layout =3D unsafe { core::alloc::Layout::from_size_align_unchecked(32, = 4) }; unsafe { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.alloc (layout) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(buffer) =3D> { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let mut box_buffer = =3D Box::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size())); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 box_buffer[0] =3D 1; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Global.dealloc (buf= fer, layout); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 drop (buffer); // I= t is useless -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 box_buffer[0] =3D 1= ; // cannot catch -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) =3D> handle_alloc_error = (layout), -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.allocate(layout) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(mut = buffer) =3D> { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 let mut box_buffer =3D Box::from_raw(buffer.as_mut()); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 box_buffer[0] =3D 1; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Global.deallocate(buffer.as_non_null_ptr(), layout); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 drop(buffer); // It is useless +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 box_buffer[0] =3D 1; // cannot catch +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) = =3D> handle_alloc_error(layout), +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } } let layout =3D core::alloc::Layout::new::(); unsafe { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.alloc (layout) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(buffer) =3D> { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Global.dealloc (buf= fer, layout); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) =3D> handle_alloc_error = (layout), -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.allocate(layout) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(buff= er) =3D> { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Global.deallocate(buffer.as_non_null_ptr(), layout); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) = =3D> handle_alloc_error(layout), +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } } } -fn get_box ( -=C2=A0=C2=A0=C2=A0 r#type: u32 -=C2=A0=C2=A0=C2=A0 ) -> Box -{ -=C2=A0=C2=A0=C2=A0 let mut a =3D Box::new(TestTableFixed{ -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 r#type: 0, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 length: size_o= f::() as u32, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 value: [0; 64] -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }); // it will= call __rust_alloc(). +fn get_box(r#type: u32) -> Box { +=C2=A0=C2=A0=C2=A0 let mut a =3D Box::new(TestTableFixed { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 r#type: 0, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 length: size_of::() as u32, +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 value: [0; 64], +=C2=A0=C2=A0=C2=A0 }); // it will call __rust_alloc(). a.r#type =3D r#type; a @@ -282,35 +250,26 @@ fn get_box ( #[no_mangle] #[export_name =3D "TestBoxAlloc"] -pub extern fn test_box_alloc ( -=C2=A0=C2=A0=C2=A0 r#type: u32 -=C2=A0=C2=A0=C2=A0 ) -> Box -{ -=C2=A0 let mut a =3D get_box(1); +pub extern "C" fn test_box_alloc(r#type: u32) -> Box { +=C2=A0=C2=A0=C2=A0 let mut a =3D get_box(1); -=C2=A0 a.r#type =3D r#type; +=C2=A0=C2=A0=C2=A0 a.r#type =3D r#type; -=C2=A0 //test_box_free(a); // build fail. +=C2=A0=C2=A0=C2=A0 //test_box_free(a); // build fail. -=C2=A0 let b =3D a; -=C2=A0 b +=C2=A0=C2=A0=C2=A0 let b =3D a; +=C2=A0=C2=A0=C2=A0 b } #[no_mangle] #[export_name =3D "TestBoxFree"] -pub extern fn test_box_free ( -=C2=A0=C2=A0=C2=A0 buffer: Box -=C2=A0=C2=A0=C2=A0 ) -{ -=C2=A0 // it will call __rust_dealloc() +pub extern "C" fn test_box_free(buffer: Box) { +=C2=A0=C2=A0=C2=A0 // it will call __rust_dealloc() } #[no_mangle] #[export_name =3D "TestBoxAllocFail"] -pub extern fn test_box_alloc_fail ( -=C2=A0=C2=A0=C2=A0 size: u32 -=C2=A0=C2=A0=C2=A0 ) -> Box<[u8; 0x800]> -{ +pub extern "C" fn test_box_alloc_fail(size: u32) -> Box<[u8; 0x800]> { let mut a =3D Box::new([0_u8; 0x800]); // it will call __rust_alloc(). a @@ -318,22 +277,17 @@ pub extern fn test_box_alloc_fail ( #[no_mangle] #[export_name =3D "TestBoxConvert"] -pub extern fn test_box_convert ( -=C2=A0=C2=A0=C2=A0 size: usize -=C2=A0=C2=A0=C2=A0 ) -> *mut u8 -{ +pub extern "C" fn test_box_convert(size: usize) -> *mut u8 { let layout =3D unsafe { core::alloc::Layout::from_size_align_unchecked(size= , 4) }; unsafe { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.alloc (layout) { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(buffer) =3D> { -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let mut box_buffer = =3D Box::::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size()) = as *mut [u8] as *mut u8 ); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Global.dealloc (buf= fer, layout); -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *box_buffer =3D 1; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Box::::into_raw= (box_buffer) -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }, -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) =3D> handle_alloc_error = (layout), -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Global.allocate(layout) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Ok(buff= er) =3D> { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 let mut box_buffer =3D Box::::from_raw(buffer.as_mut= _ptr()); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Global.deallocate(buffer.as_non_null_ptr(), layout); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 *box_buffer =3D 1; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Box::::into_raw(box_buffer) +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Err(_) = =3D> handle_alloc_error(layout), +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } } - - } -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#87667): https://edk2.groups.io/g/devel/message/87667 Mute This Topic: https://groups.io/mt/89846920/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --BgmY9sSaGfF0KPi3bVic Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Ayush Singh <ayushdevel1325@gmail.com>

Hello everyon= e,

I am Ayush Singh, an applicant for for GSoC 2022. My Introduc= tion can be found here.

To get myself acqua= inted with the project, I was trying to build the Rust tests in edkii-rust = branch in edk2-staging and found out that due to changes in the Rust Alloca= tor API, Test/TestRustLangLib and Test/RustLangApp= fail to build. Also, cargo now supports cross-compiling sysroot (= build-std feature) so the= re is no need for cargo-xbuild.

I have tried to fix
Test/TestRustLangLib an= d would like someone to review if it is correct. Here is the diff:
diff --git a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs b/RustPkg/= Library/UefiRustAllocationLib/src/lib.rs
index f369e1bb17..6a65f0a5f9 = 100644
--- a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs
+++= b/RustPkg/Library/UefiRustAllocationLib/src/lib.rs
@@ -15,44 +15,42 @= @
 #![feature(alloc_layout_extra)]
 #![feature(allocat= or_api)]
 #![feature(alloc_error_handler)]
-
 #= ![cfg_attr(not(test), no_std)]
-
 #![allow(unused)]
=  
 extern crate uefi_rust_panic_lib;
 
-us= e core::alloc::{GlobalAlloc, Layout, Alloc};
-use r_efi::efi;
-= use r_efi::efi::{Status};
+use core::alloc::{GlobalAlloc, Layout};  use core::ffi::c_void;
+use r_efi::efi;
+use r_efi::e= fi::Status;
 
 pub struct MyAllocator;
  <= br />-static mut ST : *mut efi::SystemTable =3D core::ptr::null_mut();
-static mut BS : *mut efi::BootServices =3D core::ptr::null_mut();
= +static mut ST: *mut efi::SystemTable =3D core::ptr::null_mut();
+sta= tic mut BS: *mut efi::BootServices =3D core::ptr::null_mut();
  =
 unsafe impl GlobalAlloc for MyAllocator {
  &nb= sp;  unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
= -      let size =3D layout.size();
- &n= bsp;    let align =3D layout.align();
-  &nb= sp;   if align > 8 {
-     &nbs= p;  return core::ptr::null_mut();
-     = ; }
+        let size =3D layout.s= ize();
+        let align =3D layo= ut.align();
+        if align >= 8 {
+          &nb= sp; return core::ptr::null_mut();
+     &nbs= p;  }
 
-      let mut addre= ss : *mut c_void =3D core::ptr::null_mut();
-    =   let status =3D ((*BS).allocate_pool) (
-   &nbs= p;            &= nbsp;    efi::MemoryType::BootServicesData,
- &nb= sp;            =        size,
-    &= nbsp;           &nbs= p;    &mut address as *mut *mut c_void
- &nbs= p;            &= nbsp;      );
-     = ; if status !=3D Status::SUCCESS {
-     &nb= sp;  return core::ptr::null_mut();
-    &nbs= p; }
-      address as *mut u8
+ =        let mut address: *mut c_void =3D core:= :ptr::null_mut();
+        let sta= tus =3D ((*BS).allocate_pool)(
+      &= nbsp;     efi::MemoryType::BootServicesData,
+&nb= sp;           size,
+            &m= ut address as *mut *mut c_void,
+      =   );
+        if status !=3D = Status::SUCCESS {
+        &n= bsp;   return core::ptr::null_mut();
+   &nb= sp;    }
+        a= ddress as *mut u8
     }
   =   unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
= -      ((*BS).free_pool) (ptr as *mut c_void); +        ((*BS).free_pool)(ptr as *mu= t c_void);
     }
 }
 
@@ -60,14 +58,13 @@ unsafe impl GlobalAlloc for MyAllocator {
 = static ALLOCATOR: MyAllocator =3D MyAllocator;
 
 #[a= lloc_error_handler]
-fn alloc_error_handler(layout: core::alloc::Layo= ut) -> !
-{
+fn alloc_error_handler(layout: core::alloc::Lay= out) -> ! {
     loop {}
 }
&= nbsp;
-pub extern fn init(system_table: *mut efi::SystemTable) {
+pub extern "C" fn init(system_table: *mut efi::SystemTable) {
&nbs= p;    unsafe {
-      ST =3D = system_table;
-      BS =3D (*ST).boot_servi= ces;
+        ST =3D system_table;=
+        BS =3D (*ST).boot_servic= es;
     }
 }
diff --git a/RustP= kg/Test/HelloWorld/.cargo/config.toml b/RustPkg/Test/HelloWorld/.cargo/conf= ig.toml
new file mode 100644
index 0000000000..3d6a3ff35c
--= - /dev/null
+++ b/RustPkg/Test/HelloWorld/.cargo/config.toml
@@ -= 0,0 +1,3 @@
+[unstable]
+build-std =3D ["core", "compiler_builtin= s"]
+build-std-features =3D ["compiler-builtins-mem"]
diff --git = a/RustPkg/Test/HelloWorld2/.cargo/config.toml b/RustPkg/Test/HelloWorld2/.c= argo/config.toml
new file mode 100644
index 0000000000..3d6a3ff35= c
--- /dev/null
+++ b/RustPkg/Test/HelloWorld2/.cargo/config.toml=
@@ -0,0 +1,3 @@
+[unstable]
+build-std =3D ["core", "compil= er_builtins"]
+build-std-features =3D ["compiler-builtins-mem"]
d= iff --git a/RustPkg/Test/TestRustLangLib/.cargo/config.toml b/RustPkg/Test/= TestRustLangLib/.cargo/config.toml
new file mode 100644
index 000= 0000000..422bf9d2ab
--- /dev/null
+++ b/RustPkg/Test/TestRustLang= Lib/.cargo/config.toml
@@ -0,0 +1,3 @@
+[unstable]
+build-st= d =3D ["core", "compiler_builtins", "alloc"]
+build-std-features =3D [= "compiler-builtins-mem"]
diff --git a/RustPkg/Test/TestRustLangLib/src= /lib.rs b/RustPkg/Test/TestRustLangLib/src/lib.rs
index ee3a0d7cc8..88= 8733232b 100644
--- a/RustPkg/Test/TestRustLangLib/src/lib.rs
+++= b/RustPkg/Test/TestRustLangLib/src/lib.rs
@@ -14,24 +14,22 @@
&n= bsp;
 #![feature(alloc_layout_extra)]
 #![feature(all= ocator_api)]
-#![feature(core_panic_info)]
-
+#![feature(= slice_ptr_get)]
 #![cfg_attr(not(test), no_std)]
-
&= nbsp;#![allow(unused)]
 
 mod mem;
 
 use r_efi::efi;
-use r_efi::efi::{Status};
+use r_efi::e= fi::Status;
 
-extern {
-  fn AllocatePool (Siz= e: usize) -> *mut c_void;
-  fn FreePool (Buffer: *mut c_void= );
+extern "C" {
+    fn AllocatePool(Size: usiz= e) -> *mut c_void;
+    fn FreePool(Buffer: *mut c_= void);
 }
 
-use core::panic::PanicInfo;
=  use core::ffi::c_void;
+use core::panic::PanicInfo;
 = ;
 use core::mem::size_of;
 use core::mem::transmute;=
@@ -40,30 +38,22 @@ use core::slice;
 use core::slice::fro= m_raw_parts;
 use core::slice::from_raw_parts_mut;
  =
-extern crate uefi_rust_panic_lib;
 extern crate uefi_rust= _allocation_lib;
+extern crate uefi_rust_panic_lib;
 
 extern crate alloc;
 
-use alloc::vec::Vec;
= +use alloc::alloc::{handle_alloc_error, Allocator, Global, Layout};
&= nbsp;use alloc::boxed::Box;
-use alloc::{
-    a= lloc::{handle_alloc_error, Alloc, Global, Layout},
-};
-
= +use alloc::vec::Vec;
 
 #[no_mangle]
 #[e= xport_name =3D "TestIntegerOverflow"]
-pub extern fn test_integer_ove= rflow (
-    buffer_size: usize,
-  &n= bsp; width : u32,
-    height : u32,
- &nbs= p;  ) -> Status
-{
+pub extern "C" fn test_integer_over= flow(buffer_size: usize, width: u32, height: u32) -> Status {
&nbs= p;    let data_size =3D width * height * 4;
       if data_size as usize > buffer_size {
= -      return Status::UNSUPPORTED;
+ &n= bsp;      return Status::UNSUPPORTED;
 =     }
 
     Status::SU= CCESS
@@ -71,26 +61,24 @@ pub extern fn test_integer_overflow (
=  
 #[no_mangle]
 #[export_name =3D "TestIntegerC= heckedOverflow"]
-pub extern fn test_integer_checked_overflow (
+pub extern "C" fn test_integer_checked_overflow(
   =   buffer_size: usize,
-    width : u32,
-&n= bsp;   height : u32,
-    ) -> Status -{
-
+    width: u32,
+  &nbs= p; height: u32,
+) -> Status {
     let = mut data_size: u32 =3D 0;
 
     match= width.checked_mul(height) {
-      Some(siz= e) =3D> {data_size =3D size},
-      None= =3D> {return Status::INVALID_PARAMETER},
+    = ;    Some(size) =3D> data_size =3D size,
+ &nb= sp;      None =3D> return Status::INVALID_PARAM= ETER,
     }
     match= data_size.checked_mul(4) {
-      Some(size= ) =3D> {data_size =3D size},
-      None = =3D> {return Status::INVALID_PARAMETER},
+    =     Some(size) =3D> data_size =3D size,
+ &nbs= p;      None =3D> return Status::INVALID_PARAME= TER,
     }
 
   =   if data_size as usize > buffer_size {
-   &n= bsp;  return Status::UNSUPPORTED;
+     = ;   return Status::UNSUPPORTED;
     } =
 
     Status::SUCCESS
@@ -98,31= +86,27 @@ pub extern fn test_integer_checked_overflow (
 
=  #[no_mangle]
 #[export_name =3D "TestIntegerCast"]
-= pub extern fn test_integer_cast (
-    buffer_size: u6= 4,
-    ) -> u32
-{
-   = let data_size : u32 =3D buffer_size as u32;
+pub extern "C" fn test_= integer_cast(buffer_size: u64) -> u32 {
+    let da= ta_size: u32 =3D buffer_size as u32;
     data_si= ze
 }
 
-extern {
-  fn ExternInit(D= ata: *mut usize);
+extern "C" {
+    fn ExternIn= it(Data: *mut usize);
 }
 
 #[no_mangle] <= br /> #[export_name =3D "TestUninitializedVariable"]
-pub extern= fn test_uninitializd_variable (
-    index: usize, -    ) -> usize
-{
-    le= t mut data : usize =3D 1;
+pub extern "C" fn test_uninitializd_variab= le(index: usize) -> usize {
+    let mut data: usiz= e =3D 1;
 
     if index > 10 { -      data =3D 0;
+   &nb= sp;    data =3D 0;
     }
&n= bsp;
-    unsafe { ExternInit (&mut data ); }
+    unsafe {
+      &= nbsp; ExternInit(&mut data);
+    }
  <= br />     data =3D data + 1;
 
@@ -131= ,11 +115,8 @@ pub extern fn test_uninitializd_variable (
 
=  #[no_mangle]
 #[export_name =3D "TestArrayOutOfRange"] -pub extern fn test_array_out_of_range (
-    index= : usize,
-    ) -> usize
-{
- &nbs= p;  let mut data : [u8; 8] =3D [0; 8];
+pub extern "C" fn test_a= rray_out_of_range(index: usize) -> usize {
+    let= mut data: [u8; 8] =3D [0; 8];
 
     = data[index] =3D 1;
 
@@ -152,18 +133,21 @@ pub struct Test= Table {
 
 #[no_mangle]
 #[export_name =3D = "TestBufferOverflow"]
-pub extern fn test_buffer_overflow (
+pu= b extern "C" fn test_buffer_overflow(
     buffer= : &mut [u8; 0],
     buffer_size: usize,
     table: &TestTable,
   &= nbsp; table_size: usize,
-    )
-{
- =    let mut dest =3D crate::mem::MemoryRegion::new(buffer as *mut = [u8; 0] as usize as u64, buffer_size as u64);
-    let= mut source =3D crate::mem::MemoryRegion::new(&table.value as *const [u= 8; 0] as usize as u64, table_size as u64);
-
-   = ; for index in 0_u64 .. table.length as u64 {
-   &nbs= p;  dest.write_u8(index, source.read_u8(index));
+) {
+&nb= sp;   let mut dest =3D
+      = ;  crate::mem::MemoryRegion::new(buffer as *mut [u8; 0] as usize as u6= 4, buffer_size as u64);
+    let mut source =3D crate:= :mem::MemoryRegion::new(
+        = &table.value as *const [u8; 0] as usize as u64,
+  &nbs= p;     table_size as u64,
+    ); =
+
+    for index in 0_u64..table.length as u64 {=
+        dest.write_u8(index, sou= rce.read_u8(index));
     }
 }
&= nbsp;
@@ -177,59 +161,49 @@ pub struct TestTableFixed {
  <= br /> #[no_mangle]
 #[export_name =3D "TestBufferOverflowFi= xed"]
-pub extern fn test_buffer_overflow_fixed (
-  =   buffer: &mut [u8; 32],
-    table: &Tes= tTableFixed,
-    )
-{
-   = (*buffer)[0_usize..(table.length as usize)].copy_from_slice(
- =      &table.value[0_usize..(table.length as usize)]=
-      );
+pub extern "C" fn test_buf= fer_overflow_fixed(buffer: &mut [u8; 32], table: &TestTableFixed) {=
+    (*buffer)[0_usize..(table.length as usize)]
+        .copy_from_slice(&table.v= alue[0_usize..(table.length as usize)]);
 }
 
-= fn get_buffer<'a> () -> Option<&'a mut TestTableFixed> <= br />-{
-    let ptr : *mut c_void =3D unsafe { Alloca= tePool (size_of::<TestTableFixed>()) };
+fn get_buffer<'a>= ;() -> Option<&'a mut TestTableFixed> {
+  &nb= sp; let ptr: *mut c_void =3D unsafe { AllocatePool(size_of::<TestTableFi= xed>()) };
     if ptr.is_null() {
-&nbs= p;     return None;
+    &nbs= p;   return None;
     }
- &= nbsp;  let buffer : &mut TestTableFixed =3D unsafe { core::mem::tr= ansmute::<*mut c_void, &mut TestTableFixed>(ptr) };
+ =    let buffer: &mut TestTableFixed =3D
+  &nb= sp;     unsafe { core::mem::transmute::<*mut c_void,= &mut TestTableFixed>(ptr) };
     Some(bu= ffer)
 }
 
-fn release_buffer (test_table : &am= p;mut TestTableFixed)
-{
-  test_table.r#type =3D 0;
-  unsafe { FreePool (test_table as *mut TestTableFixed as *mut c_voi= d) ; }
+fn release_buffer(test_table: &mut TestTableFixed) {
+    test_table.r#type =3D 0;
+    un= safe {
+        FreePool(test_tabl= e as *mut TestTableFixed as *mut c_void);
+    }
 }
 
 #[no_mangle]
 #[export_name = =3D "TestBufferDrop"]
-pub extern fn test_buffer_drop (
- =     
-    )
-{
-  =   match get_buffer () {
-      Some(buf= fer) =3D> {
-        buffer.r#t= ype =3D 1;
-        release_buffer= (buffer);
-        drop (buffer); = // This is required.
-        //bu= ffer.r#type =3D 1; // error
-      },
= -      None =3D> {},
+pub extern "C" fn t= est_buffer_drop() {
+    match get_buffer() {
+&= nbsp;       Some(buffer) =3D> {
+&nb= sp;           buffer.r#ty= pe =3D 1;
+         &nbs= p;  release_buffer(buffer);
+      = ;      drop(buffer); // This is required.
+&= nbsp;           &nbs= p;             = //buffer.r#type =3D 1; // error
+      =   }
+        None =3D> {} =
     }
 }
 
 #[n= o_mangle]
 #[export_name =3D "TestBufferBorrow"]
-pub exte= rn fn test_buffer_borrow (
-    test_table : &mut = TestTableFixed
-    )
-{
-  &nbs= p; let test_table2 : &mut TestTableFixed =3D test_table;
+pub ext= ern "C" fn test_buffer_borrow(test_table: &mut TestTableFixed) {
= +    let test_table2: &mut TestTableFixed =3D test_table= ;
     test_table2.r#type =3D 1;
  -    let test_table3 : &mut [u8; 64] =3D &mut tes= t_table.value;
+    let test_table3: &mut [u8; 64]= =3D &mut test_table.value;
     test_table3[= 63] =3D 0;
 
     //test_table2.r#type= =3D 2; // error
@@ -237,44 +211,38 @@ pub extern fn test_buffer_borr= ow (
 
 #[no_mangle]
 #[export_name =3D "Te= stBufferAlloc"]
-pub extern fn test_buffer_alloc (
-  = ;   
-    )
-{
+pub extern "C" fn= test_buffer_alloc() {
     let layout =3D unsafe= { core::alloc::Layout::from_size_align_unchecked(32, 4) };
 &nb= sp;   unsafe {
-      match Global= .alloc (layout) {
-        Ok(buff= er) =3D> {
-         = let mut box_buffer =3D Box::from_raw(from_raw_parts_mut(buffer.as_ptr(), l= ayout.size()));
-        &nbs= p; box_buffer[0] =3D 1;
-       &n= bsp;  Global.dealloc (buffer, layout);
-    =       drop (buffer); // It is useless
- = ;         box_buffer[0] =3D 1; // c= annot catch
-        },
-&nb= sp;       Err(_) =3D> handle_alloc_error (= layout),
-      }
+   &= nbsp;    match Global.allocate(layout) {
+  =           Ok(mut buffer) =3D&g= t; {
+          &nb= sp;     let mut box_buffer =3D Box::from_raw(buffer.as_= mut());
+          =       box_buffer[0] =3D 1;
+  &nbs= p;             = Global.deallocate(buffer.as_non_null_ptr(), layout);
+  &nb= sp;            = drop(buffer); // It is useless
+      =           box_buffer[0] =3D 1;= // cannot catch
+        &nb= sp;   }
+        &n= bsp;   Err(_) =3D> handle_alloc_error(layout),
+ &n= bsp;      }
     }
 
     let layout =3D core::alloc::Layout::= new::<u32>();
     unsafe {
- &n= bsp;    match Global.alloc (layout) {
-  &nb= sp;     Ok(buffer) =3D> {
-   &= nbsp;      Global.dealloc (buffer, layout);
= -        },
-   &nb= sp;    Err(_) =3D> handle_alloc_error (layout),
-&n= bsp;     }
+      &= nbsp; match Global.allocate(layout) {
+     =        Ok(buffer) =3D> {
+ &nbs= p;            &= nbsp; Global.deallocate(buffer.as_non_null_ptr(), layout);
+ &nb= sp;          }
+ &n= bsp;          Err(_) =3D> h= andle_alloc_error(layout),
+       = ; }
     }
 }
 
-fn g= et_box (
-    r#type: u32
-    ) = -> Box<TestTableFixed>
-{
-    let mut = a =3D Box::new(TestTableFixed{
-      &= nbsp;           &nbs= p;    r#type: 0,
-      =             &nb= sp;    length: size_of::<TestTableFixed>() as u32, -            = ;           value: [0; 64= ]
-           =             }); // i= t will call __rust_alloc().
+fn get_box(r#type: u32) -> Box<Tes= tTableFixed> {
+    let mut a =3D Box::new(TestTabl= eFixed {
+        r#type: 0,
+        length: size_of::<TestTable= Fixed>() as u32,
+        value= : [0; 64],
+    }); // it will call __rust_alloc().      a.r#type =3D r#type;
 
 =     a
@@ -282,35 +250,26 @@ fn get_box (
  <= br /> #[no_mangle]
 #[export_name =3D "TestBoxAlloc"]
-pub extern fn test_box_alloc (
-    r#type: u32
-    ) -> Box<TestTableFixed>
-{
-&nb= sp; let mut a =3D get_box(1);
+pub extern "C" fn test_box_alloc(r#typ= e: u32) -> Box<TestTableFixed> {
+    let mut= a =3D get_box(1);
 
-  a.r#type =3D r#type;
+&= nbsp;   a.r#type =3D r#type;
 
-  //test_bo= x_free(a); // build fail.
+    //test_box_free(a); // = build fail.
 
-  let b =3D a;
-  b
+=     let b =3D a;
+    b
 } <= br /> 
 #[no_mangle]
 #[export_name =3D "TestBox= Free"]
-pub extern fn test_box_free (
-    buffe= r: Box<TestTableFixed>
-    )
-{
-&n= bsp; // it will call __rust_dealloc()
+pub extern "C" fn test_box_fre= e(buffer: Box<TestTableFixed>) {
+    // it will= call __rust_dealloc()
 }
 
 #[no_mangle] =
 #[export_name =3D "TestBoxAllocFail"]
-pub extern fn test= _box_alloc_fail (
-    size: u32
-  &n= bsp; ) -> Box<[u8; 0x800]>
-{
+pub extern "C" fn test_= box_alloc_fail(size: u32) -> Box<[u8; 0x800]> {
  =    let mut a =3D Box::new([0_u8; 0x800]); // it will call __rust_= alloc().
 
     a
@@ -318,22 +27= 7,17 @@ pub extern fn test_box_alloc_fail (
 
 #[no_ma= ngle]
 #[export_name =3D "TestBoxConvert"]
-pub extern fn = test_box_convert (
-    size: usize
-  = ;  ) -> *mut u8
-{
+pub extern "C" fn test_box_convert(= size: usize) -> *mut u8 {
     let layout =3D = unsafe { core::alloc::Layout::from_size_align_unchecked(size, 4) };
&= nbsp;    unsafe {
-      matc= h Global.alloc (layout) {
-       = Ok(buffer) =3D> {
-       &nbs= p;  let mut box_buffer =3D Box::<u8>::from_raw(from_raw_parts_mu= t(buffer.as_ptr(), layout.size()) as *mut [u8] as *mut u8 );
- &= nbsp;        Global.dealloc (buffer, lay= out);
-          *box_bu= ffer =3D 1;
-          B= ox::<u8>::into_raw(box_buffer)
-     &= nbsp;  },
-        Err(_) =3D= > handle_alloc_error (layout),
-      } <= br />+        match Global.allocate(layo= ut) {
+          &n= bsp; Ok(buffer) =3D> {
+       =          let mut box_buffer =3D Box= ::<u8>::from_raw(buffer.as_mut_ptr());
+    = ;            Global.= deallocate(buffer.as_non_null_ptr(), layout);
+   &nbs= p;            *box_b= uffer =3D 1;
+         &= nbsp;      Box::<u8>::into_raw(box_buffer) <= br />+            } =
+            E= rr(_) =3D> handle_alloc_error(layout),
+    &n= bsp;   }
     }
-
-
&= nbsp;}

_._,_._,_

G= roups.io Links:

You receive all messages sent to this group.

Vi= ew/Reply Online (#87667) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [importer@patchew.org]
_._,_._,_=20 --BgmY9sSaGfF0KPi3bVic--