From nobody Wed May 15 04:21:55 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+87754+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87754+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1647673577947861.0022364398986; Sat, 19 Mar 2022 00:06:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id oz0ZYY1788612xQux0uslfkl; Sat, 19 Mar 2022 00:06:19 -0700 X-Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mx.groups.io with SMTP id smtpd.web09.4910.1647673578668796199 for ; Sat, 19 Mar 2022 00:06:18 -0700 X-Received: by mail-pj1-f49.google.com with SMTP id gb19so9104661pjb.1 for ; Sat, 19 Mar 2022 00:06:18 -0700 (PDT) X-Gm-Message-State: wn7GDxcgqycHswKlRv1HIVwzx1787277AA= X-Google-Smtp-Source: ABdhPJwGO3SqlMaVO+1qM1fff0DQEPHOB4Wbih4E/dn8K2+NWTG0kAiAeiHO7XwKEOI9Sw+a0zhAhA== X-Received: by 2002:a17:902:d645:b0:153:abad:be7d with SMTP id y5-20020a170902d64500b00153abadbe7dmr3126667plh.118.1647673577840; Sat, 19 Mar 2022 00:06:17 -0700 (PDT) X-Received: from toolbox.iitism.net ([103.15.228.66]) by smtp.gmail.com with ESMTPSA id u4-20020a056a00158400b004fa0263cf5dsm12300538pfk.130.2022.03.19.00.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 00:06:17 -0700 (PDT) From: "Ayush Singh" To: devel@edk2.groups.io Cc: Jiewen Yao Subject: [edk2-devel] [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std Date: Sat, 19 Mar 2022 12:35:51 +0530 Message-Id: <20220319070553.25770-2-ayushdevel1325@gmail.com> In-Reply-To: <20220319070553.25770-1-ayushdevel1325@gmail.com> References: <20220319070553.25770-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 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 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647673579; bh=by/th5GG+aowVrCqO0ElZK6eybg1X8bzhKWweQY8EMw=; h=Cc:Date:From:Reply-To:Subject:To; b=tPDVgd4KQa8c+0uXfDJGA+10UU8rAsP7DN8r5NyARXX1mmYQwokOTTr47JFqtjJNcAY JloPzAd8S3b3GeWM14yapemycSg/293/wFbQu85r720jjfLiaMAD9v0R+4nIG0tSxdwR6 a+WP1er3t693EM4bSKRCotcIW1Alr50foQ0= X-ZohoMail-DKIM: fail (Signature date is -2 seconds in the future.) X-ZM-MESSAGEID: 1647673605345100001 Content-Type: text/plain; charset="utf-8" From: Ayush Singh Tests Migrated: - Test/HelloWorld - Test/HelloWorld2 Cc: Jiewen Yao Signed-off-by: Ayush Singh --- RustPkg/Test/HelloWorld/.cargo/config.toml | 3 +++ RustPkg/Test/HelloWorld2/.cargo/config.toml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/RustPkg/Test/HelloWorld/.cargo/config.toml b/RustPkg/Test/Hell= oWorld/.cargo/config.toml new file mode 100644 index 000000000000..3d6a3ff35cd7 --- /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 000000000000..3d6a3ff35cd7 --- /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"] --=20 2.35.1 -=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 (#87754): https://edk2.groups.io/g/devel/message/87754 Mute This Topic: https://groups.io/mt/89884784/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- From nobody Wed May 15 04:21:55 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+87755+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+87755+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1647673582; cv=none; d=zohomail.com; s=zohoarc; b=k/F8E33gngUKG176nTxVjC/AXiCB9GhBQj7vSYeD9HbQLKidD5ce2bH3yS+0zjQNnlondviyNG6uShWsm/nbc5x6Z7AuBfkn+4wyQ7dDtRFjxP7omWKWt8Qnq7E1yGF6mtS8XDx56FQ728RuGhWee7brR3eLQVsDGBJCGy/Aue8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647673582; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=qeHOifC+NF1eHxuLMY+yE7lZeYu3FFs5/SUHKk0Auig=; b=P6pnmM7vJeh7j+MP9DZQ5bsnBpYB2LbH2ycnKWEZ+Mu0diYpMOzFFyvVva0kuewoOv0whe2iJYHVN48AbQYn3kVs+354k5k4VY8hW7Dfbuv5VIwfUbOL7jS43NkAtj3gH6xutNc23byktbqx5tGJ4eQYyiBW5maF8L3fDvPfKBI= 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+87755+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 1647673582774839.0829416549199; Sat, 19 Mar 2022 00:06:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mG2UYY1788612xRhxPRjzeQr; Sat, 19 Mar 2022 00:06:22 -0700 X-Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mx.groups.io with SMTP id smtpd.web10.4758.1647673581962030176 for ; Sat, 19 Mar 2022 00:06:22 -0700 X-Received: by mail-pg1-f170.google.com with SMTP id e6so6585153pgn.2 for ; Sat, 19 Mar 2022 00:06:21 -0700 (PDT) X-Gm-Message-State: 2NAtNBuv7pYFcPd13pNrEDWGx1787277AA= X-Google-Smtp-Source: ABdhPJxjdmcaD+vEi1vzpLdHdSvAs1EYP8T4NPZJfA9iaW7GYrImpy4yrfrI1YJcsd2FW0PHitu4hg== X-Received: by 2002:aa7:88d5:0:b0:4f7:7fbd:c653 with SMTP id k21-20020aa788d5000000b004f77fbdc653mr14173531pff.41.1647673580481; Sat, 19 Mar 2022 00:06:20 -0700 (PDT) X-Received: from toolbox.iitism.net ([103.15.228.66]) by smtp.gmail.com with ESMTPSA id u4-20020a056a00158400b004fa0263cf5dsm12300538pfk.130.2022.03.19.00.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 00:06:19 -0700 (PDT) From: "Ayush Singh" To: devel@edk2.groups.io Cc: Jiewen Yao Subject: [edk2-devel] [PATCH v1 2/3] RustPkg/Test/TestRustLangLib: Fix Building Date: Sat, 19 Mar 2022 12:35:52 +0530 Message-Id: <20220319070553.25770-3-ayushdevel1325@gmail.com> In-Reply-To: <20220319070553.25770-1-ayushdevel1325@gmail.com> References: <20220319070553.25770-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 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 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647673582; bh=DF5CAav6vf1jTK4rwAn/GlGSKN3p0j0YCHNdUrvVrOI=; h=Cc:Date:From:Reply-To:Subject:To; b=xSebjv+pwcrvbhJdnJRZtQrl8SbSVG+ahD9KUD0eIxz0n0mD5XWozvIBDvdA3aDX7F7 6+zSh7Ub0nxr98Ek0fdhrA0q5YYA1hzCixx3OyYr4NeDyCm5pMFIGmlLEXuRliBXam9a+ d07fBCUww11RXu8rqMDq1KvC4abGL0ZW60I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1647673584240100001 Content-Type: text/plain; charset="utf-8" From: Ayush Singh Removed the Alloc trait usage which seems to have been removed from Rust now. Cc: Jiewen Yao Signed-off-by: Ayush Singh --- RustPkg/Library/UefiRustAllocationLib/src/lib.rs | 53 ++-- RustPkg/Test/TestRustLangLib/.cargo/config.toml | 3 + RustPkg/Test/TestRustLangLib/src/lib.rs | 264 ++++++++------------ 3 files changed, 137 insertions(+), 183 deletions(-) diff --git a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs b/RustPkg/Lib= rary/UefiRustAllocationLib/src/lib.rs index f369e1bb170b..6a65f0a5f988 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)] =20 extern crate uefi_rust_panic_lib; =20 -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; =20 pub struct MyAllocator; =20 -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(); =20 unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let size =3D layout.size(); - let align =3D layout.align(); - if align > 8 { - return core::ptr::null_mut(); - } + let size =3D layout.size(); + let align =3D layout.align(); + if align > 8 { + return core::ptr::null_mut(); + } =20 - let mut address : *mut c_void =3D core::ptr::null_mut(); - let status =3D ((*BS).allocate_pool) ( - efi::MemoryType::BootServicesData, - size, - &mut address as *mut *mut c_void - ); - if status !=3D Status::SUCCESS { - return core::ptr::null_mut(); - } - address as *mut u8 + let mut address: *mut c_void =3D core::ptr::null_mut(); + let status =3D ((*BS).allocate_pool)( + efi::MemoryType::BootServicesData, + size, + &mut address as *mut *mut c_void, + ); + if status !=3D Status::SUCCESS { + return core::ptr::null_mut(); + } + address 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 *mut c_void); } } =20 @@ -60,14 +58,13 @@ unsafe impl GlobalAlloc for MyAllocator { static ALLOCATOR: MyAllocator =3D MyAllocator; =20 #[alloc_error_handler] -fn alloc_error_handler(layout: core::alloc::Layout) -> ! -{ +fn alloc_error_handler(layout: core::alloc::Layout) -> ! { loop {} } =20 -pub extern fn init(system_table: *mut efi::SystemTable) { +pub extern "C" fn init(system_table: *mut efi::SystemTable) { unsafe { - ST =3D system_table; - BS =3D (*ST).boot_services; + ST =3D system_table; + BS =3D (*ST).boot_services; } } diff --git a/RustPkg/Test/TestRustLangLib/.cargo/config.toml b/RustPkg/Test= /TestRustLangLib/.cargo/config.toml new file mode 100644 index 000000000000..422bf9d2ab4e --- /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 ee3a0d7cc83e..888733232b71 100644 --- a/RustPkg/Test/TestRustLangLib/src/lib.rs +++ b/RustPkg/Test/TestRustLangLib/src/lib.rs @@ -14,24 +14,22 @@ =20 #![feature(alloc_layout_extra)] #![feature(allocator_api)] -#![feature(core_panic_info)] - +#![feature(slice_ptr_get)] #![cfg_attr(not(test), no_std)] - #![allow(unused)] =20 mod mem; =20 use r_efi::efi; -use r_efi::efi::{Status}; +use r_efi::efi::Status; =20 -extern { - fn AllocatePool (Size: usize) -> *mut c_void; - fn FreePool (Buffer: *mut c_void); +extern "C" { + fn AllocatePool(Size: usize) -> *mut c_void; + fn FreePool(Buffer: *mut c_void); } =20 -use core::panic::PanicInfo; use core::ffi::c_void; +use core::panic::PanicInfo; =20 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; =20 -extern crate uefi_rust_panic_lib; extern crate uefi_rust_allocation_lib; +extern crate uefi_rust_panic_lib; =20 extern crate alloc; =20 -use alloc::vec::Vec; +use alloc::alloc::{handle_alloc_error, Allocator, Global, Layout}; use alloc::boxed::Box; -use alloc::{ - alloc::{handle_alloc_error, Alloc, Global, Layout}, -}; - +use alloc::vec::Vec; =20 #[no_mangle] #[export_name =3D "TestIntegerOverflow"] -pub extern fn test_integer_overflow ( - buffer_size: usize, - width : u32, - height : u32, - ) -> Status -{ +pub extern "C" fn test_integer_overflow(buffer_size: usize, width: u32, he= ight: u32) -> Status { let data_size =3D width * height * 4; =20 if data_size as usize > buffer_size { - return Status::UNSUPPORTED; + return Status::UNSUPPORTED; } =20 Status::SUCCESS @@ -71,26 +61,24 @@ pub extern fn test_integer_overflow ( =20 #[no_mangle] #[export_name =3D "TestIntegerCheckedOverflow"] -pub extern fn test_integer_checked_overflow ( +pub extern "C" fn test_integer_checked_overflow( buffer_size: usize, - width : u32, - height : u32, - ) -> Status -{ - + width: u32, + height: u32, +) -> Status { let mut data_size: u32 =3D 0; =20 match width.checked_mul(height) { - Some(size) =3D> {data_size =3D size}, - None =3D> {return Status::INVALID_PARAMETER}, + Some(size) =3D> data_size =3D size, + None =3D> return Status::INVALID_PARAMETER, } 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, + None =3D> return Status::INVALID_PARAMETER, } =20 if data_size as usize > buffer_size { - return Status::UNSUPPORTED; + return Status::UNSUPPORTED; } =20 Status::SUCCESS @@ -98,31 +86,27 @@ pub extern fn test_integer_checked_overflow ( =20 #[no_mangle] #[export_name =3D "TestIntegerCast"] -pub extern fn test_integer_cast ( - buffer_size: u64, - ) -> u32 -{ - let data_size : u32 =3D buffer_size as u32; +pub extern "C" fn test_integer_cast(buffer_size: u64) -> u32 { + let data_size: u32 =3D buffer_size as u32; data_size } =20 -extern { - fn ExternInit(Data: *mut usize); +extern "C" { + fn ExternInit(Data: *mut usize); } =20 #[no_mangle] #[export_name =3D "TestUninitializedVariable"] -pub extern fn test_uninitializd_variable ( - index: usize, - ) -> usize -{ - let mut data : usize =3D 1; +pub extern "C" fn test_uninitializd_variable(index: usize) -> usize { + let mut data: usize =3D 1; =20 if index > 10 { - data =3D 0; + data =3D 0; } =20 - unsafe { ExternInit (&mut data ); } + unsafe { + ExternInit(&mut data); + } =20 data =3D data + 1; =20 @@ -131,11 +115,8 @@ pub extern fn test_uninitializd_variable ( =20 #[no_mangle] #[export_name =3D "TestArrayOutOfRange"] -pub extern fn test_array_out_of_range ( - index: usize, - ) -> usize -{ - let mut data : [u8; 8] =3D [0; 8]; +pub extern "C" fn test_array_out_of_range(index: usize) -> usize { + let mut data: [u8; 8] =3D [0; 8]; =20 data[index] =3D 1; =20 @@ -152,18 +133,21 @@ pub struct TestTable { =20 #[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, - ) -{ - 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 *cons= t [u8; 0] as usize as u64, table_size as u64); +) { + let mut dest =3D + crate::mem::MemoryRegion::new(buffer as *mut [u8; 0] as usize as u= 64, buffer_size as u64); + let mut source =3D crate::mem::MemoryRegion::new( + &table.value as *const [u8; 0] as usize as u64, + table_size as u64, + ); =20 - for index in 0_u64 .. table.length as u64 { - dest.write_u8(index, source.read_u8(index)); + for index in 0_u64..table.length as u64 { + dest.write_u8(index, source.read_u8(index)); } } =20 @@ -177,59 +161,49 @@ pub struct TestTableFixed { =20 #[no_mangle] #[export_name =3D "TestBufferOverflowFixed"] -pub extern fn test_buffer_overflow_fixed ( - buffer: &mut [u8; 32], - table: &TestTableFixed, - ) -{ - (*buffer)[0_usize..(table.length as usize)].copy_from_slice( - &table.value[0_usize..(table.length as usize)] - ); +pub extern "C" fn test_buffer_overflow_fixed(buffer: &mut [u8; 32], table:= &TestTableFixed) { + (*buffer)[0_usize..(table.length as usize)] + .copy_from_slice(&table.value[0_usize..(table.length as usize)]); } =20 -fn get_buffer<'a> () -> Option<&'a mut TestTableFixed> -{ - let ptr : *mut c_void =3D unsafe { AllocatePool (size_of::()) }; +fn get_buffer<'a>() -> Option<&'a mut TestTableFixed> { + let ptr: *mut c_void =3D unsafe { AllocatePool(size_of::()) }; if ptr.is_null() { - return None; + return None; } - let buffer : &mut TestTableFixed =3D unsafe { core::mem::transmute::<*= mut c_void, &mut TestTableFixed>(ptr) }; + let buffer: &mut TestTableFixed =3D + unsafe { core::mem::transmute::<*mut c_void, &mut TestTableFixed>(= ptr) }; Some(buffer) } =20 -fn release_buffer (test_table : &mut TestTableFixed) -{ - test_table.r#type =3D 0; - unsafe { FreePool (test_table as *mut TestTableFixed as *mut c_void) ; } +fn release_buffer(test_table: &mut TestTableFixed) { + test_table.r#type =3D 0; + unsafe { + FreePool(test_table as *mut TestTableFixed as *mut c_void); + } } =20 #[no_mangle] #[export_name =3D "TestBufferDrop"] -pub extern fn test_buffer_drop ( - =20 - ) -{ - match get_buffer () { - Some(buffer) =3D> { - buffer.r#type =3D 1; - release_buffer(buffer); - drop (buffer); // This is required. - //buffer.r#type =3D 1; // error - }, - None =3D> {}, +pub extern "C" fn test_buffer_drop() { + match get_buffer() { + Some(buffer) =3D> { + buffer.r#type =3D 1; + release_buffer(buffer); + drop(buffer); // This is required. + //buffer.r#type =3D 1; // error + } + None =3D> {} } } =20 #[no_mangle] #[export_name =3D "TestBufferBorrow"] -pub extern fn test_buffer_borrow ( - test_table : &mut TestTableFixed - ) -{ - let test_table2 : &mut TestTableFixed =3D test_table; +pub extern "C" fn test_buffer_borrow(test_table: &mut TestTableFixed) { + let test_table2: &mut TestTableFixed =3D test_table; test_table2.r#type =3D 1; =20 - let test_table3 : &mut [u8; 64] =3D &mut test_table.value; + let test_table3: &mut [u8; 64] =3D &mut test_table.value; test_table3[63] =3D 0; =20 //test_table2.r#type =3D 2; // error @@ -237,44 +211,38 @@ pub extern fn test_buffer_borrow ( =20 #[no_mangle] #[export_name =3D "TestBufferAlloc"] -pub extern fn test_buffer_alloc ( - =20 - ) -{ +pub extern "C" fn test_buffer_alloc() { let layout =3D unsafe { core::alloc::Layout::from_size_align_unchecked= (32, 4) }; unsafe { - match Global.alloc (layout) { - Ok(buffer) =3D> { - let mut box_buffer =3D Box::from_raw(from_raw_parts_mut(buffer.a= s_ptr(), layout.size())); - box_buffer[0] =3D 1; - Global.dealloc (buffer, layout); - drop (buffer); // It is useless - box_buffer[0] =3D 1; // cannot catch - }, - Err(_) =3D> handle_alloc_error (layout), - } + match Global.allocate(layout) { + Ok(mut buffer) =3D> { + let mut box_buffer =3D Box::from_raw(buffer.as_mut()); + box_buffer[0] =3D 1; + Global.deallocate(buffer.as_non_null_ptr(), layout); + drop(buffer); // It is useless + box_buffer[0] =3D 1; // cannot catch + } + Err(_) =3D> handle_alloc_error(layout), + } } =20 let layout =3D core::alloc::Layout::new::(); unsafe { - match Global.alloc (layout) { - Ok(buffer) =3D> { - Global.dealloc (buffer, layout); - }, - Err(_) =3D> handle_alloc_error (layout), - } + match Global.allocate(layout) { + Ok(buffer) =3D> { + Global.deallocate(buffer.as_non_null_ptr(), layout); + } + Err(_) =3D> handle_alloc_error(layout), + } } } =20 -fn get_box ( - r#type: u32 - ) -> Box -{ - let mut a =3D Box::new(TestTableFixed{ - r#type: 0, - length: size_of::() as u32, - value: [0; 64] - }); // it will call __rust_alloc(). +fn get_box(r#type: u32) -> Box { + let mut a =3D Box::new(TestTableFixed { + r#type: 0, + length: size_of::() as u32, + value: [0; 64], + }); // it will call __rust_alloc(). a.r#type =3D r#type; =20 a @@ -282,35 +250,26 @@ fn get_box ( =20 #[no_mangle] #[export_name =3D "TestBoxAlloc"] -pub extern fn test_box_alloc ( - r#type: u32 - ) -> Box -{ - let mut a =3D get_box(1); +pub extern "C" fn test_box_alloc(r#type: u32) -> Box { + let mut a =3D get_box(1); =20 - a.r#type =3D r#type; + a.r#type =3D r#type; =20 - //test_box_free(a); // build fail. + //test_box_free(a); // build fail. =20 - let b =3D a; - b + let b =3D a; + b } =20 #[no_mangle] #[export_name =3D "TestBoxFree"] -pub extern fn test_box_free ( - buffer: Box - ) -{ - // it will call __rust_dealloc() +pub extern "C" fn test_box_free(buffer: Box) { + // it will call __rust_dealloc() } =20 #[no_mangle] #[export_name =3D "TestBoxAllocFail"] -pub extern fn test_box_alloc_fail ( - size: u32 - ) -> 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(). =20 a @@ -318,22 +277,17 @@ pub extern fn test_box_alloc_fail ( =20 #[no_mangle] #[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) }; unsafe { - match Global.alloc (layout) { - Ok(buffer) =3D> { - let mut box_buffer =3D Box::::from_raw(from_raw_parts_mut(bu= ffer.as_ptr(), layout.size()) as *mut [u8] as *mut u8 ); - Global.dealloc (buffer, layout); - *box_buffer =3D 1; - Box::::into_raw(box_buffer) - }, - Err(_) =3D> handle_alloc_error (layout), - } + match Global.allocate(layout) { + Ok(buffer) =3D> { + let mut box_buffer =3D Box::::from_raw(buffer.as_mut_p= tr()); + Global.deallocate(buffer.as_non_null_ptr(), layout); + *box_buffer =3D 1; + Box::::into_raw(box_buffer) + } + Err(_) =3D> handle_alloc_error(layout), + } } - - } --=20 2.35.1 -=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 (#87755): https://edk2.groups.io/g/devel/message/87755 Mute This Topic: https://groups.io/mt/89884785/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- From nobody Wed May 15 04:21:55 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+87756+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+87756+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1647673584; cv=none; d=zohomail.com; s=zohoarc; b=d/IJm6WUn6sYLQFLuTJ9jghj3iP+zCQAErfPLf/53OV/uD9tColHhXIkr1yIaxFjCs29P1idiwk4AN6015DivCDXIfYzODP35TLPpp4DveDH/JXPExRNjUstiF7lhUo5EeBbyugZPtLtGZSackQkTZNeXxrMG3pu6vL5COKZRrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647673584; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=0/6Fv6kpW8yE8NqclC92TX61i5Ine8mC2UIGjkWJUQk=; b=S1GYH8WKx8x4AE0/DYOs+2YdTh8/FcrwLefs6r+wydY72TPiv2N+AjAQAgyK9I6Koim0Taqz1xDGO9h96Oj25shme1cTG0KWPohOypoZHOTEzR//LGxL7XGioIJYVXC8MYBhVYyzNVcrOKBqa6/KROxGjUCyN4yMyZ6n4lutP2w= 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+87756+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 164767358445088.94859775350153; Sat, 19 Mar 2022 00:06:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id AtXQYY1788612x8wvI78sMXW; Sat, 19 Mar 2022 00:06:23 -0700 X-Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mx.groups.io with SMTP id smtpd.web11.4713.1647673583300880867 for ; Sat, 19 Mar 2022 00:06:23 -0700 X-Received: by mail-pg1-f170.google.com with SMTP id o23so6596130pgk.13 for ; Sat, 19 Mar 2022 00:06:23 -0700 (PDT) X-Gm-Message-State: ED0MHlsNuZLhdPj4oov3RaYHx1787277AA= X-Google-Smtp-Source: ABdhPJziFbxbiqA9tbI/8xzh6ZGBdGsf6IQOYBc6wDPhMp7hO94Ild5tYHHDZFgzs2yCXHtOZru4+w== X-Received: by 2002:a05:6a00:10cb:b0:4f7:942:6a22 with SMTP id d11-20020a056a0010cb00b004f709426a22mr14288640pfu.84.1647673582480; Sat, 19 Mar 2022 00:06:22 -0700 (PDT) X-Received: from toolbox.iitism.net ([103.15.228.66]) by smtp.gmail.com with ESMTPSA id u4-20020a056a00158400b004fa0263cf5dsm12300538pfk.130.2022.03.19.00.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 00:06:22 -0700 (PDT) From: "Ayush Singh" To: devel@edk2.groups.io Cc: Jiewen Yao Subject: [edk2-devel] [PATCH v1 3/3] RustPkg/Test/TestRustLangApp: Fix building Date: Sat, 19 Mar 2022 12:35:53 +0530 Message-Id: <20220319070553.25770-4-ayushdevel1325@gmail.com> In-Reply-To: <20220319070553.25770-1-ayushdevel1325@gmail.com> References: <20220319070553.25770-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 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 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647673583; bh=/+sBUh1KrRAuV2JRjX8gnchN4IXuLTMnYNm8dEvTAN0=; h=Cc:Date:From:Reply-To:Subject:To; b=vd092mROIPWuUAeAWQAWifBe4HS/8fhypibEpivsGOdjIjbJ6laSXyZsxQDA/iljy8t 0PvP9euDHyOXhkAv7l5ZROzWAnvFrnATkImHRh+WtCLV20qD80HRBi72vyy4rlus76DfW 7fRyDuRHTozzW6d4xOwydOI8mPUtdYTguEA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1647673586271100005 Content-Type: text/plain; charset="utf-8" Removed defination of _fltused from RustPkg/Library/UefiRustIntrinsicLib since compiler_builtins now provides one Cc: Jiewen Yao Signed-off-by: Ayush Singh --- RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs | 8 -- RustPkg/Test/TestRustLangApp/.cargo/config.toml | 3 + RustPkg/Test/TestRustLangApp/src/main.rs | 95 +++++++++----------- 3 files changed, 43 insertions(+), 63 deletions(-) diff --git a/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs b/RustPkg/Libr= ary/UefiRustIntrinsicLib/src/lib.rs index c2341e9a65af..2bfdc524a11c 100644 --- a/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs +++ b/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs @@ -12,15 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. =20 - #![cfg_attr(not(test), no_std)] - #![allow(unused)] =20 -#[used] -#[no_mangle] -pub static _fltused : i32 =3D 0; - extern crate uefi_rust_panic_lib; - - diff --git a/RustPkg/Test/TestRustLangApp/.cargo/config.toml b/RustPkg/Test= /TestRustLangApp/.cargo/config.toml new file mode 100644 index 000000000000..422bf9d2ab4e --- /dev/null +++ b/RustPkg/Test/TestRustLangApp/.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/TestRustLangApp/src/main.rs b/RustPkg/Test/TestRu= stLangApp/src/main.rs index 9dcea4fa5c4e..72bb12e16adf 100644 --- a/RustPkg/Test/TestRustLangApp/src/main.rs +++ b/RustPkg/Test/TestRustLangApp/src/main.rs @@ -13,120 +13,105 @@ // limitations under the License. =20 #![crate_type =3D "staticlib"] - #![feature(alloc_layout_extra)] #![feature(allocator_api)] #![feature(alloc_error_handler)] -#![feature(core_panic_info)] -#![feature(asm)] - #![cfg_attr(not(test), no_std)] #![no_main] - #![allow(unused)] =20 mod mem; =20 extern crate test_rust_lang_lib; +extern crate uefi_rust_allocation_lib; extern crate uefi_rust_intrinsic_lib; extern crate uefi_rust_panic_lib; -extern crate uefi_rust_allocation_lib; =20 use r_efi::efi; -use r_efi::efi::{Status}; +use r_efi::efi::Status; =20 -use core::panic::PanicInfo; use core::ffi::c_void; +use core::panic::PanicInfo; =20 use core::mem::size_of; use core::mem::transmute; =20 use core::slice::from_raw_parts; =20 - -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(); =20 extern crate alloc; =20 -use alloc::vec::Vec; use alloc::boxed::Box; - +use alloc::vec::Vec; =20 #[no_mangle] #[export_name =3D "AllocatePool"] -extern fn AllocatePool (size: usize) -> *mut c_void -{ - let mut address : *mut c_void =3D core::ptr::null_mut(); - =20 - let status =3D unsafe { ((*BS).allocate_pool) ( - efi::MemoryType::BootServicesData, - size, - &mut address as *mut *mut c_void - ) } ; - if status !=3D Status::SUCCESS { +extern "C" fn AllocatePool(size: usize) -> *mut c_void { + let mut address: *mut c_void =3D core::ptr::null_mut(); + + let status =3D unsafe { + ((*BS).allocate_pool)( + efi::MemoryType::BootServicesData, + size, + &mut address as *mut *mut c_void, + ) + }; + if status !=3D Status::SUCCESS { return core::ptr::null_mut(); - } - address as *mut c_void + } + address as *mut c_void } =20 - - #[no_mangle] #[export_name =3D "AllocateZeroPool"] -extern fn AllocateZeroPool (size: usize) -> *mut c_void -{ - let buffer =3D AllocatePool (size); +extern "C" fn AllocateZeroPool(size: usize) -> *mut c_void { + let buffer =3D AllocatePool(size); if buffer =3D=3D core::ptr::null_mut() { - return core::ptr::null_mut(); + return core::ptr::null_mut(); } =20 - unsafe {core::ptr::write_bytes (buffer, 0, size);} + unsafe { + core::ptr::write_bytes(buffer, 0, size); + } =20 buffer as *mut c_void } =20 - - #[no_mangle] #[export_name =3D "FreePool"] -extern fn FreePool (buffer: *mut c_void) -{ +extern "C" fn FreePool(buffer: *mut c_void) { unsafe { - ((*BS).free_pool) (buffer as *mut c_void); + ((*BS).free_pool)(buffer as *mut c_void); } } #[no_mangle] #[export_name =3D "ExternInit"] -extern fn ExternInit(data: *mut usize) -{ -} - +extern "C" fn ExternInit(data: *mut usize) {} =20 #[no_mangle] -pub extern fn efi_main(handle: efi::Handle, system_table: *mut efi::System= Table) -> Status -{ +pub extern "C" fn efi_main(handle: efi::Handle, system_table: *mut efi::Sy= stemTable) -> Status { uefi_rust_allocation_lib::init(system_table); =20 unsafe { - ST =3D system_table; - BS =3D (*ST).boot_services; + ST =3D system_table; + BS =3D (*ST).boot_services; } =20 // L"Hello World!/r/n" - let string_name =3D & mut [ - 0x48u16, 0x65u16, 0x6cu16, 0x6cu16, 0x6fu16, 0x20u16, - 0x57u16, 0x6fu16, 0x72u16, 0x6cu16, 0x64u16, 0x21u16, - 0x0Au16, 0x0Du16, 0x00u16 - ]; + let string_name =3D &mut [ + 0x48u16, 0x65u16, 0x6cu16, 0x6cu16, 0x6fu16, 0x20u16, 0x57u16, 0x6= fu16, 0x72u16, 0x6cu16, + 0x64u16, 0x21u16, 0x0Au16, 0x0Du16, 0x00u16, + ]; unsafe { - ((*((*ST).con_out)).output_string) ( - unsafe {(*ST).con_out}, - string_name.as_ptr() as *mut efi::Char16, - ); + ((*((*ST).con_out)).output_string)( + unsafe { (*ST).con_out }, + string_name.as_ptr() as *mut efi::Char16, + ); } =20 - test_rust_lang_lib::test_integer_overflow (0x10000, 0xFFFFFFFF, 0xFFFF= FFFF); + test_rust_lang_lib::test_integer_overflow(0x10000, 0xFFFFFFFF, 0xFFFFF= FFF); =20 Status::SUCCESS } --=20 2.35.1 -=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 (#87756): https://edk2.groups.io/g/devel/message/87756 Mute This Topic: https://groups.io/mt/89884786/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-